Skip to content

Commit b962405

Browse files
Jim review modifications
Fixes include logging, raising plot-pixel accurate thresholds, making code more convenient and/or easier to read / conceptualize (plus some improvements!).
1 parent fd62111 commit b962405

20 files changed

Lines changed: 358 additions & 239 deletions

File tree

vcell-cli/src/main/java/org/vcell/cli/run/ExecutionJob.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public void executeArchive(boolean isBioSimSedml) throws BiosimulationsHdfWriter
141141

142142
private void executeSedmlDocument(String sedmlLocation, HDF5ExecutionResults cumulativeHdf5Results) throws IOException, PreProcessingException, ExecutionException {
143143
BiosimulationLog.instance().updateSedmlDocStatusYml(sedmlLocation, BiosimulationLog.Status.QUEUED);
144-
SedmlJob job = new SedmlJob(sedmlLocation, this.omexHandler, this.inputFile, this.outputDir, this.sedmlPath2d3d.toString(), this.cliRecorder, this.bKeepTempFiles, this.bExactMatchOnly, this.bSmallMeshOverride);
144+
SedMLJob job = new SedMLJob(sedmlLocation, this.omexHandler, this.inputFile, this.outputDir, this.sedmlPath2d3d.toString(), this.cliRecorder, this.bKeepTempFiles, this.bExactMatchOnly, this.bSmallMeshOverride);
145145
this.logOmexMessage.append("Processing ").append(job.SEDML_NAME).append(". ");
146146
SedmlStatistics stats = job.preProcessDoc();
147147
boolean hasSucceeded = job.simulateSedml(cumulativeHdf5Results);

vcell-cli/src/main/java/org/vcell/cli/run/RunUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ public static HashMap<SId, File> generateReportsAsCSV(SedMLDataContainer sedmlCo
179179
List<DataSet> datasets = sedmlReport.getDataSets();
180180
Map<DataSet, DataGenerator> dataGeneratorMapping = new LinkedHashMap<>();
181181
for (DataSet dataset : datasets) {
182-
SedBase maybeDataGenerator = sedML.searchInDataGeneratorsFor(dataset.getDataReference());
183-
if (!(maybeDataGenerator instanceof DataGenerator referencedGenerator)) throw new RuntimeException("SedML DataGenerator referenced by report is missing!");
182+
DataGenerator referencedGenerator = sedmlContainer.findDataGeneratorById(dataset.getDataReference());
183+
if (null == referencedGenerator) throw new IllegalArgumentException("Unable to find data generator referenced in dataset: " + dataset.getDataReference());
184184
if (!organizedNonSpatialResults.containsKey(referencedGenerator)) break;
185185
dataGeneratorMapping.put(dataset, referencedGenerator);
186186
}

vcell-cli/src/main/java/org/vcell/cli/run/SedmlJob.java renamed to vcell-cli/src/main/java/org/vcell/cli/run/SedMLJob.java

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.vcell.cli.run;
22

3-
import cbit.vcell.biomodel.BioModel;
43
import cbit.vcell.resource.OperatingSystemInfo;
54
import cbit.vcell.xml.ExternalDocInfo;
65
import org.apache.commons.io.FilenameUtils;
@@ -32,7 +31,6 @@
3231
import org.vcell.cli.run.plotting.PlottingDataExtractor;
3332
import org.vcell.cli.run.plotting.ChartCouldNotBeProducedException;
3433
import org.vcell.cli.run.plotting.Results2DLinePlot;
35-
import org.vcell.sbml.vcell.SBMLSymbolMapping;
3634
import org.vcell.sbml.vcell.lazy.LazySBMLNonSpatialDataAccessor;
3735
import org.vcell.sbml.vcell.lazy.LazySBMLSpatialDataAccessor;
3836
import org.vcell.sedml.log.BiosimulationLog;
@@ -53,8 +51,8 @@
5351
/**
5452
* Class that deals with the processing quest of a sedml file.
5553
*/
56-
public class SedmlJob {
57-
private final static Logger logger = LogManager.getLogger(SedmlJob.class);
54+
public class SedMLJob {
55+
private final static Logger logger = LogManager.getLogger(SedMLJob.class);
5856

5957
private final boolean SHOULD_KEEP_TEMP_FILES,
6058
ACCEPT_EXACT_MATCH_ONLY, SHOULD_OVERRIDE_FOR_SMALL_MESH;
@@ -83,7 +81,7 @@ public class SedmlJob {
8381
* @param bExactMatchOnly enforces a KISAO match, with no substitution
8482
* @param bSmallMeshOverride whether to use small meshes or standard meshes.
8583
*/
86-
public SedmlJob(String sedmlLocation, OmexHandler omexHandler, File masterOmexArchive,
84+
public SedMLJob(String sedmlLocation, OmexHandler omexHandler, File masterOmexArchive,
8785
String resultsDirPath, String pathToPlotsDirectory, CLIRecordable cliRecorder,
8886
boolean bKeepTempFiles, boolean bExactMatchOnly, boolean bSmallMeshOverride){
8987
final String SAFE_WINDOWS_FILE_SEPARATOR = "\\\\";
@@ -127,13 +125,13 @@ public SedmlStatistics preProcessDoc() throws IOException, PreProcessingExceptio
127125
logger.info("Initializing and Pre-Processing SedML document: {}", this.SEDML_NAME);
128126
biosimLog.updateSedmlDocStatusYml(this.SEDML_LOCATION, BiosimulationLog.Status.RUNNING);
129127
try {
130-
this.sedml = SedmlJob.getSedMLFile(this.SEDML_NAME_SPLIT, this.MASTER_OMEX_ARCHIVE);
128+
this.sedml = SedMLJob.getSedMLFile(this.SEDML_NAME_SPLIT, this.MASTER_OMEX_ARCHIVE);
131129
} catch (Exception e) {
132130
String prefix = "SedML pre-processing for " + this.SEDML_LOCATION + " failed";
133131
this.logDocumentError = prefix + ": " + e.getMessage();
134132
Tracer.failure(e, prefix);
135133
this.reportProblem(e);
136-
this.somethingFailed = SedmlJob.somethingDidFail();
134+
this.somethingFailed = SedMLJob.somethingDidFail();
137135
biosimLog.updateSedmlDocStatusYml(this.SEDML_LOCATION, BiosimulationLog.Status.FAILED);
138136
span.close();
139137
throw new PreProcessingException(prefix, e);
@@ -191,8 +189,6 @@ public SedmlStatistics preProcessDoc() throws IOException, PreProcessingExceptio
191189
}
192190

193191

194-
} catch(Exception e){
195-
throw e;
196192
} finally {
197193
if (span != null) span.close();
198194
}
@@ -231,10 +227,10 @@ private void runSimulations(SolverHandler solverHandler) throws ExecutionExcepti
231227
RunUtils.drawBreakLine("-", 100);
232228
try {
233229
span = Tracer.startSpan(Span.ContextType.SIMULATIONS_RUN, "runSimulations", null);
234-
Pair<SedMLDataContainer, Map<BioModel, SBMLSymbolMapping>> initializedModelPair = solverHandler.initialize(externalDocInfo, this.sedml, this.ACCEPT_EXACT_MATCH_ONLY);
235-
if (!this.sedml.equals(initializedModelPair.one)){
230+
SolverHandler.Configuration initializedModelPair = solverHandler.initialize(externalDocInfo, this.sedml, this.ACCEPT_EXACT_MATCH_ONLY);
231+
if (!this.sedml.equals(initializedModelPair.postInitializedSedml())){
236232
logger.warn("Importer returned modified SedML to process; now using modified SedML");
237-
this.sedml = initializedModelPair.one;
233+
this.sedml = initializedModelPair.postInitializedSedml();
238234
}
239235
Map<AbstractTask, BiosimulationLog.Status> taskResults = solverHandler.simulateAllTasks(this.CLI_RECORDER,
240236
this.OUTPUT_DIRECTORY_FOR_CURRENT_SEDML, this.SEDML_LOCATION, this.SHOULD_KEEP_TEMP_FILES, this.SHOULD_OVERRIDE_FOR_SMALL_MESH);
@@ -398,7 +394,7 @@ private void indexHDF5Data(Map<DataGenerator, ValueHolder<LazySBMLNonSpatialData
398394

399395
// This method is a bit weird; it uses a temp file as a reference to compare against while getting the file straight from the archive.
400396
private static SedMLDataContainer getSedMLFile(String[] tokenizedPathToSedml, File inputFile) throws XMLException, IOException {
401-
Path convertedPath = SedmlJob.getRelativePath(tokenizedPathToSedml);
397+
Path convertedPath = SedMLJob.getRelativePath(tokenizedPathToSedml);
402398
if (convertedPath == null) throw new RuntimeException("Was not able to get relative path to " + inputFile.getName());
403399
String identifyingPath = FilenameUtils.separatorsToUnix(convertedPath.toString());
404400
try (FileInputStream omexStream = new FileInputStream(inputFile)) {

vcell-cli/src/main/java/org/vcell/cli/run/SolverHandler.java

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import cbit.vcell.xml.ExternalDocInfo;
2424

2525
import org.jlibsedml.components.SId;
26-
import org.jlibsedml.components.SedBase;
2726
import org.jlibsedml.components.SedML;
2827
import org.jlibsedml.components.task.AbstractTask;
2928
import org.jlibsedml.components.dataGenerator.DataGenerator;
@@ -39,7 +38,6 @@
3938
import org.jlibsedml.components.simulation.UniformTimeCourse;
4039
import org.jlibsedml.components.Variable;
4140
import org.jlibsedml.XPathTarget;
42-
import org.jlibsedml.XMLException;
4341
import org.jlibsedml.modelsupport.SBMLSupport;
4442

4543
import org.jmathml.ASTNode;
@@ -54,7 +52,6 @@
5452
import org.apache.commons.lang.NotImplementedException;
5553
import org.apache.logging.log4j.LogManager;
5654
import org.apache.logging.log4j.Logger;
57-
import org.vcell.util.Pair;
5855

5956
import java.beans.PropertyVetoException;
6057
import java.io.*;
@@ -102,18 +99,22 @@ private static void sanityCheck(BioModel bioModel) throws SEDMLImportException {
10299
}
103100
}
104101

105-
public Pair<SedMLDataContainer, Map<BioModel, SBMLSymbolMapping>> initialize(ExternalDocInfo externalDocInfo, SedMLDataContainer providedSedmlContainer, boolean disallowModifiedImport)
102+
public Configuration initialize(ExternalDocInfo externalDocInfo, SedMLDataContainer initialSedmlContainer, boolean exactMatchOnly)
106103
throws ExpressionException, SEDMLImportException {
107104
cbit.util.xml.VCLogger sedmlImportLogger = new LocalLogger();
108105

109106
//String outDirRoot = outputDirForSedml.toString().substring(0, outputDirForSedml.toString().lastIndexOf(System.getProperty("file.separator")));
110107
SedMLDataContainer actionableSedmlContainer;
111108
Map<BioModel, SBMLSymbolMapping> bioModelMapping;
112-
SedMLImporter sedmlImporter = new SedMLImporter(sedmlImportLogger, disallowModifiedImport);
109+
SedMLImporter sedmlImporter = new SedMLImporter(sedmlImportLogger, new SedMLImporter.StrictnessPolicy(
110+
true,
111+
SedMLImporter.StrictnessPolicy.MultipleSubTaskPolicy.CONDENSE_ELSE_REMOVE,
112+
exactMatchOnly ? SedMLImporter.StrictnessPolicy.SolverMatchPolicy.STRICT_MATCH_OR_REJECT : SedMLImporter.StrictnessPolicy.SolverMatchPolicy.SUNDIALS_AS_LAST_RESORT
113+
));
113114
this.modelReportingName = org.vcell.util.FileUtils.getBaseName(externalDocInfo.getFile().getAbsolutePath());
114115

115116
try {
116-
actionableSedmlContainer = sedmlImporter.initialize(externalDocInfo.getFile(), providedSedmlContainer);
117+
actionableSedmlContainer = sedmlImporter.initialize(externalDocInfo.getFile(), initialSedmlContainer);
117118
} catch (Exception e) {
118119
String errMessage = "Unable to prepare SED-ML for conversion into BioModel(s)";
119120
String formattedError = String.format("%s, failed with error: %s", errMessage, e.getMessage());
@@ -131,7 +132,7 @@ public Pair<SedMLDataContainer, Map<BioModel, SBMLSymbolMapping>> initialize(Ext
131132

132133
this.countBioModels = bioModelMapping.size();
133134

134-
SedML sedML = providedSedmlContainer.getSedML();
135+
SedML sedML = initialSedmlContainer.getSedML();
135136
Set <AbstractTask> topmostTasks = new LinkedHashSet<> ();
136137
for(BioModel bioModel : bioModelMapping.keySet()) {
137138
Simulation[] sims = bioModel.getSimulations();
@@ -141,8 +142,8 @@ public Pair<SedMLDataContainer, Map<BioModel, SBMLSymbolMapping>> initialize(Ext
141142
}
142143
TempSimulation tempSimulation = new TempSimulation(sim,false);
143144
String importedTaskId = tempSimulation.getImportedTaskID();
144-
SedBase foundElement = sedML.searchInTasksFor(new SId(importedTaskId));
145-
if (!(foundElement instanceof AbstractTask abstractTask)) throw new RuntimeException("Imported task id " + importedTaskId + " is not an AbstractTask.");
145+
AbstractTask abstractTask = initialSedmlContainer.findAbstractTaskById(new SId(importedTaskId));
146+
if (null == abstractTask) throw new RuntimeException("Imported task id " + importedTaskId + " is not an AbstractTask.");
146147
this.tempSimulationToTaskMap.put(tempSimulation, abstractTask);
147148
this.taskToTempSimulationMap.put(abstractTask, tempSimulation);
148149
this.origSimulationToTempSimulationMap.put(sim, tempSimulation);
@@ -156,8 +157,8 @@ public Pair<SedMLDataContainer, Map<BioModel, SBMLSymbolMapping>> initialize(Ext
156157
for(AbstractTask at : sedML.getTasks()) {
157158
if(!(at instanceof RepeatedTask rt)) continue;
158159
for (SubTask entry : rt.getSubTasks()) {
159-
SedBase foundElement = sedML.searchInTasksFor(entry.getTask());
160-
if (!(foundElement instanceof AbstractTask subTaskTarget)) throw new RuntimeException("Subtask (id=" + entry.getId().string() + " ) does not reference an AbstractTask.");
160+
AbstractTask subTaskTarget = initialSedmlContainer.findAbstractTaskById(entry.getTask());
161+
if (null == subTaskTarget) throw new RuntimeException("Subtask (id=" + entry.getId().string() + " ) does not reference an AbstractTask.");
161162
subTasks.add(subTaskTarget);
162163
}
163164
}
@@ -177,8 +178,8 @@ public Pair<SedMLDataContainer, Map<BioModel, SBMLSymbolMapping>> initialize(Ext
177178
List<AbstractTask> subTasksList = new ArrayList<> ();
178179
Task baseTask;
179180
if(abstractTask instanceof RepeatedTask repeatedTask) {
180-
subTasksList.addAll(providedSedmlContainer.getActualSubTasks(repeatedTask.getId()));
181-
baseTask = providedSedmlContainer.getBaseTask(repeatedTask.getId());
181+
subTasksList.addAll(initialSedmlContainer.getActualSubTasks(repeatedTask.getId()));
182+
baseTask = initialSedmlContainer.getBaseTask(repeatedTask.getId());
182183
if (baseTask == null) throw new RuntimeException("Unable to find base task of repeated task: " + repeatedTask.getId().string() + ".");
183184
} else if (abstractTask instanceof Task task) {
184185
baseTask = task;
@@ -204,11 +205,11 @@ public Pair<SedMLDataContainer, Map<BioModel, SBMLSymbolMapping>> initialize(Ext
204205
// variable id is constructed based on the task id
205206
List<DataSet> datasets = rep.getDataSets();
206207
for (DataSet dataset : datasets) {
207-
SedBase foundDataGen = sedML.searchInDataGeneratorsFor(dataset.getDataReference());
208-
if (!(foundDataGen instanceof DataGenerator dataGen)) throw new IllegalArgumentException("Unable to find data generator referenced in dataset: " + dataset.getDataReference());
208+
DataGenerator dataGen = initialSedmlContainer.findDataGeneratorById(dataset.getDataReference());
209+
if (null == dataGen) throw new IllegalArgumentException("Unable to find data generator referenced in dataset: " + dataset.getDataReference());
209210
for(Variable var : dataGen.getVariables()) {
210-
SedBase foundAbstractTask = sedML.searchInTasksFor(var.getTaskReference());
211-
if (!(foundAbstractTask instanceof AbstractTask task)) throw new IllegalArgumentException("Unable to find task referenced by variable: " + var.getTaskReference());
211+
AbstractTask task = initialSedmlContainer.findAbstractTaskById(var.getTaskReference());
212+
if (null == task) throw new IllegalArgumentException("Unable to find task referenced by variable: " + var.getTaskReference());
212213
variableToTaskMap.put(var, task);
213214
}
214215
}
@@ -269,7 +270,7 @@ public Pair<SedMLDataContainer, Map<BioModel, SBMLSymbolMapping>> initialize(Ext
269270
logger.info("Initialization Statistics:\n\t> taskToSimulationMap: {}\n\t> taskToListOfSubTasksMap: {}\n\t> taskToVariableMap: {}\n\t> topTaskToBaseTask: {}\n",
270271
this.taskToTempSimulationMap.size(), this.taskToListOfSubTasksMap.size(), this.taskToVariableMap.size(), this.topTaskToBaseTask.size());
271272
}
272-
return new Pair<>(this.initializedSedMLContainer = actionableSedmlContainer, this.bioModelToSBMLMapping = bioModelMapping);
273+
return new Configuration(this.initializedSedMLContainer = actionableSedmlContainer, this.bioModelToSBMLMapping = bioModelMapping);
273274
}
274275

275276
private static class TempSimulationJob extends SimulationJob {
@@ -385,10 +386,9 @@ public Map<AbstractTask, BiosimulationLog.Status> simulateAllTasks(CLIRecordable
385386
// must interpolate data for uniform time course which is not supported natively by the Java solvers
386387
Task baseTask = this.initializedSedMLContainer.getBaseTask(task.getId());
387388
if (baseTask == null) throw new RuntimeException("Unable to find base task");
388-
SedBase elementFound = this.initializedSedMLContainer.getSedML().searchInSimulationsFor(baseTask.getSimulationReference());
389-
if (!(elementFound instanceof org.jlibsedml.components.simulation.Simulation sedmlSim))
390-
throw new RuntimeException("Unable to find simulation for base task");
391-
if (sedmlSim instanceof UniformTimeCourse utcSedmlSim) {
389+
org.jlibsedml.components.simulation.Simulation sedmlSim = this.initializedSedMLContainer.findSimulationById(baseTask.getSimulationReference());
390+
if (null == sedmlSim) throw new RuntimeException("Unable to find simulation for base task");
391+
if (sedmlSim instanceof UniformTimeCourse utcSedmlSim) {
392392
odeSolverResultSet = RunUtils.interpolate(odeSolverResultSet, utcSedmlSim);
393393
logTaskMessage += "done. Interpolating... ";
394394
}
@@ -737,5 +737,7 @@ public static void main(String[] args) throws Exception {
737737
738738
*/
739739
}
740+
741+
public record Configuration(SedMLDataContainer postInitializedSedml, Map<BioModel, SBMLSymbolMapping> bioModelsToSymbolMappings){}
740742
}
741743

0 commit comments

Comments
 (0)