Skip to main content

4 posts tagged with "IQC"

View All Tags

IQC 006

· 15 min read

Boolean Functions​

f:{0,1}n→{0,1}f: \{0,1\}^n \to \{0,1\}

xf0f_0f1f_1f2f_2f3f_3
00011
10101
  • n=1n=1
  • Constant: smae output for all inputs (f0f_0 and f3f_3).
  • Balanced: outputs 0 for exactly half, 1 for the other half (f1f_1 and f2f_2).
  • In the worst case, need 2n−1+12^{n-1}+1 quries to decide which type ff is exponetial in nn.
xf0f1f2f3f4f5f6f7f8f9f10f11f12f13f14f15000000000011111111010000111100001111100011001100110011110101010101010101\begin{array}{c|cccccccccccccccc} x & {\color{orange}{f_0}} & f_1 & f_2 & {\color{blue}{f_3}} & f_4 & {\color{blue}{f_5}} & {\color{blue}{f_6}} & f_7 & f_8 & {\color{blue}{f_9}} & {\color{blue}{f_{10}}} & f_{11} & {\color{blue}{f_{12}}} & f_{13} & f_{14} & {\color{orange}{f_{15}}} \\ \hline 00 & {\color{orange}0} & 0 & 0 & {\color{blue}0} & 0 & {\color{blue}0} & {\color{blue}0} & 0 & 1 & {\color{blue}1} & {\color{blue}1} & 1 & {\color{blue}1} & 1 & 1 & {\color{orange}1} \\ 01 & {\color{orange}0} & 0 & 0 & {\color{blue}0} & 1 & {\color{blue}1} & {\color{blue}1} & 1 & 0 & {\color{blue}0} & {\color{blue}0} & 0 & {\color{blue}1} & 1 & 1 & {\color{orange}1} \\ 10 & {\color{orange}0} & 0 & 1 & {\color{blue}1} & 0 & {\color{blue}0} & {\color{blue}1} & 1 & 0 & {\color{blue}0} & {\color{blue}1} & 1 & {\color{blue}0} & 0 & 1 & {\color{orange}1} \\ 11 & {\color{orange}0} & 1 & 0 & {\color{blue}1} & 0 & {\color{blue}1} & {\color{blue}0} & 1 & 0 & {\color{blue}1} & {\color{blue}0} & 1 & {\color{blue}0} & 1 & 0 & {\color{orange}1} \end{array}

The Quantum Oracle​

  • Traditional Oracle: black box that computes ff.
  • Query complexity: number of queries to the oracle needed to solve a problem.

x→Off(x)x \xrightarrow{O_f} f(x)

  • Quantum Oracle: unitary operation that encodes ff.

Uf∣x⟩∣y⟩=∣x⟩∣y⊕f(x)⟩U_f \ket{x}\ket{y} = \ket{x}\ket{y \oplus f(x)}

  • First register: input xx.
  • Second register: auxiliary qubit initialized to ∣0⟩\ket{0} or ∣1⟩\ket{1}.
  • Oracle don't change xx, but flips yy if f(x)=1f(x)=1.
    • 0⊕0=00 \oplus 0 = 0
    • 0⊕1=10 \oplus 1 = 1
    • 1⊕0=11 \oplus 0 = 1
    • 1⊕1=01 \oplus 1 = 0
  • f(x)=0f(x) = 0: yy unchanged.
  • f(x)=1f(x) = 1: yy flipped.
  • Example:
    • ∣x⟩∣0⟩\ket{x}\ket{0}
    • Uf∣x⟩∣0⟩=∣x⟩∣0⟩⊕∣f(x)⟩=∣x⟩∣f(x)⟩U_f \ket{x}\ket{0} = \ket{x}\ket{0} \oplus \ket{f(x)} = \ket{x}\ket{f(x)}.
    • if f(x)=0f(x) = 0: ∣x⟩∣0⟩\ket{x}\ket{0}.
    • if f(x)=1f(x) = 1: ∣x⟩∣1⟩\ket{x}\ket{1}
  • so that it ignores the input xx and only flips the second qubit if f(x)=1f(x)=1.
  • it can be reversed: (y⊕f(x))⊕f(x)=y(y \oplus f(x)) \oplus f(x) = y.

Phase Kickback​

  • Prepare the scratch qubit in ∣−⟩=12(∣0⟩−∣1⟩)\ket{-} = \frac{1}{\sqrt{2}}(\ket{0} - \ket{1}).
    • Uf∣x⟩∣−⟩=12(Uf∣x⟩∣0⟩−Uf∣x⟩∣1⟩)U_f \ket{x}\ket{-} = \frac{1}{\sqrt{2}}(U_f \ket{x} \ket{0} - U_f \ket{x} \ket{1})
    • =12(∣x⟩∣0⊕f(x)⟩−∣x⟩∣1⊕f(x)⟩) = \frac{1}{\sqrt{2}}(\ket{x} \ket{0 \oplus f(x)} - \ket{x}\ket{1 \oplus f(x)})
    • if f(x)=0→12(∣x⟩∣0⊕0⟩−∣x⟩∣1⊕0⟩)=12(∣x⟩∣0⟩−∣x⟩∣1⟩)=∣x⟩12(∣0⟩−∣1⟩)=∣x⟩∣−⟩f(x) = 0 \rightarrow \\ \frac{1}{\sqrt{2}}(\ket{x}\ket{0 \oplus 0} - \ket{x}\ket{1 \oplus 0}) \\ = \frac{1}{\sqrt{2}}(\ket{x}\ket{0} - \ket{x}\ket{1}) \\ = \ket{x} \frac{1}{\sqrt{2}}(\ket{0} - \ket{1}) \\ = \ket{x}\ket{-}.
    • if f(x)=1→12(∣x⟩∣0⊕1⟩−∣x⟩∣1⊕1⟩)=12(∣x⟩∣1⟩−∣x⟩∣0⟩)=−∣x⟩12(∣0⟩−∣1⟩)=−∣x⟩∣−⟩f(x) = 1 \rightarrow \\ \frac{1}{\sqrt{2}}(\ket{x}\ket{0 \oplus 1} - \ket{x}\ket{1 \oplus 1}) \\ = \frac{1}{\sqrt{2}}(\ket{x}\ket{1} - \ket{x}\ket{0}) \\ = - \ket{x} \frac{1}{\sqrt{2}}(\ket{0} - \ket{1}) \\ = -\ket{x}\ket{-}.
      • it doesn't matter where the phase is, it can be moved around:
      • α(∣ψ⟩⊗∣ϕ⟩)=α∣ψ⟩⊗∣ϕ⟩=∣ψ⟩⊗α∣ϕ⟩\alpha(\ket{\psi} \otimes \ket{\phi}) = \alpha\ket{\psi} \otimes \ket{\phi} = \ket{\psi} \otimes \alpha\ket{\phi}.
  • if we put the second register to ∣−⟩\ket{-}, f(x)f(x) will be encoded in the phase of the first register.

∣x⟩∣−⟩↦(−1)f(x)∣x⟩∣−⟩\ket{x}\ket{-}\mapsto (-1)^{f(x)} \ket{x} \ket{-}

  • The function's output has been "kicked back" into the phase of the first register, while the second register remains unchanged.

The Deutsch Problem​

  • Given a boolean function f:{0,1}n→{0,1}f:\{0,1\}^{n} \to \{0,1\}, determine if ff is constant or balanced.
  • Constant: same output for all inputs.
  • Balanced: outpus 0 for half the inputs and 1 for the other half.

Deutsch's Algorithm

  1. Prepare ∣0⟩∣1⟩\ket{0}\ket{1}.
  2. Apply HH to both qubits →∣+⟩∣−⟩\to \ket{+}\ket{-}.
  3. Apply oracle UfU_f.
  4. Phase kickback encodes ff in the input phase.
  5. Apply HH to input qubit, then measure.
  • One query to the oracle is sufficient to determine if ff is constant or balanced.
  • if measure 0: ff is constant.
  • if measure 1: ff is balanced.

Deustch-Jozsa Algorithm​

The direct generalization for any nn-bit boolean function.

  1. Input register nn qubits: Initialize qubits in ∣0⟩\ket{0} and apply HH gate to each one.
  2. Scratch Qubit 11 qubit: Initialize in ∣1⟩\ket{1} with XX and then apply an HH gate.
  3. Oracle: Apply UfU_f to the input and scratch registers (All qubits).
  4. Final Hadamards: Apply HH to input qubits.
  5. Measurement: Measure the input register.
  • if all qubits returned 00: ff is constant.
  • if any qubit returned 11: ff is balanced.

Deutsch-Jozsa Algorithm

How it works​

  • The initial state is

∣00⋯0⟩∣1⟩\ket{00 \cdots 0} \ket{1}

  • After applying HH gates to the input and scratch registers, we get

∣00⋯0⟩→12n(∣00⋯0⟩+∣00⋯1⟩+⋯+∣11⋯1⟩)\ket{00 \cdots 0} \rightarrow \frac{1}{\sqrt{2^n}} \left( \ket{00 \cdots 0} + \ket{00 \cdots 1} + \cdots + \ket{11 \cdots 1} \right)

  • The input register is in a superposition of a computational states containing all possible inputs to nn-bit string.
  • The last qubit hasn't changed from n=1n = 1 case, so it is in the state ∣−⟩\ket{-}.
    • H∣1⟩=∣−⟩H\ket{1} = \ket{-}
  • The definition of the oracle was generic for any bit string: Uf∣x⟩∣−⟩=(−1)f(x)∣x⟩∣−⟩U_f \ket{x}\ket{-} = (-1)^{f(x)} \ket{x} \ket{-}
  • The phase-kickback puts a phase in front of each term in the input register that depends on the output of the function ff: 12n(  (−1)f(00…0)∣00…0⟩+⋯+(−1)f(11…1)∣11…1⟩  )\frac{1}{\sqrt{2^n}}\big(\;(-1)^{f(00\ldots0)}|00\ldots 0\rangle+ \cdots +(-1)^{f(11\ldots1)}|11\ldots 1\rangle\;\big)
    • The scratch qubit remains in ∣−⟩\ket{-}, so we can ignore it for the rest of the algorithm.
  • Constant case
    • if ff is constant, then all the phases are the same, either +1+1 or −1-1:
    • f(00⋯0)=f(00⋯1)=⋯=f(11⋯1)=0f(00 \cdots 0) = f(00 \cdots 1) = \cdots = f(11 \cdots 1) = 0
    • f(00⋯0)=f(00⋯1)=⋯=f(11⋯1)=1f(00 \cdots 0) = f(00 \cdots 1) = \cdots = f(11 \cdots 1) = 1
    • The phse in front of every computational state is the same, Either +1+1 or −1-1.
    • Before the second application of the HH gates, the state of the input register is:
    • ±12n(∣00⋯0⟩+∣00⋯1⟩+⋯+∣11⋯1⟩)\pm \frac{1}{\sqrt{2^n}} \left( \ket{00 \cdots 0} + \ket{00 \cdots 1} + \cdots + \ket{11 \cdots 1} \right)
    • In measurement, in either case, the probability to obtain P(00⋯0)=1P(00 \cdots 0) = 1
    • A constant function deterministically returns all zeros with a single query.
  • Balanced case
    • we are promised the function is either constant or balanced, so there are equal number of +1+1 and −1-1 phases. so we don't need to consider this case.
    • If the measurement produces anything but all zeros, we know with certainty the function is not constant, so it must be balanced.
    • There are a lot of balanced function, but half the terms in the superposition will exactly have a −1-1 phase.
    • It's clearly orthogonal to the state with all ones in superposition.
    • Appllying HH's will change the state to some other superpostiion, or perhaps a unique computational state.
    • But, orthogonality to ∣00⋯0⟩\ket{00 \cdots 0} must remain.
    • A balenced function deterministically returns a state with at least one entry as 11, with a single query.

