-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathobj_f_bunch_matching.py
/
obj_f_bunch_matching.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
import subprocess
import numpy as np
from rsbeams.rsdata.SDDS import readSDDS
def obj_f(_):
analysis_command = ["sddsanalyzebeam", "run_setup.output.sdds", "output.anb"]
subprocess.call(analysis_command)
anb = readSDDS("output.anb")
anb.read()
betax, betax_target = anb.columns['betax'].squeeze(), 10.
betay, betay_target = anb.columns['betay'].squeeze(), 10.
alphax, alphax_target = anb.columns['alphax'].squeeze(), 1.
alphay, alphay_target = anb.columns['alphay'].squeeze(), 1.
obj_val = np.sqrt((betax - betax_target) ** 2 +
(betay - betay_target) ** 2 +
(alphax - alphax_target) ** 2 +
(alphay - alphay_target) ** 2)
return obj_val
def obj_f_dfols(_):
analysis_command = ["sddsanalyzebeam", "run_setup.output.sdds", "output.anb"]
subprocess.call(analysis_command)
anb = readSDDS("output.anb")
anb.read()
betax, betax_target = anb.columns['betax'].squeeze(), 10.
betay, betay_target = anb.columns['betay'].squeeze(), 10.
alphax, alphax_target = anb.columns['alphax'].squeeze(), 1.
alphay, alphay_target = anb.columns['alphay'].squeeze(), 1.
obj_val = (betax - betax_target) ** 2 + \
(betay - betay_target) ** 2 + \
(alphax - alphax_target) ** 2 + \
(alphay - alphay_target) ** 2
obj_vec = np.array([betax - betax_target,
betay - betay_target,
alphax - alphax_target,
alphay - alphay_target])
return obj_val, obj_vec