Robert Johansson (robert@riken.jp)
%matplotlib inline
import matplotlib.pyplot as plt
import time
import numpy as np
from numpy import pi
from qutip import *
from qutip.control import *
T = 1
times = np.linspace(0, T, 100)
theta, phi = np.random.rand(2)
# target unitary transformation (random single qubit rotation)
U = rz(phi) * rx(theta); U
R = 150
H_ops = [sigmax(), sigmay(), sigmaz()]
H_labels = [r'$u_{x}$',
r'$u_{y}$',
r'$u_{z}$',
]
H0 = 0 * pi * sigmaz()
from qutip.control.grape import plot_grape_control_fields, _overlap
from qutip.control.cy_grape import cy_overlap
from qutip.control.grape import cy_grape_unitary, grape_unitary_adaptive
from scipy.interpolate import interp1d
from qutip.ui.progressbar import TextProgressBar
u0 = np.array([np.random.rand(len(times)) * 2 * pi * 0.005 for _ in range(len(H_ops))])
u0 = [np.convolve(np.ones(10)/10, u0[idx,:], mode='same') for idx in range(len(H_ops))]
result = cy_grape_unitary(U, H0, H_ops, R, times, u_start=u0, eps=2*pi/T, phase_sensitive=False,
progress_bar=TextProgressBar())
10.0%. Run time: 7.45s. Est. time left: 00:00:01:07 20.0%. Run time: 14.05s. Est. time left: 00:00:00:56 30.0%. Run time: 21.91s. Est. time left: 00:00:00:51 40.0%. Run time: 27.99s. Est. time left: 00:00:00:41 50.0%. Run time: 34.34s. Est. time left: 00:00:00:34 60.0%. Run time: 40.20s. Est. time left: 00:00:00:26 70.0%. Run time: 46.05s. Est. time left: 00:00:00:19 80.0%. Run time: 52.30s. Est. time left: 00:00:00:13 90.0%. Run time: 58.29s. Est. time left: 00:00:00:06 Total run time: 63.70s
plot_grape_control_fields(times, result.u[:,:,:] / (2 * pi), H_labels, uniform_axes=True);
# target unitary
U
# unitary from grape pulse
result.U_f
# target / result overlap
_overlap(U, result.U_f).real, abs(_overlap(U, result.U_f))**2
(0.9999999999999987, 0.9999999999999973)
c_ops = []
U_f_numerical = propagator(result.H_t, times[-1], c_ops, args={})
U_f_numerical
_overlap(U, U_f_numerical)
(0.9999289415682254+0j)
psi0 = basis(2, 0)
e_ops = [sigmax(), sigmay(), sigmaz()]
me_result = mesolve(result.H_t, psi0, times, c_ops, e_ops)
b = Bloch()
b.add_points(me_result.expect)
b.add_states(psi0)
b.add_states(U * psi0)
b.render()
op_basis = [[qeye(2), sigmax(), sigmay(), sigmaz()]]
op_label = [["i", "x", "y", "z"]]
fig = plt.figure(figsize=(8,6))
U_ideal = spre(U) * spost(U.dag())
chi = qpt(U_ideal, op_basis)
fig = qpt_plot_combined(chi, op_label, fig=fig, threshold=0.001)
fig = plt.figure(figsize=(8,6))
U_ideal = spre(result.U_f) * spost(result.U_f.dag())
chi = qpt(U_ideal, op_basis)
fig = qpt_plot_combined(chi, op_label, fig=fig, threshold=0.001)
from qutip.ipynbtools import version_table
version_table()
Software | Version |
---|---|
QuTiP | 4.2.0 |
Numpy | 1.13.1 |
SciPy | 0.19.1 |
matplotlib | 2.0.2 |
Cython | 0.25.2 |
Number of CPUs | 2 |
BLAS Info | INTEL MKL |
IPython | 6.1.0 |
Python | 3.6.1 |Anaconda custom (x86_64)| (default, May 11 2017, 13:04:09) [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] |
OS | posix [darwin] |
Wed Jul 19 22:14:32 2017 MDT |