diff --git a/CHANGELOG.md b/CHANGELOG.md index a07cb81..d9ef800 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,22 @@ All notable changes to this project will be documented in this file. +## [0.15.1] - 2025-05-28 + +### Bug Fixes + +- Incorrect results with non-contiguous shared variable (Adrian Seyboldt) + +- Allow upper case backend string (Adrian Seyboldt) + +- Allow data named x with unfrozen model (Adrian Seyboldt) + + +### Styling + +- Fix small typing issue (Adrian Seyboldt) + + ## [0.15.0] - 2025-05-27 ### Bug Fixes @@ -39,7 +55,9 @@ All notable changes to this project will be documented in this file. - Add entries to gitignore (Adrian Seyboldt) -- Bump dependencies (Adrian Seyboldt) +- Update dependencies (Adrian Seyboldt) + +- Update changelog (Adrian Seyboldt) ### Styling diff --git a/Cargo.lock b/Cargo.lock index a3aa5e7..b3fbdce 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -445,18 +445,18 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.38" +version = "4.5.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed93b9805f8ba930df42c2590f05453d5ec36cbb85d018868a5b24d31f6ac000" +checksum = "fd60e63e9be68e5fb56422e397cf9baddded06dae1d2e523401542383bc72a9f" dependencies = [ "clap_builder", ] [[package]] name = "clap_builder" -version = "4.5.38" +version = "4.5.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "379026ff283facf611b0ea629334361c4211d1b12ee01024eec1591133b04120" +checksum = "89cc6392a1f72bbeb820d71f32108f61fdaf18bc526e1d23954168a67759ef51" dependencies = [ "anstyle", "clap_lex", @@ -1363,7 +1363,7 @@ dependencies = [ [[package]] name = "nutpie" -version = "0.15.0" +version = "0.15.1" dependencies = [ "anyhow", "arrow", diff --git a/Cargo.toml b/Cargo.toml index 84081ed..c8c7bf3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "nutpie" -version = "0.15.0" +version = "0.15.1" authors = [ "Adrian Seyboldt ", "PyMC Developers ", diff --git a/python/nutpie/compile_pymc.py b/python/nutpie/compile_pymc.py index c714146..36a3a09 100644 --- a/python/nutpie/compile_pymc.py +++ b/python/nutpie/compile_pymc.py @@ -32,7 +32,7 @@ def intrinsic(f): def _rv_dict_to_flat_array_wrapper( - fn: Callable[[SeedType], dict[str, np.ndarray]], + fn: Callable[[SeedType | None], dict[str, np.ndarray]], names: list[str], shapes: list[tuple[int]], ) -> Callable[[SeedType], np.ndarray]: @@ -61,7 +61,7 @@ def _rv_dict_to_flat_array_wrapper( """ @wraps(fn) - def seeded_array_fn(seed: SeedType = None): + def seeded_array_fn(seed: SeedType | None = None): initial_value_dict = fn(seed) total_size = sum(np.prod(shape).astype(int) for shape in shapes) flat_array = np.empty(total_size, dtype="float64", order="C") @@ -406,8 +406,8 @@ def logp_fn_jax_grad(x, *shared): seen.add(val) def make_logp_func(): - def logp(x, **shared): - logp, grad = logp_fn(x, *[shared[name] for name in logp_shared_names]) + def logp(_x, **shared): + logp, grad = logp_fn(_x, *[shared[name] for name in logp_shared_names]) return float(logp), np.asarray(grad, dtype="float64", order="C") return logp @@ -418,8 +418,8 @@ def logp(x, **shared): def make_expand_func(seed1, seed2, chain): # TODO handle seeds - def expand(x, **shared): - values = expand_fn(x, *[shared[name] for name in expand_shared_names]) + def expand(_x, **shared): + values = expand_fn(_x, *[shared[name] for name in expand_shared_names]) return { name: np.asarray(val, order="C", dtype=dtype).ravel() for name, val, dtype in zip(names, values, dtypes, strict=True) @@ -499,6 +499,11 @@ def compile_pymc_model( "and restart your kernel in case you are in an interactive session." ) + if gradient_backend is not None: + gradient_backend = gradient_backend.lower() # type: ignore[assignment] + if backend is not None: + backend = backend.lower() # type: ignore[assignment] + from pymc.model.transform.optimization import freeze_dims_and_data from pymc.initial_point import make_initial_point_fn diff --git a/tests/test_pymc.py b/tests/test_pymc.py index 938f36c..e710aae 100644 --- a/tests/test_pymc.py +++ b/tests/test_pymc.py @@ -31,6 +31,21 @@ def test_pymc_model(backend, gradient_backend): trace.posterior.a # noqa: B018 +@pytest.mark.pymc +@parameterize_backends +def test_name_x(backend, gradient_backend): + with pm.Model() as model: + x = pm.Data("x", 1.0) + a = pm.Normal("a", mu=x) + pm.Deterministic("z", x * a) + + compiled = nutpie.compile_pymc_model( + model, backend=backend, gradient_backend=gradient_backend, freeze_model=False + ) + trace = nutpie.sample(compiled, chains=1) + trace.posterior.a # noqa: B018 + + @pytest.mark.pymc def test_order_shared(): a_val = np.array([[0.0, 1.0, 2.0], [3.0, 4.0, 5.0]])