One quantum query vs 2n−1+12^{n-1} + 1 classical queries. It is an algorithm that puts all inputs into superposition at once, encodes the function values as phases, and then uses interference to distinguish between constant and balanced functions.

Buildling Oracles​

Multi-Controlled and Anti-Controlled Gates​

  • build UfU_f that applies XX to the output qubit exactly when f(x)=1f(x) = 1.
    • if n=2n=2, the multi-controlled XX gate is a Toffoli gate.
    • x=11x=11 is the only input that gives f(x)=1f(x) = 1, so we can use a Toffoli gate with controls on the first two qubits and target on the output qubit.
      • This is because the Toffoli gate will flip the output qubit if and only if both control qubits are ∣1⟩\ket{1}, which corresponds to the input x=11x=11.
    • if x=00x=00 is the only input that gives f(x)=1f(x) = 1, we can use an anti-controlled Toffoli gate, which applies XX to the target qubit if both control qubits are ∣0⟩\ket{0}.
      • This is because the anti-controlled Toffoli gate will flip the output qubit if and only if both control qubits are ∣0⟩\ket{0}, which corresponds to the input x=00x=00.
      • Applying XX gates to the two control qubits, then applying a Toffoli gate, and then applying XX gates again to the control qubits will effectively create an anti-controlled Toffoli gate.

Anti-Controlled Gates

  • A multi-controlled XX gates (CnXC^nX) flips the target only all control qubits are ∣1⟩\ket{1}.
  • To target a specific input xx:
    • Place XX gates on each qubit ii where xi=0x_i = 0. (anti-control)
    • Apply CnXC^nX.
    • Undo the XX gates.
  • For nn qubits, it can be generalized to perform an XX gate (or any UU) with nn control qubits, requireing n−1n-1 extra scratch qubits and 2(n−1)2(n-1) Toffoli gates.
  • Whenever scratch qubits are invoked, always see a symmetric pattern of gates.
  • Uf8Uf1∣x⟩∣y⟩=∣x⟩∣y⊕f1(x)⊕f8(x)⟩=∣x⟩∣y⊕f9(x)⟩U_{f8} U_{f1} \ket{x}\ket{y} = \ket{x}\ket{y \oplus f_1(x) \oplus f_8(x)} = \ket{x}\ket{y \oplus f_9(x)}

CCCX

  1. The computation is done using the scratch qubits.
  2. The answer is copied to the target or output register
  3. The computation is inverted to reset the scratch qubits to ∣0⟩\ket{0}.
  • called "uncomputation", ensures the scratch qubits are returned to their initial state.
  • no input or output qubits are entangled with the scratch qubits at the end of the algorithm.

Implementing Deutsch-Jozsa​

def random_oracle(n):
# Circuit object to hold the gates
circuit = qiskit.QuantumCircuit(n + 1)

# With 50% probability, return a constant oracle
if np.random.randint(0, 2):
qasm = ""
# another 50:50 chance of it being a 1 instead of 0 oracle
if np.random.randint(0, 2):
qasm += f"x q[{n-1}];"
return qasm, "constant"

# A balanced function has half the inputs as 0
# Randomly select where those are
zero_strings = np.random.choice(range(2**n),int(2**(n-1)),replace=False)

for string in zero_strings:

# Convert base 10 to 2
bitstring= f"{string:0b}"

# X gates for 0 locations
for xi, bit in enumerate(reversed(bitstring)): # enumerate iterates through the list as well as the index in the list
if bit == "1":
circuit.x(xi)

# C^n X gate
circuit.mcx(list(range(n)), n)

# X gates for 0 locations
for xi, bit in enumerate(reversed(bitstring)):
if bit == "1":
circuit.x(xi)

transpiled_circuit = qiskit.transpile(circuit, basis_gates=["u1", "u3", "u2", "cx"])
qasm = qiskit.qasm2.dumps(transpiled_circuit)[47:]
return qasm, "balanced"
OPENQASM 2.0;
qreg q[3];
creg c[2];

x q[2];
h q[0];
h q[1];
h q[2];

/* oracle for f(00)=1 */
x q[0];
x q[1];
ccx q[0],q[1],q[2];
x q[0];
x q[1];

/* oracle for f(11)=1 */
ccx q[0],q[1],q[2];

h q[0];
h q[1];

measure q[0] -> c[0];
measure q[1] -> c[1];
OPENQASM 2.0;
qreg q[n+1];
creg c[n];

x q[n];
h q[0];
h q[1];
...
h q[n];
/* oracle U_f */
h q[0];
h q[1];
...
h q[n-1];
measure q[0] -> c[0];
...
measure q[n-1] -> c[n-1];

Bernstein-Vazirani Algorithm​

  • Given fs:{0,1}n→{0,1}f_s: \{0,1\}^n \to \{0,1\} defined as fs(x)=s⋅xmod  2f_s(x) = s \cdot x \mod 2
    • where ss is an unknown nn-bit string and xx is the input.
  • The goal is to determine the hidden string ss as few queries as possible.
  • Classically: query ff with input e0=00⋯01e_0 = 00 \cdots 01, e1=00⋯10e_1 = 00 \cdots 10, ..., en−1=10⋯00e_{n-1} = 10 \cdots 00 to get each bit of ss.
    • Total nn queries.
  • Quantum: use the exact same circuit as Deutsch-Jozsa.
    • Ufs∣x⟩=(−1)s⋅x∣x⟩U_{f_s} \ket{x} = (-1)^{s \cdot x} \ket{x}.
      • where we can ignore the output register in the ∣−⟩\ket{-} state.
      • For n=1n =1, the state after the oracle before the final HH gate is:
        • 12(∣0⟩+(−1)s∣1⟩)\frac{1}{\sqrt{2}} \left( \ket{0} + (-1)^{s} \ket{1} \right)
      • which is ∣+⟩\ket{+} if s=0s=0 and ∣−⟩\ket{-} if s=1s=1.
    • Applying HH to this state returns ss:
      • H12(∣0⟩+(−1)s∣1⟩)=∣s⟩H \frac{1}{\sqrt{2}} \left( \ket{0} + (-1)^{s} \ket{1} \right) = \ket{s}.
    • The measurement deterministically reveals ss.

n=2 case​

  • s=s1s0s = s_1s_0 and x=x1x0x = x_1 x_0
  • →s⋅x=s1x1+s0x0\rightarrow s\cdot x = s_1x_1 + s_0 x_0
12((−1)s0⋅0+s1⋅0∣00⟩+(−1)s0⋅1+s1⋅0∣01⟩+(−1)s0⋅0+s1⋅1∣10⟩+(−1)s0⋅1+s1⋅1∣11⟩)=12(∣00⟩+(−1)s0∣01⟩+(−1)s1∣10⟩+(−1)s1+s0∣11⟩).\begin{aligned} &\frac{1}{2}\big((-1) ^{s_0\cdot 0+s_1\cdot 0} \ket{00} + (-1) ^{s_0\cdot 1+s_1\cdot 0} \ket{01}+(-1) ^{s_0\cdot 0+s_1\cdot 1} \ket{10}+(-1) ^{s_0\cdot 1+s_1\cdot 1} \ket{11}\big)\\ &=\frac{1}{2}\big( \ket{00} + (-1) ^{s_0} \ket{01}+(-1) ^{s_1} \ket{10}+(-1) ^{s_1+s_0} \ket{11}\big). \end{aligned}

this factorized into:

12(∣0⟩+(−1)s1∣1⟩)⊗12(∣0⟩+(−1)s0∣1⟩).\frac{1}{\sqrt{2}}\big(\ket 0 + (-1)^{s_1}\ket 1\big)\otimes \frac{1}{\sqrt{2}}\big(\ket 0 + (-1)^{s_0}\ket 1\big).

this reduces the same agument as n=1n=1 for each qubit where after the final HH gates, the state becomes:

∣s1⟩⊗∣s0⟩≡∣s1s0⟩.\ket{s_1}\otimes \ket {s_0} \equiv \ket{s_1 s_0}.

Implemnting Bernstein-Vazirani​

Ufs∣x⟩∣y⟩=∣x⟩∣y⊕(s⋅x)⟩U_{f_s} \ket{x} \ket y = \ket{x} \ket {y\oplus (s\cdot x)} y⊕(s⋅x)=y⊕s0x0⊕s1x1⊕⋯⊕sn−1xn−1y\oplus (s\cdot x) = y\oplus s_0 x_0 \oplus s_1 x_1 \oplus \cdots \oplus s_{n-1} x_{n-1} Ufs∣x⟩∣y⟩=∣x⟩∣y⊕sx⟩U_{f_s} \ket{x} \ket y = \ket{x} \ket {y\oplus s x}
  • I\mathbb{I} if s=0s = 0 and CNOTCNOT if s=1s = 1.
  • To implement fs(x)=s⋅xf_{s}(x) = s \cdot x, we can use a CNOT from qubit ii to the scratch qubit if si=1s_i = 1.
import numpy as np
from qiskit import QuantumCircuit, transpile
from qiskit_aer import AerSimulator


