Skip to content

Commit

Permalink
Propapagate type aliases through sphinx (#453)
Browse files Browse the repository at this point in the history
* type annotations fix in dynamical systems

* add type aliases for interventional

* add type aliases for observational

* add counterfactual doc type aliases

* lint
  • Loading branch information
SamWitty committed Dec 11, 2023
1 parent bf0674c commit af04458
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 2 deletions.
2 changes: 2 additions & 0 deletions chirho/counterfactual/handlers/counterfactual.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from typing import Any, Dict, Generic, Mapping, TypeVar

import pyro
Expand Down
2 changes: 2 additions & 0 deletions chirho/counterfactual/handlers/explanation.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import collections.abc
import contextlib
import functools
Expand Down
2 changes: 2 additions & 0 deletions chirho/counterfactual/ops.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import functools
from typing import Optional, Tuple, TypeVar

Expand Down
2 changes: 2 additions & 0 deletions chirho/dynamical/handlers/interruption.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import numbers
import typing
from typing import Callable, Generic, Tuple, TypeVar, Union
Expand Down
2 changes: 2 additions & 0 deletions chirho/dynamical/ops.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import numbers
from typing import Callable, Mapping, Optional, Tuple, TypeVar, Union

Expand Down
6 changes: 4 additions & 2 deletions chirho/interventional/handlers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import collections
import functools
from typing import Callable, Dict, Generic, Hashable, Mapping, Optional, TypeVar
Expand Down Expand Up @@ -41,7 +43,7 @@ def _intervene_atom(
def _intervene_atom_distribution(
obs: pyro.distributions.Distribution,
act: Optional[AtomicIntervention[pyro.distributions.Distribution]] = None,
**kwargs
**kwargs,
) -> pyro.distributions.Distribution:
"""
Intervene on a distribution in a probabilistic program.
Expand Down Expand Up @@ -70,7 +72,7 @@ def _dict_intervene(
def _intervene_callable(
obs: collections.abc.Callable,
act: Optional[CompoundIntervention[T]] = None,
**call_kwargs
**call_kwargs,
) -> Callable[..., T]:
if act is None:
return obs
Expand Down
2 changes: 2 additions & 0 deletions chirho/interventional/ops.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import functools
from typing import Callable, Hashable, Mapping, Optional, Tuple, TypeVar, Union

Expand Down
2 changes: 2 additions & 0 deletions chirho/observational/handlers/condition.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from typing import Callable, Generic, Hashable, Mapping, TypeVar, Union

import pyro
Expand Down
2 changes: 2 additions & 0 deletions chirho/observational/handlers/soft_conditioning.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import functools
import operator
from typing import Callable, Literal, Optional, Protocol, TypedDict, TypeVar, Union
Expand Down
2 changes: 2 additions & 0 deletions chirho/observational/internals.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from typing import Mapping, Optional, TypeVar

import pyro
Expand Down
2 changes: 2 additions & 0 deletions chirho/observational/ops.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import functools
from typing import Callable, Hashable, Mapping, Optional, TypeVar, Union

Expand Down
16 changes: 16 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,22 @@
author = 'Basis'


# -- Type hints configuration ------------------------------------------------

autodoc_type_aliases = {
'R': 'R',
'State': 'State',
'Dynamics': 'Dynamics',
'AtomicIntervention': 'AtomicIntervention',
'CompoundIntervention': 'CompoundIntervention',
'Intervention': 'Intervention',
'AtomicObservation': 'AtomicObservation',
'CompoundObservation': 'CompoundObservation',
'Observation': 'Observation',
'Kernel': 'Kernel',

}

# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
Expand Down

0 comments on commit af04458

Please sign in to comment.