qp.gridsynth¶
- gridsynth(qnode, epsilon=0.0001, ppr_basis=False, method='deterministic')¶
Decomposes RZ and PhaseShift gates into the Clifford+T basis or the PPR basis.
Warning
This transform must be applied within a workflow compiled with
pennylane.qjit(), as it is a frontend for Catalyst’sgridsynthcompilation pass. Consult the Catalyst documentation for more information.- Parameters:
tape (QNode) – A quantum circuit.
epsilon (float) – The accuracy per rotation gate. Defaults to
1e-4. With"deterministic", each rotation has operator norm error at mostepsilon, and therefore diamond norm error at most \(2\epsilon\). With"mixed"and"mixed-fallback", the channel averaged over samples has diamond norm error at most \(2\epsilon\).ppr_basis (bool) – If True, decompose into the PPR basis. If False, decompose into the Clifford+T basis. Defaults to
False.method (str) – The synthesis method.
"deterministic"(default) uses the standard Ross-Selinger discretization."mixed"uses the mixed diagonal approximation (arXiv:2203.10064 Section 3.4). It randomly applies either an under- or an over-rotated sequence, additionally twirled over the group \(\{I, S, Z, S^\dagger\}\). This roughly halves the T-count at the same accuracy."mixed-fallback"uses the mixed fallback approximation (Section 3.5). It randomly applies one of two projective rotations on an ancilla qubit, followed by a mixed diagonal fallback if measuring the ancilla signals failure. This roughly halves the T-count of"mixed"again.
Note
With
method="mixed"ormethod="mixed-fallback", the gate sequence of each rotation is sampled at execution time from the runtime random number generator, which is seeded by theseedargument ofqjit(). The accuracy guarantee holds for the channel averaged over these samples, while each sampled sequence has an error of order \(\sqrt{\epsilon}\). By default, and withmcm_method="single-branch-statistics", a call samples one sequence per rotation, shared by all its shots. Withmcm_method="one-shot", every shot samples its own.With
method="mixed-fallback", each rotation uses a temporary ancilla qubit and a mid-circuit measurement.Resource estimates from
specs()report the expected gate counts, since the actual sequences are only known at execution time. Withmethod="mixed-fallback", they also report one additional wire per rotation for its temporary ancilla.Example
@qp.qnode(qp.device("lightning.qubit", wires=1)) def circuit(x): qp.Hadamard(0) qp.RZ(x, 0) qp.PhaseShift(x * 0.2, 0) return qp.state() gridsynth_circuit = qp.transforms.gridsynth(circuit, epsilon=1e-4) qjitted_circuit = qp.qjit(gridsynth_circuit)
>>> circuit(1.1) array([0.60282587-0.36959568j, 0.5076395 +0.49224195j]) >>> qjitted_circuit(1.1) Array([0.60282699-0.36962758j, 0.50758458+0.49227326j], dtype=complex128)
Mixed synthesis reaches the same accuracy with roughly half the T gates, and mixed fallback synthesis with roughly half of that:
def t_count(method): @qp.qjit(capture=True, target="mlir") @qp.transforms.gridsynth(epsilon=1e-6, method=method) @qp.qnode(qp.device("null.qubit", wires=1)) def circuit(x: float): qp.RZ(x, 0) return qp.expval(qp.Z(0)) return qp.specs(circuit, level="user")(1.1).resources.quantum_operations["T"]
>>> t_count("deterministic"), t_count("mixed"), t_count("mixed-fallback") (63, 31, 16)