skip to navigation
skip to content

Not Logged In

cern-pymad 0.6

Interface to Mad-X, using Cython or Py4J through JMAD

PyMAD is a python wrapper for MAD-X (Methodical Accelerator Design). It can be used in either of two modes:

  • cpymad uses Cython to access the Mad-X library directly
  • jpymad uses JMad via Py4J which then accesses the Mad-X library



  • python with numpy


  • Cython
  • gfortran or similar
  • MAD-X shared library
  • madextern.h in your include path



Further instructions are available at


# Once installed this is a nice example showing current
# usability (run from examples folder):
from cern import pymad

# select backend,
# 'cpymad' is currently default if nothing is provided
# Returns a pymad.service object
pms = pymad.init('jpymad')

# Create a model:
pm = pms.create_model('lhc')

# Run twiss:
# This returns a "lookup dictionary" containing
# numpy arrays. Lowercase keys.
twiss,summary = pm.twiss()

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

See for further documentation.

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:

This motivates the following work flow when performing any changes:

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.



  • raise exception and don't hang up anymore, if libmadx process crashes
  • on python>=3.4, close handles in remote process properly
  • let every 'Madx' instance have an independent copy of the madx library. this makes the madx module much more useful. previously, this was only true for instances of 'cpymad.model'.
  • restrict to only one cython module that links to libmadx. (allows static linking which is advantageous on windows!)
  • use YAML model files instead of JSON
  • make 'madx' a submodule of 'cpymad'
  • fix test exit status


  • migrate to setuptools from distutils
  • python3 support
  • add continuous integration with Travis
  • proper and to be used with PyPI
  • rename package to 'cern-pymad'
  • allow to build from PyPI without having cython
File Type Py Version Uploaded on Size
cern-pymad-0.6.tar.gz (md5) Source 2014-03-17 1MB
  • Downloads (All Versions):
  • 38 downloads in the last day
  • 258 downloads in the last week
  • 824 downloads in the last month