def bv_query(n, secret=None):
# Build oracle for f_s(x) = s · x
# q[0]..q[n-1] = input register
# q[n] = scratch/output qubit

if secret is None:
value = np.random.randint(0, 2 ** n)
secret = format(value, f"0{n}b")
else:
secret = secret.zfill(n)

oracle = QuantumCircuit(n + 1, name="Uf")
for index, bit in enumerate(reversed(secret)):
if bit == "1":
oracle.cx(index, n)

return oracle, secret


def bernstein_vazirani_circuit(n, secret=None):
# Build full Bernstein-Vazirani circuit
oracle, secret = bv_query(n, secret)

qc = QuantumCircuit(n + 1, n)

# Prepare scratch qubit in |->
qc.x(n)

# Apply Hadamards to all qubits
for i in range(n + 1):
qc.h(i)

# Apply oracle
qc.compose(oracle, inplace=True)

# Apply final Hadamards to input register
for i in range(n):
qc.h(i)

# Measure input register
for i in range(n):
qc.measure(i, i)

return qc, secret


def run_bernstein_vazirani(n, secret=None, shots=1):
qc, secret = bernstein_vazirani_circuit(n, secret)

simulator = AerSimulator()
compiled = transpile(qc, simulator)
result = simulator.run(compiled, shots=shots).result()
counts = result.get_counts()

measured = max(counts, key=counts.get)
recovered = measured[::-1]

return qc, secret, recovered, counts


# Example
qc, secret, recovered, counts = run_bernstein_vazirani(5, "01101")
print(qc.draw())
print("Secret :", secret)
print("Measured :", recovered)
print("Counts :", counts)
OPENQASM 2.0;
qreg q[6];
creg c[5];

x q[5];
h q[0];
h q[1];
h q[2];
h q[3];
h q[4];
h q[5];

cx q[0],q[5];
cx q[2],q[5];
cx q[3],q[5];

h q[0];
h q[1];
h q[2];
h q[3];
h q[4];

measure q[0] -> c[0];
measure q[1] -> c[1];
measure q[2] -> c[2];
measure q[3] -> c[3];
measure q[4] -> c[4];

Summary​

  • There are 22n2^{2^n} possible Boolean functions from {0,1}n\{0,1\}^n to {0,1}\{0,1\}.
  • A Boolean function is balanced if it outputs 1 on exactly half of the inputs, that is, on 2n−12^{n-1} out of the 2n2^n possible inputs.
  • In Deutsch’s algorithm with n=1n=1, only 1 quantum query is needed to distinguish a constant function from a balanced function.
  • A quantum oracle for ff is defined as the unitary Uf: ∣x⟩∣y⟩↦∣x⟩∣y⊕f(x)⟩.U_f:\ |x\rangle|y\rangle \mapsto |x\rangle|y\oplus f(x)\rangle.
  • Every XOR-based function of the form f(x)=xj⊕xk⊕⋯f(x)=x_j\oplus x_k\oplus\cdots that depends on at least one input bit is balanced.
  • Using multi-controlled XX gates, together with anti-controls when needed, we can implement an oracle for any Boolean function.
  • The phase kickback multiplies the state by the phase factor (−1)f(x)(-1)^{f(x)}, so the phase changes exactly when f(x)=1f(x)=1.
  • If these questions were stored in a Python list called questions, then the 8th question would be questions[7].
  • Applying Hadamard gates to nn qubits initialized in ∣0⟩|0\rangle produces an equal superposition over all 2n2^n computational basis states.
  • In Deutsch–Jozsa for n>1n>1, measuring all input qubits as 0 means that ff is constant.
  • Bernstein–Vazirani solves the hidden-string problem f(x)=s⋅xf(x)=s\cdot x with 1 quantum query.
  • A multi-controlled XX gate with 3 controls can be implemented using scratch qubits and 4 Toffoli gates.
  • Applying Uf1U_{f_1} followed by Uf2U_{f_2} yields an oracle whose action on the scratch qubit corresponds to f1(x)⊕f2(x)f_1(x)\oplus f_2(x).
  • Uncomputation resets scratch qubits to their initial states by applying the inverse of the computation, which means reversing the order of the steps.
  • Multi-controlled gates with more than one control can be decomposed into simpler gates, but in general this requires more than just CXCX and XX; single-qubit gates are also needed.

IQC 004

· 10 min read

Superdense Coding​

  • counterintuitive protocol that allows us to send 2 bits of classical information by sending only 1 qubit, using pre-shared entanglement
  • it's often contextualized as a game with Alice and Bob.
  • Alice and Bob share and entangled pair of qubits
  • Pre-shared Entanglement (Shared Bell pair)
    • ∣Φ+⟩=12(∣00⟩+∣11⟩)|\Phi^+\rangle = \frac{1}{\sqrt{2}}(|00\rangle + |11\rangle)
  • Alice wants to send 2 bits of classical information (00, 01, 10, or 11) to Bob
    • For 00: Apply Identity II (do nothing)
    • For 01: Apply Pauli-X XX (bit flip)
    • For 10: Apply Pauli-Z ZZ (phase flip)
    • For 11: Apply XZXZ (bit and phase flip)
  • Alice sends her one qubit to Bob (Bob possesses both qubits of the entangled pair)
  • Bob decodes the information
    • Inverts the entanglement operation on the two qubits (CNOT followed by Hadamard)
    • Measures each of the qubits
    • The outcome of this measurement reveals the two bits Alice encoded.
  • ∣Φ+⟩|\Phi^+\rangle: is the most common and convenient form (Bell State) of entanglement and is also maximally entangled state despite single-qubit unitary gates.
    • Easy to build circuits for it
    • Symmetric and has nice properties that make it ideal for protocols like superdense coding and teleportation
    • Other Bell states can be generated from ∣Φ+⟩|\Phi^+\rangle by applying single-qubit gates.

Superdense Coding Circuit​

