Exemple #1
0
        ///<summary>
        ///Deletes all the log files in the batch
        ///</summary>
        public void CleanExperimentBatch()
        {
            int numFilesDeleted = ExperimentBatch.DeleteLogFiles(BatchFileName);

            //re-load the batch for execution
            LoadExperimentBatch(BatchFileName);
        }
Exemple #2
0
        /// <summary>
        ///     Load an experiment from a batch file. If <paramref name="batchFileName"/> is either
        ///     null or empty, a dialog window will be opened to let the user select a batch file.
        /// </summary>
        /// <param name="batchFileName">The name of the file to load</param>
        public void LoadExperimentBatch(string batchFileName)
        {
            //Ask the user for the name of the batch
            if (string.IsNullOrEmpty(batchFileName))
            {
                bool bSuccess = Files.OpenFileDialog(ref batchFileName
                                                     , Files.ExperimentBatchDescription, Files.ExperimentBatchFilter);
                if (!bSuccess)
                {
                    return;
                }
            }

            //reset the view if a batch was succesfully selected
            ClearReportViewer();

            //Inefficient but not so much as to care
            //First we load the batch file to cout how many experimental units we have
            StartLongOperation();
            LoadedBatch = "Reading batch file";

            //first count the total number of experimental units
            m_numExperimentalUnits = ExperimentBatch.CountExperimentalUnits(batchFileName, LoadOptions.ExpUnitSelection.All);

            Task.Run(() =>
            {
                //load finished experimental units from the batch
                LoadOptions loadOptions = new LoadOptions()
                {
                    Selection          = LoadOptions.ExpUnitSelection.OnlyFinished,
                    LoadVariablesInLog = true,
                    OnExpUnitLoaded    = OnExperimentalUnitProcessed
                };

                LoadedBatch           = "Reading experiment files";
                ExperimentBatch batch = new ExperimentBatch();
                batch.Load(batchFileName, loadOptions);

                //Create ViewModels from LoggedExperimentBatch
                foreach (Experiment experiment in batch.Experiments)
                {
                    LoggedExperimentViewModel newExperiment
                        = new LoggedExperimentViewModel(experiment);

                    LoggedExperiments.Add(newExperiment);
                    ExperimentalUnits.AddRange(newExperiment.ExperimentalUnits);
                    Query.AddLogVariables(newExperiment.VariablesInLog);
                    ForksLoaded |= newExperiment.Forks.Count > 0;

                    newExperiment.TraverseAction(true, (n) =>
                    {
                        if (n is LoggedForkViewModel fork)
                        {
                            fork.PropertyChanged += OnChildPropertyChanged;
                        }
                    });
                }

                //Update flags use to enable/disable parts of the report generation menu
                NotifyOfPropertyChange(() => ForksLoaded);
                NotifyOfPropertyChange(() => VariablesLoaded);

                LoadedBatch = batchFileName;
                LogsLoaded  = true;

                EndLongOperation();
            });
        }
