• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python qutip.basis函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中qutip.basis函数的典型用法代码示例。如果您正苦于以下问题:Python basis函数的具体用法?Python basis怎么用?Python basis使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了basis函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:JonathanUlm,项目名称:qutip,代码行数:27,代码来源:test_mesolve.py


示例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)
开发者ID:JonathanUlm,项目名称:qutip,代码行数:26,代码来源:test_brmesolve.py


示例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)
开发者ID:JonathanUlm,项目名称:qutip,代码行数:30,代码来源:test_mesolve.py


示例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)
开发者ID:JonathanUlm,项目名称:qutip,代码行数:35,代码来源:test_brmesolve.py


示例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
开发者ID:JonathanUlm,项目名称:qutip,代码行数:28,代码来源:test_brmesolve.py


示例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)
开发者ID:JonathanUlm,项目名称:qutip,代码行数:32,代码来源:test_mcsolve.py


示例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)
开发者ID:tmng,项目名称:qutip,代码行数:31,代码来源:test_brmesolve.py


示例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"
开发者ID:ohpyupi,项目名称:3d-optical-lattice,代码行数:9,代码来源:functions.py


示例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)
开发者ID:tmng,项目名称:qutip,代码行数:11,代码来源:test_entropy.py


示例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)
开发者ID:tmng,项目名称:qutip,代码行数:12,代码来源:test_operators.py


示例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)
开发者ID:fergusbarratt,项目名称:masters-project,代码行数:12,代码来源:quantumoptics.py


示例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)
开发者ID:tmng,项目名称:qutip,代码行数:12,代码来源:test_operators.py


示例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])
开发者ID:caseyalan,项目名称:quantum-scattering-networks,代码行数:15,代码来源:multiport_photonic_state.py


示例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)]
开发者ID:YulinWu,项目名称:python-qinfer,代码行数:8,代码来源:expdesign.py


示例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")
开发者ID:PhilReinhold,项目名称:wignerwindow,代码行数:17,代码来源:wigner_window.py


示例16: __init__

 def __init__(self, field, mass=const.MASS_OF_PROTON,
              charge=const.ELECTRON_CHARGE,
              initial_state=qt.basis(2,0)):
     self.mass = mass
     self.charge = charge
     self.parent_field = field
     self.gyromagnetic_ratio = 267.513e6
     self.parent_field.particles.append(self)
     self.state = initial_state
开发者ID:MichalKononenko,项目名称:NMR_Model,代码行数:9,代码来源:precession_model.py


示例17: testTLS

    def testTLS(self):
        "brmesolve: qubit"

        delta = 0.0 * 2 * np.pi
        epsilon = 0.5 * 2 * np.pi
        gamma = 0.25
        times = np.linspace(0, 10, 100)
        H = delta/2 * sigmax() + epsilon/2 * sigmaz()
        psi0 = (2 * basis(2, 0) + basis(2, 1)).unit()
        c_ops = [np.sqrt(gamma) * sigmam()]
        a_ops = [sigmax()]
        e_ops = [sigmax(), sigmay(), sigmaz()]
        res_me = mesolve(H, psi0, times, c_ops, e_ops)
        res_brme = brmesolve(H, psi0, times, a_ops, e_ops,
                             spectra_cb=[lambda w: gamma * (w >= 0)])

        for idx, e in enumerate(e_ops):
            diff = abs(res_me.expect[idx] - res_brme.expect[idx]).max()
            assert_(diff < 1e-2)
开发者ID:tmng,项目名称:qutip,代码行数:19,代码来源:test_brmesolve.py


示例18: test_mc_seed_noreuse

