Condition-table override referencing a parameter with a non-numeric InitialAssignment crashes with an opaque KeyError
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
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.
索引モデルが issue の本文から書いたものです。
説明
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).
- 主要言語
- Python
- スター
- 18
- フォーク
- 9
- 平均マージ
- 1日 21時間
- マージ済み PR(30日)
- 25
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
PEtab-dev/libpetab-python のほかの issue
-
`petab1to2`: random column name for pre-existing `experimentId` column対応中かも @dweindl が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
PEtab-dev/libpetab-python#568 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 73/100
PEtab-dev/libpetab-python#566 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
PEtab-dev/libpetab-python#549 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
PEtab-dev/libpetab-python#525 ·
メンテナーはふだん 1 日以内に返信
-
`petablint` fails for PEtab v2 problems with only warnings対応中かも @dweindl が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 35/100
PEtab-dev/libpetab-python#567 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
PEtab-dev/libpetab-python の issue をすべて見る
似ている issue
-
The changelog workflow excludes otelbot but not dependabot, so every Dependabot pull request fails the changelog check対応中かも @ocelotl が今日担当しました。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 82/100
open-telemetry/opentelemetry-python#5825 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
cuga-project/cuga-agent#1020 ·
メンテナーはふだん 2 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 70/100
microsoft/playwright#43640 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
stac-utils/stac-fastapi-elasticsearch-opensearch#965 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
メンテナーはふだん 1 日以内に返信