Search in sources :

Example 91 with Simulation

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

the class MathVerifier method checkMathForBioModel.

private void checkMathForBioModel(BigString bioModelXMLFromDB, BioModel bioModelFromDB, User user, boolean bUpdateDatabase) throws Exception {
    BioModel bioModelNewMath = XmlHelper.XMLToBioModel(new XMLSource(bioModelXMLFromDB.toString()));
    bioModelFromDB.refreshDependencies();
    bioModelNewMath.refreshDependencies();
    // 
    // get all Simulations for this model
    // 
    Simulation[] modelSimsFromDB = bioModelFromDB.getSimulations();
    // 
    // for each application, recompute mathDescription, and verify it is equivalent
    // then check each associated simulation to ensure math overrides are applied in an equivalent manner also.
    // 
    SimulationContext[] simContextsFromDB = bioModelFromDB.getSimulationContexts();
    SimulationContext[] simContextsNewMath = bioModelNewMath.getSimulationContexts();
    for (int k = 0; k < simContextsFromDB.length; k++) {
        SimulationContext simContextFromDB = simContextsFromDB[k];
        Simulation[] appSimsFromDB = simContextFromDB.getSimulations();
        SimulationContext simContextNewMath = simContextsNewMath[k];
        Simulation[] appSimsNewMath = simContextNewMath.getSimulations();
        MathCompareResults mathCompareResults_latest = null;
        MathCompareResults mathCompareResults_4_8 = null;
        try {
            MathDescription origMathDesc = simContextFromDB.getMathDescription();
            // 
            // find out if any simulation belonging to this Application has data
            // 
            boolean bApplicationHasData = false;
            for (int l = 0; l < modelSimsFromDB.length; l++) {
                SimulationStatusPersistent simulationStatus = dbServerImpl.getSimulationStatus(modelSimsFromDB[l].getKey());
                if (simulationStatus != null && simulationStatus.getHasData()) {
                    bApplicationHasData = true;
                }
            }
            // 
            try {
                if (simContextNewMath.getGeometry().getDimension() > 0 && simContextNewMath.getGeometry().getGeometrySurfaceDescription().getGeometricRegions() == null) {
                    simContextNewMath.getGeometry().getGeometrySurfaceDescription().updateAll();
                }
            } catch (Exception e) {
                e.printStackTrace(System.out);
            }
            // 
            // updated mathdescription loaded into copy of biomodel, then test for equivalence.
            // 
            cbit.vcell.mapping.MathMapping mathMapping = simContextNewMath.createNewMathMapping();
            MathDescription newMathDesc = mathMapping.getMathDescription();
            String issueString = null;
            org.vcell.util.Issue[] issues = mathMapping.getIssues();
            if (issues != null && issues.length > 0) {
                StringBuffer buffer = new StringBuffer("Issues(" + issues.length + "):");
                for (int l = 0; l < issues.length; l++) {
                    buffer.append(" <<" + issues[l].toString() + ">>");
                }
                issueString = buffer.toString();
            }
            MathCompareResults testIfSameResult = cbit.vcell.math.MathUtilities.testIfSame(SimulationSymbolTable.createMathSymbolTableFactory(), origMathDesc, newMathDesc);
            mathCompareResults_latest = MathDescription.testEquivalency(SimulationSymbolTable.createMathSymbolTableFactory(), origMathDesc, newMathDesc);
            System.out.println(">>>BioModel(" + bioModelFromDB.getVersion().getVersionKey() + ") '" + bioModelFromDB.getName() + "':" + bioModelFromDB.getVersion().getDate() + ", Application(" + simContextFromDB.getKey() + ") '" + simContextFromDB.getName() + "' <<EQUIV=" + mathCompareResults_latest.isEquivalent() + ">>: " + mathCompareResults_latest.toDatabaseStatus());
            MathDescription mathDesc_4_8 = null;
            try {
                mathDesc_4_8 = new MathMapping_4_8(simContextNewMath).getMathDescription();
                mathCompareResults_4_8 = MathDescription.testEquivalency(SimulationSymbolTable.createMathSymbolTableFactory(), origMathDesc, mathDesc_4_8);
            } catch (Exception e) {
                e.printStackTrace(System.out);
                mathCompareResults_4_8 = new MathCompareResults(Decision.MathDifferent_FAILURE_UNKNOWN, e.getMessage());
            }
            simContextNewMath.setMathDescription(newMathDesc);
            // 
            if (bUpdateDatabase) {
                java.sql.Connection con = null;
                java.sql.Statement stmt = null;
                try {
                    con = conFactory.getConnection(new Object());
                    stmt = con.createStatement();
                    // KeyValue mathKey = origMathDesc.getKey();
                    String UPDATESTATUS = "UPDATE " + SimContextStat2Table.table.getTableName() + " SET " + SimContextStat2Table.table.hasData.getUnqualifiedColName() + " = " + ((bApplicationHasData) ? (1) : (0)) + ", " + SimContextStat2Table.table.equiv.getUnqualifiedColName() + " = " + (mathCompareResults_latest.isEquivalent() ? (1) : (0)) + ", " + SimContextStat2Table.table.status.getUnqualifiedColName() + " = '" + org.vcell.util.TokenMangler.getSQLEscapedString(mathCompareResults_latest.toDatabaseStatus(), 255) + "', " + SimContextStat2Table.table.equiv_4_8.getUnqualifiedColName() + " = " + (mathCompareResults_4_8.isEquivalent() ? (1) : (0)) + ", " + SimContextStat2Table.table.status_4_8.getUnqualifiedColName() + " = '" + org.vcell.util.TokenMangler.getSQLEscapedString(mathCompareResults_4_8.toDatabaseStatus(), 255) + "'" + // ((issueString!=null)?(", "+SimContextStat2Table.table.comments.getUnqualifiedColName()+" = '"+org.vcell.util.TokenMangler.getSQLEscapedString(issueString,255)+"'"):(""))+
                    " WHERE " + SimContextStat2Table.table.simContextRef.getUnqualifiedColName() + " = " + simContextFromDB.getKey();
                    int numRowsChanged = stmt.executeUpdate(UPDATESTATUS);
                    if (numRowsChanged != 1) {
                        System.out.println("failed to update status");
                    }
                    con.commit();
                    if (lg.isTraceEnabled())
                        lg.trace("-------------- Update=true, saved 'newMath' for Application '" + simContextFromDB.getName() + "'");
                } catch (SQLException e) {
                    lg.error(e.getMessage(), e);
                    if (lg.isWarnEnabled())
                        lg.warn("*&*&*&*&*&*&*& Update=true, FAILED TO UPDATE MATH for Application '" + simContextFromDB.getName() + "'");
                } finally {
                    if (stmt != null) {
                        stmt.close();
                    }
                    con.close();
                }
            }
        } catch (Throwable e) {
            // exception in SimContext
            lg.error(e.getMessage(), e);
            if (bUpdateDatabase) {
                java.sql.Connection con = null;
                java.sql.Statement stmt = null;
                try {
                    con = conFactory.getConnection(new Object());
                    stmt = con.createStatement();
                    // KeyValue mathKey = origMathDesc.getKey();
                    String UPDATESTATUS = "UPDATE " + SimContextStat2Table.table.getTableName() + " SET " + SimContextStat2Table.table.status.getUnqualifiedColName() + " = 'EXCEPTION: " + org.vcell.util.TokenMangler.getSQLEscapedString(e.toString()) + "'" + " WHERE " + SimContextStat2Table.table.simContextRef.getUnqualifiedColName() + " = " + simContextFromDB.getKey();
                    int numRowsChanged = stmt.executeUpdate(UPDATESTATUS);
                    if (numRowsChanged != 1) {
                        System.out.println("failed to update status with exception");
                    }
                    con.commit();
                    if (lg.isTraceEnabled())
                        lg.trace("-------------- Update=true, saved exception for Application '" + simContextFromDB.getName() + "'");
                } catch (SQLException e2) {
                    lg.error(e2.getMessage(), e2);
                    if (lg.isWarnEnabled())
                        lg.warn("*&*&*&*&*&*&*& Update=true, FAILED TO save exception status for Application '" + simContextFromDB.getName() + "'");
                } finally {
                    if (stmt != null) {
                        stmt.close();
                    }
                    con.close();
                }
            }
        }
        // 
        for (int l = 0; l < appSimsFromDB.length; l++) {
            try {
                boolean bSimEquivalent = Simulation.testEquivalency(appSimsNewMath[l], appSimsFromDB[l], mathCompareResults_latest);
                if (lg.isTraceEnabled())
                    lg.trace("Application(" + simContextFromDB.getKey() + ") '" + simContextFromDB.getName() + "', " + "Simulation(" + modelSimsFromDB[l].getKey() + ") '" + modelSimsFromDB[l].getName() + "':" + modelSimsFromDB[l].getVersion().getDate() + "mathEquivalency=" + mathCompareResults_latest.isEquivalent() + ", simEquivalency=" + bSimEquivalent);
                // 
                if (bUpdateDatabase) {
                    java.sql.Connection con = null;
                    java.sql.Statement stmt = null;
                    try {
                        con = conFactory.getConnection(new Object());
                        stmt = con.createStatement();
                        String UPDATESTATUS = "UPDATE " + SimStatTable.table.getTableName() + " SET " + SimStatTable.table.equiv.getUnqualifiedColName() + " = " + ((bSimEquivalent) ? (1) : (0)) + ", " + SimStatTable.table.status.getUnqualifiedColName() + " = '" + org.vcell.util.TokenMangler.getSQLEscapedString(mathCompareResults_latest.decision.description) + "'" + " WHERE " + SimStatTable.table.simRef.getUnqualifiedColName() + " = " + appSimsFromDB[l].getKey();
                        int numRowsChanged = stmt.executeUpdate(UPDATESTATUS);
                        if (numRowsChanged != 1) {
                            System.out.println("failed to update status");
                        }
                        con.commit();
                        if (lg.isTraceEnabled())
                            lg.trace("-------------- Update=true, saved 'simulation status for simulation '" + appSimsFromDB[l].getName() + "'");
                    } catch (SQLException e) {
                        lg.error(e.getMessage(), e);
                        if (lg.isWarnEnabled())
                            lg.warn("*&*&*&*&*&*&*& Update=true, FAILED TO UPDATE status for simulation '" + appSimsFromDB[l].getName() + "'");
                    } finally {
                        if (stmt != null) {
                            stmt.close();
                        }
                        con.close();
                    }
                }
            } catch (Throwable e) {
                // exception in SimContext
                lg.error(e.getMessage(), e);
                if (bUpdateDatabase) {
                    java.sql.Connection con = null;
                    java.sql.Statement stmt = null;
                    try {
                        con = conFactory.getConnection(new Object());
                        stmt = con.createStatement();
                        // KeyValue mathKey = origMathDesc.getKey();
                        String UPDATESTATUS = "UPDATE " + SimStatTable.table.getTableName() + " SET " + SimStatTable.table.status.getUnqualifiedColName() + " = 'EXCEPTION: " + org.vcell.util.TokenMangler.getSQLEscapedString(e.toString()) + "'" + " WHERE " + SimStatTable.table.simRef.getUnqualifiedColName() + " = " + appSimsFromDB[l].getKey();
                        int numRowsChanged = stmt.executeUpdate(UPDATESTATUS);
                        if (numRowsChanged != 1) {
                            System.out.println("failed to update status with exception");
                        }
                        con.commit();
                        if (lg.isTraceEnabled())
                            lg.trace("-------------- Update=true, saved exception for Simulation '" + appSimsFromDB[l].getName() + "'");
                    } catch (SQLException e2) {
                        lg.error(e2.getMessage(), e2);
                        if (lg.isWarnEnabled())
                            lg.warn("*&*&*&*&*&*&*& Update=true, FAILED TO save exception status for simulation '" + appSimsFromDB[l].getName() + "'");
                    } finally {
                        if (stmt != null) {
                            stmt.close();
                        }
                        con.close();
                    }
                }
            }
        }
    }
}
Also used : Connection(java.sql.Connection) MathDescription(cbit.vcell.math.MathDescription) SQLException(java.sql.SQLException) BigString(org.vcell.util.BigString) MathCompareResults(cbit.vcell.math.MathCompareResults) Connection(java.sql.Connection) SimulationStatusPersistent(cbit.vcell.server.SimulationStatusPersistent) MathMapping_4_8(cbit.vcell.mapping.vcell_4_8.MathMapping_4_8) SimulationContext(cbit.vcell.mapping.SimulationContext) 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) Simulation(cbit.vcell.solver.Simulation) BioModel(cbit.vcell.biomodel.BioModel) XMLSource(cbit.vcell.xml.XMLSource)

