supermarq.stabilizers
Classes
A circuit to simultaneously measure a set of stabilizers. |
Functions
|
Apply a CNOT gate on the specified qubits. |
|
Apply a CZ gate on the specified qubits. |
|
Apply a Hadamard on the specified qubit. |
|
Apply an S gate on the specified qubit. |
|
Apply a SWAP gate on the specified qubits. |
Use binary Gaussian elimination to put the input matrix, mat, in row echelon form. |
|
|
Apply Hadamards to swap the Z and X matrices. |
|
Construct the independent Z+X stabilizer matrix for the given clique. |
|
Apply S and CZ operations to clear the Z matrix. |
|
Apply H's to a subset of qubits to ensure that the X matrix has full rank. |
|
Use Gaussian elimination to reduce the Z matrix to the Identity matrix. |
Apply CNOTs to put the X matrix in reduced echelon form. |
|
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(mat: numpy.typing.NDArray[numpy.uint8]) numpy.typing.NDArray[numpy.uint8]
Use binary Gaussian elimination to put the input matrix, mat, in row echelon form.
The input matrix should be a binary matrix.
- Parameters:
mat – Input matrix that contains linearly dependent 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(num_qubits: 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:
num_qubits – 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.