Search in sources :

Example 36 with VCSimulationIdentifier

use of cbit.vcell.solver.VCSimulationIdentifier in project vcell by virtualcell.

the class VCellClientDataServiceImpl method displayPostProcessingDataInVCell.

@Override
public void displayPostProcessingDataInVCell(SimulationDataSetRef simulationDataSetRef) throws NumberFormatException, DataAccessException {
    User vcUser = vcellClient.getRequestManager().getDocumentManager().getUser();
    VCSimulationIdentifier vcSimId = new VCSimulationIdentifier(new KeyValue(simulationDataSetRef.getSimId()), vcUser);
    ClientDocumentManager clientDocumentManager = (ClientDocumentManager) vcellClient.getClientServerManager().getDocumentManager();
    SimulationOwner simulationOwner = null;
    if (simulationDataSetRef.isMathModel) {
        simulationOwner = clientDocumentManager.getMathModel(new KeyValue(simulationDataSetRef.getModelId()));
    } else {
        BioModel bioModel = clientDocumentManager.getBioModel(new KeyValue(simulationDataSetRef.getModelId()));
        simulationOwner = bioModel.getSimulationContext(simulationDataSetRef.getSimulationContextName());
    }
    ArrayList<AnnotatedFunction> outputFunctionsList = simulationOwner.getOutputFunctionContext().getOutputFunctionsList();
    OutputContext outputContext = new OutputContext(outputFunctionsList.toArray(new AnnotatedFunction[outputFunctionsList.size()]));
    VCSimulationDataIdentifier vcSimDataId = new VCSimulationDataIdentifier(vcSimId, simulationDataSetRef.getJobIndex());
    PDEDataManager pdeDataManager = (PDEDataManager) vcellClient.getRequestManager().getDataManager(outputContext, vcSimDataId, true);
    final ClientPDEDataContext newClientPDEDataContext = pdeDataManager.getPDEDataContext();
    // this was the code before the windows refactoring; appears to just always get the first window???
    // Enumeration<TopLevelWindowManager> windowManagers = vcellClient.getMdiManager().getWindowManagers();
    // final Window window = FindWindow.getWindow(windowManagers.nextElement().getComponent());
    Optional<TopLevelWindowManager> first = vcellClient.getMdiManager().getWindowManagers().stream().findFirst();
    VCAssert.assertTrue(first.isPresent(), "window manager not present?");
    final Window window = getWindow(first.get().getComponent());
    AsynchClientTask task = new AsynchClientTask("Display Post Processing Statistics", AsynchClientTask.TASKTYPE_SWING_NONBLOCKING, false, false) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            DataProcessingResultsPanel dataProcessingResultsPanel = new DataProcessingResultsPanel();
            dataProcessingResultsPanel.update(newClientPDEDataContext);
            DialogUtils.showComponentOKCancelDialog(window, dataProcessingResultsPanel, "Post Processing Statistics");
        }
    };
    Hashtable<String, Object> hash = new Hashtable<String, Object>();
    Vector<AsynchClientTask> tasksV = new Vector<AsynchClientTask>();
    tasksV.add(task);
    AsynchClientTask[] tasks = new AsynchClientTask[tasksV.size()];
    tasksV.copyInto(tasks);
    ClientTaskDispatcher.dispatch(window, hash, tasks, true);
}
Also used : Window(java.awt.Window) VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) User(org.vcell.util.document.User) KeyValue(org.vcell.util.document.KeyValue) TopLevelWindowManager(cbit.vcell.client.TopLevelWindowManager) Hashtable(java.util.Hashtable) ClientDocumentManager(cbit.vcell.clientdb.ClientDocumentManager) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) LocalVCSimulationDataIdentifier(cbit.vcell.client.ClientSimManager.LocalVCSimulationDataIdentifier) OutputContext(cbit.vcell.simdata.OutputContext) SimulationOwner(cbit.vcell.solver.SimulationOwner) PDEDataManager(cbit.vcell.simdata.PDEDataManager) BioModel(cbit.vcell.biomodel.BioModel) ClientPDEDataContext(cbit.vcell.simdata.ClientPDEDataContext) Vector(java.util.Vector) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction)

