Skip to content

Commit 5ea064c

Browse files
authored
Piece-wise constant control functions and total-variation penalty term (#27)
* Implemented piece-wise constant B-spline ctrl functions. New configuration option for control types: control_segment0 = spline0, <nsplines> * Add total variation regularization to prevent noisy. New configuration option: optim_penalty_variation = <value> for the c++ code and gamma_variation = <value> for the python interface * Documenting the zeroth order B-spline basis function in the user's guide. * Setting default carrier wave frequencies to zero, if piecewise constant controls are used through the python interface
1 parent 603d7af commit 5ea064c

18 files changed

+420
-81
lines changed

config_template.cfg

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@ initialcondition = basis
4646
/* --------------------------------------------------------------- */
4747
// Define the controllable segments for each oscillator and the type of parameterization. Multiple segments can be listed behind each other, with corresponding starting and finish times.
4848
// Format: <controltype>, <number of basis functions> [, <tstart>, <tstop>]
49+
// Available control types: "spline" for 2nd order Bspline basis functions (recommended), "spline0" for piecewise constant control parameterization (aka 0th order Bspline basis functions)
4950
control_segments0 = spline, 150
5051
control_segments1 = spline, 150
52+
# control_segments0 = spline0, 300
5153
# control_segments0 = spline, 150, <tstart>, <tstop>
5254
# control_segments0 = spline_amplitude, 150, 1.0
5355
// Decide whether control pulses should start and end at zero. Default: true.
@@ -104,7 +106,9 @@ optim_penalty_param = 0.0
104106
optim_penalty_dpdm = 0.0
105107
// Coefficient (gamma_4) for penalizing the control pulse energy integral (gamma_4 \int_0^T p^2 + q^2 dt )
106108
optim_penalty_energy= 0.0
107-
// Switch to use Tikhonov regularization with ||alpha - alpha_0||^2 instead of ||alpha||^2
109+
// Coefficient (gamma_5) for penalizing variations in control amplitudes. Only used for piece-wise constant control paramterizations (spline0)
110+
optim_penalty_variation= 0.0
111+
// Switch to use Tikhonov regularization with ||x - x_0||^2 instead of ||x||^2
108112
optim_regul_tik0=false
109113

110114

doc/user_guide.bib

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@article{goerz2014optimal,
22
title={Optimal control theory for a unitary operation under dissipative evolution},
3-
author={Goerz, Michael H and Reich, Daniel M and Koch, Christiane P},
3+
author={Goerz, Michael H. and Reich, Daniel M. and Koch, Christiane P.},
44
journal={New Journal of Physics},
55
volume={16},
66
number={5},
@@ -31,17 +31,21 @@ @misc{guenther2021quandary
3131
howpublished = "https://arxiv.org/abs/2110.10310",
3232
}
3333

34-
3534
@article{petersson2021optimal,
36-
title={Optimal control of closed quantum systems via b-splines with carrier waves},
37-
author={Petersson, N Anders and Garcia, Fortino},
38-
journal={arXiv preprint arXiv:2106.14310},
39-
year={2021}
35+
author = {Petersson, N. Anders and Garcia, Fortino},
36+
title = {Optimal Control of Closed Quantum Systems via {B}-Splines with Carrier Waves},
37+
journal = {SIAM Journal on Scientific Computing},
38+
volume = {44},
39+
number = {6},
40+
pages = {A3592-A3616},
41+
year = {2022},
42+
doi = {10.1137/21M1429618}
4043
}
4144

45+
4246
@article{gunther2023practical,
4347
title={A practical approach to determine minimal quantum gate durations using amplitude-bounded quantum controls},
44-
author={G{\"u}nther, Stefanie and Petersson, N Anders},
48+
author={G{\"u}nther, Stefanie and Petersson, N. Anders},
4549
journal={AVS Quantum Science},
4650
volume={5},
4751
number={4},

doc/user_guide.pdf

4.21 KB
Binary file not shown.

doc/user_guide.tex

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,11 @@ \subsection{Rotational frame approximation}
215215

216216

217217
\subsection{Control pulses} \label{subsec:controlpulses}
218-
The time-dependent rotating-frame control functions $d^k(\vec{\alpha}^k,t)$ are parameterized using $N_s^k$ piecewise quadratic B-spline basis functions $B_s(t)$ acting as envelope for $N_f^k$ carrier waves:
219-
\begin{align}
218+
The time-dependent rotating-frame control functions $d^k(\vec{\alpha}^k,t)$ are parameterized using $N_s^k$ basis functions $B_s(t)$ acting as envelope for $N_f^k$ carrier waves:
219+
\begin{align}\label{eq:spline-ctrl}
220220
d^k(\vec{\alpha}^k,t) = \sum_{f=1}^{N_f^k} \sum_{s=1}^{N_s^k} \alpha_{s,f}^k B_s(t) e^{i\Omega_k^ft}, \quad \alpha_{s,f}^k = \alpha_{s,f}^{k(1)} + i \alpha_{s,f}^{k(2)} \in \C
221221
\end{align}
222+
By default, the basis functions are piecewise quadratic (2nd order) B-spline polynomials, centered on an equally spaced grid in time. To instead use a piecewise constant (0th order) B-spline basis, see Section~\ref{subsec:bspline-0}.
222223
The amplitudes $\alpha_{s,f}^{k(1)}, \alpha_{s,f}^{k(2)} \in \R$ are the control
223224
parameters (\textit{design} variables) that Quandary can optimize in order to realize a
224225
desired system behavior, giving a total number of $2\sum_kN_s^kN_f^k$ real-valued optimization variables. (Note that the number of carrier wave frequencies $N_f^k$ as well as the number of spline basis functions $N_s^k$ can be different for each subsystem $k$.) $\Omega_k^f \in \R$ denote the carrier wave frequencies in the rotating frame which can be choosen to trigger certain system frequencies. The corresponding Lab-frame carrier frequencies become $\omega_k^r + \Omega_k^f$. Those frequencies can be chosen to match the transition frequencies in the lab-frame system Hamiltonian. For example, when $\xi_{kl} << \xi_k$, the transition frequencies satisfy $\omega_k - n\xi_k$. Thus by choosing $\Omega_k^f = \omega_k-\omega_k^r - n \xi_k$, one triggers transition between energy levels $n$ and $n+1$ in subsystem $k$. Choosing effective carrier wave frequencies is quite important for optimization performance. We recommend to have a look at \cite{petersson2021optimal} for details on how to choose them.
@@ -285,6 +286,17 @@ \subsubsection{Storage of the control parameters}
285286
q(t) = \sum_f \sum_s \alpha_{f,s} \sin(\Omega_f t + b_f) B_s(t)
286287
\end{align}
287288

289+
\subsubsection{Zeroth order B-spline basis functions (piecewise constant controls)}\label{subsec:bspline-0}
290+
A piecewise continuous envelope function can be generated by using zeroth order B-spline basis functions. When the carrier wave frequency is set to zero, this results in a control function that is piecewise constant in the rotating frame. For example, to use the zeroth order basis functions for controlling sub-system number 0 with 50 constant control segments, use the configuration option:
291+
\begin{verbatim}
292+
control_segments0 = spline0, 50
293+
\end{verbatim}
294+
When optimizing with zeroth order B-spline control functions, strong variations between consequtive control amplitudes can be avoided by enabling the total variation penalty term through the command
295+
\begin{verbatim}
296+
optim_penalty_variation= 1.0
297+
\end{verbatim}
298+
Compare Section \ref{sec:penalty}.
299+
288300

289301
\subsection{Interfacing to Python environemnt}
290302
You can use the Python interface for Quandary to simulate and optimize from within a python environment (version $\geq$ 3). It eases the use of Quandary, and adds some additional functionality, such as automatic computation of the required number of time steps, automatic choice of the carrier frequencies, and it allows for custom Hamiltonian models to be used (system and control Hamiltonian operators $H_d$ and $H_c$). A good place to start is to have a look into the example \texttt{example\_swap02.py}. This test case optimizes for a 3-level SWAP02 gate that swaps the state of the zero and the second energy level of a 3-level qudit.
@@ -310,10 +322,10 @@ \section{The Optimal Control Problem} \label{sec:optim}
310322
In the most general form, Quandary can solve the following optimization problem
311323
\begin{align}\label{eq:minproblem}
312324
% \min_{\boldsymbol{\alpha}} \frac{1}{n_{init}} \sum_{i=1}^{n_{init}} \beta_i J(\rho^{target}_i, \rho_i(T)) + \gamma_1 \int_0^T P\left(\rho_i(t)\right) \, \mathrm{d} t + \gamma_2 \| \bfa \|^2_2
313-
\min_{\boldsymbol{\alpha}} J(\{\rho^{target}_i, \rho_i(T) \}) + \gamma_1 \| \bfa \|^2_2 + Penalty
325+
\min_{\boldsymbol{\alpha}} J(\{\rho^{target}_i, \rho_i(T) \}) \quad + \mbox{Regularization} + \mbox{Penalty}
314326
\end{align}
315327
where $\rho_i(T)$ denotes one or multiple quantum states evaluated at a final time $T>0$, which solve either Lindblad's master equation \eqref{mastereq} or Schroedinger's equation \eqref{eq:schroedinger} in the rotating frame for initial conditions $\rho_i(0)$, as specified in Section \ref{subsec:initcond}, $i=1,\dots, n_{init}$. The first term in \eqref{eq:minproblem} minimizes an objective function $J$ (see Section \ref{sec:objectivefunctionals}) that quantifies the discrepancy between the realized states $\rho_i(T)$ at final time $T$ driven by the current control $\boldsymbol{\alpha}$ and the desired target $\rho^{target}_i$, see Section \ref{sec:targets}.
316-
The second term is a standart Tikhonov regularization that can be added with parameter $\gamma_1\geq 0$ in order to regularize the optimization problem (stabilize optimization convergence) by favoring solutions with small norm. Additional penalty terms, e.g. for leakage prevention, can be added, compare \ref{sec:penalty}.
328+
The remaining terms are regularization and penalty terms that can be added to stabilize convergence, or prevent leakage, compare Section \ref{sec:penalty}
317329

318330
\subsection{Fidelity}\label{sec:fidelity}
319331

@@ -459,7 +471,7 @@ \subsubsection{Basis states}
459471

460472

461473

462-
\subsubsection{Diagonal density matrices (aka all pure states)}
474+
\subsubsection{Only the diagonal density basis matrices}
463475

464476
For density matrices (Lindblad solver), one can choose to propagate only those basis states that correspond to pure states of the form $\boldsymbol{e}_k\boldsymbol{e}_k^\dagger$, i.e. propagating only the $B^{kk}$ in \eqref{eq:basismats} for $k=0,\dots, N-1$, and then $n_{init}=N$. For the Schroedinger solver, this is equivalent to all basis states.
465477

@@ -514,22 +526,36 @@ \subsubsection{Reading an initial state from file}
514526

515527

516528

517-
\subsection{Penalty terms and leakage prevention}\label{sec:penalty}
529+
\subsection{Tikhonov regularization, penalty terms, and leakage prevention}\label{sec:penalty}
518530

519-
Three optional penalty terms can be added to the objective function:
531+
In order to regularize the optimization problem (stabilize optimization convergence), a standard Tikhonov regularization term can added to the objective function.
520532
\begin{align}
521-
Penalty = \gamma_2/T \int_0^T P\left(\{\rho_i(t)\}\right) \, \mathrm{d} t + \gamma_3 /T \int_0^T \, \| \partial_{tt} \mbox{Pop}(\rho_i(t)) \|^2 \mathrm{d}t + \gamma_4/T \int_0^T \, \sum_k |d^k(\alpha^k,t)|^2\, dt
533+
\mbox{Tikhonov} = \frac{\gamma_1}{2} \| \bfa \|^2_2
522534
\end{align}
523-
The first penalty term can be added with $\gamma_2 \geq 0$ to achieve a desired behavior over the entire time-domain $0\leq t\leq T$, rather than only at the final time. If extra (non-essential levels are considered through the optimization for at least one oscillator ($n_k^e < n_k$ for at least $k$, compare Sec. \ref{sec:essentiallevels}), then this term can be used to prevent leakage to higher energy levels that are not modelled. In particular, in that case the occupation of all \textit{guard levels} are penalized through
535+
By adding this term with a small parameter $\gamma_1 > 0$, the optimization problem will favor optimal control vectors that have a small norm. It regularizes the optimization problem since it adds a small but positive identity matrix to the Hessian of the objective function, hence ``convexifying'' the problem.
536+
537+
In addition to the Tikhonov regularization term, four additional penalty terms can optionally be added to the objective function if desired:
538+
\begin{align*}
539+
Penalty &= \frac{\gamma_2}{T} \int_0^T P\left(\{\rho_i(t)\}\right) \, \mathrm{d} t \hspace{3cm} \rightarrow \text{Leakage prevention}\\
540+
&+ \frac{\gamma_3}{T} \int_0^T \, \| \partial_{tt} \mbox{Pop}(\rho_i(t)) \|^2 \mathrm{d}t \hspace{2cm} \rightarrow \text{State variation penalty} \\
541+
&+\frac{\gamma_4}{T} \int_0^T \, \sum_k |d^k(\alpha^k,t)|^2\, dt \hspace{2cm}\rightarrow \text{Control energy penalty}\\
542+
&+ \frac{\gamma_5}{2} Var(\vec{\alpha}) \hspace{4cm}\rightarrow \text{Control variation penalty}
543+
\end{align*}
544+
The first penalty term can be added with $\gamma_2 > 0$ to drive the quantum system towards the desired state over the entire time-domain $0\leq t\leq T$, rather than only at the final time. If extra (non-essential levels are considered through the optimization for at least one oscillator ($n_k^e < n_k$ for at least $k$, compare Sec.~\ref{sec:essentiallevels}), then this term can be used to prevent leakage to higher energy levels that are not modelled. In particular, in that case, the occupation of all \textit{guard levels} are penalized with
524545
\begin{align}\label{eq:leakprevention}
525546
P(\rho(t)) = \sum_{r} \| \rho(t)_{rr} \|^2_2
526547
\end{align}
527-
where $r$ iterates over all indices that correspond to a guard level (i.e. last non-essential energy level) of at least one of the subsystems, and $\rho(t)_{rr}$ denotes their corresponding population.
548+
where $r$ iterates over all indices that correspond to a guard level (i.e., the final (highest) non-essential energy level) of at least one of the subsystems, and $\rho(t)_{rr}$ denotes their corresponding population.
528549

550+
The second penalty term can be added with parameter $\gamma_3 > 0$ to encourage solutions whose populations vary slowly in time by penalizing the second derivative of the populations of the state.
529551

530-
The second penalty term can be added with parameter $\gamma_3 \geq 0$ to encourage solutions whose populations vary slowly in time by penalizing the second derivative of the populations of the state.
552+
The third penalty term can be added with parameter $\gamma_4 > 0$ to encourage small control pulse amplitudes by penalizing the control pulse energy. This term can be useful if hardware bounds are given for the control pulse amplitudes: Rather than include amplitude bounds on control pulse directly, which often leads to more non-convex optimization problems and convergence deterioration, one can utilize this penalty term to favor short control pulses with small amplitudes. Compare also \cite{gunther2023practical} for its usage to determine minimal gate durations.
531553

532-
The third penalty term can be added with parameter $\gamma_4 \geq 0$ to encourage small control pulse amplitudes by penalizing the control pulse energy. This term can be useful if hardware bounds are given for the control pulse amplitudes: Rather than include amplitude bounds on control pulse directly, which often leads to more non-convex optimization problems and convergence deterioration, one can utilize this penalty term to favor short control pulses with small amplitudes. Compare also \cite{gunther2023practical} for its usage to determine minimal gate durations.
554+
The last penalty term, activated by setting $\gamma_5>0$, is used to penalize variation in control strength between consequtive B-spline coefficients. It is currently only implemented for piecewise zeroth order spline functions, see Section \ref{subsec:bspline-0}, where it is useful to prevent noisy control pulses. Referring to the control function representation in \eqref{eq:spline-ctrl}, this penalty function takes the form:
555+
\begin{align}
556+
Var(\vec{\alpha}) = \sum_{k=1}^Q Var_k(\vec{\alpha}),\quad Var_k(\vec{\alpha}) = \sum_{f=1}^{N_f^k} \sum_{s=2}^{N_s^k} |\alpha_{s,f}^k - \alpha_{s-1,f}^k|^2,
557+
\end{align}
558+
in terms of the complex-valued control parameters $\alpha_{s,f}^k = \alpha_{s,f}^{k(1)} + i \alpha_{s,f}^{k(2)}$. Penalizing the variance can significantly reduce the noise level in the optimized control functions.
533559

534560
Note: All regularization and penalty coefficients $\gamma_i$ should be chosen small enough so that they do not dominate the final-time objective function $J$. This might require some fine-tuning. It is recommended to always add $\gamma_1>0$, e.g. $\gamma_1 = 10^{-4}$, and add other penalties only if needed.
535561

examples/pythoninterface/example_cnot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
# Set up the Quandary configuration for this test case. Make sure to pass all of the above to the corresponding fields, compare help(Quandary)!
3737
quandary = Quandary(freq01=freq01, Jkl=Jkl, rotfreq=rotfreq, T=T, targetgate=unitary, verbose=verbose, rand_seed=rand_seed)
3838

39-
# Potentially, load initial control parameters from a file.
40-
# quandary.pcof0_filename = os.getcwd() + "./CNOT_params.dat" # absolute path!
39+
# Optionally, if you already have control parameters, load them from a file.
40+
# quandary.pcof0_filename = os.getcwd() + "/CNOT_params.dat" # absolute path!
4141

4242
# Execute quandary
4343
t, pt, qt, infidelity, expectedEnergy, population = quandary.optimize()
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Make sure you have the location of quandary.py in your PYTHONPATH. E.g. with
2+
# > export PYTHONPATH=/path/to/quandary/:$PYTHONPATH
3+
# Further, make sure that your quandary executable is in your $PATH variable. E.g. with
4+
# > export PATH=/path/to/quandary/:$PATH
5+
from quandary import *
6+
7+
## Two qubit test case, demonstrating the use of piecewise constant control functions with total variation penalty term. CNOT gate, two levels each, no guard levels, dipole-dipole coupling 5KHz ##
8+
9+
# 01 transition frequencies [GHz] per oscillator
10+
freq01 = [4.80595, 4.8601]
11+
# Coupling strength [GHz] (Format [0<->1, 0<->2, ..., 1<->2, ... ])
12+
Jkl = [0.005] # Dipole-Dipole coupling of qubit 0<->1
13+
# Frequency of rotations for computational frame [GHz] per oscillator
14+
favg = sum(freq01)/len(freq01)
15+
rotfreq = favg*np.ones(len(freq01))
16+
17+
# Set the pulse duration (ns)
18+
T = 200.0
19+
20+
# Set up the CNOT target gate
21+
unitary = np.identity(4)
22+
unitary[2,2] = 0.0
23+
unitary[3,3] = 0.0
24+
unitary[2,3] = 1.0
25+
unitary[3,2] = 1.0
26+
# print("Target gate: ", unitary)
27+
28+
# Flag for printing out more information to screen
29+
verbose = False
30+
31+
# For reproducability: Random number generator seed
32+
rand_seed=1234
33+
34+
# For piecewise constant control functions, choose spline order of 0 (Default spline order would be 2, being 2nd order Bsplines). Note, the number spline basis functions for piecewise constant controls has to be much larger than if you use 2nd order Bsplines. Also note that if the spline order is zero, it is recommended not to use any carrier frequencies, which is already the default.
35+
spline_order = 0
36+
nsplines = 1000
37+
38+
# In order get less noisy control functions, activate the penalty term for variation of the control parameters
39+
gamma_variation = 1.0
40+
41+
# Optionally: let controls functions start and end near zero
42+
control_enforce_BC = True
43+
44+
# Set up the Quandary configuration for this test case. Make sure to pass all of the above to the corresponding fields, compare help(Quandary)!
45+
quandary = Quandary(freq01=freq01, Jkl=Jkl, rotfreq=rotfreq, T=T, targetgate=unitary, verbose=verbose, rand_seed=rand_seed, spline_order=spline_order, nsplines=nsplines, gamma_variation=gamma_variation, control_enforce_BC=control_enforce_BC)
46+
47+
# Execute quandary
48+
t, pt, qt, infidelity, expectedEnergy, population = quandary.optimize(quandary_exec="~/Numerics/quandary_master/quandary")
49+
50+
print(f"Fidelity = {1.0 - infidelity}")
51+
52+
# Plot the control pulse and expected energy level evolution
53+
if True:
54+
plot_pulse(quandary.Ne, t, pt, qt)
55+
plot_expectedEnergy(quandary.Ne, t, expectedEnergy)

examples/pythoninterface/example_swap12.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@
4747
plot_expectedEnergy(quandary.Ne, t, expectedEnergy)
4848

4949

50-
# Adding some decoherence and simulate again
51-
quandary.T1 = [10000.0]
52-
quandary.T2 = [8000.0]
53-
quandary.update()
54-
quandary.pcof0 = quandary.popt[:]
55-
t, pt, qt, infidelity, expectedEnergy, population = quandary.simulate(datadir=datadir, maxcores=8)
56-
print(f"Fidelity under decoherence = {1.0 - infidelity}")
50+
# # Adding some decoherence and simulate again
51+
# quandary.T1 = [10000.0]
52+
# quandary.T2 = [8000.0]
53+
# quandary.update()
54+
# quandary.pcof0 = quandary.popt[:]
55+
# t, pt, qt, infidelity, expectedEnergy, population = quandary.simulate(datadir=datadir, maxcores=8)
56+
# print(f"Fidelity under decoherence = {1.0 - infidelity}")

0 commit comments

Comments
 (0)