Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix documentation after PEtab refactoring #2252

Merged
merged 7 commits into from
Jan 2, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/test_doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:

strategy:
matrix:
python-version: [ "3.10" ]
python-version: [ "3.11" ]

steps:
- name: Set up Python ${{ matrix.python-version }}
Expand Down
2 changes: 1 addition & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ build:
- libatlas-base-dev
- swig
tools:
python: "3.9"
python: "3.11"
36 changes: 29 additions & 7 deletions documentation/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import re
import subprocess
import sys
from enum import EnumType

# need to import before setting typing.TYPE_CHECKING=True, fails otherwise
import amici
Expand Down Expand Up @@ -254,6 +255,7 @@ def install_doxygen():
autodoc_default_options = {
"special-members": "__init__",
"inherited-members": True,
"undoc-members": True,
}

# sphinx-autodoc-typehints
Expand Down Expand Up @@ -606,7 +608,7 @@ def process_missing_ref(app, env, node, contnode):


def skip_member(app, what, name, obj, skip, options):
ignored = [
ignored_names = {
"AbstractModel",
"CVodeSolver",
"IDASolver",
Expand All @@ -615,7 +617,6 @@ def skip_member(app, what, name, obj, skip, options):
"ConditionContext",
"checkSigmaPositivity",
"createGroup",
"createGroup",
"equals",
"printErrMsgIdAndTxt",
"wrapErrHandlerFn",
Expand All @@ -640,24 +641,45 @@ def skip_member(app, what, name, obj, skip, options):
"stdVec2ndarray",
"SwigPyIterator",
"thisown",
]
}

if name in ignored:
if name in ignored_names:
return True

if name.startswith("_") and name != "__init__":
return True

obj_str = str(obj)

# ignore various functions for std::vector<> types
if re.match(r"^<function [\w]+Vector\.", str(obj)):
if re.match(r"^<function [\w]+Vector\.", obj_str):
return True

# ignore various functions for smart pointer types
if re.match(r"^<function [\w]+Ptr\.", str(obj)):
if re.match(r"^<function [\w]+Ptr\.", obj_str):
return True

# ignore various functions for StringDoubleMap
if str(obj).startswith("<function StringDoubleMap"):
if obj_str.startswith("<function StringDoubleMap"):
return True

# Skip inherited members from builtins
# (skips, for example, all the int/str-derived methods of enums
if (
objclass := getattr(obj, "__objclass__", None)
) and objclass.__module__ == "builtins":
return True

# Avoid the following issue for all enum types:
# > python/sdist/amici/amici.py:docstring of amici.amici.FixedParameterContext.from_bytes:9:
# WARNING: Inline interpreted text or phrase reference start-string without end-string.
if (
(qualname := getattr(obj, "__qualname__", ""))
and qualname == "int.to_bytes"
) or (
isinstance(getattr(obj, "__self__", None), EnumType)
and name == "from_bytes"
):
return True

return None
Expand Down
21 changes: 21 additions & 0 deletions python/sdist/amici/parameter_mapping.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
"""Parameter mapping between AMICI and PEtab.

.. deprecated:: 0.21.0
Use :mod:`amici.petab.parameter_mapping` instead.
"""

# some extra imports for backward-compatibility
import warnings

Expand All @@ -22,3 +28,18 @@
"Importing amici.parameter_mapping is deprecated. Use `amici.petab.parameter_mapping` instead.",
DeprecationWarning,
)

__all__ = [

Check warning on line 32 in python/sdist/amici/parameter_mapping.py

View check run for this annotation

Codecov / codecov/patch

python/sdist/amici/parameter_mapping.py#L32

Added line #L32 was not covered by tests
"fill_in_parameters",
"fill_in_parameters_for_condition",
"ParameterMapping",
"ParameterMappingForCondition",
"SingleParameterMapping",
"SingleScaleMapping",
"amici_to_petab_scale",
"petab_to_amici_scale",
"scale_parameter",
"scale_parameters_dict",
"unscale_parameter",
"unscale_parameters_dict",
]
30 changes: 30 additions & 0 deletions python/sdist/amici/petab/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,33 @@
# ID of model parameter that is to be added to SBML model to indicate
# preequilibration
PREEQ_INDICATOR_ID = "preequilibration_indicator"