Superdense Coding Circuit

  • Alice's message mnmn, where each of mm and nn is a bit (0 or 1)
  • Alice's operation can be represented as ZmXn⊗I∣Φ+⟩Z^m X^n \otimes \mathbb{I} | \Phi^+\rangle
    • m=0⇒Z0=Im=0 \Rightarrow Z^0 = I (no phase flip)
    • m=1⇒Z1=Zm=1 \Rightarrow Z^1 = Z (phase flip)
    • n=0⇒X0=In=0 \Rightarrow X^0 = I (no bit flip
    • n=1⇒X1=Xn=1 \Rightarrow X^1 = X (bit flip)
    • 00→I00 \rightarrow I
    • 01→X01 \rightarrow X
    • 10→Z10 \rightarrow Z
    • 11→ZX11 \rightarrow ZX
  • Zm∣b⟩=(−1)mb∣b⟩Z^m|b\rangle = (-1)^{mb}|b\rangle (phase flip)
  • Xn∣a⟩=∣a⊕n⟩X^n|a\rangle = |a \oplus n\rangle (xor operation)

Xn(12(∣00⟩+∣11⟩))=12(∣n0⟩+∣(1⊕n)1⟩)X^n \left(\frac{1}{\sqrt{2}} (|00\rangle + |11\rangle)\right) = \frac{1}{\sqrt{2}} \left( |n0\rangle + |(1\oplus n)1\rangle \right)

  • n=0n=0: 12(∣00⟩+∣11⟩)=∣Φ+⟩\frac{1}{\sqrt{2}} (|00\rangle + |11\rangle) = |\Phi^+\rangle
  • n=1n=1: 12(∣10⟩+∣01⟩)\frac{1}{\sqrt{2}} (|10\rangle + |01\rangle)

ZmXn(12(∣00⟩+∣11⟩))=12((−1)mn∣n0⟩+(−1)m(1⊕n)∣(1⊕n)1⟩)Z^m X^n \left(\frac{1}{\sqrt{2}} (|00\rangle + |11\rangle)\right) = \frac{1}{\sqrt{2}} \left( (-1)^{mn}|n0\rangle + (-1)^{m(1\oplus n)}|(1\oplus n)1\rangle \right)

  • ∣n0⟩|n0\rangle: first qubit is nn, (−1)mn(-1)^{mn} is the phase factor
  • ∣(1⊕n)1⟩|(1\oplus n)1\rangle: first qubit is 1⊕n1\oplus n, (−1)m(1⊕n)(-1)^{m(1\oplus n)} is the phase factor
  • Bob's decoding operation is the inverse of the entanglement operation
    • CNOT∣a⟩∣b⟩=∣a⟩∣a⊕b⟩CNOT |a\rangle |b\rangle = |a\rangle |a \oplus b\rangle
CNOT ZmXn(12(∣00⟩+∣11⟩))=(−1)mn2(∣nn⟩+(−1)m∣(1⊕n)n⟩)=(−1)mn2(∣n⟩+(−1)m∣1⊕n⟩)∣n⟩\begin{aligned} CNOT\, Z^m X^n \left(\frac{1}{\sqrt{2}} (|00\rangle + |11\rangle)\right) &= \frac{(-1)^{mn}}{\sqrt{2}} \left(|nn\rangle + (-1)^m|(1 \oplus n)n\rangle\right) \\ &= \frac{(-1)^{mn}}{\sqrt{2}} \left(|n\rangle + (-1)^m|1 \oplus n\rangle\right)|n\rangle \end{aligned}
  • which is seperable state.
  • First qubit is ∣n⟩+(−1)m∣1⊕n⟩|n\rangle + (-1)^m|1 \oplus n\rangle and second qubit is ∣n⟩|n\rangle.
  • n,m∈{0,1}n, m \in \{0, 1\}, then apply Hadamard to the first qubit:
H 12(∣n⟩+(−1)m∣1⊕n⟩)=(−1)mn∣m⟩H\, \frac{1}{\sqrt{2}} \left(|n\rangle + (-1)^m|1 \oplus n\rangle\right) = (-1)^{mn}|m\rangle
  • second qubit is ∣n⟩|n\rangle, so the final state is:

(−1)mn(−1)nm∣m⟩∣n⟩=∣mn⟩(-1)^{mn}(-1)^{nm}|m\rangle|n\rangle = |mn\rangle

Superdense QASM​

OPENQASM 2.0;
qreg q[2];
creg c[2];

// Prepare Bell pair
h q[0];
cx q[0],q[1];

// Alice's encoding
// For message 11: apply X and Z
x q[0];
z q[0];

// Alice sends q[0] to Bob (in simulation, we just proceed)

// Bob's decoding
cx q[0],q[1];
h q[0];

// Measure both qubits
measure q[0] -> c[0];
measure q[1] -> c[1];

QASM Programming​

Custom Gates​

// params: parameters for the gate (e.g., rotation angles)
// q_args: quantum arguments (qubits the gate acts on)
gate NAME(parameters) q_args {
// Define gate operations
}

gate bell a,b {
h a;
cx a,b;
}

qreg q[2];
creg c[2];

// Use the custom bell gate
bell q[0], q[1];

// Measure the qubits
measure q[0] -> c[0];
measure q[1] -> c[1];

Toffoli Gate​

// Toffoli gate (CCX)
gate ccx a, b, c {
h c;
cx b, c;
tdg c;
cx a, c;
t c;
cx b, c;
tdg c;
cx a, c;
t b;
t c;
cx a, b;
h c;
t a;
tdg b;
cx a, b;
}

Rotation Gates​

// Rotation around Y-axis
gate ry_deg(theta) q {
ry(theta/180 * pi) q;
}

// Rotation around X-axis
gate rx_deg(theta) q {
rx(theta/180 * pi) q;
}

Qiskit​

IBM

import qiskit

superdense = qiskit.QuantumCircuit(2, 2)
superdense.draw()

superdense.h(0)
superdense.cx(0, 1)
superdense.draw()

superdense qiskit

# Alice's encoding for message '11'
superdense.x(0)
superdense.z(0)
superdense.draw()

superdense qiskit 11

# Bob unentangles the two qubits (reverses the entangling gate)
superdense.cx(0,1)
superdense.h(0)

# The measurement pattern is `measure(qubit to measure, classical bit to store result)`
superdense.measure(0,0)
superdense.measure(1,1)
superdense.draw()

superdense qiskit measure

from qiskit.providers.basic_provider import BasicSimulator

sim = BasicSimulator()
# run the circuit on the simulator with 1 shot (execute the circuit once)
result = sim.run(superdense, shots=1).result().get_counts()

print(result)
# {'11': 1}

Custom Gates in Qiskit​

bell = qiskit.QuantumCircuit(2, name='bell')
bell.h(0)
bell.cx(0, 1)
bell_gate = bell.to_gate()

c = qiskit.QuantumCircuit(2)
c.append(bell_gate, [0, 1])
c.draw()

Decompose a custom gate​

ccxgate = qiskit.circuit.library.CCXGate()
ccx = qiskit.QuantumCircuit(3)
ccx.append(ccxgate, [0, 1, 2])

print(ccx)
print(ccx.decompose())

ccx

Cirq​

Google

import cirq

alice = cirq.NamedQubit('Alice')
bob = cirq.NamedQubit('Bob')

superdense = cirq.Circuit()
superdense.append([
cirq.H(alice),
cirq.CNOT(alice, bob),
])

superdense.append([
cirq.X(alice),
cirq.Z(alice),
])

superdense.append([
cirq.CNOT(alice, bob),
cirq.H(alice),
])

superdense.append(cirq.measure(alice, bob, key='received'))

print(superdense)
simulator = cirq.Simulator()
result = simulator.run(superdense, repetitions=1)
print(result)
# received=1, 1

Pennylane​

Xanadu

import pennylane as qml

def entangle():
qml.Hadamard(wires=0)
qml.CNOT(wires=[0, 1])

print(qml.draw(entangle)())

device = qml.device("default.qubit", wires=[0, 1])

# Wrap the quantum function as a QNode
entangle_qnode = qml.QNode(my_circuit, device)

# Set the number of shots to 10
entangle_qnode = qml.set_shots(entangle_qnode, shots=10)
import numpy as np

state = np.array([1, 1j], dtype=complex)

state = state / np.linalg.norm(state)
def teleport(state):
# Ensure "state" is loaded into the first qubit
# (otherwise qubits would start in |0>)
qml.StatePrep(state, wires=0)

# Shared entanglement between qubits 1 and 2
qml.Hadamard(wires=1)
qml.CNOT(wires=[1, 2])

# Alice's operation:
# CNOT from Alice's input qubit to her half of the Bell pair,
# then Hadamard on the input qubit
qml.CNOT(wires=[0, 1])
qml.Hadamard(wires=0)

# Measurement (store the classical outcomes)
m0 = qml.measure(0)
m1 = qml.measure(1)

# Bob's conditional correction operations
qml.cond(m1, qml.PauliX)(wires=2)
qml.cond(m0, qml.PauliZ)(wires=2)

# Return Bob's qubit as a density matrix
return qml.density_matrix(wires=2)

print(qml.draw(teleport)(state))

Quantum Teleportation​

Quantum Teleportation

-Superdense CodingTeleportation
ConsumesEntanglementEntanglement
Sends1 qubit2 bits
Transmits2 bits1 qubit
  • if there is entanglement:
    • we can use it to send 2 bits of classical information by sending 1 qubit (superdense coding)
    • we can use it to send 1 qubit of quantum information by sending 2 bits of classical information (teleportation)
  • Alice wants to send a qubit ∣ψ⟩=α∣0⟩+β∣1⟩|\psi\rangle = \alpha|0\rangle + \beta|1\rangle to Bob, but only has a classical channel.

Protocol​

  1. Alice and Bob share ∣Φ+⟩|\Phi^+\rangle (pre-shared entanglement)
  2. Alice applies CNOTCNOT (her qubit -> her Bell half), then HH, then measures both, obtaining 2 classical bits (00, 01, 10, or 11)
  3. Alice sends mnmn classically to Bob
  4. Bob applies XnZmX^n Z^m to his qubit, recovering ∣ψ⟩|\psi\rangle
  • For 00: Apply Identity II (do nothing)
  • For 01: Apply Pauli-X XX (bit flip)
  • For 10: Apply Pauli-Z ZZ (phase flip)
  • For 11: Apply XZXZ (bit and phase flip)
  • Bob now has a qubit in the state Alice wanted to send ∣ψ⟩|\psi\rangle without Alice ever sending a qubit directly to Bob.

Teleportation Circuit​

Teleportation Circuit

∣ψ⟩⊗∣Φ+⟩=(α∣0⟩+β∣1⟩)⊗12(∣00⟩+∣11⟩)|\psi\rangle \otimes |\Phi^+\rangle = \left(\alpha |0\rangle + \beta |1\rangle\right) \otimes \frac{1}{\sqrt{2}} \left(|00\rangle + |11\rangle\right)

∣ψ⟩⊗∣Φ+⟩=12(α∣0⟩∣00⟩+α∣0⟩∣11⟩+β∣1⟩∣00⟩+β∣1⟩∣11⟩)|\psi\rangle \otimes |\Phi^+\rangle = \frac{1}{\sqrt{2}} \left(\alpha |0\rangle |00\rangle + \alpha |0\rangle |11\rangle + \beta |1\rangle |00\rangle + \beta |1\rangle |11\rangle\right)

  • Alice applies a CNOTCNOT gate with her qubit ∣ψ⟩|\psi\rangle as control and her half of the Bell pair ∣Φ+⟩|\Phi^+\rangle as target.
    • β∣1⟩∣00⟩\beta |1\rangle |00\rangle becomes β∣1⟩∣10⟩\beta |1\rangle |10\rangle (target flips when control is 1)
    • β∣1⟩∣11⟩\beta |1\rangle |11\rangle becomes β∣1⟩∣01⟩\beta |1\rangle |01\rangle (target flips when control is 1)

12(α∣0⟩∣00⟩+α∣0⟩∣11⟩+β∣1⟩∣10⟩+β∣1⟩∣01⟩)\frac{1}{\sqrt{2}} \Big(\alpha |0\rangle |00\rangle + \alpha |0\rangle |11\rangle + \beta |1\rangle |10\rangle + \beta |1\rangle |01\rangle\Big)

  • Alice then applies a Hadamard gate to her qubit (∣ψ⟩|\psi\rangle).
    • H∣0⟩=∣0⟩+∣1⟩2H|0\rangle = \frac{|0\rangle + |1\rangle}{\sqrt{2}}
    • H∣1⟩=∣0⟩−∣1⟩2H|1\rangle = \frac{|0\rangle - |1\rangle}{\sqrt{2}}
  • To prepare for measurement, Bell measurement is performed on Alice's two qubits, which can be expressed as:
12[α(∣0⟩+∣1⟩2)⊗∣00⟩+α(∣0⟩+∣1⟩2)⊗∣11⟩+β(∣0⟩−∣1⟩2)⊗∣10⟩+β(∣0⟩−∣1⟩2)⊗∣01⟩]= 12[∣00⟩(α∣0⟩+β∣1⟩)+∣01⟩(α∣1⟩+β∣0⟩)+∣10⟩(α∣0⟩−β∣1⟩)+∣11⟩(α∣1⟩−β∣0⟩)]\begin{aligned} \frac{1}{\sqrt{2}} \Bigg[&\alpha \left(\frac{|0\rangle + |1\rangle}{\sqrt{2}}\right) \otimes |00\rangle + \alpha \left(\frac{|0\rangle + |1\rangle}{\sqrt{2}}\right) \otimes |11\rangle \\ &+ \beta \left(\frac{|0\rangle - |1\rangle}{\sqrt{2}}\right) \otimes |10\rangle + \beta \left(\frac{|0\rangle - |1\rangle}{\sqrt{2}}\right) \otimes |01\rangle \Bigg] \\ =\, &\frac{1}{2} \Big[ |00\rangle (\alpha |0\rangle + \beta |1\rangle) + |01\rangle (\alpha |1\rangle + \beta |0\rangle) \\ &+ |10\rangle (\alpha |0\rangle - \beta |1\rangle) + |11\rangle (\alpha |1\rangle - \beta |0\rangle) \Big] \end{aligned}
  • Alice measures her two qubits, resulting in one of four possible outcomes corresponding to the classical bits ∣mn⟩|mn\rangle where m,n∈{0,1}m, n \in \{0, 1\}
    • Alice's two qubits: ∣00⟩,∣01⟩,∣10⟩,∣11⟩|00\rangle, |0 1\rangle, |1 0\rangle, |1 1\rangle
    • Bob's qubit is in a state that depends on Alice's measurement outcome

XnZm∣ψ⟩X^n Z^m |\psi\rangle

mnBob's stateBob applies
00α∣0⟩+β∣1⟩\alpha \lvert 0\rangle + \beta \lvert 1\rangleI\mathbb{I}
01α∣1⟩+β∣0⟩\alpha \lvert 1\rangle + \beta \lvert 0\rangleXX
10α∣0⟩−β∣1⟩\alpha \lvert 0\rangle - \beta \lvert 1\rangleZZ
11α∣1⟩−β∣0⟩\alpha \lvert 1\rangle - \beta \lvert 0\rangleXZXZ

Channels​

  • Classical Channel: carries bits (fibre, radio, paper, ...)
  • Quantum Channel: carries qubits (can also carry bits)
    • Quantum channels can emulate classical ones, but not vice versa
  • Teleportation: classical channel + pre-shared entanglement -> effective quantum channel

Summary​

  • In superdense coding, by sending only one qubit and using pre-shared entanglement, Alice can transmit two classical bits of information.
  • The operation Xn∣a⟩=∣a⊕(n mod 2)⟩X^n \lvert a \rangle = \lvert a \oplus (n \bmod 2) \rangle correctly defines the effect of applying the XX gate nn times.
  • The tensor product of two identity operators is the identity operator on the composite space. In symbols, where the subscript is the dimension: I2⊗I2=I4I_2 \otimes I_2 = I_4.
  • The state ∣ϕ⟩=12(∣0⟩+∣1⟩)\lvert \phi \rangle = \frac{1}{\sqrt{2}}(\lvert 0 \rangle + \lvert 1 \rangle) is an eigenstate of the Pauli-XX gate with eigenvalue +1+1.
  • In the teleportation protocol, the classical communication channel is used to transmit two classical bits from Alice to Bob.
  • Three qubits are required for quantum teleportation.
  • After the teleportation protocol completes, Bob has a qubit in the state ∣ψ⟩\lvert \psi \rangle.
  • Of QASM, Qiskit, Cirq, and PennyLane, PennyLane is the only quantum language that spells out the full name of the Hadamard gate for its built-in gates.

IQC 003

· 12 min read

Tensor Products​

Kronecker product

  • a way to multiply vectors and matrices to generate bigger vectors and matrices

∣ψ⟩⊗∣ϕ⟩=(ψ0ψ1)⊗(ϕ0ϕ1)=(ψ0(ϕ0ϕ1)ψ1(ϕ0ϕ1))=(ψ0ϕ0ψ0ϕ1ψ1ϕ0ψ1ϕ1)|\psi\rangle \otimes |\phi\rangle = \begin{pmatrix} \psi_0 \\ \psi_1 \end{pmatrix} \otimes \begin{pmatrix} \phi_0 \\ \phi_1 \end{pmatrix} = \begin{pmatrix} \psi_0 \begin{pmatrix} \phi_0 \\ \phi_1 \end{pmatrix} \\ \\ \psi_1 \begin{pmatrix} \phi_0 \\ \phi_1 \end{pmatrix} \end{pmatrix} = \begin{pmatrix} \psi_0 \phi_0 \\ \psi_0 \phi_1 \\ \psi_1 \phi_0 \\ \psi_1 \phi_1 \end{pmatrix}

∣ψ⟩⊗∣ϕ⟩≡∣ψ⟩∣ϕ⟩≡∣ψϕ⟩|\psi\rangle \otimes |\phi\rangle \equiv |\psi\rangle |\phi\rangle \equiv|\psi\phi\rangle

Tensor product of Matrices​

A⊗B=(a00Ba01Ba10Ba11B)A \otimes B = \begin{pmatrix} a_{00}B & a_{01}B \\ a_{10}B & a_{11}B \end{pmatrix}

  • The tensor product ∣0⟩⟨1∣⊗∣1⟩⟨0∣|0\rangle \langle1| \otimes |1\rangle \langle0| is:

∣0⟩⟨1∣⊗∣1⟩⟨0∣=(0100)⊗(0010) |0\rangle \langle 1| \otimes |1\rangle \langle 0| = \begin{pmatrix} 0 & 1 \\ 0 & 0 \end{pmatrix} \otimes \begin{pmatrix} 0 & 0 \\ 1 & 0 \end{pmatrix}

∣0⟩⟨1∣⊗∣1⟩⟨0∣=(0⋅(0010)1⋅(0010)0⋅(0010)0⋅(0010))=(0000001000000000)|0\rangle \langle 1| \otimes |1\rangle \langle 0| = \begin{pmatrix} 0 \cdot \begin{pmatrix} 0 & 0 \\ 1 & 0 \end{pmatrix} & 1 \cdot \begin{pmatrix} 0 & 0 \\ 1 & 0 \end{pmatrix} \\ 0 \cdot \begin{pmatrix} 0 & 0 \\ 1 & 0 \end{pmatrix} & 0 \cdot \begin{pmatrix} 0 & 0 \\ 1 & 0 \end{pmatrix} \end{pmatrix} = \begin{pmatrix} 0 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 \end{pmatrix}

  • To short hand this, we can write:

∣0⟩⟨1∣⊗∣1⟩⟨0∣≡∣0⟩∣1⟩⟨1∣⟨0∣≡∣01⟩⟨10∣|0\rangle \langle 1| \otimes |1\rangle \langle 0| \equiv |0\rangle|1\rangle \langle 1| \langle 0| \equiv |01\rangle \langle 10|

  • (∣a⟩⟨b∣)⊗(∣c⟩⟨d∣)=(∣a⟩∣c⟩)(⟨b∣⟨d∣)=∣ac⟩⟨bd∣(|a\rangle \langle b|) \otimes (|c\rangle \langle d|) = (|a\rangle |c\rangle)(\langle b| \langle d|) = |ac\rangle \langle bd|

Bases​

  • The basis for a single qubit is {∣0⟩,∣1⟩}\{|0\rangle, |1\rangle\}
  • It is given by taking the tensor product of the basis for each qubit:
    • {∣0⟩⊗∣0⟩,∣0⟩⊗∣1⟩,∣1⟩⊗∣0⟩,∣1⟩⊗∣1⟩}\{|0\rangle \otimes |0\rangle, |0\rangle \otimes |1\rangle, |1\rangle \otimes |0\rangle, |1\rangle \otimes |1\rangle\}
    • For short hand, we write {∣00⟩,∣01⟩,∣10⟩,∣11⟩}\{|00\rangle, |01\rangle, |10\rangle, |11\rangle\}
  • The computational basis for two qubits is {∣00⟩,∣01⟩,∣10⟩,∣11⟩}\{|00\rangle, |01\rangle, |10\rangle, |11\rangle\}
  • For three qubits {∣000⟩,∣001⟩,∣010⟩,∣011⟩,∣100⟩,∣101⟩,∣110⟩,∣111⟩}\{|000\rangle, |001\rangle, |010\rangle, |011\rangle, |100\rangle, |101\rangle, |110\rangle, |111\rangle\}

Matrices​

{∣0⟩⟨0∣,  ∣0⟩⟨1∣,  ∣1⟩⟨0∣,  ∣1⟩⟨1∣}\{|0\rangle\langle0|,\; |0\rangle\langle1|,\; |1\rangle\langle0|,\; |1\rangle\langle1|\}

  • forms a basis for the space of 2×22 \times 2 matrices
  • operator basis: a set of matrices that can be used to express any matrix as a linear combination of the basis matrices

(abcd)=a∣0⟩⟨0∣+b∣0⟩⟨1∣+c∣1⟩⟨0∣+d∣1⟩⟨1∣\begin{pmatrix} a & b \\ c & d \end{pmatrix} = a |0\rangle\langle0| + b |0\rangle\langle1| + c |1\rangle\langle0| + d |1\rangle\langle1|

  • One of the basis elements is: ∣0⟩⟨0∣⊗∣0⟩⟨0∣=∣00⟩⟨00∣|0\rangle\langle0| \otimes |0\rangle\langle0| = |00\rangle\langle00|
  • Similarly ∣0⟩⟨0∣⊗∣0⟩⟨1∣=∣00⟩⟨01∣|0\rangle\langle0| \otimes |0\rangle\langle1| = |00\rangle\langle01|
  • In total, the tensor products yields 4×4=164 \times 4 = 16 basis elements for the space of 4×44 \times 4 matrices: {∣00⟩⟨00∣,  ∣00⟩⟨01∣,  ∣00⟩⟨10∣,  ∣00⟩⟨11∣,  ∣01⟩⟨00∣,  ∣01⟩⟨01∣,  …,  ∣11⟩⟨11∣}.\{|00\rangle\langle00|,\; |00\rangle\langle01|,\; |00\rangle\langle10|,\; |00\rangle\langle11|,\; |01\rangle\langle00|,\; |01\rangle\langle01|,\; \ldots,\; |11\rangle\langle11|\}.

The Golden Rule of Tensor Products​

What starts on the left of the tensor product says on the left

(A⊗B)(∣ψ⟩⊗∣ϕ⟩)=(A∣ψ⟩)⊗(B∣ϕ⟩)(A \otimes B)(|\psi\rangle \otimes |\phi\rangle) = (A|\psi\rangle) \otimes (B|\phi\rangle)

(∣0⟩⟨0∣⊗∣1⟩⟨1∣)(∣00⟩)=(∣0⟩⟨0∣⊗∣1⟩⟨1∣)(∣0⟩⊗∣0⟩)=(∣0⟩⟨0∣∣0⟩)⊗(∣1⟩⟨1∣∣0⟩)=∣0⟩⊗0=0(|0\rangle\langle0| \otimes |1\rangle\langle1|)(|00\rangle) \\ = (|0\rangle\langle 0| \otimes |1\rangle\langle1|)(|0\rangle \otimes |0\rangle) \\ \\ = (|0\rangle\langle0||0\rangle) \otimes (|1\rangle\langle1||0\rangle) \\ = |0\rangle \otimes 0 \\ = 0

  • ∣ψ⟩⊗∣ϕ⟩≡∣ψ⟩∣ϕ⟩≡∣ψϕ⟩ |\psi\rangle \otimes |\phi\rangle \equiv |\psi\rangle|\phi\rangle \equiv |\psi\phi\rangle
  • (∣ψ⟩⊗∣ϕ⟩)†=⟨ψ∣⊗⟨ϕ∣(|\psi\rangle \otimes |\phi\rangle)^\dagger = \langle\psi| \otimes \langle\phi|
  • (α∣ψ⟩+β∣ϕ⟩)⊗∣ω⟩=α∣ψ⟩⊗∣ω⟩+β∣ϕ⟩⊗∣ω⟩(\alpha|\psi\rangle + \beta|\phi\rangle) \otimes |\omega\rangle = \alpha|\psi\rangle \otimes |\omega\rangle + \beta|\phi\rangle \otimes |\omega\rangle
  • ((⟨ψ∣⊗⟨ϕ∣)(∣ω⟩⊗∣η⟩))=⟨ψ∣ω⟩⟨ϕ∣η⟩((\langle\psi| \otimes \langle\phi|)(|\omega\rangle \otimes |\eta\rangle)) = \langle\psi|\omega\rangle \langle\phi|\eta\rangle
  • (A+B)⊗C=A⊗C+B⊗C(A + B) \otimes C = A \otimes C + B \otimes C
  • A⊗(B+C)=A⊗B+A⊗CA \otimes (B + C) = A \otimes B + A \otimes C
  • (A⊗B)(C⊗D)=AC⊗BD(A \otimes B)(C \otimes D) = AC \otimes BD
  • (A⊗B)†=A†⊗B†(A \otimes B)^\dagger = A^\dagger \otimes B^\dagger

Entanglement​

  • Single-qubit state is a two dimensional vector: ∣ψ⟩=α∣0⟩+β∣1⟩|\psi\rangle = \alpha|0\rangle + \beta|1\rangle
  • where α\alpha and β\beta are complex numbers such that ∥∣ψ⟩∥2=∣α∣2+∣β∣2=1\||\psi\rangle\|^2 = |\alpha|^2 + |\beta|^2 = 1
  • Two qubits ψ1⟩\psi_1\rangle and ψ2⟩\psi_2\rangle can be combined to form a four-dimensional vector: ∣ψ12⟩=∣ψ1⟩⊗∣ψ2⟩≡∣ψ1⟩∣ψ2⟩≡∣ψ1ψ2⟩ |\psi_{12}\rangle = |\psi_1\rangle \otimes |\psi_2\rangle \equiv |\psi_1\rangle|\psi_2\rangle \equiv |\psi_1\psi_2\rangle
  • Separable States: can be written as a tensor product of single-qubit states
    • ∣Ψ⟩=α00∣00⟩+α01∣01⟩+α10∣10⟩+α11∣11⟩=∣ψ1⟩∣⊗ψ2⟩|\Psi\rangle = \alpha_{00} |00\rangle + \alpha_{01} |01\rangle + \alpha_{10} |10\rangle + \alpha_{11} |11\rangle \\ = |\psi_1\rangle| \otimes \psi_2\rangle
  • if the state is not separable, it is called entangled.
    • entangled: 12(∣00⟩+∣11⟩)\frac{1}{\sqrt{2}}(|00\rangle + |11\rangle)
  • if ad=0ad = 0 and bc=0bc = 0, then acac or bdbd must also vanish.
    • separable: 12(∣00⟩+∣01⟩)=∣0⟩⊗12(∣0⟩+∣1⟩)\frac{1}{2}(|00\rangle + |01\rangle) = |0\rangle \otimes \frac{1}{\sqrt{2}}(|0\rangle + |1\rangle)

Two-Qubit Gates​

  • Two-qubit gates are 4×44 \times 4 unitary matrices that act on two-qubit states.

CNOT Gate​

Controlled NOT gate

  • flips target if control is ∣1⟩|1\rangle

CNOT=(1000010000010010)=∣0⟩⟨0∣⊗I+∣1⟩⟨1∣⊗X\text{CNOT} = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 \end{pmatrix} = |0\rangle\langle0| \otimes \mathbb I + |1\rangle\langle1| \otimes X

SWAP Gate​

  • Exchanges the two qubits.

SWAP=(1000001001000001)\text{SWAP} = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix}

