mimiqcircuits.paulibased¶
Pauli-based computation pass.
Functions
|
Rewrite a circuit in Pauli-based computation form. |
- pauli_based_computation(circuit, basis=None, magic_states=False)[source]¶
Rewrite a circuit in Pauli-based computation form.
The result is a sequence of \(\pi/8\) Pauli product rotations (
RPauliwith angle \(\pm\pi/4\)) and Pauli product measurements (MeasurePauli), with no Clifford gates left.The circuit is first decomposed with
basis, which must produce Clifford+T gates, the measurements and resets listed below, and the conditional operations described below. Those measurements, resets and conditional Pauli products are kept whole, whateverbasisdoes with them. Each Clifford \(C\) is then moved past every later T gate and measurement, conjugating them: a T gate on qubit \(q\) becomes the rotation \(\exp(-i \frac{\pi}{8} C^\dagger Z_q C)\), and a measurement of \(Z_q\) becomes a measurement of \(C^\dagger Z_q C\). When the conjugated observable has a minus sign, the rotation angle is negated, or the measured bit is flipped withNot.The Cliffords left after the last measurement do not change any outcome and are dropped. The result therefore reproduces the measurement statistics of
circuit, not its final quantum state, and each rotation is exact up to a global phase. Classical operations and annotations are kept in place; barriers and identity gates are dropped.Measurements, resets and conditional operations
Measure,MeasureX,MeasureY,MeasureXX,MeasureYY,MeasureZZandMeasurePaulimeasure a Pauli product \(P\) and become aMeasurePauliof \(C^\dagger P C\).A reset in the Z, X or Y basis (
Reset,ResetX,ResetY) measures \(Z\), \(X\) or \(Y\) into a new bit, then applies, if the outcome is 1, the Pauli that maps the \(-1\) eigenstate to the \(+1\) one: \(X\) for the Z and Y bases, \(Z\) for the X basis. The measure-and-reset operations (MeasureReset,MeasureResetX,MeasureResetY) do the same with the bit they are given.An
IfStatementwhose body is made only of Pauli operators applies one Pauli product \(P\) when its condition holds. The body can beGateX,GateY,GateZ,GateID, aPauliString, or aBlock,Parallel,RepeatorGateCallholding only such operations, at any depth. It becomes oneIfStatementof thePauliString\(C^\dagger P C\) with the same condition. The phase of \(P\) is dropped, as it only multiplies one classical branch.A conditional T or T† gate becomes a conditional
RPaulirotation with the same condition.
Any other conditional operation is refused. After a conditional Clifford gate, the accumulated Clifford would depend on the condition bits, so the later rotations and measurements could not be computed before the circuit runs.
Magic-state injection
With
magic_states=Truethe rotations are removed as well. Each \(\pi/8\) rotation on \(P\) consumes a magic state \(T\ket{+}\), prepared withPrepareStateTon one ancilla qubit that is reused for every rotation:MeasurePauliof \(P \otimes Z\) on the data qubits and the ancilla, with outcome \(m_1\).MeasurePauliof \(X\) on the ancilla if \(m_1 = 0\), of \(Y\) if \(m_1 = 1\) (swapped for a negative angle), with outcome \(m_2\). The choice is made by twoIfStatementoperations.
When \(m_2 = 1\) the rotation is applied together with a Pauli byproduct \(P\). Byproducts are not corrected with gates. Instead, their product \(F\) is tracked in classical bits, the Pauli frame: one bit for the X part and one for the Z part of \(F\) on each data qubit. When \(m_2 = 1\),
Xoroperations multiply the frame by \(P\). Each later \(m_1\) or measurement outcome whose Pauli anticommutes with \(F\) is flipped in place, again withXor, so the bits hold the outcomes of the ideal circuit.A conditional Pauli, including the correction of a reset, is not applied either: it multiplies the frame when its condition holds, with the same
Xoroperations. A condition other than a single bit equal to 1 is first evaluated into one extra bit withSetBit1and 3-bitAndoperations; each condition bit compared with 0 is flipped withNotwhile it is read and flipped back right after. A conditional T or T† gate is refused, since a magic state cannot be injected conditionally.Every classical operation added is therefore a 3-bit
XororAnd, aNotor aSetBit1, whatever the size of the circuit. The result contains only Pauli product measurements, magic-state preparations and classical logic.Bit layout
Qubits and bits are counted from 0. With \(n_b\) the number of bits of the decomposed circuit and \(r\) its number of resets, the \(j\)-th reset (counting from 0) writes its outcome to bit \(n_b + j\). With magic states, let \(n'_b = n_b + r\), \(n\) be the number of qubits and \(t\) the number of T and T† gates of the decomposed circuit. The ancilla is qubit \(n\). The \(k\)-th rotation (counting from 0) writes \(m_1\) to bit \(n'_b + 2k\) and \(m_2\) to bit \(n'_b + 2k + 1\). The frame bits of qubit \(q\) follow: the X part at bit \(n'_b + 2t + q\) and the Z part at bit \(n'_b + 2t + n + q\). The condition of a conditional Pauli, when it needs its own bit, goes to bit \(n'_b + 2t + 2n\).
- Parameters:
circuit (Circuit) – the circuit to rewrite.
basis (DecompositionBasis or RewriteRule, optional) – the basis used for the first decomposition. A rewrite rule is wrapped in a
RuleBasis. Defaults toCliffordTBasis.magic_states (bool, optional) – replace every rotation by magic-state injection. Defaults to
False.
- Returns:
a new circuit made of
RPauli,MeasurePauli, conditionalPauliStringandRPaulioperations, classical operations and annotations. Withmagic_states=True,PrepareStateT, conditionalMeasurePaulioperations and classical logic replace the rotations and conditional Paulis.- Return type:
- Raises:
ValueError – if the decomposed circuit contains anything other than Clifford+T gates, the measurements and resets listed above, the conditional operations listed above, classical operations and annotations: for example a non-Clifford gate, a conditional Clifford gate or a conditional measurement. With
magic_states=True, a conditional T or T† gate also raises aValueError.DecompositionError – if
basiscannot decompose an operation, such as a noise channel.
Examples
Prepare a Bell pair, apply a T gate to qubit 1 and measure both qubits:
>>> from mimiqcircuits import * >>> c = Circuit() >>> _ = c.push(GateH(), 0) >>> _ = c.push(GateCX(), 0, 1) >>> _ = c.push(GateT(), 1) >>> _ = c.push(Measure(), range(2), range(2)) >>> pauli_based_computation(c) 2-qubit, 2-bit circuit with 3 instructions: ├── R("XZ", (1/4)*pi) @ q[0:1] ├── MP(X) @ q[0], c[0] └── MP(XZ) @ q[0:1], c[1]
The Clifford before the T gate is \(C = \mathrm{CX}_{01} H_0\), so the T gate becomes a \(\pi/8\) rotation on \(C^\dagger Z_1 C = X_0 Z_1\). The two measurements of \(Z_0\) and \(Z_1\) become measurements of \(X_0\) and \(X_0 Z_1\), and write to the same bits as before.
With magic states, the rotation becomes an injection on the ancilla qubit 2, whose outcomes \(m_1\) and \(m_2\) go to the new bits 2 and 3:
>>> pauli_based_computation(c, magic_states=True) 3-qubit, 8-bit circuit with 8 instructions: ├── PrepareStateT @ q[2] ├── MP(XZZ) @ q[0:2], c[2] ├── IF(c==0) MP(X) @ q[2], c[3], condition[2] ├── IF(c==1) MP(Y) @ q[2], c[3], condition[2] ├── c[4] ^= c[3] ├── c[7] ^= c[3] ├── MP(X) @ q[0], c[0] └── MP(XZ) @ q[0:1], c[1]
The ancilla is measured in X or Y depending on \(m_1\) (bit 2). The byproduct \(X_0 Z_1\) goes into the frame: bit 4 holds its X part on qubit 0 and bit 7 its Z part on qubit 1. The final measurements commute with it, so their bits are not corrected.
A conditional Pauli and a reset. The Hadamard gate before the conditional \(Z_1\) turns it into a conditional \(X_1\), and the reset of qubit 0 after its Hadamard gate measures \(X_0\) into the new bit 3, then applies \(Z_0\) if the outcome is 1:
>>> c = Circuit() >>> _ = c.push(GateH(), 0) >>> _ = c.push(Measure(), 0, 0) >>> _ = c.push(GateH(), 1) >>> _ = c.push(IfStatement(GateZ(), BitString("1")), 1, 0) >>> _ = c.push(Reset(), 0) >>> _ = c.push(Measure(), range(2), range(1, 3)) >>> pauli_based_computation(c) 2-qubit, 4-bit circuit with 6 instructions: ├── MP(X) @ q[0], c[0] ├── IF(c==1) X @ q[1], condition[0] ├── MP(X) @ q[0], c[3] ├── IF(c==1) Z @ q[0], condition[3] ├── MP(X) @ q[0], c[1] └── MP(X) @ q[1], c[2]
References
D. Litinski, “A Game of Surface Codes: Large-Scale Quantum Computing with Lattice Surgery”, Quantum 3, 128 (2019).
S. Bravyi, G. Smith, J. A. Smolin, “Trading Classical and Quantum Computational Resources”, Phys. Rev. X 6, 021043 (2016).
See also
MeasurePauli,PrepareStateT,RPauli,CliffordTBasis