Skip to content

circuit_matrix_calculator

get_circuit_matrix(circuit)

Compute the (large) unitary matrix corresponding to the circuit.

This matrix has 4**n elements, where n is the number of qubits. Result is stored as a numpy array of complex numbers.

Returns:

Type Description
NDArray[complex128]

Matrix representation of the circuit.

Source code in opensquirrel\circuit_matrix_calculator.py
def get_circuit_matrix(circuit: Circuit) -> NDArray[np.complex128]:
    """Compute the (large) unitary matrix corresponding to the circuit.

    This matrix has 4**n elements, where n is the number of qubits. Result is stored as a numpy array of complex
    numbers.

    Returns:
        Matrix representation of the circuit.
    """
    impl = _CircuitMatrixCalculator(circuit.qubit_register_size)

    circuit.ir.accept(impl)

    return impl.matrix