Hardware-Efficient Ansatz (HEA)
A parameterized quantum circuit designed for NISQ devices that uses native gate sets and respects hardware connectivity constraints, enabling variational algorithms to run within coherence time limits.
What You'll Learn:
- How to construct layered variational circuits from hardware-native gates
- Three entanglement topologies and their expressibility trade-offs
- The relationship between circuit depth, trainability, and noise resilience
- How HEA serves as the backbone for VQE, QAOA, and quantum machine learning
| Property | Value |
|---|---|
| Level | Advanced |
| Time | 45-60 minutes |
| Qubits | 4 (configurable) |
| Framework | Cirq |
| Gates | H, RY, RZ, CZ |
Prerequisites
Before starting, you should be comfortable with:
- Bell State -- entanglement basics and two-qubit gates
- GHZ State -- multi-qubit entanglement patterns
- Quantum Fourier Transform -- parameterized rotations and circuit depth
Familiarity with variational algorithms (VQE, QAOA) is helpful but not required -- this circuit teaches the ansatz layer that those algorithms rely on.
The Idea
Classical optimization on a quantum device requires a parameterized circuit -- an "ansatz" -- that can represent a wide range of quantum states. The challenge: most theoretically motivated ansatze (like UCCSD from quantum chemistry) need far more gates than NISQ hardware can reliably execute.
The hardware-efficient ansatz flips the design philosophy. Instead of starting from physics and hoping the circuit fits the hardware, it starts from the hardware's native gates and builds the most expressive circuit that the device can actually run. Each layer uses only the rotations and entangling gates that the processor implements natively, avoiding costly gate decompositions.
The trade-off: HEA circuits may not have the same physical intuition as problem-specific ansatze, and deep HEAs can suffer from barren plateaus (exponentially vanishing gradients). But for many practical problems on today's devices, they hit the sweet spot between expressibility and executability.
How It Works
Circuit Structure
Each layer consists of:
- Single-qubit rotations: RY(theta), RZ(phi) on each qubit
- Entangling gates: CZ between qubit pairs
CODELayer k: +--------++--------+ q_0: | RY(t0) || RZ(p0) |--*---------- +--------++--------+ | q_1: | RY(t1) || RZ(p1) |--*----*----- +--------++--------+ | q_2: | RY(t2) || RZ(p2) |-------*--*-- +--------++--------+ | q_3: | RY(t3) || RZ(p3) |----------*-- +--------++--------+
The full circuit is: Hadamard layer -> Initial RY layer -> L variational blocks (each with RY-RZ rotations + CZ entangling).
Entanglement Patterns
Linear -- nearest-neighbor chain (n-1 CZ gates per layer):
CODEq_0 -*------- | q_1 -*-*----- | q_2 ---*-*--- | q_3 -----*---
Circular -- linear plus wrap-around (n CZ gates per layer):
CODEq_0 -*-------*- | | q_1 -*-*-----| | | q_2 ---*-*---| | | q_3 -----*--*-
Full -- all-to-all connectivity (n(n-1)/2 CZ gates per layer):
Every qubit pair gets a CZ gate. Maximally expressive but requires all-to-all connectivity or heavy SWAP routing on constrained hardware.
The Math
Parameter Count Formula
CODEtotal_params = n_qubits + n_layers * (2 * n_qubits) = n_qubits * (1 + 2 * n_layers)
The first term covers the initial RY rotation layer. Each variational block contributes 2 * n_qubits parameters (one RY and one RZ per qubit).
| n_qubits | n_layers | Total Parameters |
|---|---|---|
| 2 | 2 | 10 |
| 4 | 3 | 28 |
| 6 | 4 | 54 |
| 8 | 6 | 104 |
Expressibility
Expressibility measures how uniformly the ansatz can cover the Hilbert space. Sim et al. (2019) quantify this via the KL divergence between the circuit's output distribution and the Haar-random distribution.
- More layers -> higher expressibility (closer to Haar-random)
- Full entanglement -> higher expressibility than linear
- Diminishing returns beyond ~n_qubits layers (and barren plateaus emerge)
CZ Gates per Layer
| Pattern | CZ Count | Scaling |
|---|---|---|
| Linear | n - 1 | O(n) |
| Circular | n | O(n) |
| Full | n(n-1)/2 | O(n^2) |
Expected Output
Running with default parameters (4 qubits, 3 layers, linear entanglement, seed=42):
| Metric | Typical Value |
|---|---|
| Total parameters | 28 |
| Circuit depth | ~8-12 moments |
| Unique outcomes (1024 shots) | 14-16 |
| Z expectation | -2.0 to 2.0 |
| ZZ expectation | -3.0 to 3.0 |
Comparison Across Entanglement Patterns
| Metric | Linear | Circular | Full |
|---|---|---|---|
| CZ gates/layer | n-1 | n | n(n-1)/2 |
| Depth/layer | O(n) | O(n) | O(n^2) |
| Expressibility | Medium | Higher | Highest |
| Hardware compatibility | Best | Good | Requires all-to-all |
Running the Circuit
PYTHONfrom circuit import run_circuit, verify_hea # Basic demonstration result = run_circuit(n_qubits=4, n_layers=3, entanglement='linear') print(f"Parameters: {result['n_params']}") print(f"Depth: {result['depth']}") print(f"Gate counts: {result['gate_counts']}") print(f"<Z>: {result['z_expectation']:.4f}") print(f"<ZZ>: {result['zz_expectation']:.4f}") # Verify correctness verification = verify_hea() for check in verification['checks']: status = 'PASS' if check['passed'] else 'FAIL' print(f" [{status}] {check['name']}: {check['detail']}")
Building Circuits Directly
PYTHONfrom circuit import create_hardware_efficient_ansatz, compute_expectation import numpy as np # Create a circuit with custom parameters params = np.random.uniform(0, 2 * np.pi, 28) circuit = create_hardware_efficient_ansatz( n_qubits=4, n_layers=3, params=params.tolist(), entanglement='circular' ) print(circuit) # Compute observables z_val = compute_expectation(circuit, 'Z') zz_val = compute_expectation(circuit, 'ZZ') print(f"<Z> = {z_val:.4f}, <ZZ> = {zz_val:.4f}")
Try It Yourself
-
Depth vs. expressibility: Increase
n_layersfrom 1 to 8 and plot the number of unique measurement outcomes. Where do diminishing returns begin? -
Entanglement comparison: Run the same parameters with
"linear","circular", and"full"entanglement. Compare the distribution entropy of measurement outcomes. -
Barren plateau detection: For
n_qubits= 2, 4, 6, 8, compute the gradient of<Z>with respect to the first parameter using finite differences. Does the gradient shrink exponentially with qubit count? -
VQE integration: Use the HEA as an ansatz for a simple VQE problem. Define a 2-qubit Hamiltonian H = -Z0Z1 + 0.5X0 and optimize the parameters to find the ground state energy.
-
Hardware mapping: Compare the circuit depth when using linear entanglement (natural for IBM's heavy-hex topology) vs. full entanglement (requires SWAP insertions). How many additional gates does transpilation add?
What's Next
After mastering the hardware-efficient ansatz, explore these related circuits:
- VQE for H2 Ground State -- apply HEA to find molecular ground state energies
- QAOA for MaxCut -- another variational algorithm using problem-specific ansatz structure
- Variational Classifier -- use parameterized circuits for quantum machine learning
- Data Re-uploading -- alternative variational strategy that interleaves data encoding with trainable layers
Applications
| Domain | Use Case | Why HEA |
|---|---|---|
| Quantum Chemistry | VQE ground state energy | Shallow alternative to UCCSD on NISQ devices |
| Combinatorial Optimization | QAOA warm-starting | HEA layers can initialize QAOA near good solutions |
| Quantum Machine Learning | Classification and regression | Trainable feature maps with tunable expressibility |
| Hardware Benchmarking | Device characterization | Standardized parameterized circuits for comparing processors |
| Quantum Error Mitigation | Zero-noise extrapolation | Controlled-depth circuits for noise scaling experiments |
Trade-offs
| Aspect | Shallow (L=1-2) | Deep (L>n) |
|---|---|---|
| Expressibility | Lower | Higher |
| Trainability | Better gradients | Barren plateaus risk |
| Noise resilience | Better | Worse (more gates = more errors) |
| Hardware compatibility | Better | Varies by topology |
| Optimization landscape | Fewer local minima | More complex landscape |
References
-
Kandala, A. et al. "Hardware-efficient variational quantum eigensolver for small molecules and quantum magnets." Nature 549, 242-246 (2017). DOI: 10.1038/nature23879
-
Sim, S., Johnson, P.D. & Aspuru-Guzik, A. "Expressibility and Entangling Capability of Parameterized Quantum Circuits for Hybrid Quantum-Classical Algorithms." Adv. Quantum Technol. 2, 1900070 (2019). DOI: 10.1002/qute.201900070
-
McClean, J.R. et al. "Barren plateaus in quantum neural network training landscapes." Nature Communications 9, 4812 (2018). DOI: 10.1038/s41467-018-07090-4
-
Peruzzo, A. et al. "A variational eigenvalue solver on a photonic quantum processor." Nature Communications 5, 4213 (2014). DOI: 10.1038/ncomms5213