use of cbit.vcell.server.SimulationStatus in project vcell by virtualcell.
the class SimulationListPanel method deleteSimulations.
/**
* Comment
*/
private void deleteSimulations() {
int[] selections = getScrollPaneTable().getSelectedRows();
StringBuilder simulationNames = new StringBuilder();
ArrayList<Simulation> simList = new ArrayList<Simulation>();
// Simulation[] allSims = getSimulationWorkspace().getSimulations();
for (int i = 0; i < selections.length; i++) {
Simulation sim = (Simulation) (ivjSimulationListTableModel1.getValueAt(selections[i]));
SimulationStatus simStatus = getSimulationWorkspace().getSimulationStatus(sim);
if (!simStatus.isRunning()) {
simList.add(sim);
simulationNames.append(sim.getName() + "\n");
}
}
if (simList.size() == 0) {
return;
}
String confirm = DialogUtils.showOKCancelWarningDialog(this, "Deleting", "You are going to delete the following simulation(s):\n\n" + simulationNames + "\n Continue?");
if (confirm.equals(UserMessage.OPTION_CANCEL)) {
return;
}
Simulation[] toDelete = (Simulation[]) BeanUtils.getArray(simList, Simulation.class);
try {
getSimulationWorkspace().deleteSimulations(toDelete);
} catch (Throwable exc) {
exc.printStackTrace(System.out);
PopupGenerator.showErrorDialog(this, "Could not delete all simulations\n" + exc.getMessage(), exc);
}
// unset selection - may not be needed...
getScrollPaneTable().clearSelection();
}
use of cbit.vcell.server.SimulationStatus in project vcell by virtualcell.
the class SimulationStatusDetails method getSimulationStatusDisplay.
/**
* Comment
*/
Object getSimulationStatusDisplay(int index) {
SimulationStatus simStatus = simWorkspace.getSimulationStatus(sim);
if (simStatus != null) {
SimulationJobStatus jobStatus = simStatus.getJobStatus(index);
Double progress = simStatus.getProgressAt(index);
if (jobStatus != null) {
if (progress != null && jobStatus.getSchedulerStatus().isRunning() && progress.doubleValue() > 0) {
statusBars[index].setValue((int) (progress.doubleValue() * 100));
return statusBars[index];
} else {
return jobStatus.getSimulationMessage().getDisplayMessage();
}
} else {
return simStatus.getDetails();
}
}
return null;
}
use of cbit.vcell.server.SimulationStatus in project vcell by virtualcell.
the class CheckBeforeDelete method checkLostResults.
/**
* Insert the method's description here.
* Creation date: (6/1/2004 3:44:03 PM)
* @return cbit.vcell.solver.SolverResultSetInfo[]
* @param mathmodel cbit.vcell.mathmodel.Mathmodel
*/
private Simulation[] checkLostResults(MathModel oldMathmodel, MathModel newlySavedMathmodel, cbit.vcell.clientdb.DocumentManager documentManager, Simulation[] submittedSimulations) throws Exception {
//
// before deleting old version, prompt user if old simulation results will not be availlable in new edition
//
Vector<Simulation> lostResultsSimulationList = new Vector<Simulation>();
Simulation[] oldSimulations = oldMathmodel.getSimulations();
for (int i = 0; i < oldSimulations.length; i++) {
Simulation oldSimulation = oldSimulations[i];
// SolverResultSetInfo rsInfo = null;
SimulationStatus simStatus = null;
SimulationInfo oldSimInfo = oldSimulation.getSimulationInfo();
if (oldSimInfo != null) {
//
// we need to ask for previous sim results (here we need possible translation to ask for parent's results).
//
simStatus = documentManager.getServerSimulationStatus(oldSimInfo.getAuthoritativeVCSimulationIdentifier());
}
if (simStatus != null && simStatus.getHasData()) {
//
// results exist in old version (the Mathmodel to be deleted) for SimulationInfo "oldSimInfo"
// Users should be warned when they are going to loose any simulation results in any unexpected way.
//
// WARN if the lost data is because new simulation is not mathematically equivalent to old edition
// (different MathDescription key)
//
// IGNORE if the lost data is from edits of a Simulation only (same MathDescription)
// (same MathDescription key, different Simulation key)
//
// IGNORE if Simulation has been deleted
// (Simulation not found in current Mathmodel)
//
// IGNORE if Simulation has been submitted for running
//
boolean bDataInNewEdition = false;
Simulation[] newSimulations = newlySavedMathmodel.getSimulations();
Simulation correspondingSimulation = null;
for (int j = 0; j < newSimulations.length; j++) {
if (newSimulations[j].getName().equals(oldSimulation.getName())) {
correspondingSimulation = newSimulations[j];
if (correspondingSimulation.getKey().equals(oldSimulation.getKey())) {
//
// exactly same simulation (same key), so no lost data
//
bDataInNewEdition = true;
} else if (correspondingSimulation.getSimulationVersion().getParentSimulationReference() != null) {
//
// new simulation changed but points to same results
//
bDataInNewEdition = true;
}
break;
}
}
if (!bDataInNewEdition && correspondingSimulation != null) {
//
// result set (for "rsInfo") will be lost, should we ignore this fact?
//
boolean bIgnore = false;
//
// ignore if only Simulation has been edited (same MathDescription)
//
MathDescription mdCorr = correspondingSimulation.getMathDescription();
MathDescription mdOld = oldSimulation.getMathDescription();
if (mdCorr.getKey().equals(mdOld.getKey())) {
bIgnore = true;
}
//
for (int j = 0; submittedSimulations != null && j < submittedSimulations.length; j++) {
if (correspondingSimulation.getName().equals(submittedSimulations[j].getName())) {
bIgnore = true;
}
}
//
if (!bIgnore) {
lostResultsSimulationList.add(correspondingSimulation);
}
}
}
}
return (Simulation[]) BeanUtils.getArray(lostResultsSimulationList, Simulation.class);
}
use of cbit.vcell.server.SimulationStatus in project vcell by virtualcell.
the class RunSims method run.
/**
* Insert the method's description here.
* Creation date: (5/31/2004 6:04:14 PM)
* @param hashTable java.util.Hashtable
* @param clientWorker cbit.vcell.desktop.controls.ClientWorker
*/
public void run(Hashtable<String, Object> hashTable) throws java.lang.Exception {
DocumentWindowManager documentWindowManager = (DocumentWindowManager) hashTable.get(CommonTask.DOCUMENT_WINDOW_MANAGER.name);
ClientSimManager clientSimManager = (ClientSimManager) hashTable.get("clientSimManager");
// DocumentManager documentManager = (DocumentManager)hashTable.get(CommonTask.DOCUMENT_MANAGER.name);
JobManager jobManager = (JobManager) hashTable.get("jobManager");
Simulation[] simulations = (Simulation[]) hashTable.get("simulations");
Hashtable<Simulation, Throwable> failures = new Hashtable<Simulation, Throwable>();
if (simulations != null && simulations.length > 0) {
// we need to get the new ones if a save occurred...
if (hashTable.containsKey(SaveDocument.DOC_KEY)) {
VCDocument savedDocument = (VCDocument) hashTable.get(SaveDocument.DOC_KEY);
Simulation[] allSims = null;
if (savedDocument instanceof BioModel) {
allSims = ((BioModel) savedDocument).getSimulations();
} else if (savedDocument instanceof MathModel) {
allSims = ((MathModel) savedDocument).getSimulations();
}
Vector<Simulation> v = new Vector<Simulation>();
for (int i = 0; i < simulations.length; i++) {
for (int j = 0; j < allSims.length; j++) {
if (simulations[i].getName().equals(allSims[j].getName())) {
v.add(allSims[j]);
break;
}
}
}
simulations = (Simulation[]) BeanUtils.getArray(v, Simulation.class);
}
for (Simulation sim : simulations) {
try {
int dimension = sim.getMathDescription().getGeometry().getDimension();
if (clientSimManager.getSimulationStatus(sim).isCompleted()) {
// completed
String warningMessage = VCellErrorMessages.getErrorMessage(VCellErrorMessages.RunSims_1, sim.getName());
String result = DialogUtils.showWarningDialog(documentWindowManager.getComponent(), warningMessage, new String[] { UserMessage.OPTION_OK, UserMessage.OPTION_CANCEL }, UserMessage.OPTION_OK);
if (result == null || !result.equals(UserMessage.OPTION_OK)) {
continue;
}
}
DataProcessingInstructions dataProcessingInstructions = sim.getDataProcessingInstructions();
try {
if (dataProcessingInstructions != null) {
dataProcessingInstructions.getSampleImageFieldData(sim.getVersion().getOwner());
}
} catch (Exception ex) {
DialogUtils.showErrorDialog(documentWindowManager.getComponent(), "Problem found in simulation '" + sim.getName() + "':\n" + ex.getMessage());
continue;
}
if (dimension > 0) {
MeshSpecification meshSpecification = sim.getMeshSpecification();
boolean bCellCentered = sim.hasCellCenteredMesh();
if (meshSpecification != null && !meshSpecification.isAspectRatioOK(bCellCentered)) {
String warningMessage = VCellErrorMessages.getErrorMessage(VCellErrorMessages.RunSims_2, sim.getName(), "\u0394x=" + meshSpecification.getDx(bCellCentered) + "\n" + "\u0394y=" + meshSpecification.getDy(bCellCentered) + (dimension < 3 ? "" : "\n\u0394z=" + meshSpecification.getDz(bCellCentered)));
String result = DialogUtils.showWarningDialog(documentWindowManager.getComponent(), warningMessage, new String[] { UserMessage.OPTION_OK, UserMessage.OPTION_CANCEL }, UserMessage.OPTION_OK);
if (result == null || !result.equals(UserMessage.OPTION_OK)) {
continue;
}
}
if (sim.getSolverTaskDescription().getSolverDescription().equals(SolverDescription.Smoldyn)) {
if (!isSmoldynTimeStepOK(sim)) {
double s = smoldynTimestepVars.getSpatialResolution();
double dMax = smoldynTimestepVars.getMaxDiffusion();
double condn = (s * s) / (2.0 * dMax);
String warningMessage = VCellErrorMessages.getErrorMessage(VCellErrorMessages.RunSims_3, Double.toString(s), Double.toString(dMax), Double.toString(condn));
DialogUtils.showErrorDialog(documentWindowManager.getComponent(), warningMessage);
continue;
}
}
// check the number of regions if the simulation mesh is coarser.
Geometry mathGeometry = sim.getMathDescription().getGeometry();
ISize newSize = meshSpecification.getSamplingSize();
ISize defaultSize = mathGeometry.getGeometrySpec().getDefaultSampledImageSize();
if (!sim.getSolverTaskDescription().getSolverDescription().isChomboSolver()) {
int defaultTotalVolumeElements = mathGeometry.getGeometrySurfaceDescription().getVolumeSampleSize().getXYZ();
int newTotalVolumeElements = meshSpecification.getSamplingSize().getXYZ();
if (defaultTotalVolumeElements > newTotalVolumeElements) {
// coarser
Geometry resampledGeometry = (Geometry) BeanUtils.cloneSerializable(mathGeometry);
GeometrySurfaceDescription geoSurfaceDesc = resampledGeometry.getGeometrySurfaceDescription();
geoSurfaceDesc.setVolumeSampleSize(newSize);
geoSurfaceDesc.updateAll();
if (mathGeometry.getGeometrySurfaceDescription().getGeometricRegions() == null) {
mathGeometry.getGeometrySurfaceDescription().updateAll();
}
int defaultNumGeometricRegions = mathGeometry.getGeometrySurfaceDescription().getGeometricRegions().length;
int numGeometricRegions = geoSurfaceDesc.getGeometricRegions().length;
if (numGeometricRegions != defaultNumGeometricRegions) {
String warningMessage = VCellErrorMessages.getErrorMessage(VCellErrorMessages.RunSims_4, newSize.getX() + (dimension > 1 ? " x " + newSize.getY() : "") + (dimension > 2 ? " x " + newSize.getZ() : ""), sim.getName(), numGeometricRegions, defaultNumGeometricRegions);
String result = PopupGenerator.showWarningDialog(documentWindowManager.getComponent(), warningMessage, new String[] { UserMessage.OPTION_OK, UserMessage.OPTION_CANCEL }, UserMessage.OPTION_OK);
if (result == null || !result.equals(UserMessage.OPTION_OK)) {
continue;
}
}
}
if (mathGeometry.getGeometrySpec().hasImage()) {
// if it's an image.
if (defaultSize.getX() + 1 < newSize.getX() || defaultSize.getY() + 1 < newSize.getY() || defaultSize.getZ() + 1 < newSize.getZ()) {
// finer
String defaultSizeString = (defaultSize.getX() + 1) + (dimension > 1 ? " x " + (defaultSize.getY() + 1) : "") + (dimension > 2 ? " x " + (defaultSize.getZ() + 1) : "");
String warningMessage = VCellErrorMessages.getErrorMessage(VCellErrorMessages.RunSims_5, newSize.getX() + (dimension > 1 ? " x " + newSize.getY() : "") + (dimension > 2 ? " x " + newSize.getZ() : ""), sim.getName(), defaultSizeString, defaultSizeString);
String result = DialogUtils.showWarningDialog(documentWindowManager.getComponent(), warningMessage, new String[] { UserMessage.OPTION_OK, UserMessage.OPTION_CANCEL }, UserMessage.OPTION_OK);
if (result == null || !result.equals(UserMessage.OPTION_OK)) {
continue;
}
}
}
}
boolean bGiveWarning = false;
for (int i = 0; i < sim.getScanCount(); i++) {
if (sim.getSolverTaskDescription().getSolverDescription().equals(SolverDescription.SundialsPDE)) {
SimulationJob simJob = new SimulationJob(sim, i, null);
if (simJob.getSimulationSymbolTable().hasTimeVaryingDiffusionOrAdvection()) {
bGiveWarning = true;
break;
}
}
}
if (bGiveWarning) {
String warningMessage = VCellErrorMessages.RunSims_6;
String result = DialogUtils.showWarningDialog(documentWindowManager.getComponent(), warningMessage, new String[] { UserMessage.OPTION_OK, UserMessage.OPTION_CANCEL }, UserMessage.OPTION_OK);
if (result == null || !result.equals(UserMessage.OPTION_OK)) {
continue;
}
}
}
SimulationInfo simInfo = sim.getSimulationInfo();
if (simInfo != null) {
//
// translate to common ancestral simulation (oldest mathematically equivalent simulation)
//
SimulationStatus simulationStatus = jobManager.startSimulation(simInfo.getAuthoritativeVCSimulationIdentifier(), sim.getScanCount());
// updateStatus
clientSimManager.updateStatusFromStartRequest(sim, simulationStatus);
} else {
// this should really not happen...
throw new RuntimeException(">>>>>>>>>> trying to run an unsaved simulation...");
}
} catch (Throwable exc) {
exc.printStackTrace(System.out);
failures.put(sim, exc);
}
}
}
// we deal with individual request failures here, passing down only other things (that break the whole thing down) to dispatcher
if (!failures.isEmpty()) {
Enumeration<Simulation> en = failures.keys();
while (en.hasMoreElements()) {
Simulation sim = en.nextElement();
Throwable exc = (Throwable) failures.get(sim);
// // updateStatus
// SimulationStatus simulationStatus = clientSimManager.updateStatusFromStartRequest(sim, true, exc.getMessage());
// notify user
PopupGenerator.showErrorDialog(documentWindowManager, "Failed to start simulation'" + sim.getName() + "'\n" + exc.getMessage());
}
}
}
use of cbit.vcell.server.SimulationStatus 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();
}
}
}
Aggregations