Exemplo n.º 1
0
        private async Task startJsonSimulationRun(JsonRunOptions runOptions)
        {
            var inputFolder  = runOptions.InputFolder;
            var outputFolder = runOptions.OutputFolder;
            var exportMode   = runOptions.ExportMode;

            clear();

            var inputDirectory = new DirectoryInfo(inputFolder);

            if (!inputDirectory.Exists)
            {
                throw new OSPSuiteException($"Input folder '{inputFolder}' does not exist");
            }

            var allSnapshsotFiles = inputDirectory.GetFiles(Constants.Filter.JSON_FILTER);

            if (allSnapshsotFiles.Length == 0)
            {
                throw new OSPSuiteException($"No snapshot file found in '{inputFolder}'");
            }

            var outputDirectory = new DirectoryInfo(outputFolder);

            if (!outputDirectory.Exists)
            {
                _logger.AddDebug($"Creating folder '{outputFolder}'");
                outputDirectory.Create();
            }

            var allExistingFiles = outputDirectory.GetFiles("*.csv");

            allExistingFiles.Each(outputFile =>
            {
                FileHelper.DeleteFile(outputFile.FullName);
                _logger.AddDebug($"Deleting file '{outputFile.FullName}'");
            });

            var begin = DateTime.UtcNow;

            _logger.AddInfo($"Found {allSnapshsotFiles.Length} files in '{inputFolder}'");

            foreach (var snapshotFile in allSnapshsotFiles)
            {
                await runAndExportSimulationsInSnapshotFile(snapshotFile, outputFolder, exportMode)
                .ConfigureAwait(false);
            }

            var end       = DateTime.UtcNow;
            var timeSpent = end - begin;

            _logger.AddInfo($"{_allSimulationNames.Count} simulations calculated and exported in '{timeSpent.ToDisplay()}'");

            createSummaryFilesIn(outputDirectory, exportMode);
        }
Exemplo n.º 2
0
        public override async Task <ModelSimulation> MapToModel(SnapshotSimulation snapshot, PKSimProject project)
        {
            _logger.AddDebug(PKSimConstants.Information.LoadingSimulation(snapshot.Name), project.Name);

            var simulation = await createSimulationFrom(snapshot, project);

            simulation.Solver = await _solverSettingsMapper.MapToModel(snapshot.Solver);

            simulation.OutputSchema = await _outputSchemaMapper.MapToModel(snapshot.OutputSchema);

            simulation.OutputSelections = await _outputSelectionsMapper.MapToModel(snapshot.OutputSelections, simulation);

            await updateParameters(simulation, snapshot.Parameters);
            await updateAdvancedParameters(simulation, snapshot.AdvancedParameters);

            updateUsedObservedData(simulation, snapshot.ObservedData, project);

            await runSimulation(snapshot, simulation);

            simulation.AddAnalyses(await individualAnalysesFrom(simulation, snapshot.IndividualAnalyses, project));
            simulation.AddAnalyses(await populationAnalysesFrom(simulation, snapshot.PopulationAnalyses, project));

            _simulationParameterOriginIdUpdater.UpdateSimulationId(simulation);
            return(simulation);
        }
Exemplo n.º 3
0
        private async Task exportProject(ExportRunOptions runOptions)
        {
            var projectFile = runOptions.ProjectFile;

            if (!FileHelper.FileExists(projectFile))
            {
                throw new OSPSuiteException($"Project file '{projectFile}' does not exist.");
            }

            DirectoryHelper.CreateDirectory(runOptions.OutputFolder);

            _logger.AddInfo($"Starting project export for '{projectFile}'");

            _workspacePersistor.LoadSession(_workspace, projectFile);
            _logger.AddDebug($"Project loaded successfully from '{projectFile}'");

            await ExportSimulationsIn(_workspace.Project, runOptions);

            _logger.AddInfo($"Project export for '{projectFile}' terminated");
        }
Exemplo n.º 4
0
        public async Task RunAndExport(Simulation simulation, string outputFolder, SimulationRunOptions simulationRunOptions, SimulationExportMode simulationExportMode, string projectName = null)
        {
            _logger.AddDebug($"Running simulation '{simulation.Name}'");
            await _simulationRunner.RunSimulation(simulation, simulationRunOptions);

            await Export(simulation, outputFolder, simulationExportMode, projectName);
        }
Exemplo n.º 5
0
        public async Task RunAsync(QualificationPlan qualificationPlan)
        {
            _logger.AddDebug(PKSimConstants.Information.StartingQualificationPlan(qualificationPlan.Name));

            //this needs to be run in order. Await EACH run
            foreach (var qualificationStep in qualificationPlan.Steps)
            {
                using (var runner = _qualificationStepRunnerFactory.CreateFor(qualificationStep))
                {
                    await runner.RunAsync(qualificationStep);
                }
            }
        }
