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 is an engineering trade-off:
Shallow ansatze (good for NISQ hardware):
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):
Choosing a good ansatz requires understanding the problem. Start simple, measure trainability and expressivity, then refine.