Exemple #1
0
def _worker(src, seeds, results, sim_args, sim_kwargs):
    # create a rr obj

    print("starting worker processes: " + str(os.getpid()))

    n = 0;

          
    r = RoadRunner(src);

    # remove and apply the selections 
    # no sense in re-evaluating selection list each time.
    if 'sel' in sim_kwargs:
        r.selections = sim_kwargs['sel']
        del sim_kwargs['sel']

    if 'selections' in sim_kwargs:
        r.selections = sim_kwargs['selections']
        del sim_kwargs['selections']


    # might have forgot to reset sim, 
    # default is to reset sim between each simulation.
    if not 'reset' in sim_kwargs:
        Logger.log(Logger.LOG_WARNING, 
                   "simulate args missing reset, defaulting to reset between simulations")
        sim_kwargs['reset'] = True

    # read until None, 
    # blocks if queue is empty
    for seed in iter(seeds.get, None):
        sim_kwargs['seed'] = seed
        result = r.simulate(*sim_args, **sim_kwargs)
        results.put(result)
        n += 1

    print("process {} finished with {} simulations".format(os.getpid(), n))
Exemple #2
0
def _worker(src, seeds, results, sim_args, sim_kwargs):
    # create a rr obj

    print("starting worker processes: " + str(os.getpid()))

    n = 0

    r = RoadRunner(src)

    # remove and apply the selections
    # no sense in re-evaluating selection list each time.
    if 'sel' in sim_kwargs:
        r.selections = sim_kwargs['sel']
        del sim_kwargs['sel']

    if 'selections' in sim_kwargs:
        r.selections = sim_kwargs['selections']
        del sim_kwargs['selections']

    # might have forgot to reset sim,
    # default is to reset sim between each simulation.
    if not 'reset' in sim_kwargs:
        Logger.log(
            Logger.LOG_WARNING,
            "simulate args missing reset, defaulting to reset between simulations"
        )
        sim_kwargs['reset'] = True

    # read until None,
    # blocks if queue is empty
    for seed in iter(seeds.get, None):
        sim_kwargs['seed'] = seed
        result = r.simulate(*sim_args, **sim_kwargs)
        results.put(result)
        n += 1

    print("process {} finished with {} simulations".format(os.getpid(), n))
Exemple #3
0
def runTester (testDir=None):
    """
    Run a series of tests from a testing dir.

    This enumerates all the files in a directory, and all the files ending with '.rrtest'
    are assumed to be testing files.
    """
    global fHandle
    global gFailedTests
    global gPassedTests

    import os.path as p
    from glob import glob
    
    gFailedTests = 0
    gPassedTests = 0
    
    if testDir is None:
        testDir = getDefaultTestDir()

    if not p.isdir(testDir):
        raise Exception("{} is NOT a directory".format(testDir))

    files = glob(p.join(testDir, "*.rrtest"))

    unknownTests = 0
    for file in files:
        print("\n\nStarting Test on ", file)

        # set the globals, these should be class instance vars...
        fHandle = open (file, 'r')
        testId = jumpToNextTest()

        

        if testId == '[SBML]':
            sbmlStr, testId = getSBMLStr ()
        else:
            Logger.log(Logger.LOG_WARNING, "rrtest file, \"" 
                       + file + "\" missing SBML section, ignoring test file")
            continue
        

        # Load any initialization actions
        if testId == '[INITIALIZATION]':
            testId = jumpToNextTest ()
            while testId != '[END_INITIALIZATION]':
                if functions.has_key(testId):
                    func = functions[testId]
                    func (rrInstance, testId)
                else:
                    print('No initialization function found for ' + testId)
                testId = jumpToNextTest()
            testId = jumpToNextTest()

        # create a RoadRunner obj with the sbml from the test file
        rrInstance = roadrunner.RoadRunner(sbmlStr)
        print('Successfully loaded model.\n')

        # Now start the tests proper
        while testId != '':
            if functions.has_key(testId):
                func = functions[testId]
                func(rrInstance, testId)
            else:
                #getFloatingSpeciesAmountRates
                unknownTests = unknownTests+1
                print(string.ljust (testId, rpadding), 'UNKNOWN TEST')
            testId = jumpToNextTest()
        
    print("\n\nTotal failed tests:\t", gFailedTests, \
    "\nTotal unknown tests:\t", unknownTests, \
    "\nTotal passed tests:\t", gPassedTests)

    return gFailedTests
