Example #1
0
        private void exportSimulationToFile(Simulation simulation, string moBiFile)
        {
            _lazyLoadTask.Load(simulation);
            if (simulation.IsImported)
            {
                throw new PKSimException(PKSimConstants.Error.CannotExportAnImportedSimulation);
            }

            var configuration  = _buildConfigurationTask.CreateFor(simulation, shouldValidate: true, createAgingDataInSimulation: false);
            var moBiSimulation = _simulationMapper.MapFrom(simulation, configuration, shouldCloneModel: false);

            updateObserverForAllFlag(moBiSimulation);
            updateRepresentationInfo(moBiSimulation);
            updateFormulaIdIn(moBiSimulation);

            var simulationTransfer = new SimulationTransfer
            {
                Simulation  = moBiSimulation,
                JournalPath = _journalRetriever.JournalFullPath
            };

            var currentProject = _projectRetriever.CurrentProject;

            if (currentProject != null)
            {
                simulationTransfer.AllObservedData = simulation.UsedObservedData.Select(o => currentProject.ObservedDataBy(o.Id)).ToList();
                simulationTransfer.Favorites       = currentProject.Favorites;
            }

            _simulationPersistor.Save(simulationTransfer, moBiFile);
        }
Example #2
0
 protected override void PerformExecute()
 {
     _lazyLoadTask.Load(Subject);
     using (var presenter = _applicationController.Start <IParameterDebugPresenter>())
     {
         presenter.ShowParametersFor(Subject);
     }
 }
Example #3
0
        public DataTable CreatePopulationDataFor(Population population, bool includeUnitsInHeader = false)
        {
            _lazyLoadTask.Load(population);
            var dataTable = new DataTable(population.Name);

            dataTable.BeginLoadData();

            //Create one column for the parameter path
            addCovariates(population, dataTable);

            //add advanced parameters
            var allAdvancedParameters = population.AllAdvancedParameters(_entityPathResolver).ToList();
            var parametersToExport    = population.AllVectorialParameters(_entityPathResolver);

            //do not take the one that should never be exported
            parametersToExport = parametersToExport.Where(p => parameterShouldBeExported(p, allAdvancedParameters));

            parametersToExport.Each(p => addParameterToTable(population, dataTable, p, includeUnitsInHeader));
            dataTable.EndLoadData();
            return(dataTable);
        }
        public void LoadPopulationAnalysisWorkflowInto(IPopulationDataCollector populationDataCollector)
        {
            var populationAnalysisWorkflow = _templateTask.LoadFromTemplate <SimulationAnalysisWorkflow>(TemplateType.PopulationSimulationAnalysisWorkflow);

            if (populationAnalysisWorkflow == null)
            {
                return;
            }

            _lazyLoadTask.Load(populationDataCollector as ILazyLoadable);

            populationAnalysisWorkflow.AllAnalyses.Each(x => { _simulationAnalysisCreator.AddSimulationAnalysisTo(populationDataCollector, x); });

            var populationSimulation = populationDataCollector as PopulationSimulation;

            if (populationSimulation == null)
            {
                return;
            }

            populationSimulation.OutputSelections.UpdatePropertiesFrom(populationAnalysisWorkflow.OutputSelections, _cloner);
        }