from .petab_import import import_petab_problem
from .simulations import (
EDATAS,
FIM,
LLH,
RDATAS,
RES,
S2LLH,
SLLH,
SRES,
rdatas_to_measurement_df,
rdatas_to_simulation_df,
simulate_petab,
)

__all__ = [
"import_petab_problem",
"simulate_petab",
"rdatas_to_simulation_df",
"rdatas_to_measurement_df",
"LLH",
"SLLH",
"FIM",
"S2LLH",
"RES",
"SRES",
"RDATAS",
"EDATAS",
]
15 changes: 9 additions & 6 deletions python/sdist/amici/petab/petab_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
# pysb not available
import_model_pysb = None


__all__ = ["import_petab_problem"]

logger = get_logger(__name__, logging.WARNING)


Expand All @@ -37,19 +40,18 @@ def import_petab_problem(
**kwargs,
) -> "amici.Model":
"""
Import model from petab problem.
Create an AMICI model for a PEtab problem.

:param petab_problem:
A petab problem containing all relevant information on the model.

:param model_output_dir:
Directory to write the model code to. Will be created if doesn't
Directory to write the model code to. It will be created if it doesn't
exist. Defaults to current directory.

:param model_name:
Name of the generated model. If model file name was provided,
this defaults to the file name without extension, otherwise
the model ID will be used.
Name of the generated model module. Defaults to the ID of the model
or the model file name without the extension.

:param force_compile:
Whether to compile the model even if the target folder is not empty,
Expand All @@ -63,7 +65,8 @@ def import_petab_problem(

:param kwargs:
Additional keyword arguments to be passed to
:meth:`amici.sbml_import.SbmlImporter.sbml2amici`.
:meth:`amici.sbml_import.SbmlImporter.sbml2amici` or
:func:`amici.pysb_import.pysb2amici`, depending on the model type.

:return:
The imported model.
Expand Down
2 changes: 1 addition & 1 deletion python/sdist/amici/petab/pysb_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def import_model_pysb(

:param kwargs:
Additional keyword arguments to be passed to
:meth:`amici.pysb_import.pysb2amici`.
:func:`amici.pysb_import.pysb2amici`.
"""
set_log_level(logger, verbose)

Expand Down
13 changes: 13 additions & 0 deletions python/sdist/amici/petab/simulations.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@
EDATAS = "edatas"


__all__ = [
"simulate_petab",
"LLH",
"SLLH",
"FIM",
"S2LLH",
"RES",
"SRES",
"RDATAS",
"EDATAS",
]


