qml.labs.intermediate_reps.parity_matrix

parity_matrix(circ, wire_order=None)[source]

Compute the parity matrix intermediate representation of a CNOT circuit.

Parameters:
  • circ (qml.tape.QuantumScript) – Quantum circuit containing only CNOT gates.

  • wire_order (Sequence) – wire_order indicating how rows and columns should be ordered. If None is provided, we take the wires of the input circuit (circ.wires).

Returns:

\(n \times n\) Parity matrix for \(n\) qubits.

Return type:

np.ndarray

Example

import pennylane as qml
from pennylane.labs.intermediate_reps import parity_matrix

circ = qml.tape.QuantumScript([
    qml.CNOT((3, 2)),
    qml.CNOT((0, 2)),
    qml.CNOT((2, 1)),
    qml.CNOT((3, 2)),
    qml.CNOT((3, 0)),
    qml.CNOT((0, 2)),
], [])

P = parity_matrix(circ, wire_order=range(4))
>>> P
array([[1., 0., 0., 1.],
       [1., 1., 1., 1.],
       [0., 0., 1., 1.],
       [0., 0., 0., 1.]])

The corresponding circuit is the following, with output values of the qubits denoted at the right end.

x_0: ────╭●───────╭X─╭●─┤  x_0 ⊕ x_3
x_1: ────│──╭X────│──│──┤  x_0 ⊕ x_1 ⊕ x_2 ⊕ x_3
x_2: ─╭X─╰X─╰●─╭X─│──╰X─┤  x_2 ⊕ x_3
x_3: ─╰●───────╰●─╰●────┤  x_3