<jupyter_start><jupyter_text>GRAPE calculation of control fields for iSWAP implementation <NAME> (<EMAIL>)<jupyter_code>%matplotlib inline
import matplotlib.pyplot as plt
import time
import numpy as np
from qutip import *
from qutip.control import *
T = 1
times = np.linspace(0, T, 100)
U = iswap()
R = 50
H_ops = [#tensor(sigmax(), identity(2)),
         #tensor(sigmay(), identity(2)),
         #tensor(sigmaz(), identity(2)),
         #tensor(identity(2), sigmax()),
         #tensor(identity(2), sigmay()),
         #tensor(identity(2), sigmaz()),
         tensor(sigmax(), sigmax()),
         tensor(sigmay(), sigmay()),
         tensor(sigmaz(), sigmaz())]

H_labels = [#r'$u_{1x}$',
            #r'$u_{1y}$',
            #r'$u_{1z}$',
            #r'$u_{2x}$',
            #r'$u_{2y}$',
            #r'$u_{2z}$',
            r'$u_{xx}$',
            r'$u_{yy}$',
            r'$u_{zz}$',
        ]
H0 = 0 * np.pi * (tensor(sigmaz(), identity(2)) + tensor(identity(2), sigmaz()))<jupyter_output><empty_output><jupyter_text>GRAPE<jupyter_code>from qutip.control.grape import plot_grape_control_fields, _overlap, grape_unitary_adaptive, cy_grape_unitary
from scipy.interpolate import interp1d
from qutip.ui.progressbar import TextProgressBar
u0 = np.array([np.random.rand(len(times)) * (2 * np.pi / T) * 0.01 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*np.pi/T,
                          progress_bar=TextProgressBar())
#result = grape_unitary(U, H0, H_ops, R, times, u_start=u0, eps=2*np.pi/T,
#                       progress_bar=TextProgressBar())<jupyter_output><empty_output><jupyter_text>Plot control fields for iSWAP gate in the presense of single-qubit tunnelling<jupyter_code>plot_grape_control_fields(times, result.u / (2 * np.pi), H_labels, uniform_axes=True);
# compare to the analytical results
np.mean(result.u[-1,0,:]), np.mean(result.u[-1,1,:]), np.pi/(4 * T)<jupyter_output><empty_output><jupyter_text>Fidelity<jupyter_code>U
result.U_f.tidyup(1e-2)
_overlap(U, result.U_f).real<jupyter_output><empty_output><jupyter_text>Test numerical integration of GRAPE pulse<jupyter_code>c_ops = []
U_f_numerical = propagator(result.H_t, times[-1], c_ops, args={})
U_f_numerical
_overlap(U, U_f_numerical).real<jupyter_output><empty_output><jupyter_text>Process tomography  Ideal iSWAP gate<jupyter_code>op_basis = [[qeye(2), sigmax(), sigmay(), sigmaz()]] * 2
op_label = [["i", "x", "y", "z"]] * 2
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)<jupyter_output><empty_output><jupyter_text>iSWAP gate calculated using GRAPE<jupyter_code>fig = plt.figure(figsize=(8,6))

U_ideal = to_super(result.U_f)

chi = qpt(U_ideal, op_basis)

fig = qpt_plot_combined(chi, op_label, fig=fig, threshold=0.001)<jupyter_output><empty_output><jupyter_text>Versions<jupyter_code>from qutip.ipynbtools import version_table

version_table()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16602564102564102, 'fraction_numerical': 0.020833333333333332, 'mean_word_length': 4.811918063314711, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '497979', 'license': 'MIT', 'n_tokens_mistral': 1269, 'n_tokens_neox': 1223, 'n_words': 210, 'path': 'qutip-notebooks-master/examples/control-grape-iswap.ipynb', 'repo_name': 'OliverDudgeon/QSync', 'size': '3138'}