本文整理汇总了Python中pysb.simulator.ScipyOdeSimulator类的典型用法代码示例。如果您正苦于以下问题:Python ScipyOdeSimulator类的具体用法?Python ScipyOdeSimulator怎么用?Python ScipyOdeSimulator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ScipyOdeSimulator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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))
示例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
)
示例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)
示例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()
示例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
示例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()
示例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)
示例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
示例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
示例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]
示例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
示例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')
示例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
示例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)