supermarq.stabilizers ===================== .. py:module:: supermarq.stabilizers Classes ------- .. autoapisummary:: supermarq.stabilizers.MeasurementCircuit Functions --------- .. autoapisummary:: supermarq.stabilizers.apply_CNOT supermarq.stabilizers.apply_CZ supermarq.stabilizers.apply_H supermarq.stabilizers.apply_S supermarq.stabilizers.apply_SWAP supermarq.stabilizers.binary_gaussian_elimination supermarq.stabilizers.change_X_to_Z_basis supermarq.stabilizers.construct_stabilizer supermarq.stabilizers.patch_Z_matrix supermarq.stabilizers.prepare_X_matrix supermarq.stabilizers.row_reduce_X_matrix supermarq.stabilizers.transform_X_matrix_to_reduced_row_echelon_form supermarq.stabilizers.transform_X_matrix_to_row_echelon_form Module Contents --------------- .. py:class:: 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. .. py:method:: get_circuit() -> cirq.Circuit Gets the current circuit. :returns: The current quantum circuit. .. py:method:: 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. .. py:method:: set_circuit(circuit: cirq.Circuit) -> None Assign the class circuit to the input circuit. :param circuit: The new circuit which will override the current one. .. py:method:: set_stabilizer(stabilizer_matrix: numpy.typing.NDArray[numpy.uint8]) -> None The input matrix is assigned to the class matrix. :param stabilizer_matrix: An input matrix in X+Z format. .. py:attribute:: circuit .. py:attribute:: num_qubits .. py:attribute:: qubits .. py:attribute:: stabilizer_matrix .. py:function:: apply_CNOT(measurement_circuit: MeasurementCircuit, control_index: int, target_index: int) -> None Apply a CNOT gate on the specified qubits. :param measurement_circuit: The current measurement circuit to act on. :param control_index: Index of the control qubit. :param target_index: Index of the target qubit. .. py:function:: apply_CZ(measurement_circuit: MeasurementCircuit, i: int, j: int) -> None Apply a CZ gate on the specified qubits. :param measurement_circuit: The current measurement circuit to act on. :param i: Index of the control qubit. :param j: Index of the target qubit. .. py:function:: apply_H(measurement_circuit: MeasurementCircuit, i: int) -> None Apply a Hadamard on the specified qubit. :param measurement_circuit: The current measurement circuit to act on. :param i: Index of the target qubit. .. py:function:: apply_S(measurement_circuit: MeasurementCircuit, i: int) -> None Apply an S gate on the specified qubit. :param measurement_circuit: The current measurement circuit to act on. :param i: Index of the target qubit. .. py:function:: apply_SWAP(measurement_circuit: MeasurementCircuit, i: int, j: int) -> None Apply a SWAP gate on the specified qubits. :param measurement_circuit: The current measurement circuit to act on. :param i: Index of the control qubit. :param j: Index of the target qubit. .. py:function:: 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. :param M: Input matrix that contains linearly depedent columns. :returns: A modified matrix in row echelon form. .. py:function:: change_X_to_Z_basis(measurement_circuit: MeasurementCircuit) -> None Apply Hadamards to swap the Z and X matrices. :param measurement_circuit: The current measurement circuit to act on. .. py:function:: 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. :param N: An integer corresponding to the number of qubits. :param 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. .. py:function:: patch_Z_matrix(measurement_circuit: MeasurementCircuit) -> None Apply S and CZ operations to clear the Z matrix. :param measurement_circuit: The current measurement circuit to act on. .. py:function:: prepare_X_matrix(measurement_circuit: MeasurementCircuit) -> None Apply H's to a subset of qubits to ensure that the X matrix has full rank. :param measurement_circuit: The current measurement circuit to act on. .. py:function:: row_reduce_X_matrix(measurement_circuit: MeasurementCircuit) -> None Use Gaussian elimination to reduce the Z matrix to the Identity matrix. :param measurement_circuit: The current measurement circuit to act on. .. py:function:: 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. :param measurement_circuit: The current measurement circuit to act on. .. py:function:: transform_X_matrix_to_row_echelon_form(measurement_circuit: MeasurementCircuit) -> None Apply SWAPs and CNOTs until the X matrix is in row echelon form. :param measurement_circuit: The current measurement circuit to act on.