twiss


Nametwiss JSON
Version 0.2.6 PyPI version JSON
download
home_pageNone
SummaryDifferentiable Wolski twiss matrices computation for arbitrary dimension stable symplectic matrices
upload_time2024-05-23 15:24:09
maintainerNone
docs_urlNone
authorIvan Morozov
requires_python>=3.10
licenseMIT
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-2024

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": null,
    "name": "twiss",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "torch, twiss, differentiable, symplectic, matrix",
    "author": "Ivan Morozov",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/7f/ed/def5c6380722460d644efe59cf7f9045d25c23706880796a0e710b16acf5/twiss-0.2.6.tar.gz",
    "platform": null,
    "description": "# twiss, 2022-2024\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.6",
    "project_urls": {
        "documentation": "https://i-a-morozov.github.io/twiss/",
        "repository": "https://github.com/i-a-morozov/twiss"
    },
    "split_keywords": [
        "torch",
        " twiss",
        " differentiable",
        " symplectic",
        " matrix"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "950b8753110f70ad33adbe733e22b4bc0e5390ba3b0e5c38c40a5349b6f54ae1",
                "md5": "42db2fce34c8cf13a638302946a979c8",
                "sha256": "ccdb689b78498d09e962aea5009f0c85dd65f8f3065512dfcbb53f873588f302"
            },
            "downloads": -1,
            "filename": "twiss-0.2.6-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "42db2fce34c8cf13a638302946a979c8",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 13391,
            "upload_time": "2024-05-23T15:24:01",
            "upload_time_iso_8601": "2024-05-23T15:24:01.936500Z",
            "url": "https://files.pythonhosted.org/packages/95/0b/8753110f70ad33adbe733e22b4bc0e5390ba3b0e5c38c40a5349b6f54ae1/twiss-0.2.6-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7feddef5c6380722460d644efe59cf7f9045d25c23706880796a0e710b16acf5",
                "md5": "cae12a9caf465c941c707343530e4fb1",
                "sha256": "8542b8bb44fa04fc24b5f6a06fb0ec7d65d83dfc5eac5dcbe957570c2380aacd"
            },
            "downloads": -1,
            "filename": "twiss-0.2.6.tar.gz",
            "has_sig": false,
            "md5_digest": "cae12a9caf465c941c707343530e4fb1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 622832,
            "upload_time": "2024-05-23T15:24:09",
            "upload_time_iso_8601": "2024-05-23T15:24:09.732536Z",
            "url": "https://files.pythonhosted.org/packages/7f/ed/def5c6380722460d644efe59cf7f9045d25c23706880796a0e710b16acf5/twiss-0.2.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-23 15:24:09",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "i-a-morozov",
    "github_project": "twiss",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "twiss"
}
        
Elapsed time: 0.58542s