Example 37 with VCSimulationIdentifier

use of cbit.vcell.solver.VCSimulationIdentifier in project vcell by virtualcell.

the class HybridSolverTester method makeAltCSV.

private static void makeAltCSV(AltArgsHelper altArgsHelper, FileWriter fw, int runIndex, File userSimDataDir) throws Exception {
    VCSimulationIdentifier vcSimID = new VCSimulationIdentifier(new KeyValue(altArgsHelper.simID), altArgsHelper.user);
    boolean bInit = runIndex == 0;
    ArrayList<Double> simTimes = new ArrayList<Double>();
    StringTokenizer st = null;
    if (altArgsHelper.times.equals("all")) {
    } else {
        st = new StringTokenizer(altArgsHelper.times, ":");
        while (st.hasMoreTokens()) {
            double timePoint = Double.parseDouble(st.nextToken());
            simTimes.add(timePoint);
        }
    }
    SimLocHelper simLocHelper0 = null;
    ArrayList<String> simVars = new ArrayList<String>();
    st = new StringTokenizer(altArgsHelper.varnames, ":");
    while (st.hasMoreTokens()) {
        String var = st.nextToken();
        simVars.add(var);
    }
    int jobCounter = 0;
    final int TIME_SPACE_EXTRA = 0;
    double[][][] trialData = null;
    while (true) {
        VCSimulationDataIdentifier vcSimulationDataIdentifier = new VCSimulationDataIdentifier(vcSimID, jobCounter);
        SimulationData simData = null;
        DataOperationResults.DataProcessingOutputInfo dataProcessingOutputInfo = null;
        try {
            simData = new SimulationData(vcSimulationDataIdentifier, userSimDataDir, null, null);
            dataProcessingOutputInfo = (DataOperationResults.DataProcessingOutputInfo) DataSetControllerImpl.getDataProcessingOutput(new DataOperation.DataProcessingOutputInfoOP(vcSimulationDataIdentifier, true, null), new File(userSimDataDir, SimulationData.createCanonicalPostProcessFileName(vcSimulationDataIdentifier)));
        } catch (FileNotFoundException e) {
            if (jobCounter == 0) {
                System.out.println("found no trials matching SimID=" + altArgsHelper.simID + " in user dir " + userSimDataDir.getAbsolutePath());
            } else {
                System.out.println("found " + jobCounter + " trials in dir " + userSimDataDir.getAbsolutePath() + " matching SimID=" + altArgsHelper.simID);
            }
            break;
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (dataProcessingOutputInfo == null) {
            System.out.println("No postprocessing found for " + jobCounter + " trials in dir " + userSimDataDir.getAbsolutePath() + " matching SimID=" + altArgsHelper.simID);
            jobCounter++;
            continue;
        }
        if (simLocHelper0 == null && !altArgsHelper.dataIndexes.equals(POSTPROC)) {
            simLocHelper0 = calcSimLocs(altArgsHelper.dataIndexes, simData.getMesh());
        }
        if (jobCounter == 0) {
            double[] allDatasetTimes = simData.getDataTimes();
            if (altArgsHelper.times.equals("all")) {
                for (double thisTime : allDatasetTimes) {
                    simTimes.add(thisTime);
                }
            } else {
                // Convert user input times to actual data times
                for (int times = 0; times < simTimes.size(); times++) {
                    double masterDelta = Double.POSITIVE_INFINITY;
                    double timePoint = -1;
                    for (int j = 0; j < allDatasetTimes.length; j++) {
                        double tempDelta = Math.abs(simTimes.get(times) - allDatasetTimes[j]);
                        if (tempDelta < masterDelta) {
                            masterDelta = tempDelta;
                            timePoint = allDatasetTimes[j];
                            if (tempDelta == 0) {
                                break;
                            }
                        }
                    }
                    System.out.println("User time=" + simTimes.get(times) + " converted to dataset time=" + timePoint);
                    simTimes.set(times, timePoint);
                }
            }
            trialData = new double[simTimes.size()][(simLocHelper0 == null ? 1 : simLocHelper0.boxToLocs.size())][simVars.size()];
        }
        if (bInit && jobCounter == 0) {
            // print state vars
            DataIdentifier[] dataIdentifiers = simData.getVarAndFunctionDataIdentifiers(null);
            for (int j = 0; j < dataIdentifiers.length; j++) {
                System.out.println(dataIdentifiers[j]);
            }
            printheader(altArgsHelper, simTimes, simLocHelper0, simVars, fw, TIME_SPACE_EXTRA);
        }
        for (int times = 0; times < simTimes.size(); times++) {
            double timePoint = simTimes.get(times);
            for (int vars = 0; vars < simVars.size(); vars++) {
                double[] data = null;
                if (altArgsHelper.dataIndexes.equals(POSTPROC)) {
                    data = dataProcessingOutputInfo.getVariableStatValues().get(simVars.get(vars) + "_average");
                } else {
                    SimDataBlock simDataBlock = simData.getSimDataBlock(null, simVars.get(vars), timePoint);
                    data = simDataBlock.getData();
                }
                for (int locs = 0; locs < trialData[times].length; locs++) {
                    double val;
                    if (simLocHelper0 != null && simLocHelper0.boxToLocs.get(locs).size() == 1) {
                        // point
                        // System.out.println("pointIndex="+simLocHelper.boxToLocs.get(locs).get(0));
                        val = data[simLocHelper0.boxToLocs.get(locs).get(0)];
                    } else if (simLocHelper0 != null) {
                        // box, calculate the average, could be concentration or counts
                        double accum = 0;
                        for (Integer locIndex : simLocHelper0.boxToLocs.get(locs)) {
                            // System.out.println("boxIndex="+locIndex);
                            accum += data[locIndex];
                        }
                        val = accum / simLocHelper0.boxToLocs.get(locs).size();
                    } else {
                        // PostProcess
                        if (times < data.length) {
                            val = data[times];
                        } else {
                            val = Double.NaN;
                        }
                    }
                    trialData[times][locs][vars] = val;
                }
            }
        }
        fw.write("r=" + runIndex + " s=" + jobCounter + ",");
        for (int times = 0; times < simTimes.size(); times++) {
            for (int locs = 0; locs < trialData[times].length; locs++) {
                for (int vars = 0; vars < simVars.size(); vars++) {
                    // System.out.println("job="+jobCounter+" time="+simTimes.get(times)+" loc="+simLocHelper.boxToID.get(locs)+" var="+simVars.get(vars)+" data="+trialData[times][locs][vars]);
                    boolean isNan = Double.isNaN(trialData[times][locs][vars]);
                    fw.write((isNan ? "" : trialData[times][locs][vars]) + ",");
                }
                fw.write(",");
            }
            for (int timeSpace = 0; timeSpace < TIME_SPACE_EXTRA; timeSpace++) {
                fw.write(",");
            }
        }
        fw.write("\n");
        jobCounter++;
    }
    fw.flush();
}
Also used : VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) KeyValue(org.vcell.util.document.KeyValue) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) DataIdentifier(cbit.vcell.simdata.DataIdentifier) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) BigString(org.vcell.util.BigString) SimDataBlock(cbit.vcell.simdata.SimDataBlock) DataOperation(cbit.vcell.simdata.DataOperation) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) StringTokenizer(java.util.StringTokenizer) SimulationData(cbit.vcell.simdata.SimulationData) DataOperationResults(cbit.vcell.simdata.DataOperationResults) File(java.io.File)

Example 38 with VCSimulationIdentifier

use of cbit.vcell.solver.VCSimulationIdentifier in project vcell by virtualcell.

the class HybridSolverTester method runHybridTest.

public void runHybridTest(String site) {
    try {
        double[] timePoints = null;
        File mathModelFile = new File(mathModelVCMLFileName);
        XMLSource vcmlSource = new XMLSource(mathModelFile);
        MathModel mathModel = XmlHelper.XMLToMathModel(vcmlSource);
        File simDataDir = mathModelFile.getParentFile();
        Simulation sim = mathModel.getSimulations()[0];
        // run multiple trials and each run will have a simID = origSimID + i
        for (int i = 0; i < numRuns; i++) {
            System.out.println("--------------Trial No: " + (startTrialNo + i) + "----------------");
            // replace random seed
            sim.getSolverTaskDescription().getSmoldynSimulationOptions().setRandomSeed(new Integer(startTrialNo + i));
            // create sim job
            int jobIndex = startTrialNo + i;
            SimulationTask simTask = new SimulationTask(new SimulationJob(sim, jobIndex, null), 0);
            /*
				 * When you want to run the multiple trials on local uncomment the line below.
				 */
            // ResourceUtil.prepareSolverExecutable(sim.getSolverTaskDescription().getSolverDescription());
            /*
				 * When you want to run the multiple trials on server (without VCell user interface), use the next line of code 
				 * Corresponding changes should be made in the shell script runhybridtest for the location of executable on server
				 */
            FVSolverStandalone fvSolver = new FVSolverStandalone(simTask, simDataDir, false);
            fvSolver.startSolver();
            SolverStatus status = fvSolver.getSolverStatus();
            while (status.getStatus() != SolverStatus.SOLVER_FINISHED && status.getStatus() != SolverStatus.SOLVER_ABORTED) {
                System.out.println("progress: " + (int) (fvSolver.getProgress() * 100) + "%");
                // ask status every 2 seconds
                Thread.sleep(2000);
                status = fvSolver.getSolverStatus();
            }
            if (status.getStatus() == SolverStatus.SOLVER_FINISHED) {
                // get data
                VCSimulationIdentifier vcSimID = new VCSimulationIdentifier(sim.getVersion().getVersionKey(), sim.getVersion().getOwner());
                VCSimulationDataIdentifier vcSimDataID = new VCSimulationDataIdentifier(vcSimID, jobIndex);
                File hdf5File = new File(simDataDir, vcSimDataID.getID() + SimDataConstants.DATA_PROCESSING_OUTPUT_EXTENSION_HDF5);
                DataOperationResults.DataProcessingOutputInfo dataProcessingOutputInfo = (DataOperationResults.DataProcessingOutputInfo) DataSetControllerImpl.getDataProcessingOutput(new DataOperation.DataProcessingOutputInfoOP(vcSimDataID, false, null), hdf5File);
                if (i == 0) {
                    // do only one time
                    timePoints = dataProcessingOutputInfo.getVariableTimePoints();
                    for (int j = 0; j < varNames.length; j++) {
                        // row: numTimePoints, col:first col time + numRuns
                        double[][] data = new double[numRuns + 1][timePoints.length];
                        data[0] = timePoints;
                        results.add(data);
                    }
                }
                // write into results after each run
                for (int j = 0; j < varNames.length; j++) {
                    results.get(j)[i + 1] = dataProcessingOutputInfo.getVariableStatValues().get(varNames[j]);
                }
                // delete the file generated for this run
                deleteSimFiles(simDataDir, vcSimDataID);
            } else {
                throw new Exception("Sover did not finish normally." + status);
            }
        }
        // write to output file, tab delimited
        if (results != null && results.size() > 0) {
            for (int j = 0; j < varNames.length; j++) {
                File file = new File(simDataDir, "SimID_" + sim.getVersion().getVersionKey().toString() + "_" + varNames[j] + "_" + startTrialNo + ".txt");
                PrintWriter pw = new PrintWriter(file);
                double[][] data = results.get(j);
                if (data != null) {
                    for (int k = 0; k < data.length; k++) {
                        if (!bPrintTime && k == 0) {
                            continue;
                        }
                        String rowStr = (k == 0) ? "Time\t" : ("trialNo_" + (startTrialNo + k - 1) + "\t");
                        double[] rowData = data[k];
                        for (int q = 0; q < rowData.length; q++) {
                            rowStr += rowData[q] + "\t";
                        }
                        pw.println(rowStr);
                    }
                }
                pw.close();
            }
        }
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : MathModel(cbit.vcell.mathmodel.MathModel) VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) SimulationTask(cbit.vcell.messaging.server.SimulationTask) BigString(org.vcell.util.BigString) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) FVSolverStandalone(cbit.vcell.solvers.FVSolverStandalone) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) Simulation(cbit.vcell.solver.Simulation) DataOperationResults(cbit.vcell.simdata.DataOperationResults) File(java.io.File) XMLSource(cbit.vcell.xml.XMLSource) SolverStatus(cbit.vcell.solver.server.SolverStatus) SimulationJob(cbit.vcell.solver.SimulationJob) PrintWriter(java.io.PrintWriter)

