Taking Apart A Quantum Routine Doesn't Help To Understand It
The HZH routine means applying a Hadamard gate (H), then a Pauli-Z gate (Z), then another Hadamard (H). This sequence effectively turns the Z operation into a Not (X) operation because . In other words, it flips the qubit’s state from to by rotating the Z-axis operation into the X-axis basis.
by Frank ZickertNovember 12, 2025
Looking at each part of a program individually is the usual approach when we learn a new programming language. So, if you look closely at a A quantum circuit is a sequence of quantum gates applied to qubits, representing the operations in a quantum computation. Each gate changes the qubits’ state using quantum mechanics principles like superposition and entanglement. The final qubit states, when measured, yield the circuit’s computational result probabilistically. Learn more about Quantum Circuit you will see a chain of A quantum gate is a basic operation that changes the state of one or more qubits, similar to how a logic gate operates on bits in classical computing. It uses unitary transformations, meaning it preserves the total probability (the state’s length in complex space). Quantum gates enable superposition and entanglement, allowing quantum computers to perform computations that classical ones cannot efficiently replicate. Learn more about Quantum Gate connected in series. Most examples can even be reduced to three simple A quantum gate is a basic operation that changes the state of one or more qubits, similar to how a logic gate operates on bits in classical computing. It uses unitary transformations, meaning it preserves the total probability (the state’s length in complex space). Quantum gates enable superposition and entanglement, allowing quantum computers to perform computations that classical ones cannot efficiently replicate. Learn more about Quantum Gate that reflect the A Pauli operator is one of three 2×2 complex matrices — **σₓ, σᵧ, σ_z** — that represent the basic quantum spin operations on a single qubit. They correspond to rotations or measurements along the x, y, and z axes of the Bloch sphere. Together with the identity matrix, they form a basis for all single-qubit operations in quantum mechanics. Learn more about Pauli Operator plus the The CNOT (Controlled-NOT) operator is a two-qubit quantum gate that flips the **target qubit** (applies an X gate) only if the **control qubit** is in the state (|1⟩). In matrix form, it leaves (|00⟩) and (|01⟩) unchanged, but swaps (|10⟩) and (|11⟩). It’s essential for creating entanglement between qubits. Learn more about Controlled-NOT Operator Each A quantum gate is a basic operation that changes the state of one or more qubits, similar to how a logic gate operates on bits in classical computing. It uses unitary transformations, meaning it preserves the total probability (the state’s length in complex space). Quantum gates enable superposition and entanglement, allowing quantum computers to perform computations that classical ones cannot efficiently replicate. Learn more about Quantum Gate seems to have a fixed purpose: The X-Gate flips a qubit's probability amplitudes between its two basis states, effectively exchanging their roles. It doesn’t just turn into , but rotates any quantum state halfway around the x-axis of the Bloch sphere. This means it inverts the qubit's orientation while preserving the overall shape of its state on the sphere. Learn more about X-Gate flips a A bit (short for “binary digit”) is the smallest unit of data in computing, representing a value of either 0 or 1. It’s the fundamental building block of all digital information. Multiple bits combine to form larger units like bytes (8 bits) and encode more complex data such as numbers, text, or images. Learn more about Binary DigitThe Z-gate changes the phase of the state by (or radians) while leaving the state unchanged. This means the amplitude of gains a negative sign, effectively flipping its phase. It's a phase-flip operation that rotates the quantum state vector a half turn around the Z-axis of the Bloch sphere. Learn more about Z-Gate flips a A **quantum phase** is the angle component of a particle’s wavefunction that determines how its probability amplitude interferes with others. It doesn’t affect observable probabilities directly but becomes crucial when comparing two or more states, as phase differences lead to interference effects. Essentially, it encodes the relative timing or “alignment” of quantum waves. Learn more about Quantum PhaseY Gate Learn more about Y Gate does both, and The CNOT (Controlled-NOT) operator is a two-qubit quantum gate that flips the **target qubit** (applies an X gate) only if the **control qubit** is in the state (|1⟩). In matrix form, it leaves (|00⟩) and (|01⟩) unchanged, but swaps (|10⟩) and (|11⟩). It’s essential for creating entanglement between qubits. Learn more about Controlled-NOT Operator entangles A qubit is the basic unit of quantum information, representing a superposition of 0 and 1 states. Learn more about Quantum Bit This seems clear and predictable. Until it doesn't.
This post is accompanied by a PDF file summarizing the key points.
Please Login to Download the PDF (your PyQML subscription works here!)
Unfortunately, this approach does not work well with A quantum circuit is a sequence of quantum gates applied to qubits, representing the operations in a quantum computation. Each gate changes the qubits’ state using quantum mechanics principles like superposition and entanglement. The final qubit states, when measured, yield the circuit’s computational result probabilistically. Learn more about Quantum Circuit At first sight, the The Z-gate changes the phase of the state by (or radians) while leaving the state unchanged. This means the amplitude of gains a negative sign, effectively flipping its phase. It's a phase-flip operation that rotates the quantum state vector a half turn around the Z-axis of the Bloch sphere. Learn more about Z-Gate often seems to have no effect. But later your In quantum computing, measurement is the process of extracting classical information from a quantum state. It collapses a qubit’s superposition into one of its basis states (usually or ), with probabilities determined by the amplitudes of those states. After measurement, the qubit’s state becomes definite, destroying the original superposition. Learn more about Measurement results change. You observe effects that do not match the simple explanation. It feels as if the A quantum computer is typically a large, highly controlled system kept at near-absolute-zero temperatures to preserve quantum behavior. It contains a processor with qubits—often made from superconducting circuits, trapped ions, or photons—manipulated by microwaves, lasers, or magnetic fields. Surrounding systems handle cooling, error correction, and control electronics to maintain quantum coherence and read out results. Learn more about Quantum Computer is behaving incorrectly and the A quantum gate is a basic operation that changes the state of one or more qubits, similar to how a logic gate operates on bits in classical computing. It uses unitary transformations, meaning it preserves the total probability (the state’s length in complex space). Quantum gates enable superposition and entanglement, allowing quantum computers to perform computations that classical ones cannot efficiently replicate. Learn more about Quantum Gate are not doing what they should.
But the problem isn’t with the machine. It’s with how we think about A quantum gate is a basic operation that changes the state of one or more qubits, similar to how a logic gate operates on bits in classical computing. It uses unitary transformations, meaning it preserves the total probability (the state’s length in complex space). Quantum gates enable superposition and entanglement, allowing quantum computers to perform computations that classical ones cannot efficiently replicate. Learn more about Quantum Gate. What if a A quantum gate is a basic operation that changes the state of one or more qubits, similar to how a logic gate operates on bits in classical computing. It uses unitary transformations, meaning it preserves the total probability (the state’s length in complex space). Quantum gates enable superposition and entanglement, allowing quantum computers to perform computations that classical ones cannot efficiently replicate. Learn more about Quantum Gatemeaning depends not on what it is, but on the basis you’re looking from?
This small shift in perspective is one of the biggest conceptual jumps in Quantum Computing is a different kind of computation that builds upon the phenomena of Quantum Mechanics. Learn more about Quantum ComputingPreskill, J., 2018, CreateSpace Independent Publishing Platform, . And the simplest proof of it is hidden inside a three-letter sequence:
But before we name what this really means, let’s first unpack why this is true. And why it matters far beyond one equation.
Cracks in the Old Belief
Start with the invisible The Z-gate changes the phase of the state by (or radians) while leaving the state unchanged. This means the amplitude of gains a negative sign, effectively flipping its phase. It's a phase-flip operation that rotates the quantum state vector a half turn around the Z-axis of the Bloch sphere. Learn more about Z-Gate
At first glance, that looks boring. No flipping, no mixing, just a A **quantum phase** is the angle component of a particle’s wavefunction that determines how its probability amplitude interferes with others. It doesn’t affect observable probabilities directly but becomes crucial when comparing two or more states, as phase differences lead to interference effects. Essentially, it encodes the relative timing or “alignment” of quantum waves. Learn more about Quantum Phase change. If you In quantum computing, measurement is the process of extracting classical information from a quantum state. It collapses a qubit’s superposition into one of its basis states (usually or ), with probabilities determined by the amplitudes of those states. After measurement, the qubit’s state becomes definite, destroying the original superposition. Learn more about Measurement the A qubit is the basic unit of quantum information, representing a superposition of 0 and 1 states. Learn more about Quantum Bit right after, you’d never know anything happened. Because the minus sign doesn't matter for the In quantum computing, measurement is the process of extracting classical information from a quantum state. It collapses a qubit’s superposition into one of its basis states (usually or ), with probabilities determined by the amplitudes of those states. After measurement, the qubit’s state becomes definite, destroying the original superposition. Learn more about Measurement But that minus sign matters for Interference in quantum computing refers to the way probability amplitudes of quantum states combine—sometimes reinforcing each other (constructive interference) or canceling out (destructive interference). Quantum algorithms exploit this to amplify the probability of correct answers while suppressing incorrect ones. It’s a key mechanism that gives quantum computers their computational advantage. Learn more about Interference It determines how In quantum computing an amplitude is a complex number that describes the weight of a basis state in a quantum superposition. The squared magnitude of an amplitude gives the probability of measuring that basis state. Amplitudes can interfere, this means adding or canceling, allowing quantum algorithms to bias outcomes toward correct solutions. Learn more about Amplitude add or cancel.
So the The Z-gate changes the phase of the state by (or radians) while leaving the state unchanged. This means the amplitude of gains a negative sign, effectively flipping its phase. It's a phase-flip operation that rotates the quantum state vector a half turn around the Z-axis of the Bloch sphere. Learn more about Z-Gate isn’t doing nothing. It’s rotating your A quantum state is the complete mathematical description of a quantum system, containing all the information needed to predict measurement outcomes. It’s usually represented by a wavefunction or a state vector in a Hilbert space. The state defines probabilities, not certainties, for observable quantities like position, momentum, or spin. Learn more about Quantum State around the-axis of the The Bloch sphere is a geometric representation of a single qubit’s quantum state as a point on or inside a unit sphere. The north and south poles represent the classical states |0⟩ and |1⟩, while any other point corresponds to a superposition of them. Its position encodes the qubit’s relative phase and probability amplitudes, making it a visual tool for understanding quantum state evolution. Learn more about Bloch Sphere. Something you can’t see from the standard In quantum computing, measurement is the process of extracting classical information from a quantum state. It collapses a qubit’s superposition into one of its basis states (usually or ), with probabilities determined by the amplitudes of those states. After measurement, the qubit’s state becomes definite, destroying the original superposition. Learn more about Measurement view but that has very real effects.
On its own, the The Hadamard operator, often denoted H, is a single-qubit quantum gate that creates an equal superposition of and . In other words, It turns the states of the computational basis and into the states of the Fourier basis and . Learn more about Hadamard Operator looks innocent too.
In matrix form it’s
It doesn’t flip or rotate the A quantum state is the complete mathematical description of a quantum system, containing all the information needed to predict measurement outcomes. It’s usually represented by a wavefunction or a state vector in a Hilbert space. The state defines probabilities, not certainties, for observable quantities like position, momentum, or spin. Learn more about Quantum State in the usual sense. It changes your point of view. It converts the The computational basis is the standard set of basis states used to describe qubits in quantum computing. These are typically and for a single qubit. For multi-qubit systems all possible combinations of basis states denote the computational basis, like , , , and . These states correspond to classical bit strings and form an orthonormal basis for the system's Hilbert space. Any quantum state can be expressed as a superposition of these computational basis states. Learn more about Computational Basis () into the The Fourier basis is a set of sine and cosine functions that can represent any periodic signal as a weighted sum of these functions. Each basis function corresponds to a specific frequency, capturing how much of that frequency is present in the signal. In essence, it’s the coordinate system for expressing signals in terms of their frequency components instead of time. Learn more about Fourier Basis (), whereMermin, N.D., 2007, Cambridge University Press,
Think of the The Hadamard operator, often denoted H, is a single-qubit quantum gate that creates an equal superposition of and . In other words, It turns the states of the computational basis and into the states of the Fourier basis and . Learn more about Hadamard Operator like rotating a cube. The cube hasn’t changed, but you now see a different face. The The Hadamard operator, often denoted H, is a single-qubit quantum gate that creates an equal superposition of and . In other words, It turns the states of the computational basis and into the states of the Fourier basis and . Learn more about Hadamard Operator does that for A qubit is the basic unit of quantum information, representing a superposition of 0 and 1 states. Learn more about Quantum Bit. It changes which axes you’re using to describe the same state.
Now combine them. You'll see the result is shocking but unambiguous. Apply . Do the math... No, wait! Let Qiskit is an open-source Python framework for programming and simulating quantum computers. It lets users create quantum circuits, run them on real quantum hardware or simulators, and analyze the results. Essentially, it bridges high-level quantum algorithms with low-level hardware execution. Learn more about Qiskit do it for you.
In ?, we create a custom A quantum gate is a basic operation that changes the state of one or more qubits, similar to how a logic gate operates on bits in classical computing. It uses unitary transformations, meaning it preserves the total probability (the state’s length in complex space). Quantum gates enable superposition and entanglement, allowing quantum computers to perform computations that classical ones cannot efficiently replicate. Learn more about Quantum Gate that applies the -sequence on a A qubit is the basic unit of quantum information, representing a superposition of 0 and 1 states. Learn more about Quantum Bit
# change perspective (back into computational basis)
hzh_qc.h(0)
# turn the circuit into a gate
HzhGate = hzh_qc.to_gate(label="HZHGate")
Listing 1 Create a custom gate for the HZH-gate sequenceThis code listing
the required QuantumCircuit class from Qiskit,
a QuantumCircuit with a single A qubit is the basic unit of quantum information, representing a superposition of 0 and 1 states. Learn more about Quantum Bit
the A qubit is the basic unit of quantum information, representing a superposition of 0 and 1 states. Learn more about Quantum Bit from the The computational basis is the standard set of basis states used to describe qubits in quantum computing. These are typically and for a single qubit. For multi-qubit systems all possible combinations of basis states denote the computational basis, like , , , and . These states correspond to classical bit strings and form an orthonormal basis for the system's Hilbert space. Any quantum state can be expressed as a superposition of these computational basis states. Learn more about Computational Basis into the The Fourier basis is a set of sine and cosine functions that can represent any periodic signal as a weighted sum of these functions. Each basis function corresponds to a specific frequency, capturing how much of that frequency is present in the signal. In essence, it’s the coordinate system for expressing signals in terms of their frequency components instead of time. Learn more about Fourier Basis
the The Z-gate changes the phase of the state by (or radians) while leaving the state unchanged. This means the amplitude of gains a negative sign, effectively flipping its phase. It's a phase-flip operation that rotates the quantum state vector a half turn around the Z-axis of the Bloch sphere. Learn more about Z-Gate that flips the phase of the is a basis state. Learn more about -In quantum computing an amplitude is a complex number that describes the weight of a basis state in a quantum superposition. The squared magnitude of an amplitude gives the probability of measuring that basis state. Amplitudes can interfere, this means adding or canceling, allowing quantum algorithms to bias outcomes toward correct solutions. Learn more about Amplitude, effectively turning the qubit from to
the A qubit is the basic unit of quantum information, representing a superposition of 0 and 1 states. Learn more about Quantum Bit back from the The Fourier basis is a set of sine and cosine functions that can represent any periodic signal as a weighted sum of these functions. Each basis function corresponds to a specific frequency, capturing how much of that frequency is present in the signal. In essence, it’s the coordinate system for expressing signals in terms of their frequency components instead of time. Learn more about Fourier Basis into the The computational basis is the standard set of basis states used to describe qubits in quantum computing. These are typically and for a single qubit. For multi-qubit systems all possible combinations of basis states denote the computational basis, like , , , and . These states correspond to classical bit strings and form an orthonormal basis for the system's Hilbert space. Any quantum state can be expressed as a superposition of these computational basis states. Learn more about Computational Basis
the QuantumCircuit into a custom A quantum gate is a basic operation that changes the state of one or more qubits, similar to how a logic gate operates on bits in classical computing. It uses unitary transformations, meaning it preserves the total probability (the state’s length in complex space). Quantum gates enable superposition and entanglement, allowing quantum computers to perform computations that classical ones cannot efficiently replicate. Learn more about Quantum Gate
With the HzhGate at hand, we can easily obtain its corresponding matrix using the Operator class as depicted in ?.
hzh.py
1
2
3
from qiskit.quantum_info import Operator
print(Operator(HzhGate).data)
Listing 2 Inspecting the matrix of the HZH-sequence
Listing 3 Inspecting the matrix of the HZH-sequence
This matrix looks very similar to the matrix of the The X-Gate flips a qubit's probability amplitudes between its two basis states, effectively exchanging their roles. It doesn’t just turn into , but rotates any quantum state halfway around the x-axis of the Bloch sphere. This means it inverts the qubit's orientation while preserving the overall shape of its state on the sphere. Learn more about X-Gate
But, once again, let's use our (classical) computer to do the hard work. ? compares the matrices of the HzhGate and the XGate.
hzh.py
1
2
3
4
from numpy import allclose
from qiskit.circuit.library import XGate
print("HZH == X ?", allclose(Operator(HzhGate).data, Operator(XGate()).data))
Listing 4 Comparing the matrices of HZH and X
The allclose(HZH, X) function we import from numpy numerically checks equality. And as we see in ?, they are both the same.
1
HZH == X ? True
Listing 5 Result of comparing HZH with X
So, we can say:
A quantum gate is a basic operation that changes the state of one or more qubits, similar to how a logic gate operates on bits in classical computing. It uses unitary transformations, meaning it preserves the total probability (the state’s length in complex space). Quantum gates enable superposition and entanglement, allowing quantum computers to perform computations that classical ones cannot efficiently replicate. Learn more about Quantum Gate don’t have fixed meanings. Their effect depends on the basis you’re looking in. That’s what the routine demonstrates so cleanly. A The Z-gate changes the phase of the state by (or radians) while leaving the state unchanged. This means the amplitude of gains a negative sign, effectively flipping its phase. It's a phase-flip operation that rotates the quantum state vector a half turn around the Z-axis of the Bloch sphere. Learn more about Z-Gate is a A **quantum phase** is the angle component of a particle’s wavefunction that determines how its probability amplitude interferes with others. It doesn’t affect observable probabilities directly but becomes crucial when comparing two or more states, as phase differences lead to interference effects. Essentially, it encodes the relative timing or “alignment” of quantum waves. Learn more about Quantum Phase flip around one axis; surround it with The Hadamard operator, often denoted H, is a single-qubit quantum gate that creates an equal superposition of and . In other words, It turns the states of the computational basis and into the states of the Fourier basis and . Learn more about Hadamard Operator and you’re now looking around a different axis. Then, it becomes a A bit (short for “binary digit”) is the smallest unit of data in computing, representing a value of either 0 or 1. It’s the fundamental building block of all digital information. Multiple bits combine to form larger units like bytes (8 bits) and encode more complex data such as numbers, text, or images. Learn more about Binary Digit flipNielsen, M.A., 2010, Cambridge university press, .
Sounds abstract? It is. Until you picture it geometrically as shown in ?. On the The Bloch sphere is a geometric representation of a single qubit’s quantum state as a point on or inside a unit sphere. The north and south poles represent the classical states |0⟩ and |1⟩, while any other point corresponds to a superposition of them. Its position encodes the qubit’s relative phase and probability amplitudes, making it a visual tool for understanding quantum state evolution. Learn more about Bloch Sphere the HZH sequence moves the A quantum state vector is a mathematical object (usually denoted |ψ⟩) that fully describes the state of a quantum system. Its components give the probability amplitudes for finding the system in each possible basis state. The squared magnitude of each component gives the probability of measuring that corresponding outcome. Learn more about Quantum State Vector in a well-defined way starting from is a basis state. Learn more about and ending in is a basis state. Learn more about .
Join to continue
This part is available to PyQML students and above. Log in or start a subscription to unlock member content.
Already a member? Use Log in. New here? Choose Subscribe.
Figure 1 The HZH Sequence in the Bloch Sphere
But if everything depends on the basis, how can we reason about anything in Quantum Computing is a different kind of computation that builds upon the phenomena of Quantum Mechanics. Learn more about Quantum Computing? The important point is that every A quantum operator is a mathematical object that represents a physical action or measurement on a quantum state. It transforms one quantum state into another, often expressed as a matrix acting on a vector in Hilbert space. In quantum computing, operators correspond to quantum gates, which manipulate qubits according to the rules of linear algebra and quantum mechanics. Learn more about Quantum Operator is a well-defined A **unitary operator** is a linear operator ( U ) on a complex vector space that satisfies ( U^\dagger U = UU^\dagger = I ), meaning it preserves inner products. In simpler terms, it preserves the **length** and **angle** between vectors—so it represents a **reversible, norm-preserving transformation**. In quantum mechanics, unitary operators describe the evolution of isolated systems because they conserve probability. Learn more about Unitary Operator. It is precise, predictable, and reversiblePreskill, J., 2018, CreateSpace Independent Publishing Platform, .
The sequence tells a deep story: by changing basis before and after the The Z-gate changes the phase of the state by (or radians) while leaving the state unchanged. This means the amplitude of gains a negative sign, effectively flipping its phase. It's a phase-flip operation that rotates the quantum state vector a half turn around the Z-axis of the Bloch sphere. Learn more about Z-Gate we transformed what the operation means. Only when we look at the entire sequence, each part of it makes sense.
This sequence is a blueprint. Quantum Error Correction (QEC) protects quantum information from decoherence and operational errors by encoding one logical qubit into multiple physical qubits. It detects and corrects errors without directly measuring the qubit’s quantum state, preserving superposition and entanglement. QEC relies on redundant encoding and stabilizer measurements to identify and reverse errors before they accumulate. Learn more about Quantum Error Correction state teleportation, and many A quantum algorithm is a step-by-step computational procedure designed to run on a quantum computer, exploiting quantum phenomena such as superposition, entanglement, and interference to solve certain problems more efficiently than classical algorithms. Learn more about Quantum Algorithm rely on basis shifts just like this. Understanding that becomes under Hadamard conjugation is the first step to grasping how entire algorithms move information around without touching it directlyNielsen, M.A., 2010, Cambridge university press, .
Once you see gates as rotations in space rather than buttons with fixed effects, A quantum circuit is a sequence of quantum gates applied to qubits, representing the operations in a quantum computation. Each gate changes the qubits’ state using quantum mechanics principles like superposition and entanglement. The final qubit states, when measured, yield the circuit’s computational result probabilistically. Learn more about Quantum Circuit stop looking mysterious. They become logical, visual, and even elegant.
That’s not just the secret of the routine. It’s the secret of how Quantum Computing is a different kind of computation that builds upon the phenomena of Quantum Mechanics. Learn more about Quantum Computing works.