本文整理汇总了Python中qutip.basis函数的典型用法代码示例。如果您正苦于以下问题:Python basis函数的具体用法?Python basis怎么用?Python basis使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了basis函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testCase2
def testCase2(self):
"mesolve: cavity-qubit without interaction, decay"
use_rwa = True
N = 4 # number of cavity fock states
wc = 2 * np.pi * 1.0 # cavity frequency
wa = 2 * np.pi * 1.0 # atom frequency
g = 2 * np.pi * 0.0 # coupling strength
kappa = 0.005 # cavity dissipation rate
gamma = 0.01 # atom dissipation rate
pump = 0.0 # atom pump rate
# start with an excited atom and maximum number of photons
n = N - 2
psi0 = tensor(basis(N, n), basis(2, 1))
tlist = np.linspace(0, 1000, 2000)
nc, na = self.jc_integrate(
N, wc, wa, g, kappa, gamma, pump, psi0, use_rwa, tlist)
nc_ex = (n + 0.5 * (1 - np.cos(2 * g * np.sqrt(n + 1) * tlist))) * \
np.exp(-kappa * tlist)
na_ex = 0.5 * (1 + np.cos(2 * g * np.sqrt(n + 1) * tlist)) * \
np.exp(-gamma * tlist)
assert_(max(abs(nc - nc_ex)) < 0.005, True)
assert_(max(abs(na - na_ex)) < 0.005, True)
示例2: testHOZeroTemperature
def testHOZeroTemperature():
"""
brmesolve: harmonic oscillator, zero temperature
"""
N = 10
w0 = 1.0 * 2 * np.pi
g = 0.05 * w0
kappa = 0.15
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())
c_ops = [np.sqrt(kappa) * a]
a_ops = [a + a.dag()]
e_ops = [a.dag() * a, a + a.dag()]
res_me = mesolve(H, psi0, times, c_ops, e_ops)
res_brme = brmesolve(H, psi0, times, a_ops, e_ops,
spectra_cb=[lambda w: kappa * (w >= 0)])
for idx, e in enumerate(e_ops):
diff = abs(res_me.expect[idx] - res_brme.expect[idx]).max()
assert_(diff < 1e-2)
示例3: testCase3
def testCase3(self):
"mesolve: cavity-qubit with interaction, decay"
use_rwa = True
N = 4 # number of cavity fock states
wc = 2 * np.pi * 1.0 # cavity frequency
wa = 2 * np.pi * 1.0 # atom frequency
g = 2 * np.pi * 0.1 # coupling strength
kappa = 0.05 # cavity dissipation rate
gamma = 0.001 # atom dissipation rate
pump = 0.25 # atom pump rate
# start with an excited atom and maximum number of photons
n = N - 2
psi0 = tensor(basis(N, n), basis(2, 1))
tlist = np.linspace(0, 200, 500)
nc, na = self.jc_integrate(
N, wc, wa, g, kappa, gamma, pump, psi0, use_rwa, tlist)
# we don't have any analytics for this parameters, so
# compare with the steady state
nc_ss, na_ss = self.jc_steadystate(
N, wc, wa, g, kappa, gamma, pump, psi0, use_rwa, tlist)
nc_ss = nc_ss * np.ones(np.shape(nc))
na_ss = na_ss * np.ones(np.shape(na))
assert_(abs(nc[-1] - nc_ss[-1]) < 0.005, True)
assert_(abs(na[-1] - na_ss[-1]) < 0.005, True)
示例4: 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)
示例5: testJCZeroTemperature
def testJCZeroTemperature():
"""
brmesolve: Jaynes-Cummings model, zero temperature
"""
N = 10
a = tensor(destroy(N), identity(2))
sm = tensor(identity(N), destroy(2))
psi0 = ket2dm(tensor(basis(N, 1), basis(2, 0)))
a_ops = [(a + a.dag())]
e_ops = [a.dag() * a, sm.dag() * sm]
w0 = 1.0 * 2 * np.pi
g = 0.05 * 2 * np.pi
kappa = 0.05
times = np.linspace(0, 2 * 2 * np.pi / g, 1000)
c_ops = [np.sqrt(kappa) * a]
H = w0 * a.dag() * a + w0 * sm.dag() * sm + \
g * (a + a.dag()) * (sm + sm.dag())
res_me = mesolve(H, psi0, times, c_ops, e_ops)
res_brme = brmesolve(H, psi0, times, a_ops, e_ops,
spectra_cb=[lambda w: kappa * (w >= 0)])
for idx, e in enumerate(e_ops):
diff = abs(res_me.expect[idx] - res_brme.expect[idx]).max()
assert_(diff < 5e-2) # accept 5% error
示例6: test_mc_dtypes2
def test_mc_dtypes2():
"Monte-carlo: check for correct dtypes (average_states=False)"
# set system parameters
kappa = 2.0 # mirror coupling
gamma = 0.2 # spontaneous emission rate
g = 1 # atom/cavity coupling strength
wc = 0 # cavity frequency
w0 = 0 # atom frequency
wl = 0 # driving frequency
E = 0.5 # driving amplitude
N = 5 # number of cavity energy levels (0->3 Fock states)
tlist = np.linspace(0, 10, 5) # times for expectation values
# construct Hamiltonian
ida = qeye(N)
idatom = qeye(2)
a = tensor(destroy(N), idatom)
sm = tensor(ida, sigmam())
H = (w0 - wl) * sm.dag() * sm + (wc - wl) * a.dag() * a + \
1j * g * (a.dag() * sm - sm.dag() * a) + E * (a.dag() + a)
# collapse operators
C1 = np.sqrt(2 * kappa) * a
C2 = np.sqrt(gamma) * sm
C1dC1 = C1.dag() * C1
C2dC2 = C2.dag() * C2
# intial state
psi0 = tensor(basis(N, 0), basis(2, 1))
opts = Options(average_expect=False)
data = mcsolve(
H, psi0, tlist, [C1, C2], [C1dC1, C2dC2, a], ntraj=5, options=opts)
assert_equal(isinstance(data.expect[0][0][1], float), True)
assert_equal(isinstance(data.expect[0][1][1], float), True)
assert_equal(isinstance(data.expect[0][2][1], complex), True)
示例7: testHOFiniteTemperature
def testHOFiniteTemperature(self):
"brmesolve: harmonic oscillator, finite temperature"
N = 10
w0 = 1.0 * 2 * np.pi
g = 0.05 * w0
kappa = 0.15
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 = [a.dag() * a, a + a.dag()]
res_me = mesolve(H, psi0, times, c_ops, e_ops)
res_brme = brmesolve(H, psi0, times, a_ops, e_ops, [S_w])
for idx, e in enumerate(e_ops):
diff = abs(res_me.expect[idx] - res_brme.expect[idx]).max()
assert_(diff < 1e-2)
示例8: eigen
def eigen(f, a, b):
if a == 1:
# returns excited states
return qt.basis(int(4*(f+1)), int(b+(f+1)))
elif a == 2:
# returns ground states
return qt.basis(int(4*(f+1)), int(b+3*(f+1)))
else:
return "Error in function eigen"
示例9: test_EntropyConcurrence
def test_EntropyConcurrence():
"Concurrence"
# check concurrence = 1 for maximal entangled (Bell) state
bell = ket2dm(
(tensor(basis(2), basis(2)) + tensor(basis(2, 1), basis(2, 1))).unit())
assert_equal(abs(concurrence(bell) - 1.0) < 1e-15, True)
# check all concurrence values >=0
rhos = [rand_dm(4, dims=[[2, 2], [2, 2]]) for k in range(10)]
for k in rhos:
assert_equal(concurrence(k) >= 0, True)
示例10: test_create
def test_create():
"Creation operator"
b3 = basis(5, 3)
c5 = create(5)
test1 = c5 * b3
assert_equal(np.allclose(test1.full(), 2.0 * basis(5, 4).full()), True)
c3 = create(3)
matrix3 = np.array([[0.00000000 + 0.j, 0.00000000 + 0.j, 0.00000000 + 0.j],
[1.00000000 + 0.j, 0.00000000 + 0.j, 0.00000000 + 0.j],
[0.00000000 + 0.j, 1.41421356 + 0.j, 0.00000000 + 0.j]])
assert_equal(np.allclose(matrix3, c3.full()), True)
示例11: mcsolve
def mcsolve(self, ntrajs=500, exps=[], initial_state=None):
"""mcsolve
Interface to qutip mcsolve for the system
:param ntrajs: number of quantum trajectories to average.
Default is QuTiP
default of 500
:param exps: List of expectation values to calculate at
each timestep
"""
if initial_state is None:
initial_state = qt.tensor(qt.basis(self.N_field_levels, 0), qt.basis(2, 0))
return qt.mcsolve(self.hamiltonian()[0], initial_state, self.tlist, self._c_ops(), exps, ntraj=ntrajs)
示例12: test_destroy
def test_destroy():
"Destruction operator"
b4 = basis(5, 4)
d5 = destroy(5)
test1 = d5 * b4
assert_equal(np.allclose(test1.full(), 2.0 * basis(5, 3).full()), True)
d3 = destroy(3)
matrix3 = np.array([[0.00000000 + 0.j, 1.00000000 + 0.j, 0.00000000 + 0.j],
[0.00000000 + 0.j, 0.00000000 + 0.j, 1.41421356 + 0.j],
[0.00000000 + 0.j, 0.00000000 + 0.j, 0.00000000 + 0.j]])
assert_equal(np.allclose(matrix3, d3.full()), True)
示例13: _label_to_ket
def _label_to_ket(self, one_pho_label):
# return qobj with correct structure of node
pol = {'H':0, 'V':1}
port = {k:v for v,k in enumerate(ascii_uppercase)}
node_info = self.get_node_info()
dof = one_pho_label.split('_')
if self._is_polarized:
# create pol vec
polarization = qt.basis(2, pol[dof[0]])
port = qt.basis(node_info[dof[1]], port[dof[2]])
else:
port = qt.basis(node_info[dof[0]], port[dof[1]])
return qt.tensor([polarization, port])
示例14: heisenberg_weyl_operators
def heisenberg_weyl_operators(d=2):
w = np.exp(2 * np.pi * 1j / d)
X = qt.Qobj([
qt.basis(d, (idx + 1) % d).data.todense().view(np.ndarray)[:, 0] for idx in xrange(d)
])
Z = qt.Qobj(np.diag(w ** np.arange(d)))
return [X**i * Z**j for i in xrange(d) for j in xrange(d)]
示例15: compute_item
def compute_item(self, name, model):
name += "_1"
fock_dim = self.editor.fock_dim.value()
timestep = self.editor.timestep.value()
initial_alpha = self.editor.initial_alpha.value()
steps = model.get_steps(fock_dim, timestep)
res0 = coherent_dm(fock_dim, initial_alpha)
qubit0 = ket2dm((basis(2, 0) + basis(2, 1)) / np.sqrt(2))
psi0 = tensor(qubit0, res0)
def add_to_viewer(r):
item = WignerPlotter(name, r)
item.wigners_complete.connect(lambda: self.viewer.add_item(item))
win.statusBar().showMessage("Computing Wigners")
args = (steps, fock_dim, psi0, timestep)
run_in_process(to_state_list, add_to_viewer, args)
#self.thread_is_running.emit()
win.statusBar().showMessage("Computing States")