CZ Gate​

Controlled Z gate

  • Applies ZZ to target if control is ∣1⟩|1\rangle

CZ=(100001000010000−1) \text{CZ} = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & -1 \end{pmatrix}

Building Multi-Qubit Gates​

  • Two qubits ∣ψ1⟩|\psi_1\rangle and ∣ψ2⟩|\psi_2\rangle can be combined to form a four-dimensional vector:
    • if U1U_1 and U2U_2 are single-qubit gates, then U1⊗U2U_1 \otimes U_2 is a two-qubit gate that acts on the combined state ∣ψ1⟩⊗∣ψ2⟩|\psi_1\rangle \otimes |\psi_2\rangle.
    • (U1⊗U2)(∣ψ1⟩⊗∣ψ2⟩)=(U1∣ψ1⟩)⊗(U2∣ψ2⟩)(U_1 \otimes U_2)(|\psi_1\rangle \otimes |\psi_2\rangle) = (U_1|\psi_1\rangle) \otimes (U_2|\psi_2\rangle)
    • For shorthand, U1U2∣ψ1ψ2⟩U_1 U_2|\psi_1\psi_2\rangle

Order of Operations​

  • When gates act independently, it doesn't matter the order in which they are apply with the understanding that if only a single gate is applied, identity acts on the other qubits.

(U1⊗U2)=(I⊗U2)(U1⊗I)=(U1⊗I)(I⊗U2)(U_1 \otimes U_2) = (\mathbb I \otimes U_2)(U_1 \otimes \mathbb I) = (U_1 \otimes \mathbb I)(\mathbb I \otimes U_2)

  • Example: Apply XX to qubit 1 and HH to qubit 2, starting with ∣00⟩|00\rangle:
  • (X⊗I)∣00⟩=∣10⟩ (X \otimes \mathbb I)|00\rangle = |10\rangle
  • (I⊗H)∣10⟩=(I⊗H)(∣1⟩⊗∣0⟩)=∣1⟩⊗H∣0⟩=∣1⟩⊗12(∣0⟩+∣1⟩)=12(∣1⟩⊗∣0⟩+∣1⟩⊗∣1⟩)=12(∣10⟩+∣11⟩)(\mathbb I \otimes H)|10\rangle \\ = (\mathbb I \otimes H)(|1\rangle \otimes |0\rangle) \\ = |1\rangle \otimes H|0\rangle \\ = |1\rangle \otimes \frac{1}{\sqrt{2}}(|0\rangle + |1\rangle) \\ = \frac{1}{\sqrt{2}}(|1\rangle \otimes |0\rangle + |1\rangle \otimes |1\rangle) \\ = \frac{1}{\sqrt{2}}(|10\rangle + |11\rangle)

Quantum Circuits​

  • A quantum program is a sequance of gates applied to qubits, which are typically assumed to be initialized in the state ∣0⟩|0\rangle.
  • Two qubits start in the state ∣0⟩⊗∣0⟩=∣00⟩|0\rangle \otimes |0\rangle = |00\rangle

Hadamard and CNOT Circuit

CNOT(H⊗I)∣00⟩=CNOT(12(∣00⟩+∣10⟩))=12(∣00⟩+∣11⟩)CNOT(H \otimes \mathbb I)|00\rangle = CNOT\left(\frac{1}{\sqrt{2}}(|00\rangle + |10\rangle)\right) = \frac{1}{\sqrt{2}}(|00\rangle + |11\rangle)

NameGatesMatrix
Pauli-XXX or ⊕\oplus(0110)\begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix}
Pauli-YYY(0−ii0)\begin{pmatrix} 0 & -i \\ i & 0 \end{pmatrix}
Pauli-ZZZ(100−1)\begin{pmatrix} 1 & 0 \\ 0 & -1 \end{pmatrix}
Rotation-XRx(θ)R_x(\theta)(cos⁡θ2−isin⁡θ2−isin⁡θ2cos⁡θ2)\begin{pmatrix} \cos\frac{\theta}{2} & -i\sin\frac{\theta}{2} \\ -i\sin\frac{\theta}{2} & \cos\frac{\theta}{2} \end{pmatrix}
Rotation-YRy(θ)R_y(\theta)(cos⁡θ2sin⁡θ2−sin⁡θ2cos⁡θ2)\begin{pmatrix} \cos\frac{\theta}{2} & \sin\frac{\theta}{2} \\ -\sin\frac{\theta}{2} & \cos\frac{\theta}{2} \end{pmatrix}
Rotation-ZRz(θ)R_z(\theta)(eiθ/200e−iθ/2)\begin{pmatrix} e^{i\theta/2} & 0 \\ 0 & e^{-i\theta/2} \end{pmatrix}
Phase ShiftPh(δ)Ph(\delta)(100eiδ)\begin{pmatrix} 1 & 0 \\ 0 & e^{i\delta} \end{pmatrix}
HadamardHH12(111−1)\frac{1}{\sqrt{2}}\begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix}
PhaseSS(100i)\begin{pmatrix} 1 & 0 \\ 0 & i \end{pmatrix}
TTT(100eiπ/4)\begin{pmatrix} 1 & 0 \\ 0 & e^{i\pi/4} \end{pmatrix}
  • S=Ph(π/2)S = Ph(\pi/2)
  • T=Ph(π/4)T = Ph(\pi/4)
  • Z=Ph(π)Z = Ph(\pi)

Multi-Qubit Gates​

NameGatesMatrix
CNOTCNOT(1000010000010010)\begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 \end{pmatrix}
CZCZ(100001000010000−1)\begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & -1 \end{pmatrix}
SWAPSWAP(1000001001000001)\begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix}
ToffoliToffoli(1000000001000000001000000001000000001000000001000000000100000010)\begin{pmatrix} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \end{pmatrix}
  • CNOT gate can be ∣0⟩⟨0∣⊗I+∣1⟩⟨1∣⊗X|0\rangle\langle0| \otimes \mathbb I + |1\rangle\langle1| \otimes X
    • ∣0⟩state→I|0\rangle \text{state} \rightarrow \mathbb I (do nothing)
    • ∣1⟩state→X|1\rangle \text{state} \rightarrow X (flip the target)
  • Larger gates can be built from smaller ones
  • Toffoli gate (CCNOT): flips the target if both controls are ∣1⟩|1\rangle.
  • Toffoli=∣00⟩⟨00∣⊗I4+∣11⟩⟨11∣⊗X\text{Toffoli} = |00\rangle\langle00| \otimes \mathbb I_4 + |11\rangle\langle11| \otimes X
    • two control qubits and one target qubit
    • if both control qubits are ∣1⟩|1\rangle, then apply XX
    • ∣110⟩→∣111⟩|110\rangle \rightarrow |111\rangle
    • ∣111⟩→∣110⟩|111\rangle \rightarrow |110\rangle
  • Can be generalized to nn-qubits: Cn−1NOTC^{n-1}NOT gate, which flips the target if all n−1n-1 control qubits are ∣1⟩|1\rangle.
    • CNOT: ∣10⟩→∣11⟩|10\rangle \rightarrow |11\rangle and ∣11⟩→∣10⟩|11\rangle \rightarrow |10\rangle
    • Toffoli: ∣110⟩→∣111⟩|110\rangle \rightarrow |111\rangle and ∣111⟩→∣110⟩|111\rangle \rightarrow |110\rangle
    • 3-control gate: ∣1110⟩→∣1111⟩|1110\rangle \rightarrow |1111\rangle and ∣1111⟩→∣1110⟩|1111\rangle \rightarrow |1110\rangle

