-
Notifications
You must be signed in to change notification settings - Fork 70
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
Use python dict to support bngl hash type arguments in console actions #539
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good - please could you add a small test for this to the BNG test suite? Similar to the example you give on the PR. Thanks!
Just added the requested test. Also, I change the exporters so that the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @ortega2247. I've made a few small suggestions in the inline comments.
# Conflicts: # pysb/export/python.py
for k, v in kwargs.items(): | ||
bng_param = BngConsole._bng_param(v) | ||
if isinstance(bng_param, collections.Mapping): | ||
par_string = f'{k}' + '=>{' + ','.join(f"{k}=>{v}" for k, v in bng_param.items()) + '}' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unwieldy and not really using the benefit of f-strings. Also re-using the local v
variable is a bit confusing. How about something like this (not tested) :
args_string = ",".join(f"{k}=>{v}" for k, v in bng_param.items())
par_string = f"{k}=>{args_string}"
for k, v in kwargs.items(): | ||
bng_param = BngConsole._bng_param(v) | ||
if isinstance(bng_param, collections.Mapping): | ||
par_string = f'{k}' + '=>{' + ','.join(f"{k}=>{v}" for k, v in bng_param.items()) + '}' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we perform some validation on the kwargs
keys and values here to make sure we don't emit invalid BNGL? If the BNG parser fails due to invalid BNGL here the error will probably be hard for the user to make sense of. The keys should be validated against the regex that matches whatever BNG accepts there, but I'm not sure what the value syntax is.
Codecov Report
@@ Coverage Diff @@
## master #539 +/- ##
==========================================
+ Coverage 80.20% 80.25% +0.05%
==========================================
Files 101 101
Lines 10661 10678 +17
==========================================
+ Hits 8551 8570 +19
+ Misses 2110 2108 -2
Continue to review full report at Codecov.
|
This adds support to use bngl hash type arguments like max_stoich that are passed to generate_network. I use f-strings because i feel it is easier to read, but most of the code in pysb uses the old string formatting (% operator). Comments, feedback, and requests are more than welcome
That caps the number of BAX molecules in a complex to 1