def test_spectrum_espi():
    """
    correlation: comparing spectrum from es and pi methods
    """

    # use JC model
    N = 4
    wc = wa = 1.0 * 2 * np.pi
    g = 0.1 * 2 * np.pi
    kappa = 0.75
    gamma = 0.25
    n_th = 0.01

    a = tensor(destroy(N), qeye(2))
    sm = tensor(qeye(N), destroy(2))
    H = wc * a.dag() * a + wa * sm.dag() * sm + \
        g * (a.dag() * sm + a * sm.dag())
    c_ops = [
        np.sqrt(kappa * (1 + n_th)) * a,
        np.sqrt(kappa * n_th) * a.dag(),
        np.sqrt(gamma) * sm
    ]

    wlist = 2 * pi * np.linspace(0.5, 1.5, 100)
    spec1 = spectrum(H, wlist, c_ops, a.dag(), a, solver='es')
    spec2 = spectrum(H, wlist, c_ops, a.dag(), a, solver='pi')

    assert_(max(abs(spec1 - spec2)) < 1e-3)
Esempio n. 2
0
def test_spectrum_espi():
    """
    correlation: comparing spectrum from es and pi methods
    """

    # use JC model
    N = 4
    wc = wa = 1.0 * 2 * np.pi
    g = 0.1 * 2 * np.pi
    kappa = 0.75
    gamma = 0.25
    n_th = 0.01

    a = tensor(destroy(N), qeye(2))
    sm = tensor(qeye(N), destroy(2))
    H = wc * a.dag() * a + wa * sm.dag() * sm + \
        g * (a.dag() * sm + a * sm.dag())
    c_ops = [np.sqrt(kappa * (1 + n_th)) * a,
             np.sqrt(kappa * n_th) * a.dag(),
             np.sqrt(gamma) * sm]

    wlist = 2 * pi * np.linspace(0.5, 1.5, 100)
    spec1 = spectrum(H, wlist, c_ops, a.dag(), a, solver='es')
    spec2 = spectrum(H, wlist, c_ops, a.dag(), a, solver='pi')

    assert_(max(abs(spec1 - spec2)) < 1e-3)
Esempio n. 3
0
def find_expect(phi=0.1, Omega_vec=3.0, wd=wd):

    Ej = (phi**2) / (
        8 * Ec
    )  #Ejmax*absolute(cos(pi*phi)) #; % Josephson energy as function of Phi.

    wTvec = -Ej + sqrt(8.0 * Ej * Ec) * (nvec + 0.5) + Ecvec

    #wdvec=nvec*sqrt(8.0*Ej*Ec)
    #wdvec=nvec*wd

    wT = wTvec - wdvec
    transmon_levels = Qobj(diag(wT[range(N)]))
    H = transmon_levels + Omega_vec  #- 0.5j*(Omega_true*adag - conj(Omega_true)*a)
    #final_state = steadystate(H, c_op_list)
    #print H.shape
    #print dir(H)
    #U,D = eig(H.full())
    #print D
    #Uinv = Qobj(inv(D))
    #U=Qobj(D)
    # Doing the chi integral (gives the susceptibility)

    #Dint = 1.0/(1.0j*(wp-wd)) #Qobj(1.0/(1.0j*(wp-wd)*diag(qeye(N**2))))# + diag(D))))

    #Hint = H.expm() #U*H*Uinv

    #Chi_temp(i,j) += (1.0/theta_steps)*1j*trace(reshape(tm_l*Lint*(p_l - p_r)*rho_ss_c,dim,dim))
    #exp1=correlation_2op_1t(H, None, wlist2, c_op_list, a, p, solver="es")
    #exp2=correlation_2op_1t(H, None, wlist2, c_op_list, p, a, solver="es", reverse=True)
    #exp1=correlation_2op_1t(H, None, wlist2, c_op_list, a, p_l-p_r, solver="es")

    #exp1=correlation_ss(H, wlist2, c_op_list, a, p)
    #exp2=correlation_ss(H, wlist2, c_op_list, p, a, reverse=True)
    exp1 = spectrum(H, wlist2, c_op_list, a, p, solver="pi", use_pinv=False)
    exp2 = spectrum(H, wlist2, c_op_list, p, a, solver="pi", use_pinv=False)
    return exp1 - exp2
    return expect(a, final_state)  #tm_l
