From 7a79c1bf9ce6e25b827780cb13817504a92720d3 Mon Sep 17 00:00:00 2001 From: Dan Vasilescu Date: Mon, 16 Dec 2024 15:45:38 -0500 Subject: [PATCH 1/6] WIP --- .../solver/ode/gui/LangevinOptionsPanel.java | 111 +++++++++++++++--- .../solver/LangevinSimulationOptions.java | 34 ++++-- .../main/java/cbit/vcell/xml/XmlReader.java | 4 +- .../main/java/cbit/vcell/xml/Xmlproducer.java | 2 +- 4 files changed, 122 insertions(+), 29 deletions(-) diff --git a/vcell-client/src/main/java/cbit/vcell/solver/ode/gui/LangevinOptionsPanel.java b/vcell-client/src/main/java/cbit/vcell/solver/ode/gui/LangevinOptionsPanel.java index a26a9317e2..de6dca327e 100644 --- a/vcell-client/src/main/java/cbit/vcell/solver/ode/gui/LangevinOptionsPanel.java +++ b/vcell-client/src/main/java/cbit/vcell/solver/ode/gui/LangevinOptionsPanel.java @@ -1,21 +1,17 @@ package cbit.vcell.solver.ode.gui; -import java.awt.Component; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Insets; +import java.awt.*; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JTextField; +import javax.swing.*; +import javax.swing.border.Border; +import cbit.vcell.solver.NFsimSimulationOptions; import org.vcell.util.gui.CollapsiblePanel; -import org.vcell.util.gui.DialogUtils; import cbit.vcell.client.PopupGenerator; import cbit.vcell.solver.LangevinSimulationOptions; -import cbit.vcell.solver.OutputTimeSpec; import cbit.vcell.solver.SolverTaskDescription; +import org.vcell.util.gui.DialogUtils; @SuppressWarnings("serial") public class LangevinOptionsPanel extends CollapsiblePanel { @@ -39,6 +35,11 @@ public class LangevinOptionsPanel extends CollapsiblePanel { private JLabel numPartitionsZLabel = null; private JLabel numPartitionsLabel = null; + private JCheckBox randomSeedCheckBox; + private JTextField randomSeedTextField; + private JButton randomSeedHelpButton = null; + + // private int[] npart = {LangevinSimulationOptions.DefaultNPart[0], LangevinSimulationOptions.DefaultNPart[1], LangevinSimulationOptions.DefaultNPart[2]}; // number of partitions on each axis private JTextField intervalImageTextField = null; @@ -72,6 +73,21 @@ public void actionPerformed(java.awt.event.ActionEvent e) { getJTextFieldNumOfTrials().setEnabled(true); getJTextFieldNumOfParallelLocalRuns().setEnabled(true); setNewOptions(); + } else if(e.getSource() == randomSeedCheckBox) { + randomSeedTextField.setEditable(randomSeedCheckBox.isSelected()); + if(randomSeedCheckBox.isSelected()) { + + Integer rs = solverTaskDescription.getLangevinSimulationOptions().getRandomSeed(); + if(rs == null) { + rs = LangevinSimulationOptions.DefaultRandomSeed; + solverTaskDescription.getLangevinSimulationOptions().setRandomSeed(rs); + } + randomSeedTextField.setText(rs.toString()); + } else { + solverTaskDescription.getLangevinSimulationOptions().setRandomSeed(null); + randomSeedTextField.setText(""); + } + } } @@ -189,7 +205,6 @@ private void initialize() { gbc.insets = new Insets(0,5,3,1); trialPanel.add(getJTextFieldNumOfParallelLocalRuns(), gbc); - // ----- aici gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 3; @@ -246,6 +261,14 @@ private void initialize() { gbc.insets = new Insets(0,5,3,1); trialPanel.add(getNumPartitionsZTextField(), gbc); + gbc = new GridBagConstraints(); + gbc.gridx = 0; + gbc.gridy = 6; + gbc.anchor = GridBagConstraints.WEST; + gbc.fill = GridBagConstraints.HORIZONTAL; + gbc.insets = new Insets(5,5,3,1); + trialPanel.add(getRandomSeedCheckBox(), gbc); + // gbc = new GridBagConstraints(); // --- empty panel (filler) // gbc.gridx = 3; @@ -311,6 +334,24 @@ private void initialize() { gbc.weighty = 1.0; centerPanel.add(new JLabel(""), gbc); + gbc = new GridBagConstraints(); + gbc.gridx = 0; + gbc.gridy = 3; + gbc.weightx = 1; + gbc.gridwidth = 2; + gbc.insets = new Insets(0, 0, 6, 6); + gbc.fill = GridBagConstraints.HORIZONTAL; + gbc.anchor = GridBagConstraints.LINE_START; + centerPanel.add(getRandomSeedTextField(), gbc); + + gbc = new GridBagConstraints(); + gbc.gridx = 2; + gbc.gridy = 3; + gbc.anchor = GridBagConstraints.LINE_END; + gbc.insets = new Insets(0, 0, 6, 6); + centerPanel.add(getRandomSeedHelpButton(), gbc); + + // ----- rightPanel ---------------------------------------------------- gbc = new GridBagConstraints(); gbc.gridx = 3; @@ -398,6 +439,34 @@ private javax.swing.JLabel getNumOfTrialsLabel() { } return numOfTrialsLabel; } + private JCheckBox getRandomSeedCheckBox() { + if(randomSeedCheckBox == null) { + randomSeedCheckBox = new JCheckBox(); + randomSeedCheckBox.setName("RandomSeedCheckBox"); + randomSeedCheckBox.setText("Set a seed to Langevin random number generator."); + } + return randomSeedCheckBox; + } + private JTextField getRandomSeedTextField() { + if(randomSeedTextField == null) { + randomSeedTextField = new JTextField(); + randomSeedTextField.setName("RandomSeedTextField"); + randomSeedTextField.setText(""); + } + return randomSeedTextField; + } + private JButton getRandomSeedHelpButton() { + if(randomSeedHelpButton == null) { + Border border = BorderFactory.createEmptyBorder(1, 1, 1, 1); + randomSeedHelpButton = new JButton(); + Font font = randomSeedHelpButton.getFont().deriveFont(Font.BOLD); + randomSeedHelpButton.setName("RandomSeedHelpButton"); + randomSeedHelpButton.setBorder(border); + randomSeedHelpButton.setFont(font); + randomSeedHelpButton.setText(" ? "); + } + return randomSeedHelpButton; + } // ======================================================================= Number of Partitions private javax.swing.JTextField getNumPartitionsXTextField() { @@ -590,7 +659,7 @@ private void refresh() { setVisible(true); LangevinSimulationOptions lso = solverTaskDescription.getLangevinSimulationOptions(); - int numTrials = lso.getNumOfTrials(); + int numTrials = lso.getNumTrials(); int numOfParallelLocalRuns = lso.getNumOfParallelLocalRuns(); if(numTrials == 1) { getTrajectoryButton().setSelected(true); @@ -635,11 +704,22 @@ private void setNewOptions() { if(getMultiRunButton().isSelected()) { numTrials = Integer.parseInt(getJTextFieldNumOfTrials().getText()); - sso.setNumOfTrials(numTrials); numOfParallelLocalRuns = Integer.parseInt(getJTextFieldNumOfParallelLocalRuns().getText()); - sso.setNumOfParallelLocalRuns(numOfParallelLocalRuns); } - + + Integer randomSeed = null; + if (randomSeedCheckBox.isSelected()) { + try { + randomSeed = Integer.valueOf(randomSeedTextField.getText()); + } catch (NumberFormatException ex) { + randomSeed = solverTaskDescription.getLangevinSimulationOptions().getRandomSeed(); + if(randomSeed == null) { + randomSeed = LangevinSimulationOptions.DefaultRandomSeed; + } + randomSeedTextField.setText(randomSeed.toString()); + } + } + intervalImage = Double.parseDouble(getJTextFieldIntervalImage().getText()); intervalSpring = Double.parseDouble(getJTextFieldIntervalSpring().getText()); @@ -649,6 +729,9 @@ private void setNewOptions() { // make a copy LangevinSimulationOptions lso = new LangevinSimulationOptions(sso); + lso.setNumTrials(numTrials); + lso.setNumOfParallelLocalRuns(numOfParallelLocalRuns); + lso.setRandomSeed(randomSeed); lso.setIntervalImage(intervalImage); lso.setIntervalSpring(intervalSpring); lso.setNPart(npart); diff --git a/vcell-core/src/main/java/cbit/vcell/solver/LangevinSimulationOptions.java b/vcell-core/src/main/java/cbit/vcell/solver/LangevinSimulationOptions.java index d3a9d8eaac..4716d1a9ba 100644 --- a/vcell-core/src/main/java/cbit/vcell/solver/LangevinSimulationOptions.java +++ b/vcell-core/src/main/java/cbit/vcell/solver/LangevinSimulationOptions.java @@ -19,7 +19,6 @@ import java.io.Serializable; import org.vcell.util.CommentStringTokenizer; -import org.vcell.util.Compare; import org.vcell.util.DataAccessException; import org.vcell.util.Matchable; @@ -42,9 +41,13 @@ public class LangevinSimulationOptions implements Serializable, Matchable, Vetoa public final static int[] DefaultNPart = { 10, 10, 10 }; - protected int numOfTrials = 1; // how many runs of the solver for this simulation + public final static int DefaultRandomSeed = 1; + public final static int DefaultNumTrials = 1; + + protected int numTrials = DefaultNumTrials; // how many runs of the solver for this simulation protected int numOfParallelLocalRuns = 1; // how many instances of the solver run in parallel protected int runIndex = 0; // run index, will result in Run0 (followed by Run1, 2,...) + protected Integer randomSeed = DefaultRandomSeed; protected double intervalSpring = 1.00E-9; // default: dtspring: 1.00E-9 - from advanced protected double intervalImage = 1.00E-4; // default: dtimage: 1.00E-4 - from advanced @@ -62,7 +65,7 @@ public LangevinSimulationOptions(LangevinSimulationOptions langevinSimulationOpt this(); // TODO: properly implement copy constructor intervalSpring = langevinSimulationOptions.intervalSpring; intervalImage = langevinSimulationOptions.intervalImage; - numOfTrials = langevinSimulationOptions.numOfTrials; + numTrials = langevinSimulationOptions.numTrials; runIndex = langevinSimulationOptions.runIndex; npart[0] = langevinSimulationOptions.npart[0]; npart[1] = langevinSimulationOptions.npart[1]; @@ -79,7 +82,7 @@ public boolean compareEqual(Matchable obj) { return false; } LangevinSimulationOptions langevinSimulationOptions = (LangevinSimulationOptions)obj; - if(numOfTrials != langevinSimulationOptions.numOfTrials) { + if(numTrials != langevinSimulationOptions.numTrials) { return false; } if(runIndex != langevinSimulationOptions.runIndex) { @@ -102,15 +105,15 @@ public boolean compareEqual(Matchable obj) { // can be between 0 and numOfTrials-1 public int getRunIndex() { // for multiple trials the runIndex must be incremented for each run, dynamically - if(runIndex > numOfTrials-1) { + if(runIndex > numTrials -1) { throw new RuntimeException("Max run index must be smaller than the number of trials."); } int currentRunIndex = runIndex; runIndex++; return currentRunIndex; } - public int getNumOfTrials() { - return numOfTrials; + public int getNumTrials() { + return numTrials; } public int getNumOfParallelLocalRuns() { return numOfParallelLocalRuns; @@ -127,12 +130,15 @@ public int getNPart(int index) { public int[] getNPart() { return npart; } + public Integer getRandomSeed() { + return randomSeed; + } public final void setRunIndex(int newValue) { this.runIndex = newValue; } - public final void setNumOfTrials(int newValue) { - this.numOfTrials = newValue; + public final void setNumTrials(int newValue) { + this.numTrials = newValue; } public final void setNumOfParallelLocalRuns(int newValue) { this.numOfParallelLocalRuns = newValue; @@ -151,6 +157,11 @@ public final void setNPart(int[] npart) { public final void setNPart(int index, int npart) { this.npart[index] = npart; } + public void setRandomSeed(Integer randomSeed) { + this.randomSeed = randomSeed; + } + + // ------------------------------------------------------------------------------------------ public synchronized void addPropertyChangeListener(java.beans.PropertyChangeListener listener) { getPropertyChange().addPropertyChangeListener(listener); @@ -186,7 +197,7 @@ private void fireVetoableChange(java.lang.String propertyName, java.lang.Object public String getVCML() { StringBuffer buffer = new StringBuffer(); buffer.append("\t" + VCML.LangevinSimulationOptions + " " + VCML.BeginBlock + "\n"); - buffer.append("\t\t" + VCML.LangevinSimulationOptions_numOfTrials + " " + numOfTrials + "\n"); + buffer.append("\t\t" + VCML.LangevinSimulationOptions_numOfTrials + " " + numTrials + "\n"); buffer.append("\t\t" + VCML.LangevinSimulationOptions_runIndex + " " + runIndex + "\n"); buffer.append("\t\t" + VCML.LangevinSimulationOptions_intervalSpring + " " + intervalSpring + "\n"); buffer.append("\t\t" + VCML.LangevinSimulationOptions_intervalImage + " " + intervalImage + "\n"); @@ -239,7 +250,7 @@ public void readVCML(CommentStringTokenizer tokens) throws DataAccessException { if(val2 < 1 ) { throw new DataAccessException("unexpected token " + token + ", num of trials is requied to be at least 1. "); } else { - numOfTrials = val2; + numTrials = val2; } } else { throw new DataAccessException("unexpected identifier " + token); @@ -262,4 +273,5 @@ public void refreshDependencies() { removeVetoableChangeListener(this); addVetoableChangeListener(this); } + } diff --git a/vcell-core/src/main/java/cbit/vcell/xml/XmlReader.java b/vcell-core/src/main/java/cbit/vcell/xml/XmlReader.java index 91fa5d82b0..52cacae678 100644 --- a/vcell-core/src/main/java/cbit/vcell/xml/XmlReader.java +++ b/vcell-core/src/main/java/cbit/vcell/xml/XmlReader.java @@ -40,7 +40,6 @@ import org.vcell.pathway.persistence.RDFXMLContext; import org.vcell.relationship.RelationshipModel; import org.vcell.relationship.persistence.RelationshipReader; -import org.vcell.sbml.vcell.StructureSizeSolver; import org.vcell.util.BeanUtils; import org.vcell.util.Commented; import org.vcell.util.Coordinate; @@ -261,7 +260,6 @@ import cbit.vcell.parser.Expression; import cbit.vcell.parser.ExpressionBindingException; import cbit.vcell.parser.ExpressionException; -import cbit.vcell.parser.ParserException; import cbit.vcell.parser.SymbolTableEntry; import cbit.vcell.render.Vect3d; import cbit.vcell.solver.AnnotatedFunction.FunctionCategory; @@ -6700,7 +6698,7 @@ private LangevinSimulationOptions getLangevinSimulationOptions(Element langevinS String temp = null; temp = langevinSimulationOptionsElement.getChildText(XMLTags.LangevinSO_numOfTrials, vcNamespace); if(temp != null){ - lo.setNumOfTrials(Integer.parseInt(temp)); + lo.setNumTrials(Integer.parseInt(temp)); } temp = langevinSimulationOptionsElement.getChildText(XMLTags.LangevinSO_intervalSpring, vcNamespace); if(temp != null){ diff --git a/vcell-core/src/main/java/cbit/vcell/xml/Xmlproducer.java b/vcell-core/src/main/java/cbit/vcell/xml/Xmlproducer.java index b17b7bf19b..0610f31440 100644 --- a/vcell-core/src/main/java/cbit/vcell/xml/Xmlproducer.java +++ b/vcell-core/src/main/java/cbit/vcell/xml/Xmlproducer.java @@ -4807,7 +4807,7 @@ private Element getXML(LangevinSimulationOptions lso) { Element lsoe = new Element(XMLTags.LangevinSimulationOptions); e = new Element(XMLTags.LangevinSO_numOfTrials); - e.setText(String.valueOf(lso.getNumOfTrials())); + e.setText(String.valueOf(lso.getNumTrials())); lsoe.addContent(e); e = new Element(XMLTags.LangevinSO_intervalSpring); From c52182eaef758a2237dda3d15f97c3ad62fabd20 Mon Sep 17 00:00:00 2001 From: Dan Vasilescu Date: Wed, 18 Dec 2024 15:59:23 -0500 Subject: [PATCH 2/6] numTrials and randomSeed: editing, persistence. SolverTaskDescription: copy constructor, compareEqual fixes --- .../solver/ode/gui/LangevinOptionsPanel.java | 164 ++++++++++++------ .../src/main/java/cbit/vcell/math/VCML.java | 3 +- .../solver/LangevinSimulationOptions.java | 59 ++----- .../vcell/solver/SolverTaskDescription.java | 6 +- .../src/main/java/cbit/vcell/xml/XMLTags.java | 2 +- .../main/java/cbit/vcell/xml/XmlReader.java | 9 +- .../main/java/cbit/vcell/xml/Xmlproducer.java | 9 +- .../vcell/solver/langevin/LangevinSolver.java | 13 +- 8 files changed, 146 insertions(+), 119 deletions(-) diff --git a/vcell-client/src/main/java/cbit/vcell/solver/ode/gui/LangevinOptionsPanel.java b/vcell-client/src/main/java/cbit/vcell/solver/ode/gui/LangevinOptionsPanel.java index de6dca327e..e63aa01a9d 100644 --- a/vcell-client/src/main/java/cbit/vcell/solver/ode/gui/LangevinOptionsPanel.java +++ b/vcell-client/src/main/java/cbit/vcell/solver/ode/gui/LangevinOptionsPanel.java @@ -1,11 +1,13 @@ package cbit.vcell.solver.ode.gui; import java.awt.*; +import java.math.BigInteger; import javax.swing.*; import javax.swing.border.Border; import cbit.vcell.solver.NFsimSimulationOptions; +import org.vcell.solver.nfsim.gui.NFSimSimulationOptionsPanel; import org.vcell.util.gui.CollapsiblePanel; import cbit.vcell.client.PopupGenerator; @@ -68,16 +70,25 @@ public void actionPerformed(java.awt.event.ActionEvent e) { if (e.getSource() == getTrajectoryButton()) { getJTextFieldNumOfTrials().setEnabled(false); getJTextFieldNumOfParallelLocalRuns().setEnabled(false); - setNewOptions(); + getJTextFieldNumOfParallelLocalRuns().setText(""); + solverTaskDescription.setNumTrials(1); + getJTextFieldNumOfTrials().setText(""); } else if (e.getSource() == getMultiRunButton()) { getJTextFieldNumOfTrials().setEnabled(true); - getJTextFieldNumOfParallelLocalRuns().setEnabled(true); - setNewOptions(); + getJTextFieldNumOfParallelLocalRuns().setEnabled(false); + getJTextFieldNumOfParallelLocalRuns().setText(solverTaskDescription.getLangevinSimulationOptions().getNumOfParallelLocalRuns()+""); + int numTrials = solverTaskDescription.getNumTrials(); + if(numTrials > 1) { // a multi-trial number is already set + getJTextFieldNumOfTrials().setText(numTrials+""); + } else { + solverTaskDescription.setNumTrials(SolverTaskDescription.DefaultNumTrials); + getJTextFieldNumOfTrials().setText(SolverTaskDescription.DefaultNumTrials+""); + } } else if(e.getSource() == randomSeedCheckBox) { randomSeedTextField.setEditable(randomSeedCheckBox.isSelected()); if(randomSeedCheckBox.isSelected()) { - Integer rs = solverTaskDescription.getLangevinSimulationOptions().getRandomSeed(); + BigInteger rs = solverTaskDescription.getLangevinSimulationOptions().getRandomSeed(); if(rs == null) { rs = LangevinSimulationOptions.DefaultRandomSeed; solverTaskDescription.getLangevinSimulationOptions().setRandomSeed(rs); @@ -87,7 +98,11 @@ public void actionPerformed(java.awt.event.ActionEvent e) { solverTaskDescription.getLangevinSimulationOptions().setRandomSeed(null); randomSeedTextField.setText(""); } - + } else if(e.getSource() == randomSeedHelpButton) { + DialogUtils.showInfoDialogAndResize(LangevinOptionsPanel.this, "Set specific seed", + "Provide a seed to the Langevin solver's random number generator so exact " + + "trajectories can be reproduced. If this value is not entered, the solver will " + + "generate different sequences for each run."); } } @@ -98,14 +113,29 @@ public void focusLost(java.awt.event.FocusEvent e) { if (e.isTemporary()) { return; } - if (e.getSource() == getJTextFieldNumOfTrials() || - e.getSource() == getJTextFieldNumOfParallelLocalRuns() || + if (e.getSource() == getJTextFieldNumOfParallelLocalRuns() || e.getSource() == getJTextFieldIntervalImage() || e.getSource() == getJTextFieldIntervalSpring() || e.getSource() == getNumPartitionsXTextField() || e.getSource() == getNumPartitionsYTextField() || - e.getSource() == getNumPartitionsXTextField()) { + e.getSource() == getNumPartitionsXTextField() || + e.getSource() == getRandomSeedTextField() ) { setNewOptions(); + } else if(e.getSource() == getJTextFieldNumOfTrials()) { + int numTrials; + try { + numTrials = Integer.parseInt(getJTextFieldNumOfTrials().getText()); + if(numTrials < 2) { + numTrials = SolverTaskDescription.DefaultNumTrials; + } + } catch(NumberFormatException ex) { + numTrials = solverTaskDescription.getNumTrials(); + if(numTrials < 2) { + numTrials = SolverTaskDescription.DefaultNumTrials; + } + } + solverTaskDescription.setNumTrials(numTrials); + getJTextFieldNumOfTrials().setText(numTrials+""); } } } @@ -127,6 +157,8 @@ private void initialize() { centerPanel.setLayout(new GridBagLayout()); JPanel rightPanel = new JPanel(new GridBagLayout()); // fake panel, for looks rightPanel.setLayout(new GridBagLayout()); + JPanel bottomPanel = new JPanel(new GridBagLayout()); + bottomPanel.setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = 0; @@ -155,6 +187,16 @@ private void initialize() { gbc.insets = new Insets(1,1,1,1); getContentPanel().add(rightPanel, gbc); + gbc = new GridBagConstraints(); + gbc.gridx = 0; + gbc.gridy = 1; + gbc.fill = GridBagConstraints.HORIZONTAL; + gbc.gridwidth = 3; +// gbc.weightx = 1.0; +// gbc.weighty = 1.0; + gbc.insets = new Insets(1,1,1,1); + getContentPanel().add(bottomPanel, gbc); + // ----- trialPanel -------------------------------------------------------------- gbc = new GridBagConstraints(); gbc.gridx = 0; @@ -261,15 +303,6 @@ private void initialize() { gbc.insets = new Insets(0,5,3,1); trialPanel.add(getNumPartitionsZTextField(), gbc); - gbc = new GridBagConstraints(); - gbc.gridx = 0; - gbc.gridy = 6; - gbc.anchor = GridBagConstraints.WEST; - gbc.fill = GridBagConstraints.HORIZONTAL; - gbc.insets = new Insets(5,5,3,1); - trialPanel.add(getRandomSeedCheckBox(), gbc); - - // gbc = new GridBagConstraints(); // --- empty panel (filler) // gbc.gridx = 3; // gbc.gridy = 1; @@ -334,34 +367,42 @@ private void initialize() { gbc.weighty = 1.0; centerPanel.add(new JLabel(""), gbc); + // ----- rightPanel ---------------------------------------------------- + gbc = new GridBagConstraints(); + gbc.gridx = 3; + gbc.gridy = 0; + gbc.anchor = GridBagConstraints.WEST; + gbc.fill = GridBagConstraints.BOTH; + gbc.weightx = 1.0; + gbc.weighty = 1.0; + gbc.insets = new Insets(0,22,1,6); + rightPanel.add(new JLabel(""), gbc); // fake, just for looks + + // ----- bottomPanel ------------------------------------------------------ gbc = new GridBagConstraints(); gbc.gridx = 0; - gbc.gridy = 3; + gbc.gridy = 0; + gbc.anchor = GridBagConstraints.WEST; + gbc.fill = GridBagConstraints.HORIZONTAL; + gbc.insets = new Insets(5,2,6,5); + bottomPanel.add(getRandomSeedCheckBox(), gbc); + + gbc = new GridBagConstraints(); + gbc.gridx = 1; + gbc.gridy = 0; gbc.weightx = 1; gbc.gridwidth = 2; - gbc.insets = new Insets(0, 0, 6, 6); + gbc.insets = new Insets(2, 2, 6, 6); gbc.fill = GridBagConstraints.HORIZONTAL; gbc.anchor = GridBagConstraints.LINE_START; - centerPanel.add(getRandomSeedTextField(), gbc); + bottomPanel.add(getRandomSeedTextField(), gbc); - gbc = new GridBagConstraints(); - gbc.gridx = 2; - gbc.gridy = 3; - gbc.anchor = GridBagConstraints.LINE_END; - gbc.insets = new Insets(0, 0, 6, 6); - centerPanel.add(getRandomSeedHelpButton(), gbc); - - - // ----- rightPanel ---------------------------------------------------- gbc = new GridBagConstraints(); gbc.gridx = 3; gbc.gridy = 0; gbc.anchor = GridBagConstraints.WEST; - gbc.fill = GridBagConstraints.BOTH; - gbc.weightx = 1.0; - gbc.weighty = 1.0; - gbc.insets = new Insets(0,22,1,6); - rightPanel.add(new JLabel(""), gbc); // fake, just for looks + gbc.insets = new Insets(2, 2, 6, 6); + bottomPanel.add(getRandomSeedHelpButton(), gbc); // ---------------------------------------------------------------------- getButtonGroupTrials().add(getTrajectoryButton()); @@ -420,7 +461,7 @@ private javax.swing.JTextField getJTextFieldNumOfTrials() { ivjJTextFieldNumOfTrials = new javax.swing.JTextField(); ivjJTextFieldNumOfTrials.setName("JTextFieldNumOfTrials"); ivjJTextFieldNumOfTrials.setColumns(9); - ivjJTextFieldNumOfTrials.setText("100"); + ivjJTextFieldNumOfTrials.setText(""); } catch (java.lang.Throwable ivjExc) { handleException(ivjExc); } @@ -451,7 +492,6 @@ private JTextField getRandomSeedTextField() { if(randomSeedTextField == null) { randomSeedTextField = new JTextField(); randomSeedTextField.setName("RandomSeedTextField"); - randomSeedTextField.setText(""); } return randomSeedTextField; } @@ -463,7 +503,7 @@ private JButton getRandomSeedHelpButton() { randomSeedHelpButton.setName("RandomSeedHelpButton"); randomSeedHelpButton.setBorder(border); randomSeedHelpButton.setFont(font); - randomSeedHelpButton.setText(" ? "); + randomSeedHelpButton.setText("  ?  "); } return randomSeedHelpButton; } @@ -563,7 +603,7 @@ private javax.swing.JTextField getJTextFieldNumOfParallelLocalRuns() { ivjJTextFieldNumOfParallelLocalRuns = new javax.swing.JTextField(); ivjJTextFieldNumOfParallelLocalRuns.setName("JTextFieldNumOfParallelLocalRuns"); ivjJTextFieldNumOfParallelLocalRuns.setColumns(3); - ivjJTextFieldNumOfParallelLocalRuns.setText("1"); + ivjJTextFieldNumOfParallelLocalRuns.setText(""); } catch (java.lang.Throwable ivjExc) { handleException(ivjExc); } @@ -638,7 +678,9 @@ public final void setSolverTaskDescription(SolverTaskDescription newValue) { private void initConnections() { getTrajectoryButton().addActionListener(ivjEventHandler); getMultiRunButton().addActionListener(ivjEventHandler); - + getRandomSeedCheckBox().addActionListener(ivjEventHandler); + getRandomSeedHelpButton().addActionListener(ivjEventHandler); + getJTextFieldNumOfTrials().addFocusListener(ivjEventHandler); getJTextFieldNumOfParallelLocalRuns().addFocusListener(ivjEventHandler); getJTextFieldIntervalImage().addFocusListener(ivjEventHandler); @@ -646,6 +688,7 @@ private void initConnections() { getNumPartitionsXTextField().addFocusListener(ivjEventHandler); getNumPartitionsYTextField().addFocusListener(ivjEventHandler); getNumPartitionsZTextField().addFocusListener(ivjEventHandler); + getRandomSeedTextField().addFocusListener(ivjEventHandler); } private void refresh() { @@ -657,19 +700,23 @@ private void refresh() { return; } setVisible(true); - + + getMultiRunButton().setEnabled(true); + LangevinSimulationOptions lso = solverTaskDescription.getLangevinSimulationOptions(); - int numTrials = lso.getNumTrials(); + int numTrials = solverTaskDescription.getNumTrials(); int numOfParallelLocalRuns = lso.getNumOfParallelLocalRuns(); if(numTrials == 1) { getTrajectoryButton().setSelected(true); getJTextFieldNumOfTrials().setEnabled(false); + getJTextFieldNumOfTrials().setText(""); getJTextFieldNumOfParallelLocalRuns().setEnabled(false); + getJTextFieldNumOfParallelLocalRuns().setText(""); } else { getMultiRunButton().setSelected(true); getJTextFieldNumOfTrials().setEnabled(true); getJTextFieldNumOfTrials().setText(numTrials+""); - getJTextFieldNumOfParallelLocalRuns().setEnabled(true); + getJTextFieldNumOfParallelLocalRuns().setEnabled(false); getJTextFieldNumOfParallelLocalRuns().setText(numOfParallelLocalRuns + ""); } @@ -680,14 +727,16 @@ private void refresh() { getJTextFieldIntervalImage().setText(lso.getIntervalImage()+""); getJTextFieldIntervalSpring().setText(lso.getIntervalSpring()+""); - // TODO: temporarily disable the button - // UNDO THIS WHEN DEVELOPMENT IS COMPLETE - if(solverTaskDescription.getSolverDescription().isLangevinSolver()) { - getMultiRunButton().setEnabled(false); - return; + BigInteger randomSeed = lso.getRandomSeed(); + if (randomSeed == null) { + randomSeedTextField.setEditable(false); + randomSeedCheckBox.setSelected(false); + randomSeedTextField.setText(""); + } else { + randomSeedTextField.setEditable(true); + randomSeedCheckBox.setSelected(true); + randomSeedTextField.setText(randomSeed.toString()); } - - } private void setNewOptions() { @@ -696,27 +745,29 @@ private void setNewOptions() { } try { LangevinSimulationOptions sso = solverTaskDescription.getLangevinSimulationOptions(); - int numTrials = 1; int numOfParallelLocalRuns = 1; double intervalImage = solverTaskDescription.getLangevinSimulationOptions().getIntervalImage(); double intervalSpring = solverTaskDescription.getLangevinSimulationOptions().getIntervalSpring(); int[] npart = solverTaskDescription.getLangevinSimulationOptions().getNPart(); - if(getMultiRunButton().isSelected()) { - numTrials = Integer.parseInt(getJTextFieldNumOfTrials().getText()); - numOfParallelLocalRuns = Integer.parseInt(getJTextFieldNumOfParallelLocalRuns().getText()); + if(getMultiRunButton().isSelected()) { // we can get here only on FocusLost event in the numOfTrials text field + try { + numOfParallelLocalRuns = Integer.parseInt(getJTextFieldNumOfParallelLocalRuns().getText()); + } catch (NumberFormatException ex) { + numOfParallelLocalRuns = sso.getNumOfParallelLocalRuns(); + } } - Integer randomSeed = null; + BigInteger randomSeed = null; if (randomSeedCheckBox.isSelected()) { try { - randomSeed = Integer.valueOf(randomSeedTextField.getText()); + randomSeed = new BigInteger(randomSeedTextField.getText()); } catch (NumberFormatException ex) { randomSeed = solverTaskDescription.getLangevinSimulationOptions().getRandomSeed(); if(randomSeed == null) { randomSeed = LangevinSimulationOptions.DefaultRandomSeed; } - randomSeedTextField.setText(randomSeed.toString()); +// randomSeedTextField.setText(randomSeed.toString()); } } @@ -729,7 +780,6 @@ private void setNewOptions() { // make a copy LangevinSimulationOptions lso = new LangevinSimulationOptions(sso); - lso.setNumTrials(numTrials); lso.setNumOfParallelLocalRuns(numOfParallelLocalRuns); lso.setRandomSeed(randomSeed); lso.setIntervalImage(intervalImage); diff --git a/vcell-core/src/main/java/cbit/vcell/math/VCML.java b/vcell-core/src/main/java/cbit/vcell/math/VCML.java index d4a27a02ae..f264b6277c 100644 --- a/vcell-core/src/main/java/cbit/vcell/math/VCML.java +++ b/vcell-core/src/main/java/cbit/vcell/math/VCML.java @@ -244,8 +244,7 @@ public class VCML { public final static String VolumeParticleSpeciesPatterns = "VolumeParticleSpeciesPatterns"; public final static String LangevinSimulationOptions = "LangevinSimulationOptions"; - public final static String LangevinSimulationOptions_numOfTrials = "NumOfTrials"; - public final static String LangevinSimulationOptions_runIndex = "RunIndex"; + public final static String LangevinSimulationOptions_randomSeed = "RandomSeed"; public final static String LangevinSimulationOptions_intervalSpring = "IntervalSpring"; public final static String LangevinSimulationOptions_intervalImage = "IntervalImage"; public final static String LangevinSimulationOptions_Partition_Nx = "PartitionNx"; diff --git a/vcell-core/src/main/java/cbit/vcell/solver/LangevinSimulationOptions.java b/vcell-core/src/main/java/cbit/vcell/solver/LangevinSimulationOptions.java index 4716d1a9ba..9cc9136252 100644 --- a/vcell-core/src/main/java/cbit/vcell/solver/LangevinSimulationOptions.java +++ b/vcell-core/src/main/java/cbit/vcell/solver/LangevinSimulationOptions.java @@ -17,6 +17,7 @@ import java.beans.VetoableChangeListener; import java.beans.VetoableChangeSupport; import java.io.Serializable; +import java.math.BigInteger; import org.vcell.util.CommentStringTokenizer; import org.vcell.util.DataAccessException; @@ -41,13 +42,11 @@ public class LangevinSimulationOptions implements Serializable, Matchable, Vetoa public final static int[] DefaultNPart = { 10, 10, 10 }; - public final static int DefaultRandomSeed = 1; - public final static int DefaultNumTrials = 1; + public final static BigInteger DefaultRandomSeed = new BigInteger("164200191287356961681"); + // randomSeed may be null, in which case the solver will generate its own randomSeed as it already does + protected BigInteger randomSeed = null; - protected int numTrials = DefaultNumTrials; // how many runs of the solver for this simulation protected int numOfParallelLocalRuns = 1; // how many instances of the solver run in parallel - protected int runIndex = 0; // run index, will result in Run0 (followed by Run1, 2,...) - protected Integer randomSeed = DefaultRandomSeed; protected double intervalSpring = 1.00E-9; // default: dtspring: 1.00E-9 - from advanced protected double intervalImage = 1.00E-4; // default: dtimage: 1.00E-4 - from advanced @@ -62,11 +61,11 @@ public LangevinSimulationOptions() { } public LangevinSimulationOptions(LangevinSimulationOptions langevinSimulationOptions) { - this(); // TODO: properly implement copy constructor + this(); + randomSeed = langevinSimulationOptions.randomSeed; + numOfParallelLocalRuns = langevinSimulationOptions.numOfParallelLocalRuns; intervalSpring = langevinSimulationOptions.intervalSpring; intervalImage = langevinSimulationOptions.intervalImage; - numTrials = langevinSimulationOptions.numTrials; - runIndex = langevinSimulationOptions.runIndex; npart[0] = langevinSimulationOptions.npart[0]; npart[1] = langevinSimulationOptions.npart[1]; npart[2] = langevinSimulationOptions.npart[2]; @@ -82,10 +81,10 @@ public boolean compareEqual(Matchable obj) { return false; } LangevinSimulationOptions langevinSimulationOptions = (LangevinSimulationOptions)obj; - if(numTrials != langevinSimulationOptions.numTrials) { + if(randomSeed != langevinSimulationOptions.randomSeed) { return false; } - if(runIndex != langevinSimulationOptions.runIndex) { + if(numOfParallelLocalRuns != langevinSimulationOptions.numOfParallelLocalRuns) { return false; } if(intervalSpring != langevinSimulationOptions.intervalSpring) { @@ -104,17 +103,6 @@ public boolean compareEqual(Matchable obj) { // ----------------------------------------------------------------------------------- // can be between 0 and numOfTrials-1 - public int getRunIndex() { // for multiple trials the runIndex must be incremented for each run, dynamically - if(runIndex > numTrials -1) { - throw new RuntimeException("Max run index must be smaller than the number of trials."); - } - int currentRunIndex = runIndex; - runIndex++; - return currentRunIndex; - } - public int getNumTrials() { - return numTrials; - } public int getNumOfParallelLocalRuns() { return numOfParallelLocalRuns; } @@ -130,16 +118,10 @@ public int getNPart(int index) { public int[] getNPart() { return npart; } - public Integer getRandomSeed() { + public BigInteger getRandomSeed() { return randomSeed; } - public final void setRunIndex(int newValue) { - this.runIndex = newValue; - } - public final void setNumTrials(int newValue) { - this.numTrials = newValue; - } public final void setNumOfParallelLocalRuns(int newValue) { this.numOfParallelLocalRuns = newValue; } @@ -157,7 +139,7 @@ public final void setNPart(int[] npart) { public final void setNPart(int index, int npart) { this.npart[index] = npart; } - public void setRandomSeed(Integer randomSeed) { + public void setRandomSeed(BigInteger randomSeed) { this.randomSeed = randomSeed; } @@ -197,8 +179,9 @@ private void fireVetoableChange(java.lang.String propertyName, java.lang.Object public String getVCML() { StringBuffer buffer = new StringBuffer(); buffer.append("\t" + VCML.LangevinSimulationOptions + " " + VCML.BeginBlock + "\n"); - buffer.append("\t\t" + VCML.LangevinSimulationOptions_numOfTrials + " " + numTrials + "\n"); - buffer.append("\t\t" + VCML.LangevinSimulationOptions_runIndex + " " + runIndex + "\n"); + if(randomSeed != null) { + buffer.append("\t\t" + VCML.LangevinSimulationOptions_randomSeed + " " + randomSeed + "\n"); + } buffer.append("\t\t" + VCML.LangevinSimulationOptions_intervalSpring + " " + intervalSpring + "\n"); buffer.append("\t\t" + VCML.LangevinSimulationOptions_intervalImage + " " + intervalImage + "\n"); buffer.append("\t\t" + VCML.LangevinSimulationOptions_Partition_Nx + " " + npart[0] + "\n"); @@ -223,9 +206,9 @@ public void readVCML(CommentStringTokenizer tokens) throws DataAccessException { if (token.equalsIgnoreCase(VCML.EndBlock)) { break; } - if(token.equalsIgnoreCase(VCML.LangevinSimulationOptions_runIndex)) { + if(token.equalsIgnoreCase(VCML.LangevinSimulationOptions_randomSeed)) { token = tokens.nextToken(); - runIndex = Integer.parseInt(token); + randomSeed = new BigInteger(token); } else if(token.equalsIgnoreCase(VCML.LangevinSimulationOptions_numOfParallelLocalRuns)) { token = tokens.nextToken(); numOfParallelLocalRuns = Integer.parseInt(token); @@ -244,15 +227,7 @@ public void readVCML(CommentStringTokenizer tokens) throws DataAccessException { } else if(token.equalsIgnoreCase(VCML.LangevinSimulationOptions_Partition_Nz)) { token = tokens.nextToken(); npart[2] = Integer.parseInt(token); - } else if (token.equalsIgnoreCase(VCML.LangevinSimulationOptions_numOfTrials)) { - token = tokens.nextToken(); - int val2 = Integer.parseInt(token); - if(val2 < 1 ) { - throw new DataAccessException("unexpected token " + token + ", num of trials is requied to be at least 1. "); - } else { - numTrials = val2; - } - } else { + } else { throw new DataAccessException("unexpected identifier " + token); } } diff --git a/vcell-core/src/main/java/cbit/vcell/solver/SolverTaskDescription.java b/vcell-core/src/main/java/cbit/vcell/solver/SolverTaskDescription.java index 5524c4d7c9..04789fd335 100644 --- a/vcell-core/src/main/java/cbit/vcell/solver/SolverTaskDescription.java +++ b/vcell-core/src/main/java/cbit/vcell/solver/SolverTaskDescription.java @@ -88,6 +88,7 @@ public String toString(){ } } + public final static int DefaultNumTrials = 20; private int numTrials = 1; // must have at least one trial (trivial case is numTrials=1) public void setNumTrials(int i) { @@ -190,6 +191,7 @@ public SolverTaskDescription(Simulation simulation, SolverTaskDescription solver bSerialParameterScan = solverTaskDescription.bSerialParameterScan; bTimeoutDisabled = solverTaskDescription.bTimeoutDisabled; bBorderExtrapolationDisabled = solverTaskDescription.bBorderExtrapolationDisabled; + numTrials = solverTaskDescription.numTrials; if(simulation.getMathDescription().isNonSpatialStoch() && (solverTaskDescription.getStochOpt() != null)){ setStochOpt(solverTaskDescription.getStochOpt()); @@ -344,7 +346,9 @@ public boolean compareEqual(Matchable object){ if(bBorderExtrapolationDisabled != solverTaskDescription.bBorderExtrapolationDisabled){ return false; } - + if(numTrials != solverTaskDescription.numTrials) { + return false; + } if(!Compare.isEqualOrNull(smoldynSimulationOptions, solverTaskDescription.smoldynSimulationOptions)){ return false; } diff --git a/vcell-core/src/main/java/cbit/vcell/xml/XMLTags.java b/vcell-core/src/main/java/cbit/vcell/xml/XMLTags.java index 6063ef22da..6dc5d394a6 100644 --- a/vcell-core/src/main/java/cbit/vcell/xml/XMLTags.java +++ b/vcell-core/src/main/java/cbit/vcell/xml/XMLTags.java @@ -800,13 +800,13 @@ public class XMLTags { // langevin (springsalad) solver simulation options public final static String LangevinSimulationOptions = "LangevinSimulationOptions"; - public final static String LangevinSO_numOfTrials = "NumOfTrials"; public final static String LangevinSO_intervalSpring = "IntervalSpring"; public final static String LangevinSO_intervalImage = "IntervalImage"; public final static String LangevinSO_Partition_Nx = "PartitionNx"; public final static String LangevinSO_Partition_Ny = "PartitionNy"; public final static String LangevinSO_Partition_Nz = "PartitionNz"; public final static String LangevinSO_numOfParallelLocalRuns = "NumOfParallelLocalRuns"; + public final static String LangevinSO_randomSeed = "RandomSeed"; public final static String ParticleInitialConcentrationTag = "ParticleInitialConcentration"; // particle public final static String ParticleDistributionTag = "ParticleDistribution"; // particle diff --git a/vcell-core/src/main/java/cbit/vcell/xml/XmlReader.java b/vcell-core/src/main/java/cbit/vcell/xml/XmlReader.java index 52cacae678..a3e03b2d50 100644 --- a/vcell-core/src/main/java/cbit/vcell/xml/XmlReader.java +++ b/vcell-core/src/main/java/cbit/vcell/xml/XmlReader.java @@ -11,6 +11,7 @@ package cbit.vcell.xml; import java.beans.PropertyVetoException; +import java.math.BigInteger; import java.text.SimpleDateFormat; import java.util.*; import java.util.function.Consumer; @@ -6696,10 +6697,6 @@ private NFsimSimulationOptions getNFSimSimulationOptions(Element nfsimSimulation private LangevinSimulationOptions getLangevinSimulationOptions(Element langevinSimulationOptionsElement) throws XmlParseException{ LangevinSimulationOptions lo = new LangevinSimulationOptions(); String temp = null; - temp = langevinSimulationOptionsElement.getChildText(XMLTags.LangevinSO_numOfTrials, vcNamespace); - if(temp != null){ - lo.setNumTrials(Integer.parseInt(temp)); - } temp = langevinSimulationOptionsElement.getChildText(XMLTags.LangevinSO_intervalSpring, vcNamespace); if(temp != null){ lo.setIntervalSpring(Double.parseDouble(temp)); @@ -6724,6 +6721,10 @@ private LangevinSimulationOptions getLangevinSimulationOptions(Element langevinS if(temp != null) { lo.setNumOfParallelLocalRuns(Integer.parseInt(temp)); } + temp = langevinSimulationOptionsElement.getChildText(XMLTags.LangevinSO_randomSeed, vcNamespace); + if(temp != null) { + lo.setRandomSeed(new BigInteger(temp)); + } return lo; } diff --git a/vcell-core/src/main/java/cbit/vcell/xml/Xmlproducer.java b/vcell-core/src/main/java/cbit/vcell/xml/Xmlproducer.java index 0610f31440..1690f007c2 100644 --- a/vcell-core/src/main/java/cbit/vcell/xml/Xmlproducer.java +++ b/vcell-core/src/main/java/cbit/vcell/xml/Xmlproducer.java @@ -4806,10 +4806,6 @@ private Element getXML(LangevinSimulationOptions lso) { Element e = null; Element lsoe = new Element(XMLTags.LangevinSimulationOptions); - e = new Element(XMLTags.LangevinSO_numOfTrials); - e.setText(String.valueOf(lso.getNumTrials())); - lsoe.addContent(e); - e = new Element(XMLTags.LangevinSO_intervalSpring); e.setText(String.valueOf(lso.getIntervalSpring())); lsoe.addContent(e); @@ -4834,6 +4830,11 @@ private Element getXML(LangevinSimulationOptions lso) { e.setText(String.valueOf(lso.getNumOfParallelLocalRuns())); lsoe.addContent(e); + if(lso.getRandomSeed() != null) { + e = new Element(XMLTags.LangevinSO_randomSeed); + e.setText(String.valueOf(lso.getRandomSeed())); + lsoe.addContent(e); + } // if (lso.getSomethingOptional() != null) { // e = new Element(XMLTags.NFSimSimulationOptions_moleculeDistance); diff --git a/vcell-core/src/main/java/org/vcell/solver/langevin/LangevinSolver.java b/vcell-core/src/main/java/org/vcell/solver/langevin/LangevinSolver.java index de4f437979..f88914ed10 100644 --- a/vcell-core/src/main/java/org/vcell/solver/langevin/LangevinSolver.java +++ b/vcell-core/src/main/java/org/vcell/solver/langevin/LangevinSolver.java @@ -197,13 +197,10 @@ protected String[] getMathExecutableCommand() { String messagingConfigOption = "--vc-send-status-config=" + getMessagingConfigFilename(); String localMessagingOption = "--vc-print-status"; - LangevinSimulationOptions lso = simTask.getSimulation().getSolverTaskDescription().getLangevinSimulationOptions(); - // TODO: Very important, in LangevinSolver.getMathExecutableCommand() (or somewhere else??) we should implement - // a loop for multiple runs, so that we could repeatedly launch the solver for the parallel runs. - // TODO: The Solver command line argument runIndex must be initialized with 0 and incremented for each run - // (remember not to launch more parralel processes than the numOfParallelLocalRuns variable) - int runIndex = lso.getRunIndex(); // run index - + // TODO: we'll probably eliminate this as command line argument, or set it correctly at some later time + // TODO: the correct value is the SolverTaskDescription TrialIndex variable + int trialIndex = 0; // run index + ArrayList cmds = new ArrayList<>(); cmds.add(executableName); // executable cmds.add("simulate"); // the new langevin solver made by jim wants this argument @@ -214,7 +211,7 @@ protected String[] getMathExecutableCommand() { cmds.add(localMessagingOption); // used for solver to send status to stdout/stderr; } cmds.add(inputFilename); // first argument - cmds.add(runIndex + ""); // second argument + cmds.add(trialIndex + ""); // second argument return cmds.toArray(new String[0]); } From 907f886e039cd07e259d1623075c1f3820297ce6 Mon Sep 17 00:00:00 2001 From: Dan Vasilescu Date: Thu, 19 Dec 2024 15:25:14 -0500 Subject: [PATCH 3/6] numTrials and randomSeed: persistence. tested database write / read, vcml file export / import --- vcell-core/src/main/java/cbit/vcell/math/VCML.java | 7 +++++-- .../java/cbit/vcell/solver/SolverTaskDescription.java | 9 ++++++++- vcell-core/src/main/java/cbit/vcell/xml/XMLTags.java | 3 ++- vcell-core/src/main/java/cbit/vcell/xml/XmlReader.java | 4 ++++ vcell-core/src/main/java/cbit/vcell/xml/Xmlproducer.java | 5 +++++ 5 files changed, 24 insertions(+), 4 deletions(-) diff --git a/vcell-core/src/main/java/cbit/vcell/math/VCML.java b/vcell-core/src/main/java/cbit/vcell/math/VCML.java index f264b6277c..75b946a1fa 100644 --- a/vcell-core/src/main/java/cbit/vcell/math/VCML.java +++ b/vcell-core/src/main/java/cbit/vcell/math/VCML.java @@ -227,7 +227,10 @@ public class VCML { public final static String ParticleComponentLocation = "Location"; // particle Langevin / SpringSaLaD public final static String ParticleComponentCoordinate = "Coordinate"; // particle Langevin / SpringSaLaD public final static String ParticleComponentColor = "NamedColor"; // particle Langevin / SpringSaLaD - + // 12/19/2024 Dan - SolverTaskDescription.numTrials that we'll use in Langevin / SpringSaLaD + // will generalize the use for anything stochastic (Gibson, NFSim, etc) that will imply parallel runs + public final static String SolverTaskDescriptionNumTrials = "SolverTaskDescriptionNumTrials"; // scan for generated random seed series + public final static String ParticleMolecularComponent = "Component"; public final static String ParticleComponentAllowableState = "AllowableState"; public final static String ParticleMolecularTypePattern = "MolecularType"; @@ -244,7 +247,7 @@ public class VCML { public final static String VolumeParticleSpeciesPatterns = "VolumeParticleSpeciesPatterns"; public final static String LangevinSimulationOptions = "LangevinSimulationOptions"; - public final static String LangevinSimulationOptions_randomSeed = "RandomSeed"; + public final static String LangevinSimulationOptions_randomSeed = "LangevinRandomSeed"; public final static String LangevinSimulationOptions_intervalSpring = "IntervalSpring"; public final static String LangevinSimulationOptions_intervalImage = "IntervalImage"; public final static String LangevinSimulationOptions_Partition_Nx = "PartitionNx"; diff --git a/vcell-core/src/main/java/cbit/vcell/solver/SolverTaskDescription.java b/vcell-core/src/main/java/cbit/vcell/solver/SolverTaskDescription.java index 04789fd335..71411e178a 100644 --- a/vcell-core/src/main/java/cbit/vcell/solver/SolverTaskDescription.java +++ b/vcell-core/src/main/java/cbit/vcell/solver/SolverTaskDescription.java @@ -690,6 +690,9 @@ public String getVCML(){ if(movingBoundarySolverOptions != null){ buffer.append(movingBoundarySolverOptions.getVCML() + "\n"); } + + buffer.append(VCML.SolverTaskDescriptionNumTrials + " " + getNumTrials() + "\n"); + buffer.append(VCML.EndBlock + "\n"); return buffer.toString(); @@ -1195,9 +1198,13 @@ public void readVCML(CommentStringTokenizer tokens) throws DataAccessException{ setSundialsPdeSolverOptions(new SundialsPdeSolverOptions(tokens)); } else if(token.equalsIgnoreCase(VCML.ChomboSolverSpec)){ chomboSolverSpec = new ChomboSolverSpec(tokens); - } else if(token.equalsIgnoreCase(VCML.NUM_PROCESSORS)){ + } else if(token.equalsIgnoreCase(VCML.NUM_PROCESSORS)) { token = tokens.nextToken(); numProcessors = Integer.parseInt(token); + } else if(token.equalsIgnoreCase(VCML.SolverTaskDescriptionNumTrials)) { + token = tokens.nextToken(); + int numTrials = Integer.parseInt(token); + setNumTrials(numTrials); } else if(token.equalsIgnoreCase(VCML.TimeoutSimulationDisabled)){ token = tokens.nextToken(); setTimeoutDisabled(Boolean.parseBoolean(token)); diff --git a/vcell-core/src/main/java/cbit/vcell/xml/XMLTags.java b/vcell-core/src/main/java/cbit/vcell/xml/XMLTags.java index 6dc5d394a6..8051c46652 100644 --- a/vcell-core/src/main/java/cbit/vcell/xml/XMLTags.java +++ b/vcell-core/src/main/java/cbit/vcell/xml/XMLTags.java @@ -199,6 +199,7 @@ public class XMLTags { public final static String RunParameterScanSerially = "RunParameterScanSerially"; public final static String TimeoutSimulationDisabled = "TimeoutSimulationDisabled"; public final static String BorderExtrapolationDisabled = "BorderExtrapolationDisabled"; + public final static String SolverTaskDescriptionNumTrials = "SolverTaskDescriptionNumTrials"; //End-Simulation @@ -806,7 +807,7 @@ public class XMLTags { public final static String LangevinSO_Partition_Ny = "PartitionNy"; public final static String LangevinSO_Partition_Nz = "PartitionNz"; public final static String LangevinSO_numOfParallelLocalRuns = "NumOfParallelLocalRuns"; - public final static String LangevinSO_randomSeed = "RandomSeed"; + public final static String LangevinSO_randomSeed = "LangevinRandomSeed"; public final static String ParticleInitialConcentrationTag = "ParticleInitialConcentration"; // particle public final static String ParticleDistributionTag = "ParticleDistribution"; // particle diff --git a/vcell-core/src/main/java/cbit/vcell/xml/XmlReader.java b/vcell-core/src/main/java/cbit/vcell/xml/XmlReader.java index a3e03b2d50..fdc9d4067a 100644 --- a/vcell-core/src/main/java/cbit/vcell/xml/XmlReader.java +++ b/vcell-core/src/main/java/cbit/vcell/xml/XmlReader.java @@ -6562,9 +6562,11 @@ private SolverTaskDescription getSolverTaskDescription(Element param, Simulation throw new XmlParseException("A PropertyVetoException was fired when setting the taskType: " + taskType, e); } int numProcessors = parseIntWithDefault(param, XMLTags.NUM_PROCESSORS, 1); + int numTrials = parseIntWithDefault(param, XMLTags.SolverTaskDescriptionNumTrials, 1); try { solverTaskDesc.setNumProcessors(numProcessors); + solverTaskDesc.setNumTrials(numTrials); solverTaskDesc.setUseSymbolicJacobian(useSymJacob); //get TimeBound solverTaskDesc.setTimeBounds(getTimeBounds(param.getChild(XMLTags.TimeBoundTag, vcNamespace))); @@ -6724,6 +6726,8 @@ private LangevinSimulationOptions getLangevinSimulationOptions(Element langevinS temp = langevinSimulationOptionsElement.getChildText(XMLTags.LangevinSO_randomSeed, vcNamespace); if(temp != null) { lo.setRandomSeed(new BigInteger(temp)); + } else { + lo.setRandomSeed(null); } return lo; } diff --git a/vcell-core/src/main/java/cbit/vcell/xml/Xmlproducer.java b/vcell-core/src/main/java/cbit/vcell/xml/Xmlproducer.java index 1690f007c2..31c25ddeef 100644 --- a/vcell-core/src/main/java/cbit/vcell/xml/Xmlproducer.java +++ b/vcell-core/src/main/java/cbit/vcell/xml/Xmlproducer.java @@ -4757,6 +4757,11 @@ private Element getXML(SolverTaskDescription param) { Element numProcessors= new Element(XMLTags.NUM_PROCESSORS); numProcessors.setText(Integer.toString(param.getNumProcessors())); solvertask.addContent(numProcessors); + + Element numTrials = new Element(XMLTags.SolverTaskDescriptionNumTrials); + numTrials.setText(Integer.toString(param.getNumTrials())); + solvertask.addContent(numTrials); + return solvertask; } private Element getXML(NFsimSimulationOptions sso) { // we know that sso is not null, no need to check again From f225062ad77e73dcc1c8f9edf6dcd862d88a1187 Mon Sep 17 00:00:00 2001 From: Dan Vasilescu Date: Fri, 20 Dec 2024 13:14:50 -0500 Subject: [PATCH 4/6] looking in simTask for simulation job and get index --- .../java/org/vcell/solver/langevin/LangevinSolver.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/vcell-core/src/main/java/org/vcell/solver/langevin/LangevinSolver.java b/vcell-core/src/main/java/org/vcell/solver/langevin/LangevinSolver.java index f88914ed10..1ccbb7fd29 100644 --- a/vcell-core/src/main/java/org/vcell/solver/langevin/LangevinSolver.java +++ b/vcell-core/src/main/java/org/vcell/solver/langevin/LangevinSolver.java @@ -197,9 +197,13 @@ protected String[] getMathExecutableCommand() { String messagingConfigOption = "--vc-send-status-config=" + getMessagingConfigFilename(); String localMessagingOption = "--vc-print-status"; - // TODO: we'll probably eliminate this as command line argument, or set it correctly at some later time - // TODO: the correct value is the SolverTaskDescription TrialIndex variable - int trialIndex = 0; // run index + int trialIndex; // run index + String simJobId = simTask.getSimulationJobID(); + try { + trialIndex = Integer.parseInt(simJobId); + } catch(NumberFormatException e) { + trialIndex = 0; + } ArrayList cmds = new ArrayList<>(); cmds.add(executableName); // executable From 1c953ef426ce5d508b93e85306bf8b32a3e549cb Mon Sep 17 00:00:00 2001 From: Dan Vasilescu Date: Fri, 20 Dec 2024 14:17:52 -0500 Subject: [PATCH 5/6] looking in simTask for trial index --- .../main/java/org/vcell/solver/langevin/LangevinSolver.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/vcell-core/src/main/java/org/vcell/solver/langevin/LangevinSolver.java b/vcell-core/src/main/java/org/vcell/solver/langevin/LangevinSolver.java index 1ccbb7fd29..da8f6597ee 100644 --- a/vcell-core/src/main/java/org/vcell/solver/langevin/LangevinSolver.java +++ b/vcell-core/src/main/java/org/vcell/solver/langevin/LangevinSolver.java @@ -198,9 +198,8 @@ protected String[] getMathExecutableCommand() { String localMessagingOption = "--vc-print-status"; int trialIndex; // run index - String simJobId = simTask.getSimulationJobID(); try { - trialIndex = Integer.parseInt(simJobId); + trialIndex = simTask.getSimulationJob().getTrialIndex().index; } catch(NumberFormatException e) { trialIndex = 0; } From c604e06f8ceeabb06aa6c1b6611653aee0ebbecc Mon Sep 17 00:00:00 2001 From: Dan Vasilescu Date: Fri, 20 Dec 2024 16:55:24 -0500 Subject: [PATCH 6/6] try - catch not needed --- .../java/org/vcell/solver/langevin/LangevinSolver.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/vcell-core/src/main/java/org/vcell/solver/langevin/LangevinSolver.java b/vcell-core/src/main/java/org/vcell/solver/langevin/LangevinSolver.java index da8f6597ee..e947380023 100644 --- a/vcell-core/src/main/java/org/vcell/solver/langevin/LangevinSolver.java +++ b/vcell-core/src/main/java/org/vcell/solver/langevin/LangevinSolver.java @@ -197,12 +197,7 @@ protected String[] getMathExecutableCommand() { String messagingConfigOption = "--vc-send-status-config=" + getMessagingConfigFilename(); String localMessagingOption = "--vc-print-status"; - int trialIndex; // run index - try { - trialIndex = simTask.getSimulationJob().getTrialIndex().index; - } catch(NumberFormatException e) { - trialIndex = 0; - } + int trialIndex = simTask.getSimulationJob().getTrialIndex().index; // run index ArrayList cmds = new ArrayList<>(); cmds.add(executableName); // executable