-
Notifications
You must be signed in to change notification settings - Fork 0
/
perfect_entanglers.jl
291 lines (220 loc) · 8.27 KB
/
perfect_entanglers.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
# -*- coding: utf-8 -*-
# ---
# jupyter:
# jupytext:
# formats: ipynb,jl:light
# text_representation:
# extension: .jl
# format_name: light
# format_version: '1.5'
# jupytext_version: 1.14.5
# kernelspec:
# display_name: Julia 1.9.2
# language: julia
# name: julia-1.9
# ---
# # Example: Optimization of a Perfectly Entangling Quantum gate
# $
# \newcommand{tr}[0]{\operatorname{tr}}
# \newcommand{diag}[0]{\operatorname{diag}}
# \newcommand{abs}[0]{\operatorname{abs}}
# \newcommand{pop}[0]{\operatorname{pop}}
# \newcommand{aux}[0]{\text{aux}}
# \newcommand{opt}[0]{\text{opt}}
# \newcommand{tgt}[0]{\text{tgt}}
# \newcommand{init}[0]{\text{init}}
# \newcommand{lab}[0]{\text{lab}}
# \newcommand{rwa}[0]{\text{rwa}}
# \newcommand{bra}[1]{\langle#1\vert}
# \newcommand{ket}[1]{\vert#1\rangle}
# \newcommand{Bra}[1]{\left\langle#1\right\vert}
# \newcommand{Ket}[1]{\left\vert#1\right\rangle}
# \newcommand{Braket}[2]{\left\langle #1\vphantom{#2}\mid{#2}\vphantom{#1}\right\rangle}
# \newcommand{op}[1]{\hat{#1}}
# \newcommand{Op}[1]{\hat{#1}}
# \newcommand{dd}[0]{\,\text{d}}
# \newcommand{Liouville}[0]{\mathcal{L}}
# \newcommand{DynMap}[0]{\mathcal{E}}
# \newcommand{identity}[0]{\mathbf{1}}
# \newcommand{Norm}[1]{\lVert#1\rVert}
# \newcommand{Abs}[1]{\left\vert#1\right\vert}
# \newcommand{avg}[1]{\langle#1\rangle}
# \newcommand{Avg}[1]{\left\langle#1\right\rangle}
# \newcommand{AbsSq}[1]{\left\vert#1\right\vert^2}
# \newcommand{Re}[0]{\operatorname{Re}}
# \newcommand{Im}[0]{\operatorname{Im}}
# $
# ## Two Transmon qubits with a shared transmission line
# ![Two transmons with a shared transmission line](transmon.png)
# ### Hamiltonian
# The energies system energies are on the order of GHz (angular frequency; the factor
# 2π is implicit), with dynamics on the order of ns
const GHz = 2π
const MHz = 0.001GHz
const ns = 1.0
const μs = 1000ns;
⊗ = kron;
const 𝕚 = 1im;
# We truncated the Hamiltonian to $N$ levels
const N = 6; # levels per transmon
# So the dimension of the total Hilbert space is $N^2 = 36$
# The Hamiltonian and parameters are taken from
# [Goerz *et al.*, Phys. Rev. A 91, 062307 (2015); Table 1](https://michaelgoerz.net/#GoerzPRA2015).
# +
using LinearAlgebra
using SparseArrays
using QuantumControl: hamiltonian
function transmon_hamiltonian(;
Ωre, Ωim, N=N, ω₁=4.380GHz, ω₂=4.614GHz, ωd=4.498GHz, α₁=-210MHz,
α₂=-215MHz, J=-3MHz, λ=1.03,
)
𝟙 = SparseMatrixCSC{ComplexF64,Int64}(sparse(I, N, N))
b̂₁ = spdiagm(1 => complex.(sqrt.(collect(1:N-1)))) ⊗ 𝟙
b̂₂ = 𝟙 ⊗ spdiagm(1 => complex.(sqrt.(collect(1:N-1))))
b̂₁⁺ = sparse(b̂₁'); b̂₂⁺ = sparse(b̂₂')
n̂₁ = sparse(b̂₁' * b̂₁); n̂₂ = sparse(b̂₂' * b̂₂)
n̂₁² = sparse(n̂₁ * n̂₁); n̂₂² = sparse(n̂₂ * n̂₂)
b̂₁⁺_b̂₂ = sparse(b̂₁' * b̂₂); b̂₁_b̂₂⁺ = sparse(b̂₁ * b̂₂')
# rotating frame: ω₁, ω₂ → detuning; driving field Ω ∈ ℂ
ω̃₁ = ω₁ - ωd; ω̃₂ = ω₂ - ωd
Ĥ₀ = sparse(
(ω̃₁ - α₁ / 2) * n̂₁ +
(α₁ / 2) * n̂₁² +
(ω̃₂ - α₂ / 2) * n̂₂ +
(α₂ / 2) * n̂₂² +
J * (b̂₁⁺_b̂₂ + b̂₁_b̂₂⁺)
)
Ĥ₁re = sparse((1 / 2) * (b̂₁ + b̂₁⁺ + λ * b̂₂ + λ * b̂₂⁺))
Ĥ₁im = sparse((𝕚 / 2) * (b̂₁⁺ - b̂₁ + λ * b̂₂⁺ - λ * b̂₂))
return hamiltonian(Ĥ₀, (Ĥ₁re, Ωre), (Ĥ₁im, Ωim))
end;
# -
# ...
# ### Initial driving field
# +
using QuantumControl.Amplitudes: ShapedAmplitude
using QuantumControl.Shapes: flattop
function guess_amplitudes(; T=400ns, E₀=35MHz, dt=0.1ns, t_rise=15ns)
tlist = collect(range(0, T, step=dt))
shape(t) = flattop(t, T=T, t_rise=t_rise)
Ωre = ShapedAmplitude(t -> E₀, tlist; shape)
Ωim = ShapedAmplitude(t -> 0.0, tlist; shape)
return tlist, Ωre, Ωim
end
tlist, Ωre_guess, Ωim_guess = guess_amplitudes();
# -
include("includes/plot_complex_pulse.jl")
plot_complex_pulse(tlist, Array(Ωre_guess))
H = transmon_hamiltonian(Ωre=Ωre_guess, Ωim=Ωim_guess);
# ### Logical basis
# +
function ket(i::Int64; N=N)
Ψ = zeros(ComplexF64, N)
Ψ[i+1] = 1
return Ψ
end
function ket(indices::Int64...; N=N)
Ψ = ket(indices[1]; N=N)
for i in indices[2:end]
Ψ = Ψ ⊗ ket(i; N=N)
end
return Ψ
end
function ket(label::AbstractString; N=N)
indices = [parse(Int64, digit) for digit in label]
return ket(indices...; N=N)
end;
# -
basis = [ket("00"), ket("01"), ket("10"), ket("11")];
ket("01")
# ## Dynamics of the guess field
using QuantumControl: propagate
# ...
logical_overlap = [(Ψ -> Ψ ⋅ ϕ) for ϕ ∈ basis];
dyn00 = propagate(ket("00"), H , tlist; observables=logical_overlap, storage=true)
dyn01 = propagate(ket("01"), H , tlist; observables=logical_overlap, storage=true)
dyn10 = propagate(ket("10"), H , tlist; observables=logical_overlap, storage=true)
dyn11 = propagate(ket("11"), H , tlist; observables=logical_overlap, storage=true)
# We concatenate the columns to get the $4 \times 4$ matrix U that is that "gate" in the two-qubit subspace at each point in time:
U_of_t = [[dyn00[:,n] dyn01[:,n] dyn10[:,n] dyn11[:,n]] for n = 1:length(tlist)];
using TwoQubitWeylChamber: gate_concurrence, unitarity
# The `gate_concurrence` is the amount of entanglement that can be generated by applying the gate to a separable input state.
#
# A well-known perfectly entangling gate is the controlled-NOT gate:
CNOT = [
1 0 0 0
0 1 0 0
0 0 0 1
0 0 1 0
];
gate_concurrence(CNOT)
plot(tlist, gate_concurrence.(U_of_t), xlabel="time (ns)", ylabel="gate concurrence", label="", ylim=(0, 1))
gate_concurrence(U_of_t[end])
# Our guess pulse does not result in a perfectly entangling gate.
#
# Moreover, there is loss of population from the logical subspace, i.e., the $4 \times 4$ matrices in `U_of_t` are not unitary:
plot(tlist, 1 .- unitarity.(U_of_t), xlabel="time (ns)", ylabel="loss from subspace", label="")
1 - unitarity(U_of_t[end])
# ## Maximization of Gate Concurrence
# +
using QuantumControl: Objective
objectives = [Objective(; initial_state=Ψ, generator=H) for Ψ ∈ basis];
# -
J_T_C = U -> 0.5 * (1 - gate_concurrence(U)) + 0.5 * (1 - unitarity(U));
J_T_C(U_of_t[end])
# +
using QuantumControl.Functionals: gate_functional
J_T = gate_functional(J_T_C);
# -
# $J_T$ is now a function of the propagated states $\ket{\Psi_{00}(T)}$, $\ket{\Psi_{01}(T)}$, $\ket{\Psi_{10}(T)}$, $\ket{\Psi_{11}(T)}$.
#
# ...
# +
using QuantumControl.Functionals: make_gate_chi
chi = make_gate_chi(J_T_C, objectives)
# +
using QuantumControl: ControlProblem
problem = ControlProblem(;
objectives, tlist, J_T, chi,
check_convergence=res -> begin
(
(res.J_T <= 1e-3) &&
(res.converged = true) &&
(res.message = "Found a perfect entangler")
)
end,
use_threads=true,
);
# +
using QuantumControl: optimize
res = optimize(problem; method=:GRAPE)
# +
ϵ_opt = res.optimized_controls[1] + 𝕚 * res.optimized_controls[2]
Ω_opt = ϵ_opt .* discretize(Ωre_guess.shape, tlist)
plot_complex_pulse(tlist, Ω_opt)
# -
# ## Dynamics of the optimized field
# +
using QuantumControl.Controls: get_controls
ϵ_re_guess, ϵ_im_guess = get_controls(H);
# +
using QuantumControl.Controls: substitute
H_opt = substitute(
H,
IdDict(
ϵ_re_guess => res.optimized_controls[1],
ϵ_im_guess => res.optimized_controls[2]
)
);
# -
dyn00_opt = propagate(ket("00"), H_opt , tlist; observables=logical_overlap, storage=true)
dyn01_opt = propagate(ket("01"), H_opt , tlist; observables=logical_overlap, storage=true)
dyn10_opt = propagate(ket("10"), H_opt , tlist; observables=logical_overlap, storage=true)
dyn11_opt = propagate(ket("11"), H_opt , tlist; observables=logical_overlap, storage=true)
U_opt_of_t = [[dyn00_opt[:,n] dyn01_opt[:,n] dyn10_opt[:,n] dyn11_opt[:,n]] for n = 1:length(tlist)];
plot(tlist, gate_concurrence.(U_opt_of_t), xlabel="time (ns)", ylabel="gate concurrence", label="")
plot!(tlist, gate_concurrence.(U_of_t), label="guess")
gate_concurrence(U_opt_of_t[end])
plot(tlist, 1 .- unitarity.(U_opt_of_t), xlabel="time (ns)", ylabel="loss from subspace", label="")
plot!(tlist, 1 .- unitarity.(U_of_t), label="guess")
1 - unitarity(U_opt_of_t[end])