Cython binding to MAD-X
Project description
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.
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.
Dependencies
To build MAD-X and CPyMAD from source you will need
python>=2.7
C / Fortran compilers.
Furthermore, CPyMAD depends on the following python packages:
The python packages can be installed using pip.
Installation
Installation instructions are available at http://hibtc.github.io/cpymad/installation.
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")
# 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.
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-2014, 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
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
Built Distributions
Hashes for cpymad-0.10.1.post1.win-amd64-py2.7.exe
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3899a594ee6c09cf45099616e30a96e8e15f887f76a5e65bbbeb8e1794a1c81d |
|
MD5 | 7f4f71a7216dc585477778f7a97666b2 |
|
BLAKE2b-256 | 568022a2cfd87e608d81fc31a471491f3486e574e27fa14618060a2ce7cd52ca |
Hashes for cpymad-0.10.1.post1.win32-py2.7.exe
Algorithm | Hash digest | |
---|---|---|
SHA256 | bcdebc96367f4c0e1811c78d8b39291aa9ef7d7a89af4db033a4c53edb3f1632 |
|
MD5 | 5bfab97dc807536990bce011628d573a |
|
BLAKE2b-256 | eb784c12132375cbcc2c34571d5759f467e31bd0459bc5a3b6cd5e9c68829b7b |
Hashes for cpymad-0.10.1.post1-py2.7-win-amd64.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | 80c677de0245867b7610302285a6c962417a0a3bca2e23bd8114f822008d8284 |
|
MD5 | cffd5ff0b2ad05cac73230478f19ffdf |
|
BLAKE2b-256 | e92411cbbdb267be29cb316c5aecd7f46f7cbdfcccefd35047ab07336db8f460 |
Hashes for cpymad-0.10.1.post1-py2.7-win32.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | e16ec847d1bb6b6c739b1924e83e31d63f5d507545f630772e27dc5a387b612c |
|
MD5 | 28428e5a7086230e74b983914229f225 |
|
BLAKE2b-256 | a7489f4145f5d4baefeb3f3b015c75fdd85548ae789a8b5c536fc185ebeac08b |
Hashes for cpymad-0.10.1.post1-cp27-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 545a96680e3fd4d24252ad58747300bea88bf9c635c515c5741e489a16a8eb66 |
|
MD5 | dbe82545db85db40888176006a0fc211 |
|
BLAKE2b-256 | 3378b7fe5447d1bacf804cc96449db83eb4e9a2290bcf7c5ca4d20b7999b8aed |
Hashes for cpymad-0.10.1.post1-cp27-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 51fa3741b2e3813c46ef554927d7bff2749fc322984c4a04cb11f01413886363 |
|
MD5 | 75e7357c84ac03a085fda9569abf3fec |
|
BLAKE2b-256 | 12cf0670063ebc088f3aced8388d67a370b6d1bf75bf99443d4d3112e7a8c598 |