Quickstart Guide

To set up and solve a quantum optimal control problems we provide high level problem templates to quickly get started. For unitary gate problems, where we want to realize a gate $U_{\text{goal}}$, with a system Hamiltonian of the form,

\[H(t) = H_0 + \sum_i a^i(t) H_i\]

there is the UnitarySmoothPulseProblem constructor which only requires

  • the drift Hamiltonian, $H_0$
  • the drive Hamiltonians, $\qty{H_i}$
  • the target unitary, $U_{\text{goal}}$
  • the number of timesteps, $T$
  • the (initial) time step size, $\Delta t$

Basic Usage

For example, to create a problem for a single qubit $X$ gate (with a bound on the drive of $|a^i| < a_{\text{bound}}$), i.e., with system hamiltonian

\[H(t) = \frac{\omega}{2} \sigma_z + a^1(t) \sigma_x + a^2(t) \sigma_y\]

we can do the following:

using NamedTrajectories
using QuantumCollocation

# set time parameters
T = 100
Δt = 0.1

# use the exported gate dictionary to get the gates we need
σx = GATES[:X]
σy = GATES[:Y]
σz = GATES[:Z]

# define drift and drive Hamiltonians
H_drift = 0.5 * σz
H_drives = [σx, σy]

# define target unitary
U_goal = σx

# set bound on the drive
a_bound = 1.0

# build the problem
prob = UnitarySmoothPulseProblem(
    H_drift,
    H_drives,
    U_goal,
    T,
    Δt;
    a_bound=a_bound,
)

# solve the problem
solve!(prob; max_iter=30)
    building dynamics from integrators...
        constructing knot point dynamics functions...
        determining dynamics derivative structure...
            computing jacobian sparsity...
            creating full trajectory jacobian structure...
        constructing full dynamics derivative functions...
    building evaluator...
    initializing optimizer...
applying constraint: initial value of Ũ⃗
applying constraint: initial value of a
applying constraint: final value of a
applying constraint: bounds on a
applying constraint: bounds on da
applying constraint: bounds on dda
applying constraint: bounds on Δt
applying constraint: time step all equal constraint
This is Ipopt version 3.14.16, running with linear solver MUMPS 5.7.3.

Number of nonzeros in equality constraint Jacobian...:    10442
Number of nonzeros in inequality constraint Jacobian.:        0
Number of nonzeros in Lagrangian Hessian.............:        0

Total number of variables............................:     1488
                     variables with only lower bounds:        0
                variables with lower and upper bounds:      496
                     variables with only upper bounds:        0
Total number of equality constraints.................:     1287
Total number of inequality constraints...............:        0
        inequality constraints with only lower bounds:        0
   inequality constraints with lower and upper bounds:        0
        inequality constraints with only upper bounds:        0

iter    objective    inf_pr   inf_du lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
   0  3.3212091e-03 1.90e+00 3.18e-05   0.0 0.00e+00    -  0.00e+00 0.00e+00   0
   1  1.9003673e+00 5.90e-01 5.00e+01  -0.2 1.04e+00    -  2.31e-02 6.87e-01h  1
   2  6.1420856e+01 7.63e-02 1.01e+02  -1.8 2.02e+00    -  4.00e-01 1.00e+00h  1
   3  4.2693641e+01 3.04e-02 1.08e+02  -0.3 2.20e+00    -  9.24e-01 1.00e+00f  1
   4  8.2970856e+00 2.86e-02 1.04e+02   0.1 3.89e+00    -  1.00e+00 1.47e-01f  3
   5  2.6458570e+01 7.23e-03 4.30e+01  -0.6 6.60e-01    -  1.00e+00 1.00e+00h  1
   6  1.9896529e+01 1.53e-03 3.13e+01  -1.5 3.38e-01    -  1.00e+00 1.00e+00f  1
   7  1.5008871e+01 4.68e-03 6.57e+01  -1.7 4.59e-01    -  1.00e+00 1.00e+00f  1
   8  4.1468768e+00 6.60e-04 4.11e+01  -1.9 2.20e-01    -  1.00e+00 1.00e+00f  1
   9  8.7673766e-01 2.73e-04 2.08e+01  -2.9 1.66e-01    -  1.00e+00 1.00e+00f  1
