Skip to content

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

Draft
dweindl wants to merge 6 commits into
PEtab-dev:mainfrom
dweindl:petab1to2-reparametrize-log
Draft

dweindl wants to merge 6 commits 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 initial assignment <id> = 10^log10_<id> (replacing any existing one; <id> stays constant=true)
  • 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 parameterScale* 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). Parameters with lowerBound = 0 (allowed in v1 for log-scaled parameters with an initialization prior) are skipped with a warning, as their lower bound on log scale would be -inf.

Checked on the benchmark collection: all 35 problems convert and pass v2 linting with "all" (now also tested in CI); 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 point: default stays "none" until Benchmarking-Initiative/Benchmark-Models-PEtab#333 is decided.

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

🤖 Generated with Claude Code

@dweindl dweindl self-assigned this Oct 13, 2026
@codecov-commenter

codecov-commenter commented Oct 13, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.25468% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.85%. Comparing base (5fb4066) to head (4be4d4a).

Files with missing lines Patch % Lines
petab/v2/reparametrize.py 95.37% 4 Missing and 4 partials ⚠️
petab/v2/petab1to2.py 97.84% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #539      +/-   ##
==========================================
+ Coverage   77.98%   78.85%   +0.87%     
==========================================
  Files          68       69       +1     
  Lines        7791     8055     +264     
  Branches     1390     1461      +71     
==========================================
+ Hits         6076     6352     +276     
+ Misses       1227     1213      -14     
- Partials      488      490       +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.

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.

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

Generated with AI assistance.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dweindl
dweindl force-pushed the petab1to2-reparametrize-log branch from 2f22c43 to bdad27e Compare October 15, 2026 12:00
dweindl and others added 2 commits October 15, 2026 14:47
Report all affected placeholders at once, by ID, together with the
reparametrized parameters overriding them. Separate overrides by
parameters that are not reparametrized (which can be fixed by including
them in `parameter_ids`) from non-positive numbers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`math.log(x) / math.log(10)` is inexact for powers of 10 (e.g.
`2.9999999999999996` for 1000), which gave bounds and log-uniform prior
parameters that differ from those computed with `log10` elsewhere.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dweindl and others added 3 commits October 15, 2026 21:16
In `reparametrize_log`, define `p = base^q` by an initial assignment
instead of an assignment rule. `q` is a parameter table parameter and
therefore constant during the simulation, so `p` keeps its
`constant=true` attribute and stays a constant entity in the sense of
the PEtab v2 spec (e.g., it can still be a condition target). An
existing initial assignment for `p` is replaced.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PEtab v1 allows a lower bound of 0 for log-scaled parameters if an
initialization prior is given. On log scale, this would be `-inf`, for
which `reparametrize_log` raises, and neither the v1 default prior nor
`parameterScaleUniform` would be proper. Instead of failing the whole
conversion, keep such parameters on linear scale and warn.

Generated with AI assistance.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* `petab1to2`: also warn about converted `parameterScaleUniform` priors
  with `reparametrize="none"`, which change the maximum a posteriori
  estimate as well
* `petab1to2`: point to `reparametrize="none"` if reparametrization
  fails, and drop the `parameter_ids` hint from the
  `reparametrize_log` error, which doesn't apply there
* `petab1to2`: warn once about parameters skipped because of
  placeholders, not once per base
* `reparametrize_log`: ignore non-positive bounds of non-estimated
  parameters, and raise `NotImplementedError` for SBML models before
  L2V2, which have no initial assignments
* tests: likelihood after reparametrizing overrides with both bases,
  and the benchmark collection with `reparametrize="all"`

Generated with AI assistance.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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