本文整理汇总了Python中qutip.expect函数的典型用法代码示例。如果您正苦于以下问题:Python expect函数的具体用法?Python expect怎么用?Python expect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了expect函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: testHOFiniteTemperatureStates
def testHOFiniteTemperatureStates():
"""
brmesolve: harmonic oscillator, finite temperature, states
"""
N = 10
w0 = 1.0 * 2 * np.pi
g = 0.05 * w0
kappa = 0.25
times = np.linspace(0, 25, 1000)
a = destroy(N)
H = w0 * a.dag() * a + g * (a + a.dag())
psi0 = ket2dm((basis(N, 4) + basis(N, 2) + basis(N, 0)).unit())
n_th = 1.5
w_th = w0/np.log(1 + 1/n_th)
def S_w(w):
if w >= 0:
return (n_th + 1) * kappa
else:
return (n_th + 1) * kappa * np.exp(w / w_th)
c_ops = [np.sqrt(kappa * (n_th + 1)) * a, np.sqrt(kappa * n_th) * a.dag()]
a_ops = [a + a.dag()]
e_ops = []
res_me = mesolve(H, psi0, times, c_ops, e_ops)
res_brme = brmesolve(H, psi0, times, a_ops, e_ops, [S_w])
n_me = expect(a.dag() * a, res_me.states)
n_brme = expect(a.dag() * a, res_brme.states)
diff = abs(n_me - n_brme).max()
assert_(diff < 1e-2)
开发者ID:JonathanUlm,项目名称:qutip,代码行数:35,代码来源:test_brmesolve.py
示例2: compute
def compute(N, wc, wa, glist, use_rwa):
# Pre-compute operators for the hamiltonian
a = tensor(destroy(N), qeye(2))
sm = tensor(qeye(N), destroy(2))
nc = a.dag() * a
na = sm.dag() * sm
idx = 0
na_expt = zeros(shape(glist))
nc_expt = zeros(shape(glist))
for g in glist:
# recalculate the hamiltonian for each value of g
if use_rwa:
H = wc * nc + wa * na + g * (a.dag() * sm + a * sm.dag())
else:
H = wc * nc + wa * na + g * (a.dag() + a) * (sm + sm.dag())
# find the groundstate of the composite system
evals, ekets = H.eigenstates()
psi_gnd = ekets[0]
na_expt[idx] = expect(na, psi_gnd)
nc_expt[idx] = expect(nc, psi_gnd)
idx += 1
return nc_expt, na_expt, ket2dm(psi_gnd)
开发者ID:priyanka27s,项目名称:TA_software,代码行数:28,代码来源:test_qutip.py
示例3: correlator
def correlator(self):
"""correlator
Measure of quantum vs semiclassical"""
if not self.precalc:
self._calculate()
return np.abs(
np.asarray([qt.expect(self.a * self.sm, rho) for rho in self.rhos_ss])
- np.asarray([qt.expect(self.a, rho) for rho in self.rhos_ss])
* np.asarray([qt.expect(self.sm, rho) for rho in self.rhos_ss])
).T
开发者ID:fergusbarratt,项目名称:masters-project,代码行数:10,代码来源:quantumoptics.py
示例4: g2
def g2(self):
if not self.precalc:
self._calculate()
return np.abs(
np.asarray(
[
qt.expect(self.a.dag() * self.a.dag() * self.a * self.a, rho)
/ qt.expect(self.a.dag() * self.a, rho) ** 2
for rho in self.rhos_ss
]
)
).T
开发者ID:fergusbarratt,项目名称:masters-project,代码行数:12,代码来源:quantumoptics.py
示例5: test_ho_lgmres
def test_ho_lgmres():
"Steady state: Thermal HO - iterative-lgmres solver"
# thermal steadystate of an oscillator: compare numerics with analytical
# formula
a = destroy(40)
H = 0.5 * 2 * np.pi * a.dag() * a
gamma1 = 0.05
wth_vec = np.linspace(0.1, 3, 20)
p_ss = np.zeros(np.shape(wth_vec))
for idx, wth in enumerate(wth_vec):
n_th = 1.0 / (np.exp(1.0 / wth) - 1) # bath temperature
c_op_list = []
rate = gamma1 * (1 + n_th)
c_op_list.append(np.sqrt(rate) * a)
rate = gamma1 * n_th
c_op_list.append(np.sqrt(rate) * a.dag())
rho_ss = steadystate(H, c_op_list, method='iterative-lgmres')
p_ss[idx] = np.real(expect(a.dag() * a, rho_ss))
p_ss_analytic = 1.0 / (np.exp(1.0 / wth_vec) - 1)
delta = sum(abs(p_ss_analytic - p_ss))
assert_equal(delta < 1e-3, True)
开发者ID:jrjohansson,项目名称:qutip,代码行数:25,代码来源:test_steadystate.py
示例6: test_qubit_power
def test_qubit_power():
"Steady state: Thermal qubit - power solver"
# thermal steadystate of a qubit: compare numerics with analytical formula
sz = sigmaz()
sm = destroy(2)
H = 0.5 * 2 * np.pi * sz
gamma1 = 0.05
wth_vec = np.linspace(0.1, 3, 20)
p_ss = np.zeros(np.shape(wth_vec))
for idx, wth in enumerate(wth_vec):
n_th = 1.0 / (np.exp(1.0 / wth) - 1) # bath temperature
c_op_list = []
rate = gamma1 * (1 + n_th)
c_op_list.append(np.sqrt(rate) * sm)
rate = gamma1 * n_th
c_op_list.append(np.sqrt(rate) * sm.dag())
rho_ss = steadystate(H, c_op_list, method='power')
p_ss[idx] = expect(sm.dag() * sm, rho_ss)
p_ss_analytic = np.exp(-1.0 / wth_vec) / (1 + np.exp(-1.0 / wth_vec))
delta = sum(abs(p_ss_analytic - p_ss))
assert_equal(delta < 1e-5, True)
开发者ID:jrjohansson,项目名称:qutip,代码行数:26,代码来源:test_steadystate.py
示例7: steady
def steady(N = 20): # number of basis states to consider
n=num(N)
a = destroy(N)
H = a.dag() * a
print H.eigenstates()
#psi0 = basis(N, 10) # initial state
kappa = 0.1 # coupling to oscillator
c_op_list = []
n_th_a = 2 # temperature with average of 2 excitations
rate = kappa * (1 + n_th_a)
c_op_list.append(sqrt(rate) * a) # decay operators
rate = kappa * n_th_a
c_op_list.append(sqrt(rate) * a.dag()) # excitation operators
final_state = steadystate(H, c_op_list)
fexpt = expect(a.dag() * a, final_state)
#tlist = linspace(0, 100, 100)
#mcdata = mcsolve(H, psi0, tlist, c_op_list, [a.dag() * a], ntraj=100)
#medata = mesolve(H, psi0, tlist, c_op_list, [a.dag() * a])
#plot(tlist, mcdata.expect[0],
#plt.plot(tlist, medata.expect[0], lw=2)
plt.axhline(y=fexpt, color='r', lw=1.5) # ss expt. value as horiz line (= 2)
plt.ylim([0, 10])
plt.show()
开发者ID:priyanka27s,项目名称:TA_software,代码行数:26,代码来源:test_qutip.py
示例8: find_expect
def find_expect(self, vg, pwr, fd):
if self.power_plot:
phi, pwr=vg
else:
phi, fd=vg
pwr_fridge=pwr-self.atten
lin_pwr=0.001*10**(pwr_fridge/10.0)
Omega=sqrt(lin_pwr/h*2.0)
gamma, Delta=self._get_GammaDelta(fd=fd, f0=self.f0, Np=self.Np, gamma=self.gamma)
g_el=self._get_Gamma_C(fd=fd)
wTvec=self._get_fTvec(phi=phi, gamma=gamma, Delta=Delta, fd=fd, Psaw=lin_pwr)
if self.acoustic_plot:
Om=Omega*sqrt(gamma/fd)
else:
Om=Omega*sqrt(g_el/fd)
wT = wTvec-fd*self.nvec #rotating frame of gate drive \omega_m-m*\omega_\gate
transmon_levels = Qobj(diag(wT[range(self.N_dim)]))
rate1 = (gamma+g_el)*(1.0 + self.N_gamma)
rate2 = (gamma+g_el)*self.N_gamma
c_ops=[sqrt(rate1)*self.a_op, sqrt(rate2)*self.a_dag]#, sqrt(rate3)*self.a_op, sqrt(rate4)*self.a_dag]
Omega_vec=-0.5j*(Om*self.a_dag - conj(Om)*self.a_op)
H=transmon_levels +Omega_vec
final_state = steadystate(H, c_ops) #solve master equation
fexpt=expect(self.a_op, final_state) #expectation value of relaxation operator
#return fexpt
if self.acoustic_plot:
return 1.0*gamma/Om*fexpt
else:
return 1.0*sqrt(g_el*gamma)/Om*fexpt
开发者ID:thomasaref,项目名称:TA_software,代码行数:31,代码来源:qubit_saturation_Lamb.py
示例9: e_ops_func
def e_ops_func(t, rho, transformation=Utrans, e_ops=results.e_ops):
"""Transform the density matrix into the lab frame, and calculate the expectation values.
TODO: this could probably be streamlined... need to look into qutip's code
"""
rho_lab_frame=Utrans(t).dag()*q.Qobj(rho)*Utrans(t)
for i, e_operator in enumerate(e_ops):
expectation_values[i][e_ops_func.idx]=q.expect(e_operator, rho_lab_frame).real
e_ops_func.idx+=1
开发者ID:nelsonleung,项目名称:Qutip,代码行数:8,代码来源:multimode.py
示例10: essolve
def essolve(H, rho0, tlist, c_op_list, expt_op_list):
"""
Evolution of a state vector or density matrix (`rho0`) for a given
Hamiltonian (`H`) and set of collapse operators (`c_op_list`), by expressing
the ODE as an exponential series. The output is either the state vector at
arbitrary points in time (`tlist`), or the expectation values of the supplied
operators (`expt_op_list`).
Parameters
----------
H : qobj/function_type
System Hamiltonian.
rho0 : qobj
Initial state density matrix.
tlist : list/array
``list`` of times for :math:`t`.
c_op_list : list
``list`` of ``qobj`` collapse operators.
expt_op_list : list
``list`` of ``qobj`` operators for which to evaluate expectation values.
Returns
-------
expt_array : array
Expectation values of wavefunctions/density matrices for the times specified in ``tlist``.
.. note:: This solver does not support time-dependent Hamiltonians.
"""
n_expt_op = len(expt_op_list)
n_tsteps = len(tlist)
# Calculate the Liouvillian
if c_op_list == None or len(c_op_list) == 0:
L = H
else:
L = liouvillian(H, c_op_list)
es = ode2es(L, rho0)
# evaluate the expectation values
if n_expt_op == 0:
result_list = [Qobj() for k in range(n_tsteps)]
else:
result_list = zeros([n_expt_op, n_tsteps], dtype=complex)
for n in range(0, n_expt_op):
result_list[n,:] = esval(expect(expt_op_list[n],es),tlist)
return result_list
开发者ID:niazalikhan87,项目名称:qutip,代码行数:56,代码来源:essolve.py
示例11: get_reduced_dms
def get_reduced_dms(self, states, spin):
"""
takes a number of states and returns a list of bloch vector of the 0th spin coordinates for each
"""
sz = sigmaz()
sy = sigmay()
sx = sigmax()
zs = []
ys = []
xs = []
for state in states:
ptrace = state.ptrace(spin)
zval = abs(expect(sz, ptrace))
yval = abs(expect(sy, ptrace))
xval = abs(expect(sx, ptrace))
zs.append(zval)
ys.append(yval)
xs.append(xval)
return xs, ys, zs
开发者ID:HaeffnerLab,项目名称:HaeffnerLabLattice,代码行数:19,代码来源:state_quantifier.py
示例12: testCoherentState
def testCoherentState(self):
"""
states: coherent state
"""
N = 10
alpha = 0.5
c1 = coherent(N, alpha) # displacement method
c2 = coherent(7, alpha, offset=3) # analytic method
assert_(abs(expect(destroy(N), c1) - alpha) < 1e-10)
assert_((c1[3:]-c2).norm() < 1e-7)
开发者ID:NunoEdgarGub1,项目名称:qutip,代码行数:10,代码来源:test_states.py
示例13: get_dms
def get_dms(states):
'''
takes a number of states and returns a list of bloch vector coordinates for each
'''
si = qeye(2)
sz = sigmaz()
sy = sigmay()
sx = sigmax()
zs = []
ys = []
xs = []
for state in states:
ptrace = state.ptrace(0)
zval = expect(sz, ptrace )
yval = expect(sy, ptrace )
xval = expect(sx, ptrace )
zs.append(zval)
ys.append(yval)
xs.append(xval)
return xs,ys,zs
开发者ID:HaeffnerLab,项目名称:HaeffnerLabLattice,代码行数:20,代码来源:time_evolution.py
示例14: test_SparseHermValsVecs
def test_SparseHermValsVecs():
"""
Sparse eigs Hermitian
"""
# check using number operator
N = num(10)
spvals, spvecs = N.eigenstates(sparse=True)
for k in range(10):
# check that eigvals are in proper order
assert_equal(abs(spvals[k] - k) <= 1e-13, True)
# check that eigenvectors are right and in right order
assert_equal(abs(expect(N, spvecs[k]) - spvals[k]) < 5e-14, True)
# check ouput of only a few eigenvals/vecs
spvals, spvecs = N.eigenstates(sparse=True, eigvals=7)
assert_equal(len(spvals), 7)
assert_equal(spvals[0] <= spvals[-1], True)
for k in range(7):
assert_equal(abs(spvals[k] - k) < 1e-12, True)
spvals, spvecs = N.eigenstates(sparse=True, sort='high', eigvals=5)
assert_equal(len(spvals), 5)
assert_equal(spvals[0] >= spvals[-1], True)
vals = np.arange(9, 4, -1)
for k in range(5):
# check that eigvals are ordered from high to low
assert_equal(abs(spvals[k] - vals[k]) < 5e-14, True)
assert_equal(abs(expect(N, spvecs[k]) - vals[k]) < 1e-14, True)
# check using random Hermitian
H = rand_herm(10)
spvals, spvecs = H.eigenstates(sparse=True)
# check that sorting is lowest eigval first
assert_equal(spvals[0] <= spvals[-1], True)
# check that spvals equal expect vals
for k in range(10):
assert_equal(abs(expect(H, spvecs[k]) - spvals[k]) < 5e-14, True)
# check that ouput is real for Hermitian operator
assert_equal(np.isreal(spvals[k]), True)
开发者ID:JonathanUlm,项目名称:qutip,代码行数:39,代码来源:test_sp_eigs.py
示例15: jc_steadystate
def jc_steadystate(self, N, wc, wa, g, kappa, gamma,
pump, psi0, use_rwa, tlist):
# Hamiltonian
a = tensor(destroy(N), identity(2))
sm = tensor(identity(N), destroy(2))
if use_rwa:
# use the rotating wave approxiation
H = wc * a.dag(
) * a + wa * sm.dag() * sm + g * (a.dag() * sm + a * sm.dag())
else:
H = wc * a.dag() * a + wa * sm.dag() * sm + g * (
a.dag() + a) * (sm + sm.dag())
# collapse operators
c_op_list = []
n_th_a = 0.0 # zero temperature
rate = kappa * (1 + n_th_a)
c_op_list.append(np.sqrt(rate) * a)
rate = kappa * n_th_a
if rate > 0.0:
c_op_list.append(np.sqrt(rate) * a.dag())
rate = gamma
if rate > 0.0:
c_op_list.append(np.sqrt(rate) * sm)
rate = pump
if rate > 0.0:
c_op_list.append(np.sqrt(rate) * sm.dag())
# find the steady state
rho_ss = steadystate(H, c_op_list)
return expect(a.dag() * a, rho_ss), expect(sm.dag() * sm, rho_ss)
开发者ID:JonathanUlm,项目名称:qutip,代码行数:39,代码来源:test_mesolve.py
示例16: find_expect
def find_expect(vg, self=a): #phi=0.1, Omega_vec=3.0):
phi, Omega=vg#.shape
Omega_vec=-0.5j*(Omega*self.a_dag - conj(Omega)*self.a_op)
Ej = self.Ejmax*absolute(cos(pi*phi)) #Josephson energy as function of Phi.
wTvec = (-Ej + sqrt(8.0*Ej*self.Ec)*(self.nvec+0.5)+self.Ecvec)/h #\omega_m
wT = wTvec-a.fdvec #rotating frame of gate drive \omega_m-m*\omega_\gate
transmon_levels = Qobj(diag(wT[range(self.N_dim)]))
H=transmon_levels +Omega_vec #- 0.5j*(Omega_true*adag - conj(Omega_true)*a)
final_state = steadystate(H, self.c_ops) #solve master equation
return expect( self.a_op, final_state) #expectation value of relaxation operator
开发者ID:thomasaref,项目名称:TA_software,代码行数:14,代码来源:qubit_saturation.py
示例17: find_expect
def find_expect(vg): #phi=0.1, Omega_vec=3.0):
phi, Omega=vg#.shape
Omega_vec=- 0.5j*(Omega*adag - conj(Omega)*a)
Ej = Ejmax*absolute(cos(pi*phi)) #Josephson energy as function of Phi.
wTvec = -Ej + sqrt(8.0*Ej*Ec)*(nvec+0.5)+Ecvec #\omega_m
wT = wTvec-wdvec #rotating frame of gate drive \omega_m-m*\omega_\gate
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) #solve master equation
return expect( a, final_state) #expectation value of relaxation operator
开发者ID:thomasaref,项目名称:TA_software,代码行数:14,代码来源:qutip_steadystate.py
示例18: test_MCNoCollStates
def test_MCNoCollStates():
"Monte-carlo: Constant H with no collapse ops (states)"
error = 1e-8
N = 10 # number of basis states to consider
a = destroy(N)
H = a.dag() * a
psi0 = basis(N, 9) # initial state
c_op_list = []
tlist = np.linspace(0, 10, 100)
mcdata = mcsolve(H, psi0, tlist, c_op_list, [], ntraj=ntraj)
states = mcdata.states
expt = expect(a.dag() * a, states)
actual_answer = 9.0 * np.ones(len(tlist))
diff = np.mean(abs(actual_answer - expt) / actual_answer)
assert_equal(diff < error, True)
开发者ID:JonathanUlm,项目名称:qutip,代码行数:15,代码来源:test_mcsolve.py
示例19: calculate_expects
def calculate_expects(self):
'''
requires: self.expects
format: [[expectation for operator 1 for all times], [expectation for operator 1 for all times], ...]
'''
self.sim_expects = []
for i, oper in enumerate(self.expects):
expects = qt.expect(oper, self.sim_states)
self.sim_expects.append(expects)
self.sim_expects = np.array(self.sim_expects)
开发者ID:kschou,项目名称:QubitSimulator,代码行数:16,代码来源:qubit_simulator.py
示例20: test_MCSimpleConstStates
def test_MCSimpleConstStates():
"Monte-carlo: Constant H with constant collapse (states)"
N = 10 # number of basis states to consider
a = destroy(N)
H = a.dag() * a
psi0 = basis(N, 9) # initial state
kappa = 0.2 # coupling to oscillator
c_op_list = [np.sqrt(kappa) * a]
tlist = np.linspace(0, 10, 100)
mcdata = mcsolve(H, psi0, tlist, c_op_list, [], ntraj=ntraj,
options=Options(average_states=True))
assert_(len(mcdata.states) == len(tlist))
assert_(isinstance(mcdata.states[0], Qobj))
expt = expect(a.dag() * a, mcdata.states)
actual_answer = 9.0 * np.exp(-kappa * tlist)
avg_diff = np.mean(abs(actual_answer - expt) / actual_answer)
assert_equal(avg_diff < mc_error, True)
开发者ID:JonathanUlm,项目名称:qutip,代码行数:17,代码来源:test_mcsolve.py
注:本文中的qutip.expect函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论