-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from CovertLab/fix-48
Avoid selection of 0 propensity reactions and negative counts
- Loading branch information
Showing
7 changed files
with
134 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# A test case for Issue #48. | ||
# | ||
# This code should reproduce the error: the program hangs after it prints "7100" | ||
# and eventually runs out of memory. You'll have to Ctrl+Z to stop it. | ||
# Ctrl+C won't work. | ||
# | ||
# It hangs only with certain seeds and numbers of molecules. The system can | ||
# evolve with the same number of molecule counts for 7179 iterations before it | ||
# hangs. Adding 1 to all of the molecules causes it to hang at an earlier | ||
# iteration. | ||
# | ||
# TODO: Debug this. Is it caused by a Gillespie algorithm blowup (see below), | ||
# integer overflow Undefined Behavior in C, or something else? | ||
# | ||
# The Gillespie algorithm is prone to explode [symptom?] under certain | ||
# conditions if the exponent term in the choice calculation is too large. | ||
# | ||
# The workaround is to find the problematic reaction and decompose the | ||
# stoichiometry into an equivalent problem with more steps. | ||
# | ||
# The flagella example had something like 170 identical subunits which caused | ||
# the problem. Breaking it into 2+ equivalent reactions fixed it. | ||
# | ||
# It'd be good for the Arrow code to catch this problem when/before it happens | ||
# and at least identify which reactions are problematic. | ||
|
||
import os | ||
|
||
from arrow import StochasticSystem | ||
import numpy as np | ||
|
||
|
||
def np_load(filename): | ||
filepath = os.path.join(os.path.dirname(__file__), filename) | ||
return np.load(filepath) | ||
|
||
|
||
def test_hang(): | ||
# TODO: Use a pytest plug-in to timeout after some threshold. | ||
|
||
seed = 807952948 | ||
|
||
stoich = np_load('stoich.npy') | ||
mol = np_load('complex-counts.npy') | ||
rates = np_load('rates.npy') | ||
|
||
system = StochasticSystem(stoich, random_seed=seed) | ||
for i in range(7300): | ||
if i % 100 == 0: | ||
print(i) | ||
|
||
result = system.evolve(1, mol, rates) | ||
|
||
|
||
if __name__ == '__main__': | ||
test_hang() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
import os | ||
# from glob import glob | ||
import setuptools # used indirectly for bdist_wheel cmd and long_description_content_type | ||
from distutils.core import setup | ||
from distutils.extension import Extension | ||
import numpy.distutils.misc_util | ||
|
||
with open("README.md", 'r') as readme: | ||
long_description = readme.read() | ||
long_description = readme.read() | ||
|
||
current_dir = os.getcwd() | ||
arrow_dir = os.path.join(current_dir, 'arrow') | ||
|
@@ -23,38 +22,38 @@ | |
ext = '.pyx' if USE_CYTHON else '.c' | ||
|
||
cython_extensions = [ | ||
Extension('arrow.arrowhead', | ||
sources=['arrow/mersenne.c', 'arrow/obsidian.c', 'arrow/arrowhead'+ext,], | ||
include_dirs=['arrow'] + numpy.distutils.misc_util.get_numpy_include_dirs(), | ||
define_macros=[('NPY_NO_DEPRECATED_API', 'NPY_1_7_API_VERSION')], | ||
)] | ||
Extension('arrow.arrowhead', | ||
sources=['arrow/mersenne.c', 'arrow/obsidian.c', 'arrow/arrowhead'+ext,], | ||
include_dirs=['arrow'] + numpy.distutils.misc_util.get_numpy_include_dirs(), | ||
define_macros=[('NPY_NO_DEPRECATED_API', 'NPY_1_7_API_VERSION')], | ||
)] | ||
|
||
if USE_CYTHON: | ||
from Cython.Build import cythonize | ||
cython_extensions = cythonize( | ||
cython_extensions, | ||
include_path=['arrow'], | ||
annotate=True, # to get an HTML code listing | ||
) | ||
from Cython.Build import cythonize | ||
cython_extensions = cythonize( | ||
cython_extensions, | ||
include_path=['arrow'], | ||
annotate=True, # to get an HTML code listing | ||
) | ||
|
||
setup( | ||
name='stochastic-arrow', | ||
version='0.4.4', | ||
packages=['arrow'], | ||
author='Ryan Spangler, John Mason, Jerry Morrison', | ||
author_email='[email protected]', | ||
url='https://github.com/CovertLab/arrow', | ||
license='MIT', | ||
include_dirs=include, | ||
ext_modules=cython_extensions, | ||
long_description=long_description, | ||
long_description_content_type='text/markdown', | ||
requires=['numpy (>=1.14)', 'six'], | ||
classifiers=[ | ||
'Development Status :: 3 - Alpha', | ||
'License :: OSI Approved :: MIT License', | ||
'Programming Language :: Python', | ||
'Programming Language :: Python :: 2.7', | ||
'Programming Language :: Python :: 3', | ||
'Topic :: Scientific/Engineering', | ||
]) | ||
name='stochastic-arrow', | ||
version='0.5.0', | ||
packages=['arrow'], | ||
author='Ryan Spangler, John Mason, Jerry Morrison, Chris Skalnik, Travis Ahn-Horst', | ||
author_email='[email protected]', | ||
url='https://github.com/CovertLab/arrow', | ||
license='MIT', | ||
include_dirs=include, | ||
ext_modules=cython_extensions, | ||
long_description=long_description, | ||
long_description_content_type='text/markdown', | ||
requires=['numpy (>=1.14)', 'six'], | ||
classifiers=[ | ||
'Development Status :: 3 - Alpha', | ||
'License :: OSI Approved :: MIT License', | ||
'Programming Language :: Python', | ||
'Programming Language :: Python :: 2.7', | ||
'Programming Language :: Python :: 3', | ||
'Topic :: Scientific/Engineering', | ||
]) |