From e72a8164134381676a27f0ef6f3b0bf9d4cc6b49 Mon Sep 17 00:00:00 2001 From: Adrian Price-Whelan Date: Mon, 19 Aug 2024 15:58:42 -0400 Subject: [PATCH 01/17] update min version and some publishing stuff --- .github/workflows/cd.yml | 3 ++- pyproject.toml | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index b088283..ce4d5d1 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -9,6 +9,7 @@ on: release: types: - published + - edited concurrency: group: ${{ github.workflow }}-${{ github.ref }} @@ -71,7 +72,7 @@ jobs: permissions: id-token: write runs-on: ubuntu-latest - if: github.event_name == 'release' && github.event.action == 'published' + if: github.event_name == 'release' && (github.event.action == 'published' || github.event.action == 'edited') steps: - name: Download packages built by build-and-inspect-python-package diff --git a/pyproject.toml b/pyproject.toml index 067acf2..137c38f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,10 +2,10 @@ requires = [ "setuptools>=64", "setuptools_scm>=8", - "numpy", + "numpy>=2.0", "scipy", "cython", - "twobody" + "twobody>=0.9.1", ] build-backend = 'setuptools.build_meta' @@ -14,13 +14,13 @@ name = "thejoker" authors = [{name = "Adrian Price-Whelan", email = "adrianmpw@gmail.com"}] description = "A custom Monte Carlo sampler for the two-body problem." readme = "README.rst" -requires-python = ">=3.9" +requires-python = ">=3.10" license.file = "LICENSE" dynamic = ["version"] dependencies = [ "astropy", - "numpy", - "twobody>=0.9", + "numpy>=1.24.4", + "twobody>=0.9.1", "scipy", "h5py", "schwimmbad>=0.4", From 2d03dfe486963b804cc8de446a0987128e7dbc6b Mon Sep 17 00:00:00 2001 From: Adrian Price-Whelan Date: Mon, 19 Aug 2024 16:02:10 -0400 Subject: [PATCH 02/17] drop 3.9 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 51d6f28..d6a6d2b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,7 +18,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - python-version: ["3.9", "3.10", "3.11"] + python-version: ["3.10", "3.11", "3.12"] os: ["ubuntu-latest", "macos-latest"] steps: From 83d60f4bbb1200e03cfb6843e713ffa59a08d61e Mon Sep 17 00:00:00 2001 From: Adrian Price-Whelan Date: Mon, 19 Aug 2024 16:07:10 -0400 Subject: [PATCH 03/17] brew install hdf5 and remove tables pin --- .github/workflows/ci.yml | 8 ++++++++ pyproject.toml | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d6a6d2b..03e567b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,6 +29,14 @@ jobs: with: python-version: ${{ matrix.python-version }} + - name: "Install hdf5 for tables (linux)" + if: runner.os == 'ubuntu-latest' + run: sudo apt-get install libhdf5-serial-dev + + - name : "Install hdf5 for tables (mac)" + if: runner.os == 'macos-latest' + run: brew install hdf5 + - name: Install dependencies run: | python -m pip install -U pip diff --git a/pyproject.toml b/pyproject.toml index 137c38f..a9adba5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,7 +27,7 @@ dependencies = [ "pymc>=5", "pymc_ext>=1.0.1", "exoplanet-core[pymc]>=0.3.0", - "tables<3.9.2", # https://github.com/PyTables/PyTables/issues/1093 + "tables", "dill" ] From 46692771fce7c230147c4ad250ee62ab48923328 Mon Sep 17 00:00:00 2001 From: Adrian Price-Whelan Date: Mon, 19 Aug 2024 16:31:40 -0400 Subject: [PATCH 04/17] remove old RV class attrs --- thejoker/distributions.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/thejoker/distributions.py b/thejoker/distributions.py index b8441b0..d14f816 100644 --- a/thejoker/distributions.py +++ b/thejoker/distributions.py @@ -13,9 +13,6 @@ class UniformLogRV(RandomVariable): name = "uniformlog" - ndim_supp = 0 - ndims_params = [0, 0] - dtype = "floatX" @classmethod def rng_fn(cls, rng, a, b, size): From cbe24d5e57707c871139e1bade1c2ea35c7ca598 Mon Sep 17 00:00:00 2001 From: Adrian Price-Whelan Date: Mon, 19 Aug 2024 21:20:44 -0400 Subject: [PATCH 05/17] catch old and new pymc RV behavior --- thejoker/distributions.py | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/thejoker/distributions.py b/thejoker/distributions.py index d14f816..d3ca487 100644 --- a/thejoker/distributions.py +++ b/thejoker/distributions.py @@ -3,22 +3,43 @@ import numpy as np import pymc as pm import pytensor.tensor as pt +from packaging.version import Version from pymc.distributions.dist_math import check_parameters from pytensor.tensor.random.basic import NormalRV, RandomVariable from thejoker.units import UNIT_ATTR_NAME +PYMC_GT_516 = Version(pm.__version__) >= Version("5.16.0") + __all__ = ["UniformLog", "FixedCompanionMass"] -class UniformLogRV(RandomVariable): - name = "uniformlog" +if PYMC_GT_516: - @classmethod - def rng_fn(cls, rng, a, b, size): - _fac = np.log(b) - np.log(a) - uu = rng.uniform(size=size) - return np.exp(uu * _fac + np.log(a)) + class UniformLogRV(RandomVariable): + name: str = "uniformlog" + dtype: str = "floatX" + signature: str = "(),()->()" + + @classmethod + def rng_fn(cls, rng, a, b, size): + _fac = np.log(b) - np.log(a) + uu = rng.uniform(size=size) + return np.exp(uu * _fac + np.log(a)) + +else: # old behavior + + class UniformLogRV(RandomVariable): + name: str = "uniformlog" + dtype: str = "floatX" + ndim_supp: int = 0 + ndims_params: list[int] = [0, 0] + + @classmethod + def rng_fn(cls, rng, a, b, size): + _fac = np.log(b) - np.log(a) + uu = rng.uniform(size=size) + return np.exp(uu * _fac + np.log(a)) uniformlog = UniformLogRV() From 0c3b93bd30ee0abc0bd44302fd3c56b024e57ca0 Mon Sep 17 00:00:00 2001 From: Adrian Price-Whelan Date: Mon, 19 Aug 2024 21:21:28 -0400 Subject: [PATCH 06/17] new pytensor behavior - closes #134 --- thejoker/src/fast_likelihood.pyx | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/thejoker/src/fast_likelihood.pyx b/thejoker/src/fast_likelihood.pyx index 2c1e9f4..e441b83 100644 --- a/thejoker/src/fast_likelihood.pyx +++ b/thejoker/src/fast_likelihood.pyx @@ -17,6 +17,11 @@ cimport cython cimport scipy.linalg.cython_lapack as lapack import thejoker.units as xu +# Change of behavior: +import pytensor +from packaging.version import Version +PYTENSOR_GT_223 = Version(pytensor.__version__) >= Version("2.23.0") + # from libc.stdio cimport printf from libc.math cimport pow, log, fabs, pi @@ -232,13 +237,20 @@ cdef class CJokerHelper: to_unit = self.internal_units[name] dist = prior.model[name] - # first three are (rng, size, dtype) as per - # https://github.com/pymc-devs/pymc/blob/main/pymc/printing.py#L43 - pars = dist.owner.inputs[3:] - # mean is par 0 - mu = (pars[0].eval() * _unit).to_value(to_unit) - std = (pars[1].eval() * _unit).to_value(to_unit) + if PYTENSOR_GT_223: + # See: https://github.com/pymc-devs/pytensor/releases/tag/rel-2.23.0 + dist_params = dist.owner.op.dist_params(dist.owner) + mu = (dist_params[0].eval() * _unit).to_value(to_unit) + std = (dist_params[1].eval() * _unit).to_value(to_unit) + else: # old behavior + # first three are (rng, size, dtype) as per + # https://github.com/pymc-devs/pymc/blob/main/pymc/printing.py#L43 + pars = dist.owner.inputs[3:] + + # mean is par 0 + mu = (pars[0].eval() * _unit).to_value(to_unit) + std = (pars[1].eval() * _unit).to_value(to_unit) if name == 'K' and self.fixed_K_prior == 0: # TODO: here's the major hack From 85b491f7e0524f7d0653283f10b2a70c023091bc Mon Sep 17 00:00:00 2001 From: Adrian Price-Whelan Date: Mon, 19 Aug 2024 21:22:01 -0400 Subject: [PATCH 07/17] test old pymc --- .github/workflows/ci.yml | 48 +++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 03e567b..f40fa26 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,31 +20,39 @@ jobs: matrix: python-version: ["3.10", "3.11", "3.12"] os: ["ubuntu-latest", "macos-latest"] + pymc-version: ["latest"] + include: + - os: ubuntu-latest + pymc-version: "5.0.0" steps: + - uses: actions/checkout@v4 - - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python-version }} + - name: "Install hdf5 for tables (linux)" + if: runner.os == 'ubuntu-latest' + run: sudo apt-get install libhdf5-serial-dev - - name: "Install hdf5 for tables (linux)" - if: runner.os == 'ubuntu-latest' - run: sudo apt-get install libhdf5-serial-dev + - name : "Install hdf5 for tables (mac)" + if: runner.os == 'macos-latest' + run: brew install hdf5 - - name : "Install hdf5 for tables (mac)" - if: runner.os == 'macos-latest' - run: brew install hdf5 + - name: Install dependencies + run: | + python -m pip install -U pip + python -m pip install -e .[test] - - name: Install dependencies - run: | - python -m pip install -U pip - python -m pip install -e .[test] + - name: Correct pymc version + if: matrix.pymc-version != 'latest' + run: | + python -m pip install pymc==${{ matrix.pymc-version }} - - name: Test package - run: >- - python -m pytest -ra --cov --cov-report=xml --cov-report=term --durations=20 + - name: Test package + run: >- + python -m pytest -ra --cov --cov-report=xml --cov-report=term --durations=20 - - name: Upload coverage report - uses: codecov/codecov-action@v4.1.0 \ No newline at end of file + - name: Upload coverage report + uses: codecov/codecov-action@v4.1.0 \ No newline at end of file From cc668b9c3121e8966998a3ebc25571d9a1c67485 Mon Sep 17 00:00:00 2001 From: Adrian Price-Whelan Date: Mon, 19 Aug 2024 21:22:56 -0400 Subject: [PATCH 08/17] oops also match python version --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f40fa26..26dbb87 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,6 +23,7 @@ jobs: pymc-version: ["latest"] include: - os: ubuntu-latest + python-version: "3.10" pymc-version: "5.0.0" steps: - uses: actions/checkout@v4 From 311035f3278c25dbc507612bca9d2f679f994c56 Mon Sep 17 00:00:00 2001 From: Adrian Price-Whelan Date: Mon, 19 Aug 2024 21:30:56 -0400 Subject: [PATCH 09/17] remove moment --- thejoker/distributions.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/thejoker/distributions.py b/thejoker/distributions.py index d3ca487..41a4b8f 100644 --- a/thejoker/distributions.py +++ b/thejoker/distributions.py @@ -58,9 +58,6 @@ def support_point(rv, size, a, b): a, b = pt.broadcast_arrays(a, b) return 0.5 * (a + b) - # TODO: remove this once new pymc version is released - moment = support_point - def logp(value, a, b): _fac = pt.log(b) - pt.log(a) res = -pt.as_tensor_variable(value) - pt.log(_fac) From 437071e43be1b8c1ff13a562b0086340bc0e36b3 Mon Sep 17 00:00:00 2001 From: Adrian Price-Whelan Date: Mon, 19 Aug 2024 21:49:32 -0400 Subject: [PATCH 10/17] dot for this dir --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 26dbb87..6bcfd56 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -53,7 +53,7 @@ jobs: - name: Test package run: >- - python -m pytest -ra --cov --cov-report=xml --cov-report=term --durations=20 + python -m pytest -ra --cov --cov-report=xml --cov-report=term --durations=20 . - name: Upload coverage report uses: codecov/codecov-action@v4.1.0 \ No newline at end of file From df62fa1335c3497c5ebf2600921663a399e49b67 Mon Sep 17 00:00:00 2001 From: Adrian Price-Whelan Date: Mon, 19 Aug 2024 21:49:44 -0400 Subject: [PATCH 11/17] add helper function for getting mean stddev from a dist --- thejoker/src/fast_likelihood.pyx | 21 ++------------------- thejoker/src/tests/py_likelihood.py | 15 ++++++++------- thejoker/utils.py | 24 ++++++++++++++++++++++-- 3 files changed, 32 insertions(+), 28 deletions(-) diff --git a/thejoker/src/fast_likelihood.pyx b/thejoker/src/fast_likelihood.pyx index e441b83..2363a12 100644 --- a/thejoker/src/fast_likelihood.pyx +++ b/thejoker/src/fast_likelihood.pyx @@ -16,11 +16,7 @@ import cython cimport cython cimport scipy.linalg.cython_lapack as lapack import thejoker.units as xu - -# Change of behavior: -import pytensor -from packaging.version import Version -PYTENSOR_GT_223 = Version(pytensor.__version__) >= Version("2.23.0") +from thejoker.utils import _pytensor_get_mean_std # from libc.stdio cimport printf from libc.math cimport pow, log, fabs, pi @@ -237,20 +233,7 @@ cdef class CJokerHelper: to_unit = self.internal_units[name] dist = prior.model[name] - - if PYTENSOR_GT_223: - # See: https://github.com/pymc-devs/pytensor/releases/tag/rel-2.23.0 - dist_params = dist.owner.op.dist_params(dist.owner) - mu = (dist_params[0].eval() * _unit).to_value(to_unit) - std = (dist_params[1].eval() * _unit).to_value(to_unit) - else: # old behavior - # first three are (rng, size, dtype) as per - # https://github.com/pymc-devs/pymc/blob/main/pymc/printing.py#L43 - pars = dist.owner.inputs[3:] - - # mean is par 0 - mu = (pars[0].eval() * _unit).to_value(to_unit) - std = (pars[1].eval() * _unit).to_value(to_unit) + mu, std = _pytensor_get_mean_std(dist, _unit, to_unit) if name == 'K' and self.fixed_K_prior == 0: # TODO: here's the major hack diff --git a/thejoker/src/tests/py_likelihood.py b/thejoker/src/tests/py_likelihood.py index 6389b38..44eb02d 100644 --- a/thejoker/src/tests/py_likelihood.py +++ b/thejoker/src/tests/py_likelihood.py @@ -8,7 +8,8 @@ from astroML.utils import log_multivariate_gaussian from twobody.wrap import cy_rv_from_elements -from ...samples import JokerSamples +from thejoker.samples import JokerSamples +from thejoker.utils import _pytensor_get_mean_std __all__ = ["get_ivar", "likelihood_worker", "marginal_ln_likelihood"] @@ -141,20 +142,20 @@ def get_M_Lambda_ivar(samples, prior, data): n_linear = len(prior._linear_equiv_units) Lambda = np.zeros(n_linear) - for i, k in enumerate(prior._linear_equiv_units.keys()): - if k == "K": + for i, name in enumerate(prior._linear_equiv_units.keys()): + if name == "K": continue # set below - pars = prior.pars[k].owner.inputs[3:] - Lambda[i] = pars[1].eval() ** 2 + _, std = _pytensor_get_mean_std(prior.pars[name], u.one, u.one) + Lambda[i] = std**2 K_dist = prior.pars["K"] - K_pars = K_dist.owner.inputs[3:] if K_dist.owner.op._print_name[0] == "FixedCompanionMass": sigma_K0 = K_dist._sigma_K0.to_value(v_unit) P0 = K_dist._P0.to_value(samples["P"].unit) max_K2 = K_dist._max_K.to_value(v_unit) ** 2 else: - Lambda[0] = K_pars[1].eval() ** 2 + _, std = _pytensor_get_mean_std(K_dist, u.one, u.one) + Lambda[0] = std**2 for n in range(n_samples): M = design_matrix(packed_samples[n], data, prior) diff --git a/thejoker/utils.py b/thejoker/utils.py index 4fd6b22..9346188 100644 --- a/thejoker/utils.py +++ b/thejoker/utils.py @@ -1,20 +1,20 @@ """Miscellaneous utilities""" -# Standard library import contextlib import inspect import os from functools import wraps from tempfile import NamedTemporaryFile -# Third-party import astropy.units as u import h5py import numpy as np +import pytensor import tables as tb from astropy.io.misc.hdf5 import meta_path from astropy.table.meta import get_header_from_yaml from astropy.utils.decorators import deprecated_renamed_argument +from packaging.version import Version __all__ = ["batch_tasks", "table_header_to_units", "read_batch", "tempfile_decorator"] @@ -312,3 +312,23 @@ def rng_context(rng): finally: if rng is not None: np.random.set_bit_generator(pre_state) + + +def _pytensor_get_mean_std(dist, in_unit, out_unit): + PYTENSOR_GT_223 = Version(pytensor.__version__) >= Version("2.23.0") + + if PYTENSOR_GT_223: + # See: https://github.com/pymc-devs/pytensor/releases/tag/rel-2.23.0 + dist_params = dist.owner.op.dist_params(dist.owner) + mu = dist_params[0].eval() + std = dist_params[1].eval() + else: # old behavior + # first three are (rng, size, dtype) as per + # https://github.com/pymc-devs/pymc/blob/main/pymc/printing.py#L43 + pars = dist.owner.inputs[3:] + + # mean is par 0 + mu = pars[0].eval() + std = pars[1].eval() + + return (mu * in_unit).to_value(out_unit), (std * in_unit).to_value(out_unit) From 230900a37de68f2ad591bce7f432c32058619863 Mon Sep 17 00:00:00 2001 From: Adrian Price-Whelan Date: Mon, 19 Aug 2024 22:02:11 -0400 Subject: [PATCH 12/17] update oldest pymc version --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6bcfd56..129646d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,7 +24,7 @@ jobs: include: - os: ubuntu-latest python-version: "3.10" - pymc-version: "5.0.0" + pymc-version: "5.10.0" # Oldest pymc version steps: - uses: actions/checkout@v4 From cbe5db90ec9691308261af148cc62e69050ba93f Mon Sep 17 00:00:00 2001 From: Adrian Price-Whelan Date: Mon, 19 Aug 2024 22:09:59 -0400 Subject: [PATCH 13/17] use moment for older pymc --- thejoker/distributions.py | 71 ++++++++++++++++++++++++++------------- 1 file changed, 48 insertions(+), 23 deletions(-) diff --git a/thejoker/distributions.py b/thejoker/distributions.py index 41a4b8f..299002e 100644 --- a/thejoker/distributions.py +++ b/thejoker/distributions.py @@ -27,6 +27,30 @@ def rng_fn(cls, rng, a, b, size): uu = rng.uniform(size=size) return np.exp(uu * _fac + np.log(a)) + uniformlog = UniformLogRV() + + class UniformLog(pm.Continuous): + rv_op = uniformlog + + @classmethod + def dist(cls, a, b, **kwargs): + a = pt.as_tensor_variable(a) + b = pt.as_tensor_variable(b) + return super().dist([a, b], **kwargs) + + def support_point(rv, size, a, b): + a, b = pt.broadcast_arrays(a, b) + return 0.5 * (a + b) + + def logp(value, a, b): + _fac = pt.log(b) - pt.log(a) + res = -pt.as_tensor_variable(value) - pt.log(_fac) + return check_parameters( + res, + (a > 0) & (a < b), + msg="a > 0 and a < b", + ) + else: # old behavior class UniformLogRV(RandomVariable): @@ -41,31 +65,32 @@ def rng_fn(cls, rng, a, b, size): uu = rng.uniform(size=size) return np.exp(uu * _fac + np.log(a)) + uniformlog = UniformLogRV() -uniformlog = UniformLogRV() - + class UniformLog(pm.Continuous): + rv_op = uniformlog -class UniformLog(pm.Continuous): - rv_op = uniformlog - - @classmethod - def dist(cls, a, b, **kwargs): - a = pt.as_tensor_variable(a) - b = pt.as_tensor_variable(b) - return super().dist([a, b], **kwargs) - - def support_point(rv, size, a, b): - a, b = pt.broadcast_arrays(a, b) - return 0.5 * (a + b) - - def logp(value, a, b): - _fac = pt.log(b) - pt.log(a) - res = -pt.as_tensor_variable(value) - pt.log(_fac) - return check_parameters( - res, - (a > 0) & (a < b), - msg="a > 0 and a < b", - ) + @classmethod + def dist(cls, a, b, **kwargs): + a = pt.as_tensor_variable(a) + b = pt.as_tensor_variable(b) + return super().dist([a, b], **kwargs) + + def support_point(rv, size, a, b): + a, b = pt.broadcast_arrays(a, b) + return 0.5 * (a + b) + + # TODO: remove this once new pymc version is released + moment = support_point + + def logp(value, a, b): + _fac = pt.log(b) - pt.log(a) + res = -pt.as_tensor_variable(value) - pt.log(_fac) + return check_parameters( + res, + (a > 0) & (a < b), + msg="a > 0 and a < b", + ) class FixedCompanionMassRV(NormalRV): From d77fd76e5807332e4e0f251716d912848f85b043 Mon Sep 17 00:00:00 2001 From: Adrian Price-Whelan Date: Tue, 20 Aug 2024 09:13:01 -0400 Subject: [PATCH 14/17] rearrange directives --- thejoker/src/fast_likelihood.pyx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/thejoker/src/fast_likelihood.pyx b/thejoker/src/fast_likelihood.pyx index 2363a12..e8770c7 100644 --- a/thejoker/src/fast_likelihood.pyx +++ b/thejoker/src/fast_likelihood.pyx @@ -1,10 +1,12 @@ # coding: utf-8 # cython: boundscheck=False # cython: nonecheck=False -# cython: cdivision=True # cython: wraparound=False # cython: initializedcheck=False +# cython: overflowcheck=False +# cython: linetrace=False # cython: profile=False +# cython: cdivision=True # cython: language_level=3 # Third-party From 8008cdfd9d5160dc243f94667d946ab965d71c83 Mon Sep 17 00:00:00 2001 From: Adrian Price-Whelan Date: Tue, 20 Aug 2024 10:15:07 -0400 Subject: [PATCH 15/17] catch dead kernel --- docs/run_notebooks.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/docs/run_notebooks.py b/docs/run_notebooks.py index cb82e64..9fe35a7 100644 --- a/docs/run_notebooks.py +++ b/docs/run_notebooks.py @@ -47,6 +47,14 @@ def process_notebook(filename, kernel_name=None): nbsphinx_kernel_name = os.environ.get("NBSPHINX_KERNEL", "python3") for filename in sorted(glob.glob(pattern)): - success = process_notebook(filename, kernel_name=nbsphinx_kernel_name) + try: + success = process_notebook(filename, kernel_name=nbsphinx_kernel_name) + except Exception as e: + print(f"Error while processing: {filename}") + print(e) + success = False + if not success: sys.exit(1) + + print(f"✅ Processed: {filename}") From 444d42e7dfaf39a6cbe2968a83aaba166559f362 Mon Sep 17 00:00:00 2001 From: Adrian Price-Whelan Date: Tue, 20 Aug 2024 10:15:27 -0400 Subject: [PATCH 16/17] offsets handle new pymc inputs --- thejoker/src/fast_likelihood.pyx | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/thejoker/src/fast_likelihood.pyx b/thejoker/src/fast_likelihood.pyx index e8770c7..92fb1f5 100644 --- a/thejoker/src/fast_likelihood.pyx +++ b/thejoker/src/fast_likelihood.pyx @@ -1,11 +1,11 @@ # coding: utf-8 -# cython: boundscheck=False -# cython: nonecheck=False -# cython: wraparound=False -# cython: initializedcheck=False -# cython: overflowcheck=False -# cython: linetrace=False -# cython: profile=False +# cython: boundscheck=True +# cython: nonecheck=True +# cython: wraparound=True +# cython: initializedcheck=True +# cython: overflowcheck=True +# cython: linetrace=True +# cython: profile=True # cython: cdivision=True # cython: language_level=3 @@ -213,10 +213,7 @@ cdef class CJokerHelper: _unit = getattr(dist, xu.UNIT_ATTR_NAME) to_unit = self.internal_units[name] - # mean is par 0, stddev par 1 - pars = dist.owner.inputs[3:] - mu = (pars[0].eval() * _unit).to_value(to_unit) - std = (pars[1].eval() * _unit).to_value(to_unit) + mu, std = _pytensor_get_mean_std(dist, _unit, to_unit) # K, v0 = 2 - start at index 2 self.mu[2+i] = mu From f4e5f15b6a251bcd0fe45f67135e1f15c16c70e1 Mon Sep 17 00:00:00 2001 From: Adrian Price-Whelan Date: Tue, 20 Aug 2024 10:59:47 -0400 Subject: [PATCH 17/17] min pymc version --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index a9adba5..8bf2b70 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,7 +24,7 @@ dependencies = [ "scipy", "h5py", "schwimmbad>=0.4", - "pymc>=5", + "pymc>=5.10.0", "pymc_ext>=1.0.1", "exoplanet-core[pymc]>=0.3.0", "tables",