Skip to content

Commit 88810a8

Browse files
committed
PyBioNetGen: Add PLA support to BNGsim backend bridge
Previously the BNGsim backend hook rejected PLA actions and routed them to the BNG2.pl subprocess, where the bundled run_network binary fails on the '-p pla' method. Now PLA is treated like ode/ssa/psa: the Perl hook intercepts it and delegates to the backend helper, which passes it through to BNGsim when available. The method alias map, routing checks, and test patch hook are all updated accordingly.
1 parent e991daa commit 88810a8

3 files changed

Lines changed: 7 additions & 57 deletions

File tree

bionetgen/core/tools/bngsim_backend_helper.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"ode": "ode",
4242
"ssa": "ssa",
4343
"psa": "psa",
44+
"pla": "pla",
4445
"rm": "rm",
4546
}
4647

bionetgen/core/tools/bngsim_bridge.py

Lines changed: 1 addition & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,7 +1199,7 @@ def _nfsim_session_kwargs(nf_params):
11991199
FORMAT_ANTIMONY,
12001200
}
12011201

1202-
_BNGSIM_NETWORK_METHODS = frozenset({"ode", "ssa", "psa", "rm"})
1202+
_BNGSIM_NETWORK_METHODS = frozenset({"ode", "ssa", "psa", "pla", "rm"})
12031203

12041204
_BNGL_ROUTING_COMPLEX_ACTIONS = frozenset(
12051205
{
@@ -1424,40 +1424,11 @@ def _classify_bngl_actions_for_bngsim(
14241424
if len(sim_actions) > 1:
14251425
has_backend_hook_workflow = True
14261426

1427-
if any(workflow_method == "pla" for workflow_method in workflow_methods):
1428-
return BngsimRouteDecision(
1429-
ROUTE_SUBPROCESS,
1430-
"BNGL PLA is not supported by BNGsim",
1431-
method="pla",
1432-
)
1433-
14341427
if method is not None:
14351428
method_name = _strip_quotes(str(method).strip()).lower()
14361429
if sim_actions:
1437-
if any(
1438-
_bngl_action_method_for_routing(action) == "pla"
1439-
for action in sim_actions
1440-
):
1441-
return BngsimRouteDecision(
1442-
ROUTE_SUBPROCESS,
1443-
"BNGL PLA is not supported by BNGsim",
1444-
method="pla",
1445-
)
1446-
action_method = _bngl_action_method_for_routing(sim_actions[0])
1447-
if action_method == "pla":
1448-
return BngsimRouteDecision(
1449-
ROUTE_SUBPROCESS,
1450-
"BNGL PLA is not supported by BNGsim",
1451-
method="pla",
1452-
)
14531430
if method_name == "ssa" and "poplevel" in (sim_actions[0].args or {}):
14541431
method_name = "psa"
1455-
if method_name == "pla":
1456-
return BngsimRouteDecision(
1457-
ROUTE_SUBPROCESS,
1458-
"BNGL PLA is not supported by BNGsim",
1459-
method="pla",
1460-
)
14611432
if _method_supported_by_bngsim_for_routing(method_name, bngsim_has_nfsim):
14621433
return BngsimRouteDecision(
14631434
ROUTE_BNGL_BNGSIM,
@@ -1473,21 +1444,9 @@ def _classify_bngl_actions_for_bngsim(
14731444
candidate_methods = []
14741445
for action in sim_actions:
14751446
method_name = _bngl_action_method_for_routing(action)
1476-
if method_name == "pla":
1477-
return BngsimRouteDecision(
1478-
ROUTE_SUBPROCESS,
1479-
"BNGL PLA is not supported by BNGsim",
1480-
method="pla",
1481-
)
14821447
candidate_methods.append(method_name)
14831448

14841449
for method_name in workflow_methods:
1485-
if method_name == "pla":
1486-
return BngsimRouteDecision(
1487-
ROUTE_SUBPROCESS,
1488-
"BNGL PLA is not supported by BNGsim",
1489-
method="pla",
1490-
)
14911450
if method_name != "protocol":
14921451
candidate_methods.append(method_name)
14931452

@@ -1602,18 +1561,6 @@ def classify_bngsim_route(
16021561
method=method_name,
16031562
)
16041563
method_name = _strip_quotes(str(method).strip()).lower() if method else None
1605-
if method_name == "pla":
1606-
if fmt in FALLBACK_FORMATS:
1607-
return BngsimRouteDecision(
1608-
ROUTE_SUBPROCESS,
1609-
"PLA is not supported by the direct BNGsim route",
1610-
method=method_name,
1611-
)
1612-
return BngsimRouteDecision(
1613-
ROUTE_ERROR,
1614-
f"Format '{fmt}' requires BNGsim but method='pla' is not supported",
1615-
method=method_name,
1616-
)
16171564
return BngsimRouteDecision(
16181565
ROUTE_DIRECT_BNGSIM,
16191566
f"Format '{fmt}' routes directly to BNGsim",

tests/test_bngsim_backend_hook.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def _patch_real_bng_action(bng_root):
6464
hook = r"""
6565
# PyBioNetGen/BNGsim backend hook. BNG2.pl has already normalized the
6666
# model state, artifact path, method, options, and output prefix.
67-
if ($ENV{'BIONETGEN_BNGSIM_BACKEND'} && $method =~ /^(cvode|ssa|psa)$/)
67+
if ($ENV{'BIONETGEN_BNGSIM_BACKEND'} && $method =~ /^(cvode|ssa|psa|pla)$/)
6868
{
6969
my @helper_command;
7070
if ($ENV{'BIONETGEN_BNGSIM_BACKEND_HELPER'})
@@ -640,15 +640,17 @@ def test_fake_helper_receives_psa_as_psa(tmp_path, real_bng_backend_runtime):
640640
assert jobs[0]["simulation_options"]["poplevel"] == 100
641641

642642

643-
def test_pla_action_does_not_call_helper(tmp_path, real_bng_backend_runtime):
643+
def test_fake_helper_receives_pla_as_pla(tmp_path, real_bng_backend_runtime):
644644
_run_real_hook(
645645
tmp_path,
646646
real_bng_backend_runtime,
647647
"PLA",
648648
"generate_network({overwrite=>1})\nsimulate_pla({t_end=>1,n_steps=>1})",
649649
)
650650

651-
assert _captured_jobs(real_bng_backend_runtime["capture"]) == []
651+
jobs = _captured_jobs(real_bng_backend_runtime["capture"])
652+
assert len(jobs) == 1
653+
assert jobs[0]["method"] == "pla"
652654

653655

654656
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)