/
5cells.py
456 lines (374 loc) · 18.2 KB
/
5cells.py
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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
# -*- coding: utf-8 -*-
"""Dissipative-Time=4pi/g, Target=|1><1|, 5Cells.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1bO4srVG0chB4DjPsoe94QNmnEDgDp82m
# Optimization of Dissipative Qubit Reset
"""
# NBVAL_IGNORE_OUTPUT
import qutip
import numpy as np
import scipy
import matplotlib
import matplotlib.pylab as plt
import krotov
import math
"""$\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{int}[0]{\text{int}}
\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}}$
This example illustrates an optimization in an *open* quantum system,
where the dynamics is governed by the Liouville-von Neumann equation. Hence,
states are represented by density matrices $\op{\rho}(t)$ and the time-evolution
operator is given by a general dynamical map $\DynMap$.
## Define parameters
The system consists of a qubit with Hamiltonian
$\op{H}_{q}(t) = - \frac{\omega_{q}}{2} \op{\sigma}_{z} - \frac{\epsilon(t)}{2} \op{\sigma}_{z}$,
where $\omega_{q}$ is an energy level splitting that can be dynamically adjusted
by the control $\epsilon(t)$. This qubit couples strongly to another two-level
system (TLS) with Hamiltonian $\op{H}_{t} = - \frac{\omega_{t}}{2} \op{\sigma}_{z}$ with
static energy level splitting $\omega_{t}$. The coupling strength between both
systems is given by $J$ with the interaction Hamiltonian given by $\op{H}_{\int}
= J \op{\sigma}_{x} \otimes \op{\sigma}_{x}$.
The Hamiltonian for the system of qubit and TLS is
$$
\op{H}(t)
= \op{H}_{q}(t) \otimes \identity_{t}
+ \identity_{q} \otimes \op{H}_{t} + \op{H}_{\int}.
$$
In addition, the TLS is embedded in a heat bath with inverse temperature
$\beta$. The TLS couples to the bath with rate $\kappa$. In order to simulate
the dissipation arising from this coupling, we consider the two Lindblad
operators
$$
\begin{split}
\op{L}_{1} &= \sqrt{\kappa (N_{th}+1)} \identity_{q} \otimes \ket{0}\bra{1} \\
\op{L}_{2} &= \sqrt{\kappa N_{th}} \identity_{q} \otimes \ket{1}\bra{0}
\end{split}
$$
with $N_{th} = 1/(e^{\beta \omega_{t}} - 1)$.
"""
omega = 1 # qubit level splitting
g = 0.2*omega # qubit-TLS coupling
gamma = 0.05*omega # TLS decay rate
beta = 1000000000 # inverse bath temperature
T = 4*math.pi/g # final time
nt = 1000 # number of time steps
"""## Define the Liouvillian
The dynamics of the qubit-TLS system state $\op{\rho}(t)$ is governed by the
Liouville-von Neumann equation
$$
\begin{split}
\frac{\partial}{\partial t} \op{\rho}(t)
&= \Liouville(t) \op{\rho}(t) \\
&= - i \left[\op{H}(t), \op{\rho}(t)\right]
+ \sum_{k=1,2} \left(
\op{L}_{k} \op{\rho}(t) \op{L}_{k}^\dagger
- \frac{1}{2}
\op{L}_{k}^\dagger
\op{L}_{k} \op{\rho}(t)
- \frac{1}{2} \op{\rho}(t)
\op{L}_{k}^\dagger
\op{L}_{k}
\right)\,.
\end{split}
$$
"""
qutip.tensor(qutip.qeye(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2))
def liouvillian(omega, g, gamma, beta):
"""Liouvillian for the coupled system of qubit and TLS"""
H0_q = omega*0.5*(-qutip.operators.sigmaz()+qutip.qeye(2))
# drive qubit Hamiltonian
H1_q = -0.5*qutip.operators.sigmax()
# drift TLS Hamiltonian
H0_T = qutip.tensor(omega*0.5*(-qutip.operators.sigmaz()+qutip.qeye(2)), qutip.qeye(2), qutip.qeye(2), qutip.qeye(2), qutip.qeye(2))\
+qutip.tensor(qutip.qeye(2), omega*0.5*(-qutip.operators.sigmaz()+qutip.qeye(2)), qutip.qeye(2), qutip.qeye(2), qutip.qeye(2))\
+qutip.tensor(qutip.qeye(2), qutip.qeye(2), omega*0.5*(-qutip.operators.sigmaz()+qutip.qeye(2)), qutip.qeye(2), qutip.qeye(2))\
+qutip.tensor(qutip.qeye(2), qutip.qeye(2), qutip.qeye(2), omega*0.5*(-qutip.operators.sigmaz()+qutip.qeye(2)), qutip.qeye(2))\
+qutip.tensor(qutip.qeye(2), qutip.qeye(2), qutip.qeye(2), qutip.qeye(2), omega*0.5*(-qutip.operators.sigmaz() + qutip.qeye(2)))
# Lift Hamiltonians to joint system operators
H0 = qutip.tensor(H0_q, qutip.qeye(2), qutip.qeye(2), qutip.qeye(2), qutip.qeye(2), qutip.qeye(2)) + qutip.tensor(qutip.qeye(2), H0_T)
H1 = qutip.tensor(H1_q, qutip.qeye(2), qutip.qeye(2), qutip.qeye(2), qutip.qeye(2), qutip.qeye(2))
# qubit-TLS interaction
H_int = g*(qutip.tensor(qutip.destroy(2),qutip.create(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2))\
+qutip.tensor(qutip.create(2),qutip.destroy(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2))\
+qutip.tensor(qutip.destroy(2),qutip.qeye(2),qutip.create(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2))\
+qutip.tensor(qutip.create(2),qutip.qeye(2),qutip.destroy(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2))\
+qutip.tensor(qutip.destroy(2),qutip.qeye(2),qutip.qeye(2),qutip.create(2),qutip.qeye(2),qutip.qeye(2))\
+qutip.tensor(qutip.create(2),qutip.qeye(2),qutip.qeye(2),qutip.destroy(2),qutip.qeye(2),qutip.qeye(2))\
+qutip.tensor(qutip.destroy(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2),qutip.create(2),qutip.qeye(2))\
+qutip.tensor(qutip.create(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2),qutip.destroy(2),qutip.qeye(2))\
+qutip.tensor(qutip.destroy(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2),qutip.create(2))\
+qutip.tensor(qutip.create(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2),qutip.destroy(2)))
# convert Hamiltonians to QuTiP objects
H0 = qutip.Qobj(H0 + H_int)
H1 = qutip.Qobj(H1)
# Define Lindblad operators
N = 1.0 / (np.exp(beta * omega) - 1.0)
# Cooling on TLS
L1 = np.sqrt(gamma * (N + 1)) * qutip.tensor(qutip.destroy(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2))
# Heating on TLS
L2 = np.sqrt(gamma * N) *qutip.tensor(qutip.create(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2),qutip.qeye(2))
# convert Lindblad operators to QuTiP objects
L1 = qutip.Qobj(L1)
L2 = qutip.Qobj(L2)
# generate the Liouvillian
L0 = qutip.liouvillian(H=H0, c_ops=[L1, L2])
L1 = qutip.liouvillian(H=H1)
# Shift the qubit and TLS into resonance by default
eps0 = lambda t, args: 1
return [L0, [L1, eps0]]
L = liouvillian(omega, g, gamma, beta)
"""## Define the optimization target
The initial state of qubit and TLS are assumed to be in thermal equilibrium with
the heat bath (although only the TLS is directly interacting with the bath).
Both states are given by
$$
\op{\rho}_{\alpha}^{th} =
\frac{e^{x_{\alpha}} \ket{0}\bra{0} + e^{-x_{\alpha}} \ket{1}\bra{1}}{2
\cosh(x_{\alpha})},
\qquad
x_{\alpha} = \frac{\omega_{\alpha} \beta}{2},
$$
with $\alpha = q,t$. The initial state of the bipartite system
of qubit and TLS is given by the thermal state
$\op{\rho}_{th} = \op{\rho}_{q}^{th} \otimes \op{\rho}_{t}^{th}$.
"""
rho_th = qutip.Qobj(qutip.tensor(qutip.basis(2,0)*qutip.basis(2,0).dag(), qutip.basis(2,0)*qutip.basis(2,0).dag(),qutip.basis(2,0)*qutip.basis(2,0).dag(),qutip.basis(2,0)*qutip.basis(2,0).dag(),qutip.basis(2,0)*qutip.basis(2,0).dag(),qutip.basis(2,0)*qutip.basis(2,0).dag()))
print(rho_th)
"""The target state is (temporarily) the ground state of the bipartite system,
i.e., $\op{\rho}_{\tgt} = \ket{00}\bra{00}$. Note that in the end we will only
optimize the reduced state of the qubit.
"""
rho_q_trg = qutip.Qobj(np.diag([1, 0]))
rho_T_trg = qutip.tensor(qutip.Qobj(np.diag([0, 1])),qutip.Qobj(np.diag([0,1])),qutip.Qobj(np.diag([0,1])),qutip.Qobj(np.diag([0,1])),qutip.Qobj(np.diag([0,1])))
rho_trg = qutip.tensor(rho_q_trg, rho_T_trg)
rho_trg = qutip.Qobj(rho_trg)
print(rho_trg)
"""Next, the list of `objectives` is defined, which contains the initial and target
state and the Liouvillian $\Liouville(t)$ that determines the system dynamics.
"""
objectives = [krotov.Objective(initial_state=rho_th, target=rho_trg, H=L)]
"""In the following, we define the shape function $S(t)$, which we use in order to
ensure a smooth switch on and off in the beginning and end. Note that at times
$t$ where $S(t)$ vanishes, the updates of the field is suppressed.
"""
def S(t):
"""Shape function for the field update"""
return krotov.shapes.flattop(
t, t_start=0, t_stop=T, t_rise=0.005 * T, t_fall=0.005 * T, func='sinsq'
)
"""We re-use this function to also shape the guess control $\epsilon_{0}(t)$ to be
zero at $t=0$ and $t=T$. This is on top of the originally defined constant
value shifting the qubit and TLS into resonance.
"""
def shape_field(eps0):
"""Applies the shape function S(t) to the guess field"""
eps0_shaped = lambda t, args: eps0(t, args) * S(t)
return eps0_shaped
L[1][1] = shape_field(L[1][1])
"""At last, before heading to the actual optimization below, we assign the shape
function $S(t)$ to the OCT parameters of the control and choose `lambda_a`, a
numerical parameter that controls the field update magnitude in each iteration.
"""
pulse_options = {L[1][1]: dict(lambda_a=1, update_shape=S)}
"""## Simulate the dynamics of the guess field
"""
tlist = np.linspace(0, T, nt)
"""The following plot shows the guess field $\epsilon_{0}(t)$ as a constant that
puts qubit and TLS into resonance, but with a smooth switch-on and switch-off.
We solve the equation of motion for this guess field, storing the expectation
values for the population in the bipartite levels:
The population dynamics of qubit and TLS ground state show that
both are oscillating and especially the qubit's ground state population reaches
a maximal value at intermediate times $t < T$. This maximum is indeed the
maximum that is physically possible. It corresponds to a perfect swap of
the initial qubit and TLS purities. However, we want to reach this maximum at
final time $T$ (not before), so the guess control is not yet working as desired.
## Optimize
Our optimization target is the ground state $\ket{\Psi_{q}^{\tgt}}
= \ket{0}$ of the qubit, irrespective of the state of the TLS. Thus, our
optimization functional reads
$$
J_T = 1 -
\Braket{\Psi_{q}^{\tgt}}{\tr_{t}\{\op{\rho}(T)\} \,|\; \Psi_{q}^{\tgt}}\,,
$$
and we first define `print_qubit_error`, which prints out the
above functional after each iteration.
"""
def print_qubit_error(**args):
"""Utility function writing the qubit error to screen"""
taus = []
for state_T in args['fw_states_T']:
taus.append(np.real(np.trace(np.dot(state_T,rho_trg))))
J_T = 1 - np.average(taus)
print(" qubit error: %.1e" % J_T)
return J_T
"""In order to minimize the above functional, we need to provide the correct
`chi_constructor` for the Krotov optimization. This is the only place where the
functional (implicitly) enters the optimization.
Given our bipartite system and choice of $J_T$, the equation for
$\op{\chi}(T)$ reads
$$
\op{\chi}(T)
=
\frac{1}{2} \ket{\Psi_{q}^{\tgt}} \bra{\Psi_{q}^{\tgt}} \otimes \op{1}_{2}
=
\frac{1}{2} \ket{00}\bra{00} + \frac{1}{2} \ket{01}\bra{01}.
$$
"""
def chis_qubit(fw_states_T, objectives, tau_vals):
"""Calculate chis for the chosen functional"""
chis = []
for state_i_T in fw_states_T:
chi_i = qutip.Qobj(qutip.tensor(qutip.identity(2),rho_T_trg))
chis.append(chi_i)
return chis
"""We now carry out the optimization for five iterations."""
def plot_iterations(opt_result):
"""Plot the control fields in population dynamics over all iterations.
This depends on ``store_all_pulses=True`` in the call to
`optimize_pulses`.
"""
fig, [ax_ctr,ax] = plt.subplots(nrows=2, figsize=(4, 5))
n_iters = len(opt_result.iters)
EEnergy=np.zeros(nt)
for (iteration, pulses) in zip(opt_result.iters, opt_result.all_pulses):
controls = [
krotov.conversions.pulse_onto_tlist(pulse)
for pulse in pulses
]
objectives = opt_result.objectives_with_controls(controls)
dynamics = objectives[0].mesolve(
opt_result.tlist, e_ops=[]
)
if iteration == 0:
ls = '--' # dashed
alpha = 1 # full opacity
ctr_label = 'guess'
pop_labels = ['0 (guess)', '1 (guess)']
elif iteration == opt_result.iters[-1]:
ls = '-' # solid
alpha = 1 # full opacity
ctr_label = 'optimized'
pop_labels = ['0 (optimized)', '1 (optimized)']
else:
ls = '-' # solid
alpha = 0.5 * float(iteration) / float(n_iters) # max 50%
ctr_label = None
pop_labels = [None, None]
ax_ctr.plot(
dynamics.times,
controls[0],
label=ctr_label,
color='black',
ls=ls,
alpha=alpha,
)
EField=np.transpose(np.array(opt_result.optimized_controls))
EEnergy[0]=(np.square(EField[0]))*(T/nt)
a=0
for i in range (1,nt):
a+=np.square(EField[i-1])
EEnergy[i]=(np.square(EField[i])+a)*(T/nt)
ax.plot(tlist,np.transpose(EEnergy))
plt.legend()
fig.savefig('ElectricField5cells.png')
# NBVAL_IGNORE_OUTPUT
# the DensityMatrixODEPropagator is not sufficiently exact to guarantee that
# you won't get slightly different results in the optimization when
# running this on different systems
opt_result = krotov.optimize_pulses(
objectives,
pulse_options,
tlist,
iter_stop=20000,
propagator=krotov.propagators.DensityMatrixODEPropagator(
atol=1e-10, rtol=1e-8
),
chi_constructor=chis_qubit,
info_hook=krotov.info_hooks.chain(
krotov.info_hooks.print_debug_information, print_qubit_error
),
check_convergence=krotov.convergence.Or(
krotov.convergence.value_below('5e-3', name='J_T'),
krotov.convergence.check_monotonic_error,
),
store_all_pulses=True,
)
plot_iterations(opt_result)
opt_result
from numpy import linalg as npla
def eigenvalues(A):
eigenValues, eigenVectors = npla.eig(A)
idx = np.argsort(eigenValues)
eigenValues = eigenValues[idx]
eigenVectors = eigenVectors[:,idx]
return (eigenValues)
optimized_dynamics = opt_result.optimized_objectives[0].mesolve(
tlist, e_ops=[]
)
Ergotropy=np.zeros(nt)
Energy=np.zeros(nt)
time=np.zeros(nt)
for i in range(0,nt):
FinalStateB = np.trace(np.array(optimized_dynamics.states[i]).reshape(2,2,2,2,2,2,2,2,2,2,2,2), axis1=0, axis2=6)
FinalStateCell1=np.trace(np.array(FinalStateB).reshape(2,16,2,16), axis1=1, axis2=3)
PreFinalStateCell2=np.trace(np.array(FinalStateB).reshape(2,2,8,2,2,8), axis1=2, axis2=5)
FinalStateCell2=np.trace(np.array(PreFinalStateCell2).reshape(2,2,2,2), axis1=0, axis2=2)
PreFinalStateCell3=np.trace(np.array(FinalStateB).reshape(4,2,2,2,4,2,2,2), axis1=0, axis2=4)
FinalStateCell3=np.trace(np.array(PreFinalStateCell3).reshape(2,4,2,4), axis1=1, axis2=3)
PreFinalStateCell4=np.trace(np.array(FinalStateB).reshape(8,2,2,8,2,2), axis1=0, axis2=3)
FinalStateCell4=np.trace(np.array(PreFinalStateCell4).reshape(2,2,2,2), axis1=1, axis2=3)
FinalStateCell5=np.trace(np.array(FinalStateB).reshape(16,2,16,2), axis1=0, axis2=2)
Rho_fCell1=eigenvalues(FinalStateCell1)[1]*np.array([[1, 0], [0, 0]])+eigenvalues(FinalStateCell1)[0]*np.array([[0, 0], [0, 1]])
Rho_fCell2=eigenvalues(FinalStateCell2)[1]*np.array([[1, 0], [0, 0]])+eigenvalues(FinalStateCell2)[0]*np.array([[0, 0], [0, 1]])
Rho_fCell3=eigenvalues(FinalStateCell3)[1]*np.array([[1, 0], [0, 0]])+eigenvalues(FinalStateCell3)[0]*np.array([[0, 0], [0, 1]])
Rho_fCell4=eigenvalues(FinalStateCell4)[1]*np.array([[1, 0], [0, 0]])+eigenvalues(FinalStateCell4)[0]*np.array([[0, 0], [0, 1]])
Rho_fCell5=eigenvalues(FinalStateCell5)[1]*np.array([[1, 0], [0, 0]])+eigenvalues(FinalStateCell5)[0]*np.array([[0, 0], [0, 1]])
Energy[i]=np.real(np.matrix.trace(omega*np.dot(np.array([[0, 0], [0, 1]]),FinalStateCell5)))+np.real(np.matrix.trace(omega*np.dot(np.array([[0, 0], [0, 1]]),FinalStateCell4)))+np.real(np.matrix.trace(omega*np.dot(np.array([[0, 0], [0, 1]]),FinalStateCell3)))+np.real(np.matrix.trace(omega*np.dot(np.array([[0, 0], [0, 1]]),FinalStateCell1)))+np.real(np.matrix.trace(omega*np.dot(np.array([[0, 0], [0, 1]]),FinalStateCell2)))
Ergotropy[i]=-np.real(np.matrix.trace(omega*np.dot(np.array([[0, 0], [0, 1]]),(Rho_fCell5-FinalStateCell5))))-np.real(np.matrix.trace(omega*np.dot(np.array([[0, 0], [0, 1]]),(Rho_fCell4-FinalStateCell4))))-np.real(np.matrix.trace(omega*np.dot(np.array([[0, 0], [0, 1]]),(Rho_fCell3-FinalStateCell3))))-np.real(np.matrix.trace(omega*np.dot(np.array([[0, 0], [0, 1]]),(Rho_fCell1-FinalStateCell1))))-np.real(np.matrix.trace(omega*np.dot(np.array([[0, 0], [0, 1]]),(Rho_fCell2-FinalStateCell2))))
time[i]=(T/nt)*i
fig2, ax1 =plt.subplots()
ax1.plot(time,Energy,label='Energy')
ax1.plot(time,Ergotropy,label='Ergotropy')
ax1.set_xlabel("time")
ax1.set_ylabel("Energy, Ergotropy")
ax1.legend()
fig2.savefig('EnergyvsErgotropy5cells.png')
"""## Simulate the dynamics of the optimized field
The plot of the optimized field shows that the optimization slightly shifts
the field such that qubit and TLS are no longer perfectly in resonance.
This slight shift of qubit and TLS out of resonance delays the population
oscillations between qubit and TLS ground state such that the qubit ground
state is maximally populated at final time $T$.
"""
file1 = open("Percentage5cells.txt","w")
file1.write(repr(Ergotropy[nt-1]/Energy[nt-1]))
file1.close()