def METHOD_NAME(program: "qbraid.QPROGRAM", ensure_contiguous: Optional[bool] = False) -> np.ndarray:
    """Calculates the unitary of any valid input quantum program.
    Args:
        program (:data:`~qbraid.QPROGRAM`): Any quantum program object supported by qBraid.
        ensure_contiguous: If True, calculates unitary using contiguous qubit indexing
    Raises:
        ProgramTypeError: If the input quantum program is not supported.
        UnitaryCalculationError: If the programs unitary could not be calculated.
    Returns:
        Matrix representation of the input quantum program.
    """
    to_unitary_function: Callable[[Any], np.ndarray]
    if isinstance(program, str):
        try:
            package = get_qasm_version(program)
        except QasmError as err:
            raise ProgramTypeError(
                "Input of type string must represent a valid OpenQASM program."
            ) from err
    else:
        try:
            package = program.__module__
        except AttributeError as err:
            raise ProgramTypeError(program) from err
    # whether calculated unitary requires permutation
    # to match qBraid qubit ordering convention
    permute = False
    # pylint: disable=import-outside-toplevel
    if "qiskit" in package:
        from qbraid.interface.qbraid_qiskit.tools import _unitary_from_qiskit
        permute = True
        to_unitary_function = _unitary_from_qiskit
    elif "cirq" in package:
        from qbraid.interface.qbraid_cirq.tools import _unitary_from_cirq
        to_unitary_function = _unitary_from_cirq
    elif "braket" in package:
        from qbraid.interface.qbraid_braket.tools import _unitary_from_braket
        to_unitary_function = _unitary_from_braket
    elif "pyquil" in package:
        from qbraid.interface.qbraid_pyquil.tools import _unitary_from_pyquil
        permute = True
        to_unitary_function = _unitary_from_pyquil
    elif "pytket" in package:
        from qbraid.interface.qbraid_pytket.tools import _unitary_from_pytket
        to_unitary_function = _unitary_from_pytket
    elif package == "qasm2":
        from qbraid.interface.qbraid_qasm.tools import _unitary_from_qasm
        to_unitary_function = _unitary_from_qasm
    elif package == "qasm3":
        from qbraid.interface.qbraid_qasm3.tools import _unitary_from_qasm3
        permute = True
        to_unitary_function = _unitary_from_qasm3
    else:
        raise ProgramTypeError(program)
    program_input = convert_to_contiguous(program) if ensure_contiguous else program
    try:
        unitary = to_unitary_function(program_input)
        compat_unitary = rev_qubits_unitary(unitary) if permute else unitary
    except Exception as err:
        raise UnitaryCalculationError(
            "Unitary could not be calculated from given quantum program."
        ) from err
    return compat_unitary