Skip to main content

Cython binding to MAD-X

Project description

Latest Version Downloads License Supported Python versions

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.

This version of CPyMAD is tested with MAD-X 5.02.05. Other MAD-X versions (and immediate revisions) might work too, but are more likely to cause problems.

The installable wheel archives that are provided for some versions of python to simplify the installation on windows contain a precompiled version of CPyMAD that is statically linked against MAD-X 5.02.05.

Disclaimer

This is a heavily modified fork of the cern-cpymad package. The fork is not authored or maintained by CERN members.

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.

Project pages

Usage

The Madx class provides a basic binding to the MAD-X interpreter:

from cpymad.madx import Madx

# create a new interpreter instance:
# the optional 'command_log' parameter can be used to store MAD-X
# command history.
madx = Madx(command_log="log.madx")

# determine the version of MAD-X that is actually loaded:
print(madx.version)

# you execute arbitrary textual MAD-X commands:
madx.input('call, file="input_file.madx";')

# there is a more convenient syntax available which does the same:
madx.command.call(file="input_file.madx")

# And for some commands there exist direct shortcuts:
madx.call('/path/to/some/input_file.madx')

# Calculate TWISS parameters:
twiss = madx.twiss(sequence='LEBT',
                   betx=0.1, bety=0.1,
                   alfx=0.1, alfy=0.1)

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

There is also a Model class which encapsulates more metadata for complex accelerator machines. If you have ready-to-use model definitions on your filesystem, models can be instanciated and used as follows:

from cpymad.model import Model

model = Model.load('/path/to/model/definition.cpymad.yml')

for sequence in model.sequences.values():
    twiss = sequence.twiss()

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

Contributing

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

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.

Tests

Currently, tests run on:

  • The Travis CI service is mainly used to check that the unit tests for pymad itself execute on several python versions. Python{2.7,3.3} are supported. The tests are executed on any update of an upstream branch. The Travis builds use a unofficial precompiled libmadx-dev package to avoid having to rebuild the entire MAD-X library on each invocation.

    Build Status Coverage

License

CPyMAD must be used in compliance with the licenses as described in the following sections:

License for CPyMAD source

applies to the python source of the CPyMAD package:

Copyright (c) 2013-2015, HIT - Heidelberg Ion-Therapy Center

To the extent possible under law, the person who associated CC0 with
CPyMAD has waived all copyright and related or neighboring rights to
CPyMAD.

You should have received a copy of the CC0 legalcode along with this
work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.

Note that this package is a heavily modified fork of the original cern-cpymad package developed at CERN:

Copyright (c) 2011, CERN. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use cern-cpymad except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

For details, see the version history or ask the package maintainer.

License for MAD-X

applies to binary distributions that do not require a separate installation of MAD-X, i.e. binaries that are statically linked to MAD-X:

CERN

EUROPEAN ORGANISATION FOR NUCLEAR RESEARCH


Program name:                 MAD --- Methodical Accelerator Design

CERN program library entry:   T5001

Authors or contacts:          mad@cern.ch
                              BE-ABP Group
                              CERN
                              CH-1211 GENEVA 23
                              SWITZERLAND


Copyright CERN, Geneva 1990 - Copyright and any other appropriate legal
protection of this computer program and associated documentation reserved
in all countries of the world. Organisations collaborating with CERN may
receive this program and documentation freely and without charge. CERN
undertakes no obligation for the maintenance of this program, nor
responsibility for its correctness, and accepts no liability whatsoever
resulting from its use. Program and documentation are provided solely for
the use of the organisation to which they are distributed. This program
may not be copied or otherwise distributed without permission. This
message must be retained on this and any other authorised copies. The
material cannot be sold. CERN should be given credit in all references.

Changelog

(dates are in the form dd.mm.yyyy)

0.10.6

Date: 29.05.2015

  • add csv() method for ResourceProvider

  • use C loader from yaml for performance if available

  • convert madx.metadata.get_copyright_notice

  • add accessors to real sequence + elements for model.Sequence

0.10.5

Date: 25.05.2015

  • add MAD-X specific metadata in cpymad.madx.metadata

  • speedup Travis testing (using caches and docker containers)

0.10.4

Date: 22.04.2015

  • prevent MAD-X process from exiting on Ctrl-C (this was an especially nasty feature when using the interactive python interpretor)

  • upgrade to MAD-X 5.02.05 (development release from 10.04.2015)

  • fix leakage of open file handles into remote process on py2/windows

0.10.3

Date: 29.03.2015

  • make sequence.elements.index more convenient: can now handle names with or without the ‘:d’ suffix as well as the special names ‘#s’ and ‘#e’

0.10.2

Date: 05.03.2015

  • add some utility functions to work with MAD-X element names and identifiers

  • add a setter method for values to Madx

  • improve install instructions. In particular, recommend WinPython as build environment

  • fix the MinGW build error due to broken sysconfig inline

  • run setup only if invoked as main script

0.10.1

Date: 09.01.2015

  • convert IOError to RemoteProcessCrashed, which can occur on transmission if the remote process is already down

  • convert ValueError to RemoteProcessClosed, which can occur on transmission if the remote process was already closed

0.10.0 Fork

Date: 09.01.2015

This is the first independent version released for the HIT cpymad fork. The changes on the public API are so heavy, that this is basically a new library.

  • rename package from cern.cpymad to cpymad

  • remove LHC models from repository

  • redesign API to make more use of OOP (no stable API yet!)

  • removed some obsolete / unused modules

0.9

Date: 17.11.2014

  • don’t link against numpy anymore (this makes distribution of prebuilt binaries on windows actually useful)

  • add MAD-X license notice (required to distribute binaries)

  • setup.py doesn’t require setuptools to be pre-installed anymore (if internet is available)

  • some doc-fixes

  • convert cpymad._couch to a simple module (was a single file package)

  • use logging through-out the project

  • alow logger to be specified as model/madx constructor argument

  • multi-column access, e.g.: table.columns['betx','bety']

  • move tests one folder level up

0.8

Date: 30.06.2014

  • isolate cpymad: remove jpymad backend, remove pymad base

  • bootstrap the dependency on numpy

  • remove custom MAD-X path discovery during setup. You should use –madxdir if the library is not installed in a system location.

  • add function libmadx.is_expanded

  • add function libmadx.chdir

  • handle MAD-X table columns with integer arrays

  • make madx.command more powerful (allows **kwargs and attribute access)

  • use inherited pipes for IPC with remote MAD-X processes (allows to forward stdin/stdout separately)

  • close connection to remote process on finalization of LibMadxClient

  • remove MAD-X command checks, recursive_history and filename completion

  • fix name clash

  • fix some bugs

  • rename convenience constructors to cern.cpymad.load_model and cern.cpymad.start_madx due to name clash with module names

0.7

Date: 16.04.2014

  • close handles in remote process properly on all supported python versions

  • rewrite libmadx.get_table functionality

  • madx functions that return tables now return proxy objects instead. For backward compatibility these can be iterated to allow unpacking into a tuple

  • the returned table columns is now a proxy object as well and not TfsTable

  • remove retdict parameter

  • move some cpymad specific functionality into the cpymad package

  • add libmadx/madx functions to access list of elements in a sequence

0.6

Date: 17.03.2014

  • 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

0.5

Date: 21.01.2014

  • migrate to setuptools from distutils

  • python3 support

  • add continuous integration with Travis

  • proper setup.py and MANIFEST.in to be used with PyPI

  • rename package to ‘cern-pymad’

  • allow to build from PyPI without having cython

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

cpymad-0.10.6.tar.gz (116.0 kB view details)

Uploaded Source

Built Distributions

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

cpymad-0.10.6-py3.4-win-amd64.egg (3.3 MB view details)

Uploaded Egg

cpymad-0.10.6-py3.4-win32.egg (2.9 MB view details)

Uploaded Egg

cpymad-0.10.6-py3.3-win-amd64.egg (3.3 MB view details)

Uploaded Egg

cpymad-0.10.6-py3.3-win32.egg (2.9 MB view details)

Uploaded Egg

cpymad-0.10.6-py2.7-win-amd64.egg (3.3 MB view details)

Uploaded Egg

cpymad-0.10.6-py2.7-win32.egg (2.8 MB view details)

Uploaded Egg

cpymad-0.10.6-cp34-none-win_amd64.whl (3.3 MB view details)

Uploaded CPython 3.4Windows x86-64

cpymad-0.10.6-cp34-none-win32.whl (2.8 MB view details)

Uploaded CPython 3.4Windows x86

cpymad-0.10.6-cp33-none-win_amd64.whl (3.3 MB view details)

Uploaded CPython 3.3Windows x86-64

cpymad-0.10.6-cp33-none-win32.whl (2.8 MB view details)

Uploaded CPython 3.3Windows x86

cpymad-0.10.6-cp27-none-win_amd64.whl (3.3 MB view details)

Uploaded CPython 2.7Windows x86-64

cpymad-0.10.6-cp27-none-win32.whl (2.8 MB view details)

Uploaded CPython 2.7Windows x86

File details

Details for the file cpymad-0.10.6.tar.gz.

File metadata

  • Download URL: cpymad-0.10.6.tar.gz
  • Upload date:
  • Size: 116.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for cpymad-0.10.6.tar.gz
Algorithm Hash digest
SHA256 046bf3dc52a0fe3e1e11ad065cdc47172c20089c1303920c4d5c20b276199de2
MD5 d3746b2b3b79fc381c16bef1ee1454c7
BLAKE2b-256 94996d1563707c0716e4ef036ae0ab6222033fcaa6bfaa79465e005d9d08f8fe

See more details on using hashes here.

File details

Details for the file cpymad-0.10.6-py3.4-win-amd64.egg.

File metadata

File hashes

Hashes for cpymad-0.10.6-py3.4-win-amd64.egg
Algorithm Hash digest
SHA256 2175c66d346d21f88cc8a8699fd0f694a8894d29ca00ded72c45d3aa62752e8f
MD5 70b76e7ccea16a472c49236b1a232d0b
BLAKE2b-256 615fdc18a0a8da2a340e8fec4f63a79806ab63077bacb688d8ea7630b5f1e54b

See more details on using hashes here.

File details

Details for the file cpymad-0.10.6-py3.4-win32.egg.

File metadata

File hashes

Hashes for cpymad-0.10.6-py3.4-win32.egg
Algorithm Hash digest
SHA256 06c1b4aedb84224b3fe4285fc3ae7e3788f6ed516ce6899b5cf8f6e9c4e8a90e
MD5 afd718d17d9d113356688dbaaba51b38
BLAKE2b-256 8af15337c1e55d5fbb0091e8a22eeecbab990bd5cd4cb6013da53e7cdb9b4a84

See more details on using hashes here.

File details

Details for the file cpymad-0.10.6-py3.3-win-amd64.egg.

File metadata

File hashes

Hashes for cpymad-0.10.6-py3.3-win-amd64.egg
Algorithm Hash digest
SHA256 b6f6fc1e6cdb39a8dde0c8b5afeebe108a720ff58249c15ba18c0471b403c6ba
MD5 e783b901331137cabf0cbb8c7b4cdcdf
BLAKE2b-256 8a31b416faaa7a482b79d753eb208988db90c423da4747456d87133ffac00656

See more details on using hashes here.

File details

Details for the file cpymad-0.10.6-py3.3-win32.egg.

File metadata

File hashes

Hashes for cpymad-0.10.6-py3.3-win32.egg
Algorithm Hash digest
SHA256 0166c90fb87b8e4cf991d76757c57f59d52aac11e0bad5fbb20ad7cce18ad853
MD5 e5ed46f8d84bb5facb52817b7793a318
BLAKE2b-256 4241b9890b191138faca109f23ca405aa1d12ddf6e005b339493f31bdb0f2a75

See more details on using hashes here.

File details

Details for the file cpymad-0.10.6-py2.7-win-amd64.egg.

File metadata

File hashes

Hashes for cpymad-0.10.6-py2.7-win-amd64.egg
Algorithm Hash digest
SHA256 6de0183e4f390fa9069dd8e6d676c751c98226c014d87d049b8058dd42350fa6
MD5 2d8b7d81501d18f21e37ea6bf2574176
BLAKE2b-256 a47a93bb4f6e75726a2c09dc070f2f970ecbd6eb26e24ccd706859a8c788004f

