use of cbit.vcell.solver.server.SolverStatus in project vcell by virtualcell.
the class StandaloneRuleBasedTest method runsolver.
// private static void printout(String printThis){
// System.out.flush();
// disableSystemOut(false);
// System.out.print(printThis);
// System.out.flush();
// disableSystemOut(true);
// }
private static void runsolver(Simulation newSimulation, File baseDirectory, int numRuns, TimeSeriesMultitrialData timeSeriesMultitrialData) {
Simulation versSimulation = null;
File destDir = null;
// int progress = 1;
for (int trialIndex = 0; trialIndex < numRuns; trialIndex++) {
// }
try {
versSimulation = new TempSimulation(newSimulation, false);
// printout(ruleBasedTestDir.getAbsolutePath());
destDir = new File(baseDirectory, timeSeriesMultitrialData.datasetName);
SimulationTask simTask = new SimulationTask(new SimulationJob(versSimulation, 0, null), 0);
Solver solver = ClientSimManager.createQuickRunSolver(destDir, simTask);
solver.startSolver();
while (true) {
try {
Thread.sleep(250);
} catch (InterruptedException e) {
e.printStackTrace();
}
SolverStatus solverStatus = solver.getSolverStatus();
if (solverStatus != null) {
if (solverStatus.getStatus() == SolverStatus.SOLVER_ABORTED) {
throw new RuntimeException(solverStatus.getSimulationMessage().getDisplayMessage());
}
if (solverStatus.getStatus() != SolverStatus.SOLVER_STARTING && solverStatus.getStatus() != SolverStatus.SOLVER_READY && solverStatus.getStatus() != SolverStatus.SOLVER_RUNNING) {
break;
}
}
}
SimulationData simData = new SimulationData(simTask.getSimulationJob().getVCDataIdentifier(), destDir, null, null);
ODEDataBlock odeDataBlock = simData.getODEDataBlock();
ODESimData odeSimData = odeDataBlock.getODESimData();
timeSeriesMultitrialData.addDataSet(odeSimData, trialIndex);
} catch (Exception e) {
e.printStackTrace();
File file = new File(baseDirectory, Simulation.createSimulationID(versSimulation.getKey()) + "_solverExc.txt");
StochtestFileUtils.writeMessageTofile(file, e.getMessage());
}
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
StochtestFileUtils.clearDir(destDir);
}
// printout("\n");
}
use of cbit.vcell.solver.server.SolverStatus in project vcell by virtualcell.
the class FRAPStudy method runFVSolverStandalone_ref.
public static void runFVSolverStandalone_ref(File simulationDataDir, Simulation sim, ExternalDataIdentifier imageDataExtDataID, ExternalDataIdentifier roiExtDataID, ExternalDataIdentifier psfExtDataID, ClientTaskStatusSupport progressListener, boolean bCheckSteadyState) throws Exception {
FieldFunctionArguments[] fieldFunctionArgs = FieldUtilities.getFieldFunctionArguments(sim.getMathDescription());
FieldDataIdentifierSpec[] fieldDataIdentifierSpecs = new FieldDataIdentifierSpec[fieldFunctionArgs.length];
for (int i = 0; i < fieldDataIdentifierSpecs.length; i++) {
if (fieldFunctionArgs[i].getFieldName().equals(imageDataExtDataID.getName())) {
fieldDataIdentifierSpecs[i] = new FieldDataIdentifierSpec(fieldFunctionArgs[i], imageDataExtDataID);
} else if (fieldFunctionArgs[i].getFieldName().equals(roiExtDataID.getName())) {
fieldDataIdentifierSpecs[i] = new FieldDataIdentifierSpec(fieldFunctionArgs[i], roiExtDataID);
} else if (fieldFunctionArgs[i].getFieldName().equals(psfExtDataID.getName())) {
fieldDataIdentifierSpecs[i] = new FieldDataIdentifierSpec(fieldFunctionArgs[i], psfExtDataID);
} else {
throw new RuntimeException("failed to resolve field named " + fieldFunctionArgs[i].getFieldName());
}
}
int jobIndex = 0;
SimulationTask simTask = new SimulationTask(new SimulationJob(sim, jobIndex, fieldDataIdentifierSpecs), 0);
SolverUtilities.prepareSolverExecutable(sim.getSolverTaskDescription().getSolverDescription());
// if we need to check steady state, do the following two lines
if (bCheckSteadyState) {
simTask.getSimulation().getSolverTaskDescription().setStopAtSpatiallyUniformErrorTolerance(ErrorTolerance.getDefaultSpatiallyUniformErrorTolerance());
// simJob.getSimulation().getSolverTaskDescription().setErrorTolerance(new ErrorTolerance(1e-6, 1e-2));
}
FVSolverStandalone fvSolver = new FVSolverStandalone(simTask, simulationDataDir, false);
fvSolver.startSolver();
SolverStatus status = fvSolver.getSolverStatus();
while (status.getStatus() != SolverStatus.SOLVER_FINISHED && status.getStatus() != SolverStatus.SOLVER_ABORTED) {
if (progressListener != null) {
progressListener.setProgress((int) (fvSolver.getProgress() * 100));
if (progressListener.isInterrupted()) {
fvSolver.stopSolver();
throw UserCancelException.CANCEL_GENERIC;
}
}
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
ex.printStackTrace(System.out);
// catch interrupted exception and ignore it, otherwise it will popup a dialog in user interface saying"sleep interrupted"
}
status = fvSolver.getSolverStatus();
}
if (status.getStatus() != SolverStatus.SOLVER_FINISHED) {
throw new Exception("Sover did not finish normally." + status);
}
}
use of cbit.vcell.solver.server.SolverStatus in project vcell by virtualcell.
the class NFSimSolver method initialize.
/**
* This method takes the place of the old runUnsteady()...
*/
protected void initialize() throws SolverException {
if (lg.isTraceEnabled())
lg.trace("NFSimSolver.initialize()");
fireSolverStarting(SimulationMessage.MESSAGE_SOLVEREVENT_STARTING_INIT);
writeFunctionsFile();
String inputFilename = getInputFilename();
if (lg.isTraceEnabled())
lg.trace("NFSimSolver.initialize() inputFilename = " + getInputFilename());
setSolverStatus(new SolverStatus(SolverStatus.SOLVER_RUNNING, SimulationMessage.MESSAGE_SOLVER_RUNNING_INPUT_FILE));
fireSolverStarting(SimulationMessage.MESSAGE_SOLVEREVENT_STARTING_INPUT_FILE);
try (PrintWriter pw = new PrintWriter(inputFilename)) {
NFSimFileWriter stFileWriter = new NFSimFileWriter(pw, simTask, bMessaging);
stFileWriter.write();
} catch (Exception e) {
setSolverStatus(new SolverStatus(SolverStatus.SOLVER_ABORTED, SimulationMessage.solverAborted("Could not generate input file: " + e.getMessage())));
e.printStackTrace(System.out);
throw new SolverException(e.getMessage());
}
PrintWriter lg = null;
String logFilename = getLogFilename();
String outputFilename = getOutputFilename();
try {
lg = new PrintWriter(logFilename);
String shortOutputFilename = outputFilename.substring(1 + outputFilename.lastIndexOf("\\"));
lg.println(NFSIM_DATA_IDENTIFIER + " " + shortOutputFilename);
} catch (Exception e) {
setSolverStatus(new SolverStatus(SolverStatus.SOLVER_ABORTED, SimulationMessage.solverAborted("Could not generate log file: " + e.getMessage())));
e.printStackTrace(System.out);
throw new SolverException(e.getMessage());
} finally {
if (lg != null) {
lg.close();
}
}
setSolverStatus(new SolverStatus(SolverStatus.SOLVER_RUNNING, SimulationMessage.MESSAGE_SOLVER_RUNNING_START));
// get executable path+name.
setMathExecutable(new MathExecutable(getMathExecutableCommand(), getSaveDirectory()));
// setMathExecutable(new
// cbit.vcell.solvers.MathExecutable(executableName + " gibson " +
// getBaseName() + ".stochInput" + " " + getBaseName() + ".stoch"));
}
use of cbit.vcell.solver.server.SolverStatus in project vcell by virtualcell.
the class RunSimulation2DOp method runFVSolverStandalone.
private static void runFVSolverStandalone(File simulationDataDir, Simulation sim, ClientTaskStatusSupport progressListener) throws Exception {
int jobIndex = 0;
SimulationTask simTask = new SimulationTask(new SimulationJob(sim, jobIndex, null), 0);
SolverUtilities.prepareSolverExecutable(sim.getSolverTaskDescription().getSolverDescription());
FVSolverStandalone fvSolver = new FVSolverStandalone(simTask, simulationDataDir, false);
fvSolver.startSolver();
// fvSolver.runSolver();
SolverStatus status = fvSolver.getSolverStatus();
while (status.getStatus() != SolverStatus.SOLVER_FINISHED && status.getStatus() != SolverStatus.SOLVER_ABORTED && status.getStatus() != SolverStatus.SOLVER_STOPPED) {
if (progressListener != null) {
progressListener.setProgress((int) (fvSolver.getProgress() * 100));
if (progressListener.isInterrupted()) {
fvSolver.stopSolver();
throw UserCancelException.CANCEL_GENERIC;
}
}
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
ex.printStackTrace(System.out);
// catch interrupted exception and ignore it, otherwise it will popup a dialog in user interface saying"sleep interrupted"
}
status = fvSolver.getSolverStatus();
}
if (status.getStatus() != SolverStatus.SOLVER_FINISHED) {
throw new Exception("Sover did not finish normally." + status);
}
}
use of cbit.vcell.solver.server.SolverStatus in project vcell by virtualcell.
the class JavaSimulationExecutable method runSimulation.
private void runSimulation() throws SolverException {
solver = SolverFactory.createSolver(new File(userDirectory), simulationTask, true);
solver.addSolverListener(new SolverListener() {
public final void solverAborted(SolverEvent event) {
sendFailed(event.getSimulationMessage());
}
public final void solverFinished(SolverEvent event) {
sendCompleted(event.getProgress(), event.getTimePoint(), event.getSimulationMessage());
}
public final void solverPrinted(SolverEvent event) {
// can never get data messages here
sendNewData(event.getProgress(), event.getTimePoint(), event.getSimulationMessage());
}
public final void solverProgress(SolverEvent event) {
// can never get progress message here
sendProgress(event.getProgress(), event.getTimePoint(), event.getSimulationMessage());
}
public final void solverStarting(SolverEvent event) {
sendStarting(event.getSimulationMessage());
}
public final void solverStopped(SolverEvent event) {
if (lg.isTraceEnabled())
lg.trace("Caught solverStopped(" + event.getSource() + ")");
// Don't send message anymore because the dispatcher will update the database anyway no matter if the worker responds
// workerMessaging.sendStopped(event.getProgress(), event.getTimePoint());
}
});
solver.startSolver();
while (true) {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
}
cbit.vcell.solver.server.SolverStatus solverStatus = solver.getSolverStatus();
if (solverStatus != null) {
if (solverStatus.getStatus() != SolverStatus.SOLVER_STARTING && solverStatus.getStatus() != SolverStatus.SOLVER_READY && solverStatus.getStatus() != SolverStatus.SOLVER_RUNNING) {
break;
}
}
}
}
Aggregations