iter    objective    inf_pr   inf_du lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
  10  3.0777329e-01 1.11e-03 1.01e+02  -3.3 2.94e-01    -  7.93e-01 1.00e+00F  1
  11  1.2222840e+00 1.09e-03 1.29e+01  -3.4 5.13e-01    -  1.00e+00 1.25e-01h  4
  12  7.2852937e-01 1.69e-04 3.23e+01  -3.5 8.69e-02    -  1.00e+00 1.00e+00h  1
  13  1.6474924e-01 1.85e-04 5.95e+01  -4.0 1.35e-01    -  1.00e+00 5.00e-01f  2
  14  3.2681351e-01 1.98e-06 3.69e+01  -4.0 8.62e-03    -  1.00e+00 1.00e+00h  1
  15  1.4206276e-01 1.01e-05 3.88e+01  -4.0 2.30e-02    -  1.00e+00 1.00e+00f  1
  16  3.2144465e-02 1.79e-05 6.71e+01  -4.0 2.30e-01    -  1.00e+00 1.25e-01f  4
  17  9.8104515e-03 8.99e-06 4.43e+01  -4.0 3.05e-03    -  1.00e+00 5.00e-01h  2
  18  8.3112195e-03 4.09e-06 5.75e+01  -4.0 1.62e-02    -  1.00e+00 1.00e+00h  1
  19  3.0692749e-03 5.92e-07 5.56e+01  -4.0 6.61e-03    -  1.00e+00 1.00e+00h  1
iter    objective    inf_pr   inf_du lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
  20  1.4644862e-03 4.63e-07 2.52e+01  -4.0 3.17e-03    -  1.00e+00 1.00e+00h  1
  21  1.4164924e-03 2.89e-06 4.90e+00  -4.0 6.99e-03    -  1.00e+00 1.00e+00H  1
  22  3.9855726e-03 2.82e-06 9.52e+01  -4.0 1.75e-01    -  1.00e+00 3.12e-02h  6
  23  2.8078731e-03 3.62e-06 3.06e+01  -4.1 1.17e-02    -  1.00e+00 1.00e+00h  1
  24  1.4867636e-03 1.68e-06 4.74e+01  -4.1 7.80e-03    -  1.00e+00 1.00e+00h  1
  25  1.7280827e-03 1.00e-06 4.84e+01  -4.1 5.93e-03    -  1.00e+00 1.00e+00h  1
  26  1.0144610e-03 2.31e-06 5.17e+01  -4.1 6.76e-03    -  1.00e+00 1.00e+00h  1
  27  1.3196107e-03 2.96e-04 4.17e+01  -4.0 8.04e-02    -  1.00e+00 1.00e+00h  1
  28  9.1719502e-04 6.68e-05 4.97e+01  -4.1 3.82e-02    -  1.00e+00 1.00e+00h  1
  29  1.8539406e-01 9.90e-05 1.00e+02  -4.0 5.48e-02    -  1.00e+00 1.00e+00h  1
iter    objective    inf_pr   inf_du lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
  30  2.7849393e-02 1.53e-04 5.79e+00  -4.1 3.96e+00    -  3.23e-01 1.06e-02f  5

Number of Iterations....: 30

                                   (scaled)                 (unscaled)
Objective...............:   2.7849393205252593e-02    2.7849393205252593e-02
Dual infeasibility......:   5.7940076078263578e+00    5.7940076078263578e+00
Constraint violation....:   1.5340619589698790e-04    1.5340619589698790e-04
Variable bound violation:   0.0000000000000000e+00    0.0000000000000000e+00
Complementarity.........:   2.6254139294135017e-04    2.6254139294135017e-04
Overall NLP error.......:   5.7940076078263578e+00    5.7940076078263578e+00


Number of objective function evaluations             = 58
Number of objective gradient evaluations             = 31
Number of equality constraint evaluations            = 58
Number of inequality constraint evaluations          = 0
Number of equality constraint Jacobian evaluations   = 31
Number of inequality constraint Jacobian evaluations = 0
Number of Lagrangian Hessian evaluations             = 0
Total seconds in IPOPT                               = 0.753

EXIT: Maximum Number of Iterations Exceeded.

The above output comes from the Ipopt.jl solver. To see the final fidelity we can use the unitary_fidelity function exported by QuantumCollocation.jl.

