def makeUpdateMatrix(qnnArch, unitaries, trainingData, storedStates, lda, ep,
                     l, j):
    numInputQubits = qnnArch[l - 1]

    #Calculate the sum:
    summ = 0
    for x in range(len(trainingData)):
        #Calculate the commutator
        firstPart = updateMatrixFirstPart(qnnArch, unitaries, storedStates, l,
                                          j, x)
        secondPart = updateMatrixSecondPart(qnnArch, unitaries, trainingData,
                                            l, j, x)
        mat = qt.commutator(firstPart, secondPart)

        #Trace out the rest
        keep = list(range(numInputQubits))
        keep.append(numInputQubits + j)
        mat = partialTraceKeep(mat, keep)

        #Add to sum
        summ = summ + mat

    #Calculate the update matrix from the sum
    summ = (-ep * (2**numInputQubits) / (lda * len(trainingData))) * summ
    return summ.expm()
예제 #2
0
파일: solvers.py 프로젝트: gharib85/QDSim
def drho(rho, H, lindblads):
    res = -1j * qt.commutator(H, rho)
    if lindblads:
        for l in lindblads:
            res += (l * rho * l.dag() - 0.5 * l.dag() * l * rho -
                    0.5 * rho * l.dag() * l)
    return res
예제 #3
0
def test_XYZ(XYZ):
    return [qt.commutator(XYZ["X"], XYZ["Y"]) == 2j*XYZ["Z"],\
            qt.commutator(XYZ["Y"], XYZ["Z"]) == 2j*XYZ["X"],\
            qt.commutator(XYZ["Z"], XYZ["X"]) == 2j*XYZ["Y"],\
            qt.commutator(XYZ["X"], XYZ["X"]) == qt.commutator(XYZ["Y"], XYZ["Y"])\
                                              == qt.commutator(XYZ["Z"], XYZ["Z"]),\
            qt.commutator(XYZ["X"], XYZ["X"]).norm() == 0]
예제 #4
0
def test_commutator():
    A = qutip.qeye(N)
    B = qutip.destroy(N)
    assert qutip.commutator(A, B) == qutip.qzero(N)

    sx = qutip.sigmax()
    sy = qutip.sigmay()
    assert qutip.commutator(sx, sy) / 2 == (qutip.sigmaz() * 1j)

    A = qutip.qeye(N)
    B = qutip.destroy(N)
    assert qutip.commutator(A, B, 'anti') == qutip.destroy(N) * 2

    sx = qutip.sigmax()
    sy = qutip.sigmay()
    assert qutip.commutator(sx, sy, 'anti') == qutip.qzero(2)

    with pytest.raises(TypeError) as e:
        qutip.commutator(sx, sy, 'something')
    assert str(e.value).startswith("Unknown commutator kind")
예제 #5
0
def test_commutator_type():
    "Operator CSR Type: commutator"
    op = commutator(position(5), momentum(5))
    assert_equal(isspmatrix_csr(op.data), True)
예제 #6
0
def drho(rho,H,lindblads):
    res = -1j* qt.commutator(H,rho)
    if lindblads:
        for l in lindblads:
            res += (l*rho*l.dag() - 0.5* l.dag()*l*rho - 0.5*rho*l.dag()*l)
    return res
예제 #7
0
def test_commutator_type():
    "Operator CSR Type: commutator"
    op = commutator(position(5), momentum(5))
    assert_equal(isspmatrix_csr(op.data), True)
예제 #8
0
def check(X, Y, Z):
    print(qt.commutator(X, Y) - 2 * 1j * Z)
    print(qt.commutator(Y, Z) - 2 * 1j * X)
    print(qt.commutator(Z, X) - 2 * 1j * Y)
예제 #9
0
        self.fig.canvas.draw()
        plt.pause(0.00001)
        print()


syk_graphics = SYKGraphics()
syk_graphics.view()

#########################################################################################

BOOST = HR_ - HL_
ETA = HR_ + HL_ - g * SIZE
E = ETA - qt.expect(ETA, state)
PR = -HR_ - g * SIZE / 2
PL = -HL_ - g * SIZE / 2
P = -1j * qt.commutator(BOOST, E)


def evolve(op=None, dt=0.1, T=100, sign=-1j):
    global syk_graphics, state, E
    if type(op) == type(None):
        op = E
    U = (sign * op * dt).expm()
    for t in range(T):
        state = U * state
        syk_graphics.view()


def insert(t=0, dt=0.1):
    global syk_graphics, state, INSERT, HL_
    evolve(op=HL_, dt=dt, T=abs(int(t / dt)), sign=1j)