Condition-table override referencing a parameter with a non-numeric InitialAssignment crashes with an opaque KeyError
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 72/100
Direzione di ricerca
Start in petab/v1/parameter_mapping.py at _apply_parameter_table, then inspect SbmlModel.get_free_parameter_ids_with_values() and the condition-table validation checks. Reproduce the minimal example, and make the unresolved condition-table reference produce an informative validation error naming the column and value rather than an unhandled KeyError.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Summary
When a condition-table cell overrides a model entity with the ID of another SBML parameter, and that referenced parameter's value can only be given via an InitialAssignment that depends on another parameter (i.e. it can't be reduced to a plain number without already knowing that other parameter's value), get_optimization_to_simulation_parameter_mapping crashes with an unhandled KeyError instead of a clear validation error.
This surfaced via AMICI-dev/AMICI#2418. The behavior described below is still present in the latest release (0.9.0).
Root cause
SbmlModel.get_free_parameter_ids_with_values() seeds the parameter-mapping dict with every SBML parameter's value, evaluating each one via get_initial():
def get_initial(p):
if ia := self.sbml_model.getInitialAssignmentBySymbol(p.getId()):
sym_expr = sympify_sbml(ia.getMath())
return (
float(sym_expr.evalf())
if sym_expr.evalf().is_Number
else None
)
return p.getValue()
If the InitialAssignment doesn't evaluate to a plain number (because it references another, possibly-estimated, parameter), get_initial() returns None, and that parameter is silently excluded from get_free_parameter_ids_with_values() — regardless of whether it's ever referenced from a condition table.
Later, in _apply_parameter_table (petab/v1/parameter_mapping.py), any condition-table cell value that's still an unresolved string is looked up two ways: as another condition-table column, or as a row in the parameter table. A parameter excluded above is neither, so:
try:
par_mapping[problem_par] = par_mapping[sim_par] # KeyError, caught
...
except KeyError:
...
scale = parameter_df.loc[sim_par, PARAMETER_SCALE] # KeyError, NOT caught
the fallback branch assumes sim_par is a parameter-table index and raises an unhandled KeyError if it isn't.
Minimal example
import pandas as pd
import petab.v1 as petab
from petab.v1.models.sbml_model import SbmlModel
C = petab.C
problem = petab.Problem()
problem.model = SbmlModel.from_antimony(
"k_base = 1.5; k_derived = k_base + 1; k_decay = 1; "
"conc = 1; conc' = -k_decay * conc;"
)
problem.condition_df = pd.DataFrame(
{"k_decay": ["k_derived"]},
index=pd.Index(["condition1"], name=C.CONDITION_ID),
)
problem.parameter_df = pd.DataFrame(
{
C.PARAMETER_SCALE: ["log10"],
C.LOWER_BOUND: [1e-3],
C.UPPER_BOUND: [1e3],
C.NOMINAL_VALUE: [1.5],
C.ESTIMATE: [1],
},
index=pd.Index(["k_base"], name=C.PARAMETER_ID),
)
petab.get_optimization_to_simulation_parameter_mapping(
condition_df=problem.condition_df,
measurement_df=None,
parameter_df=problem.parameter_df,
observable_df=None,
model=problem.model,
)
KeyError: 'k_derived'
petab.lint.lint_problem(problem) reports no issues for this problem — none of the existing checks (check_condition_df, assert_model_parameters_in_condition_or_parameter_table) inspect condition-table cell values, only column names and parameter-table row IDs.
Note: this is not specific to InitialAssignment
The same failure occurs for any condition-table override value that can't be resolved through the two supported paths (another condition-table column, or a parameter-table row) — InitialAssignment is just the most common way to end up with such a value. A plain SBML parameter without any InitialAssignment resolves fine, since get_free_parameter_ids_with_values() can always give it a value.
Suggested fix
At minimum, _apply_parameter_table's fallback branch should raise an informative error (naming the unresolved column and value) instead of letting a raw KeyError escape. Ideally, condition-table validation (check_condition_df or a new check) would catch this ahead of time, since the format doc ("Values for these condition parameters may be provided ... as IDs defined in the SBML model, the parameter table or both") doesn't obviously rule this out, and a validated problem shouldn't crash with an internal KeyError.
Whether actually resolving such references (evaluating the InitialAssignment using the current value of its dependencies) is worth supporting is a separate, larger question — this issue is about the crash/error-message gap either way.
🤖 This issue was generated with AI assistance (Claude Code).
- Lingua principale
- Python
- Stelle
- 18
- Fork
- 9
- Merge medio
- 1g 8h
- PR unite (30g)
- 21
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di PEtab-dev/libpetab-python
-
`petab1to2`: random column name for pre-existing `experimentId` columnForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
PEtab-dev/libpetab-python#568 ·
I maintainer di solito rispondono entro 1 giorno
-
`petab_files_1to2` keeps a stale model file when converting into a non-empty output directoryAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 73/100
PEtab-dev/libpetab-python#566 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
PEtab-dev/libpetab-python#549 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
PEtab-dev/libpetab-python#525 ·
I maintainer di solito rispondono entro 1 giorno
-
Deprecation warnings with pandas 3.1 (`inplace`, `read_csv(float_precision=...)`)Forse già presa @dweindl l’ha presa 3 giorni fa. Aperta
PEtab-dev/libpetab-python#570 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di PEtab-dev/libpetab-python
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
Arekkazu/sgpmp-backend#744 ·
I maintainer di solito rispondono entro 1 giorno
-
Review backlog (security): master-branch remote guard trusts unbound provenance package fieldApertaagent/reviewer
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
projectbluefin/utah-packages#634 ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement good first issue help wanted
Difficoltà 2/5 1-2 giorni Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
home-assistant/core#188613 ·
I maintainer di solito rispondono entro 1 giorno
-
WebsiteApertagood first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 91/100
TanbirRamim/open-source-radar#314 ·
I maintainer di solito rispondono entro 1 giorno