-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Closed
Labels
Description
Describe the issue:
Hello guys!
While trying to run the exact example from exoplanet package documentation (cf Transit, Occultations and Eclipses), I am encountering the following issue:
NotImplementedError: ValuedVar should not be present in the final graph!
This arises after I tried to upgrade my old PyMC3/theano/exoplanet script to newer PyMC/PyTensor/exoplanet[pymc] versions. I must admit I have no real idea where this issue arises from as the exoplanet tutorial script is quite simple and direct.
I also opened an issue on exoplanet-dev issue
Thanks for your help!
Reproduceable code example:
import pymc_ext as pmx
import pymc as pm
import exoplanet as xo
import matplotlib.pyplot as plt
import numpy as np
random = np.random.default_rng(123)
num_transits = 4
t = np.arange(0, 35, 0.02)
yerr = 5e-4
with pm.Model():
# The baseline flux
mean = pm.Normal("mean", mu=0.0, sigma=1.0)
# Often the best parameterization is actually in terms of the
# times of two reference transits rather than t0 and period
t0 = pm.Normal("t0", mu=4.35, sigma=1.0)
t1 = pm.Normal("t1", mu=33.2, sigma=1.0)
period = pm.Deterministic("period", (t1 - t0) / num_transits)
# The Kipping (2013) parameterization for quadratic limb darkening
# paramters
u = xo.distributions.quad_limb_dark("u", initval=np.array([0.3, 0.2]))
# The radius ratio and impact parameter; these parameters can
# introduce pretty serious covariances and are ripe for
# reparameterization
log_r = pm.Normal("log_r", mu=np.log(0.04), sigma=2.0)
r = pm.Deterministic("r", pt.exp(log_r))
b = xo.distributions.impact_parameter("b", r, initval=0.35)
# Set up a Keplerian orbit for the planets
orbit = xo.orbits.KeplerianOrbit(period=period, t0=t0, b=b)
# Compute the model light curve; note that we index using `[:, 0]`
# since `get_light_curve` returns an object with the shape
# `(n_times, n_planets)`
light_curve = (
xo.LimbDarkLightCurve(u[0], u[1]).get_light_curve(
orbit=orbit, r=r, t=t
)[:, 0]
+ mean
)
# Here we track the value of the model light curve for plotting
# purposes
pm.Deterministic("__light_curve", light_curve)
# ================================================== #
# Simulate data from the model for testing #
# You should remove the following lines in your code #
# ================================================== #
y = pmx.eval_in_model(light_curve)
y += yerr * random.normal(size=len(y))
# =============== end simulated data =============== #
# The likelihood function assuming known Gaussian uncertainty
pm.Normal("obs", mu=light_curve, sigma=yerr, observed=y)
trace = pm.sample(
tune=1000, draws=1000, cores=2, chains=2, init="adapt_full"
)
# Plot the results
q16, q50, q84 = np.percentile(
trace.posterior["__light_curve"].values, [16, 50, 84], axis=(0, 1)
)
plt.plot(t, y, ".k", ms=2, label="data")
plt.plot(t, q50)
plt.fill_between(t, q16, q84, alpha=0.3, label="posterior")
plt.xlim(0.0, 35)
plt.legend(fontsize=12, loc=3)
plt.xlabel("time [days]")
plt.ylabel("relative flux")
# Compute the convergence stats
az.summary(trace, var_names=["^(?!__).*"], filter_vars="regex")
Error message:
Traceback (most recent call last):
File "/mnt/c/Users/vince/OneDrive/Bureau/DC20/ASTEP/package/ProSTEP3/prostep3/src/prostep3/scripts/redo_fit_prose3_vincent.py", line 838, in <module>
main(args)
File "/mnt/c/Users/vince/OneDrive/Bureau/DC20/ASTEP/package/ProSTEP3/prostep3/src/prostep3/scripts/redo_fit_prose3_vincent.py", line 720, in main
opt,summary,trace=fit_georgina(data,predictions)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/mnt/c/Users/vince/OneDrive/Bureau/DC20/ASTEP/package/ProSTEP3/prostep3/src/prostep3/scripts/redo_fit_prose3_vincent.py", line 255, in fit_georgina
opt = pm.find_MAP(start=model.initial_point())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jaskier/miniconda3/envs/prostep3-dev/lib/python3.11/site-packages/pymc/tuning/starting.py", line 134, in find_MAP
model.check_start_vals(start)
File "/home/jaskier/miniconda3/envs/prostep3-dev/lib/python3.11/site-packages/pymc/model/core.py", line 1766, in check_start_vals
initial_eval = self.point_logps(point=elem, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jaskier/miniconda3/envs/prostep3-dev/lib/python3.11/site-packages/pymc/model/core.py", line 1798, in point_logps
factor_logps_fn = [pt.sum(factor) for factor in self.logp(factors, sum=False)]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jaskier/miniconda3/envs/prostep3-dev/lib/python3.11/site-packages/pymc/model/core.py", line 696, in logp
rv_logps = transformed_conditional_logp(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jaskier/miniconda3/envs/prostep3-dev/lib/python3.11/site-packages/pymc/logprob/basic.py", line 595, in transformed_conditional_logp
temp_logp_terms = conditional_logp(
^^^^^^^^^^^^^^^^^
File "/home/jaskier/miniconda3/envs/prostep3-dev/lib/python3.11/site-packages/pymc/logprob/basic.py", line 479, in conditional_logp
fgraph = construct_ir_fgraph(rv_values, ir_rewriter=ir_rewriter)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jaskier/miniconda3/envs/prostep3-dev/lib/python3.11/site-packages/pymc/logprob/rewriting.py", line 249, in construct_ir_fgraph
replacements = tuple((rv, valued_rv(rv, value)) for rv, value in ir_rv_values.items())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jaskier/miniconda3/envs/prostep3-dev/lib/python3.11/site-packages/pymc/logprob/rewriting.py", line 249, in <genexpr>
replacements = tuple((rv, valued_rv(rv, value)) for rv, value in ir_rv_values.items())
^^^^^^^^^^^^^^^^^^^^
File "/home/jaskier/miniconda3/envs/prostep3-dev/lib/python3.11/site-packages/pytensor/graph/op.py", line 304, in __call__
compute_test_value(node)
File "/home/jaskier/miniconda3/envs/prostep3-dev/lib/python3.11/site-packages/pytensor/graph/op.py", line 125, in compute_test_value
thunk()
File "/home/jaskier/miniconda3/envs/prostep3-dev/lib/python3.11/site-packages/pytensor/graph/op.py", line 531, in rval
r = p(n, [x[0] for x in i], o)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jaskier/miniconda3/envs/prostep3-dev/lib/python3.11/site-packages/pymc/logprob/abstract.py", line 245, in perform
raise NotImplementedError("ValuedVar should not be present in the final graph!")
NotImplementedError: ValuedVar should not be present in the final graph!
PyMC version information:
- Version of exoplanet: 0.6.0
- Version of PyMC: 5.19.1
- Version of PyTensor: 2.26.4
- Operating system: Linux ZBook 5.15.167.4-microsoft-standard-WSL2 1 SMP Tue Nov 5 00:21:55 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
- Python version & installation method (pip, conda, etc.): Python 3.11.11, everything installed with pip inside a conda environment (conda create -n name python=3.11, package by conda-forge)
Context for the issue:
I am working on adapting a data reduction pipeline for exoplanetary transits detection using a 40-cm newtonian telescope.