println("Final fidelity: ", unitary_fidelity(prob))
Final fidelity: 0.9958203931870839

We can also easily plot the solutions using the plot function exported by NamedTrajectories.jl.

plot(prob.trajectory, [:Ũ⃗, :a])
Example block output

Minimum Time Problems

We can also easily set up and solve a minimum time problem, where we enforce a constraint on the final fidelity:

\[\mathcal{F}(U_T, U_{\text{goal}}) \geq \mathcal{F}_{\text{min}}\]

Using the problem we just solved we can do the following:

# final fidelity constraint
final_fidelity = 0.99

# weight on the minimum time objective
D = 10.0

prob_min_time = UnitaryMinimumTimeProblem(
    prob;
    final_fidelity=final_fidelity,
    D=D
)

solve!(prob_min_time; max_iter=30)
    building dynamics from integrators...
        constructing knot point dynamics functions...
        determining dynamics derivative structure...
            computing jacobian sparsity...
            creating full trajectory jacobian structure...
        constructing full dynamics derivative functions...
    building evaluator...
    initializing optimizer...
applying constraint: initial value of Ũ⃗
applying constraint: initial value of a
applying constraint: final value of a
applying constraint: bounds on a
applying constraint: bounds on da
applying constraint: bounds on dda
applying constraint: bounds on Δt
applying constraint: time step all equal constraint
This is Ipopt version 3.14.16, running with linear solver MUMPS 5.7.3.

Number of nonzeros in equality constraint Jacobian...:    10442
Number of nonzeros in inequality constraint Jacobian.:        4
Number of nonzeros in Lagrangian Hessian.............:        0

Total number of variables............................:     1488
                     variables with only lower bounds:        0
                variables with lower and upper bounds:      496
                     variables with only upper bounds:        0
Total number of equality constraints.................:     1287
Total number of inequality constraints...............:        1
        inequality constraints with only lower bounds:        1
   inequality constraints with lower and upper bounds:        0
        inequality constraints with only upper bounds:        0

iter    objective    inf_pr   inf_du lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
   0  6.4864455e+01 1.53e-04 2.42e-01   0.0 0.00e+00    -  0.00e+00 0.00e+00   0
   1  6.1931462e+01 2.09e-04 2.09e+00  -1.2 6.27e-02    -  9.92e-01 1.00e+00f  1
   2  5.4673071e+01 6.46e-03 5.07e+01  -1.2 4.45e-01    -  1.00e+00 1.00e+00F  1
   3  7.2473442e+01 1.54e-02 1.00e+02  -0.6 9.49e-01    -  1.00e+00 1.00e+00f  1
   4  7.1055706e+01 1.35e-02 4.50e+01  -0.7 6.09e-01    -  1.00e+00 1.25e-01f  1
   5  6.6150251e+01 1.89e-03 3.15e+01  -0.7 3.78e-01    -  6.45e-01 1.00e+00f  1
   6  6.9779944e+01 1.34e-03 3.54e+01  -0.7 2.26e-01    -  1.00e+00 1.00e+00h  1
   7  6.5600406e+01 1.34e-03 6.53e+01  -0.7 1.66e-01    -  1.00e+00 1.00e+00f  1
   8  6.8063723e+01 3.42e-04 4.93e+01  -0.7 1.12e-01    -  1.00e+00 7.28e-01h  1
   9  6.8544584e+01 1.57e-04 2.51e+01  -0.7 7.59e-02    -  8.55e-01 1.00e+00f  1
