def test_active_reset():
    """Test ActiveReset PRAGMA with PyQuEST interface"""
    definition = ops.DefinitionBit(name='ro', length=2, is_output=True)
    circuit = Circuit()
    circuit += definition
    circuit += ops.PauliX(qubit=0)

    circuit_with = circuit + ops.PragmaActiveReset(qubit=0) + ops.PragmaActiveReset(qubit=1)
    circuit_without = circuit + ops.PauliX(qubit=0)
    circuit_list = [circuit, circuit_with, circuit_without]
    for circuit in circuit_list:
        circuit += ops.MeasureQubit(qubit=0, readout='ro', readout_index=0)
        circuit += ops.MeasureQubit(qubit=1, readout='ro', readout_index=1)

    test_dict = {'ro': [False, False]}
    env = utils.createQuestEnv()()
    qureg = utils.createQureg()(2, env)
    results_list_0 = []
    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]
コード例 #2
0
    ops.RotateAroundSphericalAxis(0, 0.01, 0.02, 0.03),
    ops.PragmaSetNumberOfMeasurements(20, 'ro'),
    ops.PragmaSetStateVector(np.array([0, 1], dtype=complex)),
    ops.PragmaSetDensityMatrix(np.array([[0, 0], [0, 1]], dtype=complex)),
    ops.PragmaDamping(0, 0.005, 0.02),
    ops.PragmaDephasing(0, 0.005, 0.02),
    ops.PragmaDepolarising(0, 0.005, 0.02),
    ops.PragmaRandomNoise(0, 0.005, 0.02, 0.01),
    ops.PragmaGeneralNoise(
        0, 0.005, np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]], dtype=float)),
    ops.PragmaConditional('ro', 0, Circuit()),
    ops.PragmaRepeatGate(3),
    ops.PragmaBoostNoise(0.004),
    ops.PragmaStopParallelBlock([0, 1], 0.002),
    ops.PragmaSleep([0, 1], 0.002),
    ops.PragmaActiveReset(0),
    ops.PragmaGlobalPhase(0.03),
    ops.MeasureQubit(0, 'ro', 0),
    ops.PragmaRepeatedMeasurement('ro', 20, {}),
    ops.PragmaGetStateVector('ro', Circuit()),
    ops.PragmaGetDensityMatrix('ro', Circuit()),
    ops.PragmaGetOccupationProbability('ro', Circuit()),
    ops.PragmaGetPauliProduct({}, 'ro', Circuit()),
    ops.PragmaStartDecompositionBlock([0, 1], {}),
    ops.PragmaStopDecompositionBlock([0, 1]),
    ops.InputSymbolic('other', 0),
])
def test_all_operations(op: Any):
    """Test all operations with mocked interface"""
    circuit = Circuit()
    circuit += ops.DefinitionFloat(name='ro', length=1, is_output=False)