Exemplo n.º 6
0
        public override async Task <ModelProject> MapToModel(SnapshotProject snapshot)
        {
            _logger.AddDebug($"Loading project '{snapshot.Name}' from snapshot...", snapshot.Name);

            var project = new ModelProject
            {
                Name        = snapshot.Name,
                Description = snapshot.Description,
                Creation    = _creationMetaDataFactory.Create()
            };

            project.Creation.InternalVersion = snapshot.Version;
            project.Creation.Version         = ProjectVersions.FindBy(snapshot.Version)?.VersionDisplay;

            var buildingBlocks = await allBuidingBlocksFrom(snapshot);

            buildingBlocks?.Each(project.AddBuildingBlock);

            var observedData = await observedDataFrom(snapshot.ObservedData);

            observedData?.Each(repository => addObservedDataToProject(project, repository));

            var allSimulations = await allSimulationsFrom(snapshot.Simulations, project);

            allSimulations?.Each(simulation => addSimulationToProject(project, simulation));

            var allSimulationComparisons = await allSimulationComparisonsFrom(snapshot.SimulationComparisons, project);

            allSimulationComparisons?.Each(comparison => addComparisonToProject(project, comparison));

            var allParameterIdentifications = await allParameterIdentificationsFrom(snapshot.ParameterIdentifications, project);

            allParameterIdentifications?.Each(parameterIdentification => addParameterIdentificationToProject(project, parameterIdentification));

            var allQualificationPlans = await allQualificationPlansFrom(snapshot.QualificationPlans, project);

            allQualificationPlans?.Each(qualificationPlan => addQualificationPlanToProject(project, qualificationPlan));

            //Map all classifications once project is loaded
            await updateProjectClassifications(snapshot, project);

            return(project);
        }
Exemplo n.º 7
0
        public override async Task <ModelSimulation> MapToModel(SnapshotSimulation snapshot, PKSimProject project)
        {
            _logger.AddDebug(PKSimConstants.Information.LoadingSimulation(snapshot.Name), project.Name);

            //Local cache of ids' that will be used to retrieve original building block parameters as the project is only registered
            //in global context once the whole snapshot mapping process is completed

            var withIdRepository    = new WithIdRepository();
            var registrationVisitor = new RegisterObjectVisitor(withIdRepository);

            var simulation = await createSimulationFrom(snapshot, project);

            simulation.Solver = await _solverSettingsMapper.MapToModel(snapshot.Solver);

            simulation.OutputSchema = await _outputSchemaMapper.MapToModel(snapshot.OutputSchema);

            simulation.OutputSelections = await _outputSelectionsMapper.MapToModel(snapshot.OutputSelections, simulation);

            registrationVisitor.Register(simulation);

            await updateParameters(simulation, snapshot.Parameters, withIdRepository);

            await updateAdvancedParameters(simulation, snapshot.AdvancedParameters);

            updateUsedObservedData(simulation, snapshot.ObservedData, project);

            updateAlteredBuildingBlock(simulation, snapshot.AlteredBuildingBlocks);

            await runSimulation(snapshot, simulation);

            simulation.AddAnalyses(await individualAnalysesFrom(simulation, snapshot.IndividualAnalyses, project));
            simulation.AddAnalyses(await populationAnalysesFrom(simulation, snapshot.PopulationAnalyses, project));

            _simulationParameterOriginIdUpdater.UpdateSimulationId(simulation);
            return(simulation);
        }
Exemplo n.º 8
0
        public async Task RunBatchAsync(QualificationRunOptions runOptions)
        {
            _runOptions = runOptions;

            if (!FileHelper.FileExists(runOptions.ConfigurationFile))
            {
                throw new QualificationRunException(ConfigurationFileNotFound(runOptions.ConfigurationFile));
            }

            setupOutputFolder();

            dynamic qualificationPlan = await _jsonSerializer.Deserialize <dynamic>(runOptions.ConfigurationFile);

            IReadOnlyList <Project> projects = GetListFrom <Project>(qualificationPlan.Projects);

            if (projects == null)
            {
                throw new QualificationRunException(ProjectsNotDefinedInQualificationFile);
            }

            IReadOnlyList <SimulationPlot> allPlots  = retrieveProjectPlots(qualificationPlan);
            IReadOnlyList <Input>          allInputs = retrieveInputs(qualificationPlan);

            var begin = DateTime.UtcNow;

            await updateProjectsFullPath(projects);

            //Configurations only need to be created once!
            var projectConfigurations = await Task.WhenAll(projects.Select(p => createQualifcationConfigurationFor(p, projects, allPlots, allInputs)));

            _logger.AddDebug("Copying static files");
            StaticFiles staticFiles = await copyStaticFiles(qualificationPlan);

            _logger.AddInfo("Starting validation runs...");
            var validations = await Task.WhenAll(projectConfigurations.Select(validateProject));

            var invalidConfigurations = validations.Where(x => !x.Success).ToList();

            if (invalidConfigurations.Any())
            {
                throw new QualificationRunException(errorMessageFrom(invalidConfigurations));
            }

            //Run all qualification projects
            _logger.AddInfo("Starting qualification runs...");
            var runResults = await Task.WhenAll(projectConfigurations.Select(runQualification));

            var invalidRunResults = runResults.Where(x => !x.Success).ToList();

            if (invalidRunResults.Any())
            {
                throw new QualificationRunException(errorMessageFrom(invalidRunResults));
            }

            await createReportConfigurationPlan(runResults, staticFiles, qualificationPlan);

            var end       = DateTime.UtcNow;
            var timeSpent = end - begin;

            _logger.AddInfo($"Qualification scenario finished in {timeSpent.ToDisplay()}");
        }
