Search in sources :

Example 1 with Solver

use of cbit.vcell.solver.server.Solver in project vcell by virtualcell.

the class StochtestRunService method runsolver.

private static void runsolver(Simulation newSimulation, File baseDirectory, int numRuns, TimeSeriesMultitrialData timeSeriesMultitrialData) {
    Simulation versSimulation = null;
    File destDir = null;
    boolean bTimeout = false;
    // int progress = 1;
    for (int trialIndex = 0; trialIndex < numRuns; trialIndex++) {
        System.out.println("\n=====================================\n\nStarting trial " + (trialIndex + 1) + " of " + numRuns + "\n\n==============================\n");
        long startTime = System.currentTimeMillis();
        // }
        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();
                }
                if (System.currentTimeMillis() - startTime > 30 * 1000) {
                    // timeout after 30 seconds .. otherwise multiple runs will take forever
                    bTimeout = true;
                    solver.stopSolver();
                    throw new RuntimeException("timed out");
                }
                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());
            if (bTimeout) {
                throw new RuntimeException("timed out");
            } else {
                throw new RuntimeException("solver failed : " + e.getMessage(), e);
            }
        }
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        StochtestFileUtils.clearDir(destDir);
    }
// printout("\n");
}
Also used : Solver(cbit.vcell.solver.server.Solver) SimulationTask(cbit.vcell.messaging.server.SimulationTask) TempSimulation(cbit.vcell.solver.TempSimulation) ODESimData(cbit.vcell.solver.ode.ODESimData) PropertyVetoException(java.beans.PropertyVetoException) SQLException(java.sql.SQLException) XmlParseException(cbit.vcell.xml.XmlParseException) ImageException(cbit.image.ImageException) IOException(java.io.IOException) DataAccessException(org.vcell.util.DataAccessException) ExpressionException(cbit.vcell.parser.ExpressionException) MappingException(cbit.vcell.mapping.MappingException) GeometryException(cbit.vcell.geometry.GeometryException) TempSimulation(cbit.vcell.solver.TempSimulation) Simulation(cbit.vcell.solver.Simulation) SimulationData(cbit.vcell.simdata.SimulationData) ODEDataBlock(cbit.vcell.simdata.ODEDataBlock) File(java.io.File) SolverStatus(cbit.vcell.solver.server.SolverStatus) SimulationJob(cbit.vcell.solver.SimulationJob)

Example 2 with Solver

use of cbit.vcell.solver.server.Solver in project vcell by virtualcell.

the class SimulationServiceImpl method createQuickRunSolver.

private static Solver createQuickRunSolver(File directory, SimulationTask simTask) throws SolverException, IOException {
    SolverDescription solverDescription = simTask.getSimulation().getSolverTaskDescription().getSolverDescription();
    if (solverDescription == null) {
        throw new IllegalArgumentException("SolverDescription cannot be null");
    }
    // ----- 'FiniteVolume, Regular Grid' solver (semi-implicit) solver is not supported for quick run; throw exception.
    if (solverDescription.equals(SolverDescription.FiniteVolume)) {
        throw new IllegalArgumentException("Semi-Implicit Finite Volume Compiled, Regular Grid (Fixed Time Step) solver not allowed for quick run of simulations.");
    }
    SolverUtilities.prepareSolverExecutable(solverDescription);
    // create solver from SolverFactory
    Solver solver = SolverFactory.createSolver(directory, simTask, false);
    return solver;
}
Also used : Solver(cbit.vcell.solver.server.Solver) SolverDescription(cbit.vcell.solver.SolverDescription)

Example 3 with Solver

use of cbit.vcell.solver.server.Solver in project vcell by virtualcell.

the class HtcSimulationWorker method submit2PBS.

