|
| 1 | +# Copyright 2025 - present The PyMC Developers |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | + |
| 16 | +def __init__(): |
| 17 | + """Make PyMC aware of the xtensor functionality. |
| 18 | +
|
| 19 | + This should be done eagerly once development matures. |
| 20 | + """ |
| 21 | + import datetime |
| 22 | + import warnings |
| 23 | + |
| 24 | + from pytensor.compile import optdb |
| 25 | + |
| 26 | + from pymc.initial_point import initial_point_rewrites_db |
| 27 | + from pymc.logprob.abstract import MeasurableOp |
| 28 | + from pymc.logprob.rewriting import logprob_rewrites_db |
| 29 | + |
| 30 | + # Filter PyTensor xtensor warning, we emmit our own warning |
| 31 | + with warnings.catch_warnings(): |
| 32 | + warnings.simplefilter("ignore", UserWarning) |
| 33 | + import pytensor.xtensor |
| 34 | + |
| 35 | + from pytensor.xtensor.vectorization import XRV |
| 36 | + |
| 37 | + # Make PyMC aware of xtensor functionality |
| 38 | + MeasurableOp.register(XRV) |
| 39 | + lower_xtensor_query = optdb.query("+lower_xtensor") |
| 40 | + logprob_rewrites_db.register("lower_xtensor", lower_xtensor_query, "basic", position=0.1) |
| 41 | + initial_point_rewrites_db.register("lower_xtensor", lower_xtensor_query, "basic", position=0.1) |
| 42 | + |
| 43 | + # TODO: Better model of probability of bugs |
| 44 | + day_of_conception = datetime.date(2025, 6, 17) |
| 45 | + day_of_last_bug = datetime.date(2025, 6, 20) |
| 46 | + today = datetime.date.today() |
| 47 | + days_with_bugs = (day_of_last_bug - day_of_conception).days |
| 48 | + days_without_bugs = (today - day_of_last_bug).days |
| 49 | + p = 1 - (days_without_bugs / (days_without_bugs + days_with_bugs + 10)) |
| 50 | + if p > 0.05: |
| 51 | + warnings.warn( |
| 52 | + f"The `pymc.dims` module is experimental and may contain critical bugs (p={p:.3f}).\n" |
| 53 | + "Please report any issues you encounter at https://github.com/pymc-devs/pymc/issues.\n" |
| 54 | + "Disclaimer: This an experimental API and may change at any time.", |
| 55 | + UserWarning, |
| 56 | + stacklevel=2, |
| 57 | + ) |
| 58 | + |
| 59 | + |
| 60 | +__init__() |
| 61 | +del __init__ |
| 62 | + |
| 63 | +from pytensor.xtensor import as_xtensor, concat |
| 64 | + |
| 65 | +from pymc.dims import math |
| 66 | +from pymc.dims.distributions import * |
| 67 | +from pymc.dims.model import Data, Deterministic, Potential, with_dims |
0 commit comments