Exemple #1
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__()
Exemple #2
0
def test_qureg_engine():
    eng1 = MainEngine(backend=DummyEngine(), engine_list=[DummyEngine()])
    eng2 = MainEngine(backend=DummyEngine(), engine_list=[DummyEngine()])
    qureg = _qubit.Qureg([_qubit.Qubit(eng1, 0), _qubit.Qubit(eng1, 1)])
    assert eng1 == qureg.engine
    qureg.engine = eng2
    assert qureg[0].engine == eng2 and qureg[1].engine == eng2
Exemple #3
0
def test_qureg(qubit_ids, expected):
	eng = MainEngine(backend = DummyEngine(), engine_list = [DummyEngine()])
	qureg = _qubit.Qureg()
	for qubit_id in qubit_ids:
		qubit = _qubit.Qubit(eng, qubit_id)
		qureg.append(qubit)
	assert str(qureg) == expected
Exemple #4
0
def test_qureg_measure_exception():
    eng = MainEngine(backend=DummyEngine(), engine_list=[DummyEngine()])
    qureg = _qubit.Qureg()
    for qubit_id in [0, 1]:
        qubit = _qubit.Qubit(eng, qubit_id)
        qureg.append(qubit)
    with pytest.raises(Exception):
        qureg.__bool__()
    with pytest.raises(Exception):
        qureg.__int__()
Exemple #5
0
def test_qureg_str():
    assert str(_qubit.Qureg([])) == 'Qureg[]'
    eng = MainEngine(backend=DummyEngine(), engine_list=[])
    a = eng.allocate_qureg(10)
    b = eng.allocate_qureg(50)
    c = eng.allocate_qubit()
    d = eng.allocate_qubit()
    e = eng.allocate_qubit()
    assert str(a) == 'Qureg[0-9]'
    assert str(b) == 'Qureg[10-59]'
    assert str(c) == 'Qureg[60]'
    assert str(d) == 'Qureg[61]'
    assert str(e) == 'Qureg[62]'
    assert str(_qubit.Qureg(c + e)) == 'Qureg[60, 62]'
    assert str(_qubit.Qureg(a + b)) == 'Qureg[0-59]'
    assert str(_qubit.Qureg(a + b + c)) == 'Qureg[0-60]'
    assert str(_qubit.Qureg(a + b + d)) == 'Qureg[0-59, 61]'
    assert str(_qubit.Qureg(a + b + e)) == 'Qureg[0-59, 62]'
    assert str(_qubit.Qureg(b + a)) == 'Qureg[10-59, 0-9]'
    assert str(_qubit.Qureg(e + b + a)) == 'Qureg[62, 10-59, 0-9]'