Name | strupnet JSON |
Version |
0.0.4
JSON |
| download |
home_page | None |
Summary | Structure-preserving neural networks |
upload_time | 2024-06-11 20:30:52 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.9 |
license | MIT License Copyright (c) 2024 Ben Tapley Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
keywords |
pytorch
neural networks
physics-informed machine learning
structure-preserving neural networks
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# STRUPNET: structure-preserving neural networks
This package implements structure-preserving neural networks for learning dynamics of differential systems from data.
## Installing
Install it using pip: ```pip install strupnet```
## `SympNet`: Symplectic neural networks
This package implements the symplectic neural networks found in [1] ("G" and "LA"-SympNets) and [2] ("H"-SympNets) as well as some new ones [3] ("P", "R" and "GR"-SympNets).
### Basic example
```python
import torch
from strupnet import SympNet
dim = 2 # degrees of freedom for the Hamiltonian system. x = (p, q) \in R^{2*dim}
sympnet = SympNet(dim=dim, layers=12, width=8)
timestep = torch.tensor([0.1]) # time-step
x0 = torch.randn(2 * dim) # phase space coordinate x0 = (p0, q0)
x1 = sympnet(x0, timestep) # defines a random but symplectic transformation from x0 to x1
```
The rest of your code is identical to you how you would train any module that inherits from `torch.nn.Module`.
## `VolNet`: Volume-preserving neural networks
This module neural networks with unit Jacobian determinant. The `VolNet` is constructed from compositions of `SympNets`, and therefore requires you to pass through arguments that define one of the above `SympNets`. See the below example on how it's initialised.
### Basic example
```python
import torch
from strupnet import VolNet
dim = 3 # dimension of the ODE
p_sympnet_kwargs = dict(
method="P",
layers=6,
max_degree=4, # used for method='P' only, method='R' requires you to specify width.
)
volnet = VolNet(dim=DIM, **p_sympnet_kwargs)
timestep = torch.tensor([0.1]) # time-step
x0 = torch.randn(3)
x1 = sympnet(x0, timestep) # defines a random but volume-preserving neural network mapping from x0 to x1
```
The rest of your code is identical to you how you would train any module that inherits from `torch.nn.Module`.
## Example notebooks
See the `examples/` folder for notebooks on basic implementation of `SympNet` and `VolNet`
## References
[1] Jin, P., Zhang, Z., Zhu, A., Tang, Y. and Karniadakis, G.E., 2020. SympNets: Intrinsic structure-preserving symplectic networks for identifying Hamiltonian systems. Neural Networks, 132, pp.166-179.
[2] Burby, J.W., Tang, Q. and Maulik, R., 2020. Fast neural Poincaré maps for toroidal magnetic fields. Plasma Physics and Controlled Fusion, 63(2), p.024001.
[3] In press.
<!-- # Contributing:
To add your own ```SympNet``` method/layer, do the following:
- Create a new branch.
- Add a file to the ```sympnet/layers``` folder. Call it, for example, ```sympnet/layers/NEW_LAYER.py``` where NEW_LAYER is an abbreviation to the methods name (ideally no longer than a couple of letters).
- In ```sympnet/layers/NEW_LAYER.py``` define a ```Layer``` class that inherits from ```torch.nn.Module```.
- Define the forward method to accept an input of the form ```p, q, h``` and return the tuple ```p, q``` where ```p``` and ```q``` are of type ```torch.Tensor``` and shape ```(dim, )``` or ```(nbatch, dim)``` and ```h``` of shape ```(1, )``` or ```(nbatch, 1)```.
- Add ```"NEW_LAYER"``` to the ```ALLOWED_METHODS``` list in ```sympnet.py```.
- Check that it passes the unit tests by running ```python -m pytest``` (Note that the tests will automatically test your new layer if it is added to ```ALLOWED_METHODS```). This tests for things like valid implementation and whether it is symplectic or not.
- Create a pull request to the main branch.
Otherwise, any contribution is appreciated! -->
Raw data
{
"_id": null,
"home_page": null,
"name": "strupnet",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "pytorch, neural networks, physics-informed machine learning, structure-preserving neural networks",
"author": null,
"author_email": "Ben Tapley <bentapley@hotmail.com>",
"download_url": "https://files.pythonhosted.org/packages/e4/2e/e783e6c46cbc27f61acf07ea961f8641b3219aa8446723a0d6a27692bab2/strupnet-0.0.4.tar.gz",
"platform": null,
"description": "# STRUPNET: structure-preserving neural networks\n\nThis package implements structure-preserving neural networks for learning dynamics of differential systems from data. \n\n## Installing \nInstall it using pip: ```pip install strupnet```\n\n## `SympNet`: Symplectic neural networks\n\nThis package implements the symplectic neural networks found in [1] (\"G\" and \"LA\"-SympNets) and [2] (\"H\"-SympNets) as well as some new ones [3] (\"P\", \"R\" and \"GR\"-SympNets).\n\n### Basic example\n```python \nimport torch\nfrom strupnet import SympNet\n\ndim = 2 # degrees of freedom for the Hamiltonian system. x = (p, q) \\in R^{2*dim}\nsympnet = SympNet(dim=dim, layers=12, width=8)\n\ntimestep = torch.tensor([0.1]) # time-step \nx0 = torch.randn(2 * dim) # phase space coordinate x0 = (p0, q0) \n\nx1 = sympnet(x0, timestep) # defines a random but symplectic transformation from x0 to x1\n```\nThe rest of your code is identical to you how you would train any module that inherits from `torch.nn.Module`. \n\n## `VolNet`: Volume-preserving neural networks\n\nThis module neural networks with unit Jacobian determinant. The `VolNet` is constructed from compositions of `SympNets`, and therefore requires you to pass through arguments that define one of the above `SympNets`. See the below example on how it's initialised.\n\n### Basic example\n```python \nimport torch\nfrom strupnet import VolNet\n\ndim = 3 # dimension of the ODE \n\np_sympnet_kwargs = dict(\n method=\"P\",\n layers=6,\n max_degree=4, # used for method='P' only, method='R' requires you to specify width.\n)\n\nvolnet = VolNet(dim=DIM, **p_sympnet_kwargs)\n\ntimestep = torch.tensor([0.1]) # time-step \nx0 = torch.randn(3)\n\nx1 = sympnet(x0, timestep) # defines a random but volume-preserving neural network mapping from x0 to x1\n```\nThe rest of your code is identical to you how you would train any module that inherits from `torch.nn.Module`. \n\n## Example notebooks\nSee the `examples/` folder for notebooks on basic implementation of `SympNet` and `VolNet`\n\n## References\n\n[1] Jin, P., Zhang, Z., Zhu, A., Tang, Y. and Karniadakis, G.E., 2020. SympNets: Intrinsic structure-preserving symplectic networks for identifying Hamiltonian systems. Neural Networks, 132, pp.166-179.\n\n[2] Burby, J.W., Tang, Q. and Maulik, R., 2020. Fast neural Poincar\u00e9 maps for toroidal magnetic fields. Plasma Physics and Controlled Fusion, 63(2), p.024001.\n\n[3] In press. \n\n<!-- # Contributing:\n\nTo add your own ```SympNet``` method/layer, do the following: \n- Create a new branch.\n- Add a file to the ```sympnet/layers``` folder. Call it, for example, ```sympnet/layers/NEW_LAYER.py``` where NEW_LAYER is an abbreviation to the methods name (ideally no longer than a couple of letters). \n- In ```sympnet/layers/NEW_LAYER.py``` define a ```Layer``` class that inherits from ```torch.nn.Module```. \n- Define the forward method to accept an input of the form ```p, q, h``` and return the tuple ```p, q``` where ```p``` and ```q``` are of type ```torch.Tensor``` and shape ```(dim, )``` or ```(nbatch, dim)``` and ```h``` of shape ```(1, )``` or ```(nbatch, 1)```. \n- Add ```\"NEW_LAYER\"``` to the ```ALLOWED_METHODS``` list in ```sympnet.py```.\n- Check that it passes the unit tests by running ```python -m pytest``` (Note that the tests will automatically test your new layer if it is added to ```ALLOWED_METHODS```). This tests for things like valid implementation and whether it is symplectic or not. \n- Create a pull request to the main branch. \n\nOtherwise, any contribution is appreciated! -->\n",
"bugtrack_url": null,
"license": "MIT License Copyright (c) 2024 Ben Tapley Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
"summary": "Structure-preserving neural networks",
"version": "0.0.4",
"project_urls": {
"Homepage": "https://github.com/bentaps/strupnet"
},
"split_keywords": [
"pytorch",
" neural networks",
" physics-informed machine learning",
" structure-preserving neural networks"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "929623f26746258e94cc77b3bd3ea2c7f1d3cd6a518bf92b378e5e2462e873f5",
"md5": "04796cc1ad4994e4510488233c6f0194",
"sha256": "4b2db8880f5d74963dc69b74e34506ba3317152deb2996cf09ea1b3ef62aa451"
},
"downloads": -1,
"filename": "strupnet-0.0.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "04796cc1ad4994e4510488233c6f0194",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 19346,
"upload_time": "2024-06-11T20:30:50",
"upload_time_iso_8601": "2024-06-11T20:30:50.980925Z",
"url": "https://files.pythonhosted.org/packages/92/96/23f26746258e94cc77b3bd3ea2c7f1d3cd6a518bf92b378e5e2462e873f5/strupnet-0.0.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "e42ee783e6c46cbc27f61acf07ea961f8641b3219aa8446723a0d6a27692bab2",
"md5": "79742817ab7479334741f37e3a0baa46",
"sha256": "b45b6dcb3e9cc3263e06854ce30c93bd40586bf3ca597899e86cb24534f1e9e0"
},
"downloads": -1,
"filename": "strupnet-0.0.4.tar.gz",
"has_sig": false,
"md5_digest": "79742817ab7479334741f37e3a0baa46",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 14976,
"upload_time": "2024-06-11T20:30:52",
"upload_time_iso_8601": "2024-06-11T20:30:52.465895Z",
"url": "https://files.pythonhosted.org/packages/e4/2e/e783e6c46cbc27f61acf07ea961f8641b3219aa8446723a0d6a27692bab2/strupnet-0.0.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-06-11 20:30:52",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "bentaps",
"github_project": "strupnet",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "strupnet"
}