#!/usr/bin/env python # coding: utf-8 # # Tutorial # In[1]: # NBVAL_IGNORE_OUTPUT get_ipython().run_line_magic('load_ext', 'watermark') import numpy as np import qutip import matplotlib import matplotlib.pylab as plt import weylchamber from weylchamber.visualize import WeylChamber get_ipython().run_line_magic('watermark', '-v --iversions') # $\newcommand{Re}[0]{\operatorname{Re}} # \newcommand{Im}[0]{\operatorname{Im}} # \newcommand{dd}[0]{\,\text{d}} # \newcommand{abs}[0]{\operatorname{abs}}$ # Every two-qubit gate is associated with a point in the "Weyl-chamber" that may be visualized in three dimensions as the following polyhedron: # In[2]: WeylChamber().plot() # Note: if you run this interactively, and switch to an interactive matplotlib backend, e.g. # # %matplotlib tk # # you will be able to rotate the 3D plot to get a better intuition. # Consider the following common two-qubit gates: # In[3]: IDENTITY = qutip.gates.identity([2,2]) IDENTITY # In[4]: CNOT = qutip.gates.cnot() CNOT # In[5]: CPHASE = qutip.gates.cphase(np.pi) CPHASE # In[6]: BGATE = qutip.gates.berkeley() BGATE # In[7]: iSWAP = qutip.gates.iswap() iSWAP # In[8]: sqrtISWAP = qutip.gates.sqrtiswap() sqrtISWAP # In[9]: sqrtSWAP = qutip.gates.sqrtswap() sqrtSWAP # In[10]: MGATE = weylchamber.canonical_gate(3/4, 1/4, 0) MGATE # All of these gates are situatated at special points in the Weyl chamber. We can print their Weyl chamber coordinates and add a point in the graphical representation # In[11]: w = WeylChamber(); list_of_gates = [ ('Identity', IDENTITY), ('CNOT', CNOT), ('CPHASE', CPHASE), ('BGATE', BGATE), ('iSWAP', iSWAP), ('sqrtISWAP', sqrtISWAP), ('sqrtSWAP', sqrtSWAP), ('MGATE', MGATE)] print("Weyl Chamber Coordinates") print("----------------------------------") for (name, gate) in list_of_gates: c1, c2, c3 = weylchamber.c1c2c3(gate) print("%10s: \t%.2fπ %.2fπ %.2fπ" % (name, c1, c2, c3)) w.add_point(c1, c2, c3) w.plot() # The gates locally equivalent to the controlled-phase gates are on an the axis 0 - A1 in the Weyl chamber: # In[12]: w.scatter(*zip(*[ weylchamber.c1c2c3(qutip.gates.cphase(phase)) for phase in np.linspace(0, 2*np.pi, 20)])) # In[13]: w.plot() # The Weyl chamber coordinates $(c_1, c_2, c_3)$ are closely associated with the *local invariants* $(g_1, g_2, g_3)$ # In[14]: print("Local Invariants") print("----------------------------------") for (name, gate) in list_of_gates: g1, g2, g3 = weylchamber.g1g2g3(gate) print("%10s: \t%5.2f %5.2f %5.2f" % (name, g1, g2, g3)) # This shows that the MGATE and $\sqrt{\text{iSWAP}}$ are actually locally equivalent, despite being different Weyl chamber coordinates (M and Q, respectively)