-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add experimental dims
module with objects that follow dim-based semantics (like xarray)
#7820
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
base: main
Are you sure you want to change the base?
Changes from all commits
7416be2
5d02b63
0bb3bd1
1931859
17f503f
6440d6e
e713339
174818e
58c6a97
33be94f
1c6d249
3f5611a
ab026f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# Copyright 2025 - present The PyMC Developers | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
|
||
def __init__(): | ||
"""Make PyMC aware of the xtensor functionality. | ||
|
||
This should be done eagerly once development matures. | ||
""" | ||
import datetime | ||
import warnings | ||
|
||
from pytensor.compile import optdb | ||
|
||
from pymc.initial_point import initial_point_rewrites_db | ||
from pymc.logprob.abstract import MeasurableOp | ||
from pymc.logprob.rewriting import logprob_rewrites_db | ||
|
||
# Filter PyTensor xtensor warning, we emmit our own warning | ||
with warnings.catch_warnings(): | ||
warnings.simplefilter("ignore", UserWarning) | ||
import pytensor.xtensor | ||
|
||
from pytensor.xtensor.vectorization import XRV | ||
|
||
# Make PyMC aware of xtensor functionality | ||
MeasurableOp.register(XRV) | ||
logprob_rewrites_db.register( | ||
"pre_lower_xtensor", optdb.query("+lower_xtensor"), "basic", position=0.1 | ||
) | ||
logprob_rewrites_db.register( | ||
"post_lower_xtensor", optdb.query("+lower_xtensor"), "cleanup", position=5.1 | ||
) | ||
initial_point_rewrites_db.register( | ||
"lower_xtensor", optdb.query("+lower_xtensor"), "basic", position=0.1 | ||
) | ||
|
||
# TODO: Better model of probability of bugs | ||
day_of_conception = datetime.date(2025, 6, 17) | ||
day_of_last_bug = datetime.date(2025, 6, 30) | ||
today = datetime.date.today() | ||
days_with_bugs = (day_of_last_bug - day_of_conception).days | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wtf 😆 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This has two purposes: distract reviewers so they don't focus on the critical changes, and prove that OSS libraries can't be fun. |
||
days_without_bugs = (today - day_of_last_bug).days | ||
p = 1 - (days_without_bugs / (days_without_bugs + days_with_bugs + 10)) | ||
if p > 0.05: | ||
warnings.warn( | ||
f"The `pymc.dims` module is experimental and may contain critical bugs (p={p:.3f}).\n" | ||
"Please report any issues you encounter at https://github.com/pymc-devs/pymc/issues.\n" | ||
"Disclaimer: This an experimental API and may change at any time.", | ||
UserWarning, | ||
stacklevel=2, | ||
) | ||
|
||
|
||
__init__() | ||
del __init__ | ||
|
||
from pytensor.xtensor import as_xtensor, concat | ||
|
||
from pymc.dims import math | ||
from pymc.dims.distributions import * | ||
from pymc.dims.model import Data, Deterministic, Potential |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Copyright 2025 - present The PyMC Developers | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
from pymc.dims.distributions.scalar import * | ||
from pymc.dims.distributions.vector import * |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inside the notebook you have to use myst syntax, so you'll have to replace the
:reftype:`reftarget`
with{reftype}`reftarget`