Skip to content

Commit

Permalink
[WIP] Returning solver handler results for recording
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeByDrescher committed Nov 19, 2024
1 parent f35690b commit 5b3d266
Show file tree
Hide file tree
Showing 10 changed files with 166 additions and 70 deletions.
14 changes: 8 additions & 6 deletions vcell-cli/src/main/java/org/vcell/cli/CLIRecordable.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@

public interface CLIRecordable {

public void writeDetailedErrorList(String message) throws IOException;
void writeDetailedErrorList(String message) throws IOException;

public void writeFullSuccessList(String message) throws IOException;
void writeFullSuccessList(String message) throws IOException;

public void writeErrorList(String message) throws IOException;
void writeErrorList(String message) throws IOException;

public void writeDetailedResultList(String message) throws IOException;
void writeDetailedResultList(String message) throws IOException;

void writeDetailedSimBreakdown(String message) throws IOException;

// we make a list with the omex files that contain (some) spatial simulations (FVSolverStandalone solver)
public void writeSpatialList(String message) throws IOException;
void writeSpatialList(String message) throws IOException;

public void writeImportErrorList(String message) throws IOException;
void writeImportErrorList(String message) throws IOException;
}
12 changes: 11 additions & 1 deletion vcell-cli/src/main/java/org/vcell/cli/CLIRecorder.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
public class CLIRecorder extends Recorder implements CLIRecordable {
protected final static boolean DEFAULT_SHOULD_PRINT_LOG_FILES = false, DEFAULT_SHOULD_FLUSH_LOG_FILES = false;
protected boolean shouldPrintLogFiles, shouldFlushLogFiles;
protected TextFileRecord detailedErrorLog, fullSuccessLog, errorLog, detailedResultsLog, spatialLog, importErrorLog;
protected TextFileRecord detailedErrorLog, fullSuccessLog, errorLog, detailedResultsLog, detailedSimBreakdown, spatialLog, importErrorLog;
protected File outputDirectory;

// Note: this constructor is not public
Expand Down Expand Up @@ -86,6 +86,7 @@ public CLIRecorder(File outputDirectory, boolean forceLogFiles, boolean shouldFl
this.fullSuccessLog = logManager.requestNewRecord(Paths.get(this.outputDirectory.getAbsolutePath(), "fullSuccessLog.txt").toString());
this.errorLog = logManager.requestNewRecord(Paths.get(this.outputDirectory.getAbsolutePath(), "errorLog.txt").toString());
this.detailedResultsLog = logManager.requestNewRecord(Paths.get(this.outputDirectory.getAbsolutePath(), "detailedResultLog.txt").toString());
this.detailedSimBreakdown = logManager.requestNewRecord(Paths.get(this.outputDirectory.getAbsolutePath(), "detailedSimBreakdown.txt").toString());
this.spatialLog = logManager.requestNewRecord(Paths.get(this.outputDirectory.getAbsolutePath(), "hasSpatialLog.txt").toString());
this.importErrorLog = logManager.requestNewRecord(Paths.get(this.outputDirectory.getAbsolutePath(), "importErrorLog.txt").toString());

Expand Down Expand Up @@ -152,6 +153,15 @@ public void writeDetailedResultList(String message) throws IOException {
this.writeToFileLog(this.detailedResultsLog, message);
}

/**
* Write to `detailedSimBreakdown.txt`
*
* @param message string to write to file
*/
public void writeDetailedSimBreakdown(String message) throws IOException {
this.writeToFileLog(this.detailedSimBreakdown, message);
}


/**
* Write to `hasSpatialLog.txt`
Expand Down
4 changes: 2 additions & 2 deletions vcell-cli/src/main/java/org/vcell/cli/run/ExecuteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import java.util.concurrent.Callable;
import java.util.Date;

@Command(name = "execute", description = "run .vcml or .omex files via Python API")
@Command(name = "execute", description = "run .vcml or .omex files")
public class ExecuteCommand implements Callable<Integer> {

private final static Logger logger = org.apache.logging.log4j.LogManager.getLogger(ExecuteCommand.class);
Expand Down Expand Up @@ -100,7 +100,7 @@ public Integer call() {
bKeepTempFiles, bExactMatchOnly, bEncapsulateOutput,
EXECUTABLE_MAX_WALLCLOCK_MILLIS, help, bDebug, bQuiet
);
logger.trace(trace_args);
logger.debug(trace_args);

logger.debug("Validating CLI arguments");
if (bDebug && bQuiet) {
Expand Down
2 changes: 1 addition & 1 deletion vcell-cli/src/main/java/org/vcell/cli/run/ExecuteImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static void batchMode(File dirOfArchivesToProcess, File outputDir, CLIRec

logger.info("Preparing output directory...");
// we don't want to accidentally delete the input...
// if the output is a subset of the input file's housing directory, we shouldn't delete!!
// if the output directory is a subset of the input file's housing directory, we shouldn't delete!!
if (!inputFile.getParentFile().getCanonicalPath().contains(adjustedOutputDir.getCanonicalPath()))
RunUtils.removeAndMakeDirs(adjustedOutputDir);
try {
Expand Down
67 changes: 67 additions & 0 deletions vcell-cli/src/main/java/org/vcell/cli/run/RunResults.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package org.vcell.cli.run;

import cbit.vcell.biomodel.BioModel;
import cbit.vcell.solver.TempSimulation;
import org.vcell.util.Pair;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class RunResults {
private final Map<BioModel, List<TempSimulation>> bioModelToListOfTemp;
private final Map<TempSimulation, Pair<Status, Integer>> tempSimulationToStatus;

public RunResults() {
this.bioModelToListOfTemp = new HashMap<>();
this.tempSimulationToStatus = new HashMap<>();
}

public List<TempSimulation> getTempSimulations(BioModel bioModel) {
return this.bioModelToListOfTemp.get(bioModel);
}

public Pair<Status, Integer> getStatus(BioModel bioModel, TempSimulation tempSimulation) {
return this.bioModelToListOfTemp.containsKey(bioModel) ? null : tempSimulationToStatus.get(tempSimulation);
}

public void setStatus(BioModel bioModel, TempSimulation tempSimulation, Integer duration) {
this.setStatus(bioModel, tempSimulation, null, duration);
}

public void setStatus(BioModel bioModel, TempSimulation tempSimulation, Status status) {
this.setStatus(bioModel, tempSimulation, status, null);
}

public void setStatus(BioModel bioModel, TempSimulation tempSimulation, Status status, Integer duration){
if (!this.bioModelToListOfTemp.containsKey(bioModel)) this.bioModelToListOfTemp.put(bioModel, new ArrayList<>());
List<TempSimulation> relevantSims = this.bioModelToListOfTemp.get(bioModel);
if (!relevantSims.contains(tempSimulation)) this.bioModelToListOfTemp.get(bioModel).add(tempSimulation);
if (!this.tempSimulationToStatus.containsKey(tempSimulation)) {
this.tempSimulationToStatus.put(tempSimulation, new Pair<>(status, duration));
}
Pair<Status, Integer> previousStatuses = this.tempSimulationToStatus.get(tempSimulation);
if (status != null){
this.tempSimulationToStatus.put(tempSimulation, new Pair<>(status, previousStatuses.two));
previousStatuses = this.tempSimulationToStatus.get(tempSimulation);
}

if (duration != null){
this.tempSimulationToStatus.put(tempSimulation, new Pair<>(previousStatuses.one, duration));
}
}

public List<IndividualResult> generateRecordsOfResults(){
List<IndividualResult> results = new ArrayList<>();
for (BioModel bm : this.bioModelToListOfTemp.keySet()) {
for (TempSimulation ts : this.bioModelToListOfTemp.get(bm)) {
Pair<Status, Integer> statusAndDuration = this.tempSimulationToStatus.get(ts);
results.add(new IndividualResult(bm, ts, statusAndDuration.one, statusAndDuration.two));
}
}
return results;
}

public record IndividualResult(BioModel bioModel, TempSimulation tempSimulation, Status status, Integer duration) {}
}
41 changes: 25 additions & 16 deletions vcell-cli/src/main/java/org/vcell/cli/run/SedmlJob.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.vcell.cli.run;

import cbit.vcell.biomodel.BioModel;
import cbit.vcell.resource.OperatingSystemInfo;
import cbit.vcell.xml.ExternalDocInfo;
import org.apache.commons.io.FilenameUtils;
Expand Down Expand Up @@ -228,7 +229,6 @@ public boolean simulateSedml(HDF5ExecutionResults masterHdf5File) throws Interru
ExternalDocInfo externalDocInfo = new ExternalDocInfo(this.MASTER_OMEX_ARCHIVE, true);

this.runSimulations(solverHandler, externalDocInfo);
this.recordRunDetails(solverHandler);
Span span = null;
try {
span = Tracer.startSpan(Span.ContextType.PROCESSING_SIMULATION_OUTPUTS, "processOutputs", null);
Expand All @@ -244,7 +244,7 @@ public boolean simulateSedml(HDF5ExecutionResults masterHdf5File) throws Interru
return this.evaluateResults();
}

private void runSimulations(SolverHandler solverHandler, ExternalDocInfo externalDocInfo) throws IOException {
private void runSimulations(SolverHandler solverHandler, ExternalDocInfo externalDocInfo) {
/*
* - Run solvers and make reports; all failures/exceptions are being caught
* - we send both the whole OMEX file and the extracted SEDML file path
Expand All @@ -256,10 +256,11 @@ private void runSimulations(SolverHandler solverHandler, ExternalDocInfo externa
String str = "Building solvers and starting simulation of all tasks... ";
logger.info(str);
this.logDocumentMessage += str;
solverHandler.simulateAllTasks(externalDocInfo, this.sedml, this.CLI_RECORDER,
RunResults results = solverHandler.simulateAllTasks(externalDocInfo, this.sedml, this.CLI_RECORDER,
this.OUTPUT_DIRECTORY_FOR_CURRENT_SEDML, this.RESULTS_DIRECTORY_PATH,
this.ROOT_OUTPUT_DIR.getAbsolutePath(), this.SEDML_LOCATION, this.SHOULD_KEEP_TEMP_FILES,
this.ACCEPT_EXACT_MATCH_ONLY, this.SHOULD_OVERRIDE_FOR_SMALL_MESH);
this.recordRunDetails(solverHandler, results);
} catch (Exception e) {
Throwable currentTierOfException = e;
StringBuilder errorMessage = new StringBuilder();
Expand All @@ -277,8 +278,6 @@ private void runSimulations(SolverHandler solverHandler, ExternalDocInfo externa
span.close();
}
}

this.recordRunDetails(solverHandler);
}

private void processOutputs(SolverHandler solverHandler, HDF5ExecutionResults masterHdf5File) throws InterruptedException, ExecutionException, PythonStreamException {
Expand Down Expand Up @@ -466,17 +465,27 @@ private void reportProblem(Exception e) throws PythonStreamException, Interrupte
PythonCalls.updateSedmlDocStatusYml(this.SEDML_LOCATION, Status.FAILED, this.RESULTS_DIRECTORY_PATH);
}

private void recordRunDetails(SolverHandler solverHandler) throws IOException {
String message = this.DOC_STATISTICS.getNumModels() + ",";
message += this.DOC_STATISTICS.getNumSimulations() + ",";
message += this.DOC_STATISTICS.getNumTasks() + ",";
message += this.DOC_STATISTICS.getNumOutputs() + ",";
private void recordRunDetails(SolverHandler solverHandler, RunResults results) throws IOException {
StringBuilder generalMessage = new StringBuilder(this.BIOMODEL_BASE_NAME + ",");
generalMessage.append(this.DOC_STATISTICS.getNumModels()).append(",");
generalMessage.append(this.DOC_STATISTICS.getNumSimulations()).append(",");
generalMessage.append(this.DOC_STATISTICS.getNumTasks()).append(",");
generalMessage.append(this.DOC_STATISTICS.getNumOutputs()).append(",");

message += solverHandler.countBioModels + ",";
message += this.hasOverrides + ",";
message += this.hasScans + ",";
message += solverHandler.countSuccessfulSimulationRuns;
this.CLI_RECORDER.writeDetailedResultList(this.BIOMODEL_BASE_NAME + "," + message);
logger.debug(message);
generalMessage.append(solverHandler.countBioModels).append(",");
generalMessage.append(this.hasOverrides).append(",");
generalMessage.append(this.hasScans).append(",");
generalMessage.append(solverHandler.countSuccessfulSimulationRuns);
this.CLI_RECORDER.writeDetailedResultList(generalMessage.toString());

for (RunResults.IndividualResult result : results.generateRecordsOfResults()){
String individualMessage = result.bioModel() + "," +
result.tempSimulation() + "," +
result.duration() + "," +
result.status() + ",";
this.CLI_RECORDER.writeDetailedSimBreakdown(individualMessage);
}

logger.debug(generalMessage.toString());
}
}
Loading

0 comments on commit 5b3d266

Please sign in to comment.