Exemplo n.º 9
0
        public async Task RunBatchAsync(QualificationRunOptions runOptions)
        {
            _snapshotProjectCache.Clear();
            _logger.AddInfo(runOptions.Validate ? "Starting validation run..." : "Starting qualification run...");

            var config = await readConfigurationFrom(runOptions);

            if (config == null)
            {
                throw new QualificationRunException(UnableToLoadQualificationConfigurationFromFile(runOptions.ConfigurationFile));
            }

            var errorMessage = config.Validate().Message;

            if (!string.IsNullOrEmpty(errorMessage))
            {
                throw new QualificationRunException(errorMessage);
            }

            _logger.AddDebug($"Loading project from snapshot file '{config.SnapshotFile}'...");
            var snapshot = await snapshotProjectFromFile(config.SnapshotFile);

            //Ensures that the name of the snapshot is also the name of the project as defined in the configuration
            snapshot.Name = config.Project;
            _logger.AddDebug($"Project {snapshot.Name} loaded from snapshot file '{config.SnapshotFile}'.");

            await performBuildingBlockSwap(snapshot, config.BuildingBlocks);

            await performSimulationParameterSwap(snapshot, config.SimulationParameters);

            //Retrieve charts and validate inputs before exiting validation to ensure that we can throw error messages if an element is not available
            var plots = retrievePlotDefinitionsFrom(snapshot, config);

            validateInputs(snapshot, config);

            if (runOptions.Validate)
            {
                _logger.AddInfo($"Validation run terminated for {snapshot.Name}");
                return;
            }

            var begin   = DateTime.UtcNow;
            var project = await _snapshotTask.LoadProjectFromSnapshot(snapshot);

            _workspace.Project = project;

            var projectOutputFolder = createProjectOutputFolder(config.OutputFolder, project.Name);

            _logger.AddDebug($"Exporting project {project.Name} to '{projectOutputFolder}'", project.Name);

            var exportRunOptions = new ExportRunOptions
            {
                OutputFolder = projectOutputFolder,
                ExportMode   = SimulationExportMode.Xml | SimulationExportMode.Csv
            };

            var simulationExports = await _exportSimulationRunner.ExportSimulationsIn(project, exportRunOptions);

            var simulationMappings = simulationExports.Select(x => simulationMappingFrom(x, config)).ToArray();

            var observedDataMappings = await exportAllObservedData(project, config);

            var inputMappings = exportInputs(project, config);

            var mapping = new QualificationMapping
            {
                SimulationMappings   = simulationMappings,
                ObservedDataMappings = observedDataMappings,
                Plots  = plots,
                Inputs = inputMappings
            };

            await _jsonSerializer.Serialize(mapping, config.MappingFile);

            _logger.AddDebug($"Project mapping for '{project.Name}' exported to '{config.MappingFile}'", project.Name);

            var projectFile = Path.Combine(config.TempFolder, $"{project.Name}{CoreConstants.Filter.PROJECT_EXTENSION}");

            _workspacePersistor.SaveSession(_workspace, projectFile);
            _logger.AddDebug($"Project saved to '{projectFile}'", project.Name);

            var snapshotFile = Path.Combine(config.TempFolder, $"{project.Name}{Constants.Filter.JSON_EXTENSION}");
            await _snapshotTask.ExportModelToSnapshot(project, snapshotFile);

            _logger.AddDebug($"Project snapshot saved to '{snapshotFile}'", project.Name);

            var end       = DateTime.UtcNow;
            var timeSpent = end - begin;

            _logger.AddInfo($"Project '{project.Name}' exported for qualification in {timeSpent.ToDisplay()}", project.Name);
        }
Exemplo n.º 10
0
 public async Task RunAsync(IQualificationStep qualificationStep)
 {
     _logger.AddDebug(PKSimConstants.Information.StartingQualificationStep(qualificationStep.Display));
     await RunAsync(qualificationStep.DowncastTo <T>());
 }