nifty8.minimization.config.optimize_kl_config module#

class OptimizeKLConfig(config_parser, builders)[source]#

Bases: object

Plug config files into ift.optimize_kl.

If you use this class for the first time, look at an example config file (e.g. demos/getting_started_7_config_file.cfg) before continuing to read the documentation.

After parsing the config file the following steps are taken:

  • All base entries are interpreted. The options that are written out explicitly in a given section override what might be imported via a base entry. base inheritance does not work recursively (yet?).

  • Repetitions (e.g. “2*5,3*2”) in optimization.* are expanded and replaced by an explicit list (e.g. “5,5,2,2,2”). The length of the resulting list is not allowed to be longer than total iterations. If it is shorter, the last value is repeated.

  • All optimization stages (optimization.*) are joined into a single stage (optimization.0). For this, the quantity after the point . in optimization.* is interpreted as int and sorted afterwards. This means that for example optimization.02 comes after optimization.-1. E.g. optimization.1.1 is not allowed.

For referring to e.g. likelihood energy operators, the star * is used as dereferencing operator. The value after the * refers to a section in the config file that must be instantiable via OptimizeKLConfig.instantiate_section(key).

Generally, all spaces (` ) in keys are internally replaced by underscores (`_) such that they can be used in function calls.

Parameters:
  • config_parser (ConfigParser) – ConfigParser that contains all configuration.

  • builders (dict) – Dictionary of functions that are used to instantiate e.g. operators.

Example

For an example of a typical config file, look at demos/getting_started_7_config_file.cfg in the nifty repository.

Note

Not treated by this class: export_operator_outputs, initial_position, initial_index, comm, inspect_callback, terminate_callback, return_final_position, resume

Note

Make sure that ConfigParser is case-sensitive by setting its attribute optionxform to str before parsing.

__init__(config_parser, builders)[source]#
__iter__()[source]#

Enable conversion to dict such that the result of this class can easily be passed into ift.optimize_kl.

classmethod from_file(file_name, builders)[source]#
Parameters:
  • file_name (str) – File name of the config file that is imported.

  • builders (dict) – Dictionary of functions that are used to instantiate e.g. operators.

instantiate_section(sec)[source]#

Instantiate object that is described by a section in the config file.

There are two mechanisms how this instantiation works:

  • Look up the section key in the self._builders dictionary and call the respective function.

  • If custom function is specified in the section, pass all other entries of the section as arguments to the referred function.

Before the instantiation is performed the inputs are transformed according to the type information that is passed in the config file. By default all values have type str. If bool, float or int shall be passed, the syntax type :: value, e.g. float :: 1.2, needs to be used in the config file.

optimize_kl(**kwargs)[source]#

Do the inference and write the config file to output directory.

All additional parameters to ift.optimize_kl can be passed via kwargs.

to_file(name)[source]#

Write configuration in standardized form to file.

Parameters:

name (str) – Path to which the config shall be written.