iter    objective    inf_pr   inf_du lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
  10  6.8317804e+01 2.58e-04 6.34e+01  -0.7 1.92e-01    -  1.00e+00 5.00e-01f  2
  11  6.7980397e+01 5.73e-05 4.24e+01  -0.7 3.49e-02    -  1.00e+00 1.00e+00h  1
  12  6.4113589e+01 1.98e-04 4.27e+01  -1.0 7.46e-02    -  9.93e-01 1.00e+00f  1
  13  5.8159553e+01 6.89e-04 4.67e+01  -1.1 1.36e-01    -  1.00e+00 1.00e+00f  1
  14  5.0971668e+01 1.05e-03 3.68e+01  -2.0 1.61e-01    -  1.00e+00 1.00e+00f  1
  15  5.0094304e+01 7.70e-05 5.48e+01  -3.2 6.54e-02    -  1.00e+00 9.78e-01f  1
  16  5.0052687e+01 1.79e-05 6.00e+01  -3.9 3.44e-02    -  1.00e+00 1.00e+00h  1
  17  5.0024926e+01 1.52e-05 4.76e+01  -4.0 1.36e-01    -  1.00e+00 2.50e-01f  3
  18  5.0024408e+01 7.52e-06 5.41e+01  -4.0 2.37e-02    -  1.00e+00 1.00e+00h  1
  19  5.0012353e+01 1.34e-06 7.05e+01  -4.0 8.14e-03    -  1.00e+00 1.00e+00h  1
iter    objective    inf_pr   inf_du lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
  20  5.0011917e+01 1.31e-06 3.27e+01  -4.0 3.82e-02    -  1.00e+00 6.25e-02h  5
  21  5.0010829e+01 6.51e-07 4.27e+01  -4.0 7.11e-03    -  1.00e+00 1.00e+00h  1
  22  5.0011561e+01 5.97e-07 5.79e+01  -4.0 1.97e-02    -  1.00e+00 1.25e-01h  4
  23  5.0009096e+01 4.64e-07 4.95e+01  -4.1 9.75e-03    -  1.00e+00 1.00e+00h  1
  24  5.0010929e+01 7.56e-07 5.13e+01  -4.0 1.23e-02    -  1.00e+00 1.00e+00h  1
  25  5.0008843e+01 6.45e-07 4.85e+01  -4.1 8.35e-03    -  1.00e+00 1.00e+00h  1
  26  5.0010835e+01 5.11e-07 5.02e+01  -4.0 6.62e-03    -  1.00e+00 1.00e+00h  1
  27  5.0008806e+01 1.82e-06 5.16e+01  -4.1 1.32e-02    -  1.00e+00 1.00e+00h  1
  28  5.0010906e+01 1.92e-05 4.76e+01  -4.0 3.58e-02    -  1.00e+00 1.00e+00h  1
  29  5.0009967e+01 1.99e-05 4.86e+01  -4.1 5.40e-02    -  1.00e+00 5.00e-01h  2
iter    objective    inf_pr   inf_du lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
  30  5.0008800e+01 1.29e-05 4.88e+01  -4.1 2.05e-02    -  1.00e+00 1.00e+00h  1

Number of Iterations....: 30

                                   (scaled)                 (unscaled)
Objective...............:   5.0008799724605389e+01    5.0008799724605389e+01
Dual infeasibility......:   4.8848420623081736e+01    4.8848420623081736e+01
Constraint violation....:   1.2923423576283177e-05    1.2923423576283177e-05
Variable bound violation:   0.0000000000000000e+00    0.0000000000000000e+00
Complementarity.........:   8.0075742180553676e-05    8.0075742180553676e-05
Overall NLP error.......:   4.8848420623081736e+01    4.8848420623081736e+01


Number of objective function evaluations             = 49
Number of objective gradient evaluations             = 31
Number of equality constraint evaluations            = 49
Number of inequality constraint evaluations          = 49
Number of equality constraint Jacobian evaluations   = 31
Number of inequality constraint Jacobian evaluations = 31
Number of Lagrangian Hessian evaluations             = 0
Total seconds in IPOPT                               = 2.321

EXIT: Maximum Number of Iterations Exceeded.

We can see that the final fidelity is indeed greater than the minimum fidelity we set.

println("Final fidelity:    ", unitary_fidelity(prob_min_time))
Final fidelity:    0.9996735261995057

and that the duration of the pulse has decreased.

initial_dur = get_times(prob.trajectory)[end]
min_time_dur = get_times(prob_min_time.trajectory)[end]

println("Initial duration:  ", initial_dur)
println("Minimum duration:  ", min_time_dur)
println("Duration decrease: ", initial_dur - min_time_dur)
Initial duration:  6.418823943132196
Minimum duration:  4.950791537195261
Duration decrease: 1.4680324059369347

We can also plot the solutions for the minimum time problem.

plot(prob_min_time.trajectory, [:Ũ⃗, :a])
Example block output

This page was generated using Literate.jl.