Quantum Mechanics for Computer Science

Chapter 8
Quantum Circuits, Control and Information Protocols

Diploma in Quantum Computing
Quantum Mechanics for Computer Science   •   Diploma

Quantum Circuits, Control and Information Protocols

Introduction

Quantum algorithms are implemented as sequences of elementary operations on qubits. A circuit specifies not only which gates are applied, but also their order, their control conditions, the initial state, and the point at which measurement occurs. This chapter develops the practical skills needed to design and trace circuits containing controlled gates, SWAP operations, state preparation, and measurement. It then applies those skills to quantum teleportation, superdense coding, and interference-based protocols.

A quantum circuit is not a flowchart of definite bit values. Until measurement, a qubit may be in a superposition, and a multi-qubit register may contain entanglement. Consequently, circuit analysis requires amplitudes, tensor products, unitary operators, and probabilistic measurement rules.

Learning objectives

By the end of this chapter, you should be able to:

  • represent one- and multi-qubit states using Dirac notation and vectors;
  • explain the operation of controlled gates and the SWAP gate;
  • prepare, trace, and measure simple quantum states;
  • distinguish state evolution from classical measurement results;
  • explain and trace quantum teleportation and superdense coding;
  • use interference to understand phase kickback and simple algorithmic tests;
  • identify implementation limitations, sources of error, and responsible uses of quantum information systems.

1. Circuit notation and state representation

A qubit has computational basis states |0⟩ and |1⟩. A general pure state is

|ψ⟩ = α|0⟩ + β|1⟩

where α and β are complex amplitudes satisfying

|α|² + |β|² = 1

The squared magnitudes are probabilities: measuring |ψ⟩ in the computational basis produces 0 with probability |α|² and 1 with probability |β|². Measurement changes the state to the observed basis state.

For two qubits, the computational basis is |00⟩, |01⟩, |10⟩, and |11⟩. The order convention must be stated. Here, the left symbol is the first, or most significant, qubit. Thus

|ψ⟩ = a|00⟩ + b|01⟩ + c|10⟩ + d|11⟩

with |a|² + |b|² + |c|² + |d|² = 1. In column-vector form, using the ordering above,

|ψ⟩ = [a, b, c, d]ᵀ

The tensor product combines systems. If |u⟩ = u₀|0⟩ + u₁|1⟩ and |v⟩ = v₀|0⟩ + v₁|1⟩, then

|u⟩⊗|v⟩ = u₀v₀|00⟩ + u₀v₁|01⟩ + u₁v₀|10⟩ + u₁v₁|11⟩

This expression describes a separable state. Some states, such as (|00⟩ + |11⟩)/√2, cannot be written as a tensor product of two single-qubit states and are entangled.

Common single-qubit gates

The Pauli-X gate is the quantum analogue of a bit flip:

X|0⟩ = |1⟩, X|1⟩ = |0⟩

The Hadamard gate creates and removes equal superpositions:

H|0⟩ = (|0⟩ + |1⟩)/√2
H|1⟩ = (|0⟩ − |1⟩)/√2

The Pauli-Z gate changes phase but not computational-basis value:

Z|0⟩ = |0⟩, Z|1⟩ = −|1⟩

A phase is not directly visible in a computational-basis measurement, but relative phase affects later interference. This distinction is central to quantum computing.

2. Controlled operations

A controlled gate applies a target operation only when a control qubit has a specified value. The controlled-NOT, or CNOT, applies X to the target when the control is |1⟩:

CNOT|00⟩ = |00⟩
CNOT|01⟩ = |01⟩
CNOT|10⟩ = |11⟩
CNOT|11⟩ = |10⟩

For a general two-qubit state,

CNOT(a|00⟩ + b|01⟩ + c|10⟩ + d|11⟩)
= a|00⟩ + b|01⟩ + c|11⟩ + d|10⟩

The control is not measured in order to decide whether the gate operates. The gate acts coherently on both branches of a superposition. For example,

CNOT[(|00⟩ + |10⟩)/√2] = (|00⟩ + |11⟩)/√2

This creates a Bell state.

A controlled-Z gate applies Z to the target when the control is 1. Its only computational-basis sign change is

CZ|11⟩ = −|11⟩

while |00⟩, |01⟩, and |10⟩ remain unchanged. The CZ gate is symmetric with respect to its two qubits, whereas CNOT has a directional control-target distinction.

More generally, a controlled-U operation has the form

CU = |0⟩⟨0|⊗I + |1⟩⟨1|⊗U

where I is the identity and U is a unitary operation. This expression shows that the operation is conditional in the computational basis but remains a single coherent unitary transformation.

3. SWAP operations and routing

The SWAP gate exchanges two qubit states:

SWAP|a,b⟩ = |b,a⟩

Its action on basis states is |00⟩→|00⟩, |01⟩→|10⟩, |10⟩→|01⟩, and |11⟩→|11⟩. For arbitrary states, it exchanges the complete quantum states, including phase and entanglement relationships.

A SWAP can be decomposed into three CNOT gates:

SWAP = CNOT₁→₂ · CNOT₂→₁ · CNOT₁→₂

The rightmost operation is applied first under the usual operator convention. This decomposition is useful because many hardware platforms provide CNOT-like interactions but not a native SWAP gate. However, three two-qubit gates generally introduce more noise than one native operation.

Worked example: tracing a SWAP

Suppose the input is |ψ⟩⊗|1⟩, where |ψ⟩ = α|0⟩ + β|1⟩. The input is

α|01⟩ + β|11⟩

After SWAP, the state becomes

α|10⟩ + β|11⟩ = |1⟩⊗|ψ⟩

Thus the unknown state has moved from the first wire to the second without being measured.

4. State preparation and measurement

State preparation begins with a known initialization, commonly |0⟩ for every qubit. Applying gates produces the desired state. For example, H prepares |+⟩:

|+⟩ = (|0⟩ + |1⟩)/√2

Applying X after H prepares |−⟩ only up to a global phase convention depending on the sequence; directly, H|1⟩ gives |−⟩ = (|0⟩ − |1⟩)/√2.

A measurement basis can be changed by applying a basis transformation before computational measurement. To measure in the X basis {|+⟩, |−⟩}, apply H and then measure in the computational basis. To measure in the Y basis, an appropriate phase gate followed by H is used.

For a state |ψ⟩ and projector P, the probability of the corresponding outcome is

p = ⟨ψ|P|ψ⟩

where P satisfies P² = P and P† = P. For computational measurement of a normalized state ∑ₓ aₓ|x⟩, the probability of x is |aₓ|². Repeating a circuit many times, or shots, estimates these probabilities; it does not reveal the amplitudes from one run.

A global phase has no physical effect: |ψ⟩ and e^{iφ}|ψ⟩ produce identical measurement statistics for every measurement. A relative phase between components is physically meaningful because it can change interference.

5. Interference and phase kickback

Interference results when amplitudes associated with the same final state combine. Their signs and complex phases can cause constructive or destructive interference. A simple example is

H|0⟩ = |+⟩, H|+⟩ = |0⟩

The second H does not produce a random result because the two paths recombine constructively for |0⟩ and destructively for |1⟩.

For a phase oracle U_f acting as U_f|x⟩ = (−1)^{f(x)}|x⟩, preparing |+⟩ and applying the oracle gives a phase-encoded state. A final H converts this phase information into measurable computational-basis information. This is the basic pattern behind the Deutsch algorithm and many larger algorithms: prepare a superposition, apply a phase-dependent operation, and recombine amplitudes.

In a controlled-U circuit, an eigenstate |u⟩ satisfying U|u⟩ = e^{iθ}|u⟩ can transfer the phase e^{iθ} to a control superposition. This phenomenon, called phase kickback, is important in phase estimation and oracle-based algorithms.

6. Quantum teleportation

Quantum teleportation transfers an unknown qubit state using a shared entangled pair, two classical bits, and a correction operation. It does not transmit matter or information faster than light, and it does not clone the input state. The original state is destroyed by the sender's measurement.

Let Alice possess the unknown state

|ψ⟩ = α|0⟩ + β|1⟩

and let Alice and Bob share the Bell state

|Φ⁺⟩ = (|00⟩ + |11⟩)/√2

The combined state can be rearranged in the Bell basis of Alice's two qubits:

|ψ⟩|Φ⁺⟩ = 1/2 [
|Φ⁺⟩(α|0⟩ + β|1⟩) +
|Φ⁻⟩(α|0⟩ − β|1⟩) +
|Ψ⁺⟩(β|0⟩ + α|1⟩) +
|Ψ⁻⟩(β|0⟩ − α|1⟩)
]

where |Φ±⟩ = (|00⟩ ± |11⟩)/√2 and |Ψ±⟩ = (|01⟩ ± |10⟩)/√2. Alice measures her two qubits in the Bell basis. Each result has probability 1/4, assuming a normalized input state. Depending on the two classical bits received, Bob applies one of I, X, Z, or XZ. The correction recovers |ψ⟩, possibly differing only by an irrelevant global phase.

A standard circuit creates the Bell pair using H followed by CNOT, then uses a CNOT from the input to Alice's entangled qubit and H on the input before measurement. The measurement outcomes control Bob's corrections:

Alice's bitsBob's correction
00I
01X
10Z
11XZ, equivalently ZX up to global phase

Teleportation demonstrates entanglement, conditional operations, classical communication, and the no-cloning principle in one protocol.

7. Superdense coding

Superdense coding reverses the resource balance of teleportation. If Alice and Bob share a Bell pair, Alice can communicate two classical bits by transmitting only one qubit, provided the entangled pair was previously distributed.

Start with |Φ⁺⟩. Alice encodes a two-bit message by applying a local operation to her qubit:

MessageAlice's operationResult
00I
01X
10Z
11XZ

Alice sends her qubit to Bob. Bob performs a Bell-basis measurement, usually CNOT followed by H and computational measurements. The four Bell states map to four distinct two-bit outcomes, allowing Bob to identify the message in an ideal noiseless circuit.

The protocol does not violate communication limits. The entangled pair is a prior resource, and one physical qubit must still be transmitted. Entanglement increases the information capacity of the transmitted qubit under the protocol's assumptions; it does not permit faster-than-light signalling.

8. A worked protocol trace

Consider teleporting |+⟩ = (|0⟩ + |1⟩)/√2. Alice's input is |+⟩ and the shared pair is |Φ⁺⟩. The Bell-basis decomposition shows that the possible measurement outcomes are equally likely, but Bob's conditional state is one of |+⟩ or X|+⟩ for bit-flip-related outcomes and one of Z|+⟩ or XZ|+⟩ for phase-related outcomes. Since X|+⟩ = |+⟩ and Z|+⟩ = |−⟩, Bob obtains |+⟩ after applying the correction specified by Alice's two bits. Measuring Bob directly in the computational basis then gives 0 or 1 with probability 1/2, while measuring in the X basis gives the + outcome with probability 1.

This example illustrates why the measurement basis matters. The state is not “random” in every basis: computational measurement is random, whereas an X-basis measurement is deterministic.

9. Applied case: a small hardware-compatible communication demonstrator

Background

An illustrative university laboratory has a three-qubit superconducting processor with nearest-neighbour connectivity. Students must demonstrate teleportation, but the input and receiver qubits are not directly connected.

Problem

A direct three-qubit teleportation circuit would require a non-native interaction. Additional gates may increase readout and gate errors, making it difficult to distinguish protocol failure from hardware noise.

Analysis and approach

The team maps the qubits so that the entangled pair occupies adjacent hardware sites. Where a logical wire must cross another site, the compiler inserts a SWAP, decomposed into three CNOTs. Students first run calibration circuits: repeated measurement of |0⟩ and |1⟩ estimates readout confusion, while repeated Bell-state preparation estimates two-qubit-gate performance. They then execute teleportation for |0⟩, |1⟩, |+⟩, and |−⟩, collecting many shots for each input and measurement basis.

The classical feed-forward corrections are applied either dynamically, if supported, or reconstructed in software by sorting results according to Alice's measured bits. The team compares Bob's corrected output distributions with the ideal distributions and reports the number of added SWAP gates.

Outcome

The experiment should show that computational-basis inputs are transferred with high probability, while superposition inputs are more sensitive to phase errors and decoherence. A result below the ideal fidelity is not evidence that teleportation theory fails; it reflects imperfect gates, measurement error, idle-qubit decoherence, crosstalk, and finite sampling.

Learning points

  • Logical circuit design must be separated from hardware mapping.
  • Entanglement and classical control are both essential.
  • Verification requires a defined measurement basis and an error model.
  • Gate count and connectivity affect practical performance.

10. Implementation, governance, and limitations

Real devices are noisy intermediate-scale quantum systems. Important error sources include relaxation, dephasing, imperfect calibration, crosstalk, leakage outside the computational subspace, and readout error. A circuit with fewer and shorter two-qubit operations is often preferable, but circuit depth is not the only metric: connectivity, scheduling, calibration quality, and measurement strategy also matter.

Best practices include fixing a qubit-order convention, documenting control and target wires, checking normalization after symbolic transformations, testing basis states before arbitrary states, comparing ideal simulation with hardware results, and using sufficient shots with uncertainty reported. Results should not be described as proof of a quantum advantage merely because a quantum circuit produced a nonclassical distribution.

Quantum communication also raises governance issues. Entanglement-based protocols can improve communication functionality, but they do not automatically provide authentication, confidentiality, or resistance to all attacks. Practical deployments require authenticated classical channels, trusted or characterized devices, key-management procedures where cryptography is involved, and careful treatment of experimental data. Quantum technologies should be assessed for dual-use risks, privacy implications, supply-chain dependence, and equitable access.

Contemporary development is moving toward hardware-aware compilation, error mitigation, mid-circuit measurement, dynamic circuits, and eventually fault-tolerant logical qubits. These developments do not alter the foundational rules used in this chapter; they improve how reliably those rules can be implemented.

Chapter Summary

Quantum circuits manipulate amplitudes coherently through unitary gates and convert amplitudes into classical data through measurement. Controlled gates apply operations conditionally without measuring the control, while SWAP exchanges quantum states and can be synthesized from three CNOT gates. State preparation, basis choice, and relative phase determine observed interference patterns.

Teleportation uses a shared Bell pair, two classical measurement bits, and conditional corrections to transfer an unknown state without cloning or superluminal communication. Superdense coding uses a shared Bell pair to encode two classical bits into one transmitted qubit. Both protocols demonstrate that entanglement is a resource whose value depends on carefully coordinated quantum and classical operations.

Practical circuit design must account for qubit ordering, hardware connectivity, gate count, noise, calibration, measurement statistics, and governance. The most reliable workflow is to derive the ideal state evolution first, map it to available hardware second, and evaluate experimental results against an explicit ideal model.

Key Terms

Qubit: A two-level quantum information system.

Amplitude: A complex coefficient whose squared magnitude determines measurement probability.

Tensor product: Mathematical operation combining state spaces of separate systems.

Controlled gate: A gate applied to a target conditional on a control state.

CNOT: A controlled-X gate that flips the target when the control is 1.

Controlled-Z: A controlled phase-flip gate that changes the sign of |11⟩.

SWAP gate: A two-qubit operation that exchanges their quantum states.

Entanglement: A non-separable relationship between quantum systems.

Bell state: One of four maximally entangled two-qubit states.

Measurement: A process producing classical outcomes and projecting the state.

Projector: An operator representing a measurement subspace.

Global phase: A common phase factor with no observable effect.

Relative phase: A phase difference that can affect interference.

Interference: Combination of amplitudes that may enhance or cancel outcomes.

Phase kickback: Transfer of an eigenvalue phase to a control superposition.

Quantum teleportation: Entanglement-assisted transfer of an unknown state.