private HtcJobID submit2PBS(SimulationTask simTask, HtcProxy clonedHtcProxy, PostProcessingChores chores) throws XmlParseException, IOException, SolverException, ExecutableException {
    HtcJobID jobid = null;
    String htcLogDirExternalString = new File(PropertyLoader.getRequiredProperty(PropertyLoader.htcLogDirExternal)).getAbsolutePath();
    if (!htcLogDirExternalString.endsWith("/")) {
        htcLogDirExternalString = htcLogDirExternalString + "/";
    }
    String htcLogDirInternalString = new File(PropertyLoader.getRequiredProperty(PropertyLoader.htcLogDirInternal)).getAbsolutePath();
    if (!htcLogDirInternalString.endsWith("/")) {
        htcLogDirInternalString = htcLogDirInternalString + "/";
    }
    // "S_" + simTask.getSimKey() + "_" + simTask.getSimulationJob().getJobIndex()+ "_" + simTask.getTaskID();
    String jobname = HtcProxy.createHtcSimJobName(new HtcProxy.SimTaskInfo(simTask.getSimKey(), simTask.getSimulationJob().getJobIndex(), simTask.getTaskID()));
    String subFileExternal = htcLogDirExternalString + jobname + clonedHtcProxy.getSubmissionFileExtension();
    String subFileInternal = htcLogDirInternalString + jobname + clonedHtcProxy.getSubmissionFileExtension();
    File parallelDirInternal = new File(chores.runDirectoryInternal);
    File parallelDirExternal = new File(chores.runDirectoryExternal);
    File primaryUserDirInternal = new File(chores.finalDataDirectoryInternal);
    File primaryUserDirExternal = new File(chores.finalDataDirectoryExternal);
    Solver realSolver = (AbstractSolver) SolverFactory.createSolver(primaryUserDirInternal, parallelDirInternal, simTask, true);
    realSolver.setUnixMode();
    String simTaskXmlText = XmlHelper.simTaskToXML(simTask);
    String simTaskFilePathInternal = ResourceUtil.forceUnixPath(new File(primaryUserDirInternal, simTask.getSimulationJobID() + "_" + simTask.getTaskID() + ".simtask.xml").toString());
    String simTaskFilePathExternal = ResourceUtil.forceUnixPath(new File(primaryUserDirExternal, simTask.getSimulationJobID() + "_" + simTask.getTaskID() + ".simtask.xml").toString());
    if (!primaryUserDirInternal.exists()) {
        FileUtils.forceMkdir(primaryUserDirInternal);
        // 
        // directory create from container (possibly) as root, make this user directory accessible from user "vcell"
        // 
        primaryUserDirInternal.setWritable(true, false);
        primaryUserDirInternal.setExecutable(true, false);
        primaryUserDirInternal.setReadable(true, false);
    }
    XmlUtil.writeXMLStringToFile(simTaskXmlText, simTaskFilePathInternal, true);
    final String SOLVER_EXIT_CODE_REPLACE_STRING = "SOLVER_EXIT_CODE_REPLACE_STRING";
    KeyValue simKey = simTask.getSimKey();
    User simOwner = simTask.getSimulation().getVersion().getOwner();
    final int jobId = simTask.getSimulationJob().getJobIndex();
    ExecutableCommand.Container commandContainer = new ExecutableCommand.Container();
    // the post processor command itself is neither messaging nor parallel; it's independent of the previous solver call
    ExecutableCommand postprocessorCmd = new ExecutableCommand(null, false, false, PropertyLoader.getRequiredProperty(PropertyLoader.simulationPostprocessor), simKey.toString(), simOwner.getName(), simOwner.getID().toString(), Integer.toString(jobId), Integer.toString(simTask.getTaskID()), SOLVER_EXIT_CODE_REPLACE_STRING, subFileExternal);
    postprocessorCmd.setExitCodeToken(SOLVER_EXIT_CODE_REPLACE_STRING);
    commandContainer.add(postprocessorCmd);
    // CBN?
    int ncpus = simTask.getSimulation().getSolverTaskDescription().getNumProcessors();
    Collection<PortableCommand> postProcessingCommands = new ArrayList<PortableCommand>();
    if (realSolver instanceof AbstractCompiledSolver) {
        AbstractCompiledSolver compiledSolver = (AbstractCompiledSolver) realSolver;
        List<String> args = new ArrayList<>(4);
        args.add(PropertyLoader.getRequiredProperty(PropertyLoader.simulationPreprocessor));
        args.add(simTaskFilePathExternal);
        args.add(primaryUserDirExternal.getAbsolutePath());
        if (chores.isParallel()) {
            args.add(chores.runDirectoryExternal);
        }
        // compiled solver ...used to be only single executable, now we pass 2 commands to PBSUtils.submitJob that invokes SolverPreprocessor.main() and then the native executable
        // the pre-processor command itself is neither messaging nor parallel; it's independent of the subsequent solver call
        ExecutableCommand preprocessorCmd = new ExecutableCommand(null, false, false, args);
        commandContainer.add(preprocessorCmd);
        for (ExecutableCommand ec : compiledSolver.getCommands()) {
            if (ec.isMessaging()) {
                ec.addArgument("-tid");
                ec.addArgument(simTask.getTaskID());
            }
            commandContainer.add(ec);
        }
        if (chores.isCopyNeeded()) {
            String logName = chores.finalDataDirectoryInternal + '/' + SimulationData.createCanonicalSimLogFileName(simKey, jobId, false);
            CopySimFiles csf = new CopySimFiles(simTask.getSimulationJobID(), chores.runDirectoryInternal, chores.finalDataDirectoryInternal, logName);
            postProcessingCommands.add(csf);
        }
        if (chores.isVtkUser()) {
            VtkMeshGenerator vmg = new VtkMeshGenerator(simOwner, simKey, jobId);
            postProcessingCommands.add(vmg);
        }
    } else {
        ExecutableCommand ec = new ExecutableCommand(null, false, false, PropertyLoader.getRequiredProperty(PropertyLoader.javaSimulationExecutable), simTaskFilePathExternal, ResourceUtil.forceUnixPath(parallelDirExternal.getAbsolutePath()));
        commandContainer.add(ec);
    }
    jobid = clonedHtcProxy.submitJob(jobname, subFileInternal, subFileExternal, commandContainer, ncpus, simTask.getEstimatedMemorySizeMB(), postProcessingCommands);
    if (jobid == null) {
        throw new RuntimeException("Failed. (error message: submitting to job scheduler failed).");
    }
    return jobid;
}
Also used : Solver(cbit.vcell.solver.server.Solver) AbstractSolver(cbit.vcell.solvers.AbstractSolver) AbstractCompiledSolver(cbit.vcell.solvers.AbstractCompiledSolver) HtcProxy(cbit.vcell.message.server.htc.HtcProxy) KeyValue(org.vcell.util.document.KeyValue) User(org.vcell.util.document.User) VtkMeshGenerator(cbit.vcell.simdata.VtkMeshGenerator) ArrayList(java.util.ArrayList) AbstractCompiledSolver(cbit.vcell.solvers.AbstractCompiledSolver) AbstractSolver(cbit.vcell.solvers.AbstractSolver) ExecutableCommand(cbit.vcell.solvers.ExecutableCommand) HtcJobID(cbit.vcell.server.HtcJobID) PortableCommand(cbit.vcell.simdata.PortableCommand) File(java.io.File)