Exemple #3
0
        /// <summary>
        ///     Initializes the experiments to be monitored through a batch file that
        ///     contains all required data for the task.
        /// </summary>
        /// <param name="batchFileName">The batch file with experiment data</param>
        public bool LoadExperimentBatch(string batchFileName)
        {
            //Load unfinished experiments
            LoadOptions loadOptionsUnfinished = new LoadOptions()
            {
                Selection          = LoadOptions.ExpUnitSelection.OnlyUnfinished,
                LoadVariablesInLog = false
            };

            ExperimentBatch batchUnfinished = new ExperimentBatch();

            batchUnfinished.Load(batchFileName, loadOptionsUnfinished);

            LoggedExperiments.Clear();
            foreach (Experiment experiment in batchUnfinished.Experiments)
            {
                LoggedExperimentViewModel newExperiment = new LoggedExperimentViewModel(experiment);
                LoggedExperiments.Add(newExperiment);
            }
            //count unfinished experiments
            int numUnfinishedExperimentalUnits = batchUnfinished.CountExperimentalUnits();

            //load all experimental units and count them
            LoadOptions loadOptionsFinished = new LoadOptions()
            {
                Selection          = LoadOptions.ExpUnitSelection.OnlyFinished,
                LoadVariablesInLog = false
            };

            //we use a temp variable first to get the count of finished units so that setting the value of NumFinishedExperimentalUnitsBeforeStart triggers the progress update
            //AFTER setting the value of NumExperimentalUnits
            NumFinishedExperimentalUnitsBeforeStart = ExperimentBatch.CountExperimentalUnits(batchFileName, LoadOptions.ExpUnitSelection.OnlyFinished);
            NumExperimentalUnits = numUnfinishedExperimentalUnits + NumFinishedExperimentalUnitsBeforeStart;
            NumFinishedExperimentalUnitsAfterStart = 0;

            //Initialize pending experiment list
            m_pendingExperiments.Clear();

            foreach (var experiment in LoggedExperiments)
            {
                foreach (AppVersion version in experiment.AppVersions)
                {
                    if (!ExistsRequiredFile(version.ExeFile))
                    {
                        CaliburnUtility.ShowWarningDialog("Cannot find required file: " + version.ExeFile + ". Check the app definition file in /config/apps", "ERROR");
                        return(false);
                    }
                    foreach (string pre in version.Requirements.InputFiles)
                    {
                        if (!ExistsRequiredFile(pre))
                        {
                            CaliburnUtility.ShowWarningDialog("Cannot find required file: " + pre + ". Check the app definition file in /config/apps", "ERROR");
                            return(false);
                        }
                    }
                }
                foreach (LoggedExperimentalUnitViewModel unit in experiment.ExperimentalUnits)
                {
                    m_pendingExperiments.Add(unit.Model);
                }
            }

            BatchFileName = batchFileName;
            Plot.ClearLineSeries();
            AllMonitoredJobs.Clear();
            IsBatchLoaded = true;
            IsRunning     = false;

            return(true);
        }
Exemple #4
0
        public async void runExperimentsAsync(bool monitorProgress, bool receiveJobResults)
        {
            m_bRunning          = true;
            m_cancelTokenSource = new CancellationTokenSource();

            List <Task <ExperimentBatch> > experimentBatchTaskList = new List <Task <ExperimentBatch> >();
            List <ExperimentBatch>         experimentBatchList     = new List <ExperimentBatch>();

            //assign experiments to free agents
            assignExperiments(ref m_pendingExperiments, ref m_herdAgentList, ref experimentBatchList
                              , m_cancelTokenSource.Token, logFunction);
            try
            {
                while ((experimentBatchList.Count > 0 || experimentBatchTaskList.Count > 0 ||
                        m_pendingExperiments.Count > 0) &&
                       !m_cancelTokenSource.IsCancellationRequested)
                {
                    foreach (ExperimentBatch batch in experimentBatchList)
                    {
                        experimentBatchTaskList.Add(batch.sendJobAndMonitor());
                    }
                    //all pending experiments sent? then we await completion to retry in case something fails
                    if (m_pendingExperiments.Count == 0)
                    {
                        Task.WhenAll(experimentBatchTaskList).Wait();
                        logFunction("All the experiments have finished");
                        break;
                    }

                    //wait for the first agent to finish and give it something to do
                    Task <ExperimentBatch> finishedTask = await Task.WhenAny(experimentBatchTaskList);

                    ExperimentBatch finishedTaskResult = await finishedTask;
                    logFunction("Job finished: " + finishedTaskResult.ToString());
                    experimentBatchTaskList.Remove(finishedTask);

                    if (finishedTaskResult.failedExperiments.Count > 0)
                    {
                        foreach (MonitoredExperimentViewModel exp in finishedTaskResult.failedExperiments)
                        {
                            m_pendingExperiments.Add(exp);
                        }
                        logFunction(finishedTaskResult.failedExperiments.Count + " failed experiments enqueued again for further trials");
                    }

                    //just in case the freed agent hasn't still been discovered by the shepherd
                    if (!m_herdAgentList.Contains(finishedTaskResult.herdAgent))
                    {
                        m_herdAgentList.Add(finishedTaskResult.herdAgent);
                    }

                    //assign experiments to free agents
                    assignExperiments(ref m_pendingExperiments, ref m_herdAgentList, ref experimentBatchList
                                      , m_cancelTokenSource.Token, logFunction);
                }
            }
            catch (Exception ex)
            {
                logFunction("Exception in runExperimentQueueRemotely()");
                logFunction(ex.StackTrace);
            }
            finally
            {
                if (m_pendingExperiments.Count == 0)
                {
                    bFinished = true; // used to enable the "View reports" button
                }
                m_bRunning = false;
                m_cancelTokenSource.Dispose();
            }
        }