Superdense coding: Entanglement-assisted transmission of two classical bits using one qubit.

Feed-forward: Applying later operations based on earlier measurement results.

Circuit depth: Number of sequential gate layers in a circuit.

Readout error: Incorrect classical recording of a measured quantum state.

Review Questions

Short Answer Questions

  1. What probability is obtained when measuring |ψ⟩ = α|0⟩ + β|1⟩ and obtaining 1?
  2. What is the action of a CNOT on |11⟩?
  3. Why is relative phase observable but global phase unobservable?
  4. How many classical bits does Alice send in standard teleportation?
  5. How many CNOT gates decompose a SWAP gate?

Long Answer Questions

  1. Explain controlled operations using both basis-state examples and the controlled-U expression.
  2. Describe the complete quantum teleportation protocol, including entanglement preparation, measurement, classical communication, and correction.
  3. Compare teleportation and superdense coding in terms of resources and information transferred.
  4. Explain how Hadamard gates create and reveal interference.
  5. Discuss the effects of connectivity, gate decomposition, and noise on practical circuit execution.

Analytical / Application Questions

  1. Trace the circuit H on qubit 1 followed by CNOT with qubit 1 as control and qubit 2 as target, starting from |00⟩. Identify the final state and measurement probabilities.
  2. Design a circuit that prepares |−⟩ from |0⟩. Explain why the final computational-basis measurement is not sufficient to distinguish |+⟩ from |−⟩, and specify a suitable measurement procedure.
  3. A hardware compiler replaces two required SWAP gates by their CNOT decompositions. Calculate the number of additional CNOT gates and explain two practical consequences for an experiment.

Multiple Choice Questions with Answers

Question 1

What does a CNOT do to the state |10⟩ when the first qubit is the control?

A. It produces |00⟩

B. It produces |01⟩

C. It produces |11⟩

D. It produces |10⟩

Correct Answer: C. It produces |11⟩

Question 2

Which expression gives the probability of a projector measurement outcome for a normalized state |ψ⟩?

A. ⟨ψ|P|ψ⟩

B. ⟨ψ|P²|ψ⟩ + 1

C. |ψ⟩P⟨ψ|

D. P + |ψ⟩

Correct Answer: A. ⟨ψ|P|ψ⟩

Question 3

How many CNOT gates are used in the standard decomposition of a SWAP gate?

A. 1

B. 2

C. 3

D. 4

Correct Answer: C. 3

Question 4

What is the state H|0⟩?

A. |0⟩

B. |1⟩

C. (|0⟩ − |1⟩)/√2

D. (|0⟩ + |1⟩)/√2

Correct Answer: D. (|0⟩ + |1⟩)/√2

Question 5

In quantum teleportation, what must Bob receive before selecting the correction operation?

A. The unknown state itself

B. Two classical measurement bits

C. A second Bell pair

D. A copy of Alice's measurement apparatus

Correct Answer: B. Two classical measurement bits

Question 6

How many classical bits can superdense coding communicate by transmitting one qubit, assuming a shared Bell pair?

A. One

B. Two

C. Three

D. Four

Correct Answer: B. Two

Question 7

Which statement about a global phase is correct?

A. It always changes computational-basis probabilities

B. It can be measured directly with one qubit

C. It has no observable effect on measurement statistics

D. It destroys entanglement

Correct Answer: C. It has no observable effect on measurement statistics

Question 8

If two SWAP gates are each decomposed into three CNOT gates, how many CNOT gates are required?

A. 3

B. 5

C. 6

D. 9

Correct Answer: C. 6

Question 9

Which operation is commonly used before computational measurement to measure in the X basis?

A. H

B. X

C. SWAP

D. CNOT

Correct Answer: A. H

Question 10

What is the principal role of interference in many quantum algorithms?

A. To copy an unknown qubit

B. To eliminate the need for measurement

C. To amplify some amplitudes and cancel others

D. To transmit information faster than light

Correct Answer: C. To amplify some amplitudes and cancel others

Quantum Mechanics for Computer Science
Chapter 8 of 14