示例#1
0
        /// <summary>
        /// Run the simulation by using the initial parameter according with ParameterRange object.
        /// SetLoggerData and SetParameterRange should be called, before this function use.
        /// </summary>
        /// <param name="groupName">the group name.</param>
        /// <param name="topDir">top directory include the script file and result data.</param>
        /// <param name="modelName">model name executed the simulation.</param>
        /// <param name="count">simulation time or simulation step.</param>
        /// <param name="isStep">the flag use simulation time or simulation step.</param>
        /// <returns>Dictionary of jobid and the execution parameter.</returns>
        public Dictionary<int, ExecuteParameter> RunSimParameterMatrix(string groupName, string topDir, string modelName, double count, bool isStep)
        {
            Dictionary<int, ExecuteParameter> resList = new Dictionary<int, ExecuteParameter>();
            Project prj = m_env.DataManager.CurrentProject;
            ScriptWriter writer = new ScriptWriter(prj);
            List<EcellObject> sysList = m_groupDic[groupName].SystemObjectList;
            List<EcellObject> stepperList = m_groupDic[groupName].StepperObjectList;
            Dictionary<string, double> paramDic = new Dictionary<string, double>();
            if (m_paramList.Count != 2)
            {
                Util.ShowErrorDialog("ERROR");
                return resList;
            }
            EcellParameterData x = m_paramList[0];
            EcellParameterData y = m_paramList[1];
            if (!Directory.Exists(topDir))
            {
                Directory.CreateDirectory(topDir);
            }
            int i = 0;
            for (double xd = x.Min ; xd <= x.Max; xd += x.Step)
            {
                int j = 0;
                for (double yd = y.Min; yd <= y.Max; yd += y.Step)
                {
                    paramDic.Clear();
                    foreach (EcellObject sysObj in sysList)
                    {
                        if (sysObj.Value != null)
                        {
                            foreach (EcellData d in sysObj.Value)
                            {
                                if (d.EntityPath.Equals(x.Key))
                                {
                                    d.Value = new EcellValue(xd);
                                    paramDic.Add(x.Key, xd);
                                }
                                else if (d.EntityPath.Equals(y.Key))
                                {
                                    d.Value = new EcellValue(yd);
                                    paramDic.Add(y.Key, yd);
                                }
                            }
                        }
                    }
                    foreach (EcellObject sysObj in sysList)
                    {
                        foreach (EcellObject obj in sysObj.Children)
                        {
                            if (obj.Value == null) continue;
                            foreach (EcellData d in obj.Value)
                            {
                                if (d.EntityPath.Equals(x.Key))
                                {
                                    d.Value = new EcellValue(xd);
                                    paramDic.Add(x.Key, xd);
                                }
                                else if (d.EntityPath.Equals(y.Key))
                                {
                                    d.Value = new EcellValue(yd);
                                    paramDic.Add(y.Key, yd);
                                }
                            }
                            Application.DoEvents();
                        }
                    }

                    Job job = Proxy.CreateJob();
                    job.GroupName = groupName;
                    job.Manager = this;
                    string dirName = topDir + "/" + job.JobID;
                    string fileName = topDir + "/" + job.JobID + ".ess";
                    string modelFileName = topDir + "/" + job.JobID + ".eml";

                    List<string> extFileList = ExtractExtFileList(topDir + "/" + job.JobID, m_logList);
                    if (m_groupDic[groupName].Status == AnalysisStatus.Stopped)
                        return new Dictionary<int, ExecuteParameter>();

                    int jobid = RegisterJob(job, m_proxy.GetDefaultScript(), fileName, extFileList);

                    if (this.Proxy.IsIDE())
                    {
                        //CreateLocalScript(topDir, dirName, fileName, writer,
                        //    modelName, count, isStep, sysList, stepperList, paramDic);
                        CreateLocalScript(jobid, topDir, dirName, fileName, modelFileName, writer,
                            modelName, count, isStep, sysList, stepperList, paramDic);
                    }
                    else
                    {
                        CreateUnixScript(jobid, topDir, dirName, fileName, modelFileName, writer,
                            modelName, count, isStep, sysList, stepperList, paramDic);
                    }
                    job.ExecParam = new ExecuteParameter(paramDic);
                    resList.Add(jobid, new ExecuteParameter(paramDic));
                    Application.DoEvents();
                    j++;
                }
                i++;
            }
            Run(groupName, false);
            OnJobUpdate(JobUpdateType.Update);
            return resList;
        }
