Beispiel #1
0
def test_measure_partial():
    #Basic test of collapse of entangled two qubits (Bell States)
    state = Qubit('01') + Qubit('10')
    assert measure_partial(state, (0,)) == \
        [(Qubit('10'), Rational(1, 2)), (Qubit('01'), Rational(1, 2))]
    assert measure_partial(state, long(0)) == \
        [(Qubit('10'), Rational(1, 2)), (Qubit('01'), Rational(1, 2))]
    assert measure_partial(state, (0,)) == \
        measure_partial(state, (1,))[::-1]

    #Test of more complex collapse and probability calculation
    state1 = sqrt(2)/sqrt(3)*Qubit('00001') + 1/sqrt(3)*Qubit('11111')
    assert measure_partial(state1, (0,)) == \
        [(sqrt(2)/sqrt(3)*Qubit('00001') + 1/sqrt(3)*Qubit('11111'), 1)]
    assert measure_partial(state1, (1, 2)) == measure_partial(state1, (3, 4))
    assert measure_partial(state1, (1, 2, 3)) == \
        [(Qubit('00001'), Rational(2, 3)), (Qubit('11111'), Rational(1, 3))]

    #test of measuring multiple bits at once
    state2 = Qubit('1111') + Qubit('1101') + Qubit('1011') + Qubit('1000')
    assert measure_partial(state2, (0, 1, 3)) == \
        [(Qubit('1000'), Rational(1, 4)), (Qubit('1101'), Rational(1, 4)),
         (Qubit('1011')/sqrt(2) + Qubit('1111')/sqrt(2), Rational(1, 2))]
    assert measure_partial(state2, (0,)) == \
        [(Qubit('1000'), Rational(1, 4)),
         (Qubit('1111')/sqrt(3) + Qubit('1101')/sqrt(3) +
          Qubit('1011')/sqrt(3), Rational(3, 4))]
def test_measure_partial():
    #Basic test of collapse of entangled two qubits (Bell States)
    state = Qubit('01') + Qubit('10')
    assert measure_partial(state, (0,)) == \
        [(Qubit('10'), S.Half), (Qubit('01'), S.Half)]
    assert measure_partial(state, long(0)) == \
        [(Qubit('10'), S.Half), (Qubit('01'), S.Half)]
    assert measure_partial(state, (0,)) == \
        measure_partial(state, (1,))[::-1]

    #Test of more complex collapse and probability calculation
    state1 = sqrt(2) / sqrt(3) * Qubit('00001') + 1 / sqrt(3) * Qubit('11111')
    assert measure_partial(state1, (0,)) == \
        [(sqrt(2)/sqrt(3)*Qubit('00001') + 1/sqrt(3)*Qubit('11111'), 1)]
    assert measure_partial(state1, (1, 2)) == measure_partial(state1, (3, 4))
    assert measure_partial(state1, (1, 2, 3)) == \
        [(Qubit('00001'), Rational(2, 3)), (Qubit('11111'), Rational(1, 3))]

    #test of measuring multiple bits at once
    state2 = Qubit('1111') + Qubit('1101') + Qubit('1011') + Qubit('1000')
    assert measure_partial(state2, (0, 1, 3)) == \
        [(Qubit('1000'), Rational(1, 4)), (Qubit('1101'), Rational(1, 4)),
         (Qubit('1011')/sqrt(2) + Qubit('1111')/sqrt(2), S.Half)]
    assert measure_partial(state2, (0,)) == \
        [(Qubit('1000'), Rational(1, 4)),
         (Qubit('1111')/sqrt(3) + Qubit('1101')/sqrt(3) +
          Qubit('1011')/sqrt(3), Rational(3, 4))]
