qutip_qtrl.dynamics

Classes that define the dynamics of the (quantum) system and target evolution to be optimised. The contols are also defined here, i.e. the dynamics generators (Hamiltonians, Limbladians etc). The dynamics for the time slices are calculated here, along with the evolution as determined by the control amplitudes.

See the subclass descriptions and choose the appropriate class for the application. The choice depends on the type of matrix used to define the dynamics.

These class implement functions for getting the dynamics generators for the combined (drift + ctrls) dynamics with the approriate operator applied

Note the methods in these classes were inspired by: DYNAMO - Dynamic Framework for Quantum Optimal Control See Machnes et.al., arXiv.1011.4874

Classes

Dynamics(optimconfig[, params])

This is a base class only.

DynamicsGenMat(optimconfig[, params])

This sub class can be used for any system where no additional operator is applied to the dynamics generator before calculating the propagator, e.g.

DynamicsSymplectic(optimconfig[, params])

Symplectic systems This is the subclass to use for systems where the dynamics is described by symplectic matrices, e.g.

DynamicsUnitary(optimconfig[, params])

This is the subclass to use for systems with dynamics described by unitary matrices.

class qutip_qtrl.dynamics.Dynamics(optimconfig, params=None)[source]

This is a base class only. See subclass descriptions and choose an appropriate one for the application.

Note that initialize_controls must be called before most of the methods can be used. init_timeslots can be called sometimes earlier in order to access timeslot related attributes

This acts as a container for the operators that are used to calculate time evolution of the system under study. That is the dynamics generators (Hamiltonians, Lindbladians etc), the propagators from one timeslot to the next, and the evolution operators. Due to the large number of matrix additions and multiplications, for small systems at least, the optimisation performance is much better using ndarrays to represent these operators. However

Attributes:
log_levelinteger

level of messaging output from the logger. Options are attributes of qutip_qtrl.logging_utils, in decreasing levels of messaging, are: DEBUG_INTENSE, DEBUG_VERBOSE, DEBUG, INFO, WARN, ERROR, CRITICAL Anything WARN or above is effectively ‘quiet’ execution, assuming everything runs as expected. The default NOTSET implies that the level will be taken from the QuTiP settings file, which by default is WARN

params: Dictionary

The key value pairs are the attribute name and value Note: attributes are created if they do not exist already, and are overwritten if they do.

statsStats

Attributes of which give performance stats for the optimisation set to None to reduce overhead of calculating stats. Note it is (usually) shared with the Optimizer object

tslot_computerTimeslotComputer (subclass instance)

Used to manage when the timeslot dynamics generators, propagators, gradients etc are updated

prop_computerPropagatorComputer (subclass instance)

Used to compute the propagators and their gradients

fid_computerFidelityComputer (subclass instance)

Used to computer the fidelity error and the fidelity error gradient.

memory_optimizationint

Level of memory optimisation. Setting to 0 (default) means that execution speed is prioritized over memory. Setting to 1 means that some memory prioritisation steps will be taken, for instance using Qobj (and hence sparse arrays) as the the internal operator data type, and not caching some operators Potentially further memory saving maybe made with memory_optimization > 1. The options are processed in _set_memory_optimizations, see this for more information. Individual memory saving options can be switched by settting them directly (see below)

oper_dtypetype

Data type for internal dynamics generators, propagators and time evolution operators. This can be ndarray or Qobj. Qobj may perform better for larger systems, and will also perform better when (custom) fidelity measures use Qobj methods such as partial trace. See _choose_oper_dtype for how this is chosen when not specified

cache_phased_dyn_genbool

If True then the dynamics generators will be saved with and without the propagation prefactor (if there is one) Defaults to True when memory_optimization=0, otherwise False

cache_prop_gradbool

If the True then the propagator gradients (for exact gradients) will be computed when the propagator are computed and cache until the are used by the fidelity computer. If False then the fidelity computer will calculate them as needed. Defaults to True when memory_optimization=0, otherwise False

cache_dyn_gen_eigenvectors_adj: bool

If True then DynamicsUnitary will cached the adjoint of the Hamiltion eignvector matrix Defaults to True when memory_optimization=0, otherwise False

sparse_eigen_decomp: bool

If True then DynamicsUnitary will use the sparse eigenvalue decomposition. Defaults to True when memory_optimization<=1, otherwise False

num_tslotsinteger

Number of timeslots (aka timeslices)

num_ctrlsinteger

calculate the of controls from the length of the control list

evo_timefloat

Total time for the evolution

tauarray[num_tslots] of float

