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

Doc: Show typehints in description #1192

Merged
merged 8 commits into from
Nov 20, 2023
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
6 changes: 6 additions & 0 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
'sphinxcontrib.bibtex',
# ensure that jQuery is installed
'sphinxcontrib.jquery',
# type hint formatting
'sphinx_autodoc_typehints',
]

# default autodoc options
Expand Down Expand Up @@ -84,6 +86,10 @@
'fides': ('https://fides-optimizer.readthedocs.io/en/latest/', None),
}


typehints_document_rtype = True
autodoc_typehints = "description"

bibtex_bibfiles = ["using_pypesto.bib"]

# Add any paths that contain templates here, relative to this directory.
Expand Down
9 changes: 1 addition & 8 deletions pypesto/C.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"""

from enum import Enum
from typing import Callable, Literal, Tuple, Union
from typing import Literal, Tuple, Union

###############################################################################
# ENSEMBLE
Expand Down Expand Up @@ -275,13 +275,6 @@ class InnerParameterType(str, Enum):
CSV = 'csv' # return file format
H5 = 'h5' # return file format


###############################################################################
# SELECT

TYPE_POSTPROCESSOR = Callable[["ModelProblem"], None] # noqa: F821
Copy link
Member Author

Choose a reason for hiding this comment

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

@dilpath : Had to shuffle some things around to break circular dependencies. Is that okay?

Copy link
Member

Choose a reason for hiding this comment

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

Looks fine to me, thanks 👍



###############################################################################
# VISUALIZE

Expand Down
2 changes: 2 additions & 0 deletions pypesto/history/util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""History utility functions."""

import numbers
from functools import wraps
from typing import Dict, Sequence, Union

import numpy as np
Expand Down Expand Up @@ -38,6 +39,7 @@ def trace_wrap(f):
integer `ix` the output to a single value.
"""

@wraps(f)
def wrapped_f(
self, ix: Union[Sequence[int], int, None] = None, trim: bool = False
) -> Union[Sequence[Union[float, MaybeArray]], Union[float, MaybeArray]]:
Expand Down
4 changes: 4 additions & 0 deletions pypesto/optimize/optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import re
import time
import warnings
from functools import wraps
from typing import TYPE_CHECKING, Dict, Optional

import numpy as np
Expand Down Expand Up @@ -46,6 +47,7 @@ def history_decorator(minimize):
Default decorator for the minimize() method.
"""

