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 = 'test_392.lat'
oc = genopt.DakotaOC(lat_file=latfile)
oc.simple_run(iternum=20)

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)
[0.00013981587907,
 7.5578423135e-05,
 -5.3982438406e-05,
 -1.9620020032e-06,
 0.00017942079806,
 ...
 2.0182502319e-05,
 0.0001173634281,
 8.685656753e-05,
 7.3950720611e-05,
 8.2924283647e-05]

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'])

Note

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'])
8.5216269467e-05

Or in another way:

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

New machine m could be used for the next operations.

Note

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='opt1.lat')

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.

Note

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