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. this binary may have problems that the official binary does not have and vice versa. This means:

  • Only report issues to CERN that can be reproduced with their official command line client.

  • Only report issues here if they cannot be reproduced with their official command line client.

See Reporting issues.

Project pages

Usage

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

from cpymad.madx import Madx

# Start a MAD-X interpretor. All MAD-X commands issued via cpymad will
# be logged to `command_log`:
madx = Madx(command_log="log.madx")

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

# Execute one of your predefined MAD-X files:
madx.call('/path/to/some/input_file.madx')

# Only a handful of MAD-X methods are exposed as methods. For others,
# you can use the `command` attribute. For example, to set a beam:
madx.command.beam(sequence='myseq1', particle='PROTON')

# 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 are alternative syntaxes for the extreme cases where you need more fine grained control over the command string composition or where command fails to do the right thing:

# can't use `global` as attribute, since it's a python keyword:
madx.command('global', sequence='cassps', Q1=26.58)

# issue a plain text command, don't forget the semicolon!
madx.input('FOO, BAR=[baz], QUX=<NORF>;')

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

Known issues

On windows with python3.3, there is currently no satisfying way to close file handles in the MAD-X process or prevent them from being inherited by default. You have to make sure on your own that you close all file handles before creating a new cpymad.madx.Madx instance!

Hacking

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.

Reporting issues

If you have a problem with a sequence file, first try to check if that problem remains when using the MAD-X command line client distributed by CERN, then:

  • Report the issue to CERN only if it be reproduced with their official command line client.

  • Report the issue here only if it cannot be reproduced with their official command line client.

For issues regarding the cpymad code itself or usage information, I’m happy to answer. Just keep in mind to be precise, specific, concise and provide all the necessary information.

See also:

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

Date: 13.10.2015

  • fix crash due to incorrect parameter name for logging.basicConfig

  • fix crash due to missing subprocess.MAXFD on python3.5

  • fix coverage report submitted to coveralls.io

0.12.0

Date: 05.10.2015

  • expose directory of global MAD-X variables as Madx.globals

  • expose directory of global MAD-X elements as Madx.elements

  • fix a bug with Elements.__contains__ reporting yes incorrectly

  • list only those column of a table that are marked for output

  • add function to get row names of a table

0.11.0

Date: 03.07.2015

  • Remove models + resource handling from cpymad. If you need these, check them out from the previous version and maintain them in your own code base. This way you are much more flexible to adapt models to your needs.

0.10.8

Date: 02.07.2015

  • Public element names are now of the form “foo[3]” or simply “foo”. The syntax “foo:d” can not be used anymore (this form is used by MAD-X only internally and converted at the lowest wrapper level).

  • Fix exception when not specifying sequence name on Madx methods

0.10.7

Date: 21.06.2015

  • allow redirection of MAD-X standard I/O via Madx constructor

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.12.1.tar.gz (120.4 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.12.1-py3.4-win-amd64.egg (3.3 MB view details)

Uploaded Egg

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

Uploaded Egg

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

Uploaded Egg

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

Uploaded Egg

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

Uploaded Egg

cpymad-0.12.1-py2.7-win32.egg (2.9 MB view details)

Uploaded Egg

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

Uploaded CPython 3.4Windows x86-64

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

Uploaded CPython 3.4Windows x86

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

Uploaded CPython 3.3Windows x86-64

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

Uploaded CPython 3.3Windows x86

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

Uploaded CPython 2.7Windows x86-64

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

Uploaded CPython 2.7Windows x86

File details

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

File metadata

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

File hashes

Hashes for cpymad-0.12.1.tar.gz
Algorithm Hash digest
SHA256 a53c9cb74e23d34d27107238ec14f551b71fc85b0f9b06e03ba0b9641594f5d7
MD5 6e55d7716dacb34759b116495e14fa03
BLAKE2b-256 31e97d0f0aa3f994cabee8e712036f41814dfadf39dfa453ad9ec0a20a9e0e12

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cpymad-0.12.1-py3.4-win-amd64.egg
Algorithm Hash digest
SHA256 d66eacce6c4bc4904a0286656a56f2f644a84ab667ebd8358d1ca48c8e4e237a
MD5 733493352828780d6cc17a5e39a5ce16
BLAKE2b-256 14f7e1c2a7fb47c4f43a12b0c7faca5979e31f2f61c01998da6de2aaeb890c8e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cpymad-0.12.1-py3.4-win32.egg
Algorithm Hash digest
SHA256 0634f95d0fd5502e34103b186208630c85406f8612e37fbbbaa5b8e56efab4e4
MD5 aa2b4217a6a5815d87cfbf12ccf2ae0c
BLAKE2b-256 0f23a6726b598a04cbaaaa71bb5ea2ff3aca078c5ccb9f3564625757d004f29b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cpymad-0.12.1-py3.3-win-amd64.egg
Algorithm Hash digest
SHA256 23850cf81b8ffd200dd4786f9cd2aec2b8242daf194d2d671fe8f7c145e7e42d
MD5 1efff930bc06d7155ec046c9f4b03f45
BLAKE2b-256 a7dea4b0e1352a8a4e0950c4daed7470fd246025081915e0044fa0e78465314b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cpymad-0.12.1-py3.3-win32.egg
Algorithm Hash digest
SHA256 33e09b2c03cc049f91a53459a73866d3ac2dbc2c4891fbed7f903693878f3366
MD5 f29883e70e682c4947510ba2fcf2f171
BLAKE2b-256 2f78409f726d4477d4ebe95661956a0e12e9440d8f1aeec46ae04015ea402154

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cpymad-0.12.1-py2.7-win-amd64.egg
Algorithm Hash digest
SHA256 c7e6669ec51fb1ab018d0b9fa3d3c3595d5aab04bfa7b195143b0b4fcdedbe42
MD5 0b2daaaf266347df45ada7602cb13075
BLAKE2b-256 0eac0b00b8a226012d32de5b7df6ccafe4ac619e1d1bf97d0f0a3947448dcb39

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cpymad-0.12.1-py2.7-win32.egg
Algorithm Hash digest
SHA256 8401941233677e327e70eeca7775c4b385dfe1a7dcd602eb22df0c0eca4a1ac7
MD5 328c27217ea2c5e78139cf767f32718a
BLAKE2b-256 534e77338b96be388ec3c92191d4dbba40e5c20401ec1a2504acfa9c3ca82b6d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cpymad-0.12.1-cp34-none-win_amd64.whl
Algorithm Hash digest
SHA256 e3ed3169e87d5eb39ce1f9e01758496e7cb20fef0ab521675d0de9639f469025
MD5 d59f83f09788598b442c1aabc73cc2b6
BLAKE2b-256 1535a7260b0b6a774cdefa181e020282d6eb1026920779d9dfeeb9880ad1a938

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cpymad-0.12.1-cp34-none-win32.whl
Algorithm Hash digest
SHA256 9583602052750806918b47a2b346bb17315fddf343caebb60830cb558d29e648
MD5 68b7ca8c61bd27dede44aa016fbd6cc1
BLAKE2b-256 5b55b98257f8f2b9fa882155560d3fed5e9267bd0392c09e958480e28f6fb997

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cpymad-0.12.1-cp33-none-win_amd64.whl
Algorithm Hash digest
SHA256 27fc8f540db49a1be3caf163780ee6a1151d102a5df1593087d853de3e673049
MD5 70ce4343adcd7a25cbc5fcd81d75efd9
BLAKE2b-256 462b00dc7b3b6ade64ef758d4b56374ee67eafb9085977bb5768010b37621532

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cpymad-0.12.1-cp33-none-win32.whl
Algorithm Hash digest
SHA256 116b5e3837a83b2c1b0e5377c822e8d64c7c44ca2d34aadfa70750669eb31df6
MD5 809f434bdae9ec6a5dde9da779c23a6d
BLAKE2b-256 641744bb0a9b110bafe682379871ee81e866fbcc49ea724b310f983698a1d0c3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cpymad-0.12.1-cp27-none-win_amd64.whl
Algorithm Hash digest
SHA256 48d5345760567d3ac2048c733370264d7a76310c2b4b97ca6fba14c772819cc6
MD5 83ce0233d0110e0f7c28b879ec9ff183
BLAKE2b-256 f1e5d9421db832b3232a78d8f7e6b254af2c973ad3ff750c6303f82827f87a0b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cpymad-0.12.1-cp27-none-win32.whl
Algorithm Hash digest
SHA256 5cfef076ba24ba58a505011f87260329ca3a1338782eb83eb3efa5021abac2b2
MD5 933947a21420e9336eab985bb8df322f
BLAKE2b-256 ef7ebeb81a441f06064158ff9e25267c2f39c875d2338e4cc15aa6198662d494

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