Skip to content

Add reparametrize_log and petab1to2(reparametrize=...) - #539

Draft
dweindl wants to merge 1 commit into
PEtab-dev:mainfrom
dweindl:petab1to2-reparametrize-log
Draft

dweindl wants to merge 1 commit into
PEtab-dev:mainfrom
dweindl:petab1to2-reparametrize-log

Conversation

@dweindl

@dweindl dweindl commented Oct 13, 2026

Copy link
Copy Markdown
Member

PEtab v2 has no parameterScale. Converting a v1 parameterScaleNormal(μ, σ) prior on a log10-scaled parameter to log-normal(μ ln10, σ ln10) keeps the prior distribution, but adds a Jacobian term to the v2 MAP objective, which moves the optimum by −σ² ln10 decades. No v2 prior over the unscaled parameter can preserve both the distribution and the optimum.

This adds petab.v2.reparametrize_log, which estimates log10_<id> (or log_<id>) instead of <id> and defines <id> = 10^log10_<id>, as recommended by the v2 spec for log-scale priors:

  • parameter table: log-transformed bounds and nominal value; priors from the priors argument, or derived from log-normal, log-laplace and log-uniform priors (other x-space priors raise)
  • SBML model: new parameter log10_<id> and assignment rule <id> = 10^log10_<id>
  • observable/noise formulas and condition target values: <id> → 10^log10_<id>
  • measurement overrides: replaced by the new IDs, numeric overrides are log-transformed, and the placeholder ph is replaced by 10^ph in the formulas

petab1to2 and petab_files_1to2 get a reparametrize argument:

  • "none" (default): current behaviour, now with a warning for converted parameterScaleNormal/Laplace priors
  • "priors": log-scaled parameters with parameterScale* priors
  • "all": all estimated log-scaled parameters without x-space priors; this also preserves the v1 default prior (uniform on parameter scale)

Log-scaled parameters sharing a placeholder with selected parameters are added. With "all", parameters without parameter-scale priors are skipped (with a warning) if their placeholder can't be log-transformed (e.g., Bachmann has 0 offsets).

Also fixes ConditionTable.to_df, which wrote non-numeric target values in sympy syntax (**) that can't be parsed back as PEtab math.

Checked on the benchmark collection: all 35 problems convert and pass v2 linting with "all"; with "priors", 44 parameters are reparametrized in Bachmann, Isensee, Raimundez and Schwen. Objective equivalence with a simulator is not checked here (to be done in AMICI / the benchmark repo).

Open points: lowerBound <= 0 currently raises (would be -inf on log scale); the old→new ID map is not exposed by petab1to2; default stays "none" until Benchmarking-Initiative/Benchmark-Models-PEtab#333 is decided.

References Benchmarking-Initiative/Benchmark-Models-PEtab#333

🤖 Generated with Claude Code

PEtab v2 has no `parameterScale`. Converting a v1 `parameterScaleNormal`
prior on a log-scaled parameter to `log-normal` keeps the prior
distribution, but adds a Jacobian term to the MAP objective and moves
the optimum. No v2 prior over the unscaled parameter can preserve both.

Add `petab.v2.reparametrize_log`, which estimates `log10_<id>` (or
`log_<id>`) instead of `<id>` and defines `<id> = 10^log10_<id>`:

* parameter table: log-transformed bounds and nominal value; priors
  are taken from the `priors` argument or derived from `log-normal`,
  `log-laplace` and `log-uniform` priors
* SBML model: new parameter and assignment rule for model parameters
* observable/noise formulas and condition target values: substitution
* measurement overrides: replaced by the new IDs, numbers are
  log-transformed, and the placeholder is exponentiated in the formula

`petab1to2` and `petab_files_1to2` get a `reparametrize` argument:
`"none"` (default, current behaviour), `"priors"` (log-scaled
parameters with `parameterScale*` priors) or `"all"` (all estimated
log-scaled parameters without priors on linear scale). Log-scaled
parameters that share a placeholder with selected parameters are added.
With `"all"`, parameters without parameter-scale priors are skipped if
their placeholder can't be log-transformed. With `"none"`, a warning
points to the new option.

Also fix `ConditionTable.to_df`, which wrote non-numeric target values
in sympy syntax (e.g., `**`) that cannot be parsed as PEtab math.

References
Benchmarking-Initiative/Benchmark-Models-PEtab#333

Generated with AI assistance.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dweindl dweindl self-assigned this Oct 13, 2026
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.49180% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.88%. Comparing base (e46ef71) to head (2f22c43).

Files with missing lines Patch % Lines
petab/v2/reparametrize.py 94.96% 4 Missing and 4 partials ⚠️
petab/v2/petab1to2.py 96.42% 1 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #539      +/-   ##
==========================================
+ Coverage   77.16%   77.88%   +0.71%     
==========================================
  Files          67       68       +1     
  Lines        7568     7809     +241     
  Branches     1349     1415      +66     
==========================================
+ Hits         5840     6082     +242     
+ Misses       1242     1239       -3     
- Partials      486      488       +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants