cPyMAD is a python interface to Mad-X using cython and libmadx
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


WARNING: This project is currently unmaintained! Please consider using the active fork at:


See also Project status.


CPyMad is a Cython binding to MAD-X.

MAD-X is a software package to simulate particle accelerators and is used at CERN and all around the world. It has its own proprietary scripting language and is usually launched from the command line.

There is also a binding via JMad called JPyMAD. This has less features but does not require a C compiler for installing.

IMPORTANT: cern-cpymad links against an unofficial build of MAD-X that is not supported by CERN, i.e. in case of problems you will not get help there.


To build MAD-X and CPyMAD from source you will need

  • CMake
  • python>=2.6
  • C / Fortran compilers.

Furthermore, CPyMAD depends on the following python packages:

The python packages can be installed using pip.


Installation instructions are available at http://pymad.github.io/cpymad/installation.


from cern import cpymad

# Instanciate a model:
m = cpymad.load_model('lhc')

# Calculate TWISS parameters:
twiss, summary = m.twiss()

# Your own analysis below:
from matplotlib import pyplot as plt
plt.plot(twiss['s'], twiss['betx'])

See http://pymad.github.io/cpymad for further documentation.

Project Status

There are currently no active developers working on this project. The code might still be working fine against the current stable and development version of Mad-X, so it could still be useful. Below you find a list of alternative projects which may have a more complete feature set and documentation.

Known Forks and Similar Projects:

Development guidelines


Try to be consistent with the PEP8 guidelines as far as you are familiar with it. Add unit tests for all non-trivial functionality. Dependency injection is a great pattern to keep modules testable.

Version control:

Commits should be reversible, independent units if possible. Use descriptive titles and also add an explaining commit message unless the modification is trivial. See also: A Note About Git Commit Messages.


Currently, two major test services are used:

  • The tests on CDash are run on a daily basis on the master branch and on update of the testing branch. It ensures that the integration tests for the LHC models are working correctly on all tested platforms. The tests are run only on specific python versions.
  • The Travis CI service is mainly used to check that the unit tests for pymad itself execute on several python versions. Python{2.6,2.7,3.3} are supported. The tests are executed on any update of an upstream branch.

Contribution work flow:

All changes are reviewed via pull-requests. Before merging to master the pull-request must reside aliased by the testing branch long enough to be confirmed as stable. Any issues are discussed in the associated issue thread. Concrete suggestions for changes are best posed as pull-requests onto the feature branch.