Search in sources :

Example 31 with MathModel

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);
}
Also used : MathModel(cbit.vcell.mathmodel.MathModel) MathDescription(cbit.vcell.math.MathDescription)

Example 32 with MathModel

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();
    }
}
Also used : QueryHashtable(cbit.sql.QueryHashtable) MathModel(cbit.vcell.mathmodel.MathModel) KeyValue(org.vcell.util.document.KeyValue) BioModelInfo(org.vcell.util.document.BioModelInfo) BigString(org.vcell.util.BigString) PropertyVetoException(java.beans.PropertyVetoException) MatrixException(cbit.vcell.matrix.MatrixException) ModelException(cbit.vcell.model.ModelException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) SQLException(java.sql.SQLException) XmlParseException(cbit.vcell.xml.XmlParseException) DataAccessException(org.vcell.util.DataAccessException) ExpressionException(cbit.vcell.parser.ExpressionException) MappingException(cbit.vcell.mapping.MappingException) MathException(cbit.vcell.math.MathException) BioModel(cbit.vcell.biomodel.BioModel) Level(org.apache.log4j.Level) XMLSource(cbit.vcell.xml.XMLSource)

Example 33 with MathModel

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();
    }
}
Also used : MathModel(cbit.vcell.mathmodel.MathModel) User(org.vcell.util.document.User) SimulationStatusPersistent(cbit.vcell.server.SimulationStatusPersistent) MathModelInfo(org.vcell.util.document.MathModelInfo) SimulationJobStatusPersistent(cbit.vcell.server.SimulationJobStatusPersistent) BigString(org.vcell.util.BigString) Date(java.util.Date) SQLException(java.sql.SQLException) DataAccessException(org.vcell.util.DataAccessException) FileNotFoundException(java.io.FileNotFoundException) Simulation(cbit.vcell.solver.Simulation)

Example 34 with MathModel

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.");
    }
}
Also used : MathModel(cbit.vcell.mathmodel.MathModel) User(org.vcell.util.document.User) KeyValue(org.vcell.util.document.KeyValue) MathModelInfo(org.vcell.util.document.MathModelInfo) BigString(org.vcell.util.BigString) XMLSource(cbit.vcell.xml.XMLSource) SQLException(java.sql.SQLException) XmlParseException(cbit.vcell.xml.XmlParseException) DataAccessException(org.vcell.util.DataAccessException) RemoteException(java.rmi.RemoteException)

Example 35 with MathModel

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.");
    }
}
Also used : MathModel(cbit.vcell.mathmodel.MathModel) MathCompareResults(cbit.vcell.math.MathCompareResults)

Aggregations

MathModel (cbit.vcell.mathmodel.MathModel)70 BioModel (cbit.vcell.biomodel.BioModel)26 Simulation (cbit.vcell.solver.Simulation)24 DataAccessException (org.vcell.util.DataAccessException)21 Geometry (cbit.vcell.geometry.Geometry)20 MathDescription (cbit.vcell.math.MathDescription)20 SimulationContext (cbit.vcell.mapping.SimulationContext)19 XmlParseException (cbit.vcell.xml.XmlParseException)13 MathModelInfo (org.vcell.util.document.MathModelInfo)12 ObjectNotFoundException (org.vcell.util.ObjectNotFoundException)11 UserCancelException (org.vcell.util.UserCancelException)11 VCDocument (org.vcell.util.document.VCDocument)11 XMLSource (cbit.vcell.xml.XMLSource)10 ExpressionException (cbit.vcell.parser.ExpressionException)9 File (java.io.File)9 KeyValue (org.vcell.util.document.KeyValue)8 PropertyVetoException (java.beans.PropertyVetoException)7 IOException (java.io.IOException)7 BigString (org.vcell.util.BigString)7 BioModelInfo (org.vcell.util.document.BioModelInfo)7