![seedpy logo](https://i.imgur.com/Rvv9Z3g.png)
# 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:
```python
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:
```python
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:
```python
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.
```python
def do_something(..., state=None):
random_state = get_random_state(state) # could be int, str or RandomState
....
```
Raw data
{
"_id": null,
"home_page": "https://github.com/MatthiasJakobs/seedpy",
"name": "seedpy",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.5",
"maintainer_email": "",
"keywords": "machine learning,seed,random,numpy,pytorch",
"author": "Matthias Jakobs",
"author_email": "matthias.jakobs@tu-dortmund.de",
"download_url": "https://files.pythonhosted.org/packages/dc/08/7eca95607684bffa24c70fc355ac4cf494ebc62b1a95f3677f99e579bc17/seedpy-0.3.tar.gz",
"platform": null,
"description": "![seedpy logo](https://i.imgur.com/Rvv9Z3g.png)\n\n# seedpy\nEasily seed frameworks used for machine learning like Numpy and PyTorch using context managers.\n\n## Disclaimer\nThis is almost entirely untested software (especially the torch part). Use at your own risk.\nIf you have feature suggestions, found bugs, or want to contribute, feel free to open up issues and / or pull-requests.\n\n## Changelog\n\n* **0.3** - Added seed and random state conversion methods and a numerical seed generator\n* **0.2** - Added decorators, removed requirement for `numpy` and `pytorch`\n\n\n## Installation\n`pip install git+https://github.com/MatthiasJakobs/seedpy.git`\n\n## Usage\nUse `fixedseed` to fix the seed of the global Numpy inside the context manager:\n\n```python\nnp.random.seed(0)\n\n# Number generated using seed \"0\"\nbefore_fixedseed = np.random.rand(5)\n\nwith fixedseed(np, seed=10100):\n # Number generated using seed \"10100\"\n inside_fixedseed = np.random.rand(5)\n\n# Number generated using seed \"0\"\nafter_fixedseed = np.random.rand(5)\n```\n\nYou can also pass in the `torch` global object, or even a list of both: \n```python\nwith fixedseed([torch, np], seed=10100):\n ...\n```\n\nThe same syntax can be used for the `randomseed` context in order to randomize calculations inside an otherwise fixed environment:\n```python\nwith randomseed([torch, np]):\n ...\n```\n\n\nYou 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.\nThis is particularly useful when defining reproducible functions to offer a wide variety of possible seeding options, e.g.\n```python\ndef do_something(..., state=None):\n random_state = get_random_state(state) # could be int, str or RandomState\n ....\n```\n",
"bugtrack_url": null,
"license": "GNU GPLv3",
"summary": "Easy seeding for machine learning frameworks",
"version": "0.3",
"split_keywords": [
"machine learning",
"seed",
"random",
"numpy",
"pytorch"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "b5826bdc6a9766d34c43b8b49669f42b8ef9c23c00f67e1d51325192bb1c3a59",
"md5": "98da9297ccf94c69542c826c06f3fc99",
"sha256": "de5473f3324383a0e34c309a4d2b3c2f0d6c382c7be1909984aa51af7332c9fb"
},
"downloads": -1,
"filename": "seedpy-0.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "98da9297ccf94c69542c826c06f3fc99",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.5",
"size": 16186,
"upload_time": "2023-01-19T15:29:10",
"upload_time_iso_8601": "2023-01-19T15:29:10.439514Z",
"url": "https://files.pythonhosted.org/packages/b5/82/6bdc6a9766d34c43b8b49669f42b8ef9c23c00f67e1d51325192bb1c3a59/seedpy-0.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "dc087eca95607684bffa24c70fc355ac4cf494ebc62b1a95f3677f99e579bc17",
"md5": "1b0e1aa139992fb1ef8e7fc8e54c6a22",
"sha256": "206768c0d4aa2624180a329740c8d3b650b9e061d1d754529bfee43e065ba967"
},
"downloads": -1,
"filename": "seedpy-0.3.tar.gz",
"has_sig": false,
"md5_digest": "1b0e1aa139992fb1ef8e7fc8e54c6a22",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.5",
"size": 15666,
"upload_time": "2023-01-19T15:29:12",
"upload_time_iso_8601": "2023-01-19T15:29:12.507163Z",
"url": "https://files.pythonhosted.org/packages/dc/08/7eca95607684bffa24c70fc355ac4cf494ebc62b1a95f3677f99e579bc17/seedpy-0.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-01-19 15:29:12",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "MatthiasJakobs",
"github_project": "seedpy",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "seedpy"
}