Skip to content

Action grammar rejects scientific-notation and trailing commas in list args (par_scan_vals) — stricter than BNG2.pl, causes silent legacy fallback under simulator='bngsim' #110

@wshlavacek

Description

@wshlavacek

Summary

The action-argument grammar in bionetgen/core/utils/utils.py (ActionList.define_parser) is stricter than BNG2.pl for list-valued arguments. It rejects two forms that BNG2.pl (Perl) accepts and runs fine:

  1. Scientific notation in list elements — e.g. par_scan_vals=>[2.3e-10, 5.1e-10]
  2. A trailing comma in a list — e.g. par_scan_vals=>[1, 2, 3,]

When a model uses either in a list-valued arg (most commonly par_scan_vals on parameter_scan), modelapi.bngmodel raises BNGParseError ("Failed to parse action …"). Consequence for the merged BNGsim bridge: under bionetgen.run(simulator='bngsim') the bridge cannot inspect the model's actions, so it silently falls back to the legacy BNG2.pl subprocess — the model never runs on bngsim, with no error surfaced.

Root cause

In define_parser:

arg_type_float = pp.Word(pp.nums + ".")                          # digits + '.' only
arg_type_list  = "[" + pp.delimitedList(quote_word ^ arg_type_float) + "]"
  • arg_type_float excludes e/E/+/-, so 2.3e-10 fails to match (the grammar stops at the e).
  • pp.delimitedList(...) does not allow a trailing delimiter, so [1,2,3,] fails on the final comma.

Both are valid Perl list syntax, which is why BNG2.pl parses and runs these models (a parameter_scan over e-notation values produces correct .scan/.gdat output on the legacy stack).

Repro

from bionetgen.core.utils.utils import ActionList
al = ActionList(); al.define_parser()
al.action_parser.parse_string(
    'parameter_scan({parameter=>"x",par_scan_vals=>[2.3e-10,5.1e-10],method=>"ode"})',
    parse_all=True,
)
# pyparsing.ParseException: Expected '}', found ','

Real models affected

Surfaced by a downstream parity/golden suite's per-job engine audit. In RuleHub:

  • Published/Mitra2019/15-igf1r/fit_{ade,de,pso,ss}/IGF1R_fit_all_*.bngl (4 models) — e-notation and trailing commas in par_scan_vals
  • Published/Salazar-Cavazos2019/190127_CHO_EGFR_best-fit.bngl — e-notation in par_scan_vals

All five parse + run on BNG2.pl today; all five silently route to the legacy stack under simulator='bngsim'.

Proposed fix

Broaden arg_type_list to accept e-notation values and an optional trailing comma. arg_type_expr already covers nums + ".+-eE()/*^":

arg_type_list = (
    "[" + pp.Optional(pp.delimitedList(quote_word ^ arg_type_expr)) + pp.Optional(",") + "]"
)

Validated against the full corpus list forms:

  • ✅ accepts [0.3,1,3], [2.3e-10,5.1e-10], [0.0,0.05e-9,50.0e-9], [2.3e-10,4.9e-07,] (trailing comma), ["a","b"], and []
  • ✅ still rejects genuinely-malformed lists: double commas ([1,,2]) and unclosed lists ([1,2, with no ])

With this change, all five models above parse and route to bngsim in-process.

Refs

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions