parameter#

Utility to splice (flatten) and merge (unflatten) complex parameters for β€˜real-only’ optimizers.

class ParameterFlattener(parameters: Mapping[str, ParameterValue])[source]#

Bases: object

Utility-class to flatten complex parameters.

Parameters:

parameters – Original parameter-dictionary (unflattened). Non-complex values will not be affected by any method.

unflatten(flattened_parameters: dict[str, float]) β†’ dict[str, TypeAliasForwardRef('tensorwaves.interface.ParameterValue')][source]#

Reverse the flattening operation.

Takes a parameter-dictionary and merges all real and imaginary values whose respective keys have been registered in the constructor of the ParameterFlattener into a complex number. Specifically, while this works also on inputs which have not been generated by flatten() their outputs might be unexpected.

Parameters:

flattened_parameters – parameter dict whose values are to be unflattened.

flatten(parameters: Mapping[str, ParameterValue]) β†’ dict[str, float][source]#

Flatten the parameter-values whose keys have been registered in the constructor.

Splits all complex values whose keys have been registered in the constructor of ParameterFlattener into their real and imaginary parts. Their keys are predetermined by the constructor. Other key-value pairs remain unchanged.

Parameters:

parameters – parameter dict whose values are to be flattened.