Example 92 with Simulation

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

the class MathVerifier method scanBioModels.

/**
 * Insert the method's description here.
 * Creation date: (2/2/01 3:40:29 PM)
 */
public void scanBioModels(boolean bUpdateDatabase, KeyValue[] bioModelKeys) throws MathException, MappingException, SQLException, DataAccessException, ModelException, ExpressionException {
    java.util.Calendar calendar = java.util.GregorianCalendar.getInstance();
    // calendar.set(2002,java.util.Calendar.MAY,7+1);
    calendar.set(2002, java.util.Calendar.JULY, 1);
    final java.util.Date fluxCorrectionOrDisablingBugFixDate = calendar.getTime();
    // calendar.set(2001,java.util.Calendar.JUNE,13+1);
    calendar.set(2002, java.util.Calendar.JANUARY, 1);
    final java.util.Date totalVolumeCorrectionFixDate = calendar.getTime();
    User user = new User(PropertyLoader.ADMINISTRATOR_ACCOUNT, new KeyValue(PropertyLoader.ADMINISTRATOR_ID));
    for (int i = 0; i < bioModelKeys.length; i++) {
        BioModelInfo bioModelInfo = dbServerImpl.getBioModelInfo(user, bioModelKeys[i]);
        if (lg.isTraceEnabled())
            lg.trace("Testing bioModel with key '" + bioModelKeys[i] + "'");
        java.sql.Connection con = null;
        java.sql.Statement stmt = null;
        try {
            // 
            // read in the BioModel from the database
            // 
            BigString bioModelXML = dbServerImpl.getBioModelXML(user, bioModelInfo.getVersion().getVersionKey());
            BioModel bioModelFromDB = XmlHelper.XMLToBioModel(new XMLSource(bioModelXML.toString()));
            BioModel bioModelNewMath = XmlHelper.XMLToBioModel(new XMLSource(bioModelXML.toString()));
            bioModelFromDB.refreshDependencies();
            bioModelNewMath.refreshDependencies();
            // 
            // get all Simulations for this model
            // 
            Simulation[] modelSimsFromDB = bioModelFromDB.getSimulations();
            // 
            // for each application, recompute mathDescription, and verify it is equivalent
            // then check each associated simulation to ensure math overrides are applied in an equivalent manner also.
            // 
            SimulationContext[] simContextsFromDB = bioModelFromDB.getSimulationContexts();
            SimulationContext[] simContextsNewMath = bioModelNewMath.getSimulationContexts();
            for (int k = 0; k < simContextsFromDB.length; k++) {
                SimulationContext simContextFromDB = simContextsFromDB[k];
                Simulation[] appSimsFromDB = simContextFromDB.getSimulations();
                SimulationContext simContextNewMath = simContextsNewMath[k];
                Simulation[] appSimsNewMath = simContextNewMath.getSimulations();
                MathCompareResults mathCompareResults = null;
                try {
                    MathDescription origMathDesc = simContextFromDB.getMathDescription();
                    // 
                    // find out if any simulation belonging to this Application has data
                    // 
                    boolean bApplicationHasData = false;
                    for (int l = 0; l < modelSimsFromDB.length; l++) {
                        SimulationStatusPersistent simulationStatus = dbServerImpl.getSimulationStatus(modelSimsFromDB[l].getKey());
                        if (simulationStatus != null && simulationStatus.getHasData()) {
                            bApplicationHasData = true;
                        }
                    }
                    // 
                    try {
                        if (simContextNewMath.getGeometry().getDimension() > 0 && simContextNewMath.getGeometry().getGeometrySurfaceDescription().getGeometricRegions() == null) {
                            simContextNewMath.getGeometry().getGeometrySurfaceDescription().updateAll();
                        }
                    } catch (Exception e) {
                        e.printStackTrace(System.out);
                    }
                    // 
                    // updated mathdescription loaded into copy of biomodel, then test for equivalence.
                    // 
                    cbit.vcell.mapping.MathMapping mathMapping = simContextNewMath.createNewMathMapping();
                    MathDescription newMathDesc = mathMapping.getMathDescription();
                    String issueString = null;
                    org.vcell.util.Issue[] issues = mathMapping.getIssues();
                    if (issues != null && issues.length > 0) {
                        StringBuffer buffer = new StringBuffer("Issues(" + issues.length + "):");
                        for (int l = 0; l < issues.length; l++) {
                            buffer.append(" <<" + issues[l].toString() + ">>");
                        }
                        issueString = buffer.toString();
                    }
                    simContextNewMath.setMathDescription(newMathDesc);
                    MathCompareResults testIfSameResults = cbit.vcell.math.MathUtilities.testIfSame(SimulationSymbolTable.createMathSymbolTableFactory(), origMathDesc, newMathDesc);
                    mathCompareResults = MathDescription.testEquivalency(SimulationSymbolTable.createMathSymbolTableFactory(), origMathDesc, newMathDesc);
                    StringBuffer buffer = new StringBuffer();
                    buffer.append(">>>BioModel(" + bioModelFromDB.getVersion().getVersionKey() + ") '" + bioModelFromDB.getName() + "':" + bioModelFromDB.getVersion().getDate() + ", Application(" + simContextFromDB.getKey() + ") '" + simContextFromDB.getName() + "' <<EQUIV=" + mathCompareResults.isEquivalent() + ">>: " + mathCompareResults.toDatabaseStatus());
                    // 
                    if (bUpdateDatabase) {
                        con = null;
                        stmt = null;
                        try {
                            con = conFactory.getConnection(new Object());
                            stmt = con.createStatement();
                            // KeyValue mathKey = origMathDesc.getKey();
                            String UPDATESTATUS = "UPDATE " + SimContextStat2Table.table.getTableName() + " SET " + SimContextStat2Table.table.hasData.getUnqualifiedColName() + " = " + ((bApplicationHasData) ? (1) : (0)) + ", " + SimContextStat2Table.table.equiv.getUnqualifiedColName() + " = " + (mathCompareResults.isEquivalent() ? (1) : (0)) + ", " + SimContextStat2Table.table.status.getUnqualifiedColName() + " = '" + org.vcell.util.TokenMangler.getSQLEscapedString(mathCompareResults.toDatabaseStatus()) + "'" + ((issueString != null) ? (", " + SimContextStat2Table.table.comments.getUnqualifiedColName() + " = '" + org.vcell.util.TokenMangler.getSQLEscapedString(issueString, 255) + "'") : ("")) + " WHERE " + SimContextStat2Table.table.simContextRef.getUnqualifiedColName() + " = " + simContextFromDB.getKey();
                            int numRowsChanged = stmt.executeUpdate(UPDATESTATUS);
                            if (numRowsChanged != 1) {
                                System.out.println("failed to update status");
                            }
                            con.commit();
                            if (lg.isTraceEnabled())
                                lg.trace("-------------- Update=true, saved 'newMath' for Application '" + simContextFromDB.getName() + "'");
                        } catch (SQLException e) {
                            lg.error(e.getMessage(), e);
                            if (lg.isWarnEnabled())
                                lg.warn("*&*&*&*&*&*&*& Update=true, FAILED TO UPDATE MATH for Application '" + simContextFromDB.getName() + "'");
                        } finally {
                            if (stmt != null) {
                                stmt.close();
                            }
                            con.close();
                        }
                    }
                } catch (Throwable e) {
                    // exception in SimContext
                    lg.error(e.getMessage(), e);
                    if (bUpdateDatabase) {
                        con = null;
                        stmt = null;
                        try {
                            con = conFactory.getConnection(new Object());
                            stmt = con.createStatement();
                            String status = "'EXCEPTION: " + org.vcell.util.TokenMangler.getSQLEscapedString(e.toString()) + "'";
                            if (status.length() > 255)
                                status = status.substring(0, 254) + "'";
                            String UPDATESTATUS = "UPDATE " + SimContextStat2Table.table.getTableName() + " SET " + SimContextStat2Table.table.status.getUnqualifiedColName() + " = " + status + " WHERE " + SimContextStat2Table.table.simContextRef.getUnqualifiedColName() + " = " + simContextFromDB.getKey();
                            int numRowsChanged = stmt.executeUpdate(UPDATESTATUS);
                            if (numRowsChanged != 1) {
                                System.out.println("failed to update status with exception");
                            }
                            con.commit();
                            if (lg.isTraceEnabled())
                                lg.trace("-------------- Update=true, saved exception for Application '" + simContextFromDB.getName() + "'");
                        } catch (SQLException e2) {
                            lg.error(e2.getMessage(), e2);
                            if (lg.isWarnEnabled())
                                lg.warn("*&*&*&*&*&*&*& Update=true, FAILED TO save exception status for Application '" + simContextFromDB.getName() + "'");
                        } finally {
                            if (stmt != null) {
                                stmt.close();
                            }
                            con.close();
                        }
                    }
                }
                // 
                for (int l = 0; l < appSimsFromDB.length; l++) {
                    try {
                        boolean bSimEquivalent = Simulation.testEquivalency(appSimsNewMath[l], appSimsFromDB[l], mathCompareResults);
                        if (lg.isTraceEnabled())
                            lg.trace("Application(" + simContextFromDB.getKey() + ") '" + simContextFromDB.getName() + "', " + "Simulation(" + modelSimsFromDB[l].getKey() + ") '" + modelSimsFromDB[l].getName() + "':" + modelSimsFromDB[l].getVersion().getDate() + "mathEquivalency=" + mathCompareResults.isEquivalent() + ", simEquivalency=" + bSimEquivalent);
                        // 
                        if (bUpdateDatabase) {
                            con = null;
                            stmt = null;
                            try {
                                con = conFactory.getConnection(new Object());
                                stmt = con.createStatement();
                                String UPDATESTATUS = "UPDATE " + SimStatTable.table.getTableName() + " SET " + SimStatTable.table.equiv.getUnqualifiedColName() + " = " + ((bSimEquivalent) ? (1) : (0)) + ", " + SimStatTable.table.status.getUnqualifiedColName() + " = '" + org.vcell.util.TokenMangler.getSQLEscapedString(mathCompareResults.decision.description) + "'" + " WHERE " + SimStatTable.table.simRef.getUnqualifiedColName() + " = " + appSimsFromDB[l].getKey();
                                int numRowsChanged = stmt.executeUpdate(UPDATESTATUS);
                                if (numRowsChanged != 1) {
                                    System.out.println("failed to update status");
                                }
                                con.commit();
                                if (lg.isTraceEnabled())
                                    lg.trace("-------------- Update=true, saved 'simulation status for simulation '" + appSimsFromDB[l].getName() + "'");
                            } catch (SQLException e) {
                                lg.error(e.getMessage(), e);
                                if (lg.isWarnEnabled())
                                    lg.warn("*&*&*&*&*&*&*& Update=true, FAILED TO UPDATE status for simulation '" + appSimsFromDB[l].getName() + "'");
                            } finally {
                                if (stmt != null) {
                                    stmt.close();
                                }
                                con.close();
                            }
                        }
                    } catch (Throwable e) {
                        // exception in SimContext
                        lg.error(e.getMessage(), e);
                        if (bUpdateDatabase) {
                            con = null;
                            stmt = null;
                            try {
                                con = conFactory.getConnection(new Object());
                                stmt = con.createStatement();
                                String status = "'EXCEPTION: " + org.vcell.util.TokenMangler.getSQLEscapedString(e.toString()) + "'";
                                if (status.length() > 255)
                                    status = status.substring(0, 254) + "'";
                                String UPDATESTATUS = "UPDATE " + SimStatTable.table.getTableName() + " SET " + SimStatTable.table.status.getUnqualifiedColName() + " = " + status + " WHERE " + SimStatTable.table.simRef.getUnqualifiedColName() + " = " + appSimsFromDB[l].getKey();
                                int numRowsChanged = stmt.executeUpdate(UPDATESTATUS);
                                if (numRowsChanged != 1) {
                                    System.out.println("failed to update status with exception");
                                }
                                con.commit();
                                if (lg.isTraceEnabled())
                                    lg.trace("-------------- Update=true, saved exception for Simulation '" + appSimsFromDB[l].getName() + "'");
                            } catch (SQLException e2) {
                                lg.error(e2.getMessage(), e2);
                                if (lg.isWarnEnabled())
                                    lg.warn("*&*&*&*&*&*&*& Update=true, FAILED TO save exception status for simulation '" + appSimsFromDB[l].getName() + "'");
                            } finally {
                                if (stmt != null) {
                                    stmt.close();
                                }
                                con.close();
                            }
                        }
                    }
                }
            }
        } catch (Throwable e) {
            // exception in whole BioModel
            lg.error(e.getMessage(), e);
        // can't update anything in database, since we don't know what simcontexts are involved
        }
    }
}
Also used : User(org.vcell.util.document.User) KeyValue(org.vcell.util.document.KeyValue) Connection(java.sql.Connection) MathDescription(cbit.vcell.math.MathDescription) SQLException(java.sql.SQLException) BigString(org.vcell.util.BigString) BigString(org.vcell.util.BigString) MathCompareResults(cbit.vcell.math.MathCompareResults) BioModelInfo(org.vcell.util.document.BioModelInfo) SimulationStatusPersistent(cbit.vcell.server.SimulationStatusPersistent) SimulationContext(cbit.vcell.mapping.SimulationContext) 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) Simulation(cbit.vcell.solver.Simulation) BioModel(cbit.vcell.biomodel.BioModel) XMLSource(cbit.vcell.xml.XMLSource)

Example 93 with Simulation

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

the class ServerDocumentManager method getBioModelUnresolved.

/**
 * Insert the method's description here.
 * Creation date: (11/14/00 4:02:44 PM)
 * @return cbit.vcell.biomodel.BioModel
 * @param bioModelInfo cbit.vcell.biomodel.BioModelInfo
 */
// 
// this returns a BioModel that contains multiple instances of objects.
// 
public String getBioModelUnresolved(QueryHashtable dbc, User user, KeyValue bioModelKey) throws DataAccessException, XmlParseException, java.sql.SQLException {
    // 
    // get meta data associated with BioModel
    // 
    BioModelMetaData bioModelMetaData = dbServer.getDBTopLevel().getBioModelMetaData(dbc, user, bioModelKey);
    // 
    // get list of appropriate child components
    // 
    KeyValue modelKey = bioModelMetaData.getModelKey();
    KeyValue[] simKeys = getKeyArrayFromEnumeration(bioModelMetaData.getSimulationKeys());
    KeyValue[] scKeys = getKeyArrayFromEnumeration(bioModelMetaData.getSimulationContextKeys());
    Model model = dbServer.getDBTopLevel().getModel(dbc, user, modelKey);
    Simulation[] simArray = new Simulation[simKeys.length];
    for (int i = 0; i < simKeys.length; i++) {
        Simulation sim = dbServer.getDBTopLevel().getSimulation(dbc, user, simKeys[i]);
        // 
        try {
            simArray[i] = (Simulation) BeanUtils.cloneSerializable(sim);
        } catch (Throwable e) {
            e.printStackTrace(System.out);
            throw new RuntimeException("exception cloning Simulation: " + e.getMessage());
        }
    }
    SimulationContext[] scArray = new SimulationContext[scKeys.length];
    for (int i = 0; i < scKeys.length; i++) {
        SimulationContext sc = dbServer.getDBTopLevel().getSimulationContext(dbc, user, scKeys[i]);
        // 
        try {
            scArray[i] = (SimulationContext) BeanUtils.cloneSerializable(sc);
            scArray[i].getModel().refreshDependencies();
            scArray[i].refreshDependencies();
            scArray[i].setModel(model);
        } catch (Throwable e) {
            e.printStackTrace(System.out);
            throw new RuntimeException("exception cloning Application: " + e.getMessage());
        }
        if (!scArray[i].getModel().getKey().compareEqual(modelKey)) {
            // throw new DataAccessException("simulationContext("+scKeys[i]+").model = "+scArray[i].getModel().getKey()+", BioModel.model = "+modelKey);
            System.out.println("simulationContext(" + scKeys[i] + ").model = " + scArray[i].getModel().getKey() + ", BioModel.model = " + modelKey);
        }
    }
    // 
    // create new BioModel according to loaded BioModelMetaData
    // 
    BioModel newBioModel = new BioModel(bioModelMetaData.getVersion());
    try {
        // newBioModel.setMIRIAMAnnotation(bioModelMetaData.getMIRIAMAnnotation());
        System.err.println("< < < < NEED TO GET VCMETADATA FROM METADATA TABLE ... METADATA IS EMPTY. > > > >");
        newBioModel.setModel(model);
        newBioModel.setSimulationContexts(scArray);
        // 
        for (int i = 0; i < simArray.length; i++) {
            boolean bMathFound = false;
            for (int j = 0; j < scArray.length; j++) {
                if (simArray[i].getMathDescription().getVersion().getVersionKey().compareEqual(scArray[j].getMathDescription().getVersion().getVersionKey())) {
                    simArray[i].setMathDescription(scArray[j].getMathDescription());
                    bMathFound = true;
                    break;
                }
            }
            if (!bMathFound) {
                System.out.println("<<<<WARNING>>>>> ClientDocumentManager.getBioModel(), Simulation " + simArray[i].getName() + " is orphaned, Math(" + simArray[i].getMathDescription().getName() + ") not found in Applications");
                simArray = (Simulation[]) BeanUtils.removeElement(simArray, simArray[i]);
                i--;
            }
        }
        newBioModel.setSimulations(simArray);
    } catch (java.beans.PropertyVetoException e) {
        e.printStackTrace(System.out);
        throw new DataAccessException("PropertyVetoException caught " + e.getMessage());
    }
    // 
    // The BioModel is no longer cloned because the reference to this BioModel is no longer returned to the calling method.
    // the only possible side effect is the "BioModel:refreshDependencies()" method call.
    // this will reconnect internal listeners and other transient fields, and is not going to harm the cache integrity.
    // 
    // //
    // // clone BioModel (so that children can't be corrupted in the cache)
    // //
    // try {
    // newBioModel = (BioModel)BeanUtils.cloneSerializable(newBioModel);
    // }catch (Exception e){
    // e.printStackTrace(System.out);
    // throw new DataAccessException("BioModel clone failed: "+e.getMessage());
    // }
    newBioModel.refreshDependencies();
    // 
    return cbit.vcell.xml.XmlHelper.bioModelToXML(newBioModel);
}
Also used : KeyValue(org.vcell.util.document.KeyValue) BioModelMetaData(cbit.vcell.biomodel.BioModelMetaData) SimulationContext(cbit.vcell.mapping.SimulationContext) PropertyVetoException(java.beans.PropertyVetoException) Simulation(cbit.vcell.solver.Simulation) BioModel(cbit.vcell.biomodel.BioModel) MathModel(cbit.vcell.mathmodel.MathModel) BioModel(cbit.vcell.biomodel.BioModel) Model(cbit.vcell.model.Model) DataAccessException(org.vcell.util.DataAccessException)

