示例#1
0
def test_system_builder():
    check_trace_preservation(
        sb.diffusion_op, lambda c_op, partial_basis: sb.op_calc_setup(
            c_op, 0, 0, np.zeros(c_op.shape), partial_basis))
    squeezing_params = [1, 1.j, -1, -1.j]
    for M in squeezing_params:
        check_trace_preservation(
            sb.double_comm_op, lambda c_op, partial_basis: sb.op_calc_setup(
                c_op, M, 0, np.zeros(c_op.shape), partial_basis))
    c2_operators = [
        np.array([[0, 1], [0, 0]]),
        np.array([[0, 0], [1, 0]]),
        np.array([[1, 0], [0, -1]]),
        np.array([[0, 1], [1, 0]]),
        np.array([[0, -1.j], [1.j, 0]]),
        np.array([[1, 2], [3, 4]])
    ]

    c3_operators = [
        np.array([[0, 1, 0], [0, 0, 1], [0, 0, 0]]),
        np.array([[0, 0, 0], [1, 0, 0], [0, 1, 0]]),
        np.array([[1, 0, 0], [0, 0, 0], [0, 0, -1]]),
        np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
    ]
    check_vectorize(c2_operators, basis(2))
    # Check vectorization of a mixing of the basis vectors (designed to catch a
    # previous error in calculating normalization)
    orth_mat = 0.5 * np.array([[1, 1, 1, 1], [1, 1, -1, -1], [1, -1, 1, -1],
                               [1, -1, -1, 1]])
    mixed_basis2 = [
        sum([entry * basis_el for entry, basis_el in zip(row, basis(2))])
        for row in orth_mat
    ]
    check_vectorize(c2_operators, mixed_basis2)
    check_vectorize(c3_operators, basis(3))
示例#2
0
def precomp_fn(coupling_op, M_sq, N, H0, partial_basis, **kwargs):
    common_dict = sb.op_calc_setup(coupling_op, M_sq, N, H0, partial_basis)
    D_c = sb.diffusion_op(**common_dict)
    conjugate_dict = common_dict.copy()
    conjugate_dict['C_vector'] = common_dict['C_vector'].conjugate()
    D_c_dag = sb.diffusion_op(**conjugate_dict)
    E = sb.double_comm_op(**common_dict)
    F0 = sb.hamiltonian_op(**common_dict)

    Q_minus_F = (N + 1) * D_c + N * D_c_dag + E
    G, k_T = sb.weiner_op(**common_dict)

    return_vals = {
        'Q_minus_F': Q_minus_F,
        'F0': F0,
        'diffusion_reps': {
            'G': G,
            'k_T': k_T
        }
    }
    more_vals = {
        'c_op': coupling_op,
        'M_sq': M_sq,
        'N': N,
        'H': H0,
        'partial_basis': partial_basis
    }
    return_vals.update(more_vals)
    return return_vals
示例#3
0
文件: tests.py 项目: CQuIC/pysme
def test_system_builder():
    check_trace_preservation(sb.diffusion_op, lambda c_op, partial_basis:
                             sb.op_calc_setup(c_op, 0, 0, np.zeros(c_op.shape),
                                              partial_basis))
    squeezing_params = [1, 1.j, -1, -1.j]
    for M in squeezing_params:
        check_trace_preservation(sb.double_comm_op, lambda c_op, partial_basis:
                                 sb.op_calc_setup(c_op, M, 0,
                                                  np.zeros(c_op.shape),
                                                  partial_basis))
    c2_operators = [np.array([[0, 1],
                              [0, 0]]),
                    np.array([[0, 0],
                              [1, 0]]),
                    np.array([[1, 0],
                              [0, -1]]),
                    np.array([[0, 1],
                              [1, 0]]),
                    np.array([[0, -1.j],
                              [1.j, 0]]),
                    np.array([[1, 2],
                              [3, 4]])]

    c3_operators = [np.array([[0, 1, 0],
                              [0, 0, 1],
                              [0, 0, 0]]),
                    np.array([[0, 0, 0],
                              [1, 0, 0],
                              [0, 1, 0]]),
                    np.array([[1, 0, 0],
                              [0, 0, 0],
                              [0, 0, -1]]),
                    np.array([[1, 2, 3],
                              [4, 5, 6],
                              [7, 8, 9]])]
    check_vectorize(c2_operators, basis(2))
    # Check vectorization of a mixing of the basis vectors (designed to catch a
    # previous error in calculating normalization)
    orth_mat = 0.5*np.array([[1, 1, 1, 1],
                             [1, 1, -1, -1],
                             [1, -1, 1, -1],
                             [1, -1, -1, 1]])
    mixed_basis2 = [sum([entry*basis_el for entry, basis_el in
                         zip(row, basis(2))]) for row in orth_mat]
    check_vectorize(c2_operators, mixed_basis2)
    check_vectorize(c3_operators, basis(3))
示例#4
0
 def __init__(self, d_sys, n_max):
     self.d_sys = d_sys
     self.n_max = n_max
     self.d_total = (self.n_max + 1) * self.d_sys
     self.basis = gm.get_basis(self.d_total)
     # Only want the parts of common_dict pertaining to the basis setup
     # (which is time-consuming). Suggests I should split the basis part out
     # into a separate function (perhaps a basis object).
     zero_op = np.zeros((self.d_total, self.d_total), dtype=np.complex)
     self.basis_common_dict = sb.op_calc_setup(zero_op, 0, 0, zero_op,
                                               self.basis[:-1])
示例#5
0
 def __init__(self, d_sys, n_max):
     self.d_sys = d_sys
     self.n_max = n_max
     self.d_total = (self.n_max + 1) * self.d_sys
     self.basis = gm.get_basis(self.d_total)
     # Only want the parts of common_dict pertaining to the basis setup
     # (which is time-consuming). Suggests I should split the basis part out
     # into a separate function (perhaps a basis object).
     zero_op = np.zeros((self.d_total, self.d_total), dtype=np.complex)
     self.basis_common_dict = sb.op_calc_setup(zero_op, 0, 0, zero_op,
                                               self.basis[:-1])
示例#6
0
文件: smc.py 项目: CQuIC/pysme
def precomp_fn(coupling_op, M_sq, N, H0, partial_basis,
               **kwargs):
    common_dict = sb.op_calc_setup(coupling_op, M_sq, N, H0, partial_basis)
    D_c = sb.diffusion_op(**common_dict)
    conjugate_dict = common_dict.copy()
    conjugate_dict['C_vector'] = common_dict['C_vector'].conjugate()
    D_c_dag = sb.diffusion_op(**conjugate_dict)
    E = sb.double_comm_op(**common_dict)
    F0 = sb.hamiltonian_op(**common_dict)
    
    Q_minus_F = (N + 1) * D_c + N * D_c_dag + E
    G, k_T = sb.weiner_op(**common_dict)

    return_vals = {
                   'Q_minus_F': Q_minus_F,
                   'F0': F0,
                   'diffusion_reps': {'G': G, 'k_T': k_T}
                  }
    more_vals ={'c_op': coupling_op, 'M_sq': M_sq, 'N': N,
                'H': H0, 'partial_basis': partial_basis}
    return_vals.update(more_vals)
    return return_vals
示例#7
0
文件: tests.py 项目: eliegenois/pysme
def check_system_builder_double_comm_op():
    sx = np.array([[0, 1], [1, 0]], dtype=np.complex)
    sm = np.array([[0, 0], [1, 0]], dtype=np.complex)
    Id = np.eye(2, dtype=np.complex)
    zero = np.zeros((2, 2), dtype=np.complex)
    r = np.log(2)
    N = np.sinh(r)**2
    M = -np.sinh(r) * np.cosh(r)
    H = zero
    c_op = sm
    c_op_dag = c_op.conjugate().T
    rho0 = (Id + sx) / 2
    integrator = integrate.UncondGaussIntegrator(c_op, M, N, H)
    rho0_vec = sb.vectorize(rho0, integrator.basis)
    partial_basis = integrator.basis[:-1]
    common_dict = sb.op_calc_setup(c_op, M, N, H, partial_basis)
    E = sb.double_comm_op(**common_dict)
    vec_double_comm = E @ rho0_vec
    matrix_double_comm = ((M / 2) * mf.comm(c_op_dag, mf.comm(c_op_dag, rho0))
                          + (M.conjugate() / 2) * mf.comm(c_op,
                                                          mf.comm(c_op, rho0)))
    check_mat_eq(np.einsum('k,kmn->mn', vec_double_comm, integrator.basis),
                 matrix_double_comm)