krotov.info_hooks module

Routines that can be passed as info_hook to optimize_pulses()

Summary

Data:

chain Chain multiple info_hook or modify_params_after_iter callables together.
print_debug_information Print full debug information about the current Krotov iteration

__all__: chain, print_debug_information

Reference

krotov.info_hooks.chain(*hooks)[source]

Chain multiple info_hook or modify_params_after_iter callables together.

Example

>>> def print_fidelity(**kwargs):
...     F_re = np.average(np.array(kwargs['tau_vals']).real)
...     print("    F = %f" % F_re)
>>> info_hook = chain(print_debug_information, print_fidelity)

Note

Functions that are connected via chain() may use the shared_data share the same shared_data argument, which they can use to communicate down the chain.

krotov.info_hooks.print_debug_information(*, objectives, adjoint_objectives, backward_states, forward_states, optimized_pulses, lambda_vals, shape_arrays, fw_states_T, tau_vals, start_time, stop_time, iteration, shared_data, out=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>)[source]

Print full debug information about the current Krotov iteration

This routine is intended to be passed to optimize_pulses() as info_hook, and it exemplifies the full signature of a routine suitable for this purpose.

Keyword Arguments:
 
  • objectives (list[Objective]) – list of the objectives
  • adjoint_objectives (list[Objective]) – list of the adjoint objectives
  • backward_states (list) – If available, for each objective, an array-like object containing the states of the Krotov backward propagation.
  • forward_states – If available, for each objective, an array-like object containing the forward-propagated states under the optimized pulses.
  • optimized_pulses (list[numpy.ndarray]) – list of optimized pulses
  • lambda_vals (list[float]) – for each pulse, the value of the \(\lambda_a\) parameter
  • shape_arrays (list[numpy.ndarray]) – for each pulse, the array of update-shape values \(S(t)\)
  • fw_states_T (list) – for each objective, the forward-propagated state
  • tau_vals (list[complex]) – for each objective, the complex overlap for the forward-propagated state with the target state
  • start_time (float) – The time at which the iteration started, in epoch seconds
  • stop_time (float) – The time at which the iteration started, in epoch seconds
  • iteration (int) – The current iteration number. For the initial propagation of the guess controls, 0.
  • shared_data (dict) – Dict of data shared between any modify_params_after_iter and any info_hook functions chained together via chain().
  • out – An open file handle where to write the information. This parameter is not part of the info_hook interface. Use functools.partial() to pass a different value.

Note

This routine implements the full signature of an info_hook in optimize_pulses(), excluding out. However, since the info_hook only allows for keyword arguments, it is usually much simpler to use Python’s variable keyword arguments syntax (**kwargs). For example, consider the following info_hook that prints (and stores) the value of the real-part gate fidelity:

def print_fidelity(**kwargs):
    F_re = np.average(np.array(kwargs['tau_vals']).real)
    print("    F = %f" % F_re)
    return F_re