示例#2
0
        /// <summary>
        /// Run the simulation by using the initial parameter within the range of parameters.
        /// The number of sample is set. SetLoggerData and SetParameterRange should be called, before this function use.
        /// </summary>
        /// <param name="groupName">the group name</param>
        /// <param name="topDir">top directory include the script file and result data.</param>
        /// <param name="modelName">model name executed the simulation.</param>
        /// <param name="num">the number of sample.</param>
        /// <param name="count">simulation time or simulation step.</param>
        /// <param name="isStep">the flag use simulation time or simulation step.</param>
        /// <param name="isRandom">the flag this parameter is random,</param>
        /// <returns>Dictionary of jobid and the execution parameter.</returns>
        public Dictionary<int, ExecuteParameter> RunSimParameterRange(string groupName, string topDir, string modelName, int num, double count, bool isStep, bool isRandom)
        {
            Dictionary<int, ExecuteParameter> resList = new Dictionary<int, ExecuteParameter>();
            Project prj = m_env.DataManager.CurrentProject;
            ScriptWriter writer = new ScriptWriter(prj);
            List<EcellObject> sysList = m_groupDic[groupName].SystemObjectList;
            List<EcellObject> stepperList = m_groupDic[groupName].StepperObjectList;
            Dictionary<string, double> paramDic = new Dictionary<string, double>();
            Random hRandom = new Random();
            if (!Directory.Exists(topDir))
            {
                Directory.CreateDirectory(topDir);
            }
            for (int i = 0 ; i < num ; i++ )
            {
                paramDic.Clear();
                foreach (EcellParameterData p in m_paramList)
                {
                    double data = 0.0;
                    if (p.Step <= 0.0 || isRandom)
                    {
                        double d = hRandom.NextDouble();
                        data = d  * (p.Max - p.Min) + p.Min;
                    }
                    else
                    {
                        data = p.Step * i + p.Min;
                    }
                    paramDic.Add(p.Key, data);
                }

                Job job = Proxy.CreateJob();
                job.GroupName = groupName;
                job.Manager = this;
                string dirName = topDir + "/" + job.JobID;
                string fileName = topDir + "/" + job.JobID + ".ess";
                string modelFileName = topDir + "/" + job.JobID + ".eml";

                List<string> extFileList = ExtractExtFileList(topDir + "/" + job.JobID, m_logList);

                if (m_groupDic[groupName].Status == AnalysisStatus.Stopped)
                    return new Dictionary<int, ExecuteParameter>();
                int jobid = RegisterJob(job, m_proxy.GetDefaultScript(), fileName, extFileList);
                if (this.Proxy.IsIDE() == true)
                {
                    CreateLocalScript(jobid, topDir, dirName, fileName, modelFileName, writer,
                        modelName, count, isStep, sysList, stepperList, paramDic);
                    //CreateLocalScript(topDir, dirName, fileName, writer,
                    //    modelName, count, isStep, sysList, stepperList, paramDic);
                }
                else
                {
                    CreateUnixScript(jobid, topDir, dirName, fileName, modelFileName, writer,
                        modelName, count, isStep, sysList, stepperList, paramDic);
                }
                job.ExecParam = new ExecuteParameter(paramDic);
                resList.Add(jobid, new ExecuteParameter(paramDic));
                Application.DoEvents();
            }
            Run(groupName, false);
            OnJobUpdate(JobUpdateType.Update);
            return resList;
        }
示例#3
0
        /// <summary>
        /// Rerun jobs after the script is created.
        /// </summary>
        /// <param name="jobid">Job id</param>
        /// <param name="groupName">group name</param>
        /// <param name="topDir">the top directory</param>
        /// <param name="modelName">the model name</param>
        /// <param name="count">simulation time or simulation step.</param>
        /// <param                            name="isStep">the flag use simulation time or simulation step.</param>
        /// <param name="paramDic">the execution parameter.</param>
        public void ReRunSimParameterSet(int jobid, string groupName, string topDir, string modelName,
            double count, bool isStep, ExecuteParameter paramDic)
        {
            Project prj = m_env.DataManager.CurrentProject;
            ScriptWriter writer = new ScriptWriter(prj);
            List<EcellObject> sysList = m_groupDic[groupName].SystemObjectList;
            List<EcellObject> stepperList = m_groupDic[groupName].StepperObjectList;

            string dirName = topDir + "/" + jobid;
            string fileName = topDir + "/" + jobid + ".ess";
            string modelFileName = topDir + "/" + jobid + ".eml";

            //CreateLocalScript(topDir, dirName, fileName, writer,
            //    modelName, count, isStep, sysList, stepperList, paramDic.ParamDic);

            CreateLocalScript(jobid, topDir, dirName, fileName, modelFileName, writer,
                modelName, count, isStep, sysList, stepperList, paramDic.ParamDic);
        }