def test_mc_seed_noreuse():
    "Monte-carlo: check not reusing seeds"
    N0 = 6
    N1 = 6
    N2 = 6
    # damping rates
    gamma0 = 0.1
    gamma1 = 0.4
    gamma2 = 0.1
    alpha = np.sqrt(2)  # initial coherent state param for mode 0
    tlist = np.linspace(0, 10, 2)
    ntraj = 500  # number of trajectories
    # define operators
    a0 = tensor(destroy(N0), qeye(N1), qeye(N2))
    a1 = tensor(qeye(N0), destroy(N1), qeye(N2))
    a2 = tensor(qeye(N0), qeye(N1), destroy(N2))
    # number operators for each mode
    num0 = a0.dag() * a0
    num1 = a1.dag() * a1
    num2 = a2.dag() * a2
    # dissipative operators for zero-temp. baths
    C0 = np.sqrt(2.0 * gamma0) * a0
    C1 = np.sqrt(2.0 * gamma1) * a1
    C2 = np.sqrt(2.0 * gamma2) * a2
    # initial state: coherent mode 0 & vacuum for modes #1 & #2
    psi0 = tensor(coherent(N0, alpha), basis(N1, 0), basis(N2, 0))
    # trilinear Hamiltonian
    H = 1j * (a0 * a1.dag() * a2.dag() - a0.dag() * a1 * a2)
    # run Monte-Carlo
    data1 = mcsolve(H, psi0, tlist, [C0, C1, C2], [num0, num1, num2],
                    ntraj=ntraj)
    data2 = mcsolve(H, psi0, tlist, [C0, C1, C2], [num0, num1, num2],
                    ntraj=ntraj)
    diff_flag = False
    for k in range(ntraj):
        if len(data1.col_times[k]) != len(data2.col_times[k]):
            diff_flag = 1
            break
        else:
            if not np.allclose(data1.col_which[k],data2.col_which[k]):
                diff_flag = 1
                break
    assert_equal(diff_flag, 1)
开发者ID:JonathanUlm,项目名称:qutip,代码行数:43,代码来源:test_mcsolve.py


示例19: testCOPS

def testCOPS():
    """
    brmesolve: c_ops alone
    """

    delta = 0.0 * 2 * np.pi
    epsilon = 0.5 * 2 * np.pi
    gamma = 0.25
    times = np.linspace(0, 10, 100)
    H = delta/2 * sigmax() + epsilon/2 * sigmaz()
    psi0 = (2 * basis(2, 0) + basis(2, 1)).unit()
    c_ops = [np.sqrt(gamma) * sigmam()]
    e_ops = [sigmax(), sigmay(), sigmaz()]
    res_me = mesolve(H, psi0, times, c_ops, e_ops)
    res_brme = brmesolve(H, psi0, times, [], e_ops,
                         spectra_cb=[], c_ops=c_ops)

    for idx, e in enumerate(e_ops):
        diff = abs(res_me.expect[idx] - res_brme.expect[idx]).max()
        assert_(diff < 1e-2)
开发者ID:JonathanUlm,项目名称:qutip,代码行数:20,代码来源:test_brmesolve.py


示例20: test_EntropyVN

def test_EntropyVN():
    "von-Neumann entropy"
    # verify that entropy_vn gives correct binary entropy
    a = np.linspace(0, 1, 20)
    for k in range(len(a)):
        # a*|0><0|
        x = a[k] * ket2dm(basis(2, 0))
        # (1-a)*|1><1|
        y = (1 - a[k]) * ket2dm(basis(2, 1))
        rho = x + y
        # Von-Neumann entropy (base 2) of rho
        out = entropy_vn(rho, 2)
        if k == 0 or k == 19:
            assert_equal(out, -0.0)
        else:
            assert_(abs(-out - a[k] * np.log2(a[k])
                        - (1. - a[k]) * np.log2((1. - a[k]))) < 1e-12)

    # test_ entropy_vn = 0 for pure state
    psi = rand_ket(10)
    assert_equal(abs(entropy_vn(psi)) <= 1e-13, True)
开发者ID:tmng,项目名称:qutip,代码行数:21,代码来源:test_entropy.py



注:本文中的qutip.basis函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python qutip.destroy函数代码示例发布时间:2022-05-26
下一篇:
Python qutils.ask_number_question函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap