示例#1
0
def test_spin_output(func):
    assert qutip.isket(func(1.0, 0, type='ket'))
    assert qutip.isbra(func(1.0, 0, type='bra'))
    assert qutip.isoper(func(1.0, 0, type='dm'))

    with pytest.raises(ValueError) as e:
        func(1.0, 0, type='something')
    assert str(e.value) == "invalid value keyword argument 'type'"
示例#2
0
def test_ket2dm():
    N = 5
    ket = qutip.coherent(N, 2)
    bra = ket.dag()
    oper = qutip.ket2dm(ket)
    oper_from_bra = qutip.ket2dm(bra)
    assert qutip.expect(oper, ket) == pytest.approx(1.)
    assert qutip.isoper(oper)
    assert oper == ket * bra
    assert oper == oper_from_bra
    with pytest.raises(TypeError) as e:
        qutip.ket2dm(oper)
    assert str(e.value) == "Input is not a ket or bra vector."
示例#3
0
def mesolve(H,
            rho0,
            tlist,
            c_ops=None,
            e_ops=None,
            dims={},
            t_dep_fL={},
            coupling_fL={},
            max_step_size=0.1,
            rtol=1e-6,
            atol=1e-10):
    """ Mimic the interface of qutip's mesolve
    """
    lhsL, rhsL, e_op_outL = makeMESymb(H, c_opL=c_ops, e_opL=e_ops)

    ode_s = ivp.ODESolver(dict(zip(lhsL, rhsL)),
                          dims=dims,
                          driving_syms=list(t_dep_fL.keys()))
    ode_s.set_driving(t_dep_fL)
    #ode_s.set_state_dep()

    # Convert a qobj state input to a density matrix
    if q.isket(rho0):
        rho0 = rho0 * rho0.dag()
    if q.isoper(rho0):
        rho0 = toDense(rho0)
    rho0 = Dia(rho0) + Coh(rho0)
    ode_s.set_initial_conditions(rho0)
    e_op_f_L = [
        sm.lambdify(ode_s.symsD['prop_state_syms'], e_op) for e_op in e_op_outL
    ]

    def calc_expectation_vals(state):
        return [f(*state) for f in e_op_f_L]

    ode_s.set_online_processing(calc_expectation_vals)
    ode_s.setup()
    out = ode_s.integrate(tlist,
                          max_step_size=max_step_size,
                          atol=atol,
                          rtol=rtol)
    state_res = np.array(ode_s.outputL).squeeze()
    # Should do something about expectation values here. Probably evaluate them
    #if e_op_outL:
    #f = sm.lambdify(ode_s.state_syms, e_op_outL)
    #return f(state_res)
    return state_res