Skip to content

Commit

Permalink
Test case for Issue #48
Browse files Browse the repository at this point in the history
This is @tahorst's test case to reproduce an Arrow hang.

Is it caused by a Gillespie algorithm blowup? By integer overflow? Something else?

**Note:** `make clean compile` prints an unexpected warning
```
building 'arrow.arrowhead' extension
Warning: Can't read registry to find the necessary compiler setting
Make sure that Python modules winreg, win32api or win32con are installed.
C compiler: clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -I/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include
```

**Note:** `test_flagella` also fails: `arrow/arrow.py:176: SimulationFailure`.
  • Loading branch information
1fish2 committed Dec 9, 2021
1 parent 66c783d commit 791fa82
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 3 deletions.
Binary file added arrow/test/complex-counts.npy
Binary file not shown.
Binary file added arrow/test/rates.npy
Binary file not shown.
Binary file added arrow/test/stoich.npy
Binary file not shown.
56 changes: 56 additions & 0 deletions arrow/test/test_hang.py
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(10000):
if i % 100 == 0:
print(i)

result = system.evolve(1, mol, rates)


if __name__ == '__main__':
test_hang()
5 changes: 2 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
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
Expand Down Expand Up @@ -41,8 +40,8 @@
name='stochastic-arrow',
version='0.4.4',
packages=['arrow'],
author='Ryan Spangler, John Mason, Jerry Morrison',
author_email='[email protected]',
author='Ryan Spangler, John Mason, Jerry Morrison, Chris Skalnik',
author_email='[email protected]',
url='https://github.com/CovertLab/arrow',
license='MIT',
include_dirs=include,
Expand Down

0 comments on commit 791fa82

Please sign in to comment.