feat(bngsim): evaluate simulate/parameter_scan action args as expressions#512
Merged
Merged
Conversation
…ions BNGL action arguments arrive as raw strings (`_parse_action_value` keeps scalars as text), so an arithmetic value like `t_end=>2*5` was handed to bare `float()`/`int()` and raised ValueError. Route every numeric argument in the simulate (`_prepare_simulate_run`) and parameter_scan/bifurcate (`_resolve_scan_settings`) handlers through `_eval_numeric` -- the same no-builtins safe evaluator `setParameter`/`setConcentration` already use -- so an expression resolves the way its literal equivalent does. Plain numbers are unchanged. Adds an e2e test (the expression form reproduces the literal run) plus a scan-settings test covering t_start/t_end/print_functions/reset_conc/seed. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Numeric arguments of
simulate(...)andparameter_scan(...)/bifurcate(...)actions can now be arithmetic expressions (e.g.
t_end=>2*5), not just barenumbers.
Why
BNGL action arguments are parsed as raw strings (
_parse_action_valuekeepsscalars as text), so an arithmetic value like
t_end=>2*5reached the handlersas the string
"2*5"and was handed to barefloat()/int(), which raisedValueError. Routing every numeric argument through_eval_numeric— the sameno-builtins safe evaluator
setParameter/setConcentrationalready use — makesan expression resolve exactly the way its literal equivalent does.
Plain numbers are unchanged (
_eval_numerictriesfloat()first, so resultsare byte-identical). This is purely additive — no existing behavior is removed.
Converted in both handlers:
_prepare_simulate_run:continue,t_start,t_end,n_steps,print_functions,atol,rtol,seed,steady_state_resolve_scan_settings:t_start,t_end,steady_state,print_functions,seed,reset_concTest plan
New
tests/test_bngsim_action_expressions.py:t_end=>2*5,n_steps=>4*5reproduces the literal10/20run exactly (real bngsim engine, two fresh models compared point-for-point).
t_start/t_end/print_functions/reset_conc/seedresolve to the expected numbers.(
ValueError: could not convert string to float: '1+1').Full bngsim suite green with BNG2.pl (BioNetGen 2.9.3): 312 passed on this
branch in isolation.
🤖 Generated with Claude Code