Exemple #4
0
# Sabaody
# Copyright 2018 J Kyle Medley
from __future__ import print_function, division, absolute_import

from roadrunner import RoadRunner, Logger
Logger.disableConsoleLogging()
Logger.setLevel(Logger.LOG_FATAL)

from params import getDefaultParamValues, getUpperBound, getLowerBound
from b2problem import B2_UDP

from pygmo import island as pg_island, problem, rosenbrock, simulated_annealing, de, mp_island
from math import sqrt


def benchmark_loading_time():
    import arrow
    time_start = arrow.utcnow()
    r = RoadRunner('../../../../../sbml/b2.xml')
    delta_t = arrow.utcnow() - time_start
    print('Loading time:', delta_t)

def benchmark_simulated_annealing():
    island = pg_island(
        algo=simulated_annealing(Ts=1.,Tf=.01),
        prob=problem(B2_UDP(getLowerBound(),getUpperBound(),'../../../../../sbml/b2.xml')),
        size=10)

    N = 10
    import arrow
    time_start = arrow.utcnow()
Exemple #5
0
from roadrunner import RoadRunner, Logger

#Logger.setLevel(Logger.LOG_DEBUG) # too verbose
Logger.setLevel(Logger.LOG_WARNING)

# Load model

rr = RoadRunner('/tmp/tx.sbml')
#rr = RoadRunner('/tmp/tx-reduced.sbml')
#rr = RoadRunner('/tmp/antsbml.xml')

# Simulate model
results = rr.simulate(0, 10, 30, integrator='gillespie')

print(results)

# Write results to temp file
with open('/tmp/sim_res.csv', 'w') as f:
    f.write(str(results))

# Plot
rr.plot()
Exemple #6
0
def runTester(testDir=None):
    """
    Run a series of tests from a testing dir.

    This enumerates all the files in a directory, and all the files ending with '.rrtest'
    are assumed to be testing files.
    """
    global fHandle
    global gFailedTests
    global gPassedTests

    import os.path as p
    from glob import glob

    gFailedTests = 0
    gPassedTests = 0

    if testDir is None:
        testDir = getDefaultTestDir()

    if not p.isdir(testDir):
        raise Exception("{} is NOT a directory".format(testDir))

    files = glob(p.join(testDir, "*.rrtest"))

    unknownTests = 0
    for file in files:
        print("\n\nStarting Test on ", file)

        # set the globals, these should be class instance vars...
        fHandle = open(file, 'r')
        testId = jumpToNextTest()

        if testId == '[SBML]':
            sbmlStr, testId = getSBMLStr()
        else:
            Logger.log(
                Logger.LOG_WARNING, "rrtest file, \"" + file +
                "\" missing SBML section, ignoring test file")
            continue

        # Load any initialization actions
        if testId == '[INITIALIZATION]':
            testId = jumpToNextTest()
            while testId != '[END_INITIALIZATION]':
                if testId in functions:
                    func = functions[testId]
                    func(rrInstance, testId)
                else:
                    print('No initialization function found for ' + testId)
                testId = jumpToNextTest()
            testId = jumpToNextTest()

        # create a RoadRunner obj with the sbml from the test file
        rrInstance = roadrunner.RoadRunner(sbmlStr)
        print('Successfully loaded model.\n')

        # Now start the tests proper
        while testId != '':
            if testId in functions:
                func = functions[testId]
                func(rrInstance, testId)
            else:
                #getFloatingSpeciesAmountRates
                unknownTests = unknownTests + 1
                print((testId).ljust(rpadding), 'UNKNOWN TEST')
            testId = jumpToNextTest()

    for testFunc in [unitTestIntegratorSettings]:
        testFunc(testDir)

    print("\n\nTotal failed tests:\t", gFailedTests, \
    "\nTotal unknown tests:\t", unknownTests, \
    "\nTotal passed tests:\t", gPassedTests)

    return gFailedTests