Esempio n. 4
0
def find_expect(phi=0.1, Omega_vec=3.0, wd=wd):

    Ej = (phi**2)/(8*Ec) #Ejmax*absolute(cos(pi*phi)) #; % Josephson energy as function of Phi.

    wTvec = -Ej + sqrt(8.0*Ej*Ec)*(nvec+0.5)+Ecvec

    #wdvec=nvec*sqrt(8.0*Ej*Ec)
    #wdvec=nvec*wd

    wT = wTvec-wdvec
    transmon_levels = Qobj(diag(wT[range(N)]))
    H=transmon_levels +Omega_vec #- 0.5j*(Omega_true*adag - conj(Omega_true)*a)
    #final_state = steadystate(H, c_op_list)
    #print H.shape
    #print dir(H)
    #U,D = eig(H.full())
    #print D
    #Uinv = Qobj(inv(D))
    #U=Qobj(D)
    # Doing the chi integral (gives the susceptibility)

    #Dint = 1.0/(1.0j*(wp-wd)) #Qobj(1.0/(1.0j*(wp-wd)*diag(qeye(N**2))))# + diag(D))))

    #Hint = H.expm() #U*H*Uinv

    #Chi_temp(i,j) += (1.0/theta_steps)*1j*trace(reshape(tm_l*Lint*(p_l - p_r)*rho_ss_c,dim,dim))
    #exp1=correlation_2op_1t(H, None, wlist2, c_op_list, a, p, solver="es")
    #exp2=correlation_2op_1t(H, None, wlist2, c_op_list, p, a, solver="es", reverse=True)
    #exp1=correlation_2op_1t(H, None, wlist2, c_op_list, a, p_l-p_r, solver="es")

    #exp1=correlation_ss(H, wlist2, c_op_list, a, p)
    #exp2=correlation_ss(H, wlist2, c_op_list, p, a, reverse=True)
    exp1=spectrum(H, wlist2, c_op_list, a, p, solver="pi", use_pinv=False)
    exp2=spectrum(H, wlist2, c_op_list, p, a, solver="pi", use_pinv=False)
    return exp1-exp2
    return expect( a, final_state) #tm_l
Esempio n. 5
0
def find_expect(phi=0.2, Omega=3.0, wd=wd, use_other=True):

    Ej = (phi**2)/(8*Ec) #Ejmax*absolute(cos(pi*phi)) #; % Josephson energy as function of Phi.

    wTvec = -Ej + sqrt(8.0*Ej*Ec)*(nvec+0.5)+Ecvec

    wT = wTvec-wdvec
    transmon_levels = Qobj(diag(wT[range(N)]))
    Omega_vec=- 0.5j*(Omega*adag - conj(Omega)*a)
    H=transmon_levels +Omega_vec #- 0.5j*(Omega_true*adag - conj(Omega_true)*a)
    if use_other:
        exp1=spectrum(H, wlist2, c_op_list, a, p, solver="pi", use_pinv=False)
    else:
        exp1=_spectrum_pi(H, wlist2, c_op_list, a, p, use_pinv=False)
    return exp1
Esempio n. 6
0
def test_spectrum_solver_equivalence_to_es(spectrum):
    """Test equivalence of the spectrum solvers to the base "es" method."""
    # Jaynes--Cummings model.
    dimension = 4
    wc = wa = 1.0 * 2*np.pi
    g = 0.1 * 2*np.pi
    kappa = 0.75
    gamma = 0.25
    n_th = 0.01

    a = qutip.tensor(qutip.destroy(dimension), qutip.qeye(2))
    sm = qutip.tensor(qutip.qeye(dimension), qutip.sigmam())
    H = wc*a.dag()*a + wa*sm*sm.dag() + g*(a.dag()*sm.dag() + a*sm)
    c_ops = [np.sqrt(kappa * (n_th+1)) * a,
             np.sqrt(kappa * n_th) * a.dag(),
             np.sqrt(gamma) * sm.dag()]

    test, frequencies = spectrum(H, c_ops, a.dag(), a)
    base = qutip.spectrum(H, frequencies, c_ops, a.dag(), a, solver="es")
    np.testing.assert_allclose(base, test, atol=1e-3)
