Skip to content

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

Merged
dweindl merged 2 commits into
PEtab-dev:mainfrom
dweindl:petab1to2-reparametrize-log
Oct 26, 2026
Merged

dweindl merged 2 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.

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. Such placeholders are substituted by 10^placeholder, so numeric overrides are log-transformed. Since overrides must be finite, 0 overrides are replaced by a new fixed parameter negative_infinity with nominal value -inf (assuming PEtab-dev/PEtab#687 is accepted). With "all", parameters without parameter-scale priors are skipped (with a warning) if their placeholder can't be log-transformed, i.e., if it is also overridden by negative numbers or by parameters that are not reparametrized. 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 / PEtab-dev/PEtab#687 is accepted. Their parameterScale* priors are converted to log scale as well, unless they depend on missing bounds (then they are dropped with a warning).

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 ≤ 2e-5 of the largest gradient entry, except for Crauste at the nominal parameters (4e-4 at rtol/atol 1e-12/1e-16, decreasing with tighter tolerances; 5e-14 at the shifted point). The remaining deviations are due to integration tolerances. Log-priors are identical for Bachmann, Isensee and Raimundez. (Before the 0 overrides were supported, 6 log-scaled Bachmann parameters couldn't be reparametrized, and their v1 default prior became a linear uniform, which preserves the MAP, but changes the log-prior by a constant.)

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.56098% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.47%. Comparing base (ce80233) to head (b7133f4).

Files with missing lines Patch % Lines
petab/v2/petab1to2.py 97.34% 1 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #539      +/-   ##
==========================================
+ Coverage   79.06%   79.47%   +0.40%     
==========================================
  Files          70       70              
  Lines        8164     8278     +114     
  Branches     1463     1498      +35     
==========================================
+ Hits         6455     6579     +124     
+ Misses       1220     1209      -11     
- Partials      489      490       +1     

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

@dilpath dilpath left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gradients agree to ≤ 4e-4 of the largest gradient entry

This error is potentially too large?

if their placeholder can't be log-transformed (e.g., Bachmann has 0 offsets)

What is the issue here? So, exp(log_offset) does not work for some reason?

For Bachmann, they differ by a constant

Will mean that e.g. a single metadata file in the benchmark collection is insufficient (...unless the metadata file has version-specific information).

Comment thread petab/v2/petab1to2.py
Comment thread petab/v2/petab1to2.py
Comment thread petab/v2/petab1to2.py Outdated
@dweindl
dweindl force-pushed the petab1to2-reparametrize-log branch from 54362c3 to e5ad8e3 Compare October 26, 2026 11:24
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 priors are converted to log scale as well. 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.

Also, `petab1to2` no longer adds default `uniform` priors to
non-estimated parameters, or if no estimated parameter has a 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 e5ad8e3 to 652da5a Compare October 26, 2026 11:27
@dweindl

dweindl commented Oct 26, 2026

Copy link
Copy Markdown
Member Author

gradients agree to ≤ 4e-4 of the largest gradient entry

This error is potentially too large?

Yes, it is large, but this is only Crauste and it seems to be about integration errors at those specific nominal parameters, not conversion issues. At the shifted point, the deviation is several orders of magnitude smaller.

if their placeholder can't be log-transformed (e.g., Bachmann has 0 offsets)

What is the issue here? So, exp(log_offset) does not work for some reason?

The problem occurs if we have a observableFormula with a placeholder that is sometimes a log-scaled parameter, and sometimes a non-positive number. In this case, we'd have to split the observable into one version with base^placeholder, and one with just placeholder. Feasible, but not implemented here.

For Bachmann, they differ by a constant

Will mean that e.g. a single metadata file in the benchmark collection is insufficient (...unless the metadata file has version-specific information).

This is due to the missing observable splitting. This could be built on top, but I am not sure it's worth it.

Independently of that, we might have the version-specific-information problem also in the case truncation of the prior by the bounds. Depends on how we handle that for v1, where this was unspecified. But that's a discussion for https://github.com/Benchmarking-Initiative/Benchmark-Models-PEtab.

@dilpath

dilpath commented Oct 26, 2026

Copy link
Copy Markdown
Member

gradients agree to ≤ 4e-4 of the largest gradient entry

This error is potentially too large?

Yes, it is large, but this is only Crauste and it seems to be about integration errors at those specific nominal parameters, not conversion issues. At the shifted point, the deviation is several orders of magnitude smaller.

👍

if their placeholder can't be log-transformed (e.g., Bachmann has 0 offsets)

What is the issue here? So, exp(log_offset) does not work for some reason?

The problem occurs if we have a observableFormula with a placeholder that is sometimes a log-scaled parameter, and sometimes a non-positive number. In this case, we'd have to split the observable into one version with base^placeholder, and one with just placeholder. Feasible, but not implemented here.

Why is 0 an issue? Since for v2 we define log(0)=-inf -- it's not explicitly there but I would therefore assume that exp(-inf)=0 -- so splitting would not be required?

For Bachmann, they differ by a constant

Will mean that e.g. a single metadata file in the benchmark collection is insufficient (...unless the metadata file has version-specific information).

This is due to the missing observable splitting. This could be built on top, but I am not sure it's worth it.

Independently of that, we might have the version-specific-information problem also in the case truncation of the prior by the bounds. Depends on how we handle that for v1, where this was unspecified. But that's a discussion for https://github.com/Benchmarking-Initiative/Benchmark-Models-PEtab.

Yes agreed, fine for me, was just pointing out.

@dweindl

dweindl commented Oct 26, 2026 •

Copy link
Copy Markdown
Member Author

The problem occurs if we have a observableFormula with a placeholder that is sometimes a log-scaled parameter, and sometimes a non-positive number. In this case, we'd have to split the observable into one version with base^placeholder, and one with just placeholder. Feasible, but not implemented here.

Why is 0 an issue? Since for v2 we define log(0)=-inf -- it's not explicitly there but I would therefore assume that exp(-inf)=0 -- so splitting would not be required?

Same issue as PEtab-dev/PEtab#687 -- so far, placeholder overrides are restricted to finite values or parameters. Intentionally or not, not sure. I guess there could be use cases. Maybe drop a comment there if you think we should extend that to observableParameters and noiseParameters.

With PEtab-dev/PEtab#687 pretty much accepted, this can be circumvented by adding a fixed parameter negative_infinity = -inf. This doesn't address the negative values, but that seems to be an even more special use case. I can implement that.

Placeholders that are overridden by reparametrized parameters are
log-transformed, which requires all their overrides to be on log scale.
`0` overrides were rejected so far, since `log(0) = -inf` is not a valid
override value. They are now replaced by a new non-estimated parameter
`negative_infinity` with nominal value `-inf` (assuming
PEtab-dev/PEtab#687 is accepted). Only negative overrides still prevent
the transformation.

With `petab1to2(reparametrize="all")`, this reparametrizes all log-scaled
parameters of Bachmann_MSB2011, so that the v1 and v2 log-priors agree.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dweindl
dweindl merged commit 8e5a3bf into PEtab-dev:main Oct 26, 2026
7 checks passed
@dweindl
dweindl deleted the petab1to2-reparametrize-log branch October 26, 2026 13:53
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.

3 participants