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

Add ZarrTrace and fix non-determinism with Generators in sample #7540

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
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: 2 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ jobs:

- |
tests/backends/test_mcbackend.py
tests/backends/test_zarr.py
tests/distributions/test_truncated.py
tests/logprob/test_abstract.py
tests/logprob/test_basic.py
Expand Down Expand Up @@ -240,6 +241,7 @@ jobs:

- |
tests/backends/test_arviz.py
tests/backends/test_zarr.py
tests/variational/test_updates.py
fail-fast: false
runs-on: ${{ matrix.os }}
Expand Down
1 change: 1 addition & 0 deletions conda-envs/environment-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ dependencies:
- scipy>=1.4.1
- typing-extensions>=3.7.4
- threadpoolctl>=3.1.0
- zarr>=2.5.0,<3
# Extra dependencies for dev, testing and docs build
- ipython>=7.16
- jax
Expand Down
1 change: 1 addition & 0 deletions conda-envs/environment-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ dependencies:
- scipy>=1.4.1
- typing-extensions>=3.7.4
- threadpoolctl>=3.1.0
- zarr>=2.5.0,<3
# Extra dependencies for docs build
- ipython>=7.16
- jax
Expand Down
1 change: 1 addition & 0 deletions conda-envs/environment-jax.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ dependencies:
- cachetools>=4.2.1
- cloudpickle
- h5py>=2.7
- zarr>=2.5.0,<3
# Jaxlib version must not be greater than jax version!
- blackjax>=1.2.2
- jax>=0.4.28
Expand Down
1 change: 1 addition & 0 deletions conda-envs/environment-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ dependencies:
- scipy>=1.4.1
- typing-extensions>=3.7.4
- threadpoolctl>=3.1.0
- zarr>=2.5.0,<3
# Extra dependencies for testing
- ipython>=7.16
- pre-commit>=2.8.0
Expand Down
1 change: 1 addition & 0 deletions conda-envs/windows-environment-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ dependencies:
- scipy>=1.4.1
- typing-extensions>=3.7.4
- threadpoolctl>=3.1.0
- zarr>=2.5.0,<3
# Extra dependencies for dev, testing and docs build
- ipython>=7.16
- myst-nb<=1.0.0
Expand Down
1 change: 1 addition & 0 deletions conda-envs/windows-environment-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ dependencies:
- scipy>=1.4.1
- typing-extensions>=3.7.4
- threadpoolctl>=3.1.0
- zarr>=2.5.0,<3
# Extra dependencies for testing
- ipython>=7.16
- pre-commit>=2.8.0
Expand Down
2 changes: 2 additions & 0 deletions docs/source/api/backends.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ Internal structures
NDArray
base.BaseTrace
base.MultiTrace
zarr.ZarrTrace
zarr.ZarrChain
1 change: 1 addition & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@
"python": ("https://docs.python.org/3/", None),
"scipy": ("https://docs.scipy.org/doc/scipy/", None),
"xarray": ("https://docs.xarray.dev/en/stable/", None),
"zarr": ("https://zarr.readthedocs.io/en/stable/", None),
}


Expand Down
15 changes: 14 additions & 1 deletion pymc/backends/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
from pymc.backends.arviz import predictions_to_inference_data, to_inference_data
from pymc.backends.base import BaseTrace, IBaseTrace
from pymc.backends.ndarray import NDArray
from pymc.backends.zarr import ZarrTrace
from pymc.blocking import PointType
from pymc.model import Model
from pymc.step_methods.compound import BlockedStep, CompoundStep
Expand Down Expand Up @@ -120,15 +121,27 @@ def _init_trace(

def init_traces(
*,
backend: TraceOrBackend | None,
backend: TraceOrBackend | ZarrTrace | None,
chains: int,
expected_length: int,
step: BlockedStep | CompoundStep,
initial_point: PointType,
model: Model,
trace_vars: list[TensorVariable] | None = None,
tune: int = 0,
) -> tuple[RunType | None, Sequence[IBaseTrace]]:
"""Initialize a trace recorder for each chain."""
if isinstance(backend, ZarrTrace):
backend.init_trace(
chains=chains,
draws=expected_length - tune,
tune=tune,
step=step,
model=model,
vars=trace_vars,
test_point=initial_point,
)
return None, backend.straces
if HAS_MCB and isinstance(backend, Backend):
return init_chain_adapters(
backend=backend,
Expand Down
Loading
Loading