Skip to content

Commit dec207b

Browse files
committed
Running batch simulations.
Batch simulations creation. For a math model.
1 parent 571c9ed commit dec207b

File tree

3 files changed

+76
-12
lines changed

3 files changed

+76
-12
lines changed

vcell-client/src/main/java/cbit/vcell/client/desktop/simulation/SimulationListPanel.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public class SimulationListPanel extends DocumentEditorSubPanel {
112112
private JButton ivjNewButton = null;
113113
private JButton ivjNativeResultsButton = null;
114114
private JButton importBatchButton = null;
115-
private JButton exportBatchButton = null;
115+
private JButton getBatchResultsButton = null;
116116

117117
// private JButton ivjPythonResultsButton = null;
118118
private JButton ivjRunButton = null;
@@ -148,7 +148,7 @@ public void actionPerformed(java.awt.event.ActionEvent e) {
148148
runSimulations();
149149
} else if (e.getSource() == stopButton) {
150150
stopSimulations();
151-
} else if (e.getSource() == exportBatchButton) {
151+
} else if (e.getSource() == getBatchResultsButton) {
152152
// DialogUtils.showInfoDialog(SimulationListPanel.this, "Under Construction");
153153
getBatchSimulationsResults();
154154
} else if (e.getSource() == importBatchButton) {
@@ -488,9 +488,9 @@ private javax.swing.JToolBar getToolBar() {
488488
importBatchButton = new JButton("", VCellIcons.importBatchSimIcon);
489489
importBatchButton.setToolTipText("Import Batch Simulation Data");
490490
importBatchButton.addActionListener(ivjEventHandler);
491-
exportBatchButton = new JButton("", VCellIcons.exportBatchSimIcon);
492-
exportBatchButton.setToolTipText("Export Batch Simulation Results");
493-
exportBatchButton.addActionListener(ivjEventHandler);
491+
getBatchResultsButton = new JButton("", VCellIcons.exportBatchSimIcon);
492+
getBatchResultsButton.setToolTipText("Export Batch Simulation Results");
493+
getBatchResultsButton.addActionListener(ivjEventHandler);
494494
stopButton = new JButton("", VCellIcons.stopSimIcon);
495495
stopButton.setToolTipText("Stop Simulation");
496496
stopButton.setEnabled(false);
@@ -518,7 +518,7 @@ private javax.swing.JToolBar getToolBar() {
518518
toolBar.add(getDeleteButton());
519519
toolBar.addSeparator();
520520
toolBar.add(importBatchButton);
521-
toolBar.add(exportBatchButton);
521+
toolBar.add(getBatchResultsButton);
522522
toolBar.addSeparator();
523523

524524
toolBar.add(getMassConservationModelReductionPanel());
@@ -537,7 +537,7 @@ private javax.swing.JToolBar getToolBar() {
537537

538538
ReactionCartoonEditorPanel.setToolBarButtonSizes(getNewButton());
539539
ReactionCartoonEditorPanel.setToolBarButtonSizes(importBatchButton);
540-
ReactionCartoonEditorPanel.setToolBarButtonSizes(exportBatchButton);
540+
ReactionCartoonEditorPanel.setToolBarButtonSizes(getBatchResultsButton);
541541
ReactionCartoonEditorPanel.setToolBarButtonSizes(copyButton);
542542
ReactionCartoonEditorPanel.setToolBarButtonSizes(getEditButton());
543543
ReactionCartoonEditorPanel.setToolBarButtonSizes(getDeleteButton());
@@ -1171,7 +1171,7 @@ private void refreshButtonsLax() {
11711171
}
11721172
}
11731173
importBatchButton.setEnabled(bBatch);
1174-
exportBatchButton.setEnabled(bBatch);
1174+
getBatchResultsButton.setEnabled(bBatch);
11751175
copyButton.setEnabled(bCopy);
11761176
getEditButton().setEnabled(bEditable);
11771177
getDeleteButton().setEnabled(bDeletable);

vcell-client/src/main/java/cbit/vcell/client/desktop/simulation/SimulationWorkspace.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,6 @@ private static String applyChanges(Simulation clonedSimulation, Simulation simul
134134
* Creation date: (10/4/2004 6:36:12 AM)
135135
*/
136136
public static String checkCompatibility(SimulationOwner simOwner, Simulation simulation) {
137-
if (simOwner instanceof MathModel){
138-
return null;
139-
}
140137
if (simOwner instanceof SimulationContext){
141138
SimulationContext simContext = (SimulationContext)simOwner;
142139
if(simulation == null){

vcell-core/src/main/java/cbit/vcell/mathmodel/MathModel.java

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import java.beans.PropertyVetoException;
1414
import java.beans.VetoableChangeListener;
1515
import java.util.Arrays;
16+
import java.util.LinkedHashMap;
1617
import java.util.List;
1718
import java.util.Map;
1819

@@ -34,8 +35,12 @@
3435
import cbit.vcell.geometry.Geometry;
3536
import cbit.vcell.geometry.GeometryOwner;
3637
import cbit.vcell.geometry.GeometrySpec;
38+
import cbit.vcell.math.Constant;
3739
import cbit.vcell.math.MathDescription;
3840
import cbit.vcell.model.VCMODL;
41+
import cbit.vcell.parser.Expression;
42+
import cbit.vcell.parser.ExpressionException;
43+
import cbit.vcell.solver.MathOverrides;
3944
import cbit.vcell.solver.OutputFunctionContext;
4045
import cbit.vcell.solver.Simulation;
4146
import cbit.vcell.solver.SimulationOwner;
@@ -229,8 +234,70 @@ public boolean contains(Simulation simulation) {
229234
return bFound;
230235
}
231236

237+
private final int MaxBatchSize = 199;
238+
public static final String ReservedBatchExtensionString = "_bat_";
232239
public Simulation createBatchSimulations(Simulation simulation, Map<Integer, Map<String, String>> batchInputDataMap) throws java.beans.PropertyVetoException {
233-
throw new RuntimeException("This feature is not supported for MathModels.");
240+
// throw new RuntimeException("This feature is not supported for MathModels.");
241+
if(getMathDescription() == null) {
242+
throw new RuntimeException("Application " + getName() + " has no generated Math, cannot add simulation");
243+
}
244+
if(simulation.getMathDescription() != getMathDescription()){
245+
throw new IllegalArgumentException("cannot copy simulation '" + simulation.getName() + "', has different MathDescription than Application");
246+
}
247+
248+
// mathModel == this
249+
int batchSize = batchInputDataMap.size();
250+
if(batchSize >= MaxBatchSize) {
251+
throw new RuntimeException("Batch size must be smaller than " + MaxBatchSize);
252+
}
253+
Simulation allSims[] = getSimulations();
254+
for (int k = 0; k < batchSize; k++) {
255+
if(batchInputDataMap.get(k) == null) {
256+
// entry missing, perhaps parsing error
257+
System.out.println("List of overrides missing for batch simulation " + k + ". Check input data file.");
258+
}
259+
}
260+
261+
// now we go through all those we have
262+
LinkedHashMap<Integer, Map<String, String>> batchInputLinkedMap = (LinkedHashMap<Integer, Map<String, String>>)batchInputDataMap;
263+
for(Integer i : batchInputLinkedMap.keySet()) {
264+
LinkedHashMap<String, String> overrideMap = (LinkedHashMap<String, String>)batchInputLinkedMap.get(i);
265+
266+
String insert = "";
267+
if(i<10) {
268+
insert = "00";
269+
} else if(i<100) {
270+
insert = "0";
271+
}
272+
String proposedName = simulation.getName() + ReservedBatchExtensionString + insert + i;
273+
boolean bFound = false;
274+
for (int j = 0; !bFound && j < allSims.length; j++) {
275+
// go through all existing simulations to make sure the name we want to use is not already taken
276+
if (allSims[j].getName().equals(proposedName)) {
277+
bFound = true;
278+
throw new RuntimeException("Batch file name already in use: " + proposedName);
279+
}
280+
}
281+
Simulation newSimulation = new Simulation(simulation);
282+
newSimulation.setName(proposedName);
283+
284+
MathOverrides mo = new MathOverrides(newSimulation);
285+
for(String name : overrideMap.keySet()) {
286+
String value = overrideMap.get(name);
287+
try {
288+
Expression expression = new Expression(value);
289+
Constant constant = new Constant(name, expression);
290+
mo.putConstant(constant);
291+
} catch (ExpressionException e) {
292+
e.printStackTrace();
293+
}
294+
}
295+
296+
newSimulation.setMathOverrides(mo);
297+
addSimulation(newSimulation);
298+
}
299+
return null;
300+
234301
}
235302
public void importBatchSimulations(Simulation simulation) throws java.beans.PropertyVetoException {
236303
throw new RuntimeException("This feature is not supported for MathModels.");

0 commit comments

Comments
 (0)