Home | Algorithms | Commercialization | Data Science | Information Theories | Quantum Theories | Lab | Linear Algebra |
<< Wavefunctions and Relativity | Controlled Operations as an Eigenvalue >> |
$\require{cancel} \newcommand{\Ket}[1]{\left|{#1}\right\rangle} \newcommand{\Bra}[1]{\left\langle{#1}\right|} \newcommand{\Braket}[1]{\left\langle{#1}\right\rangle} \newcommand{\Rsr}[1]{\frac{1}{\sqrt{#1}}} \newcommand{\RSR}[1]{1/\sqrt{#1}} \newcommand{\Verti}{\rvert} \newcommand{\HAT}[1]{\hat{\,#1~}} \DeclareMathOperator{\Tr}{Tr}$
First created in September 2018
The Controlled-$X$ (or CNOT) gate is foundmental, especially in creating entanglement. This article is to explore other controlled gates like controlled-$Z~(cZ)$ and controlled-$Y~(cY)$, and the general form of controlled gates, i.e. $cV$.
$cV=\begin{bmatrix}I&0\\0&V\end{bmatrix}.~~$ For $\Ket{kq} =\Ket{k}\otimes\Ket{q} =\begin{bmatrix}k_0\Ket q\\k_1\Ket q\end{bmatrix} =\begin{bmatrix}k_0~q_0\\k_0~q_1\\k_1~q_0\\k_1~q_1\end{bmatrix} .$
$cV\Ket{kq} =\begin{bmatrix} k_0~I\Ket q\\ k_1~V\Ket q\\ \end{bmatrix} =\left\{\begin{matrix} I\Ket q\quad\text{when }\Ket k=\Ket0,\text{ i.e. }k_0=1,k_1=0\\ V\Ket q\quad\text{when }\Ket k=\Ket1,\text{ i.e. }k_0=0,k_1=1\\ \end{matrix}\right.~~ .$
Note: In this context, the control bit is the MSB (the left qubit), so $cX\Ket{10}=\Ket{11}.$
A quantum logical gate can be taken as rotation on the Bloch Sphere. Generally, if $V$ is a gate that rotates about axis $\Ket v$, a controlled-$V$ gate ($cV$) can be implemented by by transforming $\Ket v$ to $\Ket+$, controlled-rotating about the $X$-axis, then reverse the transformation from $\Ket+$ back to $\Ket v$.
For example, to rotate about $Z$, the transformation from $Z$ to $X$ is $H$, so $HXH=Z$. Likewise, to rotate about $Y$, the transformation to $X$ is $S^\dagger$, so $SXS^\dagger=Y$.
If we control the middle $X$ by $cX$, then the corresponding controlled gate can be achieved.
For example, $cZ=(I\otimes H)~cX~(I\otimes H),~~ cY=(I\otimes S)~cX~(I\otimes S^\dagger)~~\text{and}~~ cX=(I\otimes I)~cX~(I\otimes I) .~~$ (The last is trivial.)
Notes:
The control is on the left, where the $I$ is.
$I\otimes V=\begin{bmatrix}V&0\\0&V\end{bmatrix}\ne cV.$
An exercise here to do a $cH$. The rotation axis of $H$ is $\left[\Rsr2,\Rsr2\right]$. To rotate it to $X$, we can use $THS$. So $cH=(I\otimes S^\dagger HT^\dagger)~cX~(I\otimes THS).$
$Q=(I\otimes S^\dagger HT^\dagger)~cX~(I\otimes THS)\\ =\begin{bmatrix}[S^\dagger HT^\dagger]&0\\0&[S^\dagger HT^\dagger]\end{bmatrix} \begin{bmatrix}I&0\\0&X\end{bmatrix} \begin{bmatrix}[THS]&0\\0&[THS]\end{bmatrix}\\ =\begin{bmatrix}[S^\dagger HT^\dagger]~I~[THS]&0\\0&[S^\dagger HT^\dagger]~X~[THS]\end{bmatrix} .$
$[S^\dagger HT^\dagger]~I~[THS]=I.~~$ Applyig $[S^\dagger HT^\dagger]~X~[THS]$ to $\Ket0$ will result in $\Ket+$, and applying it to $\Ket 1$ will get $\Ket-$. It is an $H$.
$\therefore Q=\begin{bmatrix}I&0\\0&H\end{bmatrix}=cH.$
# Preamble
import numpy as np
import math
import matplotlib.pyplot as plt
from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister, execute
from qiskit.tools.visualization import plot_histogram, plot_state, circuit_drawer
shots = 1024
def run_job(qc_run, shots=shots):
job = execute(qc_run, backend = 'local_qasm_simulator', shots=shots)
result = job.result()
data = result.get_counts(qc_run)
for i in range(8):
dataIndex = str(bin(i+8))[-3:]
try:
p = data[dataIndex]/shots
print("P%s=%.3f" % (dataIndex, p))
except:
p = 0
plot_histogram(job.result().get_counts(qc_run))
return job
# Vector length is arbitrary.
precDP = 3 # Precision is 3 decimal places
tooSmallIgnored = 1E-5 # ignored if under 10^(-5)
def print_vec(vec):
vecLen = len(vec)
qbCount = int(math.log(vecLen, 2))
vecRnd = np.around(vec, precDP) # 3 decimal points
jn = ''
for i in range(vecLen):
ket = str(bin(i+vecLen))[-qbCount:]
if np.abs(vecRnd[i]) >= tooSmallIgnored: # 3 decimal points
print("%s%s|%s>" % (jn, vecRnd[i], ket), end='')
jn = ' + '
print("")
return vecRnd
# Number of qubits
qbNum = 2
# Define the Quantum and Classical Registers
q = QuantumRegister(qbNum)
c = ClassicalRegister(qbNum)
qc = QuantumCircuit(q, c)
# Preparation: Put the control qubit q_0 through H
# so we see both cases (q_0 on left): \Rsr2(|00>+|1+>)
# Not: The histogram has q_0 on the right.
qc.h(q[0])
# Circuit building
# (S^\dagger HT^\dagger)~cX~(THS)
# s;h;t;cx;tdg;h;sdg
qc.s(q[1])
qc.h(q[1])
qc.t(q[1])
qc.cx(q[0], q[1])
qc.tdg(q[1])
qc.h(q[1])
qc.sdg(q[1])
#qc.measure(q, c)
job = execute(qc, backend = 'local_statevector_simulator', shots=shots)
print_vec(job.result().get_statevector(qc))
# Histogram
#job = execute(qc, backend = 'local_qasm_simulator')
#plot_histogram(job.result().get_counts(qc))
# State Vector
#job = execute(qc, backend = 'local_statevector_simulator', shots=shots)
#print_vec(job.result().get_statevector(qc))
# Block Vector
#bloch = [x0-x1, y0-y1, z0-z1]
#plot_bloch_vector(bloch)
# Check the circuit (must be last or it will not show)
#circuit_drawer(qc)
The above works because when the control qubit is off, the operation is $[S^\dagger HT^\dagger]~I~[THS]=I$, and when it the control is on, the operation is $[S^\dagger HT^\dagger]~X~[THS]=H$.
\hspace{15em}$G$\hspace{1em} | \hspace{6em}$G\Ket0$\hspace{6em} | \hspace{6em}$G\Ket+$\hspace{6em} |
---|---|---|
$THS$ | $\Rsr2(\Ket++\Ket{+i})$ | $\Rsr2(\Ket++\Ket{-i})$ |
$X[THS]$ | $\Rsr2(\Ket++\Ket{-i})$ | $\Rsr2(\Ket++\Ket{+i})$ |
$[S^\dagger HT^\dagger]X[THS]$ | $\Rsr2(\Ket++\Ket{-i})$ | $\Rsr2(\Ket++\Ket{+i})$ |
$[S^\dagger HT^\dagger]X[THS]$ | $\Ket+$ | $\Ket0$ |
$\therefore[S^\dagger HT^\dagger]X[THS]=H$ | $\Ket+$ | $\Ket0$ |
In IBM Q Experience, it is extremely complex:
Find $ABC=I$ and $e^{i\alpha}AZBZC=V$, and their solution for $V=H$ is:
$A=e^{i3\pi/8}XSHTHS^\dagger,~ B=e^{-i\pi/8}SHT^\dagger HS^\dagger HSH,~ C=e^{-i\pi/4}HSH, e^{i3\alpha}=-i.~~ .$
$cH=(I\otimes A)~cZ~(I\otimes B)~cZ~(I\otimes C).$
\hspace{15em}$G$\hspace{1em} | \hspace{6em}$G\Ket0$\hspace{6em} | \hspace{6em}$G\Ket+$\hspace{6em} |
---|---|---|
$C=HSH$ | $\Ket{-i}$ | $\Ket+$ |
$[B=SHT^\dagger HS^\dagger HSH]C$ | $\Rsr2(\Ket++\Ket1)$ | $\Rsr2(\Ket0+\Ket+)$ |
$[A=XSHTHS^\dagger]BC$ | $\Ket0$ | $\Ket+$ |
$\therefore ABC=I$ | $\Ket0$ | $\Ket+$ |
\hspace{15em}$G$\hspace{1em} | \hspace{6em}$G\Ket0$\hspace{6em} | \hspace{6em}$G\Ket+$\hspace{6em} |
---|---|---|
$C=HSH$ | $\Ket{-i}$ | $\Ket+$ |
$ZC$ | $\Ket{+i}$ | $\Ket-$ |
$[B=SHT^\dagger HS^\dagger HSH]ZC$ | $\Rsr2(\Ket0+\Ket-)$ | $\Rsr2(\Ket-+\Ket1)$ |
$ZBZC$ | $\Rsr2(\Ket0+\Ket+)$ | $\Rsr2(\Ket++\Ket1)$ |
$[A=XSHTHS^\dagger]ZBZC$ | $\Ket+$ | $\Ket0$ |
$\therefore AZBAC=H$ | $\Ket+$ | $\Ket0$ |
<< Wavefunctions and Relativity | Top | Controlled Operations as an Eigenvalue >> |