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

New BioNetGen interfaces for console and file based access #168

Merged
merged 15 commits into from Nov 3, 2015

Conversation

alubbock
Copy link
Member

@alubbock alubbock commented Oct 2, 2015

I've added two new classes, BngFileInterface and BngConsole, for interacting with BioNetGen. Both extend an abstract base class BngBaseInterface. I've adjusted generate_network and run_ssa to use BngFileInterface.

Both BngFileInterface and BngConsole have very similar API and usage. The difference is that BngConsole executes commands instantly and waits for the response using the pexpect library and the BNG Console interface. BngFileInterface buffers all BNG commands and outputs them to the .bngl file for execution in one go. BngFileInterface is typically faster (no repeated command/response lag) and cross-platform; BngConsole is great for interactive use and development, but the pexpect library doesn't support Windows.

alubbock and others added 9 commits October 1, 2015 19:25
Call any arbitrary BNG command using a context manager
and Python kwargs. Example:

with BngConsole(model) as con:
    con.action('simulate_ssa', t_end=10, n_steps=100)

The context manager automatically loads the model into BNG
and cleans up on exit.
'simlulate_ssa' to 'simulate({method=>"ssa",...})', which is the
preferred call method. Note that the "ssa" argument has to be passed to
BNG with enclosing quotes. This is true of all string arguments. So
we'll have to keep this in mind as we implement more wrappers around BNG
actions using the console interface. Any args passed in as strings will
have to be type checked and enclosed in quotes when building the action
call.
BioNetGen requires string arguments to be double quoted and booleans
as 0 or 1. A small class method _bng_param now handles this
automatically.

Also, two quick fixes: BngConsole now extends object, and network
generation in run_ssa() should be done within try block, not
finally block (more fault tolerant).
Both BNGFileInterface and BNGConsole have very similar API and usage.
The difference is that BNGConsole executes commands instantly and
waits for the response using the pexpect library. BNGFileInterface
buffers all BNG commands and outputs them to the .bngl file for
execution in one go. BNGFileInterface is typically faster (no
repeated command/response lag) and cross-platform; BNGConsole is
great for interactive use and development.
Cleanup and verbose arguments to run_ssa and generate_network
are now handled better - verbose is passed to BNG's
generate_network, and cleanup is now passed to the BngFileInterface
constructor rather than the BNG simulate call as expected.

Thanks to @JamesPino for catching the cleanup arg issue.
@johnbachman
Copy link
Member

Looks good to me. @jmuhlich, do you want to take a look?

@@ -12,7 +12,7 @@ before_install:
- conda install --yes python=$TRAVIS_PYTHON_VERSION numpy scipy matplotlib sympy networkx
nose h5py
- pip install -i https://pypi.binstar.org/pypi/simple pygraphviz==1.3rc1
- pip install python-coveralls
- pip install python-coveralls pexpect
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also pedantic: I think anaconda offers pexpect (see http://docs.continuum.io/anaconda/pkg-docs), so ideally we'd install that with conda rather than pip.

@alubbock
Copy link
Member Author

I think I've addressed all your feedback @jmuhlich - let me know if there's anything I missed. The verbose=True argument in BngFileInterface doesn't stop the output from being captured if there's an error, but it did make me realize BngConsole would hide any issues unless verbose=True was set. I've added new warning output which passes on any BNG warnings encountered in 0e2262e.

@jmuhlich
Copy link
Member

jmuhlich commented Nov 3, 2015

Hmm, it's good to note that your "allow synthesis instead of initial conditions" fix is rolled up in here too.

@jmuhlich jmuhlich merged commit c0ae7b7 into pysb:master Nov 3, 2015
@alubbock alubbock deleted the bngconsole branch November 4, 2015 06:45
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

Successfully merging this pull request may close these issues.

None yet

4 participants