Beispiel #3
0
def test_measure_partial():
    # Basic test of collapse of entangled two qubits (Bell States)
    state = Qubit("01") + Qubit("10")
    assert sorted(measure_partial(state, (0,))) == [(Qubit("01"), Rational(1, 2)), (Qubit("10"), Rational(1, 2))]
    assert sorted(measure_partial(state, (0,))) == sorted(measure_partial(state, (1,)))

    # Test of more complex collapse and probability calculation
    state1 = sqrt(2) / sqrt(3) * Qubit("00001") + 1 / sqrt(3) * Qubit("11111")
    assert measure_partial(state1, (0,)) == [(sqrt(2) / sqrt(3) * Qubit("00001") + 1 / sqrt(3) * Qubit("11111"), 1)]
    assert measure_partial(state1, (1, 2)) == measure_partial(state1, (3, 4))
    assert measure_partial(state1, (1, 2, 3)) == [(Qubit("00001"), Rational(2, 3)), (Qubit("11111"), Rational(1, 3))]

    # test of measuring multiple bits at once
    state2 = Qubit("1111") + Qubit("1101") + Qubit("1011") + Qubit("1000")
    assert sorted(measure_partial(state2, (0, 1, 3))) == sorted(
        [
            (Qubit("1011") / sqrt(2) + Qubit("1111") / sqrt(2), Rational(1, 2)),
            (Qubit("1101"), Rational(1, 4)),
            (Qubit("1000"), Rational(1, 4)),
        ]
    )
    assert sorted(measure_partial(state2, (0,))) == sorted(
        [
            (Qubit("1111") / sqrt(3) + Qubit("1101") / sqrt(3) + Qubit("1011") / sqrt(3), Rational(3, 4)),
            (Qubit("1000"), Rational(1, 4)),
        ]
    )
Beispiel #4
0
def test_measure_normalize():
    a, b = symbols('a b')
    state = a * Qubit('110') + b * Qubit('111')
    assert measure_partial(state, (0,), normalize=False) ==\
     [(a*Qubit('110'), a*a.conjugate()), (b*Qubit('111'),b*b.conjugate())]
    assert measure_all(state, normalize=False) ==\
    [(Qubit('110'), a*a.conjugate()),(Qubit('111'), b*b.conjugate())]
Beispiel #5
0
def test_measure_normalize():
    a, b = symbols('a b')
    state = a*Qubit('110') + b*Qubit('111')
    assert measure_partial(state, (0,), normalize=False) == \
        [(a*Qubit('110'), a*a.conjugate()), (b*Qubit('111'), b*b.conjugate())]
    assert measure_all(state, normalize=False) == \
        [(Qubit('110'), a*a.conjugate()), (Qubit('111'), b*b.conjugate())]
Beispiel #6
0
def test_measure_normalize():
    a, b = symbols("a b")
    state = a * Qubit("110") + b * Qubit("111")
    assert measure_partial(state, (0,), normalize=False) == [
        (a * Qubit("110"), a * a.conjugate()),
        (b * Qubit("111"), b * b.conjugate()),
    ]
    assert measure_all(state, normalize=False) == [(Qubit("110"), a * a.conjugate()), (Qubit("111"), b * b.conjugate())]
Beispiel #7
0
def test_measure_normalize():
    a, b = symbols("a b")
    state = a * Qubit("110") + b * Qubit("111")
    assert measure_partial(state, (0,), normalize=False) == [
        (a * Qubit("110"), a * a.conjugate()),
        (b * Qubit("111"), b * b.conjugate()),
    ]
    assert measure_all(state, normalize=False) == [
        (Qubit("110"), a * a.conjugate()),
        (Qubit("111"), b * b.conjugate()),
    ]
Beispiel #8
0
measure_all(_)

# In[39]:

measure_all(q0)

# 1量子ビットにmeasure_allすると、2量子ビットが出てきますね。(これは現在不明です)

# In[40]:

measure_all(q00)

# In[41]:

measure_partial(q00, (0, ))

# In[42]:

measure_partial(q11, (1))

# sympyのdescriptionにある例題を実行して、measure_partialがどうなるか見てみます。おそらく2量子系で意味のある測定が出来るという事でしょうか・・・1量子だとpartialは一つだけですし・・・

# In[43]:

qapply(H(0) * H(1) * Qubit('00'))

# In[44]:

measure_partial(qapply(H(0) * H(1) * Qubit('00')), (0, ))