After optimization

Suppose all the optimized results have been generated, here are the possible post-operations:

  1. Operations on the optimized Machine object;
  2. Generate new lattice file with optimized results for other programs.

Optimization snippet:

latfile = ''
oc = genopt.DakotaOC(lat_file=latfile)

Get optimized results

Optimized results could be retrieved by get_opt_results() method of DakotaOC class:

  • return type: list
>>> r = oc.get_opt_results(rtype='list')
>>> print(r)

The returned list is alphabetically sorted according to the variables’ names.

  • return type: dictionary, label format: plain
>>> r = oc.get_opt_results()
>>> # or
>>> r = oc.get_opt_results(rtype='dict', label='plain')
>>> print(r)
{'x001': 0.00013981587907,
 'x002': 7.5578423135e-05,
 'x003': -5.3982438406e-05,
 'x004': -1.9620020032e-06,
 'x005': 0.00017942079806,
 'y056': 2.0182502319e-05,
 'y057': 0.0001173634281,
 'y058': 8.685656753e-05,
 'y059': 7.3950720611e-05,
 'y060': 8.2924283647e-05}
  • return type: dictionary, label format: fancy
>>> r = oc.get_opt_results(label='fancy')
>>> print(r)
{'FS1_BBS:DCH_D2412': {'config': {'theta_x': 0.00021066533055}, 'id': 1048},
 'FS1_BBS:DCH_D2476': {'config': {'theta_x': 0.00025833402592}, 'id': 1098},

This is the more comprehensive way to represent the results, one of the advantages is that results with this format could be easily to apply on to reconfigure method of Machine object, for instance:

>>> for k,v in r.items():
>>>     m.reconfigure(v['id'], v['config'])


get_opt_results has outfile optional parameter, if not defined, output file that generated by current optimization instance would be used, or the defined dakota output file would be used, but only valid for cases of label='plain'; label='fancy' is only valid for the case of rtype='dict'.

Get orbit data

get_orbit() could be used to apply all the optimized results, then new Machine could be get in the following way:

>>> z,x,y,m = oc.get_orbit()
>>> print(m.conf(1224)['theta_x'])

Or in another way:

>>> oc.get_orbit()
>>> m = oc.get_machine()

New machine m could be used for the next operations.


get_orbit() could be assigned a optional parameter: outfile, into which the plain ASCII data of zpos, x, and y would be saved.

Get new optimized lattice file

get_opt_latfile() is created to generate new lattice file with optimized results, for the sake of possible next usage of asking for lattice file, this is kind of more general interface.

>>> oc.get_opt_latfile(outfile='')

Here is the links to the lattice files of original and optimized ones, both could be used as the input lattice file of flame program.


generate_latfile() in module genopt.dakutils could be used to generate lattice file from flame.Machine object.