コード例 #1
0
ファイル: test_algorithms.py プロジェクト: nimpod/stocal
 def test_iter_includes_all_events_at_tmax(self):
     proc = stocal.Process([
         stocal.Event({}, {'a': 1}, 10, 10),
         stocal.Event({}, {'b': 1}, 0, 10),
     ])
     sampler = self.Sampler(proc, {}, tmax=10)
     for _ in sampler:
         pass
     self.assertEqual(sampler.step, 3)
     self.assertEqual(sampler.time, 10)
     self.assertEqual(sampler.state, {'a': 1, 'b': 2})
コード例 #2
0
ファイル: test_algorithms.py プロジェクト: nimpod/stocal
 def test_iter_simultaneous_events(self):
     """two Events can occur at the exact same time"""
     proc = stocal.Process([
         stocal.Event({}, {'a': 1}, 10),
         stocal.Event({}, {'b': 1}, 10),
     ])
     sampler = self.Sampler(proc, {})
     for _ in sampler:
         pass
     self.assertEqual(sampler.state, {'a': 1, 'b': 1})
     self.assertEqual(sampler.step, 2)
     self.assertEqual(sampler.time, 10)
コード例 #3
0
ファイル: test_algorithms.py プロジェクト: nimpod/stocal
 def test_do_not_apply_inapplicable_events(self):
     """assert that Event does not fire if reactants are missing"""
     process = stocal.Process([stocal.Event(['a'], ['b'], 1)])
     traj = self.Sampler(process, {})
     for _ in traj:
         pass
     self.assertEqual(traj.state, stocal.structures.multiset({}))
コード例 #4
0
ファイル: test_algorithms.py プロジェクト: nimpod/stocal
    def test_fire_inferred_event(self):
        """sampler fires inferred events"""
        class Rule(stocal.ReactionRule):
            Transition = stocal.Event

            def novel_reactions(self, x):
                if x == 'a':
                    yield self.Transition(['a'], [], 10)

        process = stocal.Process(transitions=[stocal.Event([], ['a'], 1)],
                                 rules=[Rule()])

        traj = stocal.algorithms.AndersonNRM(process, {})
        it = iter(traj)

        try:
            trans = next(it)
        except StopIteration:
            self.fail("Static event not fired.")
        self.assertEqual(traj.time, 1)
        self.assertEqual(traj.state, {'a': 1})

        try:
            trans = next(it)
        except StopIteration:
            self.fail("Infered event not fired.")
        self.assertEqual(traj.time, 10)
        self.assertEqual(traj.state, {})
コード例 #5
0
ファイル: test_algorithms.py プロジェクト: nimpod/stocal
 def test_exact_number_of_events(self):
     """sampler performs specified number of events"""
     proc = stocal.Process([stocal.Event({}, {'a': 1}, 0, 1)])
     sampler = self.Sampler(proc, {}, tmax=10)
     for _ in sampler:
         pass
     self.assertEqual(sampler.step, 11)
     self.assertAlmostEqual(sampler.time, 10)
コード例 #6
0
ファイル: test_transitions.py プロジェクト: MrLiono21/stocal
    def test_text_occurrence_delayed(self):
        """assert that repeated events do not fire before first occurrence

        test closes issue #1
        """
        self.assertEqual(
            stocal.Event(['a'], ['z'], 1, 1).next_occurrence(0), 1)
        self.assertEqual(
            stocal.Event(['a'], ['z'], 1, 1).next_occurrence(0.5), 1)
        self.assertEqual(
            stocal.Event(['a'], ['z'], 1, 1).next_occurrence(1), 1)
        self.assertEqual(
            stocal.Event(['a'], ['z'], 1, 1).next_occurrence(1.5), 2)
        self.assertEqual(
            stocal.Event(['a'], ['z'], 2, 1).next_occurrence(0), 2)
        self.assertEqual(
            stocal.Event(['a'], ['z'], 2, 1).next_occurrence(1), 2)
        self.assertEqual(
            stocal.Event(['a'], ['z'], 2, 1).next_occurrence(1.5), 2)
        self.assertEqual(
            stocal.Event(['a'], ['z'], 2, 1).next_occurrence(2), 2)
        self.assertEqual(
            stocal.Event(['a'], ['z'], 2, 1).next_occurrence(2.5), 3)
コード例 #7
0
ファイル: bugs.py プロジェクト: MrLiono21/stocal
 def setUp(self):
     self.process = stocal.Process(transitions=[stocal.Event([], ['a'], 1)],
                                   rules=[self.Rule()])
コード例 #8
0
ファイル: bugs.py プロジェクト: MrLiono21/stocal
 def test_text_occurrence_delayed(self):
     """assert that repeated events do not fire before first occurrence"""
     event = stocal.Event(['a'], ['z'], 1, 1)
     self.assertEqual(event.next_occurrence(0), 1)
コード例 #9
0
ファイル: events.py プロジェクト: nimpod/stocal
"""Event example

stocal.Event's can be added to a processes definition just like
Reactions. Process.trajectory returns an StochasticSimulationAlgorithm
that can cope with deterministic transitions (e.g. FirstReactionMethod).
Sampler selection and usage is entirely transparent to the user.
"""
import stocal


process = stocal.Process([
    stocal.MassAction(['A', 'A'], ['A2'], 0.01),
    stocal.MassAction(['A2'], ['A', 'A'], 1.),
    stocal.Event([], ['A'], 0., 1.)
])


if __name__ == '__main__':
    traj = process.sample({}, tmax=100)
    for _ in traj:
        print(traj.time, traj.state['A'], traj.state['A2'])
コード例 #10
0
 def test_trajectory_with_events(self):
     """Partly deterministic processes return an appropriate sampler"""
     proc = self.Process([stocal.Event({}, {'a': 1}, 1.)])
     proc.trajectory({})
コード例 #11
0
ファイル: test_transitions.py プロジェクト: nimpod/stocal
 def test_sample_return_type_behavior(self):
     """Partly deterministic processes return an appropriate sampler"""
     proc = self.Process([stocal.Event({}, {'a': 1}, 1.)])
     traj = iter(proc.sample({}))
     self.assertEqual(len(next(traj)), 2)
コード例 #12
0
ファイル: bugs.py プロジェクト: nimpod/stocal
 def setUp(self):
     self.process = stocal.Process([stocal.Event(['a'], ['b'], 1)])