Skip to main content

DiPAS is a framework for differentiable simulations of particle accelerators.

Project description

https://gitlab.com/Dominik1123/dipas/badges/develop/pipeline.svg https://gitlab.com/Dominik1123/dipas/badges/develop/coverage.svg https://img.shields.io/pypi/v/dipas.svg

DiPAS

DiPAS is a program for differentiable simulations of particle accelerators. It acts as a framework and thus supports a wide range of use cases such as particle tracking or optics calculations such as closed orbit search or computation of Twiss parameters.

The involved computations are backed by the PyTorch package which also provides the relevant functionality for differentiation of user-defined quantities as well as a variety of gradient-based optimizers that integrate with the thus derived quantities.

The DiPAS package can parse MADX lattice definitions and hence allows for zero-overhead importing of existing lattices. In addition it supports custom lattice definitions from provided element classes.

Example usage

Minimizing loss along beamline by tuning quadrupoles:

import numpy
from dipas.build import from_file
from dipas.elements import Quadrupole
import torch

lattice = from_file('example.madx')

for quad in lattice[Quadrupole]:
    quad.k1 = torch.nn.Parameter(quad.k1)

optimizer = torch.optim.Adam(lattice.parameters(), lr=1e-3)

particles = torch.from_numpy(numpy.load('particles.npy'))

while True:
    tracked, loss_val = lattice.linear(particles, recloss='sum')
    lost = 1 - tracked.shape[1] / particles.shape[1]
    if lost < 0.01:  # Fraction of particles lost less than 1%.
        break
    optimizer.zero_grad()
    loss_val.backward()
    optimizer.step()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

DiPAS-1.2.2.tar.gz (1.9 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

DiPAS-1.2.2-py3-none-any.whl (176.2 kB view details)

Uploaded Python 3

File details

Details for the file DiPAS-1.2.2.tar.gz.

File metadata

  • Download URL: DiPAS-1.2.2.tar.gz
  • Upload date:
  • Size: 1.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.1.post20201107 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.9

File hashes

Hashes for DiPAS-1.2.2.tar.gz
Algorithm Hash digest
SHA256 e81f0e376e25fe420be8b20c427c6b13b0b4d1083332f683f1df738df8dc5318
MD5 349f80d7e39bd1e5306be0af70900d8d
BLAKE2b-256 f773a2af40c8e4fc4bd33d9a8260ea78da75bedefa439451cd479dadd2053ac3

See more details on using hashes here.

File details

Details for the file DiPAS-1.2.2-py3-none-any.whl.

File metadata

  • Download URL: DiPAS-1.2.2-py3-none-any.whl
  • Upload date:
  • Size: 176.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.1.post20201107 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.9

File hashes

Hashes for DiPAS-1.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f3f9c2576f1c9a6973f76931cda33cc3f999f531e1e2d4264525e5648128eaca
MD5 60dc4877f80998796339e685eabe70f6
BLAKE2b-256 2d10e285f1ac68408695c5193bc4d61efe84e05c7d118c31a66f006a57b60b52

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page