Lesson 45 · 95 min · advanced
Strongly Entangling Layers
Strongly entangling layers (SEL) are the default trainable block of many quantum machine-learning libraries. Each layer applies a general single-qubit rotation to every wire and then a cyclic block of CNOTs whose range changes from layer to layer. This lesson proves that reaches all of (ZYZ decomposition), fixes the PennyLane conventions (weights of shape , default range ), shows that every entangling block is an invertible linear map over on basis labels, counts parameters and CNOTs, analyses the growth of light cones and direct couplings, and relates the template to the circuit-centric classifiers of Schuld, Bocharov, Svore and Wiebe.
Prerequisites: Hardware-Efficient Ansatz
Objectives and key results
Prove that every equals , write the explicit matrix of and translate the matrix order into the time order , , .
Implement PennyLane-convention strongly entangling layers with weights of shape and the default range , and explain why only is admissible.
Represent a product of CNOTs as an invertible matrix over , compute it for with and , and invert it.
Count parameters () and CNOTs (), and bound the growth of light cones and of the set of directly coupled pairs with the number of layers.
Describe the circuit-centric classifier (amplitude encoding, layered model circuit, single-qubit readout, bias and threshold) and its parameter count .
- theorem · ZYZ decomposition
- definition · General rotation
- definition · Strongly entangling layer
- identity · The n = 3, r = 1 block over F₂
- formula · Resource counts
The general single-qubit rotation#
The hardware-efficient ansatz of the previous lesson used two rotations per qubit and layer and a CNOT ladder between neighbours. This leaves two gaps: is a two-parameter family, while modulo global phase is three-dimensional; and the ladder couples only neighbouring qubits. Strongly entangling layers close both: each wire receives a general rotation with three angles, and the CNOTs close a cycle whose stride, the range, changes from layer to layer. The template goes back to the circuit-centric classifiers of Schuld, Bocharov, Svore and Wiebe and is implemented in PennyLane as StronglyEntanglingLayers. We begin with the rotation.
Definition
General rotation Rot
For real angles the general rotation is In a matrix product the rightmost factor acts first, so in a circuit is the sequence , then , then . Since , .
Explicit matrix of Rot
- Step 1:Right multiplication by a diagonal matrix scales the columns: column by , column by .
- Step 2:Left multiplication by a diagonal matrix scales the rows: row by , row by .
- Step 3:Collect the exponents: , , , .
- Step 4:Exchanging and conjugates the phase of the off-diagonal entries. The two orders agree when , which is why the lab has a check with that a learner with the wrong order still passes.
- Step 5:At the two rotations merge, because rotations about the same axis add their angles. Only the sum is then determined: the parametrisation is singular at (and at , where only matters), the familiar gimbal lock of Euler angles.
Result
The matrices of SU(2)
A complex matrix lies in (that is, and ) if and only if
Proof (6 steps)
- Step 1:The entries of are the inner products of the columns , ; unitarity says the columns are orthonormal.
- Step 2:An explicit unit vector orthogonal to the first column.
- Step 3:The orthogonal complement of the non-zero vector is the kernel of the non-zero linear functional , hence one-dimensional and spanned by .
- Step 4:Substitute and and use the normalisation of the first column.
- Step 5:This proves the "only if" direction with , .
- Step 6:The "if" direction: direct multiplication and the determinant .
∎
ZYZ decomposition: Rot reaches all of SU(2)
For every there are real numbers , with , such that Consequently , and every single-qubit unitary equals a gate up to a global phase.
Proof (9 steps)
- Step 1:Multiplicativity of the determinant and .
- Step 2:A scalar factor multiplies the determinant of a matrix by and leaves unitarity intact when . Hence .
- Step 3:The lemma on the matrices of .
- Step 4:The point lies on the quarter of the unit circle with non-negative coordinates, so it is for a unique . The phases and are arbitrary when the modulus vanishes.
- Step 5:The explicit matrix of with , , .
- Step 6:Two linear equations for the two unknown angles: and .
- Step 7:Substitute the two phase relations entry by entry; and .
- Step 8:Undo the phase. For we have , so ; the sign is absorbed by , giving . Together with this proves .
- Step 9:On a register, a phase on one tensor factor is a global phase of the whole state, which no measurement detects. A column of gates therefore realises every product of single-qubit unitaries up to an unobservable phase.
∎
Quick check
Which gate is ?
Layers, ranges and resources#
Definition
Strongly entangling layers (PennyLane convention)
Let be the number of wires, the number of layers and the weights; belongs to wire in layer . For a range sequence is chosen, by default Layer is the circuit i.e. in time order the rotations on all wires, then for (control , target ). For there is no entangling block: . The template is .
Admissible ranges and the cycle structure of a block
Let . (a) is a valid two-qubit gate for every if and only if ; the ranges and give the same block, so lists every admissible block exactly once, and is excluded. (b) The default sequence takes the values in this cyclic order. (c) Regard each CNOT of as the edge on the wires. The edges form disjoint cycles , , each of length ; for the block is one cycle through all wires, for it is the triangle on for both and .
Proof (6 steps)
- Step 1:A CNOT needs two distinct wires. If is a multiple of , every "gate" has control equal to target and is undefined; otherwise no wire is paired with itself.
- Step 2:Only enters the block, and the non-zero residues are exactly . In particular is the excluded residue .
- Step 3:runs through periodically with period , so the range runs through and starts again. For every layer has .
- Step 4:Wire is the control of edge and the target of edge . A finite multigraph in which every vertex has degree is a disjoint union of cycles.
- Step 5:The subgroup of generated by is generated by (Bézout: ), so the orbits are the cosets of , each with elements. For there is a single cycle through all wires.
- Step 6:For both blocks consist of the three edges of the triangle; they differ in the direction of the CNOTs and in the order in which the edges are applied, which the analysis below makes precise. If (i.e. ), each cycle is a pair carrying the two CNOTs and .
∎
Circuit · 3 qubits
Two strongly entangling layers on qubits with the numeric weights and . Each wire receives , , ; layer has range (CNOTs ), layer has range (CNOTs ).
Parameter and gate counts
strongly entangling layers on wires have (a) trainable parameters and single-qubit rotations; (b) CNOTs if and none if ; (c) for , depth exactly per layer, so depth for the whole circuit. For the block is , which maps .
Proof (5 steps)
- Step 1:One gate with three independent angles per wire and layer; it is emitted as three rotations.
- Step 2:Every block has one CNOT per wire , including the wrap-around gate ; the HEA ladder has only CNOTs because it does not close the cycle.
- Step 3:Gates sharing a wire cannot be in the same moment, so the three CNOTs of a block occupy three consecutive moments.
- Step 4:Three moments for on all wires, three for the block. Layers do not overlap: if a block ends at moment , the two wires of its last CNOT are busy until , and any pair of the three wires contains one of them. The first CNOT of the next block therefore waits for three rotations after and runs at , and its two successors follow at and , because the edges of the triangle pairwise share a wire.
- Step 5:For the range is and the block is followed by ; . This is the visible test of the lab: two of the three CNOTs of a SWAP.
∎
The gallery draws the -qubit, -layer template ( parameters, CNOTs) and compares its fidelity histogram with the Haar density for , as in the previous lesson.
Quick check
How many trainable parameters do strongly entangling layers on wires have?
Quick check
With wires and the default ranges, what is the range of layer ?
The entangling block as a linear map over F₂#
A block of CNOTs never creates superpositions on its own: it permutes the computational basis. The permutation is not arbitrary. Writing a basis label as a column vector over the two-element field , with addition (XOR) and multiplication AND, every CNOT block is a linear map with an invertible matrix . This turns questions about entangling blocks into linear algebra, exactly as the prefix-parity lemma did for the ladder of the hardware-efficient ansatz.
A CNOT is an elementary row operation over F₂
For distinct wires let , the identity with an additional in row , column . Then for every , and . If a block consists of CNOTs , applied in the order , then
Proof (5 steps)
- Step 1:flips the target bit exactly when the control bit is , i.e. adds to modulo .
- Step 2:Row of has ones in columns and , every other row is a row of the identity. Multiplying by adds row of a matrix to row : the elementary row operation .
- Step 3:In , , and because . Hence every CNOT is its own inverse, as a matrix over and as a unitary.
- Step 4:Induction over the gates: each gate maps a basis state to a basis state and multiplies the current label from the left by its elementary matrix; later gates stand further to the left.
- Step 5:The innermost pair cancels, then the next pair, and so on. Thus is invertible, is a bijection of , and is a permutation matrix.
∎
The n = 3, r = 1 block step by step
- Step 1:: the gates for , applied in this order (rightmost first).
- Step 2:Control , target wire : .
- Step 3:The control is the current bit on wire , which is already ; the target wire becomes .
- Step 4:The wrap-around gate adds the current bit of wire to wire ; .
- Step 5:Row of lists which inputs enter output bit . The product of the elementary matrices (mod ) gives the same rows, as the lemma predicts.
- Step 6:Cofactor expansion along the first row. A non-zero determinant over confirms invertibility independently of the lemma.
- Step 7:Solve for the inputs: ; then from ; finally in .
- Step 8:The inverse read off from the previous line, checked by multiplication modulo . It equals , the gates in reverse order.
- Step 9:For every pair of distinct wires, the input of one of them enters the output of the other: and both reach output , and reaches output . Already a single layer couples every wire to every other; output is the parity of all three inputs.
Result
Unitary verified: (max deviation 0.0e+0)
The n = 3, r = 2 block of the second layer
- Step 1:: targets for .
- Step 2:First wire receives , then wire receives the current bit of wire .
- Step 3:Wire receives the current bit of wire .
- Step 4:The rows list the inputs of each output; the determinant over is .
- Step 5:Solve: , then gives , then gives .
- Step 6:Multiplication modulo confirms the inverse.
- Step 7:Without rotations the blocks of two layers with ranges compose to (the second block acts after the first). In this composite, output is and output is : the second block partly undoes the mixing of the first. The rotations between the blocks destroy this cancellation in the full circuit, which is why the lab compares unitaries rather than permutations.
Result
A range-1 block couples every pair of wires
For the block maps to with Hence for all wires the input enters the output : a single layer couples every wire to every other, and the output on wire is the parity of all inputs.
Proof (3 steps)
- Step 1:The first gates are exactly the CNOT ladder of the hardware-efficient ansatz, which computes prefix parities (lemma of the previous lesson).
- Step 2:The wrap-around gate adds the current bit of wire , the total parity, to wire ; . The other bits are unchanged.
- Step 3:Row of is the prefix with ones, so it contains column . For this reproduces .
∎
Quick check
The , block acts on the basis state . Give the output label as a decimal number (qubit is the most significant bit).
Light cones and direct couplings#
Definition
Light cone of a wire
Let a circuit be a sequence of gates, each acting on a set of wires (its support). The forward light cone of wire is computed by starting from and processing the gates in time order: whenever the support of a gate meets , the whole support is added to . The backward light cone of is obtained in the same way with the gates processed in reverse time order. Single-qubit gates never enlarge . An input on a wire outside the backward light cone of cannot influence any measurement on at the end of the circuit, because the reduced state of the cone's wires evolves under the gates inside it only; the cone is therefore an upper bound on the set of inputs that a local observable can depend on.
Growth of the light cone through one block
Let be the light cone (in either direction) before the entangling block and the light cone after it. Write and let be the union of the cycles of that meet . Then Consequently, with the default ranges and layers, the light cone of every wire contains , and it is the whole register as soon as .
Proof (8 steps)
- Step 1:is the set after processing of the gates of the block, in whichever order the direction prescribes. The update only adds wires.
- Step 2:Every wire is the control of the gate ; when that gate is processed, is already in the set by monotonicity, so its partner is added. Hence .
- Step 3:Every wire is also the target of exactly one gate, , by the same argument. Hence .
- Step 4:A wire enters only together with a partner that already belongs to the set. By induction, every wire of is connected within the cycle graph to a wire of , so .
- Step 5:Apply the lower bound layer by layer (rotations do not change the set). The backward cone processes the layers in reverse order, which produces the same set of signed sums.
- Step 6:Induction on : the subset sums of fill ; adding to them fills ; the two intervals overlap because for every . With signs the negative values follow by symmetry.
- Step 7:At least consecutive integers meet every residue class modulo . For : gives . The smallest such satisfies , because gives .
- Step 8:Propagation is monotone in the initial set. Forward: the first layers already give , and the extra layer only adds wires. Backward: processing layer first yields a set containing , from which layers produce a superset of . Hence a full cone stays full for every larger .
∎
The viewer above shows one layer on wires with the forward cone of wire : after the set is , after it is . The sequential order of the block lets a cone travel along a chain of gates in one layer, so the lower bound is often not tight. The parity map is the matrix derived above. Note the difference between the two notions: the light cone of output contains wire , although does not depend on for basis inputs. For superposition inputs a CNOT also acts from target to control (in the basis the roles of control and target are exchanged), so with the rotations of the next layer in between, the gate-support cone is the right causal bound.
The following table gives the exact number of layers after which every light cone, forward and backward, of every wire is the full register, computed by gate-support propagation, together with the sufficient bound of the theorem.
| default ranges | |||||||
| in every layer | |||||||
| bound |
The bound is attained for . A fixed range saturates the light cones at least as fast, for even one layer earlier: the chain effect of the sequential block already spreads every cone over the register after two layers. Light cones alone therefore do not explain why the range should change. What changes is which pairs of wires interact directly.
With the default ranges every pair shares a CNOT after ⌊n/2⌋ layers
Let and use the default ranges. The pair of wires is the support of some CNOT among the first layers (with ) if and only if . In particular every one of the pairs shares a CNOT after exactly layers, and not earlier. With in every layer, only the cyclically neighbouring pairs ever share a CNOT.
Proof (5 steps)
- Step 1:The block contains exactly the pairs at cyclic offset in one of the two directions.
- Step 2:The default ranges are for .
- Step 3:Combine the two previous lines. The cyclic distance of the pair is .
- Step 4:The largest cyclic distance is , attained at . Also , so the assumption is satisfied at .
- Step 5:With a fixed range the same edges repeat in every layer. Distant wires then interact only indirectly, through chains of gates that are interleaved with rotations.
∎
The first viewer uses the defaults: wires, layers with ranges and the backward cone of wire , the inputs that can influence a measurement of . The second shows wires and three layers with ranges , the smallest depth at which the bound of the theorem guarantees a full cone, for wire . The CNOT pattern drawn by the viewer shows which pairs are joined directly: the ranges couple all pairs at cyclic distance at most , whereas would repeat the same eight neighbouring pairs in every layer.
Quick check
With wires and the default ranges, after how many layers has every pair of wires shared at least one CNOT?
Circuit-centric classifiers#
Schuld, Bocharov, Svore and Wiebe (2020) proposed a variational classifier whose design principles are visible in the strongly entangling template. Its structure, in the notation of this course, is as follows.
- Encoding. An input is padded and normalised and loaded by amplitude encoding, , on qubits; nonlinear feature maps can be applied before the encoding.
- Model circuit. is a product of code blocks. Each code block applies a general single-qubit gate with three angles to every qubit and then a cycle of controlled single-qubit gates in which qubit is coupled to qubit , with a range chosen per block.
- Readout. The first qubit is measured: .
- Decision. A trainable bias gives , and the predicted class is if and otherwise.
PennyLane's StronglyEntanglingLayers keeps the general rotations and the cyclic layout with a per-layer range, and replaces the trainable controlled gates by fixed CNOTs, so that all parameters sit in the gates and the circuit uses only one kind of two-qubit gate.
Readout probability, decision rule and parameter count
- Step 1:The projector onto written in the Pauli basis.
- Step 2:Linearity of the expectation and for a normalised state. The classifier is a variational model with observable in the sense of the lesson on variational circuit architecture.
- Step 3:Substitute and rearrange. The bias moves the decision threshold of the expectation value away from .
- Step 4:Count for code blocks with general single-qubit gates and controlled single-qubit gates, when every one of these gates is parametrised by three angles.
- Step 5:With fixed CNOTs only the angles remain. Either way the number of parameters grows logarithmically with the input dimension , which is the central resource argument of the circuit-centric design; the price is the amplitude-encoding state preparation, whose gate count is studied in Stage 3.
The TypeScript cell builds the circuit of this lesson by hand, compares it with the platform's builder stronglyEntanglingLayersOps, prints its resources and output distribution, and checks the matrices of the and blocks against simulated basis states.
import { circuitUnitary, matrix, runStatevector } from '@/lib/quantum-simulator';
import { stronglyEntanglingLayersOps } from '@/lib/qml';
type Op = { kind: 'gate'; gate: 'X' | 'RZ' | 'RY' | 'CNOT'; targets: number[]; params?: number[] };
const circ = (n: number, ops: Op[]) => ({ version: 1 as const, numQubits: n, numClbits: 0, ops });
// Strongly entangling layers: Rot = RZ(phi), RY(theta), RZ(omega) on every wire, then CNOT(i, (i + r_l) mod n).
function sel(weights: number[][][], n: number): Op[] {
const ops: Op[] = [];
weights.forEach((layer, l) => {
layer.forEach(([phi, theta, omega], i) => {
ops.push({ kind: 'gate', gate: 'RZ', targets: [i], params: [phi] });
ops.push({ kind: 'gate', gate: 'RY', targets: [i], params: [theta] });
ops.push({ kind: 'gate', gate: 'RZ', targets: [i], params: [omega] });
});
if (n > 1) {
const r = (l % (n - 1)) + 1;
for (let i = 0; i < n; i++) ops.push({ kind: 'gate', gate: 'CNOT', targets: [i, (i + r) % n] });
}
});
return ops;
}
// (1) The 3-qubit, 2-layer circuit of the lesson against the engine builder.
const W = [
[[0.3, 1.2, -0.4], [0.8, -0.5, 1.1], [-1.0, 0.7, 0.2]],
[[0.5, -1.3, 0.9], [-0.2, 0.4, -0.7], [1.4, 0.6, -1.1]],
];
const ops = sel(W, 3);
const U = circuitUnitary(circ(3, ops));
const V = circuitUnitary(circ(3, stronglyEntanglingLayersOps(W, 3) as Op[]));
const cnots = ops.filter((o) => o.gate === 'CNOT');
console.log('rotations = ' + (ops.length - cnots.length) + ' (3nL = 18), CNOTs = ' + cnots.length + ' (nL = 6)');
console.log('CNOT pairs: ' + cnots.map((o) => '(' + o.targets.join(',') + ')').join(' '));
console.log('max |U - U_engine| = ' + matrix.maxAbsDiff(U, V));
const p = runStatevector(circ(3, ops)).probabilities();
console.log('P(x) = ' + Array.from(p, (v) => v.toFixed(4)).join(' '));
// (2) One CNOT block on basis labels: the F2 matrix A (y = A x mod 2) against simulated basis states.
function f2Block(n: number, r: number): number[][] {
let A = Array.from({ length: n }, (_, i) => Array.from({ length: n }, (_, j) => (i === j ? 1 : 0)));
for (let i = 0; i < n; i++) {
const t = (i + r) % n;
A = A.map((row, k) => (k === t ? row.map((v, j) => v ^ A[i][j]) : row)); // CNOT(i, t): row t += row i
}
return A;
}
for (const r of [1, 2]) {
const A = f2Block(3, r);
const image: number[] = [];
let agree = true;
for (let x = 0; x < 8; x++) {
const bits = [0, 1, 2].map((q) => (x >> (2 - q)) & 1);
const prep: Op[] = [];
bits.forEach((b, q) => { if (b) prep.push({ kind: 'gate', gate: 'X', targets: [q] }); });
const block: Op[] = [0, 1, 2].map((i) => ({ kind: 'gate', gate: 'CNOT', targets: [i, (i + r) % 3] }));
const probs = runStatevector(circ(3, [...prep, ...block])).probabilities();
const y = A.map((row) => row.reduce((s, a, j) => s ^ (a & bits[j]), 0));
const label = y.reduce((s, b) => 2 * s + b, 0);
image.push(label);
agree = agree && Math.abs(probs[label] - 1) < 1e-12;
}
console.log('n = 3, r = ' + r + ': A = ' + JSON.stringify(A) + ', x -> Ax: [' + image.join(', ') + '], simulation agrees: ' + agree);
}Expected output
rotations = 18 (3nL = 18), CNOTs = 6 (nL = 6) CNOT pairs: (0,1) (1,2) (2,0) (0,2) (1,0) (2,1) max |U - U_engine| = 0 P(x) = 0.3160 0.0181 0.0483 0.0025 0.1148 0.2338 0.0233 0.2431 n = 3, r = 1: A = [[0,1,1],[1,1,0],[1,1,1]], x -> Ax: [0, 5, 7, 2, 3, 6, 4, 1], simulation agrees: true n = 3, r = 2: A = [[1,1,0],[1,1,1],[1,0,1]], x -> Ax: [0, 3, 6, 5, 7, 4, 1, 2], simulation agrees: true
The NumPy cell checks the ZYZ theorem on Haar-random unitaries, the explicit matrix of , the two -qubit matrices and their inverses (Gauss–Jordan elimination over ), the range- formula for and the pair-coverage depth .
import numpy as np
def rz(a):
return np.diag([np.exp(-0.5j * a), np.exp(0.5j * a)])
def ry(a):
c, s = np.cos(a / 2), np.sin(a / 2)
return np.array([[c, -s], [s, c]], dtype=complex)
def rot(phi, theta, omega): # Rot(phi, theta, omega) = R_Z(omega) R_Y(theta) R_Z(phi)
return rz(omega) @ ry(theta) @ rz(phi)
# (1) ZYZ: U = e^{i alpha} R_Z(beta) R_Y(gamma) R_Z(delta) for Haar-random U in U(2).
def zyz(U):
alpha = np.angle(np.linalg.det(U)) / 2
V = np.exp(-1j * alpha) * U # det V = 1
p, q = V[0, 0], V[1, 0]
gamma = 2 * np.arctan2(abs(q), abs(p))
lam, kap = np.angle(p), np.angle(q)
return alpha, kap - lam, gamma, -kap - lam
rng = np.random.default_rng(45)
worst, form = 0.0, 0.0
for _ in range(1000):
Q, R = np.linalg.qr(rng.standard_normal((2, 2)) + 1j * rng.standard_normal((2, 2)))
U = Q @ np.diag(np.diag(R) / abs(np.diag(R)))
a, b, g, d = zyz(U)
worst = max(worst, abs(np.exp(1j * a) * rz(b) @ ry(g) @ rz(d) - U).max())
phi, theta, omega = rng.uniform(-np.pi, np.pi, 3)
c, s = np.cos(theta / 2), np.sin(theta / 2)
M = np.array([[np.exp(-0.5j * (phi + omega)) * c, -np.exp(0.5j * (phi - omega)) * s],
[np.exp(-0.5j * (phi - omega)) * s, np.exp(0.5j * (phi + omega)) * c]])
form = max(form, abs(M - rot(phi, theta, omega)).max())
print("ZYZ reconstruction of 1000 Haar-random U(2), max error < 1e-12:", worst < 1e-12)
print("explicit Rot matrix = R_Z(omega) R_Y(theta) R_Z(phi), max error < 1e-14:", form < 1e-14)
# (2) One CNOT block as an F2-linear map: CNOT(c, t) is the row operation row_t += row_c (mod 2).
def block(n, r):
A = np.eye(n, dtype=int)
for i in range(n):
E = np.eye(n, dtype=int)
E[(i + r) % n, i] = 1
A = E @ A % 2
return A
def inverse_f2(A):
n = len(A)
M = np.concatenate([A % 2, np.eye(n, dtype=int)], axis=1)
for col in range(n):
piv = next(k for k in range(col, n) if M[k, col])
M[[col, piv]] = M[[piv, col]]
for k in range(n):
if k != col and M[k, col]:
M[k] = (M[k] + M[col]) % 2
return M[:, n:]
for n, r in [(3, 1), (3, 2)]:
A = block(n, r)
Ai = inverse_f2(A)
print(f"n={n} r={r}: A={A.tolist()} A^-1={Ai.tolist()} A A^-1 = I: {np.array_equal(A @ Ai % 2, np.eye(n, dtype=int))}")
# (3) r = 1: y_0 = x_1 + ... + x_{n-1}, y_k = x_0 + ... + x_k (k >= 1), so every pair of wires is coupled.
for n in range(2, 9):
A = block(n, 1)
pred = np.array([[int(j >= 1) for j in range(n)]] + [[int(j <= k) for j in range(n)] for k in range(1, n)])
coupled = all(A[i, j] or A[j, i] for i in range(n) for j in range(n) if i != j)
print(f"n={n}: prefix/suffix formula {np.array_equal(A, pred)}, all pairs coupled {coupled}")
# (4) Pairs {i, j} that share a CNOT after L layers with the default ranges r_l = (l mod (n-1)) + 1.
for n in range(2, 9):
full = next(L for L in range(1, n + 1)
if len({frozenset((i, (i + (l % (n - 1)) + 1) % n)) for l in range(L) for i in range(n)}) == n * (n - 1) // 2)
print(f"n={n}: every pair shares a CNOT after {full} layer(s) (floor(n/2) = {n // 2})")Expected output
ZYZ reconstruction of 1000 Haar-random U(2), max error < 1e-12: True explicit Rot matrix = R_Z(omega) R_Y(theta) R_Z(phi), max error < 1e-14: True n=3 r=1: A=[[0, 1, 1], [1, 1, 0], [1, 1, 1]] A^-1=[[1, 0, 1], [1, 1, 1], [0, 1, 1]] A A^-1 = I: True n=3 r=2: A=[[1, 1, 0], [1, 1, 1], [1, 0, 1]] A^-1=[[1, 1, 1], [0, 1, 1], [1, 1, 0]] A A^-1 = I: True n=2: prefix/suffix formula True, all pairs coupled True n=3: prefix/suffix formula True, all pairs coupled True n=4: prefix/suffix formula True, all pairs coupled True n=5: prefix/suffix formula True, all pairs coupled True n=6: prefix/suffix formula True, all pairs coupled True n=7: prefix/suffix formula True, all pairs coupled True n=8: prefix/suffix formula True, all pairs coupled True n=2: every pair shares a CNOT after 1 layer(s) (floor(n/2) = 1) n=3: every pair shares a CNOT after 1 layer(s) (floor(n/2) = 1) n=4: every pair shares a CNOT after 2 layer(s) (floor(n/2) = 2) n=5: every pair shares a CNOT after 2 layer(s) (floor(n/2) = 2) n=6: every pair shares a CNOT after 3 layer(s) (floor(n/2) = 3) n=7: every pair shares a CNOT after 3 layer(s) (floor(n/2) = 3) n=8: every pair shares a CNOT after 4 layer(s) (floor(n/2) = 4)
References
- M. Schuld, A. Bocharov, K. M. Svore and N. Wiebe, Circuit-centric quantum classifiers, Physical Review A 101, 032308 (2020).doi:10.1103/PhysRevA.101.032308
- PennyLane documentation, qml.StronglyEntanglingLayers (template reference, ranges and imprimitive gates).docs.pennylane.ai
- M. A. Nielsen and I. L. Chuang, Quantum Computation and Quantum Information, 10th anniversary edition, Cambridge University Press (2010), Theorem 4.1 (Z–Y decomposition for a single qubit).doi:10.1017/CBO9780511976667
- V. Bergholm et al., PennyLane: Automatic differentiation of hybrid quantum-classical computations, arXiv:1811.04968 (2018).arxiv.org
- S. Sim, P. D. Johnson and A. Aspuru-Guzik, Expressibility and entangling capability of parameterized quantum circuits for hybrid quantum-classical algorithms, Advanced Quantum Technologies 2, 1900070 (2019).doi:10.1002/qute.201900070
Hands-on labs
Build strongly entangling layers
1 step · auto-gradedOpen labImplement PennyLane-convention strongly entangling layers as a list of Circuit-IR operations: on every wire the general rotation , then the cyclic CNOT block with the layer-dependent range . The grader compares the unitary of your circuit with the reference unitary on weight tensors of shapes , , and , requiring process fidelity at least .