pymad / cpymad

cPyMAD is a python interface to Mad-X using cython and libmadx
http://cern.ch/pymad
Apache License 2.0
3 stars 3 forks source link

Matching #17

Closed coldfix closed 11 years ago

coldfix commented 11 years ago

Hey,

This pull request contains additional methods cern.madx.match() and cern.cpymad.model.match() and some utility methods in cern.libmadx._madx_tools.

For now, the interface is quite liberal when it comes to data types of input parameters: You can either use lists/tuples/dicts in quite a few places. I am not sure whether this is good or should enforce a little more uniformity/consistency. If you have any concerns, I can make it a more restrictive.

PS: Sorry for being inactive for so long.

Eothred commented 11 years ago

I tried to test the model matching, but I think the "dictionary parsing" is not correct:

from cern import cpymad l=cpymad.model('lhc',histfile="test.madx") ... l.match([{'betx':3, 'range':'#e'}, [('bety','<',3)]], ['K1', {'name':'K2', 'step':1e-6}]) +=+=+= fatal: illegal keyword: name

Looking at the history file, the problem is that the match command has name attribute: match, sequence=lhcb1, chrom, name=default-twiss;

This should perhaps be sequence= instead?

A suggestion: I think in the model we should perhaps also add an automated call to twiss() if it is not done?

coldfix commented 11 years ago

Sorry, there was a bug since I didn't expect cpymad.model._get_twiss_initial() to return anything not suitable for the MATCH directive. The doctests now run.

However, your test still fails: The command is generated as expected, but no matching is performed. Are 'K1', 'K2' valid match variables for 'lhc'?

START MATCHING
[stack trace]
IOError: [Errno 2] No such file or directory: 'match.temp.tfs'
Eothred commented 11 years ago

No, I don't think k1 and k2 are valid variables for this sequence, but it should still be able to match I figured (and do nothing).