Example 94 with Simulation

use of cbit.vcell.solver.Simulation 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 95 with Simulation

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

the class SimulationWorkspace method editSimulation.

/**
 * Comment
 */
public static void editSimulation(Component parent, SimulationOwner simOwner, Simulation simulation) {
    String errorMessage = checkCompatibility(simOwner, simulation);
    if (errorMessage != null) {
        PopupGenerator.showErrorDialog(parent, errorMessage + "\nUpdate Math before editing");
        return;
    }
    try {
        SimulationEditor simEditor = new SimulationEditor();
        simEditor.prepareToEdit(simulation, parent);
        JScrollPane scrollPane = new JScrollPane(simEditor);
        Dimension panesize = simEditor.getPreferredSize();
        scrollPane.setPreferredSize(new Dimension(panesize.width + 20, panesize.height + 20));
        boolean acceptable = false;
        String errors = null;
        do {
            int ok = PopupGenerator.showComponentOKCancelDialog(parent, scrollPane, "Edit: " + simulation.getName());
            if (ok != javax.swing.JOptionPane.OK_OPTION) {
                // user cancels, we discard
                return;
            } else {
                acceptable = checkSimulationParameters(simEditor.getClonedSimulation(), parent);
            }
        } while (!acceptable);
        Simulation clonedSimulation = simEditor.getClonedSimulation();
        if (clonedSimulation.compareEqual(simulation)) {
            return;
        }
        // clonedSimulation is the new one.
        errors = applyChanges(clonedSimulation, simulation);
        if (!errors.equals("")) {
            throw new Exception("Some or all of the changes could not be applied:" + errors);
        }
    } catch (ChomboInvalidGeometryException e) {
        String option = DialogUtils.showWarningDialog(parent, "Warning", e.getRecommendation().getErrorMessage(), e.getRecommendation().getDialogOptions(), ChomboMeshRecommendation.optionClose);
        if (ChomboMeshRecommendation.optionSuggestions.equals(option)) {
            DialogUtils.showInfoDialog(parent, ChomboMeshRecommendation.optionSuggestions, e.getRecommendation().getMeshSuggestions());
        }
    } catch (Exception e) {
        DialogUtils.showErrorDialog(parent, e.getMessage(), e);
    }
}
Also used : JScrollPane(javax.swing.JScrollPane) Simulation(cbit.vcell.solver.Simulation) Dimension(java.awt.Dimension) ChomboInvalidGeometryException(cbit.vcell.geometry.ChomboInvalidGeometryException) ExpressionException(cbit.vcell.parser.ExpressionException) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) ChomboInvalidGeometryException(cbit.vcell.geometry.ChomboInvalidGeometryException) MathException(cbit.vcell.math.MathException)

Aggregations

Simulation (cbit.vcell.solver.Simulation)195 SimulationContext (cbit.vcell.mapping.SimulationContext)57 BioModel (cbit.vcell.biomodel.BioModel)53 MathDescription (cbit.vcell.math.MathDescription)48 KeyValue (org.vcell.util.document.KeyValue)33 Geometry (cbit.vcell.geometry.Geometry)29 MathModel (cbit.vcell.mathmodel.MathModel)27 Expression (cbit.vcell.parser.Expression)26 DataAccessException (org.vcell.util.DataAccessException)26 File (java.io.File)25 ExpressionException (cbit.vcell.parser.ExpressionException)24 IOException (java.io.IOException)24 SimulationJob (cbit.vcell.solver.SimulationJob)23 ArrayList (java.util.ArrayList)23 PropertyVetoException (java.beans.PropertyVetoException)20 UniformOutputTimeSpec (cbit.vcell.solver.UniformOutputTimeSpec)18 XMLSource (cbit.vcell.xml.XMLSource)18 SimulationTask (cbit.vcell.messaging.server.SimulationTask)17 TimeBounds (cbit.vcell.solver.TimeBounds)16 BigString (org.vcell.util.BigString)16