示例#4
0
        /// <summary>
        /// Create the script for linux.
        /// </summary>
        /// <param name="jobID">the job id.</param>
        /// <param name="topDir">the top directory.</param>
        /// <param name="dirName">the execute directory.</param>
        /// <param name="fileName">the script file.</param>
        /// <param name="modelFile">the model file.</param>
        /// <param name="writer">the file writer.</param>
        /// <param name="modelName">the model name.</param>
        /// <param name="count">the simulation time.</param>
        /// <param name="isStep">the flag whetehr simulation is step.</param>
        /// <param name="stepperList">the list of stepper.</param>
        /// <param name="sysList">the list of system object.</param>
        /// <param name="paramDic">the dictionary of parameters.</param>
        private void CreateUnixScript(int jobID, string topDir, string dirName, string fileName, string modelFile,
            ScriptWriter writer, string modelName, double count, bool isStep, List<EcellObject> sysList,
            List<EcellObject> stepperList, Dictionary<string, double> paramDic)
        {
            Encoding enc = Encoding.GetEncoding(51932);
            SetLogTopDirectory(dirName);
            if (!Directory.Exists(dirName))
            {
                Directory.CreateDirectory(dirName);
            }

            //List<string> modelList = new List<string>();
            //modelList.Add(modelName);
            //m_env.DataManager.ExportModel(modelList, modelFile);

            List<EcellObject> storedList = new List<EcellObject>();
            storedList.AddRange(stepperList);
            storedList.AddRange(sysList);
            EmlWriter.Create(modelFile, storedList, false);

            writer.ClearScriptInfo();
            File.WriteAllText(fileName, "", enc);

            writer.WriteModelEntryUnix(fileName, enc, jobID);
            foreach (EcellObject sysObj in sysList)
            {
                foreach (string path in paramDic.Keys)
                {
                    if (sysObj.Value == null) continue;
                    foreach (EcellData v in sysObj.Value)
                    {
                        if (!path.Equals(v.EntityPath))
                            continue;
                        v.Value = new EcellValue(paramDic[path]);
                        writer.WriteComponentPropertyUnix(fileName, enc, sysObj, v);
                        break;
                    }
                }
            }
            Application.DoEvents();
            foreach (EcellObject sysObj in sysList)
            {
                EcellObject tmpObj = sysObj.Clone();
                foreach (string path in paramDic.Keys)
                {
                    foreach (EcellObject obj in tmpObj.Children)
                    {
                        if (obj.Value == null) continue;
                        foreach (EcellData v in obj.Value)
                        {
                            if (!path.Equals(v.EntityPath))
                                continue;
                            v.Value = new EcellValue(paramDic[path]);
                            writer.WriteComponentPropertyUnix(fileName, enc, obj, v);
                            break;
                        }
                        Application.DoEvents();
                    }
                }
            }

            Application.DoEvents();
            List<string> sList = new List<string>();
            foreach (SaveLoggerProperty s in m_logList)
            {
                sList.Add(s.FullPath);
            }
            writer.WriteLoggerPropertyUnix(fileName, enc, sList);
            if (isStep)
                writer.WriteSimulationForStepUnix(fileName, (int)(count), enc);
            else
                writer.WriteSimulationForTimeUnix(fileName, count, enc);
            writer.WriteLoggerSaveEntryUnix(fileName, enc, jobID,
                m_logList, Proxy.GetData(GlobusJob.TOPDIR_NAME));
        }
示例#5
0
        /// <summary>
        /// Execute the simulation with using the set parameters.
        /// </summary>
        /// <param name="groupName">the group name</param>
        /// <param name="topDir">top directory include the script file and result data.</param>
        /// <param name="modelName">model name executed the simulation.</param>
        /// <param name="count">simulation time or simulation step.</param>
        /// <param name="isStep">the flag use simulation time or simulation step.</param>
        /// <param name="setparam">the set parameters.</param>
        /// <returns>Dictionary of jobid and the execution parameter.</returns>
        public Dictionary<int, ExecuteParameter> RunSimParameterSet(string groupName, string topDir, string modelName, 
            double count, bool isStep, Dictionary<int, ExecuteParameter> setparam)
        {
            Project prj = m_env.DataManager.CurrentProject;
            ScriptWriter writer = new ScriptWriter(prj);
            List<EcellObject> sysList = m_groupDic[groupName].SystemObjectList;
            List<EcellObject> stepperList = m_groupDic[groupName].StepperObjectList;
            Dictionary<int, ExecuteParameter> resList = new Dictionary<int, ExecuteParameter>();
            if (!Directory.Exists(topDir))
            {
                Directory.CreateDirectory(topDir);
            }
            foreach (int i in setparam.Keys)
            {
                Dictionary<string, double> paramDic = setparam[i].ParamDic;

                Job job = Proxy.CreateJob();
                job.GroupName = groupName;
                job.Manager = this;
                string dirName = topDir + "/" + job.JobID;
                string fileName = topDir + "/" + job.JobID + ".ess";
                string modelFileName = topDir + "/" + job.JobID + ".eml";

                List<string> extFileList = ExtractExtFileList(topDir + "/" + job.JobID, m_logList);
                if (m_groupDic[groupName].Status == AnalysisStatus.Stopped)
                    return new Dictionary<int, ExecuteParameter>();
                int jobid = RegisterJob(job, m_proxy.GetDefaultScript(), fileName, extFileList);

                if (this.Proxy.IsIDE() == true)
                {
                    CreateLocalScript(jobid, topDir, dirName, fileName, modelFileName, writer,
                        modelName, count, isStep, sysList, stepperList, paramDic);
                    //CreateLocalScript(topDir, dirName, fileName, writer,
                    //    modelName, count, isStep, sysList, stepperList, paramDic);
                }
                else
                {
                    CreateUnixScript(jobid, topDir, dirName, fileName, modelFileName, writer,
                        modelName, count, isStep, sysList, stepperList, paramDic);
                }

                job.ExecParam = new ExecuteParameter(paramDic);
                resList.Add(jobid, new ExecuteParameter(paramDic));
                Application.DoEvents();
            }
            Run(groupName, false);
            OnJobUpdate(JobUpdateType.Update);
            return resList;
        }
