Пример #1
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--;

}
Пример #2
0
void TestRoadRunner::steadyState(const std::string& uri)
{
    Logger::setLevel(Logger::LOG_DEBUG);
    RoadRunner r;

    r.load(uri);

    r.steadyState();
}
Пример #3
0
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;
}
Пример #4
0
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();
}
Пример #5
0
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;
    }
}
Пример #6
0
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;
}
Пример #7
0
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;
}