Skip to content

circuit_matrix_calculator

get_circuit_matrix

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.

Parameters:

Name Type Description Default
circuit Circuit

The circuit for which to compute the matrix.

required

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.

    Args:
        circuit (Circuit): The circuit for which to compute the matrix.

    Returns:
        Matrix representation of the circuit.

    """
    impl = _CircuitMatrixCalculator(circuit.qubit_register_size)

    circuit.ir.accept(impl)

    return impl.matrix