示例#6
0
 /// <summary>
 /// Saves the script.
 /// </summary>
 /// <param name="fileName">the script file name.</param>
 public void SaveScript(string fileName)
 {
     try
     {
         ScriptWriter writer = new ScriptWriter(m_currentProject);
         writer.SaveScript(fileName);
         m_env.Console.WriteLine(string.Format(MessageResources.InfoSaveScript, fileName));
         m_env.Console.Flush();
     }
     catch (Exception ex)
     {
         Trace.WriteLine(ex);
         throw new EcellException(string.Format(MessageResources.ErrSaveScript, fileName), ex);
     }
 }
示例#7
0
        public void TestScriptWriterForUnix()
        {
            // Load Drosophila
            _unitUnderTest.LoadProject(TestConstant.Project_Drosophila);

            string processLog = "Process:/CELL/CYTOPLASM:R_toy10:Activity";
            string variableLob = "Variable:/CELL/CYTOPLASM:P0:Value";
            string systemLog = "System:/:CELL:Size";

            System.Text.Encoding enc = System.Text.Encoding.GetEncoding(51932);
            int jobID = 0;
            double count = 1.0;
            ScriptWriter writer = new ScriptWriter(_unitUnderTest.CurrentProject);
            List<SaveLoggerProperty> m_logList = new List<SaveLoggerProperty>();
            Dictionary<string, double> paramDic = new Dictionary<string, double>();
            m_logList.Add(new SaveLoggerProperty(processLog, 0.0, 0.0, TestConstant.TestDirectory));
            m_logList.Add(new SaveLoggerProperty(variableLob, 0.0, 0.0, TestConstant.TestDirectory));
            paramDic.Add(processLog, 10.0);
            paramDic.Add(variableLob, 10.0);
            paramDic.Add(systemLog, 0.1);

            if (File.Exists(TestConstant.Script_File))
                File.Delete(TestConstant.Script_File);

            string fileName = TestConstant.Script_File;
            File.WriteAllText(fileName, "", enc);
            writer.WriteModelEntryUnix(fileName, enc, jobID);
            foreach (EcellObject sysObj in _unitUnderTest.CurrentProject.SystemList)
            {
                EcellObject tmpObj = sysObj.Clone();
                foreach (string path in paramDic.Keys)
                {
                    foreach (EcellObject obj in tmpObj.Children)
                    {
                        if (obj.Value == null) continue;
                        foreach (EcellData v in obj.Value)
                        {
                            if (!path.Equals(v.EntityPath))
                                continue;
                            v.Value = new EcellValue(paramDic[path]);
                            writer.WriteComponentPropertyUnix(fileName, enc, obj, v);
                            break;
                        }
                    }
                }
            }
                        List<string> sList = new List<string>();
            foreach (SaveLoggerProperty s in m_logList)
            {
                sList.Add(s.FullPath);
            }

            writer.WriteLoggerPropertyUnix(fileName, enc, sList);
            writer.WriteSimulationForStepUnix(fileName, (int)(count), enc);
            writer.WriteSimulationForTimeUnix(fileName, count, enc);
            writer.WriteLoggerSaveEntryUnix(fileName, enc, jobID,
                m_logList,  TestConstant.TestDirectory);
            writer.WriteLoggerSaveEntryUnix(fileName, enc, jobID,
                m_logList, null);
            writer.WriteLoggerSaveEntryUnix(fileName, enc, jobID,
                null, TestConstant.TestDirectory);
        }