Example #5
0
        private async Task <bool> exportSimulation(DirectoryInfo originalDirectory, DirectoryInfo afterConversionDirectory, DirectoryInfo newDirectory, DirectoryInfo pkmlOldDirectory, DirectoryInfo pkmlNewDirectory, IndividualSimulation simulation, IPKSimProject project)
        {
            _lazyLoadTask.Load(simulation);

            if (!simulation.HasResults)
            {
                return(warn($"No results found for simulation '{simulation.Name}'"));
            }

            if (!simulation.HasUpToDateResults)
            {
                return(warn($"Results not up to date in simulation '{simulation.Name}'"));
            }

            if (simulation.IsImported)
            {
                return(warn($"Imported simulation '{simulation.Name}' cannot be exported"));
            }

            await exportSimulationToPkml(pkmlOldDirectory, project.Name, simulation);

            await exportSimulationResultsToCSV(originalDirectory, project.Name, simulation, "old");

            await runSimulation(simulation);

            await exportSimulationResultsToCSV(afterConversionDirectory, project.Name, simulation, "new");

            IndividualSimulation otherSimulation = null;

            try
            {
                _logger.AddDebug($"Creating simulation based on old building blocks for '{simulation.Name}'");
                otherSimulation = await createNewSimulationBasedOn(simulation, project);

                await runSimulation(simulation);

                await exportSimulationResultsToCSV(newDirectory, project.Name, otherSimulation, "new from old bb");

                await exportSimulationToPkml(pkmlNewDirectory, project.Name, simulation);
            }
            finally
            {
                _executionContext.Unregister(otherSimulation);
            }

            return(true);
        }
        private void renameContainerBuildingBlockInSimulation(Simulation simulation, IPKSimBuildingBlock templateBuildingBlock)
        {
            _lazyLoadTask.Load(simulation);
            var usedBuildingBlock = simulation.UsedBuildingBlockByTemplateId(templateBuildingBlock.Id);

            foreach (var containerToRename in getContainersToRename(simulation, templateBuildingBlock, usedBuildingBlock.BuildingBlock.Name))
            {
                containerToRename.Name = _containerTask.CreateUniqueName(containerToRename.ParentContainer, templateBuildingBlock.Name, canUseBaseName: true);

                //now some parameters in the simulation might reference parameters defined in the container that was renamed. We need to update
                //the formula paths of these parameters
                renameFormulaPathReferencingContainerInSimulation(simulation, containerToRename, usedBuildingBlock.BuildingBlock.Name);

                //make sure we mark the simulation has changed so that it will be saved
                simulation.HasChanged = true;
            }
        }
        public async Task <SimulationMapping> ExportSimulation(Simulation simulation, ExportRunOptions exportRunOptions, PKSimProject project)
        {
            var projectName      = project.Name;
            var simulationName   = simulation.Name;
            var simulationFile   = FileHelper.RemoveIllegalCharactersFrom(simulationName);
            var simulationFolder = Path.Combine(exportRunOptions.OutputFolder, simulationFile);

            DirectoryHelper.CreateDirectory(simulationFolder);

            var simulationExport = new SimulationMapping
            {
                Project        = projectName,
                Path           = simulationFolder,
                Simulation     = simulationName,
                SimulationFile = simulationFile
            };

            var simulationRunOptions = new SimulationRunOptions();

            _lazyLoadTask.Load(simulation);
            _lazyLoadTask.LoadResults(simulation);

            var simulationExportOptions = new SimulationExportOptions
            {
                OutputFolder = simulationFolder,
                ExportMode   = exportRunOptions.ExportMode,
                ProjectName  = projectName,
            };

            if (exportRunOptions.RunSimulation)
            {
                await _simulationExporter.RunAndExport(simulation, simulationRunOptions, simulationExportOptions);
            }

            else
            {
                await _simulationExporter.Export(simulation, simulationExportOptions);
            }

            _logger.AddDebug($"Simulation '{simulationName}' exported to '{simulationFolder}'", projectName);
            return(simulationExport);
        }
Example #8
0
 public void Load(ILazyLoadable lazyLoadable)
 {
     _lazyLoadTask.Load(lazyLoadable);
 }
Example #9
0
 public Task ExportSimulationToCppAsync(Simulation simulation, string outputFolder)
 {
     _lazyLoadTask.Load(simulation);
     return(Task.Run(() => _simModelExporter.ExportCppCode(_coreSimulationMapper.MapFrom(simulation, shouldCloneModel: false), outputFolder, FormulaExportMode.Formula)));
 }