int main() { RoadRunner lRR; LogOutput::mLogToConsole = true; gLog.SetCutOffLogLevel(lInfo); Log(lInfo)<<"======================"; Log(lInfo)<<lRR.getInfo(); Log(lInfo)<<"======================"; LoadModelThread load(JoinPath("..", "models", "feedback.xml"), &lRR); load.start(); load.waitForFinish(); SimulateThread sim(&lRR); sim.start(); sim.waitForFinish(); Log(lInfo)<<lRR.getSimulationResult(); for(int i = 0; i < 2; i++) { lRR.setNumPoints(10); sim.addJob(&lRR); sim.start(); sim.waitForFinish(); Log(lInfo)<<lRR.getSimulationResult(); } return 0; }
void LoadModelThread::worker() { RoadRunner *rri = NULL; mWasStarted = true; mIsWorking = true; //Any thread working on this Job list need to increment this one Mutex::ScopedLock lock(mNrOfWorkersMutex); mNrOfWorkers++; mNrOfWorkersMutex.unlock(); while(!mIsTimeToDie) { { //Scope for scoped lock Mutex::ScopedLock lock(mJobsMutex); if(mJobs.size() == 0) { RRPLOG(tlp::lDebug5)<<"Waiting for jobs in loadSBML worker"; //mJobsCondition.wait(mJobsMutex); break; } if(mIsTimeToDie) { break; //ends the life of the thread.. } else { //Get a job rri = mJobs.front(); mJobs.pop_front(); } } //Causes the scoped lock to unlock //Do the job if(rri) { RRPLOG(lDebug2)<<"Loading model into instance: "<<rri->getInstanceID(); if(mModelFileName.size()) { rri->load(mModelFileName, &mLoadSBMLOptions); } else if(mSBML.size()) { rri->load(mSBML, &mLoadSBMLOptions); } } else { RRPLOG(lError)<<"Null job pointer...!"; } } RRPLOG(lDebug)<<"Exiting Load Model thread: "<<mThread.id(); mIsWorking = false; Mutex::ScopedLock lock2(mNrOfWorkersMutex); mNrOfWorkers--; }
void TestRoadRunner::steadyState(const std::string& uri) { Logger::setLevel(Logger::LOG_DEBUG); RoadRunner r; r.load(uri); r.steadyState(); }
void TestRoadRunner::testRead(const std::string &fname) { Logger::enableConsoleLogging(Logger::LOG_DEBUG); //const char* fname = "/Users/andy/src/sbml_test/cases/semantic/00001/00001-sbml-l2v4.xml"; libsbml::SBMLReader reader; SBMLDocument *doc = reader.readSBML(fname); Model *m = doc->getModel(); const ListOfParameters *params = m->getListOfParameters(); for(int i = 0; i < params->size(); ++i) { const Parameter *p = params->get(i); cout << "param \'" << p->getId() << "\', conservedMoiety: " << ConservationExtension::getConservedMoiety(*p) << endl; } const ListOfSpecies *species = m->getListOfSpecies(); for(int i = 0; i < species->size(); ++i) { const Species *s = species->get(i); cout << "species \'" << s->getId() << "\', conservedMoiety: " << ConservationExtension::getConservedMoiety(*s) << endl; } delete doc; Logger::setLevel(Logger::LOG_TRACE); RoadRunner r; r.load(fname, 0); rr::ExecutableModel *model = r.getModel(); int len = model->getNumIndFloatingSpecies(); double *buffer = new double[len]; model->getFloatingSpeciesAmountRates(len, 0, buffer); delete[] buffer; cout << "its all good" << endl; }
bool TestCapabilities::test() { RoadRunner rr; std::string caps = rr.getConfigurationXML(); Log(Logger::PRIO_INFORMATION) << caps; return true; }
void ParameterScanWorker::run() { workerStarted(); //The user may have aborted the minization... check here.. if(mHost.isBeingTerminated()) { //user did set the terminate flag to true.. discard any data and get out of the //plugin execute code.. RRPLOG(lInfo)<<"The ParameterScanWorker was terminated.. aborting"; workerFinished(); return; } //Create arrayed data ArrayedParameter para(mHost.mParameter.getValueReference()); StringList selList(mHost.mSelectionList.getValue()); RoadRunner rr; rr.load(mHost.mSBML.getValue()); //Make sure time is the first column in the selectin list if(selList.size() && compareNoCase(selList[0], "time") != true) { selList.InsertAt(0,"time"); } rr.setSelections(selList); TelluriumData& data = mHost.mOutputData.getValueReference(); data.clear(); for(int i = 0; i < para.getNumberOfIncrements() + 1; i++) { rr::SimulateOptions options; options.flags |= rr::SimulateOptions::RESET_MODEL; options.start = mHost.mStartTime.getValue(); options.duration = mHost.mEndTime.getValue() - mHost.mStartTime.getValue(); options.steps = mHost.mNumberOfPointsPerSimulation.getValue() - 1; //Set parameter rr.setValue(para.getName(), para.getCurrentValue()); const RoadRunnerData *rrData = rr.simulate(&options); TelluriumData *temp = new TelluriumData(*rrData); data.append(*temp); delete temp; para.increment(); } //The Arrayed parameter need to be added to the data. data.setArrayedParameter(para); workerFinished(); }
int rrcCallConv getNumberOfRules(RRHandle handle) { start_try RoadRunner* rri = castToRoadRunner(handle); if(!rri->getModel()) { Log(Logger::LOG_WARNING)<<"Model is not allocated."; return -1; } int value = rri->getModel()->getNumRules(); return value; catch_int_macro }
void SimulateThread::worker() { mWasStarted = true; mIsWorking = true; Mutex::ScopedLock lock(mNrOfWorkersMutex); mNrOfWorkers++; mNrOfWorkersMutex.unlock(); RoadRunner *rri = NULL; ////////////////////////////////// while(!mIsTimeToDie) { { //Scope for the mutex lock... Mutex::ScopedLock lock(mJobsMutex); if(mJobs.size() == 0 )//|| mIsTimeToDie) { break; //ends the life of the thread.. } rri = mJobs.front(); mJobs.pop_front(); } //Causes the scoped lock to unlock //Do the job if(rri) { Log(lInfo)<<"Simulating RR instance: "<<rri->getInstanceID(); if(!rri->simulate2()) { Log(lError)<<"Failed simulating instance: "<<rri->getInstanceID(); } } else { Log(lError)<<"Null job pointer...!"; } } Log(lDebug)<<"Exiting Simulate thread: "<<mThread.id(); mIsWorking = false; Mutex::ScopedLock lock2(mNrOfWorkersMutex); mNrOfWorkers--; }
/** * perform a stochastic ensemble calculation. * * :param: r an existing roadrunner obj, loaded with a mode. * :param: n how many ensembles to run. * :param: seed the seed value, use None to continue with previous * random number stream. * :param: start start time * :param: stop stop time * :param: ntps how many points display in the result. */ DoubleMatrix ensemble(RoadRunner &r, int n, unsigned long seed, double start, double stop, int npts) { // set the seed value of the integrator Integrator *itg = r.getIntegrator(Integrator::GILLESPIE); itg->setItem("seed", seed); // setup the simulation // create a sim opt obj, loads itself with // default values in ctor. SimulateOptions o; o.start = start; o.duration = stop; o.steps = npts; // we should reset the model each time we simulate, // set the RESET_MODEL bit. o.flags |= SimulateOptions::RESET_MODEL; o.integrator = Integrator::GILLESPIE; // make a result var DoubleMatrix result(npts+1, n+1); for (int i = 0; i < n; ++i) { const DoubleMatrix &sim = *r.simulate(&o); // copy result data colum for (int row = 0; row < npts+1; ++row) { result(row, i+1) = sim(row, 1); } } // copy result time column const DoubleMatrix &sim = *r.getSimulationData(); // copy result data colum for (int row = 0; row < npts+1; ++row) { result(row, 0) = sim(row, 0); } return result; }
void TestRoadRunner::testLoad(const std::string& uri) { try { Logger::setLevel(Logger::LOG_DEBUG); //std::string sbml = SBMLReader::read(uri); RoadRunner r; r.load(uri); r.steadyState(); } catch(std::exception& e) { cout << "error: " << e.what() << std::endl; } }
void compareJacobians(RRHandle gRR) { RoadRunner* rri = castToRoadRunner(gRR); ls::DoubleMatrix jFull = rri->getFullJacobian(); ls::DoubleMatrix jReduced = rri->getReducedJacobian(); //Check dimensions if(jFull.RSize() != jReduced.RSize() || jFull.CSize() != jReduced.CSize()) { CHECK(false); return; } for(int row = 0; row < jFull.RSize(); row++) { for(int col = 0; col < jFull.CSize(); col++) { CHECK_CLOSE(jFull(row, col), jReduced(row, col), 1e-6); } } }
bool SBMLTestSuiteSimulation_CAPI::LoadSBMLFromFile() { if(!mRRHandle) { return false; } try { std::string fileName = GetModelsFullFilePath(); //Check first if file exists first if(!fileExists(fileName)) { Log(Logger::PRIO_ERROR) << "sbml file " << fileName << " not found"; return false; } RoadRunner* rri = (RoadRunner*) mRRHandle; LoadSBMLOptions opt; // simulation only, no need for accessor functions. opt.modelGeneratorOpt |= (LoadSBMLOptions::ReadOnlyModel | LoadSBMLOptions::ForceReCompile); if(!rri->loadSBMLFromFile(fileName, &opt)) { Log(Logger::PRIO_ERROR) << "Failed to load SBML"; return false; } return true; } catch(std::exception& e) { Log(Logger::PRIO_ERROR) << "exception while loading sbml: " << e.what(); return false; } }
bool TestModel::execute(bool inThread) { Log(lDebug)<<"Executing the TestModel plugin by Totte Karlsson"; RoadRunner rr; rr.load(mModel); rr::SimulateOptions opt; opt.start = 0; opt.duration = 10; opt.steps = 14; TelluriumData data(rr.simulate(&opt)); mTestData.setValue(data); //Add noise const PluginManager* PM = this->getPluginManager(); Plugin* noise = PM->getPlugin("AddNoise"); if(!noise) { stringstream msg; msg<<"The TestModel plugin dependes on the AddNoise plugin, which is not yet loaded."; throw(Exception(msg.str())); } mTestDataWithNoise.setValue(mTestData.getValue()); noise->setPropertyValue("Sigma", mSigma.getValueHandle()); noise->setPropertyValue("InputData", mTestDataWithNoise.getValueHandle()); noise->execute(); mTestDataWithNoise.setValue(noise->getPropertyValueHandle("InputData")); //Add weights addWeights(); return true; }
int main(int argc, char** argv) { std::string in_dir; std::string out_dir; std::string test_name; unsigned int level = 0; unsigned int version = 0; double start_time = 0.0; double duration = 0.0; std::list<std::string> variables; std::set<std::string> amounts; std::set<std::string> concentrations; double absolute_error = 0.0; double relative_error = 0.0; if (argc < 6) { std::cerr << "Usage: rr-sbml-benchmrk INPUT_DIRECTORY TESTNAME OUTPUTDIRECTORY SBMLLEVEL SBMLVERSION [steps override] [durration] [compiler] [-stiff]" << std::endl; exit(1); } in_dir = argv[1]; test_name = argv[2]; out_dir = argv[3]; level = strtol(argv[4], NULL, 10); version = strtol(argv[5], NULL, 10); if (level < 1 || level > 3) { std::cerr << "SBML Level " << level << " Version " << version << " not supported." << std::endl; exit(1); } if (level == 1 && (version < 1 || version > 2)) { std::cerr << "SBML Level " << level << " Version " << version << " not supported." << std::endl; exit(1); } std::ostringstream os; os << in_dir << "/" << test_name << "/" << test_name << "-settings.txt"; // open the settings file and parse it std::cout << "parsing file: " << os.str() << std::endl; std::ifstream f; std::string settingsFile = in_dir + "/" + test_name + "/" + test_name + "-settings.txt"; std::string sbmlFile; { stringstream os; os << in_dir << "/" << test_name << "/" << test_name << "-sbml-l" << level << "v" << version << ".xml"; sbmlFile = os.str(); } std::string output_filename; if (!out_dir.empty() || out_dir.compare("/dev/null") != 0) { stringstream os; os.str(""); os << out_dir << "/" << test_name << ".csv"; output_filename = os.str(); } RoadRunner roadRunner; LoadSBMLOptions opt; // don't generate cache for models opt.modelGeneratorOpt = opt.modelGeneratorOpt | LoadSBMLOptions::RECOMPILE; // no mutable initial conditions opt.modelGeneratorOpt = opt.modelGeneratorOpt & ~LoadSBMLOptions::MUTABLE_INITIAL_CONDITIONS; // read only model opt.modelGeneratorOpt = opt.modelGeneratorOpt | LoadSBMLOptions::READ_ONLY; opt.modelGeneratorOpt = opt.modelGeneratorOpt | LoadSBMLOptions::OPTIMIZE_CFG_SIMPLIFICATION; opt.modelGeneratorOpt = opt.modelGeneratorOpt | LoadSBMLOptions::OPTIMIZE_GVN; std::cout << "loading file: " << sbmlFile << std::endl; roadRunner.load(sbmlFile, &opt); SimulateOptions settings; settings.loadSBMLSettings(settingsFile); // override steps if (argc > 6) { int steps = strtol(argv[6], NULL, 0); if (steps > 0) { settings.steps = steps; } } if (argc > 7) { double dur = atof(argv[7]); if (dur > 0) { settings.duration = dur; } } for (int i = 0; i < argc; ++i) { if (string(argv[i]).find("stiff") != string::npos) { roadRunner.getIntegrator()->setValue("stiff", true); } } std::cout << "running for " << settings.steps << ", duration " << settings.duration << std::endl; std::cout << "absolute: " << roadRunner.getIntegrator()->getValue("absolute_tolerance").convert<bool>() << std::endl; std::cout << "relative: " << roadRunner.getIntegrator()->getValue("relative_tolerance").convert<bool>() << std::endl; std::cout << "stiff: " << (roadRunner.getIntegrator()->getValue("stiff").convert<bool>() ? "True" : "False") << std::endl; roadRunner.setSimulateOptions(settings); const DoubleMatrix& result = *roadRunner.simulate(0); if (!output_filename.empty()) { ofstream output; output.open(output_filename.c_str()); int rows = result.numRows(); int cols = result.numCols(); for (int i = 0; i < rows; ++i) { for (int j = 0; j < cols; ++j) { output << result(i, j); if (j + 1 < cols) { output << ", "; } else { output << "\n"; } } } } return 0; }