supermarq.stabilizers

Classes

MeasurementCircuit

A circuit to simultaneously measure a set of stabilizers.

Functions

apply_CNOT(→ None)

Apply a CNOT gate on the specified qubits.

apply_CZ(→ None)

Apply a CZ gate on the specified qubits.

apply_H(→ None)

Apply a Hadamard on the specified qubit.

apply_S(→ None)

Apply an S gate on the specified qubit.

apply_SWAP(→ None)

Apply a SWAP gate on the specified qubits.

binary_gaussian_elimination(...)

Use binary Gaussian elimination to put the input matrix in row echelon form.

change_X_to_Z_basis(→ None)

Apply Hadamards to swap the Z and X matrices.

construct_stabilizer(...)

Construct the independent Z+X stabilizer matrix for the given clique.

patch_Z_matrix(→ None)

Apply S and CZ operations to clear the Z matrix.

prepare_X_matrix(→ None)

Apply H's to a subset of qubits to ensure that the X matrix has full rank.

row_reduce_X_matrix(→ None)

Use Gaussian elimination to reduce the Z matrix to the Identity matrix.

transform_X_matrix_to_reduced_row_echelon_form(→ None)

Apply CNOTs to put the X matrix in reduced echelon form.

transform_X_matrix_to_row_echelon_form(→ None)

Apply SWAPs and CNOTs until the X matrix is in row echelon form.

Module Contents

class supermarq.stabilizers.MeasurementCircuit(circuit: cirq.Circuit, stabilizer_matrix: numpy.typing.NDArray[numpy.uint8], num_qubits: int, qubits: list[cirq.LineQubit])

A circuit to simultaneously measure a set of stabilizers.

The getter and setter functions defined here are used by the Mermin Bell benchmark which constructs a simultaneous measurement circuit using a Gaussian elimination process.

get_circuit() cirq.Circuit

Gets the current circuit.

Returns:

The current quantum circuit.

get_stabilizer() numpy.typing.NDArray[numpy.uint8]

Gets the current stabilizer matrix.

The stabilizer matrix is in the Z+X format where M Pauli strings, acting on N qubits, is represented as a (2*N, M) matrix.

For instance, YYI, XXY, IYZ would be represented by .. code:

[[1, 0, 0],  ========
 [1, 0, 1],  Z matrix (top half)
 [0, 1, 1],  ========
 [1, 1, 0],  ========
 [1, 1, 1],  X matrix (bottom half)
 [0, 1, 0]   ========
Returns:

The current stabilizer matrix.

set_circuit(circuit: cirq.Circuit) None

Assign the class circuit to the input circuit.

Parameters:

circuit – The new circuit which will override the current one.

set_stabilizer(stabilizer_matrix: numpy.typing.NDArray[numpy.uint8]) None

The input matrix is assigned to the class matrix.

Parameters:

stabilizer_matrix – An input matrix in X+Z format.

circuit
num_qubits
qubits
stabilizer_matrix
supermarq.stabilizers.apply_CNOT(measurement_circuit: MeasurementCircuit, control_index: int, target_index: int) None

Apply a CNOT gate on the specified qubits.

Parameters:
  • measurement_circuit – The current measurement circuit to act on.

  • control_index – Index of the control qubit.

  • target_index – Index of the target qubit.

supermarq.stabilizers.apply_CZ(measurement_circuit: MeasurementCircuit, i: int, j: int) None

Apply a CZ gate on the specified qubits.

Parameters:
  • measurement_circuit – The current measurement circuit to act on.

  • i – Index of the control qubit.

  • j – Index of the target qubit.

supermarq.stabilizers.apply_H(measurement_circuit: MeasurementCircuit, i: int) None

Apply a Hadamard on the specified qubit.

Parameters:
  • measurement_circuit – The current measurement circuit to act on.

  • i – Index of the target qubit.

supermarq.stabilizers.apply_S(measurement_circuit: MeasurementCircuit, i: int) None

Apply an S gate on the specified qubit.

Parameters:
  • measurement_circuit – The current measurement circuit to act on.

  • i – Index of the target qubit.

supermarq.stabilizers.apply_SWAP(measurement_circuit: MeasurementCircuit, i: int, j: int) None

Apply a SWAP gate on the specified qubits.

Parameters:
  • measurement_circuit – The current measurement circuit to act on.

  • i – Index of the control qubit.

  • j – Index of the target qubit.

supermarq.stabilizers.binary_gaussian_elimination(M: numpy.typing.NDArray[numpy.uint8]) numpy.typing.NDArray[numpy.uint8]

Use binary Gaussian elimination to put the input matrix in row echelon form.

The input matrix should be a binary matrix.

Parameters:

M – Input matrix that contains linearly depedent columns.

Returns:

A modified matrix in row echelon form.

supermarq.stabilizers.change_X_to_Z_basis(measurement_circuit: MeasurementCircuit) None

Apply Hadamards to swap the Z and X matrices.

Parameters:

measurement_circuit – The current measurement circuit to act on.

supermarq.stabilizers.construct_stabilizer(N: int, clique: list[tuple[float, str]]) tuple[numpy.typing.NDArray[numpy.uint8], list[str]]

Construct the independent Z+X stabilizer matrix for the given clique.

All of the terms in the input clique can be measured simultaneously. To construct the circuit which will perform this measurement we need to find an independent basis for these terms. We’ll do this by constructing the Z+X stabilizer matrix using all of the terms then select an independent basis using binary Gaussian elimination.

This implementation follows the design of Algorithm 2 in [Minimizing State Preparations in Variational Quantum Eigensolver by Partitioning into Commuting Families](https://arxiv.org/abs/1907.13623).

Note

This implementation is tailored to the Mermin operator, and assumes that no Pauli Z matrices appear in the clique terms. This function will fail if applied to general Pauli strings.

Parameters:
  • N – An integer corresponding to the number of qubits.

  • clique – A list of (coefficient, Pauli string) pairs, for example: [(-1.2, XXY), (2.3, ZXI), …].

Returns:

The reduced stabilizer matrix and the set of independent Paulis.

supermarq.stabilizers.patch_Z_matrix(measurement_circuit: MeasurementCircuit) None

Apply S and CZ operations to clear the Z matrix.

Parameters:

measurement_circuit – The current measurement circuit to act on.

supermarq.stabilizers.prepare_X_matrix(measurement_circuit: MeasurementCircuit) None

Apply H’s to a subset of qubits to ensure that the X matrix has full rank.

Parameters:

measurement_circuit – The current measurement circuit to act on.

supermarq.stabilizers.row_reduce_X_matrix(measurement_circuit: MeasurementCircuit) None

Use Gaussian elimination to reduce the Z matrix to the Identity matrix.

Parameters:

measurement_circuit – The current measurement circuit to act on.

supermarq.stabilizers.transform_X_matrix_to_reduced_row_echelon_form(measurement_circuit: MeasurementCircuit) None

Apply CNOTs to put the X matrix in reduced echelon form.

The X stabilizer matrix of the input MeasurementCircuit should already be in row echelon form.

Parameters:

measurement_circuit – The current measurement circuit to act on.

supermarq.stabilizers.transform_X_matrix_to_row_echelon_form(measurement_circuit: MeasurementCircuit) None

Apply SWAPs and CNOTs until the X matrix is in row echelon form.

Parameters:

measurement_circuit – The current measurement circuit to act on.