qml.transforms.parity_matrix

parity_matrix(circ, wire_order=None)[source]

Compute the parity matrix intermediate representation of a CNOT circuit.

Parameters:
  • circ (QNode or QuantumScript or Callable) – Quantum circuit containing only CNOT gates.

  • wire_order (Sequence) – Indicates how rows and columns should be ordered. If None is provided, uses the wires of the input circuit (tape.wires).

Returns:

\(n \times n\) Parity matrix for \(n\) qubits. In the case of inputting a callable function, a new callable with the same call signature is returned (see pennylane.transform()).

Return type:

TensorLike

Example

import pennylane as qml
from pennylane.transforms import parity_matrix

def circuit():
    qml.CNOT((3, 2))
    qml.CNOT((0, 2))
    qml.CNOT((2, 1))
    qml.CNOT((3, 2))
    qml.CNOT((3, 0))
    qml.CNOT((0, 2))
>>> parity_matrix(circuit, wire_order=range(4))()
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

For more details, see the compilation page on the parity matrix intermediate representation.