Skip to content

Remove unnecessary handling of no longer supported RandomState #1300

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

Merged

Conversation

ricardoV94
Copy link
Member

@ricardoV94 ricardoV94 commented Mar 18, 2025

Small cleanup


📚 Documentation preview 📚: https://pytensor--1300.org.readthedocs.build/en/1300/

Copy link

codecov bot commented Mar 18, 2025

Codecov Report

Attention: Patch coverage is 83.33333% with 2 lines in your changes missing coverage. Please review.

Project coverage is 82.02%. Comparing base (4378d48) to head (b7bed61).
Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
pytensor/compile/monitormode.py 0.00% 1 Missing ⚠️
pytensor/compile/nanguardmode.py 0.00% 0 Missing and 1 partial ⚠️

❌ Your patch status has failed because the patch coverage (83.33%) is below the target coverage (100.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1300   +/-   ##
=======================================
  Coverage   82.01%   82.02%           
=======================================
  Files         207      207           
  Lines       49250    49242    -8     
  Branches     8734     8732    -2     
=======================================
- Hits        40394    40389    -5     
+ Misses       6692     6690    -2     
+ Partials     2164     2163    -1     
Files with missing lines Coverage Δ
pytensor/link/jax/linker.py 95.00% <100.00%> (ø)
pytensor/link/numba/linker.py 100.00% <100.00%> (+15.00%) ⬆️
pytensor/tensor/random/type.py 80.35% <100.00%> (+0.35%) ⬆️
pytensor/compile/monitormode.py 63.04% <0.00%> (ø)
pytensor/compile/nanguardmode.py 62.37% <0.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Armavica
Copy link
Member

There are others at other places of the code, are those still needed?

❯ rg -w RandomState
tests/unittest_tools.py
30:    Useful for seeding RandomState or Generator objects.
31:    >>> rng = np.random.RandomState(fetch_seed())

pytensor/tensor/random/var.py
14:@shared_constructor.register(np.random.RandomState)
19:    r"""`SharedVariable` constructor for NumPy's `Generator` and/or `RandomState`."""
20:    if isinstance(value, np.random.RandomState):
22:            "`np.RandomState` is no longer supported in PyTensor. Use `np.random.Generator` instead."

pytensor/tensor/random/type.py
9:T = TypeVar("T", np.random.RandomState, np.random.Generator)
27:    r"""A Type wrapper for `numpy.random.Generator` and `numpy.random.RandomState`."""

doc/optimizations.rst
242:        Typically when a graph uses random numbers, the RandomState is stored

pytensor/compile/nanguardmode.py
37:    elif isinstance(arr, np.random.mtrand.RandomState | np.random.Generator):

pytensor/compile/monitormode.py
108:            not isinstance(output[0], np.random.RandomState | np.random.Generator)

doc/extending/extending_pytensor_solution_1.py
121:        rng = np.random.RandomState(43)
131:        rng = np.random.RandomState(43)
153:        rng = np.random.RandomState(43)

pytensor/gradient.py
1804:    rng: np.random.Generator | np.random.RandomState | None = None,

doc/library/d3viz/index.rst
61:    rng = np.random.RandomState(0)

doc/library/d3viz/index.ipynb
98:    "rng = np.random.RandomState(0)\n",

tests/tensor/random/test_basic.py
1422:        integers(10, rng=shared(np.random.RandomState()))

@ricardoV94 ricardoV94 force-pushed the randomstate_no_longer_supported branch from 702889b to f71e5b9 Compare April 29, 2025 14:48
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@ricardoV94
Copy link
Member Author

@Armavica thanks for pointing those. I removed a couple more. I left the sharedvariable register so users get a useful error for a while longer (and the respective test). The only other non-graph use of RandomState is in verify_grad which I left for now. It's a simple use and doesn't burden our codebase.

@ricardoV94 ricardoV94 force-pushed the randomstate_no_longer_supported branch from f71e5b9 to b7bed61 Compare April 29, 2025 15:14
@ricardoV94 ricardoV94 merged commit b2365e0 into pymc-devs:main May 2, 2025
72 of 73 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants