Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Large model Solver/Simulator construction errors in Python 3 #298

Closed
bgyori opened this issue Sep 24, 2017 · 3 comments
Closed

Large model Solver/Simulator construction errors in Python 3 #298

bgyori opened this issue Sep 24, 2017 · 3 comments

Comments

@bgyori
Copy link
Contributor

bgyori commented Sep 24, 2017

When trying to simulate models above a certain size (this is vague, but see example below) in Python 3, I get the following error:

In [10]: sim = ScipyOdeSimulator(model, numpy.linspace(0, 100))
Traceback (most recent call last):
  File "/Users/ben/.virtualenvs/py36/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2910, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-10-2af18e3a9d87>", line 1, in <module>
    sim = ScipyOdeSimulator(model, numpy.linspace(0, 100))
  File "/Users/ben/.virtualenvs/py36/lib/python3.6/site-packages/pysb/simulator/scipyode.py", line 183, in __init__
    sympy.flatten(ode_mat))
  File "/Users/ben/.virtualenvs/py36/lib/python3.6/site-packages/sympy/utilities/lambdify.py", line 434, in lambdify
    func = eval(lstr, namespace)
  File "<string>", line 1
SyntaxError: more than 255 arguments

I tried this in Python 3.5 and 3.6, and tried with both git cloned and setup.py installed PySB, and pip installed PySB (1.5.0). I tried both pysb.integrate.Solver and pysb.simulator.ScipyOdeSimulator. All result in the same error. I also tried the same in Python 2 and it worked.

To not make things more complicated with a real model, I experimented a bit with auto-generated models. I generated a model in which monomers named A-Z pairwise phosphorylate each other. I found that the error went away when I only had monomers A-T, and first appeared when I had monomer U in the model - this is the model I'm attaching.

from pysb_model import model
from pysb.simulator import ScipyOdeSimulator
sim  = ScipyOdeSimulator(model)

pysb_model.py.zip

@alubbock
Copy link
Member

The ScipyOdeSimulator constructor converts your system of ODEs into code for execution, either using the weave library to convert them into C code, or sympy to convert them into Python functions. Until recently, Python had a limit of 255 arguments per function call, which is the limit you're hitting upon above. However, this limit will be removed in Python 3.7.

Your options are:

  • Use Python 2.7 with weave installed. This is recommended where possible, as the C code produced by weave will be much faster than Python code.
  • Upgrade to a pre-release version Python 3.7 to avoid the 255 argument limit. Not recommended, as PySB hasn't been tested with Python 3.7 yet.
  • Try the experimental use_theano=True flag, e.g. ScipyOdeSimulator(model, use_theano=True). Theano compiles your ODEs to C code like weave, so it should also be fast, but it isn't as well tested in PySB yet. This is probably your best option if you want to use Python 3 with ScipyOdeSimulator.
  • Use a different Simulator, e.g. the CupSodaSimulator if you have a compatible NVIDIA GPU available.

@bgyori
Copy link
Contributor Author

bgyori commented Sep 24, 2017

Thanks, that's really informative! I went ahead with the Theano solution and it works well in Python 3. Looks like I missed this option because it's not documented -- perhaps it would be worth mentioning in the ScipeOdeSimulator docstrings (even if it's not very well tested yet).

@alubbock
Copy link
Member

Update to this ticket: preferred solution now would be to use ScipyOdeSimulator(model, compiler='cython'). Python 3.7 has also been released, which would also address the problem as described above. I'll close the ticket.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants