+[docs]
+ def__call__(self,command:str):
+"""Log a single history line and flush to file immediately."""
+ self._file.write(self._prefix+command+self._suffix)
+ self._file.flush()
+[docs]
+classMadx:
+
+"""
+ Python interface for a MAD-X process.
+
+ For usage instructions, please refer to:
+
+ https://hibtc.github.io/cpymad/getting-started
+
+ Communicates with a MAD-X interpreter in a background process.
+
+ The state of the MAD-X interpreter is controlled by feeding textual MAD-X
+ commands to the interpreter.
+
+ The state of the MAD-X interpreter is accessed by directly reading the
+ values from the C variables in-memory and sending the results pickled back
+ over the pipe.
+
+ Data attributes:
+
+ :ivar command: Mapping of all MAD-X commands.
+ :ivar globals: Mapping of global MAD-X variables.
+ :ivar elements: Mapping of globally visible elements.
+ :ivar base_types: Mapping of MAD-X base elements.
+ :ivar sequence: Mapping of all sequences in memory.
+ :ivar table: Mapping of all tables in memory.
+ """
+
+ def__init__(self,libmadx=None,command_log=None,stdout=None,
+ history=None,prompt=None,**Popen_args):
+"""
+ Initialize instance variables.
+
+ :param libmadx: :mod:`libmadx` compatible object
+ :param command_log: Log all MAD-X commands issued via cpymad.
+ :param stdout: file descriptor, file object or callable
+ :param str prompt: prefix for a new :class:`CommandLog`
+ :param Popen_args: Additional parameters to ``subprocess.Popen``
+
+ If ``libmadx`` is NOT specified, a new MAD-X interpreter will
+ automatically be spawned. This is what you will mostly want to do. In
+ this case any additional keyword arguments are forwarded to
+ ``subprocess.Popen``. The most prominent use case for this is to
+ redirect or suppress the MAD-X standard I/O::
+
+ m = Madx(stdout=False)
+
+ with open('madx_output.log', 'w') as f:
+ m = Madx(stdout=f)
+
+ m = Madx(stdout=sys.stdout)
+ """
+ ifisinstance(command_log,str):
+ # open new history file:
+ command_log=CommandLog.create(command_log,promptor'')
+ elifhasattr(command_log,'write'):
+ # assuming stream already opened:
+ command_log=CommandLog(command_log,promptor'')
+ elifpromptisnotNone:
+ assertcommand_logisNone, \
+ "Passing fully constructed `command_log` instances is " \
+ "incompatible with parameter `prompt`."
+ command_log=CommandLog(sys.stdout,prompt)
+ self.reader=NullContext()
+ # start libmadx subprocess
+ iflibmadxisNone:
+ ifstdoutisNone:
+ stdout=sys.stdout
+ ifhasattr(stdout,'write'):
+ # Detect if stdout is attached to a jupyter notebook:
+ cls=getattr(stdout,'__class__',type(None))
+ qualname=cls.__module__+'.'+cls.__name__
+ ifqualname=='ipykernel.iostream.OutStream':
+ # In that case we want to behave the same way as `print`
+ # (i.e. log to the notebook not to the terminal). On
+ # linux, python>=3.7 within notebooks 6.4 `sys.stdout` has
+ # a valid sys.stdout.fileno(), but writing to it outputs
+ # to the terminal, so we have to use `sys.stdout.write()`:
+ stdout=stdout.write
+ else:
+ # Otherwise, let the OS handle MAD-X output, by passing
+ # the file descriptor if available. This is preferred
+ # because it is faster, and also because it means that the
+ # MAD-X output is directly connected to the output as
+ # binary stream, without potential recoding errors.
+ try:
+ stdout=stdout.fileno()
+ except(AttributeError,OSError,IOError):
+ stdout=stdout.write
+ # Check for text stream to prevent TypeError (see #110).
+ ifcallable(stdout):
+ try:
+ stdout(b'')
+ except(TypeError,ValueError):
+ stdout=TextCallback(stdout)
+ Popen_args['stdout']= \
+ subprocess.PIPEifcallable(stdout)elsestdout
+ # stdin=None leads to an error on windows when STDIN is broken.
+ # Therefore, we need set stdin=os.devnull by passing stdin=False:
+ Popen_args.setdefault('stdin',False)
+ Popen_args.setdefault('bufsize',0)
+ self._service,self._process= \
+ _rpc.LibMadxClient.spawn_subprocess(**Popen_args)
+ libmadx=self._service.libmadx
+ ifcallable(stdout):
+ self.reader=AsyncReader(self._process.stdout,stdout)
+ ifnotlibmadx.is_started():
+ withself.reader:
+ libmadx.start()
+ # init instance variables:
+ self.history=history
+ self._libmadx=libmadx
+ self._command_log=command_log
+ self.command=CommandMap(self)
+ self.globals=VarList(self)
+ self.elements=GlobalElementList(self)
+ self.base_types=BaseTypeMap(self)
+ self.sequence=SequenceMap(self)
+ self.beams=BeamMap(self)
+ self.table=TableMap(self._libmadx)
+ self._enter_count=0
+ self._batch=None
+
+ def__bool__(self):
+"""Check if MAD-X is up and running."""
+ try:
+ libmadx=self._libmadx
+ # short-circuit implemented in minrpc.client.RemoteModule:
+ returnbool(libmadx)andlibmadx.is_started()
+ except(_rpc.RemoteProcessClosed,_rpc.RemoteProcessCrashed):
+ returnFalse
+
+ def__getattr__(self,name):
+"""Resolve missing attributes as commands."""
+ try:
+ returngetattr(self.command,name)
+ exceptAttributeError:
+ raiseAttributeError(
+ 'Unknown attribute or command: {!r}'.format(name))fromNone
+
+
+
+
+ exit=quit
+
+ def__enter__(self):
+"""Use as context manager to ensure that MAD-X is terminated."""
+ returnself
+
+ def__exit__(self,*exc_info):
+ self.quit()
+
+ # Data descriptors:
+
+ @property
+ defversion(self)->Version:
+"""Get the MAD-X version."""
+ returnVersion(self._libmadx.get_version_number(),
+ self._libmadx.get_version_date())
+
+ @property
+ defoptions(self)->"Command":
+"""Values of current options."""
+ returnCommand(self,self._libmadx.get_options())
+
+ @property
+ defbeam(self):
+"""Get the current default beam."""
+ returnCommand(self._madx,self._libmadx.get_current_beam())
+
+ # Methods:
+
+
+[docs]
+ definput(self,text:str)->bool:
+"""
+ Run any textual MAD-X input.
+
+ :param text: command text
+ :returns: whether the command has completed without error
+ """
+ text=text.rstrip(';')+';'
+ ifself._enter_count>0:
+ self._batch.append(text)
+ returnTrue
+ # write to history before performing the input, so if MAD-X
+ # crashes, it is easier to see, where it happened:
+ ifself.historyisnotNone:
+ self.history.append(text)
+ ifself._command_log:
+ self._command_log(text)
+ try:
+ withself.reader:
+ returnself._libmadx.input(text)
+ except_rpc.RemoteProcessCrashed:
+ raiseRuntimeError("MAD-X has stopped working!")fromNone
+
+
+ __call__=input
+
+
+[docs]
+ @contextmanager
+ defbatch(self):
+"""
+ Collect input and send in a single batch when leaving context. This is
+ useful to improve performance when issueing many related commands in
+ quick succession.
+
+ Example:
+
+ >>> with madx.batch():
+ ... madx.globals.update(optic)
+ """
+ self._enter_count+=1
+ ifself._enter_count==1:
+ self._batch=[]
+ try:
+ yieldNone
+ finally:
+ self._enter_count-=1
+ ifself._enter_count==0:
+ self.input("\n".join(self._batch))
+ self._batch=None
+
+
+
+[docs]
+ defexpr_vars(self,expr:str)->list:
+"""Find all variable names used in an expression. This does *not*
+ include element attribute nor function names."""
+ ifnotisinstance(expr,str):
+ return[]
+ return[vforvinutil.expr_symbols(expr)
+ ifutil.is_identifier(v)
+ andvinself.globals
+ andself._libmadx.get_var_type(v)>0]
+
+
+
+[docs]
+ defchdir(self,dir:str)->util.ChangeDirectory:
+"""
+ Change the directory of the MAD-X process (not the current python process).
+
+ :param dir: new path name
+ :returns: a context manager that can change the directory back
+
+ It can be used as context manager for temporary directory changes::
+
+ with madx.chdir('/x/y/z'):
+ madx.call('file.x')
+ madx.call('file.y')
+ """
+ returnutil.ChangeDirectory(dir,self._chdir,self._libmadx.getcwd)
+
+
+ # Turns `dir` into a keyword argument for CHDIR command:
+ def_chdir(self,dir:str):
+ returnself.command.chdir(dir=dir)
+
+
+[docs]
+ defcall(self,file:str,chdir:bool=False):
+"""
+ CALL a file in the MAD-X interpreter.
+
+ :param file: file name with path
+ :param chdir: temporarily change directory in MAD-X process
+ """
+ ifchdir:
+ dirname,basename=os.path.split(file)
+ withself.chdir(dirname):
+ self.command.call(file=basename)
+ else:
+ self.command.call(file=file)
+
+
+
+[docs]
+ deftwiss(self,**kwargs):
+"""
+ Run TWISS.
+
+ :param str sequence: name of sequence
+ :param kwargs: keyword arguments for the MAD-X command
+
+ Note that the kwargs overwrite any arguments in twiss_init.
+ """
+ ifnotself.command.twiss(**kwargs):
+ raiseTwissFailed()
+ table=kwargs.get('table','twiss')
+ if'file'notinkwargs:
+ self._libmadx.apply_table_selections(table)
+ returnself.table[table]
+
+
+
+[docs]
+ defsurvey(self,**kwargs):
+"""
+ Run SURVEY.
+
+ :param str sequence: name of sequence
+ :param kwargs: keyword arguments for the MAD-X command
+ """
+ self.command.survey(**kwargs)
+ table=kwargs.get('table','survey')
+ if'file'notinkwargs:
+ self._libmadx.apply_table_selections(table)
+ returnself.table[table]
+
+
+
+[docs]
+ defuse(self,sequence:str=None,range:str=None,**kwargs):
+"""
+ Run USE to expand a sequence.
+
+ :param str sequence: sequence name
+ :returns: name of active sequence
+ """
+ self.command.use(sequence=sequence,range=range,**kwargs)
+
+
+
+[docs]
+ defsectormap(self,elems,**kwargs):
+"""
+ Compute the 7D transfer maps (the 7'th column accounting for KICKs)
+ for the given elements and return as Nx7x7 array.
+ """
+ self.command.select(flag='sectormap',clear=True)
+ foreleminelems:
+ self.command.select(flag='sectormap',range=elem)
+ withutil.temp_filename()assectorfile:
+ self.twiss(sectormap=True,sectorfile=sectorfile,**kwargs)
+ returnself.sectortable(kwargs.get('sectortable','sectortable'))
+
+
+
+[docs]
+ defsectortable(self,name='sectortable'):
+"""Read sectormap + kicks from memory and return as Nx7x7 array."""
+ tab=self.table[name]
+ cnt=len(tab['r11'])
+ returnnp.vstack((
+ np.hstack((tab.rmat(slice(None)),
+ tab.kvec(slice(None)).reshape((6,1,-1)))),
+ np.hstack((np.zeros((1,6,cnt)),
+ np.ones((1,1,cnt)))),
+ )).transpose((2,0,1))
+
+
+
+[docs]
+ defsectortable2(self,name='sectortable'):
+"""Read 2nd order sectormap T_ijk, return as Nx6x6x6 array."""
+ tab=self.table[name]
+ returntab.tmat(slice(None)).transpose((3,0,1,2))
+
+
+
+[docs]
+ defmatch(self,
+ constraints=[],
+ vary=[],
+ weight=None,
+ method=('lmdif',{}),
+ knobfile=None,
+ limits=None,
+ **kwargs)->dict:
+"""
+ Perform a simple MATCH operation.
+
+ For more advanced cases, you should issue the commands manually.
+
+ :param list constraints: constraints to pose during matching
+ :param list vary: knob names to be varied
+ :param dict weight: weights for matching parameters
+ :param str knobfile: file to write the knob values to
+ :param dict kwargs: keyword arguments for the MAD-X command
+ :returns: final knob values
+
+ Example:
+
+ >>> from cpymad.madx import Madx
+ >>> from cpymad.types import Constraint
+ >>> m = Madx()
+ >>> m.call('sequence.madx')
+ >>> twiss_init = {'betx': 1, 'bety': 2, 'alfx': 3, 'alfy': 4}
+ >>> m.match(
+ ... sequence='mysequence',
+ ... constraints=[
+ ... dict(range='marker1',
+ ... betx=Constraint(min=1, max=3),
+ ... bety=2)
+ ... ],
+ ... vary=['qp1->k1',
+ ... 'qp2->k1'],
+ ... **twiss_init,
+ ... )
+ >>> tw = m.twiss('mysequence', **twiss_init)
+ """
+ command=self.command
+ # MATCH (=start)
+ command.match(**kwargs)
+ ifweight:
+ command.weight(**weight)
+ forcinconstraints:
+ command.constraint(**c)
+ limits=limitsor{}
+ forvinvary:
+ command.vary(name=v,**limits.get(v,{}))
+ command[method[0]](**method[1])
+ command.endmatch(knobfile=knobfile)
+ returndict((knob,self.eval(knob))forknobinvary)
+[docs]
+ defeval(self,expr)->float:
+"""
+ Evaluates an expression and returns the result as double.
+
+ :param str expr: expression to evaluate.
+ :returns: numeric value of the expression
+ """
+ ifisinstance(expr,(float,int,bool)):
+ returnexpr
+ ifisinstance(expr,(list,ArrayAttribute)):
+ return[self.eval(x)forxinexpr]
+ returnself._libmadx.eval(expr)
+
+
+
+classBaseElementList:
+
+"""
+ Immutable list of beam line elements.
+
+ Each element is a dictionary containing its properties.
+ """
+
+ def__contains__(self,element):
+"""Check if sequence contains element with specified name."""
+ try:
+ self.index(element)
+ returnTrue
+ exceptValueError:
+ returnFalse
+
+ def__getitem__(self,index):
+"""Return element with specified index."""
+ ifisinstance(index,str):
+ # allow element names to be passed for convenience:
+ try:
+ index=self.index(index)
+ exceptValueError:
+ raiseKeyError(
+ "Unknown element: {!r}".format(index))fromNone
+ # _get_element accepts indices in the range [0, len-1]. The following
+ # extends the accepted range to [-len, len+1], just like for lists:
+ _len=len(self)
+ ifindex<-_lenorindex>=_len:
+ raiseIndexError("Index out of bounds: {}, length is: {}"
+ .format(index,_len))
+ ifindex<0:
+ index+=_len
+ data=self._get_element(index)
+ data['index']=index
+ ifdata['base_type']=='sequence':
+ returnSequence(data['name'],self._madx)
+ else:
+ returnElement(self._madx,data)
+
+ def__len__(self):
+"""Get number of elements."""
+ returnself._get_element_count()
+
+ defindex(self,name):
+"""
+ Find index of element with specified name.
+
+ :raises ValueError: if the element is not found
+ """
+ iflen(self)==0:
+ raiseValueError('Empty element list.')
+ name=name.lower()
+ ifname=='#s':
+ return0
+ elifname=='#e':
+ returnlen(self)-1
+ index=self._get_element_index(name)
+ ifindex==-1:
+ raiseValueError("Element not in list: {!r}".format(name))
+ returnindex
+
+
+
+[docs]
+classTable(_Mapping):
+
+"""
+ MAD-X twiss table.
+
+ Loads individual columns from the MAD-X process lazily only on demand.
+ """
+
+ def__init__(self,name,libmadx,*,columns='all',rows='all',_check=True):
+"""Just store the table name for now."""
+ self._name=name=name.lower()
+ self._libmadx=libmadx
+ self._columns=columns
+ self._rows=rows
+ self._cache={}
+ if_checkandnotlibmadx.table_exists(name):
+ raiseValueError("Invalid table: {!r}".format(name))
+
+
+[docs]
+ defselection(self,columns='selected',rows=None)->"Table":
+"""
+ Return a Table object that only retrieves the specified rows and
+ columns by default.
+
+ :param columns: list of names or 'all' or 'selected'
+ :param rows: list of indices or 'all' or 'selected'
+
+ If only ``columns`` is given, ``rows`` defaults to 'selected'
+ unless ``columns`` is set to 'all' in which case it also defaults
+ to 'all'.
+ """
+ ifrowsisNone:
+ rows=columnsifisinstance(columns,str)else'selected'
+ returnTable(
+ self._name,self._libmadx,
+ columns=columns,rows=rows,
+ _check=False)
+[docs]
+ defselected_columns(self):
+"""Get list of column names that were selected by the user (can be
+ empty)."""
+ returnself._libmadx.get_table_column_names(self._name,selected=True)
+
+
+
+[docs]
+ defselected_rows(self):
+"""Get list of row indices that were selected by the user (can be
+ empty)."""
+ returnself._libmadx.get_table_selected_rows(self._name)
+
+
+
+[docs]
+ defcol_names(self,columns=None):
+"""Get list of all columns in the table."""
+ ifcolumnsisNone:
+ columns=self._columns
+ ifisinstance(columns,str):
+ returnself._libmadx.get_table_column_names(
+ self._name,selected=columns=='selected')
+ else:
+ returncolumns
+
+
+
+[docs]
+ defrow_names(self,rows=None):
+"""
+ Get table row names.
+
+ WARNING: using ``row_names`` after calling ``USE`` (before recomputing
+ the table) is unsafe and may lead to segmentation faults or incorrect
+ results.
+ """
+ ifrowsisNone:
+ rows=self._rows
+ returnself._libmadx.get_table_row_names(self._name,rows)
+
+
+ @property
+ defrange(self):
+"""Get the element names (first, last) of the valid range."""
+ row_count=self._libmadx.get_table_row_count(self._name)
+ range=(0,row_count-1)
+ returntuple(self._libmadx.get_table_row_names(self._name,range))
+
+
+[docs]
+ defcolumn(self,column:str,rows=None)->np.ndarray:
+"""Retrieve all specified rows in the given column of the table.
+
+ :param column: column name
+ :param rows: a list of row indices or ``'all'`` or ``'selected'``
+ """
+ ifrowsisNone:
+ rows=self._rows
+ returnself._libmadx.get_table_column(self._name,column.lower(),rows)
+
+
+
+[docs]
+ defrow(self,index,columns=None):
+"""Retrieve one row from the table."""
+ ifcolumnsisNone:
+ columns=self._columns
+ returnAttrDict(self._libmadx.get_table_row(self._name,index,columns))
+
+
+
+[docs]
+ defcopy(self,columns=None,rows=None)->dict:
+"""
+ Return a frozen table with the desired columns.
+
+ :param list columns: column names or ``None`` for all columns.
+ :returns: column data
+ :raises ValueError: if the table name is invalid
+ """
+ ifrowsisNone:
+ rows=columnsifisinstance(columns,str)elseself._rows
+ ifrows==self._rows:
+ table=self
+ else:
+ table=self.select(rows=rows)
+ return{column:table[column]forcolumninself.col_names(columns)}
+
+
+
+[docs]
+ defdframe(self,columns=None,rows=None,*,index=None):
+"""
+ Return table as ``pandas.DataFrame``.
+
+ :param columns: column names or 'all' or 'selected'
+ :param rows: row indices or 'all' or 'selected'
+ :param str index: column name or sequence to be used as index, or
+ ``None`` for using the ``row_names``
+ :returns: column data as ``pandas.DataFrame``
+ :raises ValueError: if the table name is invalid
+
+ WARNING: using ``index=None`` is unsafe after calling ``USE``.
+ In this case, please manually specify another column to be used,
+ e.g. ``index="name"``.
+ """
+ importpandasaspd
+ ifindexisNone:
+ index=self.row_names(rows)
+ elifisinstance(index,str):
+ index=util.remove_count_suffix_from_name(self[index])
+ else:
+ index=index
+ returnpd.DataFrame(self.copy(columns,rows),index=index)
+[docs]
+classVarParamList(_Mapping):
+
+"""Mapping of global MAD-X variables."""
+
+ __slots__=('_madx','_libmadx')
+
+ def__init__(self,madx):
+ self._madx=madx
+ self._libmadx=madx._libmadx
+
+ def__getitem__(self,name):
+ returnself._libmadx.get_var(name.lower())
+
+ def__iter__(self):
+"""Iterate names of all non-constant globals."""
+ returniter(self._libmadx.get_globals())
+
+ def__len__(self):
+ returnself._libmadx.num_globals()
+
+
+
+
+[docs]
+classMetadata:
+
+"""MAD-X metadata (license info, etc)."""
+
+ __title__=u'MAD-X'
+
+ @property
+ def__version__(self):
+ returnself._get_libmadx().get_version_number()
+
+ __summary__=(
+ u'MAD is a project with a long history, aiming to be at the '
+ u'forefront of computational physics in the field of particle '
+ u'accelerator design and simulation. The MAD scripting language '
+ u'is de facto the standard to describe particle accelerators, '
+ u'simulate beam dynamics and optimize beam optics.'
+ )
+
+ __uri__=u'http://madx.web.cern.ch/madx/'
+
+ __credits__=(
+ u'MAD-X is developed at CERN and has many contributors. '
+ u'For more information see:\n'
+ u'\n'
+ u'http://madx.web.cern.ch/madx/www/contributors.html'
+ )
+
+
+
+
+ _libmadx=None
+
+ def_get_libmadx(self):
+ ifnotself._libmadx:
+ # Need to disable stdin to avoid deadlock that occurs if starting
+ # with closed or invalid stdin:
+ svc,proc=_rpc.LibMadxClient.spawn_subprocess(stdin=False)
+ self._libmadx=svc.libmadx
+ returnself._libmadx
+
+
+
+metadata=Metadata()
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/_modules/cpymad/types.html b/_modules/cpymad/types.html
new file mode 100644
index 00000000..8e2d77b8
--- /dev/null
+++ b/_modules/cpymad/types.html
@@ -0,0 +1,226 @@
+
+
+
+
+
+
+
+ cpymad.types — cpymad 1.17.0 documentation
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ @property
+ defdefinition(self):
+"""Return command argument as should be used for MAD-X input to
+ create an identical element."""
+ ifisinstance(self.value,list):
+ return[eorvforv,einzip(self.value,self.expr)]
+ else:
+ returnself.exprorself.value
+
+ def__str__(self):
+ returnstr(self.definition)
+
+
+
+
+[docs]
+classConstraint:
+
+"""Represents a MAD-X constraint, which has either min/max/both/value."""
+
+ def__init__(self,val=None,min=None,max=None):
+"""Just store the values"""
+ self.val=val
+ self.min=min
+ self.max=max
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/_modules/cpymad/util.html b/_modules/cpymad/util.html
new file mode 100644
index 00000000..16adf28f
--- /dev/null
+++ b/_modules/cpymad/util.html
@@ -0,0 +1,671 @@
+
+
+
+
+
+
+
+ cpymad.util — cpymad 1.17.0 documentation
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+"""
+Utility functions used in other parts of the pymad package.
+"""
+importre
+importos
+importsys
+importtempfile
+fromcollectionsimportnamedtuple
+fromcontextlibimportcontextmanager
+fromenumimportEnum
+fromnumbersimportNumber
+importcollections.abcasabc
+
+importnumpyasnp
+
+fromcpymad.parsingimportParser
+fromcpymad.typesimport(
+ Range,Constraint,
+ PARAM_TYPE_LOGICAL,PARAM_TYPE_INTEGER,
+ PARAM_TYPE_DOUBLE,PARAM_TYPE_STRING,PARAM_TYPE_CONSTRAINT,
+ PARAM_TYPE_LOGICAL_ARRAY,PARAM_TYPE_INTEGER_ARRAY,
+ PARAM_TYPE_DOUBLE_ARRAY,PARAM_TYPE_STRING_ARRAY)
+
+
+__all__=[
+ 'mad_quote',
+ 'is_identifier',
+ 'name_from_internal',
+ 'name_to_internal',
+ 'format_param',
+ 'format_cmdpar',
+ 'format_command',
+ 'check_expression',
+ 'temp_filename',
+ 'ChangeDirectory',
+]
+
+
+# In CPython 3.6 dicts preserve insertion order (until deleting an element)
+# Although, this is considered an implementation detail that should not be
+# relied upon, we do so anyway:
+ordered_keys=dict.keysifsys.version_info>=(3,6)elsesorted
+
+
+
+[docs]
+defmad_quote(value:str)->str:
+"""Add quotes to a string value."""
+ if'"'notinvalue:
+ return'"'+value+'"'
+ if"'"notinvalue:
+ return"'"+value+"'"
+ # MAD-X doesn't do any unescaping (otherwise I'd simply use `json.dumps`):
+ raiseValueError("MAD-X unable to parse string with escaped quotes: {!r}"
+ .format(value))
+[docs]
+defis_identifier(name:str)->bool:
+"""Check if ``name`` is a valid identifier in MAD-X."""
+ returnbool(_re_is_identifier.match(name))
+
+
+
+defexpr_symbols(expr:str)->set:
+"""
+ Return all symbols names used in an expression.
+
+ For now this includes not only variables but also element attributes (e.g.
+ ``quad->k1``) as well as function names (e.g. ``sin``).
+ """
+ return{m[0]formin_re_symbol.findall(expr)}
+
+
+
+[docs]
+defname_from_internal(element_name:str)->str:
+"""
+ Convert element name from internal representation to user API. Example:
+
+ >>> name_from_internal("foo:1")
+ foo
+ >>> name_from_internal("foo:2")
+ foo[2]
+
+ Element names are stored with a ":d" suffix by MAD-X internally (data in
+ node/sequence structs), but users must use the syntax "elem[d]" to access
+ the corresponding elements. This function is used to transform any string
+ coming from the user before passing it to MAD-X.
+ """
+ try:
+ name,count=_re_element_internal.match(element_name).groups()
+ exceptAttributeError:
+ raiseValueError("Not a valid MAD-X element name: {!r}"
+ .format(element_name))fromNone
+ ifcountisNoneorcount==':1':
+ returnname
+ returnname+'['+count[1:]+']'
+
+
+
+def_parse_element_name(element_name:str)->tuple:
+"""
+ Parse element name from user API. Example:
+
+ >>> _parse_element_name("foo")
+ (foo, None)
+ >>> _parse_element_name("foo[2]")
+ (foo, 2)
+
+ See :func:`name_from_internal' for further information.
+ """
+ try:
+ name,count=_re_element_external.match(element_name).groups()
+ exceptAttributeError:
+ raiseValueError("Not a valid MAD-X element name: {!r}"
+ .format(element_name))fromNone
+ ifcountisNone:
+ returnname,None
+ returnname,int(count[1:-1])
+
+
+
+[docs]
+defname_to_internal(element_name:str)->str:
+"""
+ Convert element name from user API to internal representation. Example:
+
+ >>> name_to_external("foo")
+ foo:1
+ >>> name_to_external("foo[2]")
+ foo:2
+
+ See :func:`name_from_internal` for further information.
+ """
+ name,count=_parse_element_name(element_name)
+ returnname+':'+str(1ifcountisNoneelsecount)
+
+
+
+defnormalize_range_name(name:str,elems=None)->str:
+"""Make element name usable as argument to the RANGE attribute."""
+ ifisinstance(name,tuple):
+ returntuple(map(normalize_range_name,name))
+ if'/'inname:
+ return'/'.join(map(normalize_range_name,name.split('/')))
+ name=name.lower()
+ ifname.endswith('$end')orname.endswith('$start'):
+ ifelemsisNone:
+ returnu'#s'ifname.endswith('$start')elseu'#e'
+ else:
+ returnu'#s'ifelems.index(name)==0elseu'#e'
+ returnname
+
+
+QUOTED_PARAMS={'file','halofile','sectorfile','trueprofile'
+ 'pipefile','trackfile','summary_file','filename',
+ 'echo','title','text','format','dir'}
+
+
+
+[docs]
+defformat_param(key:str,value)->str:
+"""
+ Format a single MAD-X command parameter.
+
+ This is the old version that does not use type information from MAD-X. It
+ is therefore not limited to existing MAD-X commands and attributes, but
+ also less reliable for producing valid MAD-X statements.
+ """
+ ifvalueisNone:
+ returnNone
+ key=_fix_name(str(key).lower())
+ ifisinstance(value,Constraint):
+ constr=[]
+ ifvalue.minisnotNone:
+ constr.append(key+'>'+str(value.min))
+ ifvalue.maxisnotNone:
+ constr.append(key+'<'+str(value.max))
+ ifconstr:
+ returnu', '.join(constr)
+ else:
+ returnkey+'='+str(value.val)
+ elifisinstance(value,bool):
+ returnkey+'='+str(value).lower()
+ elifkey=='range'orisinstance(value,Range):
+ returnkey+'='+_format_range(value)
+ # check for basestrings before abc.Sequence, because every
+ # string is also a Sequence:
+ elifisinstance(value,str):
+ ifkeyinQUOTED_PARAMS:
+ returnkey+'='+mad_quote(value)
+ else:
+ # MAD-X parses strings incorrectly, if followed by a boolean.
+ # E.g.: "beam, sequence=s1, -radiate;" does NOT work! Therefore,
+ # these values need to be quoted. (NOTE: MAD-X uses lower-case
+ # internally and the quotes prevent automatic case conversion)
+ returnkey+'='+mad_quote(value.lower())
+ # don't quote expressions:
+ elifisinstance(value,str):
+ returnkey+':='+value
+ elifisinstance(value,abc.Sequence):
+ returnkey+'={'+','.join(map(str,value))+'}'
+ else:
+ returnkey+'='+str(value)
+[docs]
+defformat_cmdpar(cmd,key:str,value)->str:
+"""
+ Format a single MAD-X command parameter.
+
+ :param cmd: A MAD-X Command instance for which an argument is to be formatted
+ :param key: name of the parameter
+ :param value: argument value
+ """
+ key=_fix_name(str(key).lower())
+ cmdpar=cmd.cmdpar[key]
+ dtype=cmdpar.dtype
+ # the empty string was used in earlier versions in place of None:
+ ifvalueisNoneorvalue=='':
+ returnu''
+
+ # NUMERIC
+ ifdtype==PARAM_TYPE_LOGICAL:
+ ifisinstance(value,bool):returnkey+'='+str(value).lower()
+ ifdtypein(PARAM_TYPE_LOGICAL,
+ PARAM_TYPE_INTEGER,
+ PARAM_TYPE_DOUBLE,
+ PARAM_TYPE_CONSTRAINT,
+ # NOTE: allow passing scalar values to numeric arrays, mainly
+ # useful because many of the `match` command parameters are
+ # arrays, but we usually call it with a single sequence and
+ # would like to treat it similar to the `twiss` command:
+ PARAM_TYPE_LOGICAL_ARRAY,
+ PARAM_TYPE_INTEGER_ARRAY,
+ PARAM_TYPE_DOUBLE_ARRAY):
+ ifisinstance(value,bool):returnkey+'='+str(int(value))
+ ifisinstance(value,Number):returnkey+'='+str(value)
+ ifisinstance(value,str):returnkey+':='+value
+ ifdtype==PARAM_TYPE_CONSTRAINT:
+ ifisinstance(value,Constraint):
+ constr=[]
+ ifvalue.minisnotNone:
+ constr.append(key+'>'+str(value.min))
+ ifvalue.maxisnotNone:
+ constr.append(key+'<'+str(value.max))
+ ifconstr:
+ returnu', '.join(constr)
+ else:
+ returnkey+'='+str(value.val)
+ ifdtypein(PARAM_TYPE_LOGICAL_ARRAY,
+ PARAM_TYPE_INTEGER_ARRAY,
+ PARAM_TYPE_DOUBLE_ARRAY):
+ ifisinstance(value,abc.Sequence):
+ ifall(isinstance(v,Number)forvinvalue):
+ returnkey+'={'+','.join(map(str,value))+'}'
+ else:
+ returnkey+':={'+','.join(map(str,value))+'}'
+
+ # STRING
+ defformat_str(value):
+ ifkeyinQUOTED_PARAMS:
+ returnmad_quote(value)
+ # NOTE: MAD-X stops parsing the current argument as soon as it
+ # encounters another parameter name of the current command:
+ elifis_identifier(value)andvaluenotincmd:
+ returnvalue
+ else:
+ returnmad_quote(value.lower())
+ ifdtype==PARAM_TYPE_STRING:
+ ifkey=='range'orisinstance(value,Range):
+ returnkey+'='+_format_range(value)
+ ifisinstance(value,str):
+ returnkey+'='+format_str(value)
+ ifdtype==PARAM_TYPE_STRING_ARRAY:
+ # NOTE: allowing single scalar value to STRING_ARRAY, mainly useful
+ # for `match`, see above.
+ ifkey=='range'orisinstance(value,Range):
+ ifisinstance(value,list):
+ returnkey+'={'+','.join(map(_format_range,value))+'}'
+ returnkey+'='+_format_range(value)
+ ifisinstance(value,str):
+ returnkey+'='+format_str(value)
+ ifisinstance(value,abc.Sequence):
+ returnkey+'={'+','.join(map(format_str,value))+'}'
+
+ raiseTypeError('Unexpected command argument type: {}={!r} ({})'
+ .format(key,value,type(value)))
+
+
+
+
+[docs]
+defformat_command(*args,**kwargs)->str:
+"""
+ Create a MAD-X command from its name and parameter list.
+
+ :param cmd: base command (serves as template for parameter types)
+ :param args: initial bareword command arguments (including command name!)
+ :param kwargs: following named command arguments
+ :returns: command string
+
+ Examples:
+
+ >>> format_command('twiss', sequence='lhc')
+ 'twiss, sequence=lhc;'
+
+ >>> format_command('option', echo=True)
+ 'option, echo;'
+
+ >>> format_command('constraint', betx=Constraint(max=3.13))
+ 'constraint, betx<3.13;'
+ """
+ cmd,args=args[0],args[1:]
+ ifisinstance(cmd,str):
+ _args=[cmd]+list(args)
+ _keys=ordered_keys(kwargs)
+ _args+=[format_param(k,kwargs[k])forkin_keys]
+ else:
+ _args=[cmd.name]+list(args)
+ _keys=ordered_keys(kwargs)
+ _args+=[format_cmdpar(cmd,k,kwargs[k])forkin_keys]
+ returnu', '.join(filter(None,_args))+';'
+[docs]
+defcheck_expression(expr:str):
+"""
+ Check if the given expression is a valid MAD-X expression that is safe to
+ pass to :meth:`cpymad.madx.Madx.eval`.
+
+ :param expr:
+ :returns: True
+ :raises ValueError: if the expression is ill-formed
+
+ Note that this function only recognizes a sane subset of the expressions
+ accepted by MAD-X and rejects valid but strange ones such as a number
+ formatting '.' representing zero.
+ """
+ expr=expr.strip().lower()
+ tokens=list(tokenize(list(_expr_tokens.items()),expr))
+ tokens.append(Token(T.END,len(expr),0,expr))
+ _expr_parser.parse(tokens)# raises ValueError
+ returnTrue
+
+
+
+# misc
+
+
+[docs]
+@contextmanager
+deftemp_filename():
+"""Get filename for use within 'with' block and delete file afterwards."""
+ fd,filename=tempfile.mkstemp()
+ os.close(fd)
+ try:
+ yieldfilename
+ finally:
+ try:
+ os.remove(filename)
+ exceptOSError:
+ pass
+
+
+
+
+[docs]
+classChangeDirectory:
+
+"""
+ Context manager for temporarily changing current working directory.
+
+ :param str path: new path name
+ :param _os: module with ``getcwd`` and ``chdir`` functions
+ """
+
+ # Note that the code is generic enough to be applied for any temporary
+ # value patch, but we currently only need change directory, and therefore
+ # have named it so.
+
+ def__init__(self,path,chdir,getcwd):
+ self._chdir=chdir
+ self._getcwd=getcwd
+ # Contrary to common implementations of a similar context manager,
+ # we change the path immediately in the constructor. That enables
+ # this utility to be used without any 'with' statement:
+ ifpath:
+ self._restore=getcwd()
+ chdir(path)
+ else:
+ self._restore=None
+
+ def__enter__(self):
+"""Enter 'with' context."""
+ returnself
+
+ def__exit__(self,exc_type,exc_val,exc_tb):
+"""Exit 'with' context and restore old path."""
+ ifself._restore:
+ self._chdir(self._restore)
+
+
+
+@np.vectorize
+defremove_count_suffix_from_name(name):
+"""Return the :N suffix from an element name."""
+ returnname.rsplit(':',1)[0]
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/_modules/index.html b/_modules/index.html
new file mode 100644
index 00000000..b5bbac7f
--- /dev/null
+++ b/_modules/index.html
@@ -0,0 +1,106 @@
+
+
+
+
+
+
+
+ Overview: module code — cpymad 1.17.0 documentation
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
NOTE: This function does not perform rigorous input validation! It uses
+nothing but the MAD-X builtin rather incompetent error checks. This means
+invalid input such as ‘+’ can lead to program crashes! If you’re looking
+for more secure validation, see cpymad.util.check_expression().
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/automod/cpymad.libmadx.finish.html b/automod/cpymad.libmadx.finish.html
new file mode 100644
index 00000000..f087c588
--- /dev/null
+++ b/automod/cpymad.libmadx.finish.html
@@ -0,0 +1,192 @@
+
+
+
+
+
+
+
+
+ finish — cpymad 1.17.0 documentation
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
CAUTION: Numeric data is wrapped in numpy arrays but not copied. Make
+sure to copy all data before invoking any further MAD-X commands! This
+is done automatically for you if using libmadx in a remote service
+(pickle serialization effectively copies the data).
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/automod/cpymad.libmadx.get_table_column_count.html b/automod/cpymad.libmadx.get_table_column_count.html
new file mode 100644
index 00000000..86e1866f
--- /dev/null
+++ b/automod/cpymad.libmadx.get_table_column_count.html
@@ -0,0 +1,204 @@
+
+
+
+
+
+
+
+
+ get_table_column_count — cpymad 1.17.0 documentation
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v
If E present and has a .keys() method, does: for k in E: D[k] = E[k]
+If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v
+In either case, this is followed by: for k, v in F.items(): D[k] = v
If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v
If E present and has a .keys() method, does: for k in E: D[k] = E[k]
+If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v
+In either case, this is followed by: for k, v in F.items(): D[k] = v
Communicates with a MAD-X interpreter in a background process.
+
The state of the MAD-X interpreter is controlled by feeding textual MAD-X
+commands to the interpreter.
+
The state of the MAD-X interpreter is accessed by directly reading the
+values from the C variables in-memory and sending the results pickled back
+over the pipe.
Collect input and send in a single batch when leaving context. This is
+useful to improve performance when issueing many related commands in
+quick succession.
If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v
If E present and has a .keys() method, does: for k in E: D[k] = E[k]
+If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v
+In either case, this is followed by: for k, v in F.items(): D[k] = v
Convert a number or string to an integer, or return 0 if no arguments
+are given. If x is a number, return x.__int__(). For floating point
+numbers, this truncates towards zero.
+
If x is not a number or if base is given, then x must be a string,
+bytes, or bytearray instance representing an integer literal in the
+given base. The literal can be preceded by ‘+’ or ‘-’ and be surrounded
+by whitespace. The base defaults to 10. Valid bases are 0 and 2-36.
+Base 0 means to interpret the base from the string as an integer literal.
+>>> int(‘0b100’, base=0)
+4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/automod/cpymad.types.PARAM_TYPE_DOUBLE.html b/automod/cpymad.types.PARAM_TYPE_DOUBLE.html
new file mode 100644
index 00000000..a8847a0b
--- /dev/null
+++ b/automod/cpymad.types.PARAM_TYPE_DOUBLE.html
@@ -0,0 +1,156 @@
+
+
+
+
+
+
+
+
+ PARAM_TYPE_DOUBLE — cpymad 1.17.0 documentation
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Convert a number or string to an integer, or return 0 if no arguments
+are given. If x is a number, return x.__int__(). For floating point
+numbers, this truncates towards zero.
+
If x is not a number or if base is given, then x must be a string,
+bytes, or bytearray instance representing an integer literal in the
+given base. The literal can be preceded by ‘+’ or ‘-’ and be surrounded
+by whitespace. The base defaults to 10. Valid bases are 0 and 2-36.
+Base 0 means to interpret the base from the string as an integer literal.
+>>> int(‘0b100’, base=0)
+4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/automod/cpymad.types.PARAM_TYPE_DOUBLE_ARRAY.html b/automod/cpymad.types.PARAM_TYPE_DOUBLE_ARRAY.html
new file mode 100644
index 00000000..ded86cda
--- /dev/null
+++ b/automod/cpymad.types.PARAM_TYPE_DOUBLE_ARRAY.html
@@ -0,0 +1,156 @@
+
+
+
+
+
+
+
+
+ PARAM_TYPE_DOUBLE_ARRAY — cpymad 1.17.0 documentation
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Convert a number or string to an integer, or return 0 if no arguments
+are given. If x is a number, return x.__int__(). For floating point
+numbers, this truncates towards zero.
+
If x is not a number or if base is given, then x must be a string,
+bytes, or bytearray instance representing an integer literal in the
+given base. The literal can be preceded by ‘+’ or ‘-’ and be surrounded
+by whitespace. The base defaults to 10. Valid bases are 0 and 2-36.
+Base 0 means to interpret the base from the string as an integer literal.
+>>> int(‘0b100’, base=0)
+4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/automod/cpymad.types.PARAM_TYPE_INTEGER.html b/automod/cpymad.types.PARAM_TYPE_INTEGER.html
new file mode 100644
index 00000000..10aded42
--- /dev/null
+++ b/automod/cpymad.types.PARAM_TYPE_INTEGER.html
@@ -0,0 +1,156 @@
+
+
+
+
+
+
+
+
+ PARAM_TYPE_INTEGER — cpymad 1.17.0 documentation
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Convert a number or string to an integer, or return 0 if no arguments
+are given. If x is a number, return x.__int__(). For floating point
+numbers, this truncates towards zero.
+
If x is not a number or if base is given, then x must be a string,
+bytes, or bytearray instance representing an integer literal in the
+given base. The literal can be preceded by ‘+’ or ‘-’ and be surrounded
+by whitespace. The base defaults to 10. Valid bases are 0 and 2-36.
+Base 0 means to interpret the base from the string as an integer literal.
+>>> int(‘0b100’, base=0)
+4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/automod/cpymad.types.PARAM_TYPE_INTEGER_ARRAY.html b/automod/cpymad.types.PARAM_TYPE_INTEGER_ARRAY.html
new file mode 100644
index 00000000..e33b842f
--- /dev/null
+++ b/automod/cpymad.types.PARAM_TYPE_INTEGER_ARRAY.html
@@ -0,0 +1,156 @@
+
+
+
+
+
+
+
+
+ PARAM_TYPE_INTEGER_ARRAY — cpymad 1.17.0 documentation
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Convert a number or string to an integer, or return 0 if no arguments
+are given. If x is a number, return x.__int__(). For floating point
+numbers, this truncates towards zero.
+
If x is not a number or if base is given, then x must be a string,
+bytes, or bytearray instance representing an integer literal in the
+given base. The literal can be preceded by ‘+’ or ‘-’ and be surrounded
+by whitespace. The base defaults to 10. Valid bases are 0 and 2-36.
+Base 0 means to interpret the base from the string as an integer literal.
+>>> int(‘0b100’, base=0)
+4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/automod/cpymad.types.PARAM_TYPE_LOGICAL.html b/automod/cpymad.types.PARAM_TYPE_LOGICAL.html
new file mode 100644
index 00000000..a6ed725b
--- /dev/null
+++ b/automod/cpymad.types.PARAM_TYPE_LOGICAL.html
@@ -0,0 +1,156 @@
+
+
+
+
+
+
+
+
+ PARAM_TYPE_LOGICAL — cpymad 1.17.0 documentation
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Convert a number or string to an integer, or return 0 if no arguments
+are given. If x is a number, return x.__int__(). For floating point
+numbers, this truncates towards zero.
+
If x is not a number or if base is given, then x must be a string,
+bytes, or bytearray instance representing an integer literal in the
+given base. The literal can be preceded by ‘+’ or ‘-’ and be surrounded
+by whitespace. The base defaults to 10. Valid bases are 0 and 2-36.
+Base 0 means to interpret the base from the string as an integer literal.
+>>> int(‘0b100’, base=0)
+4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/automod/cpymad.types.PARAM_TYPE_LOGICAL_ARRAY.html b/automod/cpymad.types.PARAM_TYPE_LOGICAL_ARRAY.html
new file mode 100644
index 00000000..7231beec
--- /dev/null
+++ b/automod/cpymad.types.PARAM_TYPE_LOGICAL_ARRAY.html
@@ -0,0 +1,156 @@
+
+
+
+
+
+
+
+
+ PARAM_TYPE_LOGICAL_ARRAY — cpymad 1.17.0 documentation
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Convert a number or string to an integer, or return 0 if no arguments
+are given. If x is a number, return x.__int__(). For floating point
+numbers, this truncates towards zero.
+
If x is not a number or if base is given, then x must be a string,
+bytes, or bytearray instance representing an integer literal in the
+given base. The literal can be preceded by ‘+’ or ‘-’ and be surrounded
+by whitespace. The base defaults to 10. Valid bases are 0 and 2-36.
+Base 0 means to interpret the base from the string as an integer literal.
+>>> int(‘0b100’, base=0)
+4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/automod/cpymad.types.PARAM_TYPE_STRING.html b/automod/cpymad.types.PARAM_TYPE_STRING.html
new file mode 100644
index 00000000..cc744c69
--- /dev/null
+++ b/automod/cpymad.types.PARAM_TYPE_STRING.html
@@ -0,0 +1,156 @@
+
+
+
+
+
+
+
+
+ PARAM_TYPE_STRING — cpymad 1.17.0 documentation
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Convert a number or string to an integer, or return 0 if no arguments
+are given. If x is a number, return x.__int__(). For floating point
+numbers, this truncates towards zero.
+
If x is not a number or if base is given, then x must be a string,
+bytes, or bytearray instance representing an integer literal in the
+given base. The literal can be preceded by ‘+’ or ‘-’ and be surrounded
+by whitespace. The base defaults to 10. Valid bases are 0 and 2-36.
+Base 0 means to interpret the base from the string as an integer literal.
+>>> int(‘0b100’, base=0)
+4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/automod/cpymad.types.PARAM_TYPE_STRING_ARRAY.html b/automod/cpymad.types.PARAM_TYPE_STRING_ARRAY.html
new file mode 100644
index 00000000..4ea5d9c6
--- /dev/null
+++ b/automod/cpymad.types.PARAM_TYPE_STRING_ARRAY.html
@@ -0,0 +1,156 @@
+
+
+
+
+
+
+
+
+ PARAM_TYPE_STRING_ARRAY — cpymad 1.17.0 documentation
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Convert a number or string to an integer, or return 0 if no arguments
+are given. If x is a number, return x.__int__(). For floating point
+numbers, this truncates towards zero.
+
If x is not a number or if base is given, then x must be a string,
+bytes, or bytearray instance representing an integer literal in the
+given base. The literal can be preceded by ‘+’ or ‘-’ and be surrounded
+by whitespace. The base defaults to 10. Valid bases are 0 and 2-36.
+Base 0 means to interpret the base from the string as an integer literal.
+>>> int(‘0b100’, base=0)
+4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/automod/cpymad.types.Parameter.html b/automod/cpymad.types.Parameter.html
new file mode 100644
index 00000000..85d35eac
--- /dev/null
+++ b/automod/cpymad.types.Parameter.html
@@ -0,0 +1,217 @@
+
+
+
+
+
+
+
+
+ Parameter — cpymad 1.17.0 documentation
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Convert a number or string to an integer, or return 0 if no arguments
+are given. If x is a number, return x.__int__(). For floating point
+numbers, this truncates towards zero.
+
If x is not a number or if base is given, then x must be a string,
+bytes, or bytearray instance representing an integer literal in the
+given base. The literal can be preceded by ‘+’ or ‘-’ and be surrounded
+by whitespace. The base defaults to 10. Valid bases are 0 and 2-36.
+Base 0 means to interpret the base from the string as an integer literal.
+>>> int(‘0b100’, base=0)
+4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/automod/cpymad.types.VAR_TYPE_DEFERRED.html b/automod/cpymad.types.VAR_TYPE_DEFERRED.html
new file mode 100644
index 00000000..cd73bac1
--- /dev/null
+++ b/automod/cpymad.types.VAR_TYPE_DEFERRED.html
@@ -0,0 +1,156 @@
+
+
+
+
+
+
+
+
+ VAR_TYPE_DEFERRED — cpymad 1.17.0 documentation
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Convert a number or string to an integer, or return 0 if no arguments
+are given. If x is a number, return x.__int__(). For floating point
+numbers, this truncates towards zero.
+
If x is not a number or if base is given, then x must be a string,
+bytes, or bytearray instance representing an integer literal in the
+given base. The literal can be preceded by ‘+’ or ‘-’ and be surrounded
+by whitespace. The base defaults to 10. Valid bases are 0 and 2-36.
+Base 0 means to interpret the base from the string as an integer literal.
+>>> int(‘0b100’, base=0)
+4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/automod/cpymad.types.VAR_TYPE_DIRECT.html b/automod/cpymad.types.VAR_TYPE_DIRECT.html
new file mode 100644
index 00000000..04af9ae4
--- /dev/null
+++ b/automod/cpymad.types.VAR_TYPE_DIRECT.html
@@ -0,0 +1,156 @@
+
+
+
+
+
+
+
+
+ VAR_TYPE_DIRECT — cpymad 1.17.0 documentation
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Convert a number or string to an integer, or return 0 if no arguments
+are given. If x is a number, return x.__int__(). For floating point
+numbers, this truncates towards zero.
+
If x is not a number or if base is given, then x must be a string,
+bytes, or bytearray instance representing an integer literal in the
+given base. The literal can be preceded by ‘+’ or ‘-’ and be surrounded
+by whitespace. The base defaults to 10. Valid bases are 0 and 2-36.
+Base 0 means to interpret the base from the string as an integer literal.
+>>> int(‘0b100’, base=0)
+4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/automod/cpymad.types.VAR_TYPE_STRING.html b/automod/cpymad.types.VAR_TYPE_STRING.html
new file mode 100644
index 00000000..39cf5c52
--- /dev/null
+++ b/automod/cpymad.types.VAR_TYPE_STRING.html
@@ -0,0 +1,156 @@
+
+
+
+
+
+
+
+
+ VAR_TYPE_STRING — cpymad 1.17.0 documentation
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Convert a number or string to an integer, or return 0 if no arguments
+are given. If x is a number, return x.__int__(). For floating point
+numbers, this truncates towards zero.
+
If x is not a number or if base is given, then x must be a string,
+bytes, or bytearray instance representing an integer literal in the
+given base. The literal can be preceded by ‘+’ or ‘-’ and be surrounded
+by whitespace. The base defaults to 10. Valid bases are 0 and 2-36.
+Base 0 means to interpret the base from the string as an integer literal.
+>>> int(‘0b100’, base=0)
+4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/automod/cpymad.util.ChangeDirectory.html b/automod/cpymad.util.ChangeDirectory.html
new file mode 100644
index 00000000..04060750
--- /dev/null
+++ b/automod/cpymad.util.ChangeDirectory.html
@@ -0,0 +1,142 @@
+
+
+
+
+
+
+
+
+ ChangeDirectory — cpymad 1.17.0 documentation
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Note that this function only recognizes a sane subset of the expressions
+accepted by MAD-X and rejects valid but strange ones such as a number
+formatting ‘.’ representing zero.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/automod/cpymad.util.format_cmdpar.html b/automod/cpymad.util.format_cmdpar.html
new file mode 100644
index 00000000..3058d1c0
--- /dev/null
+++ b/automod/cpymad.util.format_cmdpar.html
@@ -0,0 +1,153 @@
+
+
+
+
+
+
+
+
+ format_cmdpar — cpymad 1.17.0 documentation
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
This is the old version that does not use type information from MAD-X. It
+is therefore not limited to existing MAD-X commands and attributes, but
+also less reliable for producing valid MAD-X statements.
Element names are stored with a “:d” suffix by MAD-X internally (data in
+node/sequence structs), but users must use the syntax “elem[d]” to access
+the corresponding elements. This function is used to transform any string
+coming from the user before passing it to MAD-X.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/automod/cpymad.util.name_to_internal.html b/automod/cpymad.util.name_to_internal.html
new file mode 100644
index 00000000..fe41a3a9
--- /dev/null
+++ b/automod/cpymad.util.name_to_internal.html
@@ -0,0 +1,151 @@
+
+
+
+
+
+
+
+
+ name_to_internal — cpymad 1.17.0 documentation
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
The following sections contain instructions for building MAD-X and cpymad from
+source on various platforms. This can be an intricate procedure that is mostly
+performed by package maintainers or developers who want to change cpymad code.
+Ordinary users usually don’t need to do this and can use the prebuilt wheels
+if available (see Installation).
CAUTION: End users should usually not import this module directly! Use
+cpymad.madx.Madx instead.
+
+
The API of this module is considered private, i.e. it may change between
+versions without further notice.
+
Importing this module means loading MAD-X directly into the process space.
+This means that any crash in the (sometimes fragile) MAD-X interpreter will
+crash the importing process with it.
+
All functions in this module operate on a shared global state.
+
this module exposes a very C-ish API that is not convenient to work with.
The basic way to use cpymad is to create a Madx
+instance that can be used to control and access the state of a MAD-X process:
+
fromcpymad.madximportMadx
+madx=Madx()
+
+
+
This spawns a MAD-X process in the background and opens a communication
+channel to it.
+
Running MAD-X in a separate process is necessary to create multiple instances
+with independent interpreter state. This is useful for resetting MAD-X to a
+clean initial state by simply creating a new instance; and is a requirement
+for parallelization (because MAD-X is not thread safe).
Now that you started MAD-X, most MAD-X commands can be executed using the
+corresponding method on the Madx instance (except in the
+case where the name of the command conflicts with another property, in this
+case, see the command() property). For example:
In general, parameters must be passed by their name, exactly as for the MAD-X
+command. Flags should be passed as python bools, deferred expressions (:=)
+as strings, and direct expressions (=) as floats using
+eval().
+
Most of the command methods are auto-generated by introspecting the
+corresponding MAD-X command object. Only a few of the methods provide
+additional functionality over the raw MAD-X commands:
+
call() allows to temporarily change the directory to
+the one of the executed file by setting the optional chdir parameter to
+True:
+
# change directory to `/path/to/your/` during CALL:
+madx.call('/path/to/your/file.madx',chdir=True)
+
+
+
twiss() returns the resulting twiss table, which can
+be used conveniently for your own analysis, e.g.:
The Madx class works by feeding commands in the form of
+textual input to the MAD-X process. This means that you can execute all MAD-X
+commands, even if they are not explicitly defined on the python class level.
The method responsible for feeding textual input to MAD-X is
+input() method. It is called with a single string
+argument that will be forwarded as input to the MAD-X interpreter. For
+example:
+
madx.input('CALL, FILE="fodo.madx";')
+
+
+
Do not input anything but simple single line commands, no comments.
While it can be necessary to use input() for some
+constructs like macros or loops, most of the time your most favorable option
+is to use the command attribute. It provides syntactic
+sugar for composing regular MAD-X commands from python variables and feeding
+the generated command string to input():
If you need to override how command generates the
+command string (argument order/formatting), you can pass strings as positional
+arguments. For example:
chdir() changes the directory of the MAD-X process
+(not the current python process). If the return value can be used as a context
+manager, that reverts to the original directory upon leaving the context.
In contrast to how cpymad is controlling the MAD-X state, when accessing
+state it does not use MAD-X commands, but rather directly retrieves the data
+from the C variables in the MAD-X process memory!
+
This means that data retrieval is relatively fast because it does not:
+
+
parse command in the MAD-X interpreter
+
use a file on disk or the network
+
parse resulting data on python side
+
to potentially modify the MAD-X interpreter state by executing a command
+
+
Apart from this major advantage, another important implication is that the
+command_log file will not be cluttered by data-retrieval commands but only
+show actions.
# list of element names:
+print(list(madx.elements))
+
+# check whether an element is defined:
+print('qp1'inmadx.elements)
+
+# get element properties:
+elem=madx.elements.qp1
+print(elem.k1)
+print(elem.l)
+
+
+
Note that elements support dict-like item access to retrieve properties (i.e.
+elem['k1']) besides attribute access. The same is true in other places.
# list of existing table names
+print(list(madx.table)):
+
+# get table as dict-like object:
+twiss=madx.table.twiss
+
+# get columns as numpy arrays:
+alfx=twiss.alfx
+betx=twiss.alfy
+
+# get all twiss variables for 10th element:
+row=twiss[10]
+
+
+
By default a table provides access to all available rows and columns. In order
+to restrict to the selection from a previous SELECT command, you can use
+the the table.selection() method:
+
twiss=madx.table.twiss.selection()
+
+# only selected elements:
+twiss.betx
+
+# only selected columns:
+list(twiss)
+
# list of sequence names
+print(list(madx.sequence))
+
+# get a proxy object for the sequence
+fodo=madx.sequence.fodo
+
+beam=fodo.beam
+print(beam.ex,beam.ey)
+
+# ordered dict-like object of explicitly defined elements:
+elements=fodo.elements
+
+# OR: including implicit drifts:
+expanded=fodo.expanded_elements
+
For the purpose of debugging, reproducibility and transparency in general, it
+is important to be able to get a listing of the user input sent to
+MAD-X. This can be controlled using the command_log parameter. It accepts
+file names, arbitrary callables and file-like objects as follows:
The output of the MAD-X interpreter can be controlled using the redirect
+parameter of the Madx constructor. It allows to disable
+the output completely:
Note that cpymad links against a custom build of MAD-X that may differ from
+the official CERN command line client. This binary may have problems that the
+official binary does not have and vice versa. See also: Reporting issues.
If this fails, it usually means that we haven’t uploaded wheels for your
+platform or python version. In this case, either ping us about adding a
+corresponding wheel, or refer to Building from source.
+
In case of success, check your installation by typing the following:
+
python-c"import cpymad.libmadx as l; l.start()"
+
+
+
The MAD-X banner should appear.
+
+
Note
+
The MacOS wheels are experimental and require Apple’s Accelerate framework
+to be installed on the user machine. Please let us know if there are
+problems with these.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/installation/linux.html b/installation/linux.html
new file mode 100644
index 00000000..7ec39190
--- /dev/null
+++ b/installation/linux.html
@@ -0,0 +1,238 @@
+
+
+
+
+
+
+
+
+ Linux — cpymad 1.17.0 documentation
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
cpymad is linked against a library version of MAD-X, which means that in order
+to build cpymad you first have to compile MAD-X from source. The official
+madx executable is not sufficient. These steps are described in the
+following subsections:
+
+
If you’re planning to build cpymad inside a conda environment, we recommend
+to build MAD-X within that same environment to avoid linker errors. You will
+have to install gcc, g++, and gfortran inside conda before continuing, e.g.:
We will do an out-of-source build in a build/ subdirectory. This way, you
+can easily delete the build directory and restart if anything goes wrong.
+The basic process looks as follows:
Here we have specified a custom installation prefix to prevent cmake from
+installing MAD-X to a system directory (which would require root privileges,
+and may be harder to remove completely). You can also set a more permanent
+install location if you prefer (e.g. ~/.local or /opt/madx), but keep
+in mind that there is no uninstall command other than removing the files
+manually.
+
The cmake command has many more options, the most important ones being
+(only use if you now what you’re doing!):
+
+
-DMADX_STATIC=ON: Pass this flag to link statically against the
+dependencies of MAD-X (libc, libgfortran, libstdc++, blas, lapack, etc).
+This may be attempted in case of problems and is not guaranteed to work on
+all platforms (if your OS e.g. does not distribute libgfortran.a as is
+the case on archlinux). Note that even without this flag, cpymad will still
+be linked statically against MAD-X, just not against its dependencies.
+
-DBUILD_SHARED_LIBS=ON: Pass this flag if you want to link cpymad
+dynamically against MAD-X. In theory, this allows using, testing and even
+updating the MAD-X shared object independently of cpymad. If using this
+option, also change -DCMAKE_C_FLAGS="-fvisibility=protected" and be
+aware that you have to redistribute the MAD-X shared object along with
+cpymad, or install MAD-X to a permanent location where it can be found at
+runtime. Usually this means installing to the (default) system directories,
+but it can also be done by setting the LD_LIBRARY_PATH environment variable
+or passing appropriate --rpath to the setup script.
+
+
Save the path to the install directory in the MADXDIR environment variable.
+This variable will be used later by the setup.py script to locate the
+MAD-X headers and library, for example:
+
exportMADXDIR="$(pwd)"/../dist
+
+
+
Also, set the following variables according to the flags passed to the cmake
+command above (ONLY PASS IF NEEDED!):
+
setSTATIC=1# if -DMADX_STATIC=ON
+setSHARED=1# if -DBUILD_SHARED_LIBS=ON
+
cpymad is linked against a library version of MAD-X, which means that in order
+to build cpymad you first have to compile MAD-X from source. The official
+madx executable is not sufficient. These steps are described in the
+following subsections:
We will do an out-of-source build in a build/ subdirectory. This way, you
+can easily delete the build directory and restart if anything goes wrong.
+The basic process looks as follows:
Here we have specified a custom installation prefix to prevent cmake from
+installing MAD-X to a system directory (which would require root privileges,
+and may be harder to remove completely). You can also set a more permanent
+install location if you prefer, but keep in mind that there is no
+uninstall command other than removing the files manually.
+
The cmake command has many more options, but these are untested on Mac so far.
+
Save the path to the install directory in the MADXDIR environment variable.
+This variable will be used later by the setup.py script to locate the
+MAD-X headers and library, for example:
[ 96%] Linking CXX executable madx
+/usr/bin/ld: CMakeFiles/madxbin.dir/mad_main.c.o: in function `mad_init'
+mad_main.c:(.text+0x44): undefined reference to `madx_start'
+/usr/bin/ld: CMakeFiles/madxbin.dir/mad_main.c.o: in function `mad_run'
+mad_main.c:(.text+0x73): undefined reference to `madx_input'
+/usr/bin/ld: CMakeFiles/madxbin.dir/mad_main.c.o: in function `mad_fini'
+mad_main.c:(.text+0x81): undefined reference to `madx_finish'
+/usr/bin/ld: CMakeFiles/madxbin.dir/mad_main.c.o: in function `main'
+mad_main.c:(.text.startup+0xc): undefined reference to `madx_input'
+/usr/bin/ld: mad_main.c:(.text.startup+0x11): undefined reference to `madx_finish'
+/usr/bin/ld: mad_main.c:(.text.startup+0x16): undefined reference to `geterrorflag_'
+
+
+
It probably means that you attempted to build MAD-X as shared object
+-DBUILD_SHARED_LIBS=ON with -DCMAKE_C_FLAGS="-fvisibility=hidden".
+If that is the case, either build MAD-X with -DBUILD_SHARED_LIBS=OFF, or
+change hidden to protected, or leave out the visibility option entirely.
This usually means that we haven’t uploaded wheels for your platform or python
+version. In this case, either ping us about adding a corresponding wheel, or
+refer to the platform specific Installation Instructions.
This occurs because pip couldn’t find a prebuilt binary wheel that is
+compatible with your platform, and tried to build the source distribution
+instead. Please ping us about adding a wheel for your platform or refer to the
+Building from source guide.
The simplest fix that works without rebuilding MAD-X is to link cpymad
+against libmvec. This can be done by passing -lm to the python
+setup.pybuild_ext-lm command. You can also pass it through pip as
+follows pipinstall-e.--global-optionbuild_ext--global-option-lm.
+This fix is the recommended one when building for local use on your own
+machine.
+
Rebuild MAD-X without vectorization optimizations by passing
+-DCMAKE_C_FLAGS="-fno-tree-vectorize". Same for CMAKE_CXX_FLAGS, and
+CMAKE_Fortran_FLAGS.
+
Rebuild MAD-X in Debug mode (where these optimizations are disabled by
+default)
+
Rebuild MAD-X as shared object: -DBUILD_SHARED_LIBS=ON (also remove
+-fvisibility or change to protected), and run setup.py with
+exportSHARED=1.
This message is the result of linking cpymad’s libmadx extension module
+without a required dependency. In the specific case above, it means that MAD-X
+was built with BLAS/LAPACK, but cpymad was not linked against these libraries.
+The cpymad setup currently has no mechanism to detect with which libraries
+MAD-X was built and assumes by default only some standard libraries.
+
Possible solutions are either rebuilding MAD-X without BLAS/LAPACK, or passing
+appropriate libraries during the cpymad build step. The latter can be done by
+through environment variables:
+
exportBLAS=1
+exportLAPACK=1
+pipinstall.
+
+
+
Or by passing linker flags to the setup.pybuild_ext command manually:
This error can have multiple causes. It often means that cpymad is linked
+against one or more dynamic libraries that could not be found at runtime.
+Reasons may be that the MAD-X installation was moved or removed after building
+cpymad.
+
A possible solution is to use a permanent installation directory for MAD-X and
+specify this during the build:
Here, <madx-install-prefix> is the base folder containing the subfolders
+bin, include, lib of the MAD-X build and <rpath> contains the
+dynamic library files.
+
If this does not work, you can set the LD_LIBRARY_PATH (or
+DYLD_LIBRARY_PATH on OSX) environment variable before running pymad, for
+example:
cpymad is linked against a library version of MAD-X, which means that in order
+to build cpymad you first have to compile MAD-X from source. The official
+madx executable is not sufficient. These steps are described in the
+following subsections:
Setting up a functional build environment requires more effort on windows than
+on other platforms, and there are many pitfalls if not using the right
+compiler toolchain (such as linking against DLLs that are not present on most
+target systems).
+
We recommend that you install conda. It has proven to be a reliable tool
+for this job. Specifically, I recommend getting Miniconda; anaconda should
+work too, but I wouldn’t recommend it because it ships many unnecessary
+components.
+
Note that while conda is used to setup a consistent environment for the build
+process, the generated cpymad build will be usable with other python
+distributions as well.
+
Install build tools:
+
After installing conda, open the conda command prompt.
+
We show the commands for the case of working inside a cmd.exe terminal
+(batch). If you prefer to work with powershell or bash on msys2, the workflow
+(commands/arguments) will be mostly the same, with the only exception that you
+have to adapt the syntax accordingly in some places.
+
Now create a build environment with cmake and setup the MinGW compiler
+toolchain:
There are two major alternatives how to build MAD-X:
+
+
I recommend to build MAD-X as a static library as described below. This
+way, you won’t need to carry any .dll files around and you won’t run
+into version problems when having a multiple MAD-X library builds around.
+
However, in some cases it may be easier to link cpymad dynamically against
+MAD-X, i.e. using a DLL. This comes at the cost of having to redistribute
+the madx.dll along. The choice is yours.
+
+
Note that if you’re planning on using MSVC to build the cpymad extension later
+on, you have to build MAD-X as shared library (DLL). With MinGW (recommended),
+both build types are supported.
+
In the following, we show the commands for the static build.
For shared library builds, instead use -DBUILD_SHARED_LIBS=ON.
+
+
If all went well the last command will have installed binaries and library
+files to the MAD-X\dist subfolder.
+
Save the path to this install directory in the MADXDIR environment
+variable. This variable will be used later by the setup.py script to
+locate the MAD-X headers and library, for example:
+
set"MADXDIR=C:\Users\<....>\MAD-X\dist"
+
+
+
Also, set the following variables according to the flags passed to the cmake
+command above:
+
setSTATIC=1 # if -DMADX_STATIC=ON
+setSHARED=1 # if -DBUILD_SHARED_LIBS=ON
+
For building cpymad you can simply reuse the build environment with the MinGW
+installation from above, and now also install the targeted python version into
+the build environment, e.g.:
+
conda install python=3.7 wheel cython
+
+
+
+
Note
+
If you want to build wheels for multiple python versions, just create a
+build environment for each target version, and don’t forget to install the
+same version of the m2w64 compiler toolchain.
+
+
Now invoke the following command, which will cythonize the .pyx cython
+module to .c code as a side effect:
+
python setup.py build_py
+
+
+
Now comes the tricky part: we will have to manually build the C extension
+using gcc, because setuptools doesn’t know how to properly use our MinGW.
+
First set a few environment variables corresponding to the target platform
+and python version:
For old versions of MAD-X, leave out -lDISTlib from the second gcc call.
+
If this succeeds, you have most of the work behind you.
+
At this point, you may want to check the built .pyd file with Dependency
+Walker to verify that it depends only on system dependencies (except for
+pythonXY.dll, and in the case of dynamic linking madx.dll).
+
We now proceed to build a so called wheel. Wheels are zip archives containing
+all the files ready for installation, as well as some metadata such as version
+numbers etc. The wheel can be built as follows:
+
python setup.py bdist_wheel
+
+
+
The .whl file is named after the package and its target platform. This
+file can now be used for installation on this or any other machine running the
+same operating system and python version. Install as follows:
+
pip install dist\cpymad-*.whl
+
+
+
If you plan on changing cpymad code, do the following instead:
+
pip install -e .
+
+
+
Finally, do a quick check that your cpymad installation is working by typing
+the following:
+
python -c "import cpymad.libmadx as l; l.start()"
+
+
+
The MAD-X startup banner should appear. You can also run more tests as
+follows:
Python’s official binaries are all compiled with the Visual C compiler and
+therefore this is the only officially supported method to build python C
+extensions on windows.
+
It is possible to build the cpymad C extension with Visual Studio, but there
+is a good reason that the above guide doesn’t use it:
+
Visual Studio doesn’t include a Fortran compiler which means that you still
+have to build MAD-X as described. Also, you have to build MAD-X as a shared
+library, because the static library created by MinGW most likely won’t be
+compatible with the Visual C compiler.
+
First, look up the correct Visual Studio version and download and install
+it directly from microsoft. It is possible that older versions are not
+supported anymore.
+
After that, activate the Visual Studio tools by calling vcvarsall.bat.
+Depending on your Visual Studio version and install path, this might look like
+this:
+
call"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat"
+
+
+
Once you’ve accomplished that, the steps to build cpymad should actually be
+relatively simple (simpler than using MinGW in conda):
The MAD-X command output may sometimes appear delayed and in wrong order.
+This is a problem with mixing output from C and Fortran code. On linux it
+can be fixed by setting exportGFORTRAN_UNBUFFERED_PRECONNECTED=y in the
+environment. On windows, this can be tried as well, but is not reliable to
+our knowledge.
+
the MAD-X USE command invalidates table row names. Therefore, using
+Table.dframe() is unsafe after USE should be avoided, unless
+manually specifying an index, e.g. Table.dframe(index='name'), see #93.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/objects.inv b/objects.inv
new file mode 100644
index 00000000..50c4be3e
Binary files /dev/null and b/objects.inv differ
diff --git a/py-modindex.html b/py-modindex.html
new file mode 100644
index 00000000..9ba3ea0c
--- /dev/null
+++ b/py-modindex.html
@@ -0,0 +1,142 @@
+
+
+
+
+
+
+
+ Python Module Index — cpymad 1.17.0 documentation
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+