From 96d16fc83b730b7f2f2f2dbfd2a34fe76887138d Mon Sep 17 00:00:00 2001 From: Daniel Weindl Date: Mon, 1 Jul 2024 15:33:34 +0200 Subject: [PATCH 1/5] Remove obsolute flake8 files (#296) No longer in use. --- .flake8 | 19 ------------------- run_flake8.sh | 3 --- 2 files changed, 22 deletions(-) delete mode 100644 .flake8 delete mode 100755 run_flake8.sh diff --git a/.flake8 b/.flake8 deleted file mode 100644 index 50513b8a..00000000 --- a/.flake8 +++ /dev/null @@ -1,19 +0,0 @@ -[flake8] - -extend-ignore = - # whitespace before ":", conflicts with black - E203 - F403 - F405 - # line too long, conflicts with black in rare cases - E501 -exclude = - build, - dist, - doc, - env, - venv, - example, - tmp, - _*, - .tox, diff --git a/run_flake8.sh b/run_flake8.sh deleted file mode 100755 index ae7140fb..00000000 --- a/run_flake8.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -python3 -m flake8 --exclude=build,doc,example,tmp --extend-ignore=F403,F405 From c9074f73e2b8332787f99040bebf4039ab09447a Mon Sep 17 00:00:00 2001 From: Dilan Pathirana <59329744+dilpath@users.noreply.github.com> Date: Mon, 1 Jul 2024 23:02:47 +0200 Subject: [PATCH 2/5] Implement `petab.*` deprecation with `__getattr__` (#297) Co-authored-by: Daniel Weindl Co-authored-by: Daniel Weindl --- petab/C.py | 5 - petab/__init__.py | 106 +++++++++----------- petab/calculate.py | 7 -- petab/composite_problem.py | 7 -- petab/conditions.py | 8 -- petab/core.py | 7 -- petab/lint.py | 9 -- petab/mapping.py | 7 -- petab/math/__init__.py | 9 -- petab/math/sympify.py | 5 - petab/measurements.py | 7 -- petab/models/__init__.py | 7 -- petab/models/model.py | 7 -- petab/models/pysb_model.py | 7 -- petab/models/sbml_model.py | 5 - petab/observables.py | 8 -- petab/parameter_mapping.py | 7 -- petab/parameters.py | 7 -- petab/simplify.py | 7 -- petab/simulate.py | 8 -- petab/versions.py | 2 +- petab/visualize/__init__.py | 10 -- petab/visualize/data_overview.py | 5 - petab/visualize/lint.py | 7 -- petab/visualize/plot_data_and_simulation.py | 7 -- petab/visualize/plot_residuals.py | 5 - petab/visualize/plotter.py | 9 -- petab/visualize/plotting.py | 6 -- petab/yaml.py | 7 -- tests/test_deprecation_warnings.py | 26 +++++ 30 files changed, 76 insertions(+), 248 deletions(-) delete mode 100644 petab/C.py delete mode 100644 petab/calculate.py delete mode 100644 petab/composite_problem.py delete mode 100644 petab/conditions.py delete mode 100644 petab/core.py delete mode 100644 petab/lint.py delete mode 100644 petab/mapping.py delete mode 100644 petab/math/__init__.py delete mode 100644 petab/math/sympify.py delete mode 100644 petab/measurements.py delete mode 100644 petab/models/__init__.py delete mode 100644 petab/models/model.py delete mode 100644 petab/models/pysb_model.py delete mode 100644 petab/models/sbml_model.py delete mode 100644 petab/observables.py delete mode 100644 petab/parameter_mapping.py delete mode 100644 petab/parameters.py delete mode 100644 petab/simplify.py delete mode 100644 petab/simulate.py delete mode 100644 petab/visualize/__init__.py delete mode 100644 petab/visualize/data_overview.py delete mode 100644 petab/visualize/lint.py delete mode 100644 petab/visualize/plot_data_and_simulation.py delete mode 100644 petab/visualize/plot_residuals.py delete mode 100644 petab/visualize/plotter.py delete mode 100644 petab/visualize/plotting.py delete mode 100644 petab/yaml.py create mode 100644 tests/test_deprecation_warnings.py diff --git a/petab/C.py b/petab/C.py deleted file mode 100644 index 77f11abb..00000000 --- a/petab/C.py +++ /dev/null @@ -1,5 +0,0 @@ -"""Deprecated module. Use petab.v1.C instead.""" -from petab import _deprecated_import_v1 -from petab.v1.C import * # noqa: F403, F401, E402 - -_deprecated_import_v1(__name__) diff --git a/petab/__init__.py b/petab/__init__.py index 3dd30598..a9222c97 100644 --- a/petab/__init__.py +++ b/petab/__init__.py @@ -2,74 +2,66 @@ PEtab global ============ -.. warning:: - - All functions in here are deprecated. Use the respective functions from - :mod:`petab.v1` instead. - Attributes: ENV_NUM_THREADS: Name of environment variable to set number of threads or processes PEtab should use for operations that can be performed in parallel. By default, all operations are performed sequentially. """ -import functools -import inspect +import importlib import sys -import warnings +from functools import partial +from pathlib import Path from warnings import warn -# deprecated imports -from petab.v1 import * # noqa: F403, F401, E402 - -from .v1.format_version import __format_version__ # noqa: F401, E402 - -# __all__ = [ -# 'ENV_NUM_THREADS', -# ] - ENV_NUM_THREADS = "PETAB_NUM_THREADS" - - -def _deprecated_v1(func): - """Decorator for deprecation warnings for functions.""" - - @functools.wraps(func) - def new_func(*args, **kwargs): - warnings.warn( - f"petab.{func.__name__} is deprecated, " - f"please use petab.v1.{func.__name__} instead.", - category=DeprecationWarning, - stacklevel=2, +__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 != "__path__": + 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 func(*args, **kwargs) - - return new_func + return getattr(importlib.import_module("petab.v1"), name) -def _deprecated_import_v1(module_name: str): - """Decorator for deprecation warnings for modules.""" - warn( - f"The '{module_name}' module is deprecated and will be removed " - f"in the next major release. Please use " - f"'petab.v1.{module_name.removeprefix('petab.')}' " - "instead.", - DeprecationWarning, - stacklevel=2, +def v1getattr(name, module): + if name != "__path__": + 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]) + + real_module = importlib.import_module( + f"petab.v1.{'.'.join(v1_object_parts)}" ) - - -__all__ = [ - x - for x in dir(sys.modules[__name__]) - if not x.startswith("_") - and x not in {"sys", "warnings", "functools", "warn", "inspect"} -] - - -# apply decorator to all functions in the module -for name in __all__: - obj = globals().get(name) - if callable(obj) and inspect.isfunction(obj): - globals()[name] = _deprecated_v1(obj) -del name, obj + real_module.__getattr__ = partial(v1getattr, module=real_module) + sys.modules[module_name] = real_module diff --git a/petab/calculate.py b/petab/calculate.py deleted file mode 100644 index ca4c224f..00000000 --- a/petab/calculate.py +++ /dev/null @@ -1,7 +0,0 @@ -"""Deprecated module for calculating residuals and log-likelihoods. - -Use petab.v1.calculate instead.""" -from petab import _deprecated_import_v1 -from petab.v1.calculate import * # noqa: F403, F401, E402 - -_deprecated_import_v1(__name__) diff --git a/petab/composite_problem.py b/petab/composite_problem.py deleted file mode 100644 index 51d30a20..00000000 --- a/petab/composite_problem.py +++ /dev/null @@ -1,7 +0,0 @@ -"""Deprecated module for composite problems. - -Use petab.v1.composite_problem instead.""" -from petab import _deprecated_import_v1 -from petab.v1.composite_problem import * # noqa: F403, F401, E402 - -_deprecated_import_v1(__name__) diff --git a/petab/conditions.py b/petab/conditions.py deleted file mode 100644 index cd00e466..00000000 --- a/petab/conditions.py +++ /dev/null @@ -1,8 +0,0 @@ -"""Deprecated module for condition tables. - -Use petab.v1.conditions instead. -""" -from petab import _deprecated_import_v1 -from petab.v1.conditions import * # noqa: F403, F401, E402 - -_deprecated_import_v1(__name__) diff --git a/petab/core.py b/petab/core.py deleted file mode 100644 index 2668111c..00000000 --- a/petab/core.py +++ /dev/null @@ -1,7 +0,0 @@ -"""Deprecated module for PEtab core classes and functions. - -Use petab.v1.core instead.""" -from petab import _deprecated_import_v1 -from petab.v1.core import * # noqa: F403, F401, E402 - -_deprecated_import_v1(__name__) diff --git a/petab/lint.py b/petab/lint.py deleted file mode 100644 index a7461ca3..00000000 --- a/petab/lint.py +++ /dev/null @@ -1,9 +0,0 @@ -"""Deprecated module for linting PEtab files. - -Use petab.v1.lint instead. -""" - -from petab import _deprecated_import_v1 -from petab.v1.lint import * # noqa: F403, F401, E402 - -_deprecated_import_v1(__name__) diff --git a/petab/mapping.py b/petab/mapping.py deleted file mode 100644 index ca6cdd3f..00000000 --- a/petab/mapping.py +++ /dev/null @@ -1,7 +0,0 @@ -"""Deprecated module for mapping tables. - -Use petab.v1.mapping instead.""" -from petab import _deprecated_import_v1 -from petab.v1.mapping import * # noqa: F403, F401, E402 - -_deprecated_import_v1(__name__) diff --git a/petab/math/__init__.py b/petab/math/__init__.py deleted file mode 100644 index bc857377..00000000 --- a/petab/math/__init__.py +++ /dev/null @@ -1,9 +0,0 @@ -"""Deprecated module for math handling. - -Use petab.v1.math instead.""" -from petab import _deprecated_import_v1 -from petab.v1.math import * # noqa: F403, F401, E402 - -from .sympify import sympify_petab # noqa: F401 - -_deprecated_import_v1(__name__) diff --git a/petab/math/sympify.py b/petab/math/sympify.py deleted file mode 100644 index d85b8e1b..00000000 --- a/petab/math/sympify.py +++ /dev/null @@ -1,5 +0,0 @@ -"""Deprecated module. Use petab.math.sympify instead.""" -from petab import _deprecated_import_v1 -from petab.v1.math.sympify import * # noqa: F403, F401, E402 - -_deprecated_import_v1(__name__) diff --git a/petab/measurements.py b/petab/measurements.py deleted file mode 100644 index fcc0ac8e..00000000 --- a/petab/measurements.py +++ /dev/null @@ -1,7 +0,0 @@ -"""Deprecated module for measurement tables. - -Use petab.v1.measurements instead.""" -from petab import _deprecated_import_v1 -from petab.v1.measurements import * # noqa: F403, F401, E402 - -_deprecated_import_v1(__name__) diff --git a/petab/models/__init__.py b/petab/models/__init__.py deleted file mode 100644 index 4b8c87d3..00000000 --- a/petab/models/__init__.py +++ /dev/null @@ -1,7 +0,0 @@ -"""Deprecated module for PEtab models. - -Use petab.v1.models instead""" -from petab import _deprecated_import_v1 -from petab.v1.models import * # noqa: F403, F401, E402 - -_deprecated_import_v1(__name__) diff --git a/petab/models/model.py b/petab/models/model.py deleted file mode 100644 index 72387313..00000000 --- a/petab/models/model.py +++ /dev/null @@ -1,7 +0,0 @@ -"""Deprecated module for PEtab models. - -Use petab.v1.models instead.""" -from petab import _deprecated_import_v1 -from petab.v1.models.model import * # noqa: F403, F401, E402 - -_deprecated_import_v1(__name__) diff --git a/petab/models/pysb_model.py b/petab/models/pysb_model.py deleted file mode 100644 index f60945f4..00000000 --- a/petab/models/pysb_model.py +++ /dev/null @@ -1,7 +0,0 @@ -"""Deprecated module for PySB models. - -Use petab.v1.models.pysb_model instead.""" -from petab import _deprecated_import_v1 -from petab.v1.models.pysb_model import * # noqa: F403, F401, E402 - -_deprecated_import_v1(__name__) diff --git a/petab/models/sbml_model.py b/petab/models/sbml_model.py deleted file mode 100644 index e754e903..00000000 --- a/petab/models/sbml_model.py +++ /dev/null @@ -1,5 +0,0 @@ -"""Deprecated module. Use petab.v1.models.sbml_model instead.""" -from petab import _deprecated_import_v1 -from petab.v1.models.sbml_model import * # noqa: F403, F401, E402 - -_deprecated_import_v1(__name__) diff --git a/petab/observables.py b/petab/observables.py deleted file mode 100644 index 0d94736b..00000000 --- a/petab/observables.py +++ /dev/null @@ -1,8 +0,0 @@ -"""Deprecated module for observable tables. - -Use petab.v1.observables instead. -""" -from petab import _deprecated_import_v1 -from petab.v1.observables import * # noqa: F403, F401, E402 - -_deprecated_import_v1(__name__) diff --git a/petab/parameter_mapping.py b/petab/parameter_mapping.py deleted file mode 100644 index 79598380..00000000 --- a/petab/parameter_mapping.py +++ /dev/null @@ -1,7 +0,0 @@ -"""Deprecated module for parameter mapping. - -Use petab.v1.parameter_mapping instead.""" -from petab import _deprecated_import_v1 -from petab.v1.parameter_mapping import * # noqa: F403, F401, E402 - -_deprecated_import_v1(__name__) diff --git a/petab/parameters.py b/petab/parameters.py deleted file mode 100644 index 39e66fe3..00000000 --- a/petab/parameters.py +++ /dev/null @@ -1,7 +0,0 @@ -"""Deprecated module for parameter table handling. - -Use petab.v1.parameters instead.""" -from petab import _deprecated_import_v1 -from petab.v1.parameters import * # noqa: F403, F401, E402 - -_deprecated_import_v1(__name__) diff --git a/petab/simplify.py b/petab/simplify.py deleted file mode 100644 index cd7ba25e..00000000 --- a/petab/simplify.py +++ /dev/null @@ -1,7 +0,0 @@ -"""Deprecated module for simplifying PEtab problems. - -Use petab.simplify instead.""" -from petab import _deprecated_import_v1 -from petab.v1.simplify import * # noqa: F403, F401, E402 - -_deprecated_import_v1(__name__) diff --git a/petab/simulate.py b/petab/simulate.py deleted file mode 100644 index afa866a6..00000000 --- a/petab/simulate.py +++ /dev/null @@ -1,8 +0,0 @@ -"""Deprecated module for simulating PEtab models. - -Use petab.v1.simulate instead.""" - -from petab import _deprecated_import_v1 -from petab.v1.simulate import * # noqa: F403, F401, E402 - -_deprecated_import_v1(__name__) diff --git a/petab/versions.py b/petab/versions.py index 2e2eb2f4..2b263aff 100644 --- a/petab/versions.py +++ b/petab/versions.py @@ -3,8 +3,8 @@ from pathlib import Path -from petab.C import FORMAT_VERSION from petab.v1 import Problem as V1Problem +from petab.v1.C import FORMAT_VERSION from petab.v1.yaml import load_yaml from petab.v2 import Problem as V2Problem diff --git a/petab/visualize/__init__.py b/petab/visualize/__init__.py deleted file mode 100644 index 2151c3f8..00000000 --- a/petab/visualize/__init__.py +++ /dev/null @@ -1,10 +0,0 @@ -"""Deprecated module for visualization of PEtab problems. - -Use petab.v1.visualize instead.""" - -from petab import _deprecated_import_v1 -from petab.v1.visualize import * # noqa: F403, F401, E402 - -from .plotting import DataProvider, Figure # noqa: F403, F401, E402 - -_deprecated_import_v1(__name__) diff --git a/petab/visualize/data_overview.py b/petab/visualize/data_overview.py deleted file mode 100644 index 356953da..00000000 --- a/petab/visualize/data_overview.py +++ /dev/null @@ -1,5 +0,0 @@ -"""Deprecated module. Use petab.v1.visualize.data_overview instead.""" -from petab import _deprecated_import_v1 -from petab.v1.visualize.data_overview import * # noqa: F403, F401, E402 - -_deprecated_import_v1(__name__) diff --git a/petab/visualize/lint.py b/petab/visualize/lint.py deleted file mode 100644 index e1e6c536..00000000 --- a/petab/visualize/lint.py +++ /dev/null @@ -1,7 +0,0 @@ -"""Deprecated module for linting PEtab visualization files. - -Use petab.v1.visualize.lint instead.""" -from petab import _deprecated_import_v1 -from petab.v1.visualize.lint import * # noqa: F403, F401, E402 - -_deprecated_import_v1(__name__) diff --git a/petab/visualize/plot_data_and_simulation.py b/petab/visualize/plot_data_and_simulation.py deleted file mode 100644 index 0151665f..00000000 --- a/petab/visualize/plot_data_and_simulation.py +++ /dev/null @@ -1,7 +0,0 @@ -"""Deprecated module. - -Use petab.v1.visualize.plot_data_and_simulation instead.""" -from petab import _deprecated_import_v1 -from petab.v1.visualize.plot_data_and_simulation import * # noqa: F403, F401, E402 - -_deprecated_import_v1(__name__) diff --git a/petab/visualize/plot_residuals.py b/petab/visualize/plot_residuals.py deleted file mode 100644 index 91136199..00000000 --- a/petab/visualize/plot_residuals.py +++ /dev/null @@ -1,5 +0,0 @@ -"""Deprecated module. Use petab.v1.visualize.plot_residuals instead.""" -from petab import _deprecated_import_v1 -from petab.v1.visualize.plot_residuals import * # noqa: F403, F401, E402 - -_deprecated_import_v1(__name__) diff --git a/petab/visualize/plotter.py b/petab/visualize/plotter.py deleted file mode 100644 index 8b8eeba1..00000000 --- a/petab/visualize/plotter.py +++ /dev/null @@ -1,9 +0,0 @@ -"""Deprecated module. Use petab.v1.visualize.plotter instead.""" -from petab import _deprecated_import_v1 -from petab.v1.visualize.plotter import * # noqa: F403, F401, E402 -from petab.v1.visualize.plotter import ( # noqa: F401 - measurement_line_kwargs, - simulation_line_kwargs, -) - -_deprecated_import_v1(__name__) diff --git a/petab/visualize/plotting.py b/petab/visualize/plotting.py deleted file mode 100644 index a675cf51..00000000 --- a/petab/visualize/plotting.py +++ /dev/null @@ -1,6 +0,0 @@ -"""Deprecated module. Use petab.v1.visualize.plotting instead.""" -from petab import _deprecated_import_v1 -from petab.v1.visualize.plotting import * # noqa: F403, F401, E402 -from petab.v1.visualize.plotting import DEFAULT_FIGSIZE # noqa: F401 - -_deprecated_import_v1(__name__) diff --git a/petab/yaml.py b/petab/yaml.py deleted file mode 100644 index 8a84221a..00000000 --- a/petab/yaml.py +++ /dev/null @@ -1,7 +0,0 @@ -"""Deprecated module for reading and writing PEtab YAML files. - -Use petab.v1.yaml instead.""" -from petab import _deprecated_import_v1 -from petab.v1.yaml import * # noqa: F403, F401, E402 - -_deprecated_import_v1(__name__) diff --git a/tests/test_deprecation_warnings.py b/tests/test_deprecation_warnings.py new file mode 100644 index 00000000..5845a6f0 --- /dev/null +++ b/tests/test_deprecation_warnings.py @@ -0,0 +1,26 @@ +import warnings + +import pytest + + +def test_deprecated_global(): + with pytest.warns(DeprecationWarning): + from petab import Problem # noqa + + with pytest.warns(DeprecationWarning): + import petab + + petab.Problem() + + with pytest.warns(DeprecationWarning): + import petab.parameters + + petab.parameters # noqa + + with warnings.catch_warnings(): + warnings.simplefilter("error") + from petab.v1 import Problem # noqa + + Problem() + + import petab.v1.parameters From e4b1861653343092cd5130a26334eb838ebb411e Mon Sep 17 00:00:00 2001 From: Daniel Weindl Date: Tue, 2 Jul 2024 11:10:30 +0200 Subject: [PATCH 3/5] Fix imports (#298) Fixes an issue introduced in #297, which made all optional dependencies required. --- petab/__init__.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/petab/__init__.py b/petab/__init__.py index a9222c97..81b58729 100644 --- a/petab/__init__.py +++ b/petab/__init__.py @@ -60,8 +60,11 @@ def v1getattr(name, module): v1_object_parts = [*v1_object.parts[:-1], v1_object.stem] module_name = ".".join(["petab", *v1_object_parts]) - 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 + 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 From 7fd4498aa34571a506a2ecfa178aa6d18e5460a5 Mon Sep 17 00:00:00 2001 From: Daniel Weindl Date: Tue, 2 Jul 2024 13:18:00 +0200 Subject: [PATCH 4/5] Add petab.v2.C (#299) For now, mostly a copy of v1. The be updated as petab v2 development progresses. Also adds some missing documentation. Use of PEtab v2-related constants from `petab.v1.C` is deprecated. --- doc/modules.rst | 1 + petab/v1/C.py | 171 +++++++++++----------- petab/v2/C.py | 373 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 465 insertions(+), 80 deletions(-) create mode 100644 petab/v2/C.py diff --git a/doc/modules.rst b/doc/modules.rst index a227fafa..6a747809 100644 --- a/doc/modules.rst +++ b/doc/modules.rst @@ -28,5 +28,6 @@ API Reference petab.v1.visualize petab.v1.yaml petab.v2 + petab.v2.C petab.v2.lint petab.v2.problem diff --git a/petab/v1/C.py b/petab/v1/C.py index 70ce22c3..a013a0cc 100644 --- a/petab/v1/C.py +++ b/petab/v1/C.py @@ -7,34 +7,34 @@ # MEASUREMENTS -#: +#: Observable ID column in the observable and measurement tables OBSERVABLE_ID = "observableId" -#: +#: Preequilibration condition ID column in the measurement table PREEQUILIBRATION_CONDITION_ID = "preequilibrationConditionId" -#: +#: Simulation condition ID column in the measurement table SIMULATION_CONDITION_ID = "simulationConditionId" -#: +#: Measurement value column in the measurement table MEASUREMENT = "measurement" -#: +#: Time column in the measurement table TIME = "time" #: Time value that indicates steady-state measurements TIME_STEADY_STATE = _math.inf -#: +#: Observable parameters column in the measurement table OBSERVABLE_PARAMETERS = "observableParameters" -#: +#: Noise parameters column in the measurement table NOISE_PARAMETERS = "noiseParameters" -#: +#: Dataset ID column in the measurement table DATASET_ID = "datasetId" -#: +#: Replicate ID column in the measurement table REPLICATE_ID = "replicateId" #: Mandatory columns of measurement table @@ -65,27 +65,27 @@ # PARAMETERS -#: +#: Parameter ID column in the parameter table PARAMETER_ID = "parameterId" -#: +#: Parameter name column in the parameter table PARAMETER_NAME = "parameterName" -#: +#: Parameter scale column in the parameter table PARAMETER_SCALE = "parameterScale" -#: +#: Lower bound column in the parameter table LOWER_BOUND = "lowerBound" -#: +#: Upper bound column in the parameter table UPPER_BOUND = "upperBound" -#: +#: Nominal value column in the parameter table NOMINAL_VALUE = "nominalValue" -#: +#: Estimate column in the parameter table ESTIMATE = "estimate" -#: +#: Initialization prior type column in the parameter table INITIALIZATION_PRIOR_TYPE = "initializationPriorType" -#: +#: Initialization prior parameters column in the parameter table INITIALIZATION_PRIOR_PARAMETERS = "initializationPriorParameters" -#: +#: Objective prior type column in the parameter table OBJECTIVE_PRIOR_TYPE = "objectivePriorType" -#: +#: Objective prior parameters column in the parameter table OBJECTIVE_PRIOR_PARAMETERS = "objectivePriorParameters" #: Mandatory columns of parameter table @@ -115,31 +115,31 @@ *PARAMETER_DF_OPTIONAL_COLS[1:], ] -#: +#: Initialization-type prior INITIALIZATION = "initialization" -#: +#: Objective-type prior OBJECTIVE = "objective" # CONDITIONS -#: +#: Condition ID column in the condition table CONDITION_ID = "conditionId" -#: +#: Condition name column in the condition table CONDITION_NAME = "conditionName" # OBSERVABLES -#: +#: Observable name column in the observables table OBSERVABLE_NAME = "observableName" -#: +#: Observable formula column in the observables table OBSERVABLE_FORMULA = "observableFormula" -#: +#: Noise formula column in the observables table NOISE_FORMULA = "noiseFormula" -#: +#: Observable transformation column in the observables table OBSERVABLE_TRANSFORMATION = "observableTransformation" -#: +#: Noise distribution column in the observables table NOISE_DISTRIBUTION = "noiseDistribution" #: Mandatory columns of observables table @@ -165,11 +165,11 @@ # TRANSFORMATIONS -#: +#: Linear transformation LIN = "lin" -#: +#: Logarithmic transformation LOG = "log" -#: +#: Logarithmic base 10 transformation LOG10 = "log10" #: Supported observable transformations OBSERVABLE_TRANSFORMATIONS = [LIN, LOG, LOG10] @@ -177,21 +177,21 @@ # NOISE MODELS -#: +#: Uniform distribution UNIFORM = "uniform" -#: +#: Uniform distribution on the parameter scale PARAMETER_SCALE_UNIFORM = "parameterScaleUniform" -#: +#: Normal distribution NORMAL = "normal" -#: +#: Normal distribution on the parameter scale PARAMETER_SCALE_NORMAL = "parameterScaleNormal" -#: +#: Laplace distribution LAPLACE = "laplace" -#: +#: Laplace distribution on the parameter scale PARAMETER_SCALE_LAPLACE = "parameterScaleLaplace" -#: +#: Log-normal distribution LOG_NORMAL = "logNormal" -#: +#: Log-Laplace distribution LOG_LAPLACE = "logLaplace" #: Supported prior types @@ -212,31 +212,31 @@ # VISUALIZATION -#: +#: Plot ID column in the visualization table PLOT_ID = "plotId" -#: +#: Plot name column in the visualization table PLOT_NAME = "plotName" -#: +#: Value for plot type 'simulation' in the visualization table PLOT_TYPE_SIMULATION = "plotTypeSimulation" -#: +#: Value for plot type 'data' in the visualization table PLOT_TYPE_DATA = "plotTypeData" -#: +#: X values column in the visualization table X_VALUES = "xValues" -#: +#: X offset column in the visualization table X_OFFSET = "xOffset" -#: +#: X label column in the visualization table X_LABEL = "xLabel" -#: +#: X scale column in the visualization table X_SCALE = "xScale" -#: +#: Y values column in the visualization table Y_VALUES = "yValues" -#: +#: Y offset column in the visualization table Y_OFFSET = "yOffset" -#: +#: Y label column in the visualization table Y_LABEL = "yLabel" -#: +#: Y scale column in the visualization table Y_SCALE = "yScale" -#: +#: Legend entry column in the visualization table LEGEND_ENTRY = "legendEntry" #: Mandatory columns of visualization table @@ -287,11 +287,11 @@ DATASET_ID, ] -#: +#: Plot type value in the visualization table for line plot LINE_PLOT = "LinePlot" -#: +#: Plot type value in the visualization table for bar plot BAR_PLOT = "BarPlot" -#: +#: Plot type value in the visualization table for scatter plot SCATTER_PLOT = "ScatterPlot" #: Supported plot types PLOT_TYPES_SIMULATION = [LINE_PLOT, BAR_PLOT, SCATTER_PLOT] @@ -303,65 +303,76 @@ Y_SCALES = [LIN, LOG, LOG10] -#: +#: Plot type "data" value in the visualization table for mean and standard +# deviation MEAN_AND_SD = "MeanAndSD" -#: +#: Plot type "data" value in the visualization table for mean and standard +# error MEAN_AND_SEM = "MeanAndSEM" -#: +#: Plot type "data" value in the visualization table for replicates REPLICATE = "replicate" -#: +#: Plot type "data" value in the visualization table for provided noise values PROVIDED = "provided" #: Supported settings for handling replicates PLOT_TYPES_DATA = [MEAN_AND_SD, MEAN_AND_SEM, REPLICATE, PROVIDED] # YAML -#: +#: PEtab version key in the YAML file FORMAT_VERSION = "format_version" -#: +#: Parameter file key in the YAML file PARAMETER_FILE = "parameter_file" -#: +#: Problems key in the YAML file PROBLEMS = "problems" -#: +#: SBML files key in the YAML file SBML_FILES = "sbml_files" -#: +#: Model files key in the YAML file +# (PEtab v2.0 -- DEPRECATED: use value from petab.v2.C) MODEL_FILES = "model_files" -#: +#: Model location key in the YAML file +# (PEtab v2.0 -- DEPRECATED: use value from petab.v2.C) MODEL_LOCATION = "location" -#: +#: Model language key in the YAML file +# (PEtab v2.0 -- DEPRECATED: use value from petab.v2.C) MODEL_LANGUAGE = "language" -#: +#: Condition files key in the YAML file CONDITION_FILES = "condition_files" -#: +#: Measurement files key in the YAML file MEASUREMENT_FILES = "measurement_files" -#: +#: Observable files key in the YAML file OBSERVABLE_FILES = "observable_files" -#: +#: Visualization files key in the YAML file VISUALIZATION_FILES = "visualization_files" -#: +#: Mapping files key in the YAML file +# (PEtab v2.0 -- DEPRECATED: use value from petab.v2.C) MAPPING_FILES = "mapping_files" -#: +#: Extensions key in the YAML file +# (PEtab v2.0 -- DEPRECATED: use value from petab.v2.C) EXTENSIONS = "extensions" # MAPPING -#: + +#: PEtab entity ID column in the mapping table +# (PEtab v2.0 -- DEPRECATED: use value from petab.v2.C) PETAB_ENTITY_ID = "petabEntityId" -#: +#: Model entity ID column in the mapping table +# (PEtab v2.0 -- DEPRECATED: use value from petab.v2.C) MODEL_ENTITY_ID = "modelEntityId" -#: +#: Required columns of the mapping table +# (PEtab v2.0 -- DEPRECATED: use value from petab.v2.C) MAPPING_DF_REQUIRED_COLS = [PETAB_ENTITY_ID, MODEL_ENTITY_ID] # MORE -#: +#: Simulated value column in the simulation table SIMULATION = "simulation" -#: +#: Residual value column in the residuals table RESIDUAL = "residual" -#: +#: ??? NOISE_VALUE = "noiseValue" -# separator for multiple parameter values (bounds, observableParameters, ...) +#: separator for multiple parameter values (bounds, observableParameters, ...) PARAMETER_SEPARATOR = ";" diff --git a/petab/v2/C.py b/petab/v2/C.py new file mode 100644 index 00000000..11fede25 --- /dev/null +++ b/petab/v2/C.py @@ -0,0 +1,373 @@ +# pylint: disable:invalid-name +""" +This file contains constant definitions. +""" +import math as _math +import sys + +# MEASUREMENTS + +#: Observable ID column in the observable and measurement tables +OBSERVABLE_ID = "observableId" + +#: Preequilibration condition ID column in the measurement table +PREEQUILIBRATION_CONDITION_ID = "preequilibrationConditionId" + +#: Simulation condition ID column in the measurement table +SIMULATION_CONDITION_ID = "simulationConditionId" + +#: Measurement value column in the measurement table +MEASUREMENT = "measurement" + +#: Time column in the measurement table +TIME = "time" + +#: Time value that indicates steady-state measurements +TIME_STEADY_STATE = _math.inf + +#: Observable parameters column in the measurement table +OBSERVABLE_PARAMETERS = "observableParameters" + +#: Noise parameters column in the measurement table +NOISE_PARAMETERS = "noiseParameters" + +#: Dataset ID column in the measurement table +DATASET_ID = "datasetId" + +#: Replicate ID column in the measurement table +REPLICATE_ID = "replicateId" + +#: Mandatory columns of measurement table +MEASUREMENT_DF_REQUIRED_COLS = [ + OBSERVABLE_ID, + SIMULATION_CONDITION_ID, + MEASUREMENT, + TIME, +] + +#: Optional columns of measurement table +MEASUREMENT_DF_OPTIONAL_COLS = [ + PREEQUILIBRATION_CONDITION_ID, + OBSERVABLE_PARAMETERS, + NOISE_PARAMETERS, + DATASET_ID, + REPLICATE_ID, +] + +#: Measurement table columns +MEASUREMENT_DF_COLS = [ + MEASUREMENT_DF_REQUIRED_COLS[0], + MEASUREMENT_DF_OPTIONAL_COLS[0], + *MEASUREMENT_DF_REQUIRED_COLS[1:], + *MEASUREMENT_DF_OPTIONAL_COLS[1:], +] + + +# PARAMETERS + +#: Parameter ID column in the parameter table +PARAMETER_ID = "parameterId" +#: Parameter name column in the parameter table +PARAMETER_NAME = "parameterName" +#: Parameter scale column in the parameter table +PARAMETER_SCALE = "parameterScale" +#: Lower bound column in the parameter table +LOWER_BOUND = "lowerBound" +#: Upper bound column in the parameter table +UPPER_BOUND = "upperBound" +#: Nominal value column in the parameter table +NOMINAL_VALUE = "nominalValue" +#: Estimate column in the parameter table +ESTIMATE = "estimate" +#: Initialization prior type column in the parameter table +INITIALIZATION_PRIOR_TYPE = "initializationPriorType" +#: Initialization prior parameters column in the parameter table +INITIALIZATION_PRIOR_PARAMETERS = "initializationPriorParameters" +#: Objective prior type column in the parameter table +OBJECTIVE_PRIOR_TYPE = "objectivePriorType" +#: Objective prior parameters column in the parameter table +OBJECTIVE_PRIOR_PARAMETERS = "objectivePriorParameters" + +#: Mandatory columns of parameter table +PARAMETER_DF_REQUIRED_COLS = [ + PARAMETER_ID, + PARAMETER_SCALE, + LOWER_BOUND, + UPPER_BOUND, + ESTIMATE, +] + +#: Optional columns of parameter table +PARAMETER_DF_OPTIONAL_COLS = [ + PARAMETER_NAME, + NOMINAL_VALUE, + INITIALIZATION_PRIOR_TYPE, + INITIALIZATION_PRIOR_PARAMETERS, + OBJECTIVE_PRIOR_TYPE, + OBJECTIVE_PRIOR_PARAMETERS, +] + +#: Parameter table columns +PARAMETER_DF_COLS = [ + PARAMETER_DF_REQUIRED_COLS[0], + PARAMETER_DF_OPTIONAL_COLS[0], + *PARAMETER_DF_REQUIRED_COLS[1:], + *PARAMETER_DF_OPTIONAL_COLS[1:], +] + +#: Initialization-type prior +INITIALIZATION = "initialization" +#: Objective-type prior +OBJECTIVE = "objective" + + +# CONDITIONS + +#: Condition ID column in the condition table +CONDITION_ID = "conditionId" +#: Condition name column in the condition table +CONDITION_NAME = "conditionName" + + +# OBSERVABLES + +#: Observable name column in the observables table +OBSERVABLE_NAME = "observableName" +#: Observable formula column in the observables table +OBSERVABLE_FORMULA = "observableFormula" +#: Noise formula column in the observables table +NOISE_FORMULA = "noiseFormula" +#: Observable transformation column in the observables table +OBSERVABLE_TRANSFORMATION = "observableTransformation" +#: Noise distribution column in the observables table +NOISE_DISTRIBUTION = "noiseDistribution" + +#: Mandatory columns of observables table +OBSERVABLE_DF_REQUIRED_COLS = [ + OBSERVABLE_ID, + OBSERVABLE_FORMULA, + NOISE_FORMULA, +] + +#: Optional columns of observables table +OBSERVABLE_DF_OPTIONAL_COLS = [ + OBSERVABLE_NAME, + OBSERVABLE_TRANSFORMATION, + NOISE_DISTRIBUTION, +] + +#: Observables table columns +OBSERVABLE_DF_COLS = [ + *OBSERVABLE_DF_REQUIRED_COLS, + *OBSERVABLE_DF_OPTIONAL_COLS, +] + + +# TRANSFORMATIONS + +#: Linear transformation +LIN = "lin" +#: Logarithmic transformation +LOG = "log" +#: Logarithmic base 10 transformation +LOG10 = "log10" +#: Supported observable transformations +OBSERVABLE_TRANSFORMATIONS = [LIN, LOG, LOG10] + + +# NOISE MODELS + +#: Uniform distribution +UNIFORM = "uniform" +#: Uniform distribution on the parameter scale +PARAMETER_SCALE_UNIFORM = "parameterScaleUniform" +#: Normal distribution +NORMAL = "normal" +#: Normal distribution on the parameter scale +PARAMETER_SCALE_NORMAL = "parameterScaleNormal" +#: Laplace distribution +LAPLACE = "laplace" +#: Laplace distribution on the parameter scale +PARAMETER_SCALE_LAPLACE = "parameterScaleLaplace" +#: Log-normal distribution +LOG_NORMAL = "logNormal" +#: Log-Laplace distribution +LOG_LAPLACE = "logLaplace" + +#: Supported prior types +PRIOR_TYPES = [ + UNIFORM, + NORMAL, + LAPLACE, + LOG_NORMAL, + LOG_LAPLACE, + PARAMETER_SCALE_UNIFORM, + PARAMETER_SCALE_NORMAL, + PARAMETER_SCALE_LAPLACE, +] + +#: Supported noise distributions +NOISE_MODELS = [NORMAL, LAPLACE] + + +# VISUALIZATION + +#: Plot ID column in the visualization table +PLOT_ID = "plotId" +#: Plot name column in the visualization table +PLOT_NAME = "plotName" +#: Value for plot type 'simulation' in the visualization table +PLOT_TYPE_SIMULATION = "plotTypeSimulation" +#: Value for plot type 'data' in the visualization table +PLOT_TYPE_DATA = "plotTypeData" +#: X values column in the visualization table +X_VALUES = "xValues" +#: X offset column in the visualization table +X_OFFSET = "xOffset" +#: X label column in the visualization table +X_LABEL = "xLabel" +#: X scale column in the visualization table +X_SCALE = "xScale" +#: Y values column in the visualization table +Y_VALUES = "yValues" +#: Y offset column in the visualization table +Y_OFFSET = "yOffset" +#: Y label column in the visualization table +Y_LABEL = "yLabel" +#: Y scale column in the visualization table +Y_SCALE = "yScale" +#: Legend entry column in the visualization table +LEGEND_ENTRY = "legendEntry" + +#: Mandatory columns of visualization table +VISUALIZATION_DF_REQUIRED_COLS = [PLOT_ID] + +#: Optional columns of visualization table +VISUALIZATION_DF_OPTIONAL_COLS = [ + PLOT_NAME, + PLOT_TYPE_SIMULATION, + PLOT_TYPE_DATA, + X_VALUES, + X_OFFSET, + X_LABEL, + X_SCALE, + Y_VALUES, + Y_OFFSET, + Y_LABEL, + Y_SCALE, + LEGEND_ENTRY, + DATASET_ID, +] + +#: Visualization table columns +VISUALIZATION_DF_COLS = [ + *VISUALIZATION_DF_REQUIRED_COLS, + *VISUALIZATION_DF_OPTIONAL_COLS, +] + +#: Visualization table columns that contain subplot specifications +VISUALIZATION_DF_SUBPLOT_LEVEL_COLS = [ + PLOT_ID, + PLOT_NAME, + PLOT_TYPE_SIMULATION, + PLOT_TYPE_DATA, + X_LABEL, + X_SCALE, + Y_LABEL, + Y_SCALE, +] + +#: Visualization table columns that contain single plot specifications +VISUALIZATION_DF_SINGLE_PLOT_LEVEL_COLS = [ + X_VALUES, + X_OFFSET, + Y_VALUES, + Y_OFFSET, + LEGEND_ENTRY, + DATASET_ID, +] + +#: Plot type value in the visualization table for line plot +LINE_PLOT = "LinePlot" +#: Plot type value in the visualization table for bar plot +BAR_PLOT = "BarPlot" +#: Plot type value in the visualization table for scatter plot +SCATTER_PLOT = "ScatterPlot" +#: Supported plot types +PLOT_TYPES_SIMULATION = [LINE_PLOT, BAR_PLOT, SCATTER_PLOT] + +#: Supported xScales +X_SCALES = [LIN, LOG, LOG10] + +#: Supported yScales +Y_SCALES = [LIN, LOG, LOG10] + + +#: Plot type "data" value in the visualization table for mean and standard +# deviation +MEAN_AND_SD = "MeanAndSD" +#: Plot type "data" value in the visualization table for mean and standard +# error +MEAN_AND_SEM = "MeanAndSEM" +#: Plot type "data" value in the visualization table for replicates +REPLICATE = "replicate" +#: Plot type "data" value in the visualization table for provided noise values +PROVIDED = "provided" +#: Supported settings for handling replicates +PLOT_TYPES_DATA = [MEAN_AND_SD, MEAN_AND_SEM, REPLICATE, PROVIDED] + + +# YAML +#: PEtab version key in the YAML file +FORMAT_VERSION = "format_version" +#: Parameter file key in the YAML file +PARAMETER_FILE = "parameter_file" +#: Problems key in the YAML file +PROBLEMS = "problems" +#: Model files key in the YAML file +MODEL_FILES = "model_files" +#: Model location key in the YAML file +MODEL_LOCATION = "location" +#: Model language key in the YAML file +MODEL_LANGUAGE = "language" +#: Condition files key in the YAML file +CONDITION_FILES = "condition_files" +#: Measurement files key in the YAML file +MEASUREMENT_FILES = "measurement_files" +#: Observable files key in the YAML file +OBSERVABLE_FILES = "observable_files" +#: Visualization files key in the YAML file +VISUALIZATION_FILES = "visualization_files" +#: Mapping files key in the YAML file +MAPPING_FILES = "mapping_files" +#: Extensions key in the YAML file +EXTENSIONS = "extensions" + + +# MAPPING + +#: PEtab entity ID column in the mapping table +PETAB_ENTITY_ID = "petabEntityId" +#: Model entity ID column in the mapping table +MODEL_ENTITY_ID = "modelEntityId" +#: Required columns of the mapping table +MAPPING_DF_REQUIRED_COLS = [PETAB_ENTITY_ID, MODEL_ENTITY_ID] + +# MORE + +#: Simulated value column in the simulation table +SIMULATION = "simulation" +#: Residual value column in the residuals table +RESIDUAL = "residual" +#: ??? +NOISE_VALUE = "noiseValue" + +#: separator for multiple parameter values (bounds, observableParameters, ...) +PARAMETER_SEPARATOR = ";" + + +__all__ = [ + x + for x in dir(sys.modules[__name__]) + if not x.startswith("_") and x not in {"sys", "math"} +] From 877087abc690f01ffdb52c23ecb43ae5e86cd217 Mon Sep 17 00:00:00 2001 From: dilpath Date: Tue, 2 Jul 2024 13:42:37 +0200 Subject: [PATCH 5/5] bump version; update changelog --- CHANGELOG.md | 9 +++++++++ petab/version.py | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 56ec211a..1d1327a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,15 @@ ## 0.4 series +This series contains many changes related to the new `petab.v2` subpackage. `petab.v2` should not be considered stable; the `petab.v2` API may change rapidly until we release libpetab-python v1.0.0. + +### 0.4.1 + +* Fix: keep previously-optional dependencies optional by @dweindl in https://github.com/PEtab-dev/libpetab-python/pull/298 +* Add petab.v2.C by @dweindl in https://github.com/PEtab-dev/libpetab-python/pull/299 + +**Full Changelog**: https://github.com/PEtab-dev/libpetab-python/compare/v0.4.0...v0.4.1 + ### 0.4.0 **Prepare for PEtab v2** diff --git a/petab/version.py b/petab/version.py index 1d88e505..05784482 100644 --- a/petab/version.py +++ b/petab/version.py @@ -1,2 +1,2 @@ """PEtab library version""" -__version__ = "0.4.0" +__version__ = "0.4.1"