Esempio n. 7
0
#Uinv=inv(U)
#print "Uinv", Uinv

#Lint=U*MMR*Uinv
#print "Lint", diag(Lint)
#Lop=Qobj(U)#.expm()
#print diag(Lop*MMR*Lop.dag())
#print Lop

rho_ss = steadystate(L)
rho = transpose(mat2vec(rho_ss.full()))

print p.shape

print transpose(rho)
print spectrum(H, [3.0], c_op_list, a, p, solver="pi", use_pinv=True)
#print "p", dot(p, transpose(rho))
s = dot(tr_vec, dot(a_sup, dot(MMR1, dot(b_sup, transpose(rho)))))
print s
print -2 * real(s[0, 0])
#spectrum[idx] = -2 * real(s[0, 0])

#        Chi_temp[i,j] += (1/theta_steps)
sol = a * p * rho_ss
print D.shape
print U.shape
#print MMR.shape
#print Lint.shape
print sol.shape
print rho_ss.shape
print rho.shape
Esempio n. 8
0
def two_tone(vg):
    phi, wd=vg
    Ej = Ejmax*absolute(cos(pi*phi))#(phi**2)/(8*Ec) # #; % Josephson energy as function of Phi.

    wTvec = -Ej + sqrt(8.0*Ej*Ec)*(nvec+0.5)+Ecvec
    wdvec=nvec*wd
    wT = wTvec-wdvec

    transmon_levels = Qobj(diag(wT[range(N)]))
    

    for Om in Omega_op:
        H = transmon_levels + Om
        exp1=spectrum(H, wlist2, c_op_list, a, p, solver="pi", use_pinv=False)
        exp2=spectrum(H, wlist2, c_op_list, p, a, solver="pi", use_pinv=False)
        return exp1-exp2


        #H_comm = -1j*(kron(It,H) - kron(transpose(H),It));

        #L = H_comm + Lindblad_tm + Lindblad_tp #+ Lindblad_deph;

        #print L

        #L2 = [reshape(eye(N),1,N**2); L]; %Add the condition trace(rho) = 1

        #rho_ss = L2\[1;zeros(dim^2,1)]; % Steady state density matrix

        #rho_ss_c = rho_ss; %Column vector form
        L = liouvillian(H, c_op_list)

        #D, V=L.eigenstates()
        #print "D", D.shape
        #print "V", V.shape
        #print L.diag()
        #print L.diag().shape
        #raise Exception
        A = L.full()

        rho_ss = steadystate(L)
        rho = transpose(mat2vec(rho_ss.full()))
        P = kron(transpose(rho), tr_vec)
        Q = I - P

        if 1:
            w=wp-wd
            #MMR = pinv(-1.0j * w * I + A)
            MMR = dot(Q, solve(-1.0j * w * I + A, Q))

            #Lexp=L.expm()
            #MMR=Lexp*MMR*Lexp.dag()
            #    MMR = np.dot(Q, np.linalg.solve(-1.0j * w * I + A, Q))

            #print p_l.shape
            #print p_l
            #print transpose(rho).shape

            #print dot(p_l.full(), transpose(rho))
            s = dot(tr_vec,
                       dot(tm_l, dot(MMR, dot(p_l_m_p_r, transpose(rho)))))
            return -2 * real(s[0, 0])
        D,U = eig(L.full())

        Uinv = inv(U)

        Dint = diag(1.0/(1.0j*(wp-wd)*Idiag + diag(D)))

        Lint = U*Dint*Uinv


        #H_comm = -1.0j*(kron(It,H) - kron(transpose(H),It))


        #print H
        #print H.shape, H.full().shape
        #print H_comm, H_comm.shape
        #L = H_comm + Lindblad_tm + Lindblad_tp + Lindblad_deph
        #p_l=spre(p)
        #p_r=spost(p)
        #tm_l=spre(a)
        #print L.shape, A.shape,
        #print dir(L)
        #print L.eigenenergies().shape
        #print L.eigenstates()#.shape
        #L2 = [reshape(eye(dim),1,dim^2);L]; %Add the condition trace(rho) = 1
        #rho_ss = L2\[1;zeros(dim^2,1)]; % Steady state density matrix
        #rho_ss_c = rho_ss; %Column vector form

        #print "tm_l", tm_l.full().shape
        #print "Lint", Lint.shape
        #print "pl", p_l.full().shape
        #print "pr", p_r.full().shape
        #print rho.shape, to_super(rho_ss).full().shape
        #print "rho", to_super(rho_ss) #rho_ss.full().shape #rho.shape
        #print (tm_l.full()*Lint*(p_l.full() - p_r.full())*rho).shape
        #raise Exception
        return 1j*trace(tm_l*Lint*(p_l_m_p_r)*rho_ss)
Esempio n. 9
0
def plot2ab(hamiltonian, omega_range=np.linspace(1000, 6000, 501)):
    """Constructs and displays the plot of Figure 2 (a) and (b) of
    the paper "Signatures..."
    :param hamiltonian: <code>HamiltonianSystem</code> object,
    containing the various Hamiltonian operators
    :param omega_range: List or array of frequencies for which to evaluate
    the spectra
    """
    print('Making plot figure 2')
    model_space = hamiltonian.space
    collapse_operators = hamiltonian.collapse_ops()

    # Get spectra
    xdat = omega_range
    print(' Getting spectrum for weak coupling...')
    ydat_weak = qt.spectrum(
        H=hamiltonian.H(coupling=False),
        wlist=-xdat,
        c_ops=collapse_operators,
        a_op=model_space.create_all_elec(),
        b_op=model_space.destroy_all_elec()) / model_space.n
    print(' Done')
    print(' Getting spectrum for strong coupling...')
    ydat_strong = qt.spectrum(
        H=hamiltonian.H(coupling=True),
        wlist=-xdat,
        c_ops=collapse_operators,
        a_op=model_space.create_all_elec(),
        b_op=model_space.destroy_all_elec()) / model_space.n
    print(' Done')

    # Print output
    title = 'S(omega)/N vs omega_L - omega'
    print('\n\nFigure: {}'.format(title))
    lab1 = 'S(omega), weak corr.'
    print('\nPlot: {}'.format(lab1))
    for xi, yi in zip(xdat, ydat_weak):
        print('  {:16.8f}    {:16.8E}'.format(xi, yi))
    lab2 = 'S(omega), strong corr.'
    print('\nPlot: {}'.format(lab2))
    for xi, yi in zip(xdat, ydat_strong):
        print('  {:16.8f}    {:16.8E}'.format(xi, yi))

    # Make plot figure
    print('Displaying plot figure')
    fig, ax1 = plt.subplots(1, 1)
    divider = make_axes_locatable(ax1)
    ax2 = divider.new_vertical(size='100%', pad=0.05)
    fig.add_axes(ax2)
    ax2.plot(xdat, ydat_weak, '-', label=lab1)
    ax1.plot(xdat, ydat_strong, '-', label=lab2)

    # Plot vertical lines
    omega_plus = hamiltonian.omega_up()
    omega_minus = hamiltonian.omega_lp()
    for n in count(1):
        vline = n * hamiltonian.omega_v
        if vline < min(xdat):
            continue
        elif vline > max(xdat):
            break
        else:
            ax1.axvline(vline, color='orange')
            ax2.axvline(vline, color='orange')
            for k in range(n + 1):
                l = n - k
                ax1.axvline(k * omega_plus + l * omega_minus,
                            linestyle='dashed',
                            color='green')
    ax1.set_title(title)
    ax1.set_xlabel('omega_L - omega')
    ax2.set_ylabel('S(omega)/N, weak')
    ax1.set_ylabel('S(omega)/N, strong')
    ax1.set_yscale('log')
    ax2.set_yscale('log')
    plt.show()

    return xdat, ydat_weak, ydat_strong
