Search in sources :

Example 31 with SimulationTask

use of cbit.vcell.messaging.server.SimulationTask 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);
    }
}
Also used : SimulationTask(cbit.vcell.messaging.server.SimulationTask) FieldFunctionArguments(cbit.vcell.field.FieldFunctionArguments) FieldDataIdentifierSpec(cbit.vcell.field.FieldDataIdentifierSpec) SolverStatus(cbit.vcell.solver.server.SolverStatus) SimulationJob(cbit.vcell.solver.SimulationJob) FVSolverStandalone(cbit.vcell.solvers.FVSolverStandalone) ImageException(cbit.image.ImageException) UserCancelException(org.vcell.util.UserCancelException)

Example 32 with SimulationTask

use of cbit.vcell.messaging.server.SimulationTask in project vcell by virtualcell.

the class SimulationData method getChomboFiles.

@Override
public ChomboFiles getChomboFiles() throws IOException, XmlParseException, ExpressionException {
    if (chomboFileIterationIndices == null) {
        throw new RuntimeException("SimulationData.chomboFileIterationIndices is null, can't process Chombo HDF5 files");
    }
    if (!(getVcDataId() instanceof VCSimulationDataIdentifier)) {
        throw new RuntimeException("SimulationData.getVcDataId() is not a VCSimulationDataIdentifier (type is " + getVcDataId().getClass().getName() + "), can't process chombo HDF5 files");
    }
    VCSimulationDataIdentifier vcDataID = (VCSimulationDataIdentifier) getVcDataId();
    String expectedMeshfile = vcDataID.getID() + ".mesh.hdf5";
    File meshFile = amplistorHelper.getFile(expectedMeshfile);
    ChomboFiles chomboFiles = new ChomboFiles(vcDataID.getSimulationKey(), vcDataID.getJobIndex(), meshFile);
    String simtaskFilePath = vcDataID.getID() + "_0.simtask.xml";
    File simtaskFile = amplistorHelper.getFile(simtaskFilePath);
    if (!simtaskFile.exists()) {
        throw new RuntimeException("Chombo dataset mission .simtask.xml file, please rerun");
    }
    String xmlString = FileUtils.readFileToString(simtaskFile);
    SimulationTask simTask = XmlHelper.XMLToSimTask(xmlString);
    if (!simTask.getSimulation().getSolverTaskDescription().getChomboSolverSpec().isSaveChomboOutput() && !simTask.getSimulation().getSolverTaskDescription().isParallel()) {
        throw new RuntimeException("Export of Chombo simulations to VTK requires chombo data, select 'Chombo' data format in simulation solver options and rerun simulation.");
    }
    CartesianMeshChombo chomboMesh = (CartesianMeshChombo) mesh;
    FeaturePhaseVol[] featurePhaseVols = chomboMesh.getFeaturePhaseVols();
    for (int timeIndex : chomboFileIterationIndices) {
        if (featurePhaseVols == null) {
            // for old format which doesn't have featurephasevols, we need to try ivol up to 20 for each feature
            Enumeration<SubDomain> subdomainEnum = simTask.getSimulation().getMathDescription().getSubDomains();
            while (subdomainEnum.hasMoreElements()) {
                SubDomain subDomain = subdomainEnum.nextElement();
                if (subDomain instanceof CompartmentSubDomain) {
                    for (int ivol = 0; ivol < 20; ++ivol) {
                        // can be many vol, let us try 20
                        findChomboFeatureVolFile(chomboFiles, vcDataID, subDomain.getName(), ivol, timeIndex);
                    }
                }
            }
        } else {
            // note: some feature + ivol doesn't have a file if there are no variables defined in that feature
            for (FeaturePhaseVol pfv : featurePhaseVols) {
                findChomboFeatureVolFile(chomboFiles, vcDataID, pfv.feature, pfv.ivol, timeIndex);
            }
        }
    }
    return chomboFiles;
}
Also used : SimulationTask(cbit.vcell.messaging.server.SimulationTask) FeaturePhaseVol(cbit.vcell.solvers.CartesianMeshChombo.FeaturePhaseVol) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) CartesianMeshChombo(cbit.vcell.solvers.CartesianMeshChombo) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) FilamentSubDomain(cbit.vcell.math.FilamentSubDomain) SubDomain(cbit.vcell.math.SubDomain) PointSubDomain(cbit.vcell.math.PointSubDomain) MembraneSubDomain(cbit.vcell.math.MembraneSubDomain) ChomboFiles(org.vcell.vis.io.ChomboFiles) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) ZipFile(org.apache.commons.compress.archivers.zip.ZipFile) File(java.io.File)

Example 33 with SimulationTask

use of cbit.vcell.messaging.server.SimulationTask in project vcell by virtualcell.

the class SimulationStateMachine method onDispatch.

