qutip_qoc package

Submodules

Module contents

class qutip_qoc.Objective(initial, H, target, weight=1)[source]

Bases: object

A class for storing information about an optimization objective.

Examples

To specify an objective for GOAT, provide a gradient function:

initial = qt.basis(2, 0)
target  = qt.basis(2, 1)

sin = lambda t, p: np.sin(p * t)

def d_sin(t, p, idx):
    if idx==0: return t * np.cos(t) # w.r.t. p
    if idx==1: return p * np.cos(t) # w.r.t. t

H = [qt.sigmax(), [qt.sigmay(), sin, {'grad': d_sin}]]

obj = Objective(initial, H, target)

To specify an objective for JOPT, no need for gradient function:

initial = qt.basis(2, 0)
target  = qt.basis(2, 1)

@jax.jit
def sin(t, p)
    return jax.numpy.sin(p * t)

def d_sin(t, p, idx):
    if idx==0: return t * np.cos(t) # w.r.t. p
    if idx==1: return p * np.cos(t) # w.r.t. t

H = [qt.sigmax(), [qt.sigmay(), sin]]

obj = Objective(initial, H, target)
Attributes:
initialqutip.Qobj

The initial state or operator to be transformed.

Hcallable, list

A specification of the time-depedent quantum object. Usually a list with drift Hamiltonian at zero-index followed by the control Hamiltonians. See qutip.QobjEvo for details and examples.

targetqutip.Qobj

The target state or operator.

weightfloat

Only used in multi-objective scenarios. The weight of this objective in the optimization. All weights are normalized to sum to 1.

class qutip_qoc.Result(objectives=None, time_interval=None, start_local_time=None, end_local_time=None, total_seconds=None, n_iters=None, iter_seconds=None, message=None, guess_controls=None, optimized_controls=None, optimized_H=None, final_states=None, guess_params=None, new_params=None, optimized_params=None, infidelity=inf, var_time=False, qtrl_optimizers=None)[source]

Bases: object

Class for storing the results of a pulse control optimization run.

Attributes:
objectiveslist of qutip_qoc.Objective

List of objectives to be optimized.

time_intervalqutip_qoc._TimeInterval

Time interval for the optimization.

start_local_timestruct_time

Time when the optimization started.

end_local_timestruct_time

Time when the optimization ended.

total_secondsfloat

Total time in seconds the optimization took.

itersint

Number of iterations until convergence. Equal to the length of iter_seconds.

iter_secondslist of float

Seconds between each iteration.

messagestr

Reason for termination.

optimized_paramslist of ndarray

Parameter values after optimization.

guess_controlslist of ndarray

Control pulses before the optimization.

optimized_controlslist of ndarray

Control pulses after optimization.

optimized_Hlist of qutip.QobjEvo

Optimized Hamiltonians with optimized controls.

final_stateslist of qutip.Qobj

Evolved system states after optimization.

infidelityfloat

Final infidelity error after the optimization.

var_timebool

Whether the optimization was performed with variable time. If True, the last parameter in optimized_params is the evolution time.

_update(infidelity, parameters)[source]

Used to update the result during optimization.

dump(filename)[source]

Save the result to a file.

property evo_full_final

Deprecated, use final_states[0] instead.

property fid_err

Deprecated, use infidelity instead.

property final_states

Evolved system states after optimization.

property grad_norm_final

Deprecated, not supported.

property guess_controls

Control pulses before the optimization.

classmethod load(filename, objectives=None)[source]

Load a objective from a file.

property num_iter

Deprecated, use n_iters instead.

property optimized_H

Optimized Hamiltonians with optimized controls.

property optimized_controls

Control pulses after optimization.

property optimized_params

Parameter values after optimization.

property termination_reason

Deprecated, use message instead.

property total_seconds

Total time in seconds the optimization took.

property wall_time

Deprecated, use total_seconds instead.

class qutip_qoc._TimeInterval(tslots=None, evo_time=None, n_tslots=None)[source]

Bases: object

Class for storing a time interval and deriving its attributes.

Attributes:
tslotsarray_like, optional

If not provided, it is derived from evo_time and n_tslots.

evo_timefloat, optional

If not provided, it is derived from the last element of tslots.

n_tslotsint, optional

If not provided, it is derived from the length of tslots.

property evo_time

If not provided, it is derived from the last element of tslots.

property n_tslots

If not provided, it is derived from the length of tslots.

property tslots

If not provided, it is derived from evo_time and n_tslots.

qutip_qoc.optimize_pulses(objectives, control_parameters, tlist, algorithm_kwargs=None, optimizer_kwargs=None, minimizer_kwargs=None, integrator_kwargs=None)[source]

Run GOAT, JOPT, GRAPE, CRAB or RL optimization.

Parameters:
objectiveslist of qutip_qoc.Objective

List of objectives to be optimized. Each objective is weighted by its weight attribute.

control_parametersdict

Dictionary of options for the control pulse optimization. The keys of this dict must be a unique string identifier for each control Hamiltonian / function. For the GOAT and JOPT algorithms, the dict may optionally also contain the key “__time__”. For each control function it must specify:

control_iddict
  • guess: ndarray, shape (n,)

    For RL you don’t need to specify the guess. Initial guess. Array of real elements of size (n,), where n is the number of independent variables.

  • boundssequence, optional

    Sequence of (min, max) pairs for each element in guess. None is used to specify no bound.

__time__dict, optional

Only supported by GOAT, JOPT (for RL use algorithm_kwargs: ‘shorter_pulses’). If given the pulse duration is treated as optimization parameter. It must specify both:

  • guess: ndarray, shape (n,)

    Initial guess. Array of real elements of size (n,), where n is the number of independent variables.

  • boundssequence, optional

    Sequence of (min, max) pairs for each element in guess. None is used to specify no bound.

GRAPE and CRAB bounds are only one pair of (min, max) limiting the amplitude of all tslots equally.

tlist: List.

Time over which system evolves.

algorithm_kwargsdict, optional

Dictionary of options for the optimization algorithm.

  • algstr

    Algorithm to use for the optimization. Supported are: “GRAPE”, “CRAB”, “GOAT”, “JOPT” and “RL”.

  • fid_err_targfloat, optional

    Fidelity error target for the optimization.

  • max_iterint, optional

    Maximum number of iterations to perform. Referes to local minimizer steps or in the context of alg: “RL” to the max. number of episodes. Global steps default to 0 (no global optimization). Can be overridden by specifying in minimizer_kwargs.

Algorithm specific keywords for GRAPE,CRAB can be found in qutip_qtrl.pulseoptim.optimize_pulse().

optimizer_kwargsdict, optional

Dictionary of options for the global optimizer. Only supported by GOAT and JOPT.

  • methodstr, optional

    Algorithm to use for the global optimization. Supported are: “basinhopping”, “dual_annealing”

  • max_iterint, optional

    Maximum number of iterations to perform. Default is 0 (no global optimization).

Full list of options can be found in scipy.optimize.basinhopping() and scipy.optimize.dual_annealing().

minimizer_kwargsdict, optional

Dictionary of options for the local minimizer.

  • methodstr, optional

    Algorithm to use for the local optimization. Gradient driven methods are supported.

Full list of options and methods can be found in scipy.optimize.minimize().

integrator_kwargsdict, optional

Dictionary of options for the integrator. Only supported by GOAT and JOPT. Options for the solver, see MESolver.options and Integrator for a list of all options.

Returns:
resultqutip_qoc.Result

Optimization result.