Example 39 with VCSimulationIdentifier

use of cbit.vcell.solver.VCSimulationIdentifier in project vcell by virtualcell.

the class TestMissingSimData method runSim.

private static void runSim(SimIDAndJobID simIDAndJobID) throws Exception {
    if (notCompletedSimIDs.contains(simIDAndJobID.simID.toString())) {
        // System.out.println("--skipping notCompleted");
        return;
    } else if (completedSimIDs.contains(simIDAndJobID.simID.toString())) {
        System.out.println("-----unexpected sim rerun already completed once");
        return;
    }
    VCSimulationIdentifier vcSimulationIdentifier = new VCSimulationIdentifier(simIDAndJobID.simID, simIDAndJobID.user);
    UserLoginInfo userLoginInfo = new UserLoginInfo(simIDAndJobID.user.getName(), new DigestedPassword("xoxoxox"));
    // getVcellClient().getClientServerManager().getConnectionStatus()
    VCellConnection vcellConnection = userConnections.get(simIDAndJobID.user);
    try {
        if (vcellConnection != null) {
            vcellConnection.getMessageEvents();
        }
    } catch (Exception e) {
        e.printStackTrace();
        // assume disconnected
        vcellConnection = null;
    }
    if (vcellConnection == null) {
        VCellBootstrap vCellBootstrap = getVCellBootstrap("rmi-alpha.cam.uchc.edu", 40106, "VCellBootstrapServer", 12, false);
        vcellConnection = vCellBootstrap.getVCellConnection(userLoginInfo);
        userConnections.put(simIDAndJobID.user, vcellConnection);
    }
    SimulationStatusPersistent finalSimStatus = null;
    try {
        SimulationStatusPersistent simulationStatus = vcellConnection.getUserMetaDbServer().getSimulationStatus(vcSimulationIdentifier.getSimulationKey());
        System.out.println("initial status=" + simulationStatus);
        BigString simXML = vcellConnection.getUserMetaDbServer().getSimulationXML(vcSimulationIdentifier.getSimulationKey());
        Simulation sim = XmlHelper.XMLToSim(simXML.toString());
        SolverDescription solverDescription = sim.getSolverTaskDescription().getSolverDescription();
        if (solverDescription.equals(SolverDescription.StochGibson) || solverDescription.equals(SolverDescription.FiniteVolume)) {
            // These 2 solvers give too much trouble so skip
            System.out.println("--skipping solver");
            // notCompletedSimIDs.add(simIDAndJobID.simID.toString());
            return;
        }
        int scanCount = sim.getScanCount();
        vcellConnection.getSimulationController().startSimulation(vcSimulationIdentifier, scanCount);
        long startTime = System.currentTimeMillis();
        while (simulationStatus.isStopped() || simulationStatus.isCompleted() || simulationStatus.isFailed()) {
            Thread.sleep(250);
            simulationStatus = vcellConnection.getUserMetaDbServer().getSimulationStatus(vcSimulationIdentifier.getSimulationKey());
            MessageEvent[] messageEvents = vcellConnection.getMessageEvents();
            if ((System.currentTimeMillis() - startTime) > 60000) {
                System.out.println("-----Sim finished too fast or took too long to start");
                return;
            }
        // System.out.println(simulationStatus);
        }
        SimulationStatusPersistent lastSimStatus = simulationStatus;
        while (!simulationStatus.isStopped() && !simulationStatus.isCompleted() && !simulationStatus.isFailed()) {
            Thread.sleep(3000);
            simulationStatus = vcellConnection.getUserMetaDbServer().getSimulationStatus(vcSimulationIdentifier.getSimulationKey());
            if (!simulationStatus.toString().equals(lastSimStatus.toString())) {
                lastSimStatus = simulationStatus;
                System.out.println("running status=" + simulationStatus);
            }
            // System.out.println(simulationStatus);
            MessageEvent[] messageEvents = vcellConnection.getMessageEvents();
        // for (int i = 0; messageEvents != null && i < messageEvents.length; i++) {
        // System.out.println(messageEvents[i]);
        // }
        }
        finalSimStatus = simulationStatus;
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return;
    } finally {
        System.out.println("final status=" + finalSimStatus + "\n");
        if (finalSimStatus == null || !finalSimStatus.isCompleted()) {
            notCompletedSimIDs.add(simIDAndJobID.simID.toString());
        } else {
            completedSimIDs.add(simIDAndJobID.simID.toString());
        }
    }
}
Also used : VCellConnection(cbit.vcell.server.VCellConnection) VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) SolverDescription(cbit.vcell.solver.SolverDescription) MessageEvent(cbit.rmi.event.MessageEvent) VCellBootstrap(cbit.vcell.server.VCellBootstrap) SimulationStatusPersistent(cbit.vcell.server.SimulationStatusPersistent) DigestedPassword(org.vcell.util.document.UserLoginInfo.DigestedPassword) BigString(org.vcell.util.BigString) SQLException(java.sql.SQLException) Simulation(cbit.vcell.solver.Simulation) UserLoginInfo(org.vcell.util.document.UserLoginInfo)

Example 40 with VCSimulationIdentifier

use of cbit.vcell.solver.VCSimulationIdentifier in project vcell by virtualcell.

the class HealthService method runsimLoop.

private void runsimLoop() {
    try {
        Thread.sleep(SIMULATION_LOOP_START_DELAY);
    } catch (InterruptedException e1) {
    }
    UserLoginInfo userLoginInfo = new UserLoginInfo(testUserid, testPassword);
    while (true) {
        long id = simStartEvent();
        KeyValue savedBioModelKey = null;
        VCSimulationIdentifier runningSimId = null;
        try {
            RemoteProxyVCellConnectionFactory vcellConnectionFactory = new RemoteProxyVCellConnectionFactory(host, port, userLoginInfo);
            VCellConnection vcellConnection = vcellConnectionFactory.createVCellConnection();
            String vcmlString = IOUtils.toString(getClass().getResourceAsStream("/TestTemplate.vcml"));
            BioModel templateBioModel = XmlHelper.XMLToBioModel(new XMLSource(vcmlString));
            templateBioModel.clearVersion();
            String newBiomodelName = "test_" + System.currentTimeMillis();
            templateBioModel.setName(newBiomodelName);
            // remove all existing simulations from stored template model, and add new one
            while (templateBioModel.getNumSimulations() > 0) {
                templateBioModel.removeSimulation(templateBioModel.getSimulation(0));
            }
            MathMappingCallback callback = new MathMappingCallback() {

                @Override
                public void setProgressFraction(float fractionDone) {
                }

                @Override
                public void setMessage(String message) {
                }

                @Override
                public boolean isInterrupted() {
                    return false;
                }
            };
            templateBioModel.getSimulationContext(0).addNewSimulation("sim", callback, NetworkGenerationRequirements.ComputeFullStandardTimeout);
            BigString vcml = new BigString(XmlHelper.bioModelToXML(templateBioModel));
            String[] independentSims = new String[0];
            BigString savedBioModelVCML = vcellConnection.getUserMetaDbServer().saveBioModelAs(vcml, newBiomodelName, independentSims);
            BioModel savedBioModel = XmlHelper.XMLToBioModel(new XMLSource(savedBioModelVCML.toString()));
            savedBioModelKey = savedBioModel.getVersion().getVersionKey();
            Simulation sim = savedBioModel.getSimulation(0);
            VCSimulationIdentifier vcSimId = new VCSimulationIdentifier(sim.getKey(), sim.getVersion().getOwner());
            long eventTimestamp = System.currentTimeMillis();
            SimulationStatus simStatus = vcellConnection.getSimulationController().startSimulation(vcSimId, 1);
            simSubmitEvent(id, vcSimId);
            runningSimId = vcSimId;
            long startTime_MS = System.currentTimeMillis();
            while (simStatus.isActive()) {
                if ((System.currentTimeMillis() - startTime_MS) > SIMULATION_TIMEOUT) {
                    throw new RuntimeException("simulation took longer than " + SIMULATION_TIMEOUT + " to complete");
                }
                Thread.sleep(1000);
                MessageEvent[] messageEvents = vcellConnection.getMessageEvents();
                if (messageEvents != null) {
                    for (MessageEvent event : messageEvents) {
                        if (event instanceof SimulationJobStatusEvent) {
                            SimulationJobStatusEvent jobEvent = (SimulationJobStatusEvent) event;
                            SimulationJobStatus jobStatus = jobEvent.getJobStatus();
                            VCSimulationIdentifier eventSimId = jobStatus.getVCSimulationIdentifier();
                            if (eventSimId.getOwner().equals(userLoginInfo.getUser()) && eventSimId.getSimulationKey().equals(sim.getKey())) {
                                simStatus = SimulationStatus.updateFromJobEvent(simStatus, jobEvent);
                            }
                        }
                    }
                }
            }
            runningSimId = null;
            if (!simStatus.isCompleted()) {
                throw new RuntimeException("failed: " + simStatus.getDetails());
            }
            simSuccess(id);
        } catch (Throwable e) {
            simFailed(id, e.getMessage());
        } finally {
            // cleanup
            try {
                RemoteProxyVCellConnectionFactory vcellConnectionFactory = new RemoteProxyVCellConnectionFactory(host, port, userLoginInfo);
                VCellConnection vcellConnection = vcellConnectionFactory.createVCellConnection();
                if (runningSimId != null) {
                    try {
                        vcellConnection.getSimulationController().stopSimulation(runningSimId);
                    } catch (Exception e) {
                        e.printStackTrace(System.out);
                    }
                }
                if (savedBioModelKey != null) {
                    vcellConnection.getUserMetaDbServer().deleteBioModel(savedBioModelKey);
                }
            } catch (Exception e) {
                e.printStackTrace(System.out);
            }
        }
        try {
            Thread.sleep(SIMULATION_LOOP_SLEEP);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
Also used : VCellConnection(cbit.vcell.server.VCellConnection) VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) RemoteProxyVCellConnectionFactory(cbit.vcell.message.server.bootstrap.client.RemoteProxyVCellConnectionFactory) KeyValue(org.vcell.util.document.KeyValue) MathMappingCallback(cbit.vcell.mapping.SimulationContext.MathMappingCallback) MessageEvent(cbit.rmi.event.MessageEvent) BigString(org.vcell.util.BigString) BigString(org.vcell.util.BigString) SimulationJobStatusEvent(cbit.rmi.event.SimulationJobStatusEvent) Simulation(cbit.vcell.solver.Simulation) SimulationStatus(cbit.vcell.server.SimulationStatus) BioModel(cbit.vcell.biomodel.BioModel) SimulationJobStatus(cbit.vcell.server.SimulationJobStatus) UserLoginInfo(org.vcell.util.document.UserLoginInfo) XMLSource(cbit.vcell.xml.XMLSource)

Aggregations

VCSimulationIdentifier (cbit.vcell.solver.VCSimulationIdentifier)59 KeyValue (org.vcell.util.document.KeyValue)37 VCSimulationDataIdentifier (cbit.vcell.solver.VCSimulationDataIdentifier)27 User (org.vcell.util.document.User)20 File (java.io.File)17 Simulation (cbit.vcell.solver.Simulation)16 BigString (org.vcell.util.BigString)14 UserLoginInfo (org.vcell.util.document.UserLoginInfo)11 BioModel (cbit.vcell.biomodel.BioModel)10 Hashtable (java.util.Hashtable)10 SimulationJobStatus (cbit.vcell.server.SimulationJobStatus)9 ObjectNotFoundException (org.vcell.util.ObjectNotFoundException)9 SQLException (java.sql.SQLException)7 CartesianMesh (cbit.vcell.solvers.CartesianMesh)6 FileNotFoundException (java.io.FileNotFoundException)6 VCDataIdentifier (org.vcell.util.document.VCDataIdentifier)6 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)5 VCMessageSession (cbit.vcell.message.VCMessageSession)5 VCellConnection (cbit.vcell.server.VCellConnection)5 XMLSource (cbit.vcell.xml.XMLSource)5