@log_execution_time("Simulating PEtab model", logger)
def simulate_petab(
petab_problem: petab.Problem,
Expand Down
17 changes: 16 additions & 1 deletion python/sdist/amici/petab_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
------------
Import a model in the :mod:`petab` (https://github.com/PEtab-dev/PEtab) format
into AMICI.

.. deprecated:: 0.21.0
Use :mod:`amici.petab` instead.
"""
import warnings

Expand All @@ -27,4 +30,16 @@
from .petab.sbml_import import ( # noqa
_get_fixed_parameters_sbml as get_fixed_parameters,
)
from .petab.sbml_import import species_to_parameters
from .petab.sbml_import import species_to_parameters # noqa

__all__ = [
"get_observation_model",
"petab_noise_distributions_to_amici",
"petab_scale_to_amici_scale",
"check_model",
"import_model",
"import_model_sbml",
"import_petab_problem",
"get_fixed_parameters",
"species_to_parameters",
]
10 changes: 10 additions & 0 deletions python/sdist/amici/petab_import_pysb.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
"""
PEtab import for PySB models

.. deprecated:: 0.21.0
Use :mod:`amici.petab.pysb_import` instead.
"""
import warnings

from .petab.pysb_import import * # noqa: F401, F403
Expand All @@ -8,3 +14,7 @@
"Importing amici.petab_import_pysb is deprecated. Use `amici.petab.pysb_import` instead.",
DeprecationWarning,
)

__all__ = [
"import_model_pysb",
]
26 changes: 26 additions & 0 deletions python/sdist/amici/petab_objective.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
"""
Evaluate a PEtab objective function.

.. deprecated:: 0.21.0
Use :mod:`amici.petab.simulations` instead.
"""

# THIS FILE IS TO BE REMOVED - DON'T ADD ANYTHING HERE!

import warnings
Expand Down Expand Up @@ -25,3 +32,22 @@
rescale_sensitivity,
simulate_petab,
)

__all__ = [

Check warning on line 36 in python/sdist/amici/petab_objective.py

View check run for this annotation

Codecov / codecov/patch

python/sdist/amici/petab_objective.py#L36

Added line #L36 was not covered by tests
"EDATAS",
"FIM",
"LLH",
"RDATAS",
"RES",
"S2LLH",
"SLLH",
"SRES",
"aggregate_sllh",
"create_edatas",
"fill_in_parameters",
"create_parameter_mapping",
"rdatas_to_measurement_df",
"rdatas_to_simulation_df",
"rescale_sensitivity",
"simulate_petab",
]
10 changes: 10 additions & 0 deletions python/sdist/amici/petab_simulate.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
"""
Simulate a PEtab problem

.. deprecated:: 0.21.0
Use :mod:`amici.petab.simulator` instead.
"""
# THIS FILE IS TO BE REMOVED - DON'T ADD ANYTHING HERE!

import warnings
Expand All @@ -8,3 +14,7 @@
)

from .petab.simulator import PetabSimulator # noqa: F401

__all__ = [

Check warning on line 18 in python/sdist/amici/petab_simulate.py

View check run for this annotation

Codecov / codecov/patch

python/sdist/amici/petab_simulate.py#L18

Added line #L18 was not covered by tests
"PetabSimulator",
]
12 changes: 11 additions & 1 deletion python/sdist/amici/petab_util.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
"""Various helper functions for working with PEtab problems."""
"""
Various helper functions for working with PEtab problems.

.. deprecated:: 0.21.0
Use :mod:`amici.petab.util` instead.
"""

# THIS FILE IS TO BE REMOVED - DON'T ADD ANYTHING HERE!

Expand All @@ -11,3 +16,8 @@
f"Importing {__name__} is deprecated. Use `amici.petab.util` instead.",
DeprecationWarning,
)

__all__ = [

Check warning on line 20 in python/sdist/amici/petab_util.py

View check run for this annotation

Codecov / codecov/patch

python/sdist/amici/petab_util.py#L20

Added line #L20 was not covered by tests
"get_states_in_condition_table",
"PREEQ_INDICATOR_ID",
]
4 changes: 2 additions & 2 deletions python/sdist/amici/swig.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@
) in self.mapping:
value_type_annot = self.mapping[value_type]
if isinstance(value_type_annot, ast.Constant):
return ast.Name(f"Tuple['{value_type_annot.value}']")
return ast.Name(f"tuple['{value_type_annot.value}']")

Check warning on line 100 in python/sdist/amici/swig.py

View check run for this annotation

Codecov / codecov/patch

python/sdist/amici/swig.py#L100

Added line #L100 was not covered by tests
if isinstance(value_type_annot, ast.Name):
return ast.Name(f"Tuple[{value_type_annot.id}]")
return ast.Name(f"tuple[{value_type_annot.id}]")

Check warning on line 102 in python/sdist/amici/swig.py

View check run for this annotation

Codecov / codecov/patch

python/sdist/amici/swig.py#L102

Added line #L102 was not covered by tests

return ast.Constant(old_annot)

Expand Down
Loading