Search in sources :

Example 1 with AbstractCompiledSolver

use of cbit.vcell.solvers.AbstractCompiledSolver 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 2 with AbstractCompiledSolver

use of cbit.vcell.solvers.AbstractCompiledSolver 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 3 with AbstractCompiledSolver

use of cbit.vcell.solvers.AbstractCompiledSolver 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)

Example 4 with AbstractCompiledSolver

use of cbit.vcell.solvers.AbstractCompiledSolver 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;
    File htcLogDirExternal = new File(PropertyLoader.getRequiredProperty(PropertyLoader.htcLogDirExternal));
    File htcLogDirInternal = new File(PropertyLoader.getRequiredProperty(PropertyLoader.htcLogDirInternal));
    // "S_" + simTask.getSimKey() + "_" + simTask.getSimulationJob().getJobIndex()+ "_" + simTask.getTaskID();
    String jobname = HtcProxy.createHtcSimJobName(new HtcProxy.SimTaskInfo(simTask.getSimKey(), simTask.getSimulationJob().getJobIndex(), simTask.getTaskID()));
    File subFileExternal = new File(htcLogDirExternal, jobname + clonedHtcProxy.getSubmissionFileExtension());
    File subFileInternal = new File(htcLogDirInternal, 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);
    boolean bNonSingularity = simTask.getSimulation().getSolverTaskDescription().getSolverDescription() == SolverDescription.HybridEuler || simTask.getSimulation().getSolverTaskDescription().getSolverDescription() == SolverDescription.HybridMilstein || simTask.getSimulation().getSolverTaskDescription().getSolverDescription() == SolverDescription.HybridMilAdaptive;
    Solver realSolver = (AbstractSolver) SolverFactory.createSolver((bNonSingularity ? primaryUserDirExternal : 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.getAbsolutePath());
    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);
        }
    // if(chores.isStochMultiTrial()) {
    // final String logName = chores.finalDataDirectoryInternal + '/' + SimulationData.createCanonicalSimLogFileName(simKey, jobId, false);
    // postProcessingCommands.add(new AvgStochMultiTrial(primaryUserDirInternal.getAbsolutePath(), XmlHelper.simTaskToXML(simTask)));
    // }
    } 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, simTask, primaryUserDirExternal);
    if (jobid == null) {
        throw new RuntimeException("Failed. (error message: submitting to job scheduler failed).");
    }
    return jobid;
}
Also used : GibsonSolver(cbit.vcell.solver.stoch.GibsonSolver) SundialsSolver(cbit.vcell.solver.ode.SundialsSolver) 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)

Aggregations

Solver (cbit.vcell.solver.server.Solver)4 AbstractCompiledSolver (cbit.vcell.solvers.AbstractCompiledSolver)4 GibsonSolver (cbit.vcell.solver.stoch.GibsonSolver)3 BioModel (cbit.vcell.biomodel.BioModel)2 HtcProxy (cbit.vcell.message.server.htc.HtcProxy)2 SimulationTask (cbit.vcell.messaging.server.SimulationTask)2 HtcJobID (cbit.vcell.server.HtcJobID)2 PortableCommand (cbit.vcell.simdata.PortableCommand)2 VtkMeshGenerator (cbit.vcell.simdata.VtkMeshGenerator)2 AbstractJavaSolver (cbit.vcell.solver.ode.AbstractJavaSolver)2 ODESolver (cbit.vcell.solver.ode.ODESolver)2 ODESolverResultSet (cbit.vcell.solver.ode.ODESolverResultSet)2 HybridSolver (cbit.vcell.solver.stoch.HybridSolver)2 AbstractSolver (cbit.vcell.solvers.AbstractSolver)2 ExecutableCommand (cbit.vcell.solvers.ExecutableCommand)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 LinkedHashMap (java.util.LinkedHashMap)2 SBMLImportException (org.vcell.sbml.vcell.SBMLImportException)2 KeyValue (org.vcell.util.document.KeyValue)2