Пример #1
0
def test_w_states():
    state = (
        qutip.qstate("uddd") +
        qutip.qstate("dudd") +
        qutip.qstate("ddud") +
        qutip.qstate("dddu")
    ) / 2
    assert state == qutip.w_state(4)
Пример #2
0
def test_ghz_states():
    state = (qutip.qstate("uuu") + qutip.qstate("ddd")).unit()
    assert state == qutip.ghz_state(3)
Пример #3
0
def test_qstate_error():
    with pytest.raises(TypeError) as e:
        qutip.qstate("eeggg")
    assert str(e.value) == ('String input to QSTATE must consist ' +
                            'of "u" and "d" elements only')
Пример #4
0
def test_qstate(state):
    from_basis = qutip.basis([2] * len(state), state)
    from_qstate = qutip.qstate("".join({0: "d", 1: "u"}[i] for i in state))
    assert from_basis == from_qstate
Пример #5
0
import qutip as qt
import numpy as np
"""
	            fredkin	hadamard
ancilla---------O---------H------------Measure
     f1---------X----------------------
     f2---------X----------------------
"""

up = qt.qstate('u')  #qstate down is (1,0), qstate up is (0,1)
down = qt.qstate('d')
ancilla = 1 / np.sqrt(2) * (up + down)
hadamard = qt.tensor(qt.snot(), qt.qeye(2), qt.qeye(2))
fredkin = qt.fredkin()  #fredkin swapes f1 and f2 if ancilla = 1

#------------------------------------------------------------------------
#Define Input
f1 = 1 / np.sqrt(2) * (up + down)
f2 = up
#------------------------------------------------------------------------

psi0 = qt.tensor(ancilla, f1, f2)

output = hadamard * fredkin * psi0

measure = qt.tensor(down, f1,
                    f2).dag() * output  #if f1 = f2 the output is (down,f1,f2)
#therefore measure is 1 if f1 = f2
#measure is 0.5 if f1, f2 are orthogonal

print(measure)
Пример #6
0
def random_state(N): #This function produces a random state, which could be used later
    real = np.random.normal(0, 1, 2**N)             #makes random matrices for real and imaginary part
    imag = 1j*np.random.normal(0, 1, 2**N)
    psi = real + imag
    return qt.Qobj(psi, dims=[[2**N], [1]]).unit()  #generate quantum object, that has qubit tensor structure and normalize it
    
N= 4  # number of sites
d = 2 #physical dimension

#In this example we do not truncate anything. So it is not feasable for big N

M = [] #generate empty list, where we will put our matrices

#-------------------------------------------------------------------------------------------------------------
state = 1/np.sqrt(2)*(qt.tensor([qt.qstate('d')]*N) + qt.tensor([qt.qstate('u')]*N)) #generate simple state
state = state.full() #make numpy.array out of quantum object
#-------------------------------------------------------------------------------------------------------------

"""
We have to stick to a convention, which index of the tensor represents the physical index sigma.
This decision is arbitrary. In our case it will be the 2nd index of the tensor e.g. (a_i, sigma, a_j)
"""

#first we reshape the tensor c (Schollwok calls it a vector) into the matrix Psi
psi = state.reshape(d, d**(N-1))    #the indices of Psi are in the first step (sigma1, (sigma2 sigma3 ...) )
Q, R = qr(psi)                      #apply QR decomposition
M.append(Q.reshape(1,d,d))          #The 1st index is a dummy index (see eq. (42)), 2nd is sigma_1, 3rd is a_1
                                    #This reshaped Q is already our first matrix A of the MPS
psi = R.reshape(Q.shape[1]*d,d**(N-2))  #reshape R to the 2nd Psi in Eq. 42 (Psi_(a1 sigma2),(sigma3 ... sigmaL))
Q, R = qr(psi)                          #apply next QR