Name | twiss JSON |
Version |
0.2.4
JSON |
| download |
home_page | |
Summary | Differentiable Wolski twiss matrices computation for arbitrary dimension stable symplectic matrices |
upload_time | 2023-09-24 14:17:59 |
maintainer | |
docs_url | None |
author | Ivan Morozov |
requires_python | >=3.10 |
license | MIT |
keywords |
torch
twiss
differentiable
symplectic
matrix
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# twiss, 2022-2023
Coupled twiss parameters (Wolski twiss matrices) computation for arbitrary even dimension.
# Install & build
```
$ pip install git+https://github.com/i-a-morozov/twiss.git@main
```
or
```
$ pip install twiss -U
```
# Documentation
[![Run In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/i-a-morozov/twiss/blob/main/docs/source/examples/twiss.ipynb)
[https://i-a-morozov.github.io/twiss/](https://i-a-morozov.github.io/twiss/)
# Twiss
Compute tunes, normalization matrix and twiss matrices.
```python
>>> from math import pi
>>> import torch
>>> from twiss.matrix import rotation
>>> from twiss.wolski import twiss
>>> m = rotation(2*pi*torch.tensor(0.88, dtype=torch.float64))
>>> t, n, w = twiss(m)
>>> t
tensor([0.8800], dtype=torch.float64)
>>> n
tensor([[1.0000, 0.0000],
[0.0000, 1.0000]], dtype=torch.float64)
>>> w
tensor([[[1.0000, 0.0000],
[0.0000, 1.0000]]], dtype=torch.float64)
```
Input matrices can have arbitrary even dimension.
```python
>>> from math import pi
>>> import torch
>>> from twiss.matrix import rotation
>>> from twiss.wolski import twiss
>>> m = rotation(*(2*pi*torch.linspace(0.1, 0.9, 9, dtype=torch.float64)))
>>> t, n, w = twiss(m)
>>> t
tensor([0.1000, 0.2000, 0.3000, 0.4000, 0.5000, 0.6000, 0.7000, 0.8000, 0.9000],
dtype=torch.float64)
```
Can be mapped over a batch of input matrices.
```python
>>> from math import pi
>>> import torch
>>> from twiss.matrix import rotation
>>> from twiss.wolski import twiss
>>> m = torch.func.vmap(rotation)(2*pi*torch.linspace(0.1, 0.9, 9, dtype=torch.float64))
>>> t, n, w = torch.func.vmap(twiss)(m)
>>> t
tensor([[0.1000],
[0.2000],
[0.3000],
[0.4000],
[0.5000],
[0.6000],
[0.7000],
[0.8000],
[0.9000]], dtype=torch.float64)
```
Can be used to compute derivatives of observables.
```python
>>> from math import pi
>>> import torch
>>> from twiss.matrix import rotation
>>> from twiss.wolski import twiss
>>> def fn(k):
... m = rotation(2*pi*torch.tensor(0.88, dtype=torch.float64))
... i = torch.ones_like(k)
... o = torch.zeros_like(k)
... m = m @ torch.stack([i, k, o, i]).reshape(m.shape)
... t, *_ = twiss(m)
... return t
>>> k = torch.tensor(0.0, dtype=torch.float64)
>>> fn(k)
tensor([0.8800], dtype=torch.float64)
>>> torch.func.jacfwd(fn)(k)
tensor([0.0796], dtype=torch.float64)
```
Raw data
{
"_id": null,
"home_page": "",
"name": "twiss",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": "",
"keywords": "torch,twiss,differentiable,symplectic,matrix",
"author": "Ivan Morozov",
"author_email": "",
"download_url": "https://files.pythonhosted.org/packages/fe/b1/a8245ef015b88b6030683ceb1258df0efb434f781d3c4b96e3f4fa54790f/twiss-0.2.4.tar.gz",
"platform": null,
"description": "# twiss, 2022-2023\n\nCoupled twiss parameters (Wolski twiss matrices) computation for arbitrary even dimension.\n\n# Install & build\n\n```\n$ pip install git+https://github.com/i-a-morozov/twiss.git@main\n```\nor \n```\n$ pip install twiss -U\n```\n\n# Documentation\n\n[![Run In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/i-a-morozov/twiss/blob/main/docs/source/examples/twiss.ipynb)\n\n[https://i-a-morozov.github.io/twiss/](https://i-a-morozov.github.io/twiss/)\n\n# Twiss\n\nCompute tunes, normalization matrix and twiss matrices.\n\n```python\n>>> from math import pi\n>>> import torch\n>>> from twiss.matrix import rotation\n>>> from twiss.wolski import twiss\n>>> m = rotation(2*pi*torch.tensor(0.88, dtype=torch.float64))\n>>> t, n, w = twiss(m)\n>>> t\ntensor([0.8800], dtype=torch.float64)\n>>> n\ntensor([[1.0000, 0.0000],\n [0.0000, 1.0000]], dtype=torch.float64)\n>>> w\ntensor([[[1.0000, 0.0000],\n [0.0000, 1.0000]]], dtype=torch.float64)\n```\n\nInput matrices can have arbitrary even dimension.\n\n```python\n>>> from math import pi\n>>> import torch\n>>> from twiss.matrix import rotation\n>>> from twiss.wolski import twiss\n>>> m = rotation(*(2*pi*torch.linspace(0.1, 0.9, 9, dtype=torch.float64)))\n>>> t, n, w = twiss(m)\n>>> t\ntensor([0.1000, 0.2000, 0.3000, 0.4000, 0.5000, 0.6000, 0.7000, 0.8000, 0.9000],\ndtype=torch.float64)\n```\n\nCan be mapped over a batch of input matrices.\n\n```python\n>>> from math import pi\n>>> import torch\n>>> from twiss.matrix import rotation\n>>> from twiss.wolski import twiss\n>>> m = torch.func.vmap(rotation)(2*pi*torch.linspace(0.1, 0.9, 9, dtype=torch.float64))\n>>> t, n, w = torch.func.vmap(twiss)(m)\n>>> t\ntensor([[0.1000],\n [0.2000],\n [0.3000],\n [0.4000],\n [0.5000],\n [0.6000],\n [0.7000],\n [0.8000],\n [0.9000]], dtype=torch.float64)\n```\n\nCan be used to compute derivatives of observables.\n\n```python\n >>> from math import pi\n >>> import torch\n >>> from twiss.matrix import rotation\n >>> from twiss.wolski import twiss\n >>> def fn(k):\n ... m = rotation(2*pi*torch.tensor(0.88, dtype=torch.float64))\n ... i = torch.ones_like(k)\n ... o = torch.zeros_like(k)\n ... m = m @ torch.stack([i, k, o, i]).reshape(m.shape)\n ... t, *_ = twiss(m)\n ... return t\n >>> k = torch.tensor(0.0, dtype=torch.float64)\n >>> fn(k)\n tensor([0.8800], dtype=torch.float64)\n >>> torch.func.jacfwd(fn)(k)\n tensor([0.0796], dtype=torch.float64)\n```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Differentiable Wolski twiss matrices computation for arbitrary dimension stable symplectic matrices",
"version": "0.2.4",
"project_urls": null,
"split_keywords": [
"torch",
"twiss",
"differentiable",
"symplectic",
"matrix"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "55be2d8a207fbe08001239fd566f60b22d00f73f7456cf57d06adfadc496615e",
"md5": "fe69c3dc7e2b3ff840bb9a10806bc099",
"sha256": "5ae6d34be62c0fc6635eb389285675a2f5c9bc1cbc4b08f599a7390ce05c2b57"
},
"downloads": -1,
"filename": "twiss-0.2.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "fe69c3dc7e2b3ff840bb9a10806bc099",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 12707,
"upload_time": "2023-09-24T14:17:58",
"upload_time_iso_8601": "2023-09-24T14:17:58.270078Z",
"url": "https://files.pythonhosted.org/packages/55/be/2d8a207fbe08001239fd566f60b22d00f73f7456cf57d06adfadc496615e/twiss-0.2.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "feb1a8245ef015b88b6030683ceb1258df0efb434f781d3c4b96e3f4fa54790f",
"md5": "8c7c90fd2136c7c7fad32dd9b37bc2ca",
"sha256": "3c33d51ad569f7c0a84214193fc7c7f5ea1c8c5f0d126f4be238a1e85c9437a0"
},
"downloads": -1,
"filename": "twiss-0.2.4.tar.gz",
"has_sig": false,
"md5_digest": "8c7c90fd2136c7c7fad32dd9b37bc2ca",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 501532,
"upload_time": "2023-09-24T14:17:59",
"upload_time_iso_8601": "2023-09-24T14:17:59.775551Z",
"url": "https://files.pythonhosted.org/packages/fe/b1/a8245ef015b88b6030683ceb1258df0efb434f781d3c4b96e3f4fa54790f/twiss-0.2.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-09-24 14:17:59",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "twiss"
}