{"id":24446381,"url":"https://github.com/i-a-morozov/twiss","last_synced_at":"2025-10-06T15:30:17.269Z","repository":{"id":167663445,"uuid":"643288585","full_name":"i-a-morozov/twiss","owner":"i-a-morozov","description":"Differentiable Wolski twiss matrices computation for arbitrary dimension stable symplectic matrices","archived":false,"fork":false,"pushed_at":"2024-10-04T17:30:41.000Z","size":6640,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-19T19:54:33.876Z","etag":null,"topics":["accelerator-physics","automatic-differentiation","parameterization"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/i-a-morozov.png","metadata":{"files":{"readme":"README.MD","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-20T17:27:18.000Z","updated_at":"2024-10-04T17:29:02.000Z","dependencies_parsed_at":"2024-04-26T04:28:52.215Z","dependency_job_id":"42efdfde-dac5-4273-b5cb-b27f9c8ce12c","html_url":"https://github.com/i-a-morozov/twiss","commit_stats":null,"previous_names":["i-a-morozov/twiss"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/i-a-morozov%2Ftwiss","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/i-a-morozov%2Ftwiss/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/i-a-morozov%2Ftwiss/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/i-a-morozov%2Ftwiss/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/i-a-morozov","download_url":"https://codeload.github.com/i-a-morozov/twiss/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235531154,"owners_count":19004907,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["accelerator-physics","automatic-differentiation","parameterization"],"created_at":"2025-01-20T23:55:16.923Z","updated_at":"2025-10-06T15:30:16.858Z","avatar_url":"https://github.com/i-a-morozov.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# twiss, 2022-2024\n\n\u003cp align=\"center\"\u003e\n  \u003cimg width=\"150\" height=\"95\" src=\"https://github.com/i-a-morozov/twiss/blob/main/docs/pics/logo.svg\"\u003e\n\u003c/p\u003e\n\nCoupled twiss parameters (Wolski twiss matrices) computation for arbitrary even dimension.\n\n# Install \u0026 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\u003e\u003e\u003e from math import pi\n\u003e\u003e\u003e import torch\n\u003e\u003e\u003e from twiss.matrix import  rotation\n\u003e\u003e\u003e from twiss.wolski import twiss\n\u003e\u003e\u003e m = rotation(2*pi*torch.tensor(0.88, dtype=torch.float64))\n\u003e\u003e\u003e t, n, w = twiss(m)\n\u003e\u003e\u003e t\ntensor([0.8800], dtype=torch.float64)\n\u003e\u003e\u003e n\ntensor([[1.0000, 0.0000],\n        [0.0000, 1.0000]], dtype=torch.float64)\n\u003e\u003e\u003e 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\u003e\u003e\u003e from math import pi\n\u003e\u003e\u003e import torch\n\u003e\u003e\u003e from twiss.matrix import rotation\n\u003e\u003e\u003e from twiss.wolski import twiss\n\u003e\u003e\u003e m = rotation(*(2*pi*torch.linspace(0.1, 0.9, 9, dtype=torch.float64)))\n\u003e\u003e\u003e t, n, w = twiss(m)\n\u003e\u003e\u003e 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\u003e\u003e\u003e from math import pi\n\u003e\u003e\u003e import torch\n\u003e\u003e\u003e from twiss.matrix import rotation\n\u003e\u003e\u003e from twiss.wolski import twiss\n\u003e\u003e\u003e m = torch.func.vmap(rotation)(2*pi*torch.linspace(0.1, 0.9, 9, dtype=torch.float64))\n\u003e\u003e\u003e t, n, w = torch.func.vmap(twiss)(m)\n\u003e\u003e\u003e 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    \u003e\u003e\u003e from math import pi\n    \u003e\u003e\u003e import torch\n    \u003e\u003e\u003e from twiss.matrix import  rotation\n    \u003e\u003e\u003e from twiss.wolski import twiss\n    \u003e\u003e\u003e 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    \u003e\u003e\u003e k = torch.tensor(0.0, dtype=torch.float64)\n    \u003e\u003e\u003e fn(k)\n    tensor([0.8800], dtype=torch.float64)\n    \u003e\u003e\u003e torch.func.jacfwd(fn)(k)\n    tensor([0.0796], dtype=torch.float64)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fi-a-morozov%2Ftwiss","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fi-a-morozov%2Ftwiss","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fi-a-morozov%2Ftwiss/lists"}