Site Tools


qiskit-ansatz

Ansatz

Ansatz (German for “starting point”) is the family of parameterized quantum circuits used in variational algorithms. The ansatz is the trainable part: you design its structure (which gates, how many layers), and a classical optimizer trains its parameters to minimize a cost function.

The quality of a variational algorithm depends entirely on the ansatz: if the true solution is not representable by your ansatz, the algorithm cannot find it, no matter how good the optimizer is.

Ansatz Design

Ansatz design is an engineering trade-off:

  • Expressivity: can it represent solutions to your problem? Larger ansatze are more expressive but harder to train.
  • Trainability: is the landscape smooth and conducive to gradient-based optimization? Deep ansatze often have barren plateaus (flat cost landscapes) where gradients vanish.
  • Gate count: fewer gates = less noise on real hardware, but less expressive.

Common Ansatz Families

Shallow ansatze (good for NISQ hardware):

  • Alternating layers of single-qubit rotations and two-qubit entanglers
  • Hardware-efficient ansatz: RY + RZ on each qubit, CNOT ladder between layers
from qiskit import QuantumCircuit
from qiskit.circuit import Parameter
 
def hardware_efficient_ansatz(num_qubits, depth):
    qc = QuantumCircuit(num_qubits)
    params = []
 
    for layer in range(depth):
        for q in range(num_qubits):
            theta = Parameter(f'θ_{layer}_{q}')
            qc.ry(theta, q)
            params.append(theta)
 
        for q in range(num_qubits - 1):
            qc.cx(q, q + 1)
 
    return qc, params
 
qc, params = hardware_efficient_ansatz(4, 3)
print(qc.draw())

Structured ansatze (domain-specific):

  • Chemistry: UCC (Unitary Coupled Cluster) ansatz for molecular problems
  • Optimization: problem-inspired ansatz encoding the cost structure

Choosing a good ansatz requires understanding the problem. Start simple, measure trainability and expressivity, then refine.

qiskit-ansatz.md · Last modified: by 127.0.0.1