Duration of each timeslot Note that if this is set before initialize_controls is called then num_tslots and evo_time are calculated from tau, otherwise tau is generated from num_tslots and evo_time, that is equal size time slices

timearray[num_tslots+1] of float

Cumulative time for the evolution, that is the time at the start of each time slice

drift_dyn_genQobj or list of Qobj

Drift or system dynamics generator (Hamiltonian) Matrix defining the underlying dynamics of the system Can also be a list of Qobj (length num_tslots) for time varying drift dynamics

ctrl_dyn_genList of Qobj

Control dynamics generator (Hamiltonians) List of matrices defining the control dynamics

initialQobj

Starting state / gate The matrix giving the initial state / gate, i.e. at time 0 Typically the identity for gate evolution

targetQobj

Target state / gate: The matrix giving the desired state / gate for the evolution

ctrl_ampsarray[num_tslots, num_ctrls] of float

Control amplitudes The amplitude (scale factor) for each control in each timeslot

initial_ctrl_scalingfloat

Scale factor applied to be applied the control amplitudes when they are initialised This is used by the PulseGens rather than in any fucntions in this class

initial_ctrl_offsetfloat

Linear offset applied to be applied the control amplitudes when they are initialised This is used by the PulseGens rather than in any fucntions in this class

dyn_genList of Qobj

List of combined dynamics generators (Qobj) for each timeslot

proplist of Qobj

List of propagators (Qobj) for each timeslot

prop_gradarray[num_tslots, num_ctrls] of Qobj

Array of propagator gradients (Qobj) for each timeslot, control

fwd_evoList of Qobj

List of evolution operators (Qobj) from the initial to the given

onwd_evoList of Qobj

List of evolution operators (Qobj) from the initial to the given

onto_evoList of Qobj

List of evolution operators (Qobj) from the initial to the given

evo_currentBoolean

Used to flag that the dynamics used to calculate the evolution operators is current. It is set to False when the amplitudes change

fact_mat_round_precfloat

Rounding precision used when calculating the factor matrix to determine if two eigenvalues are equivalent Only used when the PropagatorComputer uses diagonalisation

def_amps_fnamestring

Default name for the output used when save_amps is called

unitarity_check_levelint

If > 0 then unitarity of the system evolution is checked at at evolution recomputation. level 1 checks all propagators level 2 checks eigen basis as well Default is 0

unitarity_tol

Tolerance used in checking if operator is unitary Default is 1e-10

dumpqutip.control.dump.DynamicsDump

Store of historical calculation data. Set to None (Default) for no storing of historical data Use dumping property to set level of data dumping

dumpingstring

The level of data dumping that will occur during the time evolution calculation.

dump_to_filebool

If set True then data will be dumped to file during the calculations dumping will be set to SUMMARY during init_evo if dump_to_file is True and dumping not set. Default is False

dump_dirstring

Basically a link to dump.dump_dir. Exists so that it can be set through dyn_params. If dump is None then will return None or will set dumping to SUMMARY when setting a path

apply_params(params=None)[source]

Set object attributes based on the dictionary (if any) passed in the instantiation, or passed as a parameter This is called during the instantiation automatically. The key value pairs are the attribute name and value Note: attributes are created if they do not exist already, and are overwritten if they do.

combine_dyn_gen(k)[source]

Computes the dynamics generator for a given timeslot The is the combined Hamiltion for unitary systems

compute_evolution()[source]

Recalculate the time evolution operators Dynamics generators (e.g. Hamiltonian) and prop (propagators) are calculated as necessary Actual work is completed by the recompute_evolution method of the timeslot computer

property dumping

The level of data dumping that will occur during the time evolution calculation.

  • NONE : No processing data dumped (Default)

  • SUMMARY : A summary of each time evolution will be recorded

  • FULL : All operators used or created in the calculation dumped

  • CUSTOM : Some customised level of dumping

When first set to CUSTOM this is equivalent to SUMMARY. It is then up to the user to specify which operators are dumped. WARNING: FULL could consume a lot of memory!

property dyn_gen

List of combined dynamics generators (Qobj) for each timeslot

property dyn_gen_phase

Some op that is applied to the dyn_gen before expontiating to get the propagator. See phase_application for how this is applied

flag_system_changed()[source]

Flag evolution, fidelity and gradients as needing recalculation

property full_evo

Full evolution - time evolution at final time slot

property fwd_evo

List of evolution operators (Qobj) from the initial to the given timeslot

get_ctrl_dyn_gen(j)[source]

Get the dynamics generator for the control Not implemented in the base class. Choose a subclass

