This repository has been archived by the owner on Aug 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
model_params.py
executable file
·131 lines (103 loc) · 3.65 KB
/
model_params.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#! /usr/bin/env python
"""
Generate a list of error parameters for the given model.
Usage:
./model_params.py [-m MODEL] [-a ATTR]... [-b BLACKLIST]...
[--twiss] [--ealign] [--knobs]
Options:
--ealign List alignment errors
--knobs List knob errors
--twiss List twiss args errors
-m MODEL, --model MODEL Path to model
-a ATTR, --attr ATTR List element attribute (e.g. "sbend->e1/e2")
-b ELEM, --blacklist ELEM Blacklist element
Example:
./model_params.py -m hht3 \
-a quadrupole->k1 \
-a sbend->angle/e1/e2/k1 \
-a translation->x/y/px/py \
-b s4mu1e -b s4mu2e \
-b s3me2e -b s3mu1a -b s3ms1v \
-b s0qg4d -b s0qg1f
Missing:
- efcomp (field errors)
"""
from madgui.core.app import init_app
from madgui.core.session import Session
from madgui.core.config import load as load_config
from docopt import docopt
def main(args=None):
opts = docopt(__doc__, args)
model_path = opts['--model'] or '../hit_models/hht3'
init_app(['madgui'])
blacklist = opts['--blacklist'] or [
's4mu1e', 's4mu2e',
's3me2e', 's3mu1a', 's3ms1v',
's0qg4d', 's0qg1f',
]
def blacklisted(name):
return name in blacklist or any(b in name for b in blacklist)
config = load_config(isolated=True)
session = Session(config)
session.load_model(model_path, stdout=False)
model = session.model()
by_type = get_elements_by_type(model)
if opts['--twiss']:
print('')
print('############')
print('## TWISS ##')
print('############')
print('\n'.join(get_twiss_args_errors()))
if opts['--ealign']:
print('')
print('############')
print('## EALIGN ##')
print('############')
for base_name in sorted(by_type):
print('')
print('# {}'.format(base_name))
for elem in by_type[base_name]:
if not blacklisted(elem):
print('\n'.join(get_ealign_errors(elem)))
if opts['--knobs']:
print('')
print('############')
print('## KNOBS ##')
print('############')
for base_name in sorted(by_type):
print('')
print('# {}'.format(base_name))
for elem in by_type[base_name]:
if not blacklisted(elem):
print('\n'.join(get_knob_errors(model, elem)))
if opts['--attr']:
print('')
print('############')
print('## ATTRS ##')
print('############')
for spec in opts['--attr']:
type_, attrs = spec.split('->', 1)
attrs = attrs.split('/')
for elem in model.elements:
if elem.base_name == type_:
print('\n'.join(
'{}->{}'.format(elem.name, attr) for attr in attrs))
def get_elements_by_type(model):
supported_types = {
'sbend', 'quadrupole', 'hkicker', 'vkicker', 'kicker',
'solenoid', 'multipole', 'srotation',
}
by_type = {}
for elem in model.elements:
if elem.base_name in supported_types:
by_type.setdefault(elem.base_name, []).append(elem)
return by_type
def get_twiss_args_errors():
return ['x', 'y', 'px', 'py']
def get_knob_errors(model, elem):
yield from map('δ{}'.format, model.get_elem_knobs(elem))
def get_ealign_errors(elem):
return ['{}<{}>'.format(elem.name, attr)
for attr in ('dx', 'dy', 'ds', 'dphi', 'dtheta', 'dpsi')]
if __name__ == '__main__':
import sys; sys.exit(main(sys.argv[1:]))