See more details on using hashes here.

File details

Details for the file cpymad-0.10.6-py2.7-win32.egg.

File metadata

File hashes

Hashes for cpymad-0.10.6-py2.7-win32.egg
Algorithm Hash digest
SHA256 829193ceddd5ea7c36cd821d90044d157d2a937d1e3c49c9a82eaae5a6c24318
MD5 30c5d163d80dfa9b7ddade13c1d9db91
BLAKE2b-256 b019c2cce0a255096647e40915eced3f6866c152e295439cc8e8efdf405eb258

See more details on using hashes here.

File details

Details for the file cpymad-0.10.6-cp34-none-win_amd64.whl.

File metadata

File hashes

Hashes for cpymad-0.10.6-cp34-none-win_amd64.whl
Algorithm Hash digest
SHA256 337d83ace0e6db356adb76ea59d33ffcd26939eb7d20eeb65e9b1a12f0aeba44
MD5 4a346e690d183d5e6f2e59109979fc6d
BLAKE2b-256 cef4693f2fb719e374ee6e2b77f86fd5a66d1a1f04a131045b05420a57dccc0d

See more details on using hashes here.

File details

Details for the file cpymad-0.10.6-cp34-none-win32.whl.

File metadata

File hashes

Hashes for cpymad-0.10.6-cp34-none-win32.whl
Algorithm Hash digest
SHA256 4e1b36c09ed1610f8721073a72b4cb75ea9cd2014c5d3c34329987598ee4ae53
MD5 8b0503f0b00a753284ffd1d87bde0e42
BLAKE2b-256 d8fd9a92f3718114b0152a3125ff5ab15f56ce2248db83aff9da192b1ca8ed6b

See more details on using hashes here.

File details

Details for the file cpymad-0.10.6-cp33-none-win_amd64.whl.

File metadata

File hashes

Hashes for cpymad-0.10.6-cp33-none-win_amd64.whl
Algorithm Hash digest
SHA256 0902b63ad3bda9d6b931a2de7a2076def3d43e2b2bbaa9d94a9b7142afb6717c
MD5 00bf5979021e4ec7c3ebb9e7b0161fb0
BLAKE2b-256 ad9dac0d926e1c0d9c68ffccd78212e886f66d9f49eaa2fb2e6040637bb06d3d

See more details on using hashes here.

File details

Details for the file cpymad-0.10.6-cp33-none-win32.whl.

File metadata

File hashes

Hashes for cpymad-0.10.6-cp33-none-win32.whl
Algorithm Hash digest
SHA256 6732667b631188d139ead72907d2b16eb433284a27b30704f134ea7cc5ceecc1
MD5 a80aa776bb9708799e30ffdafd65ecc2
BLAKE2b-256 7fe5c7802ed3a3ab3aacbc1676dcc0ae470e60366e7f1f452e9b90e9a263b980

See more details on using hashes here.

File details

Details for the file cpymad-0.10.6-cp27-none-win_amd64.whl.

File metadata

File hashes

Hashes for cpymad-0.10.6-cp27-none-win_amd64.whl
Algorithm Hash digest
SHA256 f05f5367613a4f2af994bb309bc116c1cc7255f75ab3c104b6c9ec8b096ff7ef
MD5 e5350a1bf02c17658b2b522385b48ede
BLAKE2b-256 67ded6a899f84057fe9a753c2ef1757ff03259f4af581c7e3c47937ee4f9fe62

See more details on using hashes here.

File details

Details for the file cpymad-0.10.6-cp27-none-win32.whl.

File metadata

File hashes

Hashes for cpymad-0.10.6-cp27-none-win32.whl
Algorithm Hash digest
SHA256 dcbf734b08c64f5101a95387465d8ad51eff687645b94e2ebd2aef500d1c26cc
MD5 58599ff550ac599254dd4b7c5be1947f
BLAKE2b-256 836fa3c365690b0a434fc83eba8e3ae41aac419aca2219da98a6f7e500cf7ec6

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