Skip to main content

DiPAS is a framework for differentiable simulations of particle accelerators.

Project description

pipeline coverage pypi python


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 program 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.

DiPAS can also be used via command line interface, see dipas --help for more information.

Relevant links

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-2.0.tar.gz (2.0 MB view hashes)

Uploaded Source

Built Distribution

DiPAS-2.0-py3-none-any.whl (201.3 kB view hashes)

Uploaded Python 3

Supported by

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