get_drift_dim()[source]

Returns the size of the matrix that defines the drift dynamics that is assuming the drift is NxN, then this returns N

get_dyn_gen(k)[source]

Get the combined dynamics generator for the timeslot Not implemented in the base class. Choose a subclass

get_num_ctrls()[source]

calculate the of controls from the length of the control list sets the num_ctrls property, which can be used alternatively subsequently

init_timeslots()[source]

Generate the timeslot duration array ‘tau’ based on the evo_time and num_tslots attributes, unless the tau attribute is already set in which case this step in ignored Generate the cumulative time array ‘time’ based on the tau values

initialize_controls(amps, init_tslots=True)[source]

Set the initial control amplitudes and time slices Note this must be called after the configuration is complete before any dynamics can be calculated

property num_ctrls

calculate the of controls from the length of the control list sets the num_ctrls property, which can be used alternatively subsequently

property onto_evo

List of evolution operators (Qobj) from the initial to the given timeslot

property onwd_evo

List of evolution operators (Qobj) from the initial to the given timeslot

property phase_application

scalar(string), default=’preop’ Determines how the phase is applied to the dynamics generators

  • ‘preop’ : P = expm(phase*dyn_gen)

  • ‘postop’ : P = expm(dyn_gen*phase)

  • ‘custom’ : Customised phase application

The ‘custom’ option assumes that the _apply_phase method has been set to a custom function.

Type:

phase_application

property prop

List of propagators (Qobj) for each timeslot

property prop_grad

Array of propagator gradients (Qobj) for each timeslot, control

refresh_drift_attribs()[source]

Reset the dyn_shape, dyn_dims and time_depend_drift attribs

save_amps(file_name=None, times=None, amps=None, verbose=False)[source]

Save a file with the current control amplitudes in each timeslot The first column in the file will be the start time of the slot

Parameters:
file_namestring

Name of the file If None given the def_amps_fname attribuite will be used

timesList type (or string)

List / array of the start times for each slot If None given this will be retrieved through get_amp_times() If ‘exclude’ then times will not be saved in the file, just the amplitudes

ampsArray[num_tslots, num_ctrls]

Amplitudes to be saved If None given the ctrl_amps attribute will be used

verboseBoolean

If True then an info message will be logged

unitarity_check()[source]

Checks whether all propagators are unitary

update_ctrl_amps(new_amps)[source]

Determine if any amplitudes have changed. If so, then mark the timeslots as needing recalculation The actual work is completed by the compare_amps method of the timeslot computer

class qutip_qtrl.dynamics.DynamicsGenMat(optimconfig, params=None)[source]

This sub class can be used for any system where no additional operator is applied to the dynamics generator before calculating the propagator, e.g. classical dynamics, Lindbladian

class qutip_qtrl.dynamics.DynamicsSymplectic(optimconfig, params=None)[source]

Symplectic systems This is the subclass to use for systems where the dynamics is described by symplectic matrices, e.g. coupled oscillators, quantum optics

Attributes:
omegaarray[drift_dyn_gen.shape]

matrix used in the calculation of propagators (time evolution) with symplectic systems.

property dyn_gen_phase

The phasing operator for the symplectic group generators usually refered to as Omega By default this is applied as ‘postop’ dyn_gen*-Omega If phase_application is ‘preop’ it is applied as Omega*dyn_gen

class qutip_qtrl.dynamics.DynamicsUnitary(optimconfig, params=None)[source]

This is the subclass to use for systems with dynamics described by unitary matrices. E.g. closed systems with Hermitian Hamiltonians Note a matrix diagonalisation is used to compute the exponent The eigen decomposition is also used to calculate the propagator gradient. The method is taken from DYNAMO (see file header)

Attributes:
drift_hamQobj

This is the drift Hamiltonian for unitary dynamics It is mapped to drift_dyn_gen during initialize_controls

ctrl_hamList of Qobj

These are the control Hamiltonians for unitary dynamics It is mapped to ctrl_dyn_gen during initialize_controls

HList of Qobj

The combined drift and control Hamiltonians for each timeslot These are the dynamics generators for unitary dynamics. It is mapped to dyn_gen during initialize_controls

check_unitarity()[source]

Checks whether all propagators are unitary For propagators found not to be unitary, the potential underlying causes are investigated.

initialize_controls(amplitudes, init_tslots=True)[source]

Set the initial control amplitudes and time slices Note this must be called after the configuration is complete before any dynamics can be calculated

property num_ctrls

calculate the of controls from the length of the control list sets the num_ctrls property, which can be used alternatively subsequently