Skip to main content

seedpy logo

seedpy

Easily seed frameworks used for machine learning like Numpy and PyTorch using context managers.

Disclaimer

This is almost entirely untested software (especially the torch part). Use at your own risk. If you have feature suggestions, found bugs, or want to contribute, feel free to open up issues and / or pull-requests.

Changelog

  • 0.3 - Added seed and random state conversion methods and a numerical seed generator
  • 0.2 - Added decorators, removed requirement for numpy and pytorch

Installation

pip install git+https://github.com/MatthiasJakobs/seedpy.git

Usage

Use fixedseed to fix the seed of the global Numpy inside the context manager:

np.random.seed(0)

# Number generated using seed "0"
before_fixedseed = np.random.rand(5)

with fixedseed(np, seed=10100):
    # Number generated using seed "10100"
    inside_fixedseed = np.random.rand(5)

# Number generated using seed "0"
after_fixedseed = np.random.rand(5)

You can also pass in the torch global object, or even a list of both:

with fixedseed([torch, np], seed=10100):
    ...

The same syntax can be used for the randomseed context in order to randomize calculations inside an otherwise fixed environment:

with randomseed([torch, np]):
    ...

You can use get_random_state to obtain a numpy.random.RandomState object from any seed-like value (int or str) or an existing RandomState object. This is particularly useful when defining reproducible functions to offer a wide variety of possible seeding options, e.g.

def do_something(..., state=None):
    random_state = get_random_state(state) # could be int, str or RandomState
    ....

Release files for seedpy 0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for seedpy 0.3
File Size Uploaded
seedpy-0.3.tar.gz 15.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for seedpy 0.3
File Interpreter ABI Platform
seedpy-0.3-py3-none-any.whl Python 3 none any Details

Total release size: 31.9 kB

Release files / seedpy-0.3.tar.gz

Download URL seedpy-0.3.tar.gz
Size 15.7 kB
Tags Source
SHA-256 checksum
How to use checksums
206768c0d4aa2624180a329740c8d3b650b9e061d1d754529bfee43e065ba967
BLAKE2b-256 checksum
How to use checksums
dc087eca95607684bffa24c70fc355ac4cf494ebc62b1a95f3677f99e579bc17
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.6

Release files / seedpy-0.3-py3-none-any.whl

Download URL seedpy-0.3-py3-none-any.whl
Size 16.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
de5473f3324383a0e34c309a4d2b3c2f0d6c382c7be1909984aa51af7332c9fb
BLAKE2b-256 checksum
How to use checksums
b5826bdc6a9766d34c43b8b49669f42b8ef9c23c00f67e1d51325192bb1c3a59
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.6

Release history Release notifications | RSS feed

This release

0.3 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page