PennyLane
  • Why PennyLane
  • Getting Started
  • Documentation
  • Ecosystem
Install
Install
  1. Compilation/
  2. PermRowCol Algorithm

PermRowCol Algorithm

OverviewDetailsBenchmarksResources

Preliminaries

We briefly review two core concepts necessary to understand the PermRowCol algorithm: the parity matrix intermediate representation and the RowCol algorithm. For more details we refer to the linked pages.

Parity matrix

The parity matrix describes the action of a CNOT circuit. The action of a CNOT gate on a computational basis state |x_0 x_1\rangle with x_i \in \{0, 1\} is:

\text{CNOT}_{x_0 x_1} |x_0, x_1\rangle = |x_0, x_0 \oplus x_1\rangle

In circuit form, this is the following:

x_0: ─╭●─┤ x_0 x_1: ─╰X─┤ x_0 ⊕ x_1

The corresponding parity matrix P is:

P = \begin{pmatrix} 1 & 0 \\ 1 & 1 \end{pmatrix}

In particular, a computational basis input state \boldsymbol{x} = (x_0, x_1) is mapped to the (row) vector-matrix product P \boldsymbol{x}.

One way to interpret this is to say that \text{CNOT}_{x_\text{control} x_\text{target}} corresponds to adding the row of the control qubit to the row of the target qubit in the parity matrix. We will sometimes use the shorthand notation x_\text{control} \rightarrow x_\text{target} for that.

We can then describe a whole CNOT circuit with this logic by means of its action on arbitrary computational basis states |x_0 x_1 .. x_{n-1}\rangle. Take, for example, the following circuit.

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

The corresponding parity matrix is given by:

P = \begin{pmatrix} 0 & 1 & 0 & 0 \\ 1 & 1 & 0 & 0 \\ 1 & 1 & 1 & 0 \\ 1 & 1 & 0 & 1\end{pmatrix}

The rows of the parity matrix show how the input bits are transformed. In particular, we can read out x_0 \mapsto x_1 and x_1 \mapsto x_0 \oplus x_1, etc. from the parity matrix directly.

This is the example from Fig. 3 in [1]. Note that the parity matrix in the reference is transposed, following our convention for the parity matrix, such that \boldsymbol{x}' = P \boldsymbol{x}.

RowCol algorithm

The RowCol algorithm synthesizes a CNOT circuit, given a parity matrix IR of the circuit and a connectivity graph G. For example, consider the parity matrix P from above and the simple connectivity graph:

(0) - (1) - (2) - (3)

The algorithm works by eliminating each vertex of the graph. An arbitrary non-cut vertex is eliminated by turning the row and column into elementary basis vectors. Let us consider the non-cut vertex (0) to be eliminated:

\begin{pmatrix} \color{blue}0 & \color{blue}1 & \color{blue}0 & \color{blue}0 \\ \color{blue}1 & 1 & 0 & 0 \\ \color{blue}1 & 1 & 1 & 0 \\ \color{blue}1 & 1 & 0 & 1\end{pmatrix} \rightarrow \begin{pmatrix} \color{blue}1 & \color{blue}0 & \color{blue}0 & \color{blue}0 \\ \color{blue}0 & \cdot & \cdot & \cdot \\ \color{blue}0 & \cdot & \cdot & \cdot \\ \color{blue}0 & \cdot & \cdot & \cdot\end{pmatrix}.

Eliminations are done using only CNOT gates that are allowed by the connectivity graph. In order to perform optimal deletions with no redundancy, so-called Steiner trees are utilized that yield a minimal sub-tree of G that encompasses all required qubits to delete the row/column. The details are described in an extensive example in the details section of the RowCol algorithm page.

This step is repeated for every vertex in the connectivity graph until the identity matrix is obtained. All CNOT operations along the way are recorded, and their reverse-ordered circuit is the result that implements the parity matrix.

PermRowCol algorithm

The RowCol algorithm enforces a fixed mapping between logical and physical qubits. This is because the synthesis targets the identity matrix. There are cases where we can save resources by loosening this requirement and allowing for a new qubit allocation. This is essentially what PermRowCol does: instead of targeting the identity matrix, we target a permutation matrix, therefore leading to a new logical qubit allocation. The resulting permutation matrix informs this allocation. For example, if the resulting permutation matrix is:

\begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 \end{pmatrix}

which corresponds to permuting the second and fourth qubit.

The algorithm works analogously to RowCol with the main difference that instead of eliminating the row and column with the same index, we eliminate some row i and another column j in one step, resulting in a permutation matrix instead. It is not clear, a priori, which permutation matrix is best to target. The authors propose a heuristic based on picking the row and respective column with the lowest Hamming weight (counting the number of 1s) to be eliminated.

Reverse Traversal

The results of PermRowCol can be significantly reduced when utilizing reverse traversal [3]. That is, after finishing one round of PermRowCol with some resulting permutation matrix, the process is restarted but with the inverse (=reverse) circuit and the former output permutation matrix as the input qubit allocation. This way, potentially better CNOT routings can be found, which is also seen in practice, see benchmarks. It may be worth noting that in many cases vanilla PermRowCol, in particular, without reverse traversal, performs worse than RowCol.

PennyLane

PennyLane is an open-source software framework for quantum machine learning, quantum chemistry, and quantum computing, with the ability to run on all hardware. Built with ❤️ by Xanadu.

Stay updated with our newsletter

For researchers

  • Research
  • Features
  • Demos
  • Compilation
  • Datasets
  • Performance
  • Learn
  • Videos
  • Documentation
  • Teach

For learners

  • Learn
  • Codebook
  • Teach
  • Videos
  • Challenges
  • Demos
  • Compilation
  • Glossary

For developers

  • Features
  • Documentation
  • API
  • GitHub
  • Datasets
  • Demos
  • Compilation
  • Performance
  • Devices
  • Catalyst

© Copyright 2025 | Xanadu | All rights reserved

TensorFlow, the TensorFlow logo and any related marks are trademarks of Google Inc.

Privacy Policy|Terms of Service|Cookie Policy|Code of Conduct