Skip to content

Commit d01d454

Browse files
dweindlclaude
andcommitted
v1 lint: placeholders must not be model entities
Placeholder parameters are overridden per measurement. A model entity with the same ID is a second, conflicting definition of the same parameter. Add `assert_placeholders_not_in_model` and run it in `lint_problem`. Remove the leftover placeholder parameters and the unused observable and noise assignment rules from the Fujita example model, which violated this. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 7580974 commit d01d454

4 files changed

Lines changed: 64 additions & 64 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@
1010
`scipy>=1.15`
1111
(by @dweindl in https://github.com/PEtab-dev/libpetab-python/pull/578)
1212

13+
**Fixes**
14+
15+
v1:
16+
* `lint_problem` now reports an error for placeholder parameters that are
17+
also model entities (new `assert_placeholders_not_in_model`)
18+
(by @dweindl in https://github.com/PEtab-dev/libpetab-python/pull/605)
19+
1320
## 0.10 series
1421

1522
### 0.10.0

‎doc/example/example_Fujita/Fujita_model.xml‎

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,6 @@
3939
<parameter id="reaction_7_k1" value="0.0119329694583145" constant="true"/>
4040
<parameter id="reaction_8_k1" value="0.000941161525754959" constant="true"/>
4141
<parameter id="reaction_9_k1" value="0.0273281571867514" constant="true"/>
42-
<parameter id="observableParameter1_pAkt_tot" value="334.979345701912" constant="true"/>
43-
<parameter id="observableParameter1_pEGFR_tot" value="9.60908283106834e-08" constant="true"/>
44-
<parameter id="observableParameter1_pS6_tot" value="380222.792056961" constant="true"/>
45-
<parameter id="sigma_pAkt_tot" value="0.1" constant="false"/>
46-
<parameter id="sigma_pEGFR_tot" value="0.1" constant="false"/>
47-
<parameter id="sigma_pS6_tot" value="0.1" constant="false"/>
48-
<parameter id="noiseParameter1_pAkt_tot" value="0.1" constant="true"/>
49-
<parameter id="noiseParameter1_pEGFR_tot" value="0.1" constant="true"/>
50-
<parameter id="noiseParameter1_pS6_tot" value="0.1" constant="true"/>
51-
<parameter id="observable_pEGFR_tot" value="0" constant="false"/>
52-
<parameter id="observable_pAkt_tot" value="0" constant="false"/>
53-
<parameter id="observable_pS6_tot" value="0" constant="false"/>
5442
<parameter id="EGF" value="0.1" constant="false"/>
5543
</listOfParameters>
5644
<listOfInitialAssignments>
@@ -70,58 +58,6 @@
7058
</math>
7159
</initialAssignment>
7260
</listOfInitialAssignments>
73-
<listOfRules>
74-
<assignmentRule variable="sigma_pAkt_tot">
75-
<math xmlns="http://www.w3.org/1998/Math/MathML">
76-
<ci> noiseParameter1_pAkt_tot </ci>
77-
</math>
78-
</assignmentRule>
79-
<assignmentRule variable="sigma_pEGFR_tot">
80-
<math xmlns="http://www.w3.org/1998/Math/MathML">
81-
<ci> noiseParameter1_pEGFR_tot </ci>
82-
</math>
83-
</assignmentRule>
84-
<assignmentRule variable="sigma_pS6_tot">
85-
<math xmlns="http://www.w3.org/1998/Math/MathML">
86-
<ci> noiseParameter1_pS6_tot </ci>
87-
</math>
88-
</assignmentRule>
89-
<assignmentRule variable="observable_pEGFR_tot">
90-
<math xmlns="http://www.w3.org/1998/Math/MathML">
91-
<apply>
92-
<times/>
93-
<ci> observableParameter1_pEGFR_tot </ci>
94-
<apply>
95-
<plus/>
96-
<ci> pEGFR </ci>
97-
<ci> pEGFR_Akt </ci>
98-
</apply>
99-
</apply>
100-
</math>
101-
</assignmentRule>
102-
<assignmentRule variable="observable_pAkt_tot">
103-
<math xmlns="http://www.w3.org/1998/Math/MathML">
104-
<apply>
105-
<times/>
106-
<ci> observableParameter1_pAkt_tot </ci>
107-
<apply>
108-
<plus/>
109-
<ci> pAkt </ci>
110-
<ci> pAkt_S6 </ci>
111-
</apply>
112-
</apply>
113-
</math>
114-
</assignmentRule>
115-
<assignmentRule variable="observable_pS6_tot">
116-
<math xmlns="http://www.w3.org/1998/Math/MathML">
117-
<apply>
118-
<times/>
119-
<ci> pS6 </ci>
120-
<ci> observableParameter1_pS6_tot </ci>
121-
</apply>
122-
</math>
123-
</assignmentRule>
124-
</listOfRules>
12561
<listOfReactions>
12662
<reaction id="v1_reaction_1" name="reaction_1" reversible="true">
12763
<listOfReactants>

‎petab/v1/lint.py‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"assert_parameter_prior_parameters_are_valid",
3636
"assert_parameter_prior_type_is_valid",
3737
"assert_parameter_scale_is_valid",
38+
"assert_placeholders_not_in_model",
3839
"assert_unique_observable_ids",
3940
"assert_unique_parameter_ids",
4041
"check_condition_df",
@@ -349,6 +350,33 @@ def check_observable_df(observable_df: pd.DataFrame) -> None:
349350
) from e
350351

351352

353+
def assert_placeholders_not_in_model(
354+
observable_df: pd.DataFrame, model: Model
355+
) -> None:
356+
"""Check that no placeholder parameter is a model entity.
357+
358+
Placeholders are overridden per measurement. A model entity with the
359+
same ID would be a second, conflicting definition.
360+
361+
Arguments:
362+
observable_df: PEtab observable DataFrame
363+
model: The model
364+
365+
Raises:
366+
AssertionError: in case of problems
367+
"""
368+
from .observables import get_placeholders
369+
370+
if clashes := [
371+
placeholder
372+
for placeholder in get_placeholders(observable_df)
373+
if model.has_entity_with_id(placeholder)
374+
]:
375+
raise AssertionError(
376+
f"Placeholder parameters must not be model entities: {clashes}"
377+
)
378+
379+
352380
def assert_all_parameters_present_in_parameter_df(
353381
parameter_df: pd.DataFrame,
354382
model: Model,
@@ -936,6 +964,13 @@ def lint_problem(problem: "petab.Problem") -> bool:
936964
f"Observable ID {obs_id} shadows model entity."
937965
)
938966
errors_occurred = True
967+
try:
968+
assert_placeholders_not_in_model(
969+
problem.observable_df, problem.model
970+
)
971+
except AssertionError as e:
972+
logger.error(e)
973+
errors_occurred = True
939974
else:
940975
logger.warning("Observable table not available. Skipping.")
941976

‎tests/v1/test_lint.py‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,28 @@ def test_check_observable_df():
610610
lint.check_observable_df(bad_observable_df)
611611

612612

613+
@pytest.mark.parametrize(
614+
"model_entity", ["observableParameter1_obs1", "noiseParameter1_obs1"]
615+
)
616+
def test_assert_placeholders_not_in_model(model_entity):
617+
from petab.v1.models.sbml_model import SbmlModel
618+
619+
observable_df = pd.DataFrame(
620+
data={
621+
OBSERVABLE_ID: ["obs1"],
622+
OBSERVABLE_FORMULA: ["observableParameter1_obs1 * x1"],
623+
NOISE_FORMULA: ["noiseParameter1_obs1"],
624+
}
625+
).set_index(OBSERVABLE_ID)
626+
627+
model = SbmlModel.from_antimony("species x1 = 1")
628+
lint.assert_placeholders_not_in_model(observable_df, model)
629+
630+
model = SbmlModel.from_antimony(f"species x1 = 1; {model_entity} = 1")
631+
with pytest.raises(AssertionError, match=model_entity):
632+
lint.assert_placeholders_not_in_model(observable_df, model)
633+
634+
613635
def test_condition_ids_are_unique():
614636
condition_df = pd.DataFrame(
615637
data={

0 commit comments

Comments
 (0)