(I−∣111…⟩⟨111…∣)⊗I+∣111…⟩⟨111…∣⊗U(\mathbb I - |111\ldots\rangle\langle 111\ldots|)\otimes \mathbb I + |111\ldots\rangle\langle 111\ldots|\otimes U

The Rules of Quantum Computing​

Initialization​

  • An nn-qubit computation starts in the all-zero state:

∣phi⟩=∣0⟩⊗∣0⟩⊗…⊗∣0⟩=∣00…0⟩|phi\rangle = |0\rangle \otimes |0\rangle \otimes \ldots \otimes |0\rangle = |00\ldots0\rangle

Algorithm​

  • Apply a sequence of unitary gates to obtain the final state:

U=U1U2…Um  ⟹  U∣ψ⟩U = U_1U_2\ldots U_m \implies U|\psi\rangle

Measurement​

The Born Rule

  • Reading nn qubits producs nn classical bits.
  • The probability of outcome b1b2…bnb_1b_2\ldots b_n:

Pr(b1b2…bn)=∣⟨b1b2…bn∣ψ⟩∣2Pr(b_1b_2\ldots b_n) = |\langle b_1b_2\ldots b_n|\psi\rangle|^2

  • ∣ψ⟩|\psi\rangle: initial state of the system
  • UU: an unitary matrix summing up the gates applied to the system
  • U∣ψ⟩U|\psi\rangle: final state of the system
  • ⟨b1b2…bn∣U∣ψ⟩\langle b_1b_2\ldots b_n|U|\psi\rangle: the amplitude of the outcome b1b2…bnb_1b_2\ldots b_n
  • ∣amplitude∣2|\text{amplitude}|^2: The probability of the outcome b1b2…bnb_1b_2\ldots b_n being observed when measuring the system
    • if 12(∣00⟩+∣11⟩)\frac{1}{\sqrt{2}}(|00\rangle + |11\rangle)
    • then Pr(00)=Pr(11)=12Pr(00) = Pr(11) = \frac{1}{2}

Post-measurement States​

Measurement causes the state to collapse

  • Measuring all qubits: outcome b1…bnb_1 \ldots b_n collapses state to ∣b1…bn⟩|b_1 \ldots b_n\rangle
  • Measuring a subset: keep matching terms and renormalize.

∣ψ⟩=c00…0∣00…0⟩+c00…1∣00…1⟩+…+c11…1∣11…1⟩|\psi\rangle = c_{00\ldots0}|00\ldots0\rangle + c_{00\ldots1}|00\ldots1\rangle + \ldots + c_{11\ldots1}|11\ldots1\rangle

  • If we measure all qubits, we get outcome b1b2…bnb_1b_2\ldots b_n
    • The state will collapse to ∣ψ′⟩=∣b1b2…bn⟩|\psi'\rangle = |b_1b_2\ldots b_n\rangle
    • The probability of this outcome is Pr(b1b2…bn)=∣⟨b1b2…bn∣ψ⟩∣2Pr(b_1b_2\ldots b_n) = |\langle b_1b_2\ldots b_n|\psi\rangle|^2

∣ψ⟩=α∣00⟩+β∣01⟩+γ∣10⟩+δ∣11⟩|\psi\rangle = \alpha|00\rangle + \beta|01\rangle + \gamma|10\rangle + \delta|11\rangle

  • If we measure only the first qubit, and get outcome 00, the state maintains only terms with 00 in the first position:
    • ∣00⟩|00\rangle and ∣01⟩|01\rangle
    • The remaining state is ∣ψ′⟩=α∣00⟩+β∣01⟩|\psi'\rangle = \alpha|00\rangle + \beta|01\rangle
    • ∣10⟩|10\rangle and ∣11⟩|11\rangle are removed from the state
  • This gives us the unnormalized state: ∣ψ′⟩unnorm=α∣00⟩+β∣01⟩ |\psi'\rangle_{unnorm} = \alpha|00\rangle + \beta|01\rangle
  • The probability of this outcome is Pr(0)=∣α∣2+∣β∣2Pr(0) = |\alpha|^2 + |\beta|^2
    • ∣00⟩|00\rangle and ∣01⟩|01\rangle are the only terms that contribute to the probability of outcome 00 for the first qubit
  • After measurement, the state must be ∥∣ψ∥2=1\||\psi\|^2 = 1, so we need to renormalize the state:

∣ψ′⟩=(α∣00⟩+β∣01⟩)∣α∣2+∣β∣2|\psi'\rangle = \frac{(\alpha|00\rangle + \beta|01\rangle)}{\sqrt{|\alpha|^2 + |\beta|^2}}

QASM2.0​

Quantum GateQASM EquivalentDescription
Rx(θ)R_x(\theta)rxRotation around X-axis: rx(pi/2) q[0];
Ry(θ)R_y(\theta)ryRotation around Y-axis: ry(0) q[0];
Rz(θ)R_z(\theta)rzRotation around Z-axis: rz(pi) q[0];
XXxPauli-gate bit flip: x q[0];
ZZzPauli-gate phase flip: z q[0];
XZXZyPauli-gate bit+phase flip: y q[0];
HHhHadamard gate: h q[0];
CNOTCNOTcxControlled NOT gate: cx q[0], q[1];
SWAPSWAPswapSwap two qubit registers: swap q[0], q[1];
CZCZczControlled ZZ gate: cz q[0], q[1];

IQC 002

· 7 min read

Ket​

∣ψ⟩=(ψ0ψ1)|\psi\rangle = \begin{pmatrix} \psi_0 \\ \psi_1 \end{pmatrix}

∣0⟩=(10)|0\rangle = \begin{pmatrix} 1 \\ 0 \end{pmatrix}

∣1⟩=(01)|1\rangle = \begin{pmatrix} 0 \\ 1 \end{pmatrix}

∣ψ⟩=ψ0∣0⟩+ψ1∣1⟩=ψ0(10)+ψ1(01)|\psi\rangle = \psi_0 |0\rangle + \psi_1 |1\rangle \\ \quad = \psi_0 \begin{pmatrix} 1 \\ 0 \end{pmatrix} + \psi_1 \begin{pmatrix} 0 \\ 1 \end{pmatrix}

Matrices​

  • Matrices represent linear transformations (quantum gates). A general 2x2 matrix is: A=(α00α01α10α11)A = \begin{pmatrix} \alpha_{00} & \alpha_{01} \\ \alpha_{10} & \alpha_{11} \end{pmatrix}
  • Identity matrix: I=(1001)I = \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix}
  • Linearity: A(∣ψ⟩+∣ϕ⟩)=A∣ψ⟩+A∣ϕ⟩A(|\psi\rangle + |\phi\rangle) = A|\psi\rangle + A|\phi\rangle

Bra and Daggers​

Dagger​

  • Conjugate Transpose: swap rows/columns and complex-conjugates every entry.
  • Ket becomes Bra: ∣ψ⟩†=(ψ0ψ1)†=(ψ0‾ψ1‾)=⟨ψ∣|\psi\rangle^\dagger = \begin{pmatrix} \psi_0 \\ \psi_1 \end{pmatrix}^\dagger = \begin{pmatrix} \overline{\psi_0} & \overline{\psi_1} \end{pmatrix} = \langle\psi|
  • For a matrix: A†=(α00‾α10‾α01‾α11‾)A^\dagger = \begin{pmatrix} \overline{\alpha_{00}} & \overline{\alpha_{10}} \\ \overline{\alpha_{01}} & \overline{\alpha_{11}} \end{pmatrix}
  • Key Identities:
    • (αA)†=α‾A†(\alpha A)^\dagger = \overline{\alpha} A^\dagger
    • (A†)†=A(A^\dagger)^\dagger = A
    • (AB)†=B†A†(AB)^\dagger = B^\dagger A^\dagger

Hermitian and Unitary Matrices​

  • Hermitian: H†=HH^\dagger = H
    • Self-adjoint matrices, their eigenvalues are always real.
    • Observables in quantum mechanics are Hermitian.
  • Unitary: U†U=UU†=IU^\dagger U = UU^\dagger = I
    • The inverse of a unitary matrix is its conjugate transpose.
    • Unitary matrices preserve norms

Inner Product​

  • The angle between two vectors ∣ψ⟩|\psi\rangle and ∣ϕ⟩|\phi\rangle is defined as bra-ket: ⟨ψ∣ϕ⟩=(ψ0‾ψ1‾)(ϕ0ϕ1)=ψ0‾ϕ0+ψ1‾ϕ1\langle\psi|\phi\rangle = (\overline{\psi_0} \overline{\psi_1}) \begin{pmatrix} \phi_0 \\ \phi_1 \end{pmatrix} = \overline{\psi_0}\phi_0 + \overline{\psi_1}\phi_1
  • Important properties:
    • Order Matters: ⟨ψ∣ϕ⟩≠⟨ϕ∣ψ⟩\langle\psi|\phi\rangle \neq \langle\phi|\psi\rangle
    • But ⟨ψ∣ϕ⟩=⟨ϕ∣ψ⟩‾\langle\psi|\phi\rangle = \overline{\langle\phi|\psi\rangle} (Complex Conjugate)
    • The modulus is symmetric: ∣⟨ψ∣ϕ⟩∣=∣⟨ϕ∣ψ⟩∣|\langle\psi|\phi\rangle| = |\langle\phi|\psi\rangle|
  • The Magnitude of a vector is given by: ∥∣ψ⟩∥2=⟨ψ∣ψ⟩=∣ψ0∣2+∣ψ1∣2\| |\psi\rangle \|^2 = \langle\psi|\psi\rangle = |\psi_0|^2 + |\psi_1|^2

