Exemplo n.º 1
0
def test_measure_all():
    assert measure_all(Qubit('11')) == [(Qubit('11'), 1)]
    state = Qubit('11') + Qubit('10')
    assert measure_all(state) == [(Qubit('10'), Rational(1, 2)),
           (Qubit('11'), Rational(1, 2))]
    state2 = Qubit('11')/sqrt(5) + 2*Qubit('00')/sqrt(5)
    assert measure_all(state2) == \
        [(Qubit('00'), Rational(4, 5)), (Qubit('11'), Rational(1, 5))]
Exemplo n.º 2
0
def test_measure_all():
    assert measure_all(Qubit('11')) == [(Qubit('11'), 1)]
    state = Qubit('11') + Qubit('10')
    assert sorted(measure_all(state)) == sorted([(Qubit('11'), Rational(1,2)),\
           (Qubit('10'), Rational(1,2))])
    state2 = Qubit('11') / sqrt(5) + 2 * Qubit('00') / sqrt(5)
    assert sorted(measure_all(state2)) == sorted([(Qubit('11'), Rational(1,5)), \
           (Qubit('00'), Rational(4,5))])
Exemplo n.º 3
0
def test_measure_all():
    assert measure_all(Qubit('11')) == [(Qubit('11'), 1)]
    state = Qubit('11') + Qubit('10')
    assert measure_all(state) == [(Qubit('10'), S.Half), (Qubit('11'), S.Half)]
    state2 = Qubit('11') / sqrt(5) + 2 * Qubit('00') / sqrt(5)
    assert measure_all(state2) == \
        [(Qubit('00'), Rational(4, 5)), (Qubit('11'), Rational(1, 5))]

    # from issue #12585
    assert measure_all(qapply(Qubit('0'))) == [(Qubit('0'), 1)]
Exemplo n.º 4
0
def test_measure_all():
    assert measure_all(Qubit("11")) == [(Qubit("11"), 1)]
    state = Qubit("11") + Qubit("10")
    assert measure_all(state) == [(Qubit("10"), S.Half), (Qubit("11"), S.Half)]
    state2 = Qubit("11") / sqrt(5) + 2 * Qubit("00") / sqrt(5)
    assert measure_all(state2) == [
        (Qubit("00"), Rational(4, 5)),
        (Qubit("11"), Rational(1, 5)),
    ]

    # from issue #12585
    assert measure_all(qapply(Qubit("0"))) == [(Qubit("0"), 1)]
Exemplo n.º 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())]
Exemplo n.º 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())]
Exemplo n.º 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())]
Exemplo n.º 8
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()),
    ]
for psi_ in itertools.product([0, 1], repeat=n):
    basis.append(Qubit(*psi_))
psi0 = sum(basis) / sqrt(2**n)
psi = sum(basis) / sqrt(2**n)

Hs = prod([HadamardGate(i) for i in range(n)])
Is = prod([IdentityGate(i) for i in range(n)])
'''
p_ = [0]*n
p = Qubit(*p_)
psi0 = qapply(Hs*p).doit()
psi = qapply(Hs*p)
'''

Uf = lambda q: qapply(Is * q - 2 * fa * Dagger(fa) * q)  #lambda 引数:処理内容
Us = lambda q: qapply(2 * psi0 * Dagger(psi0) * q - Is * q)

for i in range(itr):
    psi = Us(Uf(psi))
    y = [v[1] for v in measure_all(psi)]
    x = [''.join(map(str, v[0].qubit_values)) for v in measure_all(psi)]
    plt.plot(x, y, marker='.', label=i)
    plt.xlabel("number of boxes")
    plt.ylabel("probability")
    print(y)

plt.grid()
#plt.yscale('log')
plt.legend()
plt.show()
Exemplo n.º 10
0
# ### 測定
# 量子コンピュータの最終的な出力結果は測定という行為を行わないといけません。measure_allで全方向(全直交基底)に対する測定を行い、measure_partialで部分的な基底に対する測定を行います。

# In[36]:

from sympy.physics.quantum.qubit import measure_all, measure_partial

_ = qapply(Z(0) * H(0) * q0)

# In[37]:

represent(_)

# In[38]:

measure_all(_)

# In[39]:

measure_all(q0)

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

# In[40]:

measure_all(q00)

# In[41]:

measure_partial(q00, (0, ))
Exemplo n.º 11
0
def test_measure_all():
    assert measure_all(Qubit("11")) == [(Qubit("11"), 1)]
    state = Qubit("11") + Qubit("10")
    assert sorted(measure_all(state)) == sorted([(Qubit("11"), Rational(1, 2)), (Qubit("10"), Rational(1, 2))])
    state2 = Qubit("11") / sqrt(5) + 2 * Qubit("00") / sqrt(5)
    assert sorted(measure_all(state2)) == sorted([(Qubit("11"), Rational(1, 5)), (Qubit("00"), Rational(4, 5))])