public synchronized void onDispatch(Simulation simulation, SimulationJobStatus oldSimulationJobStatus, SimulationDatabase simulationDatabase, VCMessageSession session) throws VCMessagingException, DataAccessException, SQLException {
    updateSolverProcessTimestamp();
    VCSimulationIdentifier vcSimID = oldSimulationJobStatus.getVCSimulationIdentifier();
    int taskID = oldSimulationJobStatus.getTaskID();
    if (!oldSimulationJobStatus.getSchedulerStatus().isWaiting()) {
        VCMongoMessage.sendInfo("onDispatch(" + vcSimID.getID() + ") Can't start, simulation[" + vcSimID + "] job [" + jobIndex + "] task [" + taskID + "] is already dispatched (" + oldSimulationJobStatus.getSchedulerStatus().getDescription() + ")");
        throw new RuntimeException("Can't start, simulation[" + vcSimID + "] job [" + jobIndex + "] task [" + taskID + "] is already dispatched (" + oldSimulationJobStatus.getSchedulerStatus().getDescription() + ")");
    }
    FieldDataIdentifierSpec[] fieldDataIdentifierSpecs = simulationDatabase.getFieldDataIdentifierSpecs(simulation);
    SimulationTask simulationTask = new SimulationTask(new SimulationJob(simulation, jobIndex, fieldDataIdentifierSpecs), taskID);
    double requiredMemMB = simulationTask.getEstimatedMemorySizeMB();
    double allowableMemMB = Double.parseDouble(PropertyLoader.getRequiredProperty(PropertyLoader.limitJobMemoryMB));
    final SimulationJobStatus newSimJobStatus;
    if (requiredMemMB > allowableMemMB) {
        // 
        // fail the simulation
        // 
        Date currentDate = new Date();
        // new queue status
        SimulationQueueEntryStatus newQueueStatus = new SimulationQueueEntryStatus(currentDate, PRIORITY_DEFAULT, SimulationJobStatus.SimulationQueueID.QUEUE_ID_NULL);
        SimulationExecutionStatus newSimExeStatus = new SimulationExecutionStatus(null, null, new Date(), null, false, null);
        newSimJobStatus = new SimulationJobStatus(VCellServerID.getSystemServerID(), vcSimID, jobIndex, oldSimulationJobStatus.getSubmitDate(), SchedulerStatus.FAILED, taskID, SimulationMessage.jobFailed("simulation required " + requiredMemMB + "MB of memory, only " + allowableMemMB + "MB allowed"), newQueueStatus, newSimExeStatus);
        simulationDatabase.updateSimulationJobStatus(newSimJobStatus);
        StatusMessage message = new StatusMessage(newSimJobStatus, simulation.getVersion().getOwner().getName(), null, null);
        message.sendToClient(session);
    } else {
        // 
        // dispatch the simulation, new queue status
        // 
        Date currentDate = new Date();
        SimulationQueueEntryStatus newQueueStatus = new SimulationQueueEntryStatus(currentDate, PRIORITY_DEFAULT, SimulationJobStatus.SimulationQueueID.QUEUE_ID_SIMULATIONJOB);
        SimulationExecutionStatus newSimExeStatus = new SimulationExecutionStatus(null, null, new Date(), null, false, null);
        newSimJobStatus = new SimulationJobStatus(VCellServerID.getSystemServerID(), vcSimID, jobIndex, oldSimulationJobStatus.getSubmitDate(), SchedulerStatus.DISPATCHED, taskID, SimulationMessage.MESSAGE_JOB_DISPATCHED, newQueueStatus, newSimExeStatus);
        SimulationTaskMessage simTaskMessage = new SimulationTaskMessage(simulationTask);
        simTaskMessage.sendSimulationTask(session);
        simulationDatabase.updateSimulationJobStatus(newSimJobStatus);
        StatusMessage message = new StatusMessage(newSimJobStatus, simulation.getVersion().getOwner().getName(), null, null);
        message.sendToClient(session);
    }
// addStateMachineTransition(new StateMachineTransition(new DispatchStateMachineEvent(taskID), oldSimulationJobStatus, newSimJobStatus));
}
Also used : VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) SimulationExecutionStatus(cbit.vcell.server.SimulationExecutionStatus) SimulationTask(cbit.vcell.messaging.server.SimulationTask) SimulationQueueEntryStatus(cbit.vcell.server.SimulationQueueEntryStatus) Date(java.util.Date) StatusMessage(cbit.vcell.message.messages.StatusMessage) FieldDataIdentifierSpec(cbit.vcell.field.FieldDataIdentifierSpec) SimulationJobStatus(cbit.vcell.server.SimulationJobStatus) SimulationJob(cbit.vcell.solver.SimulationJob) SimulationTaskMessage(cbit.vcell.message.messages.SimulationTaskMessage)

Example 34 with SimulationTask

use of cbit.vcell.messaging.server.SimulationTask 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);
    }
}
Also used : SimulationTask(cbit.vcell.messaging.server.SimulationTask) SolverStatus(cbit.vcell.solver.server.SolverStatus) SimulationJob(cbit.vcell.solver.SimulationJob) FVSolverStandalone(cbit.vcell.solvers.FVSolverStandalone) UserCancelException(org.vcell.util.UserCancelException)

Aggregations

SimulationTask (cbit.vcell.messaging.server.SimulationTask)34 SimulationJob (cbit.vcell.solver.SimulationJob)26 File (java.io.File)17 Simulation (cbit.vcell.solver.Simulation)15 IOException (java.io.IOException)13 SolverStatus (cbit.vcell.solver.server.SolverStatus)11 XmlParseException (cbit.vcell.xml.XmlParseException)8 FieldDataIdentifierSpec (cbit.vcell.field.FieldDataIdentifierSpec)7 SimulationContext (cbit.vcell.mapping.SimulationContext)7 ExpressionException (cbit.vcell.parser.ExpressionException)7 SolverException (cbit.vcell.solver.SolverException)7 FVSolverStandalone (cbit.vcell.solvers.FVSolverStandalone)7 PrintWriter (java.io.PrintWriter)7 UserCancelException (org.vcell.util.UserCancelException)7 TempSimulation (cbit.vcell.solver.TempSimulation)6 MathDescription (cbit.vcell.math.MathDescription)5 Variable (cbit.vcell.math.Variable)5 DataAccessException (org.vcell.util.DataAccessException)5 ImageException (cbit.image.ImageException)4 ODESimData (cbit.vcell.solver.ode.ODESimData)4