Skip to content
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

Address some Jax random key issues #531

Merged
merged 3 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions pertpy/tools/_coda/_base_coda.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import numpyro as npy
import toytree as tt
from ete3 import Tree
from jax._src.prng import PRNGKeyArray
from jax._src.typing import Array
from matplotlib.axes import Axes

Expand Down Expand Up @@ -188,7 +187,7 @@ def __run_mcmc(
self,
sample_adata: AnnData,
kernel: npy.infer.mcmc.MCMCKernel,
rng_key: Array | PRNGKeyArray,
rng_key: Array,
copy: bool = False,
*args,
**kwargs,
Expand Down Expand Up @@ -304,7 +303,7 @@ def run_nuts(
if copy:
sample_adata = sample_adata.copy()

rng_key_array = random.PRNGKey(rng_key)
rng_key_array = random.key(rng_key)
sample_adata.uns["scCODA_params"]["mcmc"]["rng_key"] = np.array(rng_key_array)

# Set up NUTS kernel
Expand Down Expand Up @@ -367,10 +366,10 @@ def run_hmc(
# Set rng key if needed
if rng_key is None:
rng = np.random.default_rng()
rng_key = random.PRNGKey(rng.integers(0, 10000))
rng_key = random.key(rng.integers(0, 10000))
sample_adata.uns["scCODA_params"]["mcmc"]["rng_key"] = rng_key
else:
rng_key = random.PRNGKey(rng_key)
rng_key = random.key(rng_key)

# Set up HMC kernel
sample_adata = self.set_init_mcmc_states(
Expand Down
2 changes: 1 addition & 1 deletion pertpy/tools/_coda/_sccoda.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ def make_arviz( # type: ignore

if rng_key is None:
rng = np.random.default_rng()
rng_key = random.PRNGKey(rng.integers(0, 10000))
rng_key = random.key(rng.integers(0, 10000))

if use_posterior_predictive:
posterior_predictive = Predictive(self.model, self.mcmc.get_samples())(
Expand Down
2 changes: 1 addition & 1 deletion pertpy/tools/_coda/_tasccoda.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ def make_arviz( # type: ignore

if rng_key is None:
rng = np.random.default_rng()
rng_key = random.PRNGKey(rng.integers(0, 10000))
rng_key = random.key(rng.integers(0, 10000))

if use_posterior_predictive:
posterior_predictive = Predictive(self.model, self.mcmc.get_samples())(
Expand Down
Loading