use of cbit.vcell.server.SimulationJobStatusPersistent in project vcell by virtualcell.
the class VCComprehensiveStatistics method collectMathModelStats.
private void collectMathModelStats(long startDateInMs, long endDateInMs) throws DataAccessException {
retrieveUsers();
for (User user : userList) {
if (!userConstraintList.contains(user.getName())) {
continue;
}
if (!internalDeveloper.contains(user.getName())) {
boolean bInternal = internalUsers.contains(user.getName());
ModelStat modelStat = mathModelStats[bInternal ? 0 : 1];
MathModelInfo[] mathModelInfos = dbServerImpl.getMathModelInfos(user, false);
for (MathModelInfo mmi : mathModelInfos) {
Date createDate = mmi.getVersion().getDate();
long t = createDate.getTime();
// }
if (t < startDateInMs || t > endDateInMs) {
continue;
}
// modelStat.count_model ++;
try {
BigString mathModelXML = dbServerImpl.getMathModelXML(user, mmi.getVersion().getVersionKey());
MathModel mathModel = (MathModel) waitForModel(mathModelXML, true);
if (mathModel == null) {
System.out.println("---------- Skipped MathModel " + mmi.getVersion() + " ----------");
continue;
}
modelStat.count_model++;
boolean bHasCompletedSim = false;
for (Simulation sim : mathModel.getSimulations()) {
SimulationStatusPersistent ss = dbServerImpl.getSimulationStatus(sim.getKey());
for (int scan = 0; scan < sim.getScanCount(); scan++) {
SimulationJobStatusPersistent jobStatus = ss.getJobStatus(scan);
if (jobStatus != null) {
if (jobStatus.getSchedulerStatus() == SchedulerStatus.COMPLETED) {
bHasCompletedSim = true;
long elapsed = jobStatus.getEndDate().getTime() - jobStatus.getStartDate().getTime();
if (elapsed < 2 * MINUTE_IN_MS) {
modelStat.runningTimeHistogram[0]++;
} else if (elapsed < 5 * MINUTE_IN_MS) {
modelStat.runningTimeHistogram[1]++;
} else if (elapsed < 20 * MINUTE_IN_MS) {
modelStat.runningTimeHistogram[2]++;
} else if (elapsed < HOUR_IN_MS) {
modelStat.runningTimeHistogram[3]++;
} else if (elapsed < DAY_IN_MS) {
modelStat.runningTimeHistogram[4]++;
} else {
modelStat.runningTimeHistogram[5]++;
}
}
int dimension = sim.getMathDescription().getGeometry().getDimension();
modelStat.count_geoDimSim[dimension]++;
if (sim.getMathDescription().isNonSpatialStoch()) {
modelStat.count_sim_stochastic++;
} else {
modelStat.count_sim_deterministic++;
}
if (dimension > 0) {
if (sim.getSolverTaskDescription().getSolverDescription().isSemiImplicitPdeSolver()) {
modelStat.count_semiSim++;
} else {
modelStat.count_fullySim++;
}
}
}
}
}
if (bHasCompletedSim) {
modelStat.count_model_simcomplete++;
}
} catch (Exception e2) {
e2.printStackTrace(System.out);
}
}
}
}
itemCount++;
statOutputPW.println(itemCount + ". MathModel Statistics ");
statOutputPW.println("====================================================");
for (ModelStat modelStat : mathModelStats) {
statOutputPW.println("\t" + modelStat.title);
statOutputPW.println("========================================");
statOutputPW.println("number of mathmodels saved :\t" + modelStat.count_model);
statOutputPW.println("number of mathmodels that has at least 1 completed simulation :\t" + modelStat.count_model_simcomplete);
statOutputPW.println();
statOutputPW.println("Simulation statistics (including all simulations (stopped, failed, completed) :");
statOutputPW.println("number of run simulation ODE :\t" + modelStat.count_geoDimSim[0]);
statOutputPW.println("number of run simulation 1D :\t" + modelStat.count_geoDimSim[1]);
statOutputPW.println("number of run simulation 2D :\t" + modelStat.count_geoDimSim[2]);
statOutputPW.println("number of run simulation 3D :\t" + modelStat.count_geoDimSim[3]);
statOutputPW.println("number of run simulation Semi-Implicit :\t" + modelStat.count_semiSim);
statOutputPW.println("number of run simulation Fully-Implicit :\t" + modelStat.count_fullySim);
statOutputPW.println("number of run simulation stochastic :\t" + modelStat.count_sim_stochastic);
statOutputPW.println("number of run simulation deterministic :\t" + modelStat.count_sim_deterministic);
statOutputPW.println();
statOutputPW.println("Running time histogram for completed simulations only:");
statOutputPW.println("0 ~ 2min:\t" + modelStat.runningTimeHistogram[0]);
statOutputPW.println("2 ~ 5min:\t" + modelStat.runningTimeHistogram[1]);
statOutputPW.println("5 ~ 20min:\t" + modelStat.runningTimeHistogram[2]);
statOutputPW.println("20min ~ 1hr:\t" + modelStat.runningTimeHistogram[3]);
statOutputPW.println("1hr ~ 1day:\t" + modelStat.runningTimeHistogram[4]);
statOutputPW.println(">1day:\t" + modelStat.runningTimeHistogram[5]);
statOutputPW.println();
statOutputPW.println();
statOutputPW.flush();
}
}
use of cbit.vcell.server.SimulationJobStatusPersistent in project vcell by virtualcell.
the class VCComprehensiveStatistics method collectBioModelStats.
private void collectBioModelStats(long startDateInMs, long endDateInMs) throws DataAccessException {
retrieveUsers();
List<String> internalDeveloper = Arrays.asList(VCComprehensiveStatistics.INTERNAL_DEVELOPERS);
for (User user : userList) {
if (!userConstraintList.contains(user.getName())) {
continue;
}
if (!internalDeveloper.contains(user.getName())) {
boolean bInternal = internalUsers.contains(user.getName());
ModelStat modelStat = bioModelStats[bInternal ? 0 : 1];
BioModelInfo[] bioModelInfos = dbServerImpl.getBioModelInfos(user, false);
for (BioModelInfo bmi : bioModelInfos) {
Date createDate = bmi.getVersion().getDate();
long t = createDate.getTime();
// }
if (t < startDateInMs || t > endDateInMs) {
continue;
}
// modelStat.count_model ++;
try {
BigString bioModelXML = dbServerImpl.getBioModelXML(user, bmi.getVersion().getVersionKey());
BioModel bioModel = (BioModel) waitForModel(bioModelXML, false);
if (bioModel == null) {
System.out.println("---------- Skipped BioModel " + bmi.getVersion() + " ----------");
continue;
}
modelStat.count_model++;
for (SimulationContext simContext : bioModel.getSimulationContexts()) {
modelStat.count_geoDimApplications[simContext.getGeometry().getDimension()]++;
if (simContext.isStoch()) {
modelStat.count_app_stochastic++;
} else {
modelStat.count_app_deterministic++;
}
}
boolean bHasCompletedSim = false;
for (Simulation sim : bioModel.getSimulations()) {
SimulationStatusPersistent ss = dbServerImpl.getSimulationStatus(sim.getKey());
if (ss != null) {
for (int scan = 0; scan < sim.getScanCount(); scan++) {
SimulationJobStatusPersistent jobStatus = ss.getJobStatus(scan);
if (jobStatus != null) {
if (jobStatus.getSchedulerStatus() == SchedulerStatus.COMPLETED) {
bHasCompletedSim = true;
long elapsed = jobStatus.getEndDate().getTime() - jobStatus.getStartDate().getTime();
if (elapsed < 2 * MINUTE_IN_MS) {
modelStat.runningTimeHistogram[0]++;
} else if (elapsed < 5 * MINUTE_IN_MS) {
modelStat.runningTimeHistogram[1]++;
} else if (elapsed < 20 * MINUTE_IN_MS) {
modelStat.runningTimeHistogram[2]++;
} else if (elapsed < HOUR_IN_MS) {
modelStat.runningTimeHistogram[3]++;
} else if (elapsed < DAY_IN_MS) {
modelStat.runningTimeHistogram[4]++;
} else {
modelStat.runningTimeHistogram[5]++;
}
}
int dimension = sim.getMathDescription().getGeometry().getDimension();
modelStat.count_geoDimSim[dimension]++;
if (sim.getMathDescription().isNonSpatialStoch() || sim.getMathDescription().isSpatialStoch()) {
modelStat.count_sim_stochastic++;
} else {
modelStat.count_sim_deterministic++;
}
if (dimension > 0) {
if (sim.getSolverTaskDescription().getSolverDescription().isSemiImplicitPdeSolver()) {
modelStat.count_semiSim++;
} else {
modelStat.count_fullySim++;
}
}
}
}
}
}
if (bHasCompletedSim) {
modelStat.count_model_simcomplete++;
}
} catch (Exception e2) {
e2.printStackTrace(System.out);
}
}
}
}
itemCount++;
statOutputPW.println(itemCount + ". BioModel Statistics ");
statOutputPW.println("====================================================");
for (ModelStat modelStat : bioModelStats) {
statOutputPW.println("\t" + modelStat.title);
statOutputPW.println("========================================");
statOutputPW.println("number of biomodels saved :\t" + modelStat.count_model);
statOutputPW.println("number of biomodels that has at least 1 completed simulation :\t" + modelStat.count_model_simcomplete);
statOutputPW.println();
statOutputPW.println("Application statistics :");
statOutputPW.println("number of application ODE :\t" + modelStat.count_geoDimApplications[0]);
statOutputPW.println("number of application 1D :\t" + modelStat.count_geoDimApplications[1]);
statOutputPW.println("number of application 2D :\t" + modelStat.count_geoDimApplications[2]);
statOutputPW.println("number of application 3D :\t" + modelStat.count_geoDimApplications[3]);
statOutputPW.println("number of application stochastic :\t" + modelStat.count_app_stochastic);
statOutputPW.println("number of application deterministic :\t" + modelStat.count_app_deterministic);
statOutputPW.println();
statOutputPW.println("Simulation statistics (including all simulations (stopped, failed, completed) :");
statOutputPW.println("number of run simulation ODE :\t" + modelStat.count_geoDimSim[0]);
statOutputPW.println("number of run simulation 1D :\t" + modelStat.count_geoDimSim[1]);
statOutputPW.println("number of run simulation 2D :\t" + modelStat.count_geoDimSim[2]);
statOutputPW.println("number of run simulation 3D :\t" + modelStat.count_geoDimSim[3]);
statOutputPW.println("number of run simulation Semi-Implicit :\t" + modelStat.count_semiSim);
statOutputPW.println("number of run simulation Fully-Implicit :\t" + modelStat.count_fullySim);
statOutputPW.println("number of run simulation stochastic :\t" + modelStat.count_sim_stochastic);
statOutputPW.println("number of run simulation deterministic :\t" + modelStat.count_sim_deterministic);
statOutputPW.println();
statOutputPW.println("Running time histogram for completed simulations only:");
statOutputPW.println("0 ~ 2min:\t" + modelStat.runningTimeHistogram[0]);
statOutputPW.println("2 ~ 5min:\t" + modelStat.runningTimeHistogram[1]);
statOutputPW.println("5 ~ 20min:\t" + modelStat.runningTimeHistogram[2]);
statOutputPW.println("20min ~ 1hr:\t" + modelStat.runningTimeHistogram[3]);
statOutputPW.println("1hr ~ 1day:\t" + modelStat.runningTimeHistogram[4]);
statOutputPW.println(">1day:\t" + modelStat.runningTimeHistogram[5]);
statOutputPW.println();
statOutputPW.println();
statOutputPW.flush();
}
}
use of cbit.vcell.server.SimulationJobStatusPersistent in project vcell by virtualcell.
the class VcmlOmexConverter method vcmlToOmexConversion.
public static boolean vcmlToOmexConversion(String outputBaseDir) throws XmlParseException, IOException, DataAccessException, SQLException {
// Get VCML file path from -i flag
int sedmlLevel = 1;
int sedmlVersion = 2;
String inputVcmlFile = cliHandler.getInputFilePath();
// Get directory file path from -o flag
String outputDir = cliHandler.getOutputDirPath();
// get VCML name from VCML path
// String vcmlName = inputVcmlFile.split(File.separator, 10)[inputVcmlFile.split(File.separator, 10).length - 1].split("\\.", 5)[0];
// platform independent, strips extension too
String vcmlName = FilenameUtils.getBaseName(inputVcmlFile);
File vcmlFilePath = new File(inputVcmlFile);
// Create biomodel
BioModel bioModel = XmlHelper.XMLToBioModel(new XMLSource(vcmlFilePath));
bioModel.refreshDependencies();
int numSimulations = bioModel.getNumSimulations();
if (outputBaseDir != null && numSimulations == 0) {
CLIStandalone.writeSimErrorList(outputBaseDir, vcmlName + " has no simulations.");
return false;
}
// we extract the simulations with field data from the list of simulations since they are not supported
List<Simulation> simulationsToRemove = new ArrayList<>();
for (Simulation simulation : bioModel.getSimulations()) {
boolean bFieldDataFound = false;
Enumeration<Variable> variables = simulation.getMathDescription().getVariables();
while (variables.hasMoreElements()) {
Variable var = variables.nextElement();
Expression exp = var.getExpression();
FieldFunctionArguments[] ffas = FieldUtilities.getFieldFunctionArguments(exp);
if (ffas != null && ffas.length > 0) {
bFieldDataFound = true;
// we are done with this simulation if we know it has at least one variable with a field data in its expression
break;
}
}
if (bFieldDataFound) {
simulationsToRemove.add(simulation);
CLIStandalone.writeSimErrorList(outputBaseDir, vcmlName + " excluded: FieldData not supported at this time.");
SolverDescription solverDescription = simulation.getSolverTaskDescription().getSolverDescription();
String solverName = solverDescription.getShortDisplayLabel();
CLIStandalone.writeSimErrorList(outputBaseDir, " " + solverName);
}
}
for (Simulation simulation : simulationsToRemove) {
try {
bioModel.removeSimulation(simulation);
} catch (PropertyVetoException e) {
System.out.println("Failed to remove simulation with field data");
e.printStackTrace();
}
}
// we replace the obsolete solver with the fully supported equivalent
for (Simulation simulation : bioModel.getSimulations()) {
if (simulation.getSolverTaskDescription().getSolverDescription().equals(SolverDescription.FiniteVolume)) {
try {
simulation.getSolverTaskDescription().setSolverDescription(SolverDescription.SundialsPDE);
} catch (PropertyVetoException e) {
System.out.println("Failed to replace obsolete solver");
e.printStackTrace();
}
}
}
// NOTE: SEDML exporter exports both SEDML as well as required SBML
List<Simulation> simsToExport = null;
Set<String> solverNames = new LinkedHashSet<>();
if (bHasDataOnly) {
// make list of simulations to export with only sims that have data on the server
simsToExport = new ArrayList<Simulation>();
for (Simulation simulation : bioModel.getSimulations()) {
SolverDescription solverDescription = simulation.getSolverTaskDescription().getSolverDescription();
String solverName = solverDescription.getShortDisplayLabel();
solverNames.add(solverName);
// check server status
KeyValue parentKey = simulation.getSimulationVersion().getParentSimulationReference();
SimulationJobStatusPersistent[] statuses = adminDbTopLevel.getSimulationJobStatusArray(parentKey == null ? simulation.getKey() : parentKey, false);
if (statuses == null)
continue;
if (statuses.length == 0)
continue;
for (int i = 0; i < statuses.length; i++) {
if (statuses[i].hasData()) {
simsToExport.add(simulation);
continue;
}
}
// String dbDriverName = PropertyLoader.getProperty(PropertyLoader.dbDriverName, null);
// String dbConnectURL = PropertyLoader.getProperty(PropertyLoader.dbConnectURL, null);
// String dbSchemaUser = PropertyLoader.getProperty(PropertyLoader.dbUserid, null);
// String dbPassword = PropertyLoader.getSecretValue(PropertyLoader.dbPasswordValue, PropertyLoader.dbPasswordFile);
// DataSetControllerImpl dsControllerImpl = new DataSetControllerImpl(null, new File(outputBaseDir), null);
//
// code used to recover field data
//
// HashMap<User, Vector<ExternalDataIdentifier>> allExternalDataIdentifiers = FieldDataDBOperationDriver.getAllExternalDataIdentifiers();
// Enumeration<Variable> variables = simulation.getMathDescription().getVariables();
// while(variables.hasMoreElements()) {
// Variable var = variables.nextElement();
// Expression exp = var.getExpression();
// FieldFunctionArguments[] ffas = FieldUtilities.getFieldFunctionArguments( exp);
//
// if(ffas != null && ffas.length > 0) {
// FieldDataIdentifierSpec[] aaa = DataSetControllerImpl.getFieldDataIdentifierSpecs_private(
// ffas, simulation.getVersion().getOwner(), true, allExternalDataIdentifiers);
//
// System.out.println((ffas == null) ? "null" : exp.infix() + ", not null:" + ffas.length);
// }
// }
}
}
if (outputBaseDir != null && bHasDataOnly == true && simsToExport.size() == 0) {
CLIStandalone.writeSimErrorList(outputBaseDir, vcmlName + " has no simulations with any results.");
for (String solverName : solverNames) {
CLIStandalone.writeSimErrorList(outputBaseDir, " " + solverName);
}
return false;
}
String rdfString = getMetadata(vcmlName, bioModel);
XmlUtil.writeXMLStringToFile(rdfString, String.valueOf(Paths.get(outputDir, "metadata.rdf")), true);
if (bMakeLogsOnly) {
return false;
}
SEDMLExporter sedmlExporter = new SEDMLExporter(bioModel, sedmlLevel, sedmlVersion, simsToExport);
String sedmlString = sedmlExporter.getSEDMLFile(outputDir, vcmlName, bForceVCML, bHasDataOnly, true);
XmlUtil.writeXMLStringToFile(sedmlString, String.valueOf(Paths.get(outputDir, vcmlName + ".sedml")), true);
// libCombine needs native lib
ResourceUtil.setNativeLibraryDirectory();
NativeLoader.load("combinej");
boolean isDeleted = false;
boolean isCreated;
try {
CombineArchive archive = new CombineArchive();
String[] files;
// TODO: try-catch if no files
File dir = new File(outputDir);
files = dir.list();
for (String sd : files) {
if (sd.endsWith(".sedml")) {
archive.addFile(Paths.get(outputDir, sd).toString(), // target file name
"./" + sd, KnownFormats.lookupFormat("sedml"), // mark file as master
true);
} else if (sd.endsWith(".sbml") || sd.endsWith(".xml")) {
archive.addFile(Paths.get(outputDir, sd).toString(), "./" + sd, KnownFormats.lookupFormat("sbml"), // mark file as master
false);
} else if (sd.endsWith(".rdf")) {
archive.addFile(Paths.get(outputDir, sd).toString(), "./" + sd, "http://identifiers.org/combine.specifications/omex-metadata", // KnownFormats.lookupFormat("xml"),
false);
}
}
archive.addFile(Paths.get(String.valueOf(vcmlFilePath)).toString(), "./" + vcmlName + ".vcml", "http://purl.org/NET/mediatypes/application/vcml+xml", false);
// writing into combine archive
String omexPath = Paths.get(outputDir, vcmlName + ".omex").toString();
File omexFile = new File(omexPath);
// Deleting file if already exists with same name
if (omexFile.exists()) {
omexFile.delete();
}
isCreated = archive.writeToFile(omexPath);
// Removing all other files(like SEDML, XML, SBML) after archiving
for (String sd : files) {
// removing
if (sd.endsWith(".sedml") || sd.endsWith(".sbml") || sd.endsWith("xml") || sd.endsWith("vcml") || sd.endsWith("rdf")) {
isDeleted = Paths.get(outputDir, sd).toFile().delete();
}
}
if (isDeleted)
System.out.println("Removed intermediary files");
} catch (Exception e) {
throw new RuntimeException("createZipArchive threw exception: " + e.getMessage());
}
return isCreated;
}
use of cbit.vcell.server.SimulationJobStatusPersistent in project vcell by virtualcell.
the class AdminDBTopLevel method getSimulationStatus.
/**
* Insert the method's description here.
* Creation date: (1/31/2003 2:35:44 PM)
* @return cbit.vcell.solvers.SimulationJobStatus[]
* @param bActiveOnly boolean
* @param owner cbit.vcell.server.User
*/
SimulationStatusPersistent getSimulationStatus(KeyValue simKey, boolean bEnableRetry) throws java.sql.SQLException, DataAccessException {
Object lock = new Object();
Connection con = conFactory.getConnection(lock);
try {
SimulationJobStatusPersistent[] jobStatuses = jobDB.getSimulationJobStatus(con, simKey);
if (jobStatuses.length > 0) {
return new SimulationStatusPersistent(jobStatuses);
} else {
return null;
}
} catch (Throwable e) {
lg.error("failure in getSimulationStatus()", e);
if (bEnableRetry && isBadConnection(con)) {
conFactory.failed(con, lock);
return getSimulationStatus(simKey, false);
} else {
handle_DataAccessException_SQLException(e);
// never gets here;
return null;
}
} finally {
conFactory.release(con, lock);
}
}
use of cbit.vcell.server.SimulationJobStatusPersistent in project vcell by virtualcell.
the class AdminDBTopLevel method getSimulationJobStatus.
/**
* Insert the method's description here.
* Creation date: (1/31/2003 2:35:44 PM)
* @return cbit.vcell.solvers.SimulationJobStatus[]
* @param bActiveOnly boolean
* @param owner cbit.vcell.server.User
*/
public SimulationJobStatusPersistent getSimulationJobStatus(KeyValue simKey, int jobIndex, int taskID, boolean bEnableRetry) throws java.sql.SQLException, DataAccessException {
Object lock = new Object();
Connection con = conFactory.getConnection(lock);
try {
SimulationJobStatusPersistent jobStatus = getSimulationJobStatus(con, simKey, jobIndex, taskID);
return jobStatus;
} catch (Throwable e) {
lg.error("failure in getSimulationJobStatus()", e);
if (bEnableRetry && isBadConnection(con)) {
conFactory.failed(con, lock);
return getSimulationJobStatus(simKey, jobIndex, taskID, false);
} else {
handle_DataAccessException_SQLException(e);
// never gets here;
return null;
}
} finally {
conFactory.release(con, lock);
}
}
Aggregations