Skip to content

Commit 07205bb

Browse files
committed
Merge branch 'arrow-hang' into fix-48
Merge in the unit test.
2 parents 75b0a37 + 7139fb7 commit 07205bb

6 files changed

Lines changed: 100 additions & 33 deletions

File tree

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,20 @@ There are more command line features in test_arrow:
104104

105105
> python -m arrow.test.test_arrow --time
106106

107+
More examples:
108+
109+
> python -m arrow.test.test_hang
110+
111+
> pytest -m arrow/test/test_arrow.py
112+
113+
> pytest -k flagella
114+
107115
## Changelog
108116

117+
### Version 0.4.4
118+
119+
* Can pickle StochasticSystem instances.
120+
109121
### Version 0.3.0
110122

111123
* Introduced backwards-incompatible API change for supplying rates at `evolve()` time rather than `__init__()` for `StochasticSystem`.

arrow/test/complex-counts.npy

20.4 KB
Binary file not shown.

arrow/test/rates.npy

8.58 KB
Binary file not shown.

arrow/test/stoich.npy

21.5 MB
Binary file not shown.

arrow/test/test_hang.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# A test case for Issue #48.
2+
#
3+
# This code should reproduce the error: the program hangs after it prints "7100"
4+
# and eventually runs out of memory. You'll have to Ctrl+Z to stop it.
5+
# Ctrl+C won't work.
6+
#
7+
# It hangs only with certain seeds and numbers of molecules. The system can
8+
# evolve with the same number of molecule counts for 7179 iterations before it
9+
# hangs. Adding 1 to all of the molecules causes it to hang at an earlier
10+
# iteration.
11+
#
12+
# TODO: Debug this. Is it caused by a Gillespie algorithm blowup (see below),
13+
# integer overflow Undefined Behavior in C, or something else?
14+
#
15+
# The Gillespie algorithm is prone to explode [symptom?] under certain
16+
# conditions if the exponent term in the choice calculation is too large.
17+
#
18+
# The workaround is to find the problematic reaction and decompose the
19+
# stoichiometry into an equivalent problem with more steps.
20+
#
21+
# The flagella example had something like 170 identical subunits which caused
22+
# the problem. Breaking it into 2+ equivalent reactions fixed it.
23+
#
24+
# It'd be good for the Arrow code to catch this problem when/before it happens
25+
# and at least identify which reactions are problematic.
26+
27+
import os
28+
29+
from arrow import StochasticSystem
30+
import numpy as np
31+
32+
33+
def np_load(filename):
34+
filepath = os.path.join(os.path.dirname(__file__), filename)
35+
return np.load(filepath)
36+
37+
38+
def test_hang():
39+
# TODO: Use a pytest plug-in to timeout after some threshold.
40+
41+
seed = 807952948
42+
43+
stoich = np_load('stoich.npy')
44+
mol = np_load('complex-counts.npy')
45+
rates = np_load('rates.npy')
46+
47+
system = StochasticSystem(stoich, random_seed=seed)
48+
for i in range(7300):
49+
if i % 100 == 0:
50+
print(i)
51+
52+
result = system.evolve(1, mol, rates)
53+
54+
55+
if __name__ == '__main__':
56+
test_hang()

setup.py

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import os
2-
# from glob import glob
32
import setuptools # used indirectly for bdist_wheel cmd and long_description_content_type
43
from distutils.core import setup
54
from distutils.extension import Extension
65
import numpy.distutils.misc_util
76

87
with open("README.md", 'r') as readme:
9-
long_description = readme.read()
8+
long_description = readme.read()
109

1110
current_dir = os.getcwd()
1211
arrow_dir = os.path.join(current_dir, 'arrow')
@@ -23,38 +22,38 @@
2322
ext = '.pyx' if USE_CYTHON else '.c'
2423

2524
cython_extensions = [
26-
Extension('arrow.arrowhead',
27-
sources=['arrow/mersenne.c', 'arrow/obsidian.c', 'arrow/arrowhead'+ext,],
28-
include_dirs=['arrow'] + numpy.distutils.misc_util.get_numpy_include_dirs(),
29-
define_macros=[('NPY_NO_DEPRECATED_API', 'NPY_1_7_API_VERSION')],
30-
)]
25+
Extension('arrow.arrowhead',
26+
sources=['arrow/mersenne.c', 'arrow/obsidian.c', 'arrow/arrowhead'+ext,],
27+
include_dirs=['arrow'] + numpy.distutils.misc_util.get_numpy_include_dirs(),
28+
define_macros=[('NPY_NO_DEPRECATED_API', 'NPY_1_7_API_VERSION')],
29+
)]
3130

3231
if USE_CYTHON:
33-
from Cython.Build import cythonize
34-
cython_extensions = cythonize(
35-
cython_extensions,
36-
include_path=['arrow'],
37-
annotate=True, # to get an HTML code listing
38-
)
32+
from Cython.Build import cythonize
33+
cython_extensions = cythonize(
34+
cython_extensions,
35+
include_path=['arrow'],
36+
annotate=True, # to get an HTML code listing
37+
)
3938

4039
setup(
41-
name='stochastic-arrow',
42-
version='0.4.4',
43-
packages=['arrow'],
44-
author='Ryan Spangler, John Mason, Jerry Morrison',
45-
author_email='spanglry@stanford.edu',
46-
url='https://github.com/CovertLab/arrow',
47-
license='MIT',
48-
include_dirs=include,
49-
ext_modules=cython_extensions,
50-
long_description=long_description,
51-
long_description_content_type='text/markdown',
52-
requires=['numpy (>=1.14)', 'six'],
53-
classifiers=[
54-
'Development Status :: 3 - Alpha',
55-
'License :: OSI Approved :: MIT License',
56-
'Programming Language :: Python',
57-
'Programming Language :: Python :: 2.7',
58-
'Programming Language :: Python :: 3',
59-
'Topic :: Scientific/Engineering',
60-
])
40+
name='stochastic-arrow',
41+
version='0.4.4',
42+
packages=['arrow'],
43+
author='Ryan Spangler, John Mason, Jerry Morrison, Chris Skalnik',
44+
author_email='ryan.spangler@gmail.com',
45+
url='https://github.com/CovertLab/arrow',
46+
license='MIT',
47+
include_dirs=include,
48+
ext_modules=cython_extensions,
49+
long_description=long_description,
50+
long_description_content_type='text/markdown',
51+
requires=['numpy (>=1.14)', 'six'],
52+
classifiers=[
53+
'Development Status :: 3 - Alpha',
54+
'License :: OSI Approved :: MIT License',
55+
'Programming Language :: Python',
56+
'Programming Language :: Python :: 2.7',
57+
'Programming Language :: Python :: 3',
58+
'Topic :: Scientific/Engineering',
59+
])

0 commit comments

Comments
 (0)