Skip to content

feat(bngsim): evaluate simulate/parameter_scan action args as expressions#512

Merged
wshlavacek merged 1 commit into
mainfrom
feat/bngsim-action-arg-expressions
Jul 23, 2026
Merged

feat(bngsim): evaluate simulate/parameter_scan action args as expressions#512
wshlavacek merged 1 commit into
mainfrom
feat/bngsim-action-arg-expressions

Conversation

@wshlavacek

Copy link
Copy Markdown
Collaborator

What

Numeric arguments of simulate(...) and parameter_scan(...)/bifurcate(...)
actions can now be arithmetic expressions (e.g. t_end=>2*5), not just bare
numbers.

Why

BNGL action arguments are parsed as raw strings (_parse_action_value keeps
scalars as text), so an arithmetic value like t_end=>2*5 reached the handlers
as the string "2*5" and was handed to bare float()/int(), which raised
ValueError. Routing every numeric argument through _eval_numeric — the same
no-builtins safe evaluator setParameter/setConcentration already use — makes
an expression resolve exactly the way its literal equivalent does.

Plain numbers are unchanged (_eval_numeric tries float() first, so results
are 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_conc

Test plan

New tests/test_bngsim_action_expressions.py:

  • simulate: t_end=>2*5, n_steps=>4*5 reproduces the literal 10/20
    run exactly (real bngsim engine, two fresh models compared point-for-point).
  • parameter_scan: expression-valued t_start/t_end/print_functions/
    reset_conc/seed resolve to the expected numbers.
  • Verified the new tests fail on the pre-change code
    (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

…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>
@wshlavacek
wshlavacek merged commit a9bdf07 into main Jul 23, 2026
8 checks passed
@wshlavacek
wshlavacek deleted the feat/bngsim-action-arg-expressions branch July 23, 2026 16:56
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.

1 participant