Setup BPMs, correctors and reference orbitΒΆ

For more general cases, genopt provides interfaces to setup BPMs, correctors, reference orbit and objective function type, etc., leaving more controls to the user side, to fulfill specific task.

Here is an exmaple to show how to use these capabilities.

import genopt

# lattice file
latfile = ''
oc_ins = genopt.DakotaOC(lat_file=latfile)

# select BPMs
bpms = oc_ins.get_elem_by_type('bpm')

# select correctors
hcors = oc_ins.get_all_cors(type='h')[0:40]
vcors = oc_ins.get_all_cors(type='v')[0:40]
oc_ins.set_cors(hcor=hcors, vcor=vcors)

# setup objective function type
oc_ins.ref_flag = "xy"

# setup reference orbit in x and y
bpms_size = len(oc_ins.bpms)

# run optimizaiton
oc_ins.simple_run(method='cg', mpi=True, np=4, iternum=30)

# get output

# plot

The highlighted code block is added for controlling all these abovementioned properties.


  1. BPMs and correctos are distinguished by the element index, which could be get by proper method, e.g. get_all_cors();
  2. The array size of selected BPMs and reference orbit must be the same;
  3. bpms, hcors, vcors are properties of DakotaOC instance.


All elements could be treated as BPMs, see set_bpms(), set pseudo_all=True option will use all elements as monitors.


Objective functions could be chosen from three types according to the value of ref_flag:

  1. ref_flag="xy": \(\sum \Delta x^2 + \sum \Delta y^2\)
  2. ref_flag="x": \(\sum \Delta x^2\)
  3. ref_flag="y": \(\sum \Delta y^2\)

where \(\Delta x = x - x_0\), \(\Delta y = y - y_0\).