Condition-table override referencing a parameter with a non-numeric InitialAssignment crashes with an opaque KeyError
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 72/100
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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).
- Lenguaje dominante
- Python
- Estrellas
- 18
- Forks
- 9
- Merge medio
- 1 d 8 h
- PR fusionados (30 d)
- 21
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de PEtab-dev/libpetab-python
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
PEtab-dev/libpetab-python#568 ·
Los mantenedores suelen responder en 1 día
-
`petab_files_1to2` keeps a stale model file when converting into a non-empty output directoryAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 73/100
PEtab-dev/libpetab-python#566 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
PEtab-dev/libpetab-python#549 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
PEtab-dev/libpetab-python#525 ·
Los mantenedores suelen responder en 1 día
-
Deprecation warnings with pandas 3.1 (`inplace`, `read_csv(float_precision=...)`)Posiblemente ocupada @dweindl la tomó hace 1 día. Abierto
PEtab-dev/libpetab-python#570 · 1 asignado ·
Los mantenedores suelen responder en 1 día
Todos los issues de PEtab-dev/libpetab-python
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
Los mantenedores suelen responder en 1 día
-
enhancement good first issue
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
iceboundrock/AutoForge#304 ·
Los mantenedores suelen responder en 1 día
-
enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
fossasia/visdom-dev#77 ·
Los mantenedores suelen responder en 4 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
aws-cloudformation/cfn-lint#4890 ·
Los mantenedores suelen responder en 2 días