use of cbit.vcell.mathmodel.MathModel in project vcell by virtualcell.
the class MathDebuggerPanel method expandBoth.
private void expandBoth() throws PropertyVetoException, MappingException, MathException, ExpressionException {
setStatus("Canonical Math for both mathDescriptions: \n");
MathDescription[] canonicalMathDescs = MathUtilities.getCanonicalMathDescriptions(SimulationSymbolTable.createMathSymbolTableFactory(), getMathModel1().getMathDescription(), getMathModel2().getMathDescription());
MathModel newMathModel = new MathModel(null);
newMathModel.setName("Math1");
newMathModel.setMathDescription(canonicalMathDescs[0]);
setMathModel1(newMathModel);
newMathModel = new MathModel(null);
newMathModel.setName("Math2");
newMathModel.setMathDescription(canonicalMathDescs[1]);
setMathModel2(newMathModel);
}
use of cbit.vcell.mathmodel.MathModel in project vcell by virtualcell.
the class MathVerifier method testDocumentLoad.
private void testDocumentLoad(boolean bUpdateDatabase, User user, VCDocumentInfo documentInfo, VCDocument vcDocumentFromDBCache) {
KeyValue versionKey = documentInfo.getVersion().getVersionKey();
// try{
// String vcDocumentXMLFromDBCacheRoundtrip = null;
// Compare self same
Exception bSameCachedAndNotCachedXMLExc = null;
Exception bSameCachedAndNotCachedObjExc = null;
Exception bSameSelfXMLCachedRoundtripExc = null;
Boolean bSameCachedAndNotCachedXML = null;
Boolean bSameCachedAndNotCachedObj = null;
Boolean bSameSelfCachedRoundtrip = null;
// Boolean bSameSelfObjCachedRoundTrip = null;
long startTime = 0;
// Long compareXMLTime = null;
// Long compareObjTime = null;
// Long loadOriginalXMLTime = null;
Long loadUnresolvedTime = null;
if (documentInfo instanceof BioModelInfo) {
Level existingLogLevel = VCMLComparator.getLogLevel();
try {
String xmlRndTrip0 = XmlHelper.bioModelToXML((BioModel) vcDocumentFromDBCache);
BioModel bioModelRndTrip0 = XmlHelper.XMLToBioModel(new XMLSource(xmlRndTrip0));
String xmlRndTrip1 = XmlHelper.bioModelToXML((BioModel) bioModelRndTrip0);
BioModel bioModelRndTrip1 = XmlHelper.XMLToBioModel(new XMLSource(xmlRndTrip1));
if (Compare.logger != null) {
Compare.loggingEnabled = true;
VCMLComparator.setLogLevel(Level.DEBUG);
}
bSameSelfCachedRoundtrip = VCMLComparator.compareEquals(xmlRndTrip0, xmlRndTrip1, true);
System.out.println("----------XML same=" + bSameSelfCachedRoundtrip);
boolean objectSame = bioModelRndTrip0.compareEqual(bioModelRndTrip1);
System.out.println("----------Objects same=" + objectSame);
bSameSelfCachedRoundtrip = bSameSelfCachedRoundtrip && objectSame;
} catch (Exception e) {
bSameSelfCachedRoundtrip = null;
lg.error(e.getMessage(), e);
bSameSelfXMLCachedRoundtripExc = e;
} finally {
Compare.loggingEnabled = false;
VCMLComparator.setLogLevel(existingLogLevel);
}
String fromDBBioModelUnresolvedXML = null;
try {
startTime = System.currentTimeMillis();
fromDBBioModelUnresolvedXML = dbServerImpl.getServerDocumentManager().getBioModelUnresolved(new QueryHashtable(), user, versionKey);
BioModel vcDocumentFromDBNotCached = XmlHelper.XMLToBioModel(new XMLSource(fromDBBioModelUnresolvedXML));
loadUnresolvedTime = System.currentTimeMillis() - startTime;
bSameCachedAndNotCachedObj = vcDocumentFromDBCache.compareEqual(vcDocumentFromDBNotCached);
} catch (Exception e) {
lg.error(e.getMessage(), e);
bSameCachedAndNotCachedObjExc = e;
}
if (fromDBBioModelUnresolvedXML != null) {
try {
String vcDocumentXMLFromDBCacheRegenerate = XmlHelper.bioModelToXML((BioModel) vcDocumentFromDBCache);
bSameCachedAndNotCachedXML = VCMLComparator.compareEquals(vcDocumentXMLFromDBCacheRegenerate, fromDBBioModelUnresolvedXML, true);
} catch (Exception e) {
lg.error(e.getMessage(), e);
bSameCachedAndNotCachedXMLExc = e;
}
}
} else {
Level existingLogLevel = VCMLComparator.getLogLevel();
try {
String xmlRndTrip0 = XmlHelper.mathModelToXML((MathModel) vcDocumentFromDBCache);
MathModel mathModelRndTrip0 = XmlHelper.XMLToMathModel(new XMLSource(xmlRndTrip0));
String xmlRndTrip1 = XmlHelper.mathModelToXML((MathModel) mathModelRndTrip0);
MathModel mathModelRndTrip1 = XmlHelper.XMLToMathModel(new XMLSource(xmlRndTrip1));
if (Compare.logger != null) {
Compare.loggingEnabled = true;
VCMLComparator.setLogLevel(Level.DEBUG);
}
bSameSelfCachedRoundtrip = VCMLComparator.compareEquals(xmlRndTrip0, xmlRndTrip1, true);
bSameSelfCachedRoundtrip = bSameSelfCachedRoundtrip && mathModelRndTrip0.compareEqual(mathModelRndTrip1);
} catch (Exception e) {
bSameSelfCachedRoundtrip = null;
lg.error(e.getMessage(), e);
bSameSelfXMLCachedRoundtripExc = e;
} finally {
Compare.loggingEnabled = false;
VCMLComparator.setLogLevel(existingLogLevel);
}
String fromDBMathModelUnresolvedXML = null;
try {
startTime = System.currentTimeMillis();
MathModel vcDocumentFromDBNotCached = dbServerImpl.getServerDocumentManager().getMathModelUnresolved(new QueryHashtable(), user, versionKey);
loadUnresolvedTime = System.currentTimeMillis() - startTime;
fromDBMathModelUnresolvedXML = XmlHelper.mathModelToXML(vcDocumentFromDBNotCached);
bSameCachedAndNotCachedObj = vcDocumentFromDBCache.compareEqual(vcDocumentFromDBNotCached);
} catch (Exception e) {
lg.error(e.getMessage(), e);
bSameCachedAndNotCachedObjExc = e;
}
if (fromDBMathModelUnresolvedXML != null) {
try {
String vcDocumentXMLFromDBCacheRegenerate = XmlHelper.mathModelToXML((MathModel) vcDocumentFromDBCache);
bSameCachedAndNotCachedXML = VCMLComparator.compareEquals(vcDocumentXMLFromDBCacheRegenerate, fromDBMathModelUnresolvedXML, true);
} catch (Exception e) {
lg.error(e.getMessage(), e);
bSameCachedAndNotCachedXMLExc = e;
}
}
}
if (bUpdateDatabase) {
updateLoadModelsStatTable_CompareTest(versionKey, null, /*loadOriginalXMLTime*/
loadUnresolvedTime, bSameCachedAndNotCachedXML, bSameCachedAndNotCachedObj, bSameSelfCachedRoundtrip, bSameCachedAndNotCachedXMLExc, bSameCachedAndNotCachedObjExc, bSameSelfXMLCachedRoundtripExc);
} else {
System.out.println("loadOriginalXMLTime=" + null + /*loadOriginalXMLTime*/
" loadUnresolvedTime=" + loadUnresolvedTime);
System.out.println("bSameCachedAndNotCachedXML=" + bSameCachedAndNotCachedXML + " bSameCachedAndNotCachedObj=" + bSameCachedAndNotCachedObj + " bSameSelfXMLCachedRoundtrip=" + bSameSelfCachedRoundtrip);
System.out.println("bSameCachedAndNotCachedXMLExc=" + bSameCachedAndNotCachedXMLExc + "\nbSameCachedAndNotCachedObjExc=" + bSameCachedAndNotCachedObjExc + "\nbSameSelfXMLCachedRoundtripExc=" + bSameSelfXMLCachedRoundtripExc);
System.out.println();
}
}
use of cbit.vcell.mathmodel.MathModel 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.mathmodel.MathModel in project vcell by virtualcell.
the class VCDatabaseScanner method scanMathModels.
public void scanMathModels(VCDatabaseVisitor databaseVisitor, PrintStream logFilePrintStream, User[] users, KeyValue singleMathmodelKey, HashSet<KeyValue> includeHash, HashSet<KeyValue> excludeHash, boolean bAbortOnDataAccessException) throws DataAccessException, XmlParseException {
BadMathVisitor badMathVisitor = null;
if (databaseVisitor instanceof BadMathVisitor) {
badMathVisitor = (BadMathVisitor) databaseVisitor;
}
final boolean isBadMathVisitor = badMathVisitor != null;
if (users == null) {
users = getAllUsers();
}
try {
// start visiting models and writing log
logFilePrintStream.println("Start scanning mathmodels ......");
logFilePrintStream.println("\n");
for (int i = 0; i < users.length; i++) {
User user = users[i];
MathModelInfo[] mathInfos = dbServerImpl.getMathModelInfos(user, false);
for (int j = 0; j < mathInfos.length; j++) {
if (singleMathmodelKey != null && !mathInfos[j].getVersion().getVersionKey().compareEqual(singleMathmodelKey)) {
System.out.println("skipping geometry, not the single one that we wanted");
continue;
}
if (excludeHash != null && excludeHash.contains(mathInfos[j].getVersion().getVersionKey())) {
System.out.println("skipping geometry with key '" + mathInfos[j].getVersion().getVersionKey() + "'");
continue;
}
if (includeHash != null && !includeHash.contains(mathInfos[j].getVersion().getVersionKey())) {
System.out.println("not including geometry with key '" + mathInfos[j].getVersion().getVersionKey() + "'");
continue;
}
if (!databaseVisitor.filterMathModel(mathInfos[j])) {
continue;
}
KeyValue vk = null;
try {
vk = mathInfos[j].getVersion().getVersionKey();
BigString mathModelXML = dbServerImpl.getMathModelXML(user, mathInfos[j].getVersion().getVersionKey());
MathModel mathModel = cbit.vcell.xml.XmlHelper.XMLToMathModel(new XMLSource(mathModelXML.toString()));
mathModel.refreshDependencies();
databaseVisitor.visitMathModel(mathModel, logFilePrintStream);
} catch (Exception e2) {
if (isBadMathVisitor) {
badMathVisitor.unableToLoad(vk, e2);
}
lg.error(e2.getMessage(), e2);
if (bAbortOnDataAccessException) {
throw e2;
}
}
}
}
logFilePrintStream.close();
} catch (Exception e) {
System.err.println("error writing to log file.");
}
}
use of cbit.vcell.mathmodel.MathModel in project vcell by virtualcell.
the class MathDebuggerPanel method compareEquivalent.
private void compareEquivalent() throws PropertyVetoException, XmlParseException {
MathModel mathModel1 = getMathModel1();
MathModel mathModel2 = getMathModel2();
if (mathModel1 != null && mathModel2 != null) {
MathCompareResults mathCompareResults = MathDescription.testEquivalency(SimulationSymbolTable.createMathSymbolTableFactory(), mathModel1.getMathDescription(), mathModel2.getMathDescription());
getStatusEditorPane().setText("equiv = " + mathCompareResults.isEquivalent() + "\n" + "reason = " + mathCompareResults.toDatabaseStatus());
} else {
DialogUtils.showErrorDialog(MathDebuggerPanel.this, "failed : at least one math description is null.");
}
}
Aggregations