Skip to content

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

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

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.

petab1to2 and petab_files_1to2 get a reparametrize argument, which uses petab.v2.reparametrize_log (#560) to estimate log10_<id> (or log_<id>) instead of <id>:

  • "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 priors on linear scale (i.e., without logNormal, uniform, ...); 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) get lowerBound = -inf on log scale (PEtab-dev/PEtab#682). They are skipped with a warning if their prior on log scale would be an improper uniform prior, i.e., the v1 default prior if other estimated parameters have priors.

Also fixes petab1to2 adding default uniform priors to non-estimated parameters, and to all parameters if the v1 parameter table has an objectivePriorType column, but no estimated parameter has a prior. Priors of non-estimated parameters are converted as before.

Non-estimated parameters are only reparametrized if they share a placeholder with selected parameters. A nominal value of 0 then becomes -inf, assuming PEtab-dev/PEtab#685 is accepted. Their priors are dropped, since they are ignored anyway (PEtab-dev/PEtab#686).

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.

Checked with AMICI (v1 importer vs. v2 PetabImporter, forward sensitivities) on 30 benchmark problems converted with "all" (5 large ones excluded), at the nominal parameters and at a shifted point: log-likelihoods agree to a relative difference of ≤ 2e-8, and gradients agree to ≤ 4e-4 of the largest gradient entry. The remaining deviations are due to integration tolerances. Log-priors are identical for Isensee and Raimundez. For Bachmann, they differ by a constant (6 log-scaled parameters with the v1 default prior that can't be reparametrized become linear uniform), so the MAP is preserved.

The default is "none" for now, to keep petab1to2 uninvasive, i.e., to not change the parametrization unless requested. Open to change.

References Benchmarking-Initiative/Benchmark-Models-PEtab#333, PEtab-dev/PEtab#680, PEtab-dev/PEtab#683

🤖 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 97.11538% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.12%. Comparing base (68be6d1) to head (54362c3).

Files with missing lines Patch % Lines
petab/v2/petab1to2.py 97.11% 1 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #539      +/-   ##
==========================================
+ Coverage   78.85%   79.12%   +0.26%     
==========================================
  Files          69       69              
  Lines        8043     8142      +99     
  Branches     1445     1475      +30     
==========================================
+ Hits         6342     6442     +100     
+ Misses       1214     1213       -1     
  Partials      487      487              

☔ 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.

@dweindl
dweindl force-pushed the petab1to2-reparametrize-log branch from 2f22c43 to bdad27e Compare October 15, 2026 12:00
dweindl added a commit to PEtab-dev/PEtab that referenced this pull request Oct 19, 2026
Add a non-normative page "Upgrading from PEtab v1" to the v2
documentation. It lists the structural changes, explains the numerical
consequences of the removal of `parameterScale`, describes how to
reparametrize log-scaled parameters (`log10_k` with `k = 10^log10_k`),
the `reparametrize` option of `petab1to2`, the other changes affecting
objective values (log10 observables, truncated priors, default prior),
and how to verify a conversion.

References #680.
The `petab1to2` section describes PEtab-dev/libpetab-python#539.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@dweindl
dweindl force-pushed the petab1to2-reparametrize-log branch from 4be4d4a to 594265d Compare October 19, 2026 14:44
@dweindl dweindl changed the title Add reparametrize_log and petab1to2(reparametrize=...) Add petab1to2(reparametrize=...) Oct 19, 2026
@dweindl
dweindl force-pushed the petab1to2-reparametrize-log branch 5 times, most recently from 2ce25b5 to 2b7cb7c Compare October 21, 2026 13:16
dweindl added a commit that referenced this pull request Oct 21, 2026
PEtab v2 has no `parameterScale`. To estimate a parameter `<id>` on log
scale, or to specify a prior for `log10(<id>)`, the v2 spec recommends
replacing `<id>` by a new parameter `log10_<id>` with `<id> =
10^log10_<id>`.

This adds `petab.v2.reparametrize_log(problem, parameter_ids, ...)`,
which does this for the given parameters on a copy of the problem and
returns the copy and the mapping of old to new parameter IDs:

* parameter table: log-transformed bounds (dropped for non-estimated
parameters) and nominal value; priors from the `priors` argument, or
derived from `log-normal`, `log-laplace` and `log-uniform` priors on
`<id>` (other priors on `<id>` raise; priors of non-estimated parameters
raise `NotImplementedError` unless dropped via `priors={<id>: None}`)
* 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

A lower bound of `0` becomes `-inf`, following PEtab-dev/PEtab#682. If
other estimated parameters have priors, such a parameter needs an
explicit prior, since the default `uniform(lb, ub)` would be improper;
otherwise, a `ValueError` is raised. A nominal value of `0` becomes
`-inf`, assuming PEtab-dev/PEtab#685 is accepted, e.g., for parameters
fixed at `0`.

Problems with required extensions are not supported.

Base e (`log_<id>`) is supported as well. The procedure follows the one
described in the proposed v1→v2 migration guide (PEtab-dev/PEtab#680).

Split off from #539, which uses this in `petab1to2(reparametrize=...)`
to preserve v1 parameter-scale priors.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@dweindl
dweindl force-pushed the petab1to2-reparametrize-log branch 3 times, most recently from 50322ae to a458869 Compare October 21, 2026 14:19
dweindl added a commit to PEtab-dev/PEtab that referenced this pull request Oct 21, 2026
Add a non-normative page "Upgrading from PEtab v1" to the v2
documentation. It lists the structural changes, explains the numerical
consequences of the removal of `parameterScale`, describes how to
reparametrize log-scaled parameters (`log10_k` with `k = 10^log10_k`),
the `reparametrize` option of `petab1to2`, the other changes affecting
objective values (log10 observables, truncated priors, default prior),
and how to verify a conversion.

References #680.
The `petab1to2` section describes PEtab-dev/libpetab-python#539.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
PEtab v2 has no `parameterScale`. Converting a v1 `parameterScaleNormal`
prior on a log10-scaled parameter to `log-normal` keeps the prior
distribution, but changes the maximum a posteriori estimate.

`petab1to2` and `petab_files_1to2` get a `reparametrize` argument to
estimate log-scaled parameters as `log10_<id>`/`log_<id>` using
`reparametrize_log`, which preserves the objective function:

* `"none"` (default): don't reparametrize; warn about converted
  `parameterScale*` priors
* `"priors"`: parameters with `parameterScale*` priors
* `"all"`: all estimated log-scaled parameters without priors on linear
  scale; this also preserves the v1 default prior

Log-scaled parameters that share a placeholder with selected parameters
are added; for non-estimated ones, a nominal value of 0 becomes -inf,
and their (ignored) priors are dropped. With `"all"`, parameters without
parameter-scale priors are skipped if their placeholder can't be
log-transformed. Parameters with a lower bound of 0 get a lower bound of
-inf on log scale; they are skipped if their prior on log scale would be
an improper uniform prior.

The benchmark collection conversion test now also runs with `"all"`.

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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dweindl
dweindl force-pushed the petab1to2-reparametrize-log branch from a458869 to 54362c3 Compare October 21, 2026 14:31
@dweindl
dweindl marked this pull request as ready for review October 21, 2026 16:57
@dweindl
dweindl requested a review from a team as a code owner October 21, 2026 16:57
dweindl added a commit to PEtab-dev/PEtab that referenced this pull request Oct 21, 2026
Add a non-normative page "Upgrading from PEtab v1" to the v2
documentation. It lists the structural changes, explains the numerical
consequences of the removal of `parameterScale`, describes how to
reparametrize log-scaled parameters (`log10_k` with `k = 10^log10_k`),
the `reparametrize` option of `petab1to2`, the other changes affecting
objective values (log10 observables, truncated priors, default prior),
and how to verify a conversion.

References #680.
The `petab1to2` section describes PEtab-dev/libpetab-python#539.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
dweindl added a commit to PEtab-dev/PEtab that referenced this pull request Oct 21, 2026
Add a non-normative page "Upgrading from PEtab v1" to the v2
documentation. It lists the structural changes, explains the numerical
consequences of the removal of `parameterScale`, describes how to
reparametrize log-scaled parameters (`log10_k` with `k = 10^log10_k`),
the `reparametrize` option of `petab1to2`, the other changes affecting
objective values (log10 observables, truncated priors, default prior),
and how to verify a conversion.

References #680.
The `petab1to2` section describes PEtab-dev/libpetab-python#539.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
dweindl added a commit to PEtab-dev/PEtab that referenced this pull request Oct 21, 2026
Add a non-normative page "Upgrading from PEtab v1" to the v2
documentation. It lists the structural changes, explains the numerical
consequences of the removal of `parameterScale`, describes how to
reparametrize log-scaled parameters (`log10_k` with `k = 10^log10_k`),
the `reparametrize` option of `petab1to2`, the other changes affecting
objective values (log10 observables, truncated priors, default prior),
and how to verify a conversion.

References #680.
The `petab1to2` section describes PEtab-dev/libpetab-python#539.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
dweindl added a commit to PEtab-dev/PEtab that referenced this pull request Oct 21, 2026
Add a non-normative page "Upgrading from PEtab v1" to the v2
documentation. It lists the structural changes, explains the numerical
consequences of the removal of `parameterScale`, describes how to
reparametrize log-scaled parameters (`log10_k` with `k = 10^log10_k`),
the `reparametrize` option of `petab1to2`, the other changes affecting
objective values (log10 observables, truncated priors, default prior),
and how to verify a conversion.

References #680.
The `petab1to2` section describes PEtab-dev/libpetab-python#539.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
dweindl added a commit to PEtab-dev/PEtab that referenced this pull request Oct 21, 2026
Add a non-normative page "Upgrading from PEtab v1" to the v2
documentation. It lists the structural changes, explains the numerical
consequences of the removal of `parameterScale`, describes how to
reparametrize log-scaled parameters (`log10_k` with `k = 10^log10_k`),
the `reparametrize` option of `petab1to2`, the other changes affecting
objective values (log10 observables, truncated priors, default prior),
and how to verify a conversion.

References #680.
The `petab1to2` section describes PEtab-dev/libpetab-python#539.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
dweindl added a commit to PEtab-dev/PEtab that referenced this pull request Oct 21, 2026
Add a non-normative page "Upgrading from PEtab v1" to the v2
documentation. It lists the structural changes, explains the numerical
consequences of the removal of `parameterScale`, describes how to
reparametrize log-scaled parameters (`log10_k` with `k = 10^log10_k`),
the `reparametrize` option of `petab1to2`, the other changes affecting
objective values (log10 observables, truncated priors, default prior),
and how to verify a conversion.

References #680.
The `petab1to2` section describes PEtab-dev/libpetab-python#539.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
dweindl added a commit to PEtab-dev/PEtab that referenced this pull request Oct 21, 2026
Add a non-normative page "Upgrading from PEtab v1" to the v2
documentation. It lists the structural changes, explains the numerical
consequences of the removal of `parameterScale`, describes how to
reparametrize log-scaled parameters (`log10_k` with `k = 10^log10_k`),
the `reparametrize` option of `petab1to2`, the other changes affecting
objective values (log10 observables, truncated priors, default prior),
and how to verify a conversion.

References #680.
The `petab1to2` section describes PEtab-dev/libpetab-python#539.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
dweindl added a commit to PEtab-dev/PEtab that referenced this pull request Oct 21, 2026
Add a non-normative page "Upgrading from PEtab v1" to the v2
documentation. It lists the structural changes, explains the numerical
consequences of the removal of `parameterScale`, describes how to
reparametrize log-scaled parameters (`log10_k` with `k = 10^log10_k`),
the `reparametrize` option of `petab1to2`, the other changes affecting
objective values (log10 observables, truncated priors, default prior),
and how to verify a conversion.

References #680.
The `petab1to2` section describes PEtab-dev/libpetab-python#539.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
dweindl added a commit to PEtab-dev/PEtab that referenced this pull request Oct 21, 2026
Add a non-normative page "Upgrading from PEtab v1" to the v2
documentation. It lists the structural changes, explains the numerical
consequences of the removal of `parameterScale`, describes how to
reparametrize log-scaled parameters (`log10_k` with `k = 10^log10_k`),
the `reparametrize` option of `petab1to2`, the other changes affecting
objective values (log10 observables, truncated priors, default prior),
and how to verify a conversion.

References #680.
The `petab1to2` section describes PEtab-dev/libpetab-python#539.

Co-Authored-By: Claude Fable 5.1 <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