Orthonormal of the Computational Basis​

  • The basis states ∣0⟩|0\rangle and ∣1⟩|1\rangle are orthonormal: ⟨0∣0⟩=1,⟨1∣1⟩=1,⟨0∣1⟩=0,⟨1∣0⟩=0\langle 0|0\rangle = 1, \quad \langle 1|1\rangle = 1, \quad \langle 0|1\rangle = 0, \quad \langle 1|0\rangle = 0
  • This simplifies inner products enormously when working with the computational basis: ⟨ψ∣ϕ⟩=(ψ0‾⟨0∣+ψ1‾⟨1∣)(ϕ0∣0⟩+ϕ1∣1⟩) \langle\psi|\phi\rangle = (\overline{\psi_0}\langle0| + \overline{\psi_1}\langle1|) (\phi_0|0\rangle + \phi_1|1\rangle)
  • All corss terms vanish due to orthogonality, leaving: =ψ0‾ϕ0⟨0∣0⟩+ψ0‾ϕ1⟨0∣1⟩+ψ1‾ϕ0⟨1∣0⟩+ψ1‾ϕ1⟨1∣1⟩ = \overline{\psi_0}\phi_0 \langle0|0\rangle + \overline{\psi_0}\phi_1 \langle0|1\rangle + \overline{\psi_1}\phi_0 \langle1|0\rangle + \overline{\psi_1}\phi_1 \langle1|1\rangle =ψ0‾ϕ0+ψ1‾ϕ1= \overline{\psi_0}\phi_0 + \overline{\psi_1}\phi_1

Outer Products​

  • The outer product of two vectors produces a matrix: ∣ψ⟩⟨ϕ∣=(ψ0ψ1)(ϕ0‾ϕ1‾)=(ψ0ϕ0‾ψ0ϕ1‾ψ1ϕ0‾ψ1ϕ1‾)|\psi\rangle\langle\phi| = \begin{pmatrix} \psi_0 \\ \psi_1 \end{pmatrix} \begin{pmatrix} \overline{\phi_0} & \overline{\phi_1} \end{pmatrix} = \begin{pmatrix} \psi_0\overline{\phi_0} & \psi_0\overline{\phi_1} \\ \psi_1\overline{\phi_0} & \psi_1\overline{\phi_1} \end{pmatrix}
  • Basis outer products: ∣0⟩⟨1∣=(0100),∣1⟩⟨0∣=(0010)|0\rangle\langle1| = \begin{pmatrix} 0 & 1 \\ 0 & 0 \end{pmatrix}, \quad |1\rangle\langle0| = \begin{pmatrix} 0 & 0 \\ 1 & 0 \end{pmatrix}
  • Any matrix can be expanded in terms of outer products of the computational basis: A=α00∣0⟩⟨0∣+α01∣0⟩⟨1∣+α10∣1⟩⟨0∣+α11∣1⟩⟨1∣A = \alpha_{00} |0\rangle\langle0| + \alpha_{01} |0\rangle\langle1| + \alpha_{10} |1\rangle\langle0| + \alpha_{11} |1\rangle\langle1|

The Qubit​

A qubit is the fundamental unit of quantum information

∣ψ⟩=α∣0⟩+β∣1⟩|\psi\rangle = \alpha |0\rangle + \beta |1\rangle

  • where α,β∈C\alpha, \beta \in \mathbb{C} are complex numbers such that ∣α∣2+∣β∣2=1|\alpha|^2 + |\beta|^2 = 1 (normalization condition).
  • Any normalized single-qubit state can be parameterized using two angles θ\theta and ϕ\phi (real numbers): ∣ψ⟩=cos⁡θ∣0⟩+eiϕsin⁡θ∣1⟩|\psi\rangle = \cos\theta|0\rangle + e^{i\phi}\sin\theta|1\rangle
  • Key difference from a bit: a bit is either 0 or 1, while a qubit can be in a superposition of both states simultaneously until measured.

Measurement​

  • When you measure a qubit ∣ψ⟩=α∣0⟩+β∣1⟩|\psi\rangle = \alpha |0\rangle + \beta |1\rangle in the computational basis, you get:
    • ∣0⟩|0\rangle with probability ∣α∣2|\alpha|^2
    • ∣1⟩|1\rangle with probability ∣β∣2|\beta|^2
OutcomeProbabilityPost-measurement State
0$\alpha
1$\beta
  • The result of measuring a qubit is a single classical bit.
  • For ∣ψ⟩=cos⁡θ∣0⟩+eiϕsin⁡θ∣1⟩|\psi\rangle = \cos\theta|0\rangle + e^{i\phi}\sin\theta|1\rangle:
    • Probability of measuring ∣0⟩|0\rangle: cos⁡2θ\cos^2\theta
    • Probability of measuring ∣1⟩|1\rangle: sin⁡2θ\sin^2\theta
    • The phase ϕ\phi does not affect measurement outcomes.

One-Qubit Gates​

Pauli Matrices​

Unitary matrics

I=(1001),X=(0110),Y=(0−ii0),Z=(100−1)\mathbb{I} = \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix}, \quad X = \begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix}, \quad Y = \begin{pmatrix} 0 & -i \\ i & 0 \end{pmatrix}, \quad Z = \begin{pmatrix} 1 & 0 \\ 0 & -1 \end{pmatrix}

  • XX is the quantum NOT gate:
    • X∣0⟩=∣1⟩X|0\rangle = |1\rangle
    • X∣1⟩=∣0⟩X|1\rangle = |0\rangle
  • ZZ filps the phase of ∣1⟩|1\rangle:
    • Z∣0⟩=∣0⟩Z|0\rangle = |0\rangle
    • Z∣1⟩=−∣1⟩Z|1\rangle = -|1\rangle
  • All three (X,Y,Z)(X, Y, Z) are both Hermitian and unitary.

Hadamard Gate​

H=12(111−1)H = \frac{1}{\sqrt{2}} \begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix}

  • HH creates superpositions:
    • H∣0⟩=∣0⟩+∣1⟩2H|0\rangle = \frac{|0\rangle + |1\rangle}{\sqrt{2}}
    • H∣1⟩=∣0⟩−∣1⟩2H|1\rangle = \frac{|0\rangle - |1\rangle}{\sqrt{2}}
  • HH also "un-does" superpositions:
    • H(∣0⟩+∣1⟩2)=∣0⟩H\left(\frac{|0\rangle + |1\rangle}{\sqrt{2}}\right) = |0\rangle
    • H(∣0⟩−∣1⟩2)=∣1⟩H\left(\frac{|0\rangle - |1\rangle}{\sqrt{2}}\right) = |1\rangle

Rotation Gate​

R(θ)=(cos⁡θsin⁡θ−sin⁡θcos⁡θ)R(\theta) = \begin{pmatrix} \cos\theta & \sin\theta \\ -\sin\theta & \cos\theta \end{pmatrix}

  • R(θ)R(\theta) rotates the state vector by an angle θ\theta in the ∣0⟩|0\rangle-∣1⟩|1\rangle plane.

The Bloch Sphere​

Every single-qubit state ∣ψ⟩=cos⁡θ∣0⟩+eiϕsin⁡θ∣1⟩|\psi\rangle = \cos\theta|0\rangle + e^{i\phi}\sin\theta|1\rangle maps to a point on the surface of a unit sphere

  • θ\theta is polar angle from north pole
  • ϕ\phi is azimuthal angle around equator
  • ∣0⟩|0\rangle is at the north pole
  • ∣1⟩|1\rangle is at the south pole
  • ∣0⟩+∣1⟩2\frac{|0\rangle + |1\rangle}{\sqrt{2}} is on the equator at ϕ=0\phi=0

Exercises​

  1. For any two-dimensional state vector ∣ψ⟩=α∣0⟩+β∣1⟩|\psi\rangle = \alpha |0\rangle + \beta |1\rangle, it holds that ∣α∣2+∣β∣2=1|\alpha|^2 + |\beta|^2 = 1.
  2. Measuring a qubit in the {∣0⟩,∣1⟩}\{|0\rangle, |1\rangle\} basis yields a probabilistic outcome when both α\alpha and β\beta are non-zero.
  3. A global phase factor eiγe^{i\gamma} applied to a qubit state does not change the probabilities of measurement outcomes in the computational basis.
  4. The Bloch sphere represents all pure single-qubit states as points on the surface of the sphere.
  5. A real 2×22 \times 2 matrix is a valid quantum gate only if it is unitary, not merely invertible.
  6. The Pauli-X gate flips ∣0⟩|0\rangle to ∣1⟩|1\rangle and ∣1⟩|1\rangle to ∣0⟩|0\rangle.
  7. When a qubit is measured in a given basis, the state collapses to the basis state corresponding to the measurement outcome.
  8. Unitary matrices preserve the norm of any vector they act on.
  9. If ∣ψ⟩=cos⁡(θ)∣0⟩+eiϕsin⁡(θ)∣1⟩|\psi\rangle = \cos(\theta)|0\rangle + e^{i\phi}\sin(\theta)|1\rangle, then the probability of measuring ∣0⟩|0\rangle is cos⁡2(θ)\cos^2(\theta).
  10. The state 12∣0⟩+32∣1⟩\frac{1}{2}|0\rangle + \frac{\sqrt{3}}{2}|1\rangle is properly normalized.
  11. If ∣ψ⟩=13∣0⟩+23eiπ/4∣1⟩|\psi\rangle = \frac{1}{\sqrt{3}}|0\rangle + \sqrt{\frac{2}{3}} e^{i\pi/4}|1\rangle, then the probability of measuring ∣0⟩|0\rangle is 13\frac{1}{3}.
  12. The states 12(∣0⟩+∣1⟩)\frac{1}{\sqrt{2}}(|0\rangle + |1\rangle) and 12(∣0⟩−∣1⟩)\frac{1}{\sqrt{2}}(|0\rangle - |1\rangle) are orthogonal.
  13. The Pauli-X matrix X=(0110)X = \begin{pmatrix}0 & 1 \\ 1 & 0\end{pmatrix} satisfies X2=IX^2 = I, where II is the 2×22 \times 2 identity matrix.
  14. Applying the Pauli-Z gate Z=(100−1)Z = \begin{pmatrix}1 & 0 \\ 0 & -1\end{pmatrix} to 12(∣0⟩+i∣1⟩)\frac{1}{\sqrt{2}}(|0\rangle + i|1\rangle) produces 12(∣0⟩−i∣1⟩)\frac{1}{\sqrt{2}}(|0\rangle - i|1\rangle).