Esempio n. 10
0
def plot3(hamiltonian, omega_range=np.linspace(1500, 2000, 501)):
    """Create and display Figure 3 of "Signatures..." based on the given
    Hamiltonian
    :param hamiltonian: <code>HamiltonianSystem</code> object. Note that
    the number of particles will be mutated in order to create the plots
    :param omega_range: Range of frequencies for which to compute the
    spectrum
    """
    print('Making plot figure 3')
    ms = hamiltonian.space
    num_molecules_original = ms.n
    xdat = omega_range

    # Print
    title = 'First Stokes lines for N=1, N=2'
    print('\n\nFigure: {}'.format(title))

    # Get data for N=1
    ms.set_num_molecules(1)

    # First plot: N=1
    ydat1 = qt.spectrum(H=hamiltonian.H(),
                        wlist=-xdat,
                        c_ops=hamiltonian.collapse_ops(),
                        a_op=ms.create_all_elec(),
                        b_op=ms.destroy_all_elec())

    # Print
    lab1 = ' N=1'
    print('\n  BEGIN Plot: {}'.format(lab1))
    for xi, yi in zip(xdat, ydat1):
        print('    {:16.8f}    {:16.8E}'.format(xi, yi))
    print('\n  END Plot: {}'.format(lab1))

    # Get data for N=2
    ms.set_num_molecules(2)

    # Second plot: N=2, coherent
    spec = qt.spectrum(H=hamiltonian.H(),
                       wlist=-xdat,
                       c_ops=hamiltonian.collapse_ops(),
                       a_op=ms.create_all_elec(),
                       b_op=ms.destroy_all_elec())
    ydat2 = .5 * spec

    # Print
    lab2 = ' N=2, coherent'
    print('\n  BEGIN Plot: {}'.format(lab2))
    for xi, yi in zip(xdat, ydat2):
        print('    {:16.8f}    {:16.8E}'.format(xi, yi))
    print('\n  END Plot: {}'.format(lab2))

    # Third plot: N=2, incoherent
    ydats3 = []
    for i in range(ms.n):
        ydats3.append(
            qt.spectrum(H=hamiltonian.H(),
                        wlist=-xdat,
                        c_ops=hamiltonian.collapse_ops(),
                        a_op=ms.create_elec(i),
                        b_op=ms.destroy_elec(i)))
    ydat3 = .5 * sum(ydats3, np.zeros_like(xdat))

    # Print
    lab3 = ' N=2, incoherent'
    print('\n  BEGIN Plot: {}'.format(lab3))
    for xi, yi in zip(xdat, ydat3):
        print('    {:16.8f}    {:16.8E}'.format(xi, yi))
    print('\n  END Plot: {}'.format(lab3))

    # Reset original num molecules
    ms.set_num_molecules(num_molecules_original)

    # Make and show plots
    print('Displaying plot figure')
    fig, ax = plt.subplots(1, 1)
    ax.set_xlabel('omega_L - omega')
    ax.set_ylabel('S(omega)/N')
    ax.set_title(title)
    ax.plot(xdat, ydat1, '--', label=lab1)
    ax.plot(xdat, ydat2, '-', label=lab2)
    ax.plot(xdat, ydat3, '-', label=lab3)
    ax.legend()
    plt.show()
    return xdat, ydat1, ydat2, ydat3
Esempio n. 11
0
    np.sqrt(kappa * n_th) * a.dag(),
    np.sqrt(gamma) * sm
]
"""
calculate the correlation function using the mesolve solver, and then fft to
obtain the spectrum. Here we need to make sure to evaluate the correlation
function for a sufficient long time and sufficiently high sampling rate so
that the discrete Fourier transform (FFT) captures all the features in the
"""

# resulting spectrum
tlist = np.linspace(0, 100, 5000)
corr = correlation_ss(H, tlist, c_ops, a.dag(), a)
wlist1, spec1 = qt.spectrum_correlation_fft(tlist, corr)

# calculate the power spectrum using spectrum, which internally uses essolve
# to solve for the dynamics (by default)
wlist2 = np.linspace(0.25, 1.75, 200) * 2 * np.pi
spec2 = qt.spectrum(H, wlist2, c_ops, a.dag(), a)

# plot the spectra
fig, ax = plt.subplots(1, 1)
ax.plot(wlist1 / (2 * np.pi), spec1, "b", lw=2, label="eseries method")
ax.plot(wlist2 / (2 * np.pi), spec2, "r--", lw=2, label="me+fft method")
ax.legend()
ax.set_xlabel("Frequency")
ax.set_ylabel("Power spectrum")
ax.set_title("Vacuum Rabi splitting")
ax.set_xlim(wlist2[0] / (2 * np.pi), wlist2[-1] / (2 * np.pi))
plt.show()