|q⟩ Bad Qubits

intermediate · Programming · Quantum Machine Learning (Intro)

Parameterized Quantum Circuits

A parameterized quantum circuit (PQC) — also called a variational ansatz — is a quantum circuit whose gate angles are continuous free parameters θRp\boldsymbol{\theta} \in \mathbb{R}^p. Rather than being fixed at design time, those angles are adjusted by a classical optimizer to minimize a cost function evaluated by running the circuit on a quantum device (or simulator).

This hybrid classical-quantum loop is the backbone of the Variational Quantum Eigensolver (VQE), the Quantum Approximate Optimization Algorithm (QAOA), and many Quantum Neural Networks (QNNs).

Anatomy of an ansatz

A typical hardware-efficient ansatz repeats a pattern of single-qubit rotations followed by entangling gates for LL layers:

U(θ)==1L(jRy(θ,j))E,U(\boldsymbol{\theta}) = \prod_{\ell=1}^{L} \Bigl( \bigotimes_{j} R_y(\theta_{\ell,j}) \Bigr) \cdot E_\ell,

where Ry(θ)R_y(\theta) is the YY-rotation and EE_\ell is a fixed entangling layer (often a chain of CNOTs). For nn qubits and LL layers the circuit has nLnL free parameters.

The Ry gate

The single-qubit YY-rotation by angle θ\theta is

Ry(θ)=eiθY/2=(cosθ2sinθ2sinθ2cosθ2).R_y(\theta) = e^{-i\theta Y/2} = \begin{pmatrix} \cos\tfrac{\theta}{2} & -\sin\tfrac{\theta}{2} \\ \sin\tfrac{\theta}{2} & \cos\tfrac{\theta}{2} \end{pmatrix}.

It maps 0cos(θ/2)0+sin(θ/2)1|0\rangle \mapsto \cos(\theta/2)|0\rangle + \sin(\theta/2)|1\rangle, so at θ=π\theta = \pi it acts as an XX gate; at θ=π/2\theta = \pi/2 it prepares an equal superposition with real, positive amplitudes.

Why Ry?

Unlike RzR_z, an RyR_y rotation moves amplitude between 0|0\rangle and 1|1\rangle with real coefficients, which keeps the state on the XZXZ great-circle of the Bloch sphere. This makes gradients easier to estimate and the landscape more amenable to classical optimizers.

Building a trainable model

For a 2-qubit, single-layer ansatz the circuit looks like:

ψ(θ0,θ1)=CNOT01(Ry(θ0)Ry(θ1))00.|\psi(\theta_0, \theta_1)\rangle = \text{CNOT}_{01} \cdot \bigl(R_y(\theta_0) \otimes R_y(\theta_1)\bigr)|00\rangle.

Choosing θ0=π/3\theta_0 = \pi/3 and θ1=π/4\theta_1 = \pi/4 gives concrete amplitudes we can compute:

The parameter-shift rule

Because U(θ)U(\boldsymbol{\theta}) depends on rotation angles, the gradient of any expectation value O(θ)\langle O \rangle(\theta) can be computed analytically on hardware:

Oθj=12[O(θj+π2)O(θjπ2)].\frac{\partial \langle O \rangle}{\partial \theta_j} = \tfrac{1}{2}\bigl[\langle O \rangle(\theta_j + \tfrac{\pi}{2}) - \langle O \rangle(\theta_j - \tfrac{\pi}{2})\bigr].

This parameter-shift rule (Mitarai et al., 2018; Schuld et al., 2019) requires exactly two circuit evaluations per parameter and works on real quantum hardware — no finite-difference approximation is needed.

Try it

Build the 2-qubit single-layer ansatz: apply Ry(π/3)R_y(\pi/3) to qubit 0, Ry(π/4)R_y(\pi/4) to qubit 1, then entangle them with a CNOT. The grader checks the exact statevector produced by your circuit.

Run your code to see the quantum state.

Sign in on the full site to ask questions and join the discussion.