def pyquest_call_operation(
        operation: Any,
        qureg: tqureg,
        classical_bit_registers: Dict[str, List[bool]],
        classical_float_registers: Dict[str, List[float]],
        classical_complex_registers: Dict[str, List[complex]],
        output_bit_register_dict: Dict[str, List[List[bool]]],
) -> None:
    """Execute the qoqo operation with PyQuEST

    Args:
        operation: The qoqo operation that is executed
        qureg: The quantum register pyquest_cffi operates on
        classical_bit_registers: Dictionary or registers (lists) containing bit readout values
        classical_float_registers: Dictionary or registers (lists) containing float readout values
        classical_complex_registers: Dictionary or registers (lists)
                                     containing complex readout values
        output_bit_register_dict: Dictionary or lists of registers (lists)
                              containing a register for each repetition of the circuit

    Raises:
        RuntimeError: Operation not in PyQuEST backend
    """
    tags = operation.tags()
    if 'RotateZ' in tags:
        operation = cast(ops.RotateZ, operation)
        qops.rotateZ()(qureg=qureg, qubit=operation.qubit(), theta=operation.theta().float())
    elif 'RotateX' in tags:
        operation = cast(ops.RotateX, operation)
        qops.rotateX()(qureg=qureg, qubit=operation.qubit(), theta=operation.theta().float())
    elif 'RotateY' in tags:
        operation = cast(ops.RotateY, operation)
        qops.rotateY()(qureg=qureg, qubit=operation.qubit(), theta=operation.theta().float())
    elif 'SqrtISwap' in tags:
        operation = cast(ops.SqrtISwap, operation)
        qops.sqrtISwap()(qureg=qureg, control=operation.control(), qubit=operation.target())
    elif 'CNOT' in tags:
        operation = cast(ops.CNOT, operation)
        qops.controlledNot()(qureg=qureg, control=operation.control(), qubit=operation.target())
    elif 'InvSqrtISwap' in tags:
        operation = cast(ops.InvSqrtISwap, operation)
        qops.invSqrtISwap()(qureg=qureg, control=operation.control(), qubit=operation.target())
    elif 'Hadamard' in tags:
        operation = cast(ops.Hadamard, operation)
        qops.hadamard()(qureg=qureg, qubit=operation.qubit())
    elif 'PauliX' in tags:
        operation = cast(ops.PauliX, operation)
        qops.pauliX()(qureg=qureg, qubit=operation.qubit())
    elif 'PauliY' in tags:
        operation = cast(ops.PauliY, operation)
        qops.pauliY()(qureg=qureg, qubit=operation.qubit())
    elif 'PauliZ' in tags:
        operation = cast(ops.PauliZ, operation)
        qops.pauliZ()(qureg=qureg, qubit=operation.qubit())
    elif 'SGate' in tags:
        operation = cast(ops.SGate, operation)
        qops.sGate()(qureg=qureg, qubit=operation.qubit())
    elif 'TGate' in tags:
        operation = cast(ops.TGate, operation)
        qops.tGate()(qureg=qureg, qubit=operation.qubit())
    elif 'SqrtPauliX' in tags:
        qops.rotateX()(qureg=qureg, qubit=operation.qubit(), theta=np.pi / 2)
    elif 'InvSqrtPauliX' in tags:
        qops.rotateX()(qureg=qureg, qubit=operation.qubit(), theta=-np.pi / 2)
    elif 'ControlledPhaseShift' in tags:
        qops.controlledPhaseShift()(qureg=qureg, control=operation.control(),
                                    qubit=operation.target(), theta=operation.theta().float())
    elif 'ControlledPauliY' in tags:
        qops.controlledPauliY()(qureg=qureg, control=operation.control(),
                                qubit=operation.target())
    elif 'ControlledPauliZ' in tags:
        qops.controlledPhaseFlip()(qureg=qureg, control=operation.control(),
                                   qubit=operation.target())
    elif 'RotateAroundSphericalAxis' in tags:
        qops.rotateAroundSphericalAxis()(
            qureg=qureg, qubit=operation.qubit(), theta=operation.theta().float(),
            spherical_theta=operation.spherical_theta().float(),
            spherical_phi=operation.spherical_phi().float())
    elif 'SingleQubitGateOperation' in tags:
        qops.compactUnitary()(qubit=operation.qubit(),
                              qureg=qureg,
                              alpha=operation.alpha_r().float() + 1j * operation.alpha_i().float(),
                              beta=operation.beta_r().float() + 1j * operation.beta_i().float())
    elif 'TwoQubitGateOperation' in tags:
        qops.twoQubitUnitary()(qureg=qureg, target_qubit_2=operation.control(),
                               target_qubit_1=operation.target(), matrix=operation.unitary_matrix())
    elif 'PragmaRepeatedMeasurement' in tags:
        _execute_PragmaRepeatedMeasurement(
            operation, qureg,
            classical_bit_registers,
            output_bit_register_dict,
        )
    elif 'PragmaDamping' in tags:
        qops.mixDamping()(
            qureg=qureg, qubit=operation.qubit(), probability=operation.probability().float())
    elif 'PragmaDepolarising' in tags:
        qops.mixDepolarising()(
            qureg=qureg, qubit=operation.qubit(), probability=operation.probability().float())
    elif 'PragmaDephasing' in tags:
        qops.mixDephasing()(
            qureg=qureg, qubit=operation.qubit(), probability=operation.probability().float())
    elif 'PragmaSetStateVector' in tags:
        vector = operation.statevector()
        qcheat.initStateFromAmps()(qureg=qureg, reals=np.real(vector), imags=np.imag(vector))
    elif 'PragmaSetDensityMatrix' in tags:
        density_matrix = operation.density_matrix()
        # dim = int(np.round(np.sqrt(density_matrix.shape[0])))
        # density_matrix = density_matrix.reshape((dim, dim))
        qcheat.initStateFromAmps()(
            qureg=qureg, reals=np.real(density_matrix), imags=np.imag(density_matrix))
    elif 'PragmaRandomNoise' in tags:
        _execute_PragmaRandomNoise(
            operation, qureg,
        )
    elif 'PragmaActiveReset' in tags:
        _execute_PragmaActiveReset(
            operation, qureg,
        )
    elif 'MeasureQubit' in tags:
        _execute_MeasureQubit(
            operation, qureg, classical_bit_registers,
        )
    elif 'InputDefinition' in tags:
        if operation.name() in classical_float_registers.keys():
            classical_float_registers = operation.input()
    elif 'Definition' in tags:
        pass
    elif 'PragmaGetPauliProduct' in tags:
        _execute_GetPauliProduct(
            operation, qureg,
            classical_float_registers,
        )
    elif 'PragmaGetStateVector' in tags:
        _execute_GetStateVector(
            operation, qureg,
            classical_complex_registers,
        )
    elif 'PragmaGetDensityMatrix' in tags:
        _execute_GetStateVector(
            operation, qureg,
            classical_complex_registers,
        )
    elif 'PragmaGetOccupationProbability' in tags:
        _execute_GetOccupationProbability(
            operation, qureg,
            classical_float_registers,
        )
    elif 'PragmaGetRotatedOccupationProbability' in tags:
        _execute_GetOccupationProbability(
            operation, qureg,
            classical_float_registers,
        )
    elif 'PragmaConditional' in tags:
        cast(ops.PragmaConditional, operation)
        if operation.condition_register() not in classical_bit_registers.keys():
            raise RuntimeError(
                "Conditional register {} not found in classical bit registers".format(
                    operation.condition_register()))
        if classical_bit_registers[operation.condition_register()][operation.condition_index()]:
            pyquest_call_circuit(
                circuit=operation.circuit(),
                qureg=qureg,
                classical_bit_registers=classical_bit_registers,
                classical_float_registers=classical_float_registers,
                classical_complex_registers=classical_complex_registers,
                output_bit_register_dict=output_bit_register_dict,
            )
    elif any(pragma in tags for pragma in _ALLOWED_PRAGMAS):
        pass
    else:
        raise RuntimeError('Operation not in PyQuEST backend')
    results_list_1 = []
    for circuit in circuit_list:
        pyquest_call_circuit(circuit=circuit, qureg=qureg, classical_bit_registers=test_dict,
                             classical_float_registers=dict(),
                             classical_complex_registers=dict(),
                             output_bit_register_dict=dict(),)
        results_list_0.append(test_dict['ro'][0])
        results_list_1.append(test_dict['ro'][1])

    assert results_list_0 == [True, False, False]
    assert results_list_1 == [False, False, False]


@pytest.mark.parametrize("init", [(ops.PragmaDamping,
                                   'PragmaDamping(gate_time, rate) 0',
                                   qops.mixDamping()),
                                  (ops.PragmaDepolarising,
                                   'PragmaDepolarising(gate_time, rate) 0',
                                   qops.mixDepolarising()),
                                  (ops.PragmaDephasing,
                                   'PragmaDephasing(gate_time, rate) 0',
                                   qops.mixDephasing())
                                  ])
@pytest.mark.parametrize("gate_time", list(np.arange(0, 2 * np.pi, 2 * np.pi / 3)))
@pytest.mark.parametrize("rate", list(np.arange(0, 2 * np.pi, 2 * np.pi / 3)))
def test_noise_operators(init, gate_time, rate):
    """Test PRAGMA operators applying noise with PyQuEST interface"""
    op = init[0]

    (Gate_time, Rate, q0) = ('gate_time',
                             'rate', 0)