@wraps(minimize)
def wrapped_minimize(
self,
problem: Problem,
Expand Down Expand Up @@ -129,6 +131,7 @@ def time_decorator(minimize):
the wall-clock time.
"""

@wraps(minimize)
def wrapped_minimize(
self,
problem: Problem,
Expand Down Expand Up @@ -160,6 +163,7 @@ def fix_decorator(minimize):
derivatives).
"""

@wraps(minimize)
def wrapped_minimize(
self,
problem: Problem,
Expand Down
4 changes: 2 additions & 2 deletions pypesto/predict/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class PredictorTask(Task):

def __init__(
self,
predictor: 'pypesto.predict.Predictor', # noqa: F821
predictor, #: 'pypesto.predict.Predictor', # noqa: F821
Copy link
Collaborator

Choose a reason for hiding this comment

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

is this also commented due to circular imports?

Copy link
Member Author

@dweindl dweindl Nov 20, 2023

Choose a reason for hiding this comment

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

No, because it doesn't exist 😑 . This whole module is not used anywhere. I think it could/should be removed, but I went for the more conservative approach.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, it should be pypesto.predict.AmiciPredictor I guess -- there is no parent Predictor class.

Copy link
Member Author

Choose a reason for hiding this comment

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

Possible, but not sure what was intended there, as it's really not used anywhere.

Copy link
Member Author

Choose a reason for hiding this comment

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

Was introduced in this monster, without usage #490

x: Sequence[float],
sensi_orders: Tuple[int, ...],
mode: ModeType,
Expand All @@ -41,7 +41,7 @@ def __init__(
self.mode = mode
self.id = id

def execute(self) -> 'pypesto.predict.PredictionResult': # noqa: F821
def execute(self): # -> 'pypesto.predict.PredictionResult': # noqa: F821
"""Execute and return the prediction."""
logger.debug(f"Executing task {self.id}.")
prediction = self.predictor(self.x, self.sensi_orders, self.mode)
Expand Down
3 changes: 1 addition & 2 deletions pypesto/select/method.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
Model,
)

from ..C import TYPE_POSTPROCESSOR
from ..problem import Problem
from .model_problem import ModelProblem
from .model_problem import TYPE_POSTPROCESSOR, ModelProblem


class MethodSignalProceed(str, Enum):
Expand Down
5 changes: 2 additions & 3 deletions pypesto/select/model_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@

from petab_select import Criterion, Model

from ..C import TYPE_POSTPROCESSOR
from ..objective import ObjectiveBase
from ..optimize import minimize
from ..problem import Problem
from ..result import OptimizerResult, Result
from .misc import model_to_pypesto_problem

OBJECTIVE_CUSTOMIZER_TYPE = Callable[[ObjectiveBase], None]
POSTPROCESSOR_TYPE = Callable[["ModelProblem"], None]
TYPE_POSTPROCESSOR = Callable[["ModelProblem"], None] # noqa: F821


class ModelProblem:
Expand Down Expand Up @@ -65,7 +64,7 @@ def __init__(
x_guess: List[float] = None,
minimize_options: Dict = None,
objective_customizer: Optional[OBJECTIVE_CUSTOMIZER_TYPE] = None,
postprocessor: Optional[TYPE_POSTPROCESSOR] = None,
postprocessor: Optional["TYPE_POSTPROCESSOR"] = None,
model_to_pypesto_problem_method: Callable[[Any], Problem] = None,
):
"""Construct then calibrate a model problem.
Expand Down
3 changes: 1 addition & 2 deletions pypesto/select/postprocessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
from petab_select.constants import ESTIMATE, TYPE_PATH, Criterion

from .. import store, visualize
from ..C import TYPE_POSTPROCESSOR
from .model_problem import ModelProblem
from .model_problem import TYPE_POSTPROCESSOR, ModelProblem

__all__ = [
'model_id_binary_postprocessor',
Expand Down
2 changes: 1 addition & 1 deletion pypesto/select/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import petab_select
from petab_select import Model

from ..C import TYPE_POSTPROCESSOR
from .method import MethodCaller
from .model_problem import TYPE_POSTPROCESSOR, ModelProblem # noqa: F401


class Problem:
Expand Down
11 changes: 6 additions & 5 deletions pypesto/visualize/ordinal_categories.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import warnings
from typing import Dict, List, Optional
from typing import TYPE_CHECKING, Dict, List, Optional

if TYPE_CHECKING:
import pypesto

import matplotlib.pyplot as plt
import numpy as np
Expand All @@ -14,9 +17,7 @@
from ..hierarchical.optimal_scaling.parameter import (
OptimalScalingParameter,
)
from ..hierarchical.optimal_scaling.problem import OptimalScalingProblem
from ..hierarchical.optimal_scaling.solver import (
OptimalScalingInnerSolver,
compute_interval_constraints,
get_bounds_for_category,
undo_inner_parameter_reparameterization,
Expand Down Expand Up @@ -155,8 +156,8 @@ def plot_categories_from_pypesto_result(


def plot_categories_from_inner_result(
inner_problem: 'OptimalScalingProblem',
inner_solver: 'OptimalScalingInnerSolver',
inner_problem: 'pypesto.hierarchical.optimal_scaling.problem.OptimalScalingProblem',
inner_solver: 'pypesto.hierarchical.optimal_scaling.solver.OptimalScalingInnerSolver',
results: List[Dict],
simulation: List[np.ndarray],
timepoints: List[np.ndarray],
Expand Down
5 changes: 3 additions & 2 deletions pypesto/visualize/spline_approximation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import matplotlib.pyplot as plt
import numpy as np

import pypesto

from ..C import AMICI_SIGMAY, AMICI_Y, CURRENT_SIMULATION, DATAPOINTS, SCIPY_X
from ..problem import Problem
from ..result import Result
Expand All @@ -15,7 +17,6 @@
from ..hierarchical.spline_approximation.calculator import (
SplineAmiciCalculator,
)
from ..hierarchical.spline_approximation.problem import SplineInnerProblem
from ..hierarchical.spline_approximation.solver import (
SplineInnerSolver,
get_spline_mapped_simulations,
Expand Down Expand Up @@ -114,7 +115,7 @@ def plot_splines_from_pypesto_result(


def plot_splines_from_inner_result(
inner_problem: 'SplineInnerProblem',
inner_problem: 'pypesto.hierarchical.spline_approximation.problem.SplineInnerProblem',
results: List[Dict],
observable_ids=None,
**kwargs,
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ description =

[testenv:doc]
extras =
doc,amici,petab,aesara,jax
doc,amici,petab,aesara,jax,select
commands =
sphinx-build -W -b html doc/ doc/_build/html
description =
Expand Down
Loading