Skip to content

Commit

Permalink
Merge pull request #1398 from virtualcell/jobindex-with-trial
Browse files Browse the repository at this point in the history
redefine simulation JobIndex in terms of ScanIndex and TrialIndex
  • Loading branch information
jcschaff authored Dec 12, 2024
2 parents 746eb9a + c0bba26 commit 55ef45b
Show file tree
Hide file tree
Showing 38 changed files with 702 additions and 502 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import cbit.vcell.parser.Expression;
import cbit.vcell.parser.ExpressionException;
import cbit.vcell.solver.MathOverrides;
import cbit.vcell.solver.Simulation;
import cbit.vcell.solver.TempSimulation;
import org.apache.logging.log4j.LogManager;
Expand Down Expand Up @@ -168,7 +169,7 @@ public static Map<Report, List<Hdf5SedmlResults>> convertNonspatialResultsToSedm
String nameKey = dataSourceNonspatial.scanParameterNames[nameIndex];
scanValues[nameIndex] = new double[dataSourceNonspatial.scanBounds[nameIndex] + 1];
for (int scanIndex = 0; scanIndex < dataSourceNonspatial.scanBounds[nameIndex] + 1; scanIndex++){
Expression overrideExp = dataSetValuesSource.vcSimulation.getMathOverrides().getActualExpression(nameKey, scanIndex);
Expression overrideExp = dataSetValuesSource.vcSimulation.getMathOverrides().getActualExpression(nameKey, new MathOverrides.ScanIndex(scanIndex));
try { scanValues[nameIndex][scanIndex] = overrideExp.evaluateConstant(); }
catch (ExpressionException e){ throw new RuntimeException(e); }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import cbit.vcell.parser.Expression;
import cbit.vcell.parser.ExpressionException;
import cbit.vcell.solver.MathOverrides;
import cbit.vcell.solver.TempSimulation;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -135,7 +136,7 @@ private static boolean processDataGenerator(SedML sedml, Report report, DataGene
String nameKey = convertedData.scanParameterNames[nameIndex];
scanValues[nameIndex] = new double[eachBound[nameIndex] + 1];
for (int scanIndex = 0; scanIndex < eachBound[nameIndex] + 1; scanIndex++){
Expression overrideExp = vcellSimulation.getMathOverrides().getActualExpression(nameKey, scanIndex);
Expression overrideExp = vcellSimulation.getMathOverrides().getActualExpression(nameKey, new MathOverrides.ScanIndex(scanIndex));
try { scanValues[nameIndex][scanIndex] = overrideExp.evaluateConstant(); }
catch (ExpressionException e){ throw new RuntimeException(e); }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import javax.swing.ListSelectionModel;
import javax.swing.table.DefaultTableCellRenderer;

import cbit.vcell.solver.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.vcell.client.logicalwindow.LWNamespace;
Expand Down Expand Up @@ -130,16 +131,7 @@
import cbit.vcell.simdata.OutputContext;
import cbit.vcell.simdata.PDEDataContext;
import cbit.vcell.simdata.PDEDataManager;
import cbit.vcell.solver.AnnotatedFunction;
import cbit.vcell.solver.AnnotatedFunction.FunctionCategory;
import cbit.vcell.solver.DefaultOutputTimeSpec;
import cbit.vcell.solver.NonspatialStochSimOptions;
import cbit.vcell.solver.Simulation;
import cbit.vcell.solver.SimulationInfo;
import cbit.vcell.solver.SimulationSymbolTable;
import cbit.vcell.solver.SolverDescription;
import cbit.vcell.solver.SolverTaskDescription;
import cbit.vcell.solver.VCSimulationDataIdentifier;
import cbit.vcell.solver.ode.ODESolverResultSet;
import cbit.vcell.solver.ode.SensVariable;
import cbit.vcell.solver.test.MathTestingUtilities;
Expand Down Expand Up @@ -1189,7 +1181,7 @@ private String generateTestCriteriaReport(TestCaseNew testCase, TestCriteriaNew
if (testSim.getScanCount() != 1) {
throw new RuntimeException("paramater scan is not supported in Math Testing Framework");
}
SimulationSymbolTable simSymbolTable = new SimulationSymbolTable(testSim, 0);
SimulationSymbolTable simSymbolTable = new SimulationSymbolTable(testSim, MathOverrides.ScanIndex.ZERO);

String simReportStatus = null;
String simReportStatusMessage = null;
Expand Down Expand Up @@ -1321,7 +1313,7 @@ private String generateTestCriteriaReport(TestCaseNew testCase, TestCriteriaNew
if (refSim.getScanCount() != 1) {
throw new RuntimeException("paramater scan is not supported in Math Testing Framework");
}
SimulationSymbolTable refSimSymbolTable = new SimulationSymbolTable(refSim, 0);
SimulationSymbolTable refSimSymbolTable = new SimulationSymbolTable(refSim, MathOverrides.ScanIndex.ZERO);

String varsToCompare[] = getVariableNamesToCompare(simSymbolTable, refSimSymbolTable);
SimulationComparisonSummary simCompSummary =
Expand Down Expand Up @@ -1418,7 +1410,7 @@ private String generateTestCriteriaReport(TestCaseNew testCase, TestCriteriaNew
if (refSim.getScanCount() != 1) {
throw new RuntimeException("paramater scan is not supported in Math Testing Framework");
}
SimulationSymbolTable refSimSymbolTable = new SimulationSymbolTable(refSim, 0);
SimulationSymbolTable refSimSymbolTable = new SimulationSymbolTable(refSim, MathOverrides.ScanIndex.ZERO);

String varsToTest[] = getVariableNamesToCompare(simSymbolTable, refSimSymbolTable);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import javax.swing.SwingConstants;
import javax.swing.table.TableColumn;

import cbit.vcell.solver.*;
import org.vcell.util.document.VCDataIdentifier;

import cbit.plot.Plot2D;
Expand All @@ -39,10 +40,6 @@
import cbit.vcell.parser.SymbolTableEntry;
import cbit.vcell.simdata.DataManager;
import cbit.vcell.simdata.ODEDataManager;
import cbit.vcell.solver.DefaultOutputTimeSpec;
import cbit.vcell.solver.Simulation;
import cbit.vcell.solver.VCSimulationDataIdentifier;
import cbit.vcell.solver.VCSimulationIdentifier;
import cbit.vcell.solver.ode.ODESolverResultSet;
import cbit.vcell.solver.ode.gui.ODESolverPlotSpecificationPanel;
/**
Expand Down Expand Up @@ -88,6 +85,7 @@ private void initialize() {

setLayout(new BorderLayout());
int scanCount = simulation.getScanCount();
int trialCount = simulation.getNumTrials();

plotPane = new PlotPane();
plotPane.getPlot2DDataPanel1().setXVarName(xVarColumnName);
Expand Down Expand Up @@ -129,7 +127,7 @@ public int getColumnCount() {

public Object getValueAt(int row, int col) {
if (col == 0) {
return new Integer(row);
return row;
}
return rowData[row][col - 1];
}
Expand All @@ -145,12 +143,11 @@ public Class<?> getColumnClass(int columnIndex) {

values = new Double[scanCount][scanParams.length];
for (int i = 0; i < scanCount; i ++) {
MathOverrides.ScanIndex scanIndex = new MathOverrides.ScanIndex(i);
for (int j = 0; j < scanParams.length; j ++){
Expression scanConstantExp = simulation.getMathOverrides().getActualExpression(scanParams[j], i);
Expression scanConstantExp = simulation.getMathOverrides().getActualExpression(scanParams[j], scanIndex);
try {
values[i][j] = scanConstantExp.evaluateConstantWithSubstitution();
} catch (DivideByZeroException e1) {
e1.printStackTrace();
} catch (ExpressionException e1) {
e1.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,9 @@ private ExportSpecs getExportSpecs() {
if (vcDataIdentifier instanceof VCSimulationDataIdentifier){
for (String filteredConstant : filteredConstants) {
String defaultValue = mathOverrides.getDefaultExpression(filteredConstant).infix();
String setValue = mathOverrides.getActualExpression(filteredConstant, ((VCSimulationDataIdentifier) vcDataIdentifier).getJobIndex()).infix();
int jobIndex = ((VCSimulationDataIdentifier) vcDataIdentifier).getJobIndex();
MathOverrides.ScanIndex scanIndex = simulation.getScanIndex(jobIndex);
String setValue = mathOverrides.getActualExpression(filteredConstant, scanIndex).infix();
if(!defaultValue.equals(setValue)){
differentParameterValues.add(filteredConstant + ":" +defaultValue + ":" + setValue);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@
import cbit.vcell.math.Constant;
import cbit.vcell.mathmodel.MathModel;
import cbit.vcell.simdata.*;
import cbit.vcell.solver.MathOverrides;
import cbit.vcell.solver.Simulation;
import cbit.vcell.solver.SolverTaskDescription;
import cbit.vcell.solver.VCSimulationDataIdentifier;
import cbit.vcell.solver.ode.ODESolverResultSet;
import org.vcell.util.ArrayUtils;
import org.vcell.util.BeanUtils;
import org.vcell.util.DataAccessException;
import org.vcell.util.UserCancelException;
import org.vcell.util.document.VCDataIdentifier;
Expand All @@ -37,6 +38,9 @@
import java.awt.event.ActionListener;
import java.util.Arrays;
import java.util.Hashtable;

import static cbit.vcell.solver.MathOverrides.parameterScanCoordinateToScanIndex;

/**
* Insert the type's description here.
* Creation date: (10/17/2005 11:22:58 PM)
Expand Down Expand Up @@ -387,7 +391,12 @@ private int getSelectedParamScanJobIndex(){
}
int selectedJobIndex = -1;
try {
selectedJobIndex = BeanUtils.parameterScanCoordinateToJobIndex(indices, bounds);
MathOverrides.ScanIndex scanIndex = MathOverrides.parameterScanCoordinateToScanIndex(indices, bounds);
SolverTaskDescription.TrialIndex trialIndex = SolverTaskDescription.TrialIndex.ZERO;
if (getSimulation().getNumTrials() > 1) {
System.err.println("SimResultsViewer.getSelectedParamScanJobIndex: multiple trials not supported yet");
}
selectedJobIndex = getSimulation().getJobIndex(scanIndex, trialIndex);
} catch (RuntimeException exc) {
exc.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public static String checkCompatibility(SimulationOwner simOwner, Simulation sim
* @param simulation cbit.vcell.solver.Simulation
*/
private static boolean checkSimulationParameters(Simulation simulation, Component parent,boolean bCheckLimits) {
SimulationSymbolTable simSymbolTable = new SimulationSymbolTable(simulation, 0);
SimulationSymbolTable simSymbolTable = new SimulationSymbolTable(simulation, MathOverrides.ScanIndex.ZERO);

String errorMessage = null;
long maxTimepoints = Simulation.MAX_LIMIT_NON_SPATIAL_TIMEPOINTS;
Expand Down
14 changes: 5 additions & 9 deletions vcell-client/src/main/java/cbit/vcell/client/task/RunSims.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.Hashtable;
import java.util.Vector;

import cbit.vcell.solver.*;
import org.vcell.util.*;
import org.vcell.util.document.VCDocument;
import org.vcell.util.gui.DialogUtils;
Expand All @@ -34,13 +35,7 @@
import cbit.vcell.parser.Expression;
import cbit.vcell.parser.ExpressionException;
import cbit.vcell.server.SimulationStatus;
import cbit.vcell.solver.DataProcessingInstructions;
import cbit.vcell.solver.MeshSpecification;
import cbit.vcell.solver.Simulation;
import cbit.vcell.solver.SimulationInfo;
import cbit.vcell.solver.SimulationJob;
import cbit.vcell.solver.SimulationSymbolTable;
import cbit.vcell.solver.SolverDescription;

/**
* Insert the type's description here.
* Creation date: (5/31/2004 6:03:16 PM)
Expand Down Expand Up @@ -71,8 +66,9 @@ public RunSims() {
}

private boolean isSmoldynTimeStepOK(Simulation sim) {
for (int jobIndex = 0; jobIndex < sim.getScanCount(); jobIndex ++) {
SimulationSymbolTable simSymbolTable = new SimulationSymbolTable(sim, jobIndex);
for (int scan = 0; scan < sim.getScanCount(); scan ++) {
MathOverrides.ScanIndex scanIndex = new MathOverrides.ScanIndex(scan);
SimulationSymbolTable simSymbolTable = new SimulationSymbolTable(sim, scanIndex);
double Dmax = 0;
MathDescription mathDesc = sim.getMathDescription();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public static void chooseApplyPaste(Component requester,
Object newValue = newMathOverridesValuesV.elementAt(i);
if(newValue instanceof Expression){
bEnableDisplay[i] = !Compare.isEqualOrNull(
mathOverrides.getActualExpression(changingMathOverridesNames[i],0),
mathOverrides.getActualExpression(changingMathOverridesNames[i],MathOverrides.ScanIndex.ZERO),
((Expression)newValue));
}else if(newValue instanceof ConstantArraySpec){
bEnableDisplay[i] = !Compare.isEqualOrNull(
Expand Down Expand Up @@ -282,7 +282,7 @@ public static void chooseApplyPaste_NOT_USED(Component requester,
boolean[] bEnableDisplay = new boolean[changingMathOverridesNames.length];
for(int i=0;i<changingMathOverridesNames.length;i+= 1){
//bEnableDisplay[i] = !changingParamters[i].getExpression().equals(newParameterExpression[i]);
bEnableDisplay[i] = !Compare.isEqualOrNull(mathOverrides.getActualExpression(changingMathOverridesNames[i],0),newMathOverridesValues[i].getExpression());
bEnableDisplay[i] = !Compare.isEqualOrNull(mathOverrides.getActualExpression(changingMathOverridesNames[i],MathOverrides.ScanIndex.ZERO),newMathOverridesValues[i].getExpression());
bAtLeatOneDifferent = bAtLeatOneDifferent || bEnableDisplay[i];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ private synchronized void copyCells(String actionCommand) {
for (int row : rows) {
String rowName = (String) getJTableFixed().getValueAt(row, MathOverridesTableModel.COLUMN_PARAMETER);
primarySymbolTableEntriesV.add(getMathOverrides().getConstant(rowName));
resolvedValuesV.add(getMathOverrides().getActualExpression(rowName, 0));
resolvedValuesV.add(getMathOverrides().getActualExpression(rowName, MathOverrides.ScanIndex.ZERO));

}
VCellTransferable.ResolvedValuesSelection rvs =
Expand Down Expand Up @@ -761,8 +761,8 @@ private void jMenuItemPaste_ActionPerformed(java.awt.event.ActionEvent actionEve
String originalValueDescription = null;
if (getMathOverrides().getConstantArraySpec(rowName) != null) {
originalValueDescription = getMathOverrides().getConstantArraySpec(rowName).toString();
} else if (getMathOverrides().getActualExpression(rowName, 0) != null) {
originalValueDescription = getMathOverrides().getActualExpression(rowName, 0).infix();
} else if (getMathOverrides().getActualExpression(rowName, MathOverrides.ScanIndex.ZERO) != null) {
originalValueDescription = getMathOverrides().getActualExpression(rowName, MathOverrides.ScanIndex.ZERO).infix();
} else {
throw new Exception("MathOverridesPanel can't find value for '" + rowName + "'");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public Object getValueAt(int row, int column) {
if (getMathOverrides().isScan(fieldKeys[row])) {
return getMathOverrides().getConstantArraySpec(fieldKeys[row]);
} else {
Expression actualExpression = getMathOverrides().getActualExpression(fieldKeys[row], 0);
Expression actualExpression = getMathOverrides().getActualExpression(fieldKeys[row], MathOverrides.ScanIndex.ZERO);
if(actualExpression == null) {
return null;
}
Expand Down Expand Up @@ -387,7 +387,7 @@ private void updateKeys(MathOverrides mathOverrides) {
fieldKeys = mathOverrides.getOverridenConstantNames();
}
Arrays.sort(fieldKeys);
simSymbolTable = new SimulationSymbolTable(getMathOverrides().getSimulation(), 0);
simSymbolTable = new SimulationSymbolTable(getMathOverrides().getSimulation(), MathOverrides.ScanIndex.ZERO);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import javax.swing.JOptionPane;

import cbit.vcell.biomodel.BioModelTransforms;
import cbit.vcell.solver.MathOverrides;
import cbit.vcell.xml.XMLSource;
import org.apache.commons.io.FilenameUtils;
import org.vcell.sbml.gui.ApplnSelectionAndStructureSizeInputPanel;
Expand Down Expand Up @@ -255,11 +256,12 @@ public void writeBioModel(DocumentManager documentManager, BioModel bioModel, Fi
clonedBM.refreshDependencies();
String originalExportFilename = exportFile.getPath();
Files.deleteIfExists(Paths.get(originalExportFilename));
for (int jobIndex = 0; jobIndex < selectedSimWOSBE.getScanCount(); jobIndex++) {
BioModelTransforms.applyMathOverrides(selectedSimWOSBE, jobIndex, clonedBM);
for (int scan = 0; scan < selectedSimWOSBE.getScanCount(); scan++) {
MathOverrides.ScanIndex scanIndex = new MathOverrides.ScanIndex(scan);
BioModelTransforms.applyMathOverrides(selectedSimWOSBE, scanIndex, clonedBM);
String resultString = XmlHelper.exportSBML(clonedBM, sbmlLevel, sbmlVersion, sbmlPkgVersion, isSpatial, selectedSimContext, bRoundTripValidation);
// Need to export each parameter scan into a separate file
String newExportFileName = exportFile.getPath().substring(0, exportFile.getPath().indexOf(".xml")) + "_" + jobIndex + ".xml";
String newExportFileName = exportFile.getPath().substring(0, exportFile.getPath().indexOf(".xml")) + "_" + scanIndex.index + ".xml";
Files.deleteIfExists(Paths.get(newExportFileName));
XmlUtil.writeXMLStringToFile(resultString, exportFile.getAbsolutePath(), true);
exportFile.renameTo(new File(newExportFileName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ public static void reconcileLegacyAbsRelSizes(BioModel bioModel) {
}
}

public static void applyMathOverrides(Simulation simulation, int jobIndex, BioModel bioModel) throws MappingException, ExpressionException {
public static void applyMathOverrides(Simulation simulation, MathOverrides.ScanIndex scanIndex, BioModel bioModel) throws MappingException, ExpressionException {
if (simulation == null) {
throw new RuntimeException("simulation was null");
}
Expand Down Expand Up @@ -443,7 +443,7 @@ public static void applyMathOverrides(Simulation simulation, int jobIndex, BioMo
throw new RuntimeException("biological symbol table entry for variable '"+overriddenConstantName+"'");
}
Expression defaultExpression = mathOverrides.getDefaultExpression(overriddenConstantName);
SimulationSymbolTable simulationSymbolTable = new SimulationSymbolTable(simulation, jobIndex);
SimulationSymbolTable simulationSymbolTable = new SimulationSymbolTable(simulation, scanIndex);
Expression actualExpression = simulationSymbolTable.getLocalConstant((Constant)var).getExpression().flatten();
if (!actualExpression.isNumeric()){
throw new RuntimeException("applying non-numeric overrides to a biomodel not yet supported: "+overriddenConstantName+": default = "+defaultExpression.infix()+", actual = "+actualExpression.infix());
Expand Down
Loading

0 comments on commit 55ef45b

Please sign in to comment.