Example 4 with Solver

use of cbit.vcell.solver.server.Solver in project vcell by virtualcell.

the class SolverHandler method simulateAllTasks.

public HashMap<String, ODESolverResultSet> simulateAllTasks(CLIUtils utils, ExternalDocInfo externalDocInfo, SedML sedml, File outputDirForSedml, String outDir, String outputBaseDir, String sedmlLocation, boolean keepTempFiles, boolean exactMatchOnly) throws Exception {
    // create the VCDocument(s) (bioModel(s) + application(s) + simulation(s)), do sanity checks
    cbit.util.xml.VCLogger sedmlImportLogger = new LocalLogger();
    String inputFile = externalDocInfo.getFile().getAbsolutePath();
    String bioModelBaseName = org.vcell.util.FileUtils.getBaseName(inputFile);
    List<VCDocument> docs = null;
    // Key String is SEDML Task ID
    HashMap<String, ODESolverResultSet> resultsHash = new LinkedHashMap<String, ODESolverResultSet>();
    String docName = null;
    BioModel bioModel = null;
    Simulation[] sims = null;
    String outDirRoot = outputDirForSedml.toString().substring(0, outputDirForSedml.toString().lastIndexOf(System.getProperty("file.separator")));
    try {
        docs = XmlHelper.sedmlToBioModel(sedmlImportLogger, externalDocInfo, sedml, null, sedmlLocation, exactMatchOnly);
    } catch (Exception e) {
        System.err.println("Unable to Parse SED-ML into Bio-Model, failed with err: " + e.getMessage());
        throw e;
    }
    if (docs != null) {
        countBioModels = docs.size();
    }
    int simulationCount = 0;
    int bioModelCount = 0;
    boolean hasSomeSpatial = false;
    boolean bTimeoutFound = false;
    for (VCDocument doc : docs) {
        try {
            sanityCheck(doc);
        } catch (Exception e) {
            e.printStackTrace(System.err);
        // continue;
        }
        docName = doc.getName();
        bioModel = (BioModel) doc;
        sims = bioModel.getSimulations();
        for (Simulation sim : sims) {
            if (sim.getImportedTaskID() == null) {
                // this is a simulation not matching the imported task, so we skip it
                continue;
            }
            String logTaskMessage = "Initializing simulation... ";
            String logTaskError = "";
            long startTimeTask = System.currentTimeMillis();
            SimulationTask simTask;
            String kisao = "null";
            ODESolverResultSet odeSolverResultSet = null;
            SolverTaskDescription std = null;
            SolverDescription sd = null;
            try {
                SimulationOwner so = sim.getSimulationOwner();
                sim = new TempSimulation(sim, false);
                sim.setSimulationOwner(so);
                std = sim.getSolverTaskDescription();
                sd = std.getSolverDescription();
                kisao = sd.getKisao();
                if (kisao == null) {
                    throw new RuntimeException("KISAO is null.");
                }
                SimulationJob simJob = new SimulationJob(sim, 0, null);
                simTask = new SimulationTask(simJob, 0);
                Solver solver = SolverFactory.createSolver(outputDirForSedml, simTask, false);
                logTaskMessage += "done. Starting simulation... ";
                if (sd.isSpatial()) {
                    hasSomeSpatial = true;
                }
                // else
                if (solver instanceof AbstractCompiledSolver) {
                    ((AbstractCompiledSolver) solver).runSolver();
                    System.out.println(solver);
                    System.out.println(solver.getSolverStatus());
                    if (solver instanceof ODESolver) {
                        odeSolverResultSet = ((ODESolver) solver).getODESolverResultSet();
                    } else if (solver instanceof GibsonSolver) {
                        odeSolverResultSet = ((GibsonSolver) solver).getStochSolverResultSet();
                    } else if (solver instanceof HybridSolver) {
                        odeSolverResultSet = ((HybridSolver) solver).getHybridSolverResultSet();
                    } else {
                        String str = "Solver results are not compatible with CSV format. ";
                        System.err.println(str);
                    // keepTempFiles = true;		// temp fix for Jasraj
                    // throw new RuntimeException(str);
                    }
                } else if (solver instanceof AbstractJavaSolver) {
                    ((AbstractJavaSolver) solver).runSolver();
                    odeSolverResultSet = ((ODESolver) solver).getODESolverResultSet();
                    // must interpolate data for uniform time course which is not supported natively by the Java solvers
                    Task task = (Task) sedml.getTaskWithId(sim.getImportedTaskID());
                    assert task != null;
                    org.jlibsedml.Simulation sedmlSim = sedml.getSimulation(task.getSimulationReference());
                    if (sedmlSim instanceof UniformTimeCourse) {
                        odeSolverResultSet = CLIUtils.interpolate(odeSolverResultSet, (UniformTimeCourse) sedmlSim);
                        logTaskMessage += "done. Interpolating... ";
                    }
                } else {
                    // this should actually never happen...
                    String str = "Unexpected solver: " + kisao + " " + solver + ". ";
                    throw new RuntimeException(str);
                }
                if (solver.getSolverStatus().getStatus() == SolverStatus.SOLVER_FINISHED) {
                    // File aaa = new File("C:\\TEMP\\aaa.hdf5");
                    // CLIUtils.exportPDE2HDF5(sim, outputDirForSedml, aaa);
                    logTaskMessage += "done. ";
                    System.out.println("Succesful execution: Model '" + docName + "' Task '" + sim.getDescription() + "'.");
                    long endTimeTask = System.currentTimeMillis();
                    long elapsedTime = endTimeTask - startTimeTask;
                    int duration = (int) Math.ceil(elapsedTime / 1000.0);
                    String msg = "Running simulation " + simTask.getSimulation().getName() + ", " + elapsedTime + " ms";
                    System.out.println(msg);
                    // we only count the number of simulations (tasks) that succeeded
                    countSuccessfulSimulationRuns++;
                    utils.updateTaskStatusYml(sedmlLocation, sim.getImportedTaskID(), CLIUtils.Status.SUCCEEDED, outDir, duration + "", kisao);
                    utils.setOutputMessage(sedmlLocation, sim.getImportedTaskID(), outDir, "task", logTaskMessage);
                    CLIUtils.drawBreakLine("-", 100);
                } else {
                    System.err.println("Solver status: " + solver.getSolverStatus().getStatus());
                    System.err.println("Solver message: " + solver.getSolverStatus().getSimulationMessage().getDisplayMessage());
                    String error = solver.getSolverStatus().getSimulationMessage().getDisplayMessage() + " ";
                    throw new RuntimeException(error);
                }
            // CLIUtils.finalStatusUpdate( CLIUtils.Status.SUCCEEDED, outDir);
            } catch (Exception e) {
                // File aaa = new File("C:\\TEMP\\aaa.hdf5");
                // CLIUtils.exportPDE2HDF5(sim, outputDirForSedml, aaa);
                String error = "Failed execution: Model '" + docName + "' Task '" + sim.getDescription() + "'. ";
                System.err.println(error);
                long endTime = System.currentTimeMillis();
                long elapsedTime = endTime - startTimeTask;
                int duration = (int) Math.ceil(elapsedTime / 1000.0);
                String msg = "Running simulation for " + elapsedTime + " ms";
                System.out.println(msg);
                if (sim.getImportedTaskID() == null) {
                    String str = "'null' imported task id, this should never happen. ";
                    System.err.println();
                    logTaskError += str;
                } else {
                    utils.updateTaskStatusYml(sedmlLocation, sim.getImportedTaskID(), CLIUtils.Status.FAILED, outDir, duration + "", kisao);
                }
                // CLIUtils.finalStatusUpdate(CLIUtils.Status.FAILED, outDir);
                if (e.getMessage() != null) {
                    // something else than failure caught by solver instance during execution
                    logTaskError += (e.getMessage() + ". ");
                    System.err.println(e.getMessage());
                } else {
                    logTaskError += (error + ". ");
                }
                String type = e.getClass().getSimpleName();
                utils.setOutputMessage(sedmlLocation, sim.getImportedTaskID(), outDir, "task", logTaskMessage);
                utils.setExceptionMessage(sedmlLocation, sim.getImportedTaskID(), outDir, "task", type, logTaskError);
                String sdl = "";
                if (sd != null && sd.getShortDisplayLabel() != null && !sd.getShortDisplayLabel().isEmpty()) {
                    sdl = sd.getShortDisplayLabel();
                } else {
                    sdl = kisao;
                }
                if (logTaskError.contains("Process timed out")) {
                    if (bTimeoutFound == false) {
                        // don't repeat this for each task
                        String str = logTaskError.substring(0, logTaskError.indexOf("Process timed out"));
                        // truncate the rest of the spam
                        str += "Process timed out";
                        CLIStandalone.writeDetailedErrorList(outputBaseDir, bioModelBaseName + ",  solver: " + sdl + ": " + type + ": " + str);
                        bTimeoutFound = true;
                    }
                } else {
                    CLIStandalone.writeDetailedErrorList(outputBaseDir, bioModelBaseName + ",  solver: " + sdl + ": " + type + ": " + logTaskError);
                }
                CLIUtils.drawBreakLine("-", 100);
            }
            if (odeSolverResultSet != null) {
                resultsHash.put(sim.getImportedTaskID(), odeSolverResultSet);
            } else {
                // if any task fails, we still put it in the hash with a null value
                resultsHash.put(sim.getImportedTaskID(), null);
            }
            if (keepTempFiles == false) {
                CLIUtils.removeIntermediarySimFiles(outputDirForSedml);
            }
            simulationCount++;
        }
        bioModelCount++;
    }
    System.out.println("Ran " + simulationCount + " simulations for " + bioModelCount + " biomodels.");
    if (hasSomeSpatial) {
        CLIStandalone.writeSpatialList(outputBaseDir, bioModelBaseName);
    }
    return resultsHash;
}
Also used : AbstractCompiledSolver(cbit.vcell.solvers.AbstractCompiledSolver) HybridSolver(cbit.vcell.solver.stoch.HybridSolver) Solver(cbit.vcell.solver.server.Solver) ODESolver(cbit.vcell.solver.ode.ODESolver) GibsonSolver(cbit.vcell.solver.stoch.GibsonSolver) AbstractJavaSolver(cbit.vcell.solver.ode.AbstractJavaSolver) SimulationTask(cbit.vcell.messaging.server.SimulationTask) Task(org.jlibsedml.Task) SimulationTask(cbit.vcell.messaging.server.SimulationTask) GibsonSolver(cbit.vcell.solver.stoch.GibsonSolver) LinkedHashMap(java.util.LinkedHashMap) AbstractJavaSolver(cbit.vcell.solver.ode.AbstractJavaSolver) ODESolverResultSet(cbit.vcell.solver.ode.ODESolverResultSet) VCDocument(org.vcell.util.document.VCDocument) VCLogger(cbit.util.xml.VCLogger) SBMLImportException(org.vcell.sbml.vcell.SBMLImportException) ODESolver(cbit.vcell.solver.ode.ODESolver) HybridSolver(cbit.vcell.solver.stoch.HybridSolver) AbstractCompiledSolver(cbit.vcell.solvers.AbstractCompiledSolver) BioModel(cbit.vcell.biomodel.BioModel) UniformTimeCourse(org.jlibsedml.UniformTimeCourse)

