if len(diff)>0: # print "name value1 value2 diff" for v,k in diff: if v> prdiff: print "%-20s %10.3e %10.3e %10.3e"%(k,t1[k],t2[k],v) else: break return ratio,diff if __name__=='__main__': import sys from pyoptics import madlang fn1=sys.argv[1] fn2=sys.argv[2] prratio=1.00001; prdiff=1e-12; if len(sys.argv)>3: prratio=float(sys.argv[3]) if len(sys.argv)>4: prdiff=float(sys.argv[4]) t1=madlang.open(fn1) t2=madlang.open(fn2) compare_optics(t1,t2,prratio,prdiff)
import os from pyoptics import madlang, MadBeam import sixtracklib def newer(f1, f2): if os.path.exists(f2): return os.path.getmtime(f1) > os.path.getmtime(f2) else: return True mad = madlang.open('bench.madx') line, rest = mad.bench.expand_struct() if len(rest) > 0: print(rest) if newer('bench.madx', 'track.obs0001.p0001'): os.system('madx bench.madx') madbeam = MadBeam.open('track.obs0001.p0001', 'twiss_bench.tfs') block = sixtracklib.cBlock.from_line(line) bref = sixtracklib.cBeam.from_full_beam(madbeam.get_full_beam()) cbeam = bref.copy()[[0]] block.track(cbeam, nturn=2, turnbyturn=True) bnew = block.turnbyturn[:, 0]
import sys sys.path.append('/home/rdemaria/work/lhc_2015/2015/toolkit/') from pyoptics import madlang from compare_opt import compare_optics def set_crossing(t): for irn in '1258': for kn in 'sep x o a': setattr(t,'on_%s%s'%(kn,irn),1) for fn in fnames.split('\n'): bn=os.path.basename(fn) irn=bn[2] ofn="IR%s/%s"%(irn,bn) jfn="%s/%s"%(jmad,fn) print jfn print ofn t1=madlang.open(ofn) t2=madlang.open(jfn) compare_optics(t1,t2,1.00001,1e-12)
from pyoptics import madlang,optics #see sps/madx/a001_track_thin.madx mad=madlang.open('madx/SPS_Q20_thin.seq') mad.acta_31637.volt=4.5 mad.acta_31637.lag=0.5 import pysixtrack elems,rest,iconv=mad.sps.expand_struct(pysixtrack.element_types) pbench=optics.open('madx/track.obs0001.p0001') sps=pysixtrack.Line(elements= [e[2] for e in elems]) def get_part(pbench,ii): pstart=[pbench[n][ii] for n in 'x px y py t pt'.split()] pstart=dict(zip('x px y py tau ptau'.split(),pstart)) prun=pysixtrack.Particles(energy0=pbench.e[ii]*1e9,**pstart) return prun def compare(prun,pbench): out=[] for att in 'x px y py tau ptau'.split(): vrun=getattr(prun,att) vbench=getattr(pbench,att) diff=vrun-vbench out.append(abs(diff)) print(f"{att:<5} {vrun:22.13e} {vbench:22.13e} {diff:22.13g}") print(f"max {max(out):21.12e}") return max(out) prun=get_part(pbench,0)
from pyoptics import madlang, optics #see sps/madx/a001_track_thin.madx mad = madlang.open('sps/madx/SPS_Q20_thin.seq') mad.acta_31637.volt = 4.5 mad.acta_31637.lag = 0.5 out, rest = mad.sps.expand_struct() import pysixtrack out, rest = mad.sps.expand_struct(pysixtrack.convert) elems = zip(*out)[1] sps = pysixtrack.Block(elems) import pickle pickle.dump(sps, open('sps.pickle', 'w')) import numpy as np import time npart = 10 def check_el(p): madt = optics.open('sps/madx/track.obs0002.p0001') out1 = [madt[l][0] for l in 'x px y py y t pt'.split()] out2 = [getattr(p, l) for l in 'x px y py y tau pt'.split()] diff = 0 for a, b in zip(out1, out2): diff += (a - b)**2 print "%24.17e %24.17e %24.17e" % (a, b, a - b)
IR8/betamed/ir8_24000_856.madx IR8/betamed/ir8_26000_843.madx IR8/betamed/ir8_27000_836.madx IR8/betamed/ir8_28000_829.madx IR8/betamed/ir8_30000_816.madx""" import sys sys.path.append('/home/rdemaria/work/lhc_2015/2015/toolkit/') from pyoptics import madlang from compare_opt import compare_optics def set_crossing(t): for irn in '1258': for kn in 'sep x o a': setattr(t, 'on_%s%s' % (kn, irn), 1) for fn in fnames.split('\n'): bn = os.path.basename(fn) irn = bn[2] ofn = "IR%s/%s" % (irn, bn) jfn = "%s/%s" % (jmad, fn) print jfn print ofn t1 = madlang.open(ofn) t2 = madlang.open(jfn) compare_optics(t1, t2, 1.00001, 1e-12)
import pickle import time import numpy as np from pyoptics import madlang, optics import pysixtrack # see sps/madx/a001_track_thin.madx mad = madlang.open("madx/SPS_Q20_thin.seq") mad.acta_31637.volt = 4.5 mad.acta_31637.lag = 0.5 out, rest = mad.sps.expand_struct() out, rest = mad.sps.expand_struct(pysixtrack.convert) elems = list(zip(*out))[1] sps = pysixtrack.Block(elems) pickle.dump(sps, open("sps.pickle", "w")) npart = 10 def check_el(p): madt = optics.open("sps/madx/track.obs0002.p0001") out1 = [madt[l][0] for l in "x px y py y t pt".split()] out2 = [getattr(p, l) for l in "x px y py y tau pt".split()] diff = 0 for a, b in zip(out1, out2): diff += (a - b)**2 print("%24.17e %24.17e %24.17e" % (a, b, a - b))
print "%-20s %10.3e %10.3e %10.3e" % (k, t1[k], t2[k], v) else: break if len(diff) > 0: # print "name value1 value2 diff" for v, k in diff: if v > prdiff: print "%-20s %10.3e %10.3e %10.3e" % (k, t1[k], t2[k], v) else: break return ratio, diff if __name__ == '__main__': import sys from pyoptics import madlang fn1 = sys.argv[1] fn2 = sys.argv[2] prratio = 1.00001 prdiff = 1e-12 if len(sys.argv) > 3: prratio = float(sys.argv[3]) if len(sys.argv) > 4: prdiff = float(sys.argv[4]) t1 = madlang.open(fn1) t2 = madlang.open(fn2) compare_optics(t1, t2, prratio, prdiff)
#!/usr/bin/python from pyoptics import * import pyoptics.madlang as mad import sys import re fn = sys.argv[1] p = mad.open(fn) #print fn reg = re.compile(r'kq(1?[0-9]).*b1') data = [] for k in p._keys(): res = reg.match(k) if res: b1 = p[k] b2 = p[k[:-1] + '2'] data.append((abs(b1 / b2), b1, b2, k)) scale = 23348 data.sort() for r, b1, b2, k in data: if r < 0.5 or r > 2: print "%-30s %-10s %6.3g %6.3g %6.3g" % (fn, k, r, b1 * scale, b2 * scale)
#!/usr/bin/python from pyoptics import * import pyoptics.madlang as mad import sys import re fn=sys.argv[1] p=mad.open(fn) #print fn reg=re.compile(r'kq(1?[0-9]).*b1') data=[] for k in p._keys(): res=reg.match(k) if res: b1=p[k] b2=p[k[:-1]+'2'] data.append((abs(b1/b2),b1,b2,k)) scale=23348 data.sort() for r,b1,b2,k in data: if r<0.5 or r>2: print "%-30s %-10s %6.3g %6.3g %6.3g"%(fn,k,r, b1*scale,b2*scale)