本文整理汇总了Python中pysb.simulator.ScipyOdeSimulator类的典型用法代码示例。如果您正苦于以下问题:Python ScipyOdeSimulator类的具体用法?Python ScipyOdeSimulator怎么用?Python ScipyOdeSimulator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ScipyOdeSimulator类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_integrate_with_expression
def test_integrate_with_expression():
"""Ensure a model with Expressions simulates."""
Monomer('s1')
Monomer('s9')
Monomer('s16')
Monomer('s20')
# Parameters should be able to contain s(\d+) without error
Parameter('ks0',2e-5)
Parameter('ka20', 1e5)
Initial(s9(), Parameter('s9_0', 10000))
Observable('s1_obs', s1())
Observable('s9_obs', s9())
Observable('s16_obs', s16())
Observable('s20_obs', s20())
Expression('keff', (ks0*ka20)/(ka20+s9_obs))
Rule('R1', None >> s16(), ks0)
Rule('R2', None >> s20(), ks0)
Rule('R3', s16() + s20() >> s16() + s1(), keff)
time = np.linspace(0, 40)
sim = ScipyOdeSimulator(model, tspan=time)
simres = sim.run()
keff_vals = simres.expressions['keff']
assert len(keff_vals) == len(time)
assert np.allclose(keff_vals, 1.8181818181818182e-05)
开发者ID:alubbock,项目名称:pysb,代码行数:31,代码来源:test_simulator_scipy.py
示例2: test_simres_dataframe
def test_simres_dataframe():
""" Test SimulationResult.dataframe() """
tspan1 = np.linspace(0, 100, 100)
tspan2 = np.linspace(50, 100, 50)
tspan3 = np.linspace(100, 150, 100)
model = tyson_oscillator.model
sim = ScipyOdeSimulator(model, integrator='lsoda')
simres1 = sim.run(tspan=tspan1)
# Check retrieving a single simulation dataframe
df_single = simres1.dataframe
# Generate multiple trajectories
trajectories1 = simres1.species
trajectories2 = sim.run(tspan=tspan2).species
trajectories3 = sim.run(tspan=tspan3).species
# Try a simulation result with two different tspan lengths
sim = ScipyOdeSimulator(model, param_values={'k6' : [1.,1.]}, integrator='lsoda')
simres = SimulationResult(sim, [tspan1, tspan2], [trajectories1, trajectories2])
df = simres.dataframe
assert df.shape == (len(tspan1) + len(tspan2),
len(model.species) + len(model.observables))
# Next try a simulation result with two identical tspan lengths, stacked
# into a single 3D array of trajectories
simres2 = SimulationResult(sim, [tspan1, tspan3],
np.stack([trajectories1, trajectories3]))
df2 = simres2.dataframe
assert df2.shape == (len(tspan1) + len(tspan3),
len(model.species) + len(model.observables))
开发者ID:LoLab-VU,项目名称:pysb,代码行数:33,代码来源:test_simulationresult.py
示例3: setup
def setup(self):
self.nsims = 100
self.timer = timeit.default_timer
self.model = earm_1_0.model
self.model.reset_equations()
self.parameter_set = np.repeat(
[[p.value for p in self.model.parameters]], self.nsims, axis=0)
integrator_options_common = {
'model': self.model,
'tspan': np.linspace(0, 20000, 101),
'param_values': self.parameter_set
}
self.sim_lsoda = ScipyOdeSimulator(
integrator='lsoda',
compiler='cython',
integrator_options={'atol': 1e-6, 'rtol': 1e-6, 'mxstep': 20000},
**integrator_options_common
)
self.sim_lsoda_no_compiler_directives = ScipyOdeSimulator(
integrator='lsoda',
compiler='cython',
cython_directives={},
integrator_options={'atol': 1e-6, 'rtol': 1e-6, 'mxstep': 20000},
**integrator_options_common
)
self.sim_cupsoda = CupSodaSimulator(
integrator_options={'atol': 1e-6, 'rtol': 1e-6, 'max_steps': 20000},
**integrator_options_common
)
开发者ID:LoLab-VU,项目名称:pysb,代码行数:31,代码来源:simulator.py
示例4: test_unicode_obsname_nonascii
def test_unicode_obsname_nonascii():
"""Ensure non-ascii unicode observable names error in python 2."""
t = np.linspace(0, 100)
rob_copy = copy.deepcopy(robertson.model)
rob_copy.observables[0].name = u'A_total\u1234'
sim = ScipyOdeSimulator(rob_copy)
simres = sim.run(tspan=t)
开发者ID:alubbock,项目名称:pysb,代码行数:7,代码来源:test_simulator_scipy.py
示例5: test_earm_integration
def test_earm_integration():
"""Ensure earm_1_0 model simulates."""
t = np.linspace(0, 1e3)
# Run with or without inline
sim = ScipyOdeSimulator(earm_1_0.model, tspan=t)
sim.run()
if sim._compiler != 'python':
# Also run without inline
ScipyOdeSimulator(earm_1_0.model, tspan=t, compiler='python').run()
开发者ID:alubbock,项目名称:pysb,代码行数:9,代码来源:test_simulator_scipy.py
示例6: test_unicode_obsname_ascii
def test_unicode_obsname_ascii():
"""Ensure ascii-convetible unicode observable names are handled."""
t = np.linspace(0, 100)
rob_copy = copy.deepcopy(robertson.model)
rob_copy.observables[0].name = u'A_total'
sim = ScipyOdeSimulator(rob_copy)
simres = sim.run(tspan=t)
simres.all
simres.dataframe
开发者ID:alubbock,项目名称:pysb,代码行数:9,代码来源:test_simulator_scipy.py
示例7: setup_module
def setup_module(module):
"""Doctest fixture for nose."""
# Distutils' temp directory creation code has a more-or-less unsuppressable
# print to stdout which will break the doctest which triggers it (via
# scipy.weave.inline). So here we run an end-to-end test of the inlining
# system to get that print out of the way at a point where it won't matter.
# As a bonus, the test harness is suppressing writes to stdout at this time
# anyway so the message is just swallowed silently.
ScipyOdeSimulator._test_inline()
开发者ID:,项目名称:,代码行数:9,代码来源:
示例8: test_unicode_exprname_nonascii
def test_unicode_exprname_nonascii():
"""Ensure non-ascii unicode expression names error in python 2."""
t = np.linspace(0, 100)
rob_copy = copy.deepcopy(robertson.model)
ab = rob_copy.observables['A_total'] + rob_copy.observables['B_total']
expr = Expression(u'A_plus_B\u1234', ab, _export=False)
rob_copy.add_component(expr)
sim = ScipyOdeSimulator(rob_copy)
simres = sim.run(tspan=t)
开发者ID:alubbock,项目名称:pysb,代码行数:9,代码来源:test_simulator_scipy.py
示例9: test_unicode_exprname_ascii
def test_unicode_exprname_ascii():
"""Ensure ascii-convetible unicode expression names are handled."""
t = np.linspace(0, 100)
rob_copy = copy.deepcopy(robertson.model)
ab = rob_copy.observables['A_total'] + rob_copy.observables['B_total']
expr = Expression(u'A_plus_B', ab, _export=False)
rob_copy.add_component(expr)
sim = ScipyOdeSimulator(rob_copy)
simres = sim.run(tspan=t)
simres.all
simres.dataframe
开发者ID:alubbock,项目名称:pysb,代码行数:11,代码来源:test_simulator_scipy.py
示例10: test_earm_integration
def test_earm_integration():
"""Ensure earm_1_0 model simulates."""
t = np.linspace(0, 1e3)
# Run with or without inline
sim = ScipyOdeSimulator(earm_1_0.model, tspan=t)
sim.run()
if ScipyOdeSimulator._use_inline:
# Also run without inline
ScipyOdeSimulator._use_inline = False
ScipyOdeSimulator(earm_1_0.model, tspan=t).run()
ScipyOdeSimulator._use_inline = True
开发者ID:,项目名称:,代码行数:11,代码来源:
示例11: test_robertson_integration
def test_robertson_integration():
"""Ensure robertson model simulates."""
t = np.linspace(0, 100)
# Run with or without inline
sim = ScipyOdeSimulator(robertson.model)
simres = sim.run(tspan=t)
assert simres.species.shape[0] == t.shape[0]
if sim._compiler != 'python':
# Also run without inline
sim = ScipyOdeSimulator(robertson.model, tspan=t, compiler='python')
simres = sim.run()
assert simres.species.shape[0] == t.shape[0]
开发者ID:alubbock,项目名称:pysb,代码行数:12,代码来源:test_simulator_scipy.py
示例12: test_robertson_integration
def test_robertson_integration():
"""Ensure robertson model simulates."""
t = np.linspace(0, 100)
# Run with or without inline
sim = ScipyOdeSimulator(robertson.model)
simres = sim.run(tspan=t)
assert simres.species.shape[0] == t.shape[0]
if ScipyOdeSimulator._use_inline:
# Also run without inline
ScipyOdeSimulator._use_inline = False
sim = ScipyOdeSimulator(robertson.model, tspan=t)
simres = sim.run()
assert simres.species.shape[0] == t.shape[0]
ScipyOdeSimulator._use_inline = True
开发者ID:,项目名称:,代码行数:14,代码来源:
示例13: setUp
def setUp(self):
Monomer('A', ['a'])
Monomer('B', ['b'])
Parameter('ksynthA', 100)
Parameter('ksynthB', 100)
Parameter('kbindAB', 100)
Parameter('A_init', 0)
Parameter('B_init', 0)
Initial(A(a=None), A_init)
Initial(B(b=None), B_init)
Observable("A_free", A(a=None))
Observable("B_free", B(b=None))
Observable("AB_complex", A(a=1) % B(b=1))
Rule('A_synth', None >> A(a=None), ksynthA)
Rule('B_synth', None >> B(b=None), ksynthB)
Rule('AB_bind', A(a=None) + B(b=None) >> A(a=1) % B(b=1), kbindAB)
self.model = model
# Convenience shortcut for accessing model monomer objects
self.mon = lambda m: self.model.monomers[m]
# This timespan is chosen to be enough to trigger a Jacobian evaluation
# on the various solvers.
self.time = np.linspace(0, 1)
self.sim = ScipyOdeSimulator(self.model, tspan=self.time,
integrator='vode')
开发者ID:,项目名称:,代码行数:32,代码来源:
示例14: setup_tropical
def setup_tropical(self, tspan, type_sign, find_passengers_by):
"""
:param tspan: time of simulation
:param type_sign: type of dynamical signature. It can either 'production' or 'consumption
:param find_passengers_by: Method to find non important species
:return:
"""
if tspan is not None:
self.tspan = tspan
else:
raise SimulatorException("'tspan' must be defined.")
if type_sign not in ['production', 'consumption']:
raise Exception('Wrong type_sign')
self.sim = ScipyOdeSimulator(self.model, self.tspan)
if find_passengers_by is 'imp_nodes':
self.find_nonimportant_nodes()
self.equations_to_tropicalize()
if not self.all_comb:
self.set_combinations_sm(type_sign=type_sign)
self.is_setup = True
return
开发者ID:LoLab-VU,项目名称:tropical,代码行数:27,代码来源:max_plus_multiprocessing.py
示例15: TestScipyOdeCompilerTests
class TestScipyOdeCompilerTests(TestScipySimulatorBase):
"""Test vode and analytic jacobian with different compiler backends"""
def setUp(self):
super(TestScipyOdeCompilerTests, self).setUp()
self.args = {'model': self.model,
'tspan': self.time,
'integrator': 'vode',
'use_analytic_jacobian': True}
self.python_sim = ScipyOdeSimulator(compiler='python', **self.args)
self.python_res = self.python_sim.run()
def test_cython(self):
sim = ScipyOdeSimulator(compiler='cython', **self.args)
simres = sim.run()
assert simres.species.shape[0] == self.args['tspan'].shape[0]
assert np.allclose(self.python_res.dataframe, simres.dataframe)
def test_theano(self):
sim = ScipyOdeSimulator(compiler='theano', **self.args)
simres = sim.run()
assert simres.species.shape[0] == self.args['tspan'].shape[0]
assert np.allclose(self.python_res.dataframe, simres.dataframe)
@unittest.skipIf(sys.version_info.major >= 3, 'weave not available for '
'Python 3')
def test_weave(self):
sim = ScipyOdeSimulator(compiler='weave', **self.args)
simres = sim.run()
assert simres.species.shape[0] == self.args['tspan'].shape[0]
assert np.allclose(self.python_res.dataframe, simres.dataframe)
开发者ID:alubbock,项目名称:pysb,代码行数:31,代码来源:test_simulator_scipy.py
示例16: test_sequential_initials_dict_then_list
def test_sequential_initials_dict_then_list(self):
A, B = self.model.monomers
base_sim = ScipyOdeSimulator(
self.model,
initials={A(a=None): 10, B(b=None): 20})
assert np.allclose(base_sim.initials, [10, 20, 0])
assert len(base_sim.initials_dict) == 2
# Now set initials using a list, which should overwrite the dict
base_sim.initials = [30, 40, 50]
assert np.allclose(base_sim.initials, [30, 40, 50])
assert np.allclose(
sorted([x[0] for x in base_sim.initials_dict.values()]),
base_sim.initials)
开发者ID:alubbock,项目名称:pysb,代码行数:17,代码来源:test_simulator_scipy.py
示例17: __init__
def __init__(self, model, tspan, use_analytic_jacobian=False,
integrator='vode', cleanup=True,
verbose=False, **integrator_options):
self._sim = ScipyOdeSimulator(model, verbose=verbose, tspan=tspan,
use_analytic_jacobian=
use_analytic_jacobian,
integrator=integrator, cleanup=cleanup,
**integrator_options)
self.result = None
开发者ID:,项目名称:,代码行数:9,代码来源:
示例18: setUp
def setUp(self):
super(TestScipyOdeCompilerTests, self).setUp()
self.args = {'model': self.model,
'tspan': self.time,
'integrator': 'vode',
'use_analytic_jacobian': True}
self.python_sim = ScipyOdeSimulator(compiler='python', **self.args)
self.python_res = self.python_sim.run()
开发者ID:alubbock,项目名称:pysb,代码行数:9,代码来源:test_simulator_scipy.py
示例19: initialize
def initialize(self, cfg_file=None, mode=None):
"""Initialize the model for simulation, possibly given a config file.
Parameters
----------
cfg_file : Optional[str]
The name of the configuration file to load, optional.
"""
self.sim = ScipyOdeSimulator(self.model)
self.state = numpy.array(copy.copy(self.sim.initials)[0])
self.time = numpy.array(0.0)
self.status = 'initialized'
开发者ID:johnbachman,项目名称:indra,代码行数:12,代码来源:bmi_wrapper.py
示例20: TestSimulationResultEarm13
class TestSimulationResultEarm13(object):
def setUp(self):
self.model = earm_1_3.model
self.tspan = np.linspace(0, 100, 101)
self.sim = ScipyOdeSimulator(self.model, tspan=self.tspan)
self.simres = self.sim.run()
@raises(ValueError)
def test_dynamic_observable_nonpattern(self):
self.simres.observable('cSmac')
@raises(ValueError)
def test_match_nonexistent_pattern(self):
m = self.model.monomers
self.simres.observable(m.cSmac() % m.Bid())
def test_on_demand_observable(self):
m = self.model.monomers
assert isinstance(self.simres.observable(m.cSmac()), pd.Series)
开发者ID:LoLab-VU,项目名称:pysb,代码行数:19,代码来源:test_simulationresult.py
注:本文中的pysb.simulator.ScipyOdeSimulator类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论