Exemple #1
0
def test_basic_qubit_measurement():
    eng = MainEngine(backend=DummyEngine(), engine_list=[DummyEngine()])
    qubit0 = eng.allocate_qubit()[0]
    qubit1 = eng.allocate_qubit()[0]
    eng.set_measurement_result(qubit0, False)
    eng.set_measurement_result(qubit1, True)
    assert not bool(qubit0)
    assert not qubit0
    assert bool(qubit1)
    assert qubit1
    assert int(qubit0) == 0
    assert int(qubit1) == 1
    # Testing functions for python 2 and python 3
    assert not qubit0.__bool__()
    assert qubit1.__bool__()
Exemple #2
0
def test_qureg_measure_if_qubit():
    eng = MainEngine(backend=DummyEngine(), engine_list=[DummyEngine()])
    qureg0 = _qubit.Qureg(eng.allocate_qubit())
    qureg1 = _qubit.Qureg(eng.allocate_qubit())
    eng.set_measurement_result(qureg0[0], False)
    eng.set_measurement_result(qureg1[0], True)
    assert not bool(qureg0)
    assert not qureg0
    assert bool(qureg1)
    assert qureg1
    assert int(qureg0) == 0
    assert int(qureg1) == 1
    # Testing functions for python 2 and python 3
    assert not qureg0.__bool__()
    assert qureg1.__bool__()