Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,39 @@
# PEtab changelog

## 0.10 series

### 0.10.0 (unreleased)

**Breaking changes**
* Removed the deprecated top-level aliases for `petab.v1` (deprecated since
0.4.0). Accessing `petab.<name>` or importing `petab.<module>` for anything
other than `petab.v1`, `petab.v2`, `petab.ENV_NUM_THREADS` and
`petab.__version__` now raises `AttributeError` / `ModuleNotFoundError`.
Use `petab.v1.<name>` instead, e.g., `import petab.v1 as petab`.
`import petab` no longer imports `petab.v1`.
(by @dweindl in https://github.com/PEtab-dev/libpetab-python/pull/538)

**Fixes**
* `get_model_for_condition` no longer turns rate-rule targets that are
overridden in the condition table into constants
(by @dweindl in https://github.com/PEtab-dev/libpetab-python/pull/520)
* Raise a clear error for a PEtab YAML file with an empty `problems` section
(by @dweindl in https://github.com/PEtab-dev/libpetab-python/pull/521)
* Several fixes to the v1-to-v2 converter (`petab1to2`): keep
pre-equilibration for conditions that set nothing, order placeholders by
index instead of lexicographically, rescale noise and priors when
converting `log10` to `log`, and fix the conversion of `logNormal`,
`logLaplace` and `parameterScaleUniform` priors
(by @FFroehlich in
https://github.com/PEtab-dev/libpetab-python/pull/532,
https://github.com/PEtab-dev/libpetab-python/pull/533,
https://github.com/PEtab-dev/libpetab-python/pull/535, and
https://github.com/PEtab-dev/libpetab-python/pull/536)

**Features**
* `petab1to2` and `petab_files_1to2` can skip validation via `validate=False`
(by @FFroehlich in https://github.com/PEtab-dev/libpetab-python/pull/534)

## 0.9 series

### 0.9.0
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ be:
entrypoints to be available as a shell command from anywhere, called
`petablint`

- [petab.create_parameter_df](https://petab.readthedocs.io/projects/libpetab-python/en/latest/build/_autosummary/petab.parameters.html#petab.parameters.create_parameter_df)
- [petab.v1.create_parameter_df](https://petab.readthedocs.io/projects/libpetab-python/en/latest/build/_autosummary/petab.v1.parameters.html#petab.v1.parameters.create_parameter_df)
to create the parameter table, once you have set up the model,
condition table, observable table and measurement table

- [petab.create_combine_archive](https://petab.readthedocs.io/projects/libpetab-python/en/latest/build/_autosummary/petab.core.html#petab.core.create_combine_archive)
- [petab.v1.create_combine_archive](https://petab.readthedocs.io/projects/libpetab-python/en/latest/build/_autosummary/petab.v1.core.html#petab.v1.core.create_combine_archive)
to create a [COMBINE Archive](https://combinearchive.org/index/) from PEtab
files

Expand Down
8 changes: 4 additions & 4 deletions doc/example/example_visualization.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
"from pathlib import Path\n",
"\n",
"import matplotlib.pyplot as plt\n",
"from petab.visualize import plot_problem\n",
"\n",
"import petab\n",
"from petab import Problem\n",
"import petab.v1 as petab\n",
"from petab.v1 import Problem\n",
"from petab.v1.visualize import plot_problem\n",
"\n",
"example_dir_fujita = Path(\"example_Fujita\")\n",
"petab_yaml_fujita = example_dir_fujita / \"Fujita.yaml\"\n",
Expand Down Expand Up @@ -62,7 +62,7 @@
"source": [
"### Plotting measurements\n",
"\n",
"For the most basic visualization, we can use the [plot_problem()](https://petab.readthedocs.io/projects/libpetab-python/en/latest/build/_autosummary/petab.visualize.html#petab.visualize.plot_problem) function."
"For the most basic visualization, we can use the [plot_problem()](https://petab.readthedocs.io/projects/libpetab-python/en/latest/build/_autosummary/petab.v1.visualize.html#petab.v1.visualize.plot_problem) function."
]
},
{
Expand Down
69 changes: 6 additions & 63 deletions petab/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,72 +10,15 @@
"""

import importlib
import sys
from functools import partial
from pathlib import Path
from warnings import warn

from .version import __version__ # noqa: F401

ENV_NUM_THREADS = "PETAB_NUM_THREADS"
__all__ = ["ENV_NUM_THREADS"]


def __getattr__(name):
if attr := globals().get(name):
return attr
if name == "v1":
return importlib.import_module("petab.v1")
if name == "v2":
return importlib.import_module("petab.v2")
if name not in (
"__path__",
"__all__",
"__wrapped__",
# accessed under pytest
"_pytestfixturefunction",
"__test__",
"__bases__",
):
warn(
f"Accessing `petab.{name}` is deprecated and will be removed in "
f"the next major release. Please use `petab.v1.{name}` instead.",
DeprecationWarning,
stacklevel=3,
)
return getattr(importlib.import_module("petab.v1"), name)


def _v1getattr(name, module):
if name not in ("__path__", "__all__", "__wrapped__"):
warn(
f"Accessing `petab.{name}` is deprecated and will be removed in "
f"the next major release. Please use `petab.v1.{name}` instead.",
DeprecationWarning,
stacklevel=3,
)
try:
return module.__dict__[name]
except KeyError:
raise AttributeError(name) from None


# Create dummy modules for all old modules
v1_root = Path(__file__).resolve().parent / "v1"
v1_objects = [f.relative_to(v1_root) for f in v1_root.rglob("*")]
for v1_object in v1_objects:
if "__pycache__" in str(v1_object):
continue
if v1_object.suffix not in ["", ".py"]:
continue
if not (v1_root / v1_object).exists():
raise ValueError(v1_root / v1_object)
v1_object_parts = [*v1_object.parts[:-1], v1_object.stem]
module_name = ".".join(["petab", *v1_object_parts])

try:
real_module = importlib.import_module(
f"petab.v1.{'.'.join(v1_object_parts)}"
)
real_module.__getattr__ = partial(_v1getattr, module=real_module)
sys.modules[module_name] = real_module
except ModuleNotFoundError:
pass
"""Lazily import the `petab.v1` and `petab.v2` subpackages."""
if name in ("v1", "v2"):
return importlib.import_module(f"petab.{name}")
raise AttributeError(f"module 'petab' has no attribute '{name}'")
2 changes: 1 addition & 1 deletion petab/v1/composite_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class CompositeProblem:

Attributes:
problems:
List of :py:class:`petab.Problem` s
List of :py:class:`petab.v1.Problem` s
parameter_df:
PEtab parameter DataFrame
"""
Expand Down
6 changes: 3 additions & 3 deletions petab/v1/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def get_hyperparameter_replacement_id(


def get_flattened_id_mappings(
petab_problem: "petab.problem.Problem",
petab_problem: "petab.v1.problem.Problem",
) -> dict[str, dict[str, str]]:
"""Get mapping from unflattened to flattened observable IDs.

Expand Down Expand Up @@ -240,7 +240,7 @@ def get_flattened_id_mappings(


def flatten_timepoint_specific_output_overrides(
petab_problem: "petab.problem.Problem",
petab_problem: "petab.v1.problem.Problem",
) -> None:
"""Flatten timepoint-specific output parameter overrides.

Expand Down Expand Up @@ -322,7 +322,7 @@ def flatten_timepoint_specific_output_overrides(

def unflatten_simulation_df(
simulation_df: pd.DataFrame,
petab_problem: "petab.problem.Problem",
petab_problem: "petab.v1.problem.Problem",
) -> pd.DataFrame:
"""Unflatten simulations from a flattened PEtab problem.

Expand Down
2 changes: 1 addition & 1 deletion petab/v1/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -1172,7 +1172,7 @@ def assert_measurements_numeric(
)
if not all_measurements_are_numeric:
raise AssertionError(
"Some values in the `petab.C.MEASUREMENT` column of the PEtab "
"Some values in the `petab.v1.C.MEASUREMENT` column of the PEtab "
"measurements table are not numeric."
)

Expand Down
2 changes: 1 addition & 1 deletion petab/v1/math/SympyVisitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class MathVisitorSympy(PetabMathExprParserVisitor):
Converts PEtab math expressions to sympy expressions.

Most users will not need to interact with this class directly, but rather
use :func:`petab.math.sympify_petab`.
use :func:`petab.v1.math.sympify_petab`.

Evaluation of any sub-expressions currently relies on sympy's defaults.

Expand Down
17 changes: 7 additions & 10 deletions petab/v1/parameter_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import numpy as np
import pandas as pd

from .. import ENV_NUM_THREADS
from . import (
core,
lint,
Expand All @@ -25,10 +26,6 @@
from .mapping import resolve_mapping
from .models import Model

# FIXME import from petab.ENV_NUM_THREADS
ENV_NUM_THREADS = "PETAB_NUM_THREADS"


logger = logging.getLogger(__name__)
__all__ = [
"ParMappingDict",
Expand Down Expand Up @@ -89,7 +86,7 @@ def get_optimization_to_simulation_parameter_mapping(
The model.
simulation_conditions:
Table of simulation conditions as created by
``petab.get_simulation_conditions``.
``petab.v1.get_simulation_conditions``.
warn_unmapped:
If ``True``, log warning regarding unmapped parameters
scaled_parameters:
Expand Down Expand Up @@ -124,7 +121,7 @@ def get_optimization_to_simulation_parameter_mapping(
if sbml_model:
warnings.warn(
"Passing a model via the `sbml_model` argument is "
"deprecated, use `model=petab.models.sbml_model."
"deprecated, use `model=petab.v1.models.sbml_model."
"SbmlModel(...)` instead.",
DeprecationWarning,
stacklevel=2,
Expand Down Expand Up @@ -347,7 +344,7 @@ def get_parameter_mapping_for_condition(
The model.
simulation_parameters:
Model simulation parameter IDs mapped to parameter values (output
of ``petab.sbml.get_model_parameters(.., with_values=True)``).
of ``petab.v1.sbml.get_model_parameters(.., with_values=True)``).
Optional, saves time if precomputed.
warn_unmapped:
If ``True``, log warning regarding unmapped parameters
Expand All @@ -374,7 +371,7 @@ def get_parameter_mapping_for_condition(
if sbml_model:
warnings.warn(
"Passing a model via the `sbml_model` argument is "
"deprecated, use `model=petab.models.sbml_model."
"deprecated, use `model=petab.v1.models.sbml_model."
"SbmlModel(...)` instead.",
DeprecationWarning,
stacklevel=2,
Expand Down Expand Up @@ -778,10 +775,10 @@ def merge_preeq_and_sim_pars(
Parameters:
parameter_mappings:
As returned by
:py:func:`petab.get_optimization_to_simulation_parameter_mapping`.
:py:func:`petab.v1.get_optimization_to_simulation_parameter_mapping`.
scale_mappings:
As returned by
:py:func:`petab.get_optimization_to_simulation_parameter_mapping`.
:py:func:`petab.v1.get_optimization_to_simulation_parameter_mapping`.

Returns:
The parameter and scale simulation mappings, modified and checked.
Expand Down
2 changes: 1 addition & 1 deletion petab/v1/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def create_parameter_df(
if sbml_model:
warnings.warn(
"Passing a model via the `sbml_model` argument is "
"deprecated, use `model=petab.models.sbml_model."
"deprecated, use `model=petab.v1.models.sbml_model."
"SbmlModel(...)` instead.",
DeprecationWarning,
stacklevel=2,
Expand Down
Loading
Loading