Example 5 with Solver

use of cbit.vcell.solver.server.Solver in project vcell by virtualcell.

the class SolverHandler method simulateAllVcmlTasks.

@Deprecated
public HashMap<String, ODESolverResultSet> simulateAllVcmlTasks(File vcmlPath, File outputDir) throws Exception {
    // create the VCDocument(s) (bioModel(s) + application(s) + simulation(s)), do sanity checks
    List<VCDocument> docs = null;
    // Key String is SEDML Task ID
    HashMap<String, ODESolverResultSet> resultsHash = new LinkedHashMap<String, ODESolverResultSet>();
    String docName = null;
    BioModel bioModel = null;
    Simulation[] sims = null;
    VCDocument singleDoc = null;
    try {
        singleDoc = VCMLHandler.convertVcmlToVcDocument(vcmlPath);
    } catch (Exception e) {
        System.err.println("Unable to Parse SED-ML into Bio-Model, failed with err: " + e.getMessage());
        throw e;
    }
    try {
        sanityCheck(singleDoc);
    } catch (Exception e) {
        e.printStackTrace(System.err);
    }
    assert singleDoc != null;
    docName = singleDoc.getName();
    bioModel = (BioModel) singleDoc;
    sims = bioModel.getSimulations();
    for (Simulation sim : sims) {
        sim = new TempSimulation(sim, false);
        SolverTaskDescription std = sim.getSolverTaskDescription();
        SolverDescription sd = std.getSolverDescription();
        String kisao = sd.getKisao();
        SimulationJob simJob = new SimulationJob(sim, 0, null);
        SimulationTask simTask = new SimulationTask(simJob, 0);
        Solver solver = SolverFactory.createSolver(outputDir, simTask, false);
        ODESolverResultSet odeSolverResultSet = null;
        try {
            if (solver instanceof AbstractCompiledSolver) {
                ((AbstractCompiledSolver) solver).runSolver();
                if (solver instanceof ODESolver) {
                    odeSolverResultSet = ((ODESolver) solver).getODESolverResultSet();
                } else if (solver instanceof GibsonSolver) {
                    odeSolverResultSet = ((GibsonSolver) solver).getStochSolverResultSet();
                } else if (solver instanceof HybridSolver) {
                    odeSolverResultSet = ((HybridSolver) solver).getHybridSolverResultSet();
                } else {
                    System.err.println("Solver results are not compatible with CSV format");
                }
            // TODO: Add support for JAVA solvers and implement interpolation
            // odeSolverResultSet = CLIUtils.interpolate(odeSolverResultSet, (UniformTimeCourse) sedmlSim);
            } else {
                // this should actually never happen...
                throw new Exception("Unexpected solver: " + kisao + " " + solver);
            }
            if (solver.getSolverStatus().getStatus() == SolverStatus.SOLVER_FINISHED) {
                System.out.println("Succesful execution: Model '" + docName + "' Task '" + sim.getDescription() + "'.");
            } else {
                System.err.println("Solver status: " + solver.getSolverStatus().getStatus());
                System.err.println("Solver message: " + solver.getSolverStatus().getSimulationMessage().getDisplayMessage());
                throw new Exception();
            }
        } catch (Exception e) {
            System.err.println("Failed execution: Model '" + docName + "' Task '" + sim.getDescription() + "'.");
            if (e.getMessage() != null) {
                // something else than failure caught by solver instance during execution
                System.err.println(e.getMessage());
            }
        }
        if (odeSolverResultSet != null) {
            resultsHash.put(sim.getName(), odeSolverResultSet);
        }
        CLIUtils.removeIntermediarySimFiles(outputDir);
    }
    return resultsHash;
}
Also used : AbstractCompiledSolver(cbit.vcell.solvers.AbstractCompiledSolver) HybridSolver(cbit.vcell.solver.stoch.HybridSolver) Solver(cbit.vcell.solver.server.Solver) ODESolver(cbit.vcell.solver.ode.ODESolver) GibsonSolver(cbit.vcell.solver.stoch.GibsonSolver) AbstractJavaSolver(cbit.vcell.solver.ode.AbstractJavaSolver) SimulationTask(cbit.vcell.messaging.server.SimulationTask) VCDocument(org.vcell.util.document.VCDocument) GibsonSolver(cbit.vcell.solver.stoch.GibsonSolver) SBMLImportException(org.vcell.sbml.vcell.SBMLImportException) ODESolver(cbit.vcell.solver.ode.ODESolver) HybridSolver(cbit.vcell.solver.stoch.HybridSolver) LinkedHashMap(java.util.LinkedHashMap) AbstractCompiledSolver(cbit.vcell.solvers.AbstractCompiledSolver) BioModel(cbit.vcell.biomodel.BioModel) ODESolverResultSet(cbit.vcell.solver.ode.ODESolverResultSet)

Aggregations

Solver (cbit.vcell.solver.server.Solver)11 SimulationTask (cbit.vcell.messaging.server.SimulationTask)6 File (java.io.File)6 Simulation (cbit.vcell.solver.Simulation)4 SimulationJob (cbit.vcell.solver.SimulationJob)4 TempSimulation (cbit.vcell.solver.TempSimulation)4 SolverStatus (cbit.vcell.solver.server.SolverStatus)4 AbstractCompiledSolver (cbit.vcell.solvers.AbstractCompiledSolver)4 ODEDataBlock (cbit.vcell.simdata.ODEDataBlock)3 SimulationData (cbit.vcell.simdata.SimulationData)3 SolverDescription (cbit.vcell.solver.SolverDescription)3 ODESimData (cbit.vcell.solver.ode.ODESimData)3 GibsonSolver (cbit.vcell.solver.stoch.GibsonSolver)3 ArrayList (java.util.ArrayList)3 BioModel (cbit.vcell.biomodel.BioModel)2 HtcProxy (cbit.vcell.message.server.htc.HtcProxy)2 ExpressionException (cbit.vcell.parser.ExpressionException)2 HtcJobID (cbit.vcell.server.HtcJobID)2 PortableCommand (cbit.vcell.simdata.PortableCommand)2 VtkMeshGenerator (cbit.vcell.simdata.VtkMeshGenerator)2