Search in sources :

Example 6 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 7 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)

Aggregations

Solver (cbit.vcell.solver.server.Solver)7 File (java.io.File)5 SimulationTask (cbit.vcell.messaging.server.SimulationTask)4 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 ODEDataBlock (cbit.vcell.simdata.ODEDataBlock)3 SimulationData (cbit.vcell.simdata.SimulationData)3 ODESimData (cbit.vcell.solver.ode.ODESimData)3 SolverDescription (cbit.vcell.solver.SolverDescription)2 ArrayList (java.util.ArrayList)2 SmoldynSolver (org.vcell.solver.smoldyn.SmoldynSolver)2 ImageException (cbit.image.ImageException)1 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)1 FieldDataIdentifierSpec (cbit.vcell.field.FieldDataIdentifierSpec)1 GeometryException (cbit.vcell.geometry.GeometryException)1 MappingException (cbit.vcell.mapping.MappingException)1 SimulationContext (cbit.vcell.mapping.SimulationContext)1 HtcProxy (cbit.vcell.message.server.htc.HtcProxy)1