Exemplo n.º 1
0
def apply_dephasing(number_of_spins, alpha, B,fm_str = 'AFM',kT = 0.0):
    '''
    takes number of spins, alpha, and the magnetic field and returns the
    hamiltonian along with its ground state and the dephased ground state
    choose fm_str = 'FM' for ferromagnetic interaction, and 'AFM' for anti-ferromagnetic 
    '''
    if fm_str == 'FM':
        calc = ising_calculator_FM(number_of_spins, alpha, B)
    elif fm_str == 'AFM':
        calc = ising_calculator_AFM(number_of_spins, alpha, B)
    H = calc.get_H()
    if kT == 0.0:
        energy,groundstate = H.groundstate()
        dm_groundstate = ket2dm(groundstate)
    else:
        Hdata = H.data.todense()
        arr_mp = mp.matrix(-Hdata /kT)
        exp_mp = mp.expm(arr_mp)
        trace = np.array(exp_mp.tolist()).trace()
        normalized_mp = exp_mp / trace
        normalized_np = np.array(normalized_mp.tolist(), dtype = np.complex)
        dm_groundstate = Qobj(normalized_np, dims = 2 * [number_of_spins*[2]])
    dephased = do_dephasing_dm(dm_groundstate, number_of_spins)
    return H, dm_groundstate, dephased
Exemplo n.º 2
0
def expM(Q):
    """Uses mpmath's exp computation
    """
    return mp.expm(Q)
mpmath.mpf.shape = ()
mpmath.mpc.shape = ()


# Observe that our E7-definitions have 'numerically exact' structure constants.
#
# So, it actually makes sense to take these as defined, and lift them to mpmath.
#
# >>> set(e7.t_a_ij_kl.reshape(-1))
# >>> {(-2+0j), (-1+0j), -2j, -1j, 0j, 1j, 2j, (1+0j), (2+0j)}


# `mpmath` does not work with numpy.einsum(), so for that reason alone,
# we use opt_einsum's generic-no-backend alternative implementation.
mpmath_scalar_manifold_evaluator = scalar_sector.get_scalar_manifold_evaluator(
    frac=lambda p, q: mpmath.mpf(p) / mpmath.mpf(q),
    to_scaled_constant=(
        lambda x, scale=1: numpy.array(
            x, dtype=mpmath.ctx_mp_python.mpc) * scale),
    # Wrapping up `expm` is somewhat tricky here, as it returns a mpmath
    # matrix-type that numpy does not understand.
    expm=lambda m: numpy.array(mpmath.expm(m).tolist()),
    einsum=lambda spec, *arrs: opt_einsum.contract(spec, *arrs),
    # trace can stay as-is.
    eye=lambda n: numpy.eye(n) + mpmath.mpc(0),
    complexify=lambda a: a + mpmath.mpc(0),
    # re/im are again tricky, since numpy.array(dtype=object)
    # does not forward .real / .imag to the contained objects.
    re=lambda a: numpy.array([z.real for z in a.reshape(-1)]).reshape(a.shape),
    im=lambda a: numpy.array([z.imag for z in a.reshape(-1)]).reshape(a.shape))