Exemplo n.º 1
0
        public void ExportForCluster(PopulationSimulation populationSimulation, string populationFolder, string fileDescription = null)
        {
            if (string.IsNullOrEmpty(populationFolder))
            {
                return;
            }

            _lazyLoadTask.Load(populationSimulation);

            if (settingsRequired(populationSimulation))
            {
                var outputSelections = _simulationSettingsRetriever.SettingsFor(populationSimulation);
                if (outputSelections == null)
                {
                    return;
                }

                populationSimulation.OutputSelections.UpdatePropertiesFrom(outputSelections, _cloner);
            }

            var existingFiles = Directory.GetFiles(populationFolder);

            if (existingFiles.Any())
            {
                if (_dialogCreator.MessageBoxYesNo(PKSimConstants.UI.DeleteFilesIn(populationFolder)).Equals(ViewResult.No))
                {
                    return;
                }

                existingFiles.Each(FileHelper.DeleteFile);
            }

            var fileName          = populationSimulation.Name;
            var modelFileFullPath = Path.Combine(populationFolder, $"{fileName}.pkml");
            var agingFileFullPath = Path.Combine(populationFolder, $"{fileName}{CoreConstants.Population.TABLE_PARAMETER_EXPORT}.csv");

            //Model
            _mobiExportTask.ExportSimulationToPkmlFile(populationSimulation, modelFileFullPath);

            var comments = _populationExportTask.CreateProjectMetaInfoFrom(fileDescription);

            //all values
            var dataTable = _populationExportTask.CreatePopulationDataFor(populationSimulation);

            dataTable.ExportToCSV(Path.Combine(populationFolder, $"{fileName}.csv"), comments: comments);

            //all aging data
            var agingData = populationSimulation.AgingData.ToDataTable();

            if (agingData.Rows.Count > 0)
            {
                agingData.ExportToCSV(agingFileFullPath, comments: comments);
            }
        }
Exemplo n.º 2
0
        public async Task <PopulationRunResults> RunAsync(PopulationSimulation populationSimulation, SimulationRunOptions simulationRunOptions)
        {
            _progressUpdater = _progressManager.Create();
            _progressUpdater.Initialize(populationSimulation.NumberOfItems, PKSimConstants.UI.Calculating);

            var begin = SystemTime.UtcNow();

            try
            {
                var populationData      = _populationExporter.CreatePopulationDataFor(populationSimulation);
                var modelCoreSimulation = _modelCoreSimulationMapper.MapFrom(populationSimulation, shouldCloneModel: false);
                var runOptions          = new RunOptions {
                    NumberOfCoresToUse = _userSettings.MaximumNumberOfCoresToUse
                };
                _eventPublisher.PublishEvent(new SimulationRunStartedEvent());
                var populationRunResults = await _populationRunner.RunPopulationAsync(modelCoreSimulation, runOptions, populationData, populationSimulation.AgingData.ToDataTable());

                _simulationResultsSynchronizer.Synchronize(populationSimulation, populationRunResults.Results);
                _populationSimulationAnalysisSynchronizer.UpdateAnalysesDefinedIn(populationSimulation);
                _eventPublisher.PublishEvent(new SimulationResultsUpdatedEvent(populationSimulation));

                return(populationRunResults);
            }
            catch (OperationCanceledException)
            {
                simulationTerminated();
                return(null);
            }
            catch (Exception)
            {
                simulationTerminated();
                throw;
            }
            finally
            {
                var end       = SystemTime.UtcNow();
                var timeSpent = end - begin;
                _eventPublisher.PublishEvent(new SimulationRunFinishedEvent(populationSimulation, timeSpent));
            }
        }
Exemplo n.º 3
0
        public async Task RunAsync(PopulationSimulation populationSimulation)
        {
            _progressUpdater = _progressManager.Create();
            _progressUpdater.Initialize(populationSimulation.NumberOfItems, PKSimConstants.UI.Calculating);
            _populationRunner.NumberOfCoresToUse = _userSettings.MaximumNumberOfCoresToUse;

            //make sure that thread methods always catch and handle any exception,
            //otherwise we risk unplanned application termination
            var begin = SystemTime.UtcNow();

            try
            {
                var populationData      = _populationExporter.CreatePopulationDataFor(populationSimulation);
                var modelCoreSimulation = _modelCoreSimulationMapper.MapFrom(populationSimulation, shouldCloneModel: false);
                _simulationPersistableUpdater.UpdatePersistableFromSettings(populationSimulation);

                _eventPublisher.PublishEvent(new SimulationRunStartedEvent());
                var populationRunResults = await _populationRunner.RunPopulationAsync(modelCoreSimulation, populationData, populationSimulation.AgingData.ToDataTable());

                _simulationResultsSynchronizer.Synchronize(populationSimulation, populationRunResults.Results);
                _populationSimulationAnalysisSynchronizer.UpdateAnalysesDefinedIn(populationSimulation);
                _eventPublisher.PublishEvent(new SimulationResultsUpdatedEvent(populationSimulation));
            }
            catch (OperationCanceledException)
            {
                simulationTerminated();
            }
            catch (Exception ex)
            {
                _exceptionManager.LogException(ex);
                simulationTerminated();
            }
            finally
            {
                var end       = SystemTime.UtcNow();
                var timeSpent = end - begin;
                _eventPublisher.PublishEvent(new SimulationRunFinishedEvent(populationSimulation, timeSpent));
            }
        }