Exemple #1
0
def GHZ (L, config):
    s1=['1']*(L)
    s2=['0']*(L)
    state = (1.0/sqrt(2.0)) \
            * (listkron([bvecs[key] for key in s1]) \
            +   listkron([bvecs[key] for key in s2]))

    return state
Exemple #2
0
def Bell_array(L, config):
    try:
        bell_type = config[0]
    except:
        bell_type = '0'
    ic = 'B0-1_{}'.format(bell_type)
    singlet = make_state(2, ic)
    if L % 2 == 0:
        state = listkron([singlet] * int(L / 2))
    else:
        state = listkron([singlet] * int((L - 1) / 2) + [bvecs['0']])
    return state
Exemple #3
0
def rule_unitaries(V,
                   R,
                   r,
                   BC,
                   L,
                   dt,
                   totalistic=False,
                   hamiltonian=False,
                   trotter=True):
    """
    Calculate qca unitiary activation V, rule R, radius r, bounary condition BC,
    size L, and time step dt.
    """
    BC_type, *BC_conf = BC.split("-")
    BC_conf = "".join(BC_conf)
    if BC_type == "1":
        BC_conf = [int(bc) for bc in BC_conf]
    if L is None:
        L = 2 * r + 1
    bulk = rule_op(V, R, r, totalistic=totalistic, hamiltonian=hamiltonian)
    lUs, rUs = boundary_rule_ops(V,
                                 R,
                                 r,
                                 BC_conf,
                                 totalistic=totalistic,
                                 hamiltonian=hamiltonian)
    if hamiltonian:
        if trotter:
            bulk = expm(-1j * bulk * dt)
            rUs = [expm(-1j * H * dt) for H in rUs]
            lUs = [expm(-1j * H * dt) for H in lUs]
        else:  # not trotter:
            H = np.zeros((2**L, 2**L), dtype=complex)
            for j in range(r, L - r):
                ln = j - r
                rn = L - 2 * r - 1 - ln
                left = np.eye(2**ln)
                right = np.eye(2**rn)
                H += mx.listkron([left, bulk, right])
            # boundaries
            for j, (lU, rU) in enumerate(zip(lUs, rUs[::-1])):
                end = np.eye(2**(L - r - 1 - j))
                H += mx.listkron([end, rU])
                H += mx.listkron([lU, end])
            U = expm(-1j * H * dt)
            assert mx.isU(U)
            return U

    if BC_type == "0":
        return bulk
    else:  # BC_type == "1"
        return lUs, bulk, rUs
Exemple #4
0
def rand_state(L, config):
    ps_qex_qbg_conf = config.split('_')
    ps = ps_qex_qbg_conf[0].split('-')
    p = float('.' + ps[0])
    s = None
    if len(ps) == 2:
        s = ps[1]
    if len(ps_qex_qbg_conf) == 1:
        state_dict = {'ex': bvecs['1'], 'bg': bvecs['0']}
    if len(ps_qex_qbg_conf) == 2:
        ex_th, ex_ph = ps_qex_qbg_conf[1].split('-')
        ex_th = float(ex_th[1:])
        ex_ph = float(ex_ph[1:])
        state_dict = {'ex': qubit(ex_th, ex_ph), 'bg': bvecs['0']}
    if len(ps_qex_qbg_conf) == 3:
        ex_th, ex_ph = ps_qex_qbg_conf[1].split('-')
        ex_th = float(ex_th[1:])
        ex_ph = float(ex_ph[1:])
        bg_th, bg_ph = ps_qex_qbg_conf[2].split('-')
        bg_th = float(bg_th[1:])
        bg_ph = float(bg_ph[1:])
        state_dict = {'ex': qubit(ex_th, ex_ph), 'bg': qubit(bg_th, bg_ph)}
    prob = [p, 1.0 - p]
    if s is not None:
        np.random.seed(int(s))
    distrib = np.random.choice(['ex', 'bg'], size=L, p=prob)
    return listkron([state_dict[i] for i in distrib])
Exemple #5
0
def rand_plus(L, config):
    exs_ps_qex_qbg_conf = config.split('_')
    exs = exs_ps_qex_qbg_conf[0].split('-')
    exs = np.array([int(ex) for ex in exs])
    ps = exs_ps_qex_qbg_conf[1].split('-')
    p = float('.' + ps[0])
    prob = [p, 1.0 - p]
    s = None
    if len(ps) == 2:
        s = ps[1]
    if s is not None:
        np.random.seed(int(s))
    if len(exs_ps_qex_qbg_conf) == 2:
        state_dict = {'ex': bvecs['1'], 'bg': bvecs['0']}
    if len(exs_ps_qex_qbg_conf) == 3:
        ex_th, ex_ph = exs_ps_qex_qbg_conf[2].split('-')
        ex_th = float(ex_th[1:])
        ex_ph = float(ex_ph[1:])
        state_dict = {'ex': qubit(ex_th, ex_ph), 'bg': bvecs['0']}
    if len(exs_ps_qex_qbg_conf) == 4:
        ex_th, ex_ph = exs_ps_qex_qbg_conf[2].split('-')
        ex_th = float(ex_th[1:])
        ex_ph = float(ex_ph[1:])
        bg_th, bg_ph = exs_ps_qex_qbg_conf[3].split('-')
        bg_th = float(bg_th[1:])
        bg_ph = float(bg_ph[1:])
        state_dict = {'ex': qubit(ex_th, ex_ph), 'bg': qubit(bg_th, bg_ph)}
    distrib = np.random.choice(['ex', 'bg'], size=L, p=prob)
    distrib[exs] = 'ex'
    state = listkron([state_dict[q] for q in distrib])
    return state
Exemple #6
0
def rand_plus(L, config):
    exs_ps_qex_qbg_conf = config.split('_')
    exs = exs_ps_qex_qbg_conf[0].split('-')
    exs = np.array([int(ex) for ex in exs])
    ps = exs_ps_qex_qbg_conf[1].split('-')
    p = float('.'+ps[0])
    prob = [p, 1.0 - p]
    s = None
    if len(ps) == 2:
        s = ps[1]
    if s is not None:
        np.random.seed(int(s))

    if len(exs_ps_qex_qbg_conf) == 2:
        state_dict = {'ex':bvecs['1'], 'bg':bvecs['0']}

    if len(exs_ps_qex_qbg_conf) == 3:
        ex_th, ex_ph = exs_ps_qex_qbg_conf[2].split('-')
        ex_th = float(ex_th[1:])
        ex_ph = float(ex_ph[1:])
        state_dict = {'ex':qubit(ex_th, ex_ph), 'bg':bvecs['0']}

    if len(exs_ps_qex_qbg_conf) == 4:
        ex_th, ex_ph = exs_ps_qex_qbg_conf[2].split('-')
        ex_th = float(ex_th[1:])
        ex_ph = float(ex_ph[1:])
        bg_th, bg_ph = exs_ps_qex_qbg_conf[3].split('-')
        bg_th = float(bg_th[1:])
        bg_ph = float(bg_ph[1:])
        state_dict = {'ex':qubit(ex_th, ex_ph), 'bg':qubit(bg_th, bg_ph)}
    distrib = np.random.choice(['ex','bg'], size=L, p=prob)
    distrib[exs] = 'ex'
    state = listkron([state_dict[q] for q in distrib])
    return state
Exemple #7
0
def rand_state(L, config):
    ps_qex_qbg_conf = config.split('_')
    ps = ps_qex_qbg_conf[0].split('-')
    p = float('.'+ps[0])
    s = None
    if len(ps) == 2:
        s = ps[1]

    if len(ps_qex_qbg_conf)==1:
        state_dict = {'ex':bvecs['1'], 'bg':bvecs['0']}

    if len(ps_qex_qbg_conf)==2:
        ex_th, ex_ph = ps_qex_qbg_conf[1].split('-')
        ex_th = float(ex_th[1:])
        ex_ph = float(ex_ph[1:])
        state_dict = {'ex':qubit(ex_th, ex_ph), 'bg':bvecs['0']}

    if len(ps_qex_qbg_conf)==3:
        ex_th, ex_ph = ps_qex_qbg_conf[1].split('-')
        ex_th = float(ex_th[1:])
        ex_ph = float(ex_ph[1:])
        bg_th, bg_ph = ps_qex_qbg_conf[2].split('-')
        bg_th = float(bg_th[1:])
        bg_ph = float(bg_ph[1:])
        state_dict = {'ex':qubit(ex_th, ex_ph), 'bg':qubit(bg_th, bg_ph)}

    prob = [p, 1.0 - p]
    if s is not None:
        np.random.seed(int(s))
    distrib = np.random.choice(['ex','bg'], size=L, p=prob)
    return listkron([state_dict[i] for i in distrib])
Exemple #8
0
def fock(L, config):
    config_dict = make_config_dict(config)
    ex_list = np.array(config_dict['ex_list'])
    qubits = np.array([qubit(**config_dict['bg_config'])]*L)
    for ex in ex_list:
        qubits[ex, ::] = qubit(**config_dict['ex_config'])
    state = listkron(qubits)
    return state
Exemple #9
0
def fock(L, config):
    config_dict = make_config_dict(config)
    ex_list = np.array(config_dict['ex_list'])
    qubits = np.array([qubit(**config_dict['bg_config'])] * L)
    for ex in ex_list:
        qubits[ex, :] = qubit(**config_dict['ex_config'])

    state = listkron(qubits)
    return state
Exemple #10
0
def cluster_all(L, config):
    state = np.zeros(2**L, dtype=np.complex128)
    for k in range(2**L):
        b = dec_to_bin(k, L)
        c = 1.0
        for j in range(L - 1):
            c *= (-1)**(b[j] * b[j + 1])
        state += c * listkron([bvecs[str(bj)] for bj in b])
    return state / 2**(L / 2)
Exemple #11
0
def spin_wave(L, config):
    Tt, Pp = config.split('-')
    ang_dict = {'T' : np.linspace(0.0,  pi*float(Tt[1:]), L),
                't' : [float(Tt[1:])]*L,
                'P' : np.linspace(0.0, 2*pi*float(Pp[1:]), L),
                'p' : [float(Pp[1:])]*L}
    th_list = ang_dict[Tt[0]]
    ph_list = ang_dict[Pp[0]]
    qubit_list = [0.0]*L
    for j, (th, ph) in enumerate(zip(th_list, ph_list)):
        qubit_list[j] = qubit(th, ph)
    return listkron(qubit_list)
Exemple #12
0
def Bell(L, config):
    jk, typ = config.split('_')
    j, k = jk.split('-')
    coeff = 1.0
    if typ in ('1', '3'):
        coeff = -1.0
    if typ in ('2', '3'):
        state = 1/sqrt(2)*(fock(L, j) + coeff*fock(L, k))

    elif typ in ('0', '1'):
        state = 1/sqrt(2)*(listkron([qubit(0.0, 0.0)]*L) + coeff*fock(L, jk))
    return state
Exemple #13
0
def center(L, config):
    Lcent = config.split('_')[0]
    cent_IC = config.split('_')[1:]
    cent_IC = '_'.join(cent_IC)
    len_cent = int(Lcent)
    len_back = L - len_cent
    len_L = int(len_back / 2)
    len_R = len_back - len_L
    if cent_IC[0] == 'f':
        config_dict = make_config_dict(cent_IC[1:])
    else:
        config_dict = make_config_dict('0')
    bg_qubit = qubit(**config_dict['bg_config'])
    left = listkron([bg_qubit for _ in range(len_L)])
    cent = make_state(len_cent, cent_IC)
    right = listkron([bg_qubit for _ in range(len_R)])
    if len_back == 0:
        return cent
    elif len_back == 1:
        return listkron([cent, right])
    return listkron([left, cent, right])
Exemple #14
0
def Bell(L, config):
    jk, typ = config.split('_')
    j, k = jk.split('-')
    coeff = 1.0
    if typ in ('1', '3'):
        coeff = -1.0
    if typ in ('2', '3'):
        state = 1 / sqrt(2) * (fock(L, j) + coeff * fock(L, k))
    else:
        if typ in ('0', '1'):
            state = 1 / sqrt(2) * (listkron([qubit(0.0, 0.0)] * L) +
                                   coeff * fock(L, jk))
    return state
Exemple #15
0
def make_H(L, R, V):
    H = np.zeros((2**L, 2**L), dtype=np.complex128)
    if type(V) is not str:
        ops['V'] = V
        V = 'V'
    bulks = []
    lbs = []
    rbs = []
    for s, b in enumerate(mx.dec_to_bin(R, 4)[::-1]):
        if b:
            r = mx.dec_to_bin(s, 2)
            if r[1] == 0:
                rbs += [str(r[0]) + V]
            if r[0] == 0:
                lbs += [V + str(r[1])]
            bulks += [str(r[0]) + V + str(r[1])]

    #print('rule', R, mx.dec_to_bin(R, 4), lbs, bulks, rbs)
    for i in range(1, L - 1):
        l = i - 1
        r = L - 3 - l
        left = np.eye(2**l)
        right = np.eye(2**r)
        for bulk in bulks:
            bulk = mx.listkron([ops[o] for o in bulk])
            H += mx.listkron([left, bulk, right])

    # boundaries
    end = np.eye(2**(L - 2))
    for rb in rbs:
        rb = mx.listkron([ops[o] for o in rb])
        #H += mx.listkron([end, rb])

    for lb in lbs:
        lb = mx.listkron([ops[o] for o in lb])
        #H += mx.listkron([lb, end])

    assert mx.isherm(H)
    return H
Exemple #16
0
def center(L, config):
    Lcent = config.split('_')[0]
    cent_IC = config.split('_')[1::]
    cent_IC = '_'.join(cent_IC)
    len_cent = int(Lcent)
    len_back = L - len_cent
    len_L = int(len_back/2)
    len_R = len_back - len_L
    if cent_IC[0] == 'f':
        config_dict = make_config_dict(cent_IC[1::])
    else:
        config_dict = make_config_dict('0')
    bg_qubit = qubit(**config_dict['bg_config'])
    left = listkron([bg_qubit for _ in range(len_L)])
    cent = make_state(len_cent, cent_IC)
    right = listkron([bg_qubit for _ in range(len_R)])
    if len_back == 0:
        return cent
    elif len_back == 1:
        return listkron([cent, right])
    else:
        return listkron([left, cent, right])
Exemple #17
0
def rule_element(V, Rel, hood, hamiltonian=False):
    """
    Operator for neighborhood bitstring hood with activation V if Rel=1
    or `option` if Rel=0.
    """
    Vmat = mx.make_U2(V)
    if hamiltonian:
        Vmat = Vmat * Rel
    else:  # unitaty
        Vmat = matrix_power(Vmat, Rel)
    ops = [Vmat] + [mx.ops[str(el)] for el in hood]
    OP = mx.listkron(ops)
    return OP
Exemple #18
0
def make_U(V, r, S):
    N = 2 * r
    Sb = mx.dec_to_bin(S, 2**N)[::-1]
    U = np.zeros((2**(N + 1), 2**(N + 1)), dtype=complex)
    for sig, s in enumerate(Sb):
        sigb = mx.dec_to_bin(sig, N)
        Vmat = get_V(V, s)
        ops = ([mx.ops[str(op)] for op in sigb[0:r]] + [Vmat] +
               [mx.ops[str(op)] for op in sigb[r:2 * r + 1]])
        U += mx.listkron(ops)

    if not mx.isU(U):
        raise AssertionError
    return U
Exemple #19
0
def spin_wave(L, config):
    Tt, Pp = config.split('-')
    ang_dict = {
        'T': np.linspace(0.0, pi * float(Tt[1:]), L),
        't': [float(Tt[1:])] * L,
        'P': np.linspace(0.0, 2 * pi * float(Pp[1:]), L),
        'p': [float(Pp[1:])] * L
    }
    th_list = ang_dict[Tt[0]]
    ph_list = ang_dict[Pp[0]]
    qubit_list = [0.0] * L
    for j, (th, ph) in enumerate(zip(th_list, ph_list)):
        qubit_list[j] = qubit(th, ph)

    return listkron(qubit_list)
Exemple #20
0
def cluster(L, config):
    try:
        mn, ph = config.split("_")
        ph = float(ph) * np.pi / 180
        m, n = map(int, mn.split("-"))
    except:
        ph = 45.0 * np.pi / 180
        m, n = map(int, config.split("-"))
    assert L == m * n
    E = gridedge(m, n)
    Cphase = np.eye(4, dtype=np.complex128)
    Cphase[3, 3] = np.exp(1j * ph)
    # equal superposition for all qubits
    state = listkron([bvecs["es"] for _ in range(m * n)])
    # apply phase gate according to edges of graph
    for e in E:
        state = op_on_state(Cphase, e, state)
    return state
Exemple #21
0
def rule_element(V, Rel, hood, hamiltonian=False, lslice=None, rslice=None):
    """
    Operator for neighborhood hood with activation V if Rel=1
    or `option` if Rel=0.
    """
    N = len(hood)
    r = N // 2
    if hamiltonian:
        option = "O"  # zero matrix
    else:  # unitaty
        option = "I"  # identity matrix
    if lslice is None:
        lslice = slice(0, r)
    if rslice is None:
        rslice = slice(r, N + 1)
    Vmat = matrix_power(mx.make_U2(V), Rel)
    mx.ops["V"] = Vmat
    ops = ([str(el) for el in hood[lslice]] + ["V" if Rel else option] +
           [str(el) for el in hood[rslice]])
    OP = mx.listkron([mx.ops[op] for op in ops])
    return OP
Exemple #22
0
def make_boundary_Us(V, r, S, BC_conf):
    BC_conf = list(map(int, BC_conf))
    N = 2 * r
    Sb = mx.dec_to_bin(S, 2**N)[::-1]
    bUs = []
    for w in (0, 1):
        fixed_o = list(BC_conf[w * r:r + w * r])
        for c in range(r):
            U = np.zeros((2**(r + 1 + c), 2**(r + 1 + c)), dtype=complex)
            for i in range(2**(r + c)):
                if w == 0:
                    var = mx.dec_to_bin(i, r + c)
                    var1 = var[:c]
                    var2 = var[c:]
                    fixed = fixed_o[c:r]
                    n = fixed + var1 + var2
                    s = Sb[mx.bin_to_dec(n)]
                    Vmat = get_V(V, s)
                    ops = ([mx.ops[str(op)] for op in var1] + [Vmat] +
                           [mx.ops[str(op)] for op in var2])

                elif w == 1:
                    var = mx.dec_to_bin(i, r + c)
                    var1 = var[c:]
                    var2 = var[:c]
                    fixed = fixed_o[0:r - c]
                    n = var1 + var2 + fixed
                    s = Sb[mx.bin_to_dec(n)]
                    Vmat = get_V(V, s)
                    ops = ([mx.ops[str(op)] for op in var1] + [Vmat] +
                           [mx.ops[str(op)] for op in var2])
                U += mx.listkron(ops)

            bUs.append(U)

    return bUs
Exemple #23
0
from collections import namedtuple, Iterable, OrderedDict

from numpy import sin, cos, log, pi
import matrix as mx
import states as ss
import processing as pp
import fio as io
import sweep_eca as sweep

init_state = ss.make_state(3, [('E0_1', 1.0)])

r0 = mx.rdms(init_state, [0])
r1 = mx.rdms(init_state, [1])
r2 = mx.rdms(init_state, [2])

state_1 = mx.op_on_state(mx.listkron([ss.pauli['1']] * 2), [0, 2], init_state)
r0_1 = mx.rdms(state_1, [0])
r1_1 = mx.rdms(state_1, [1])
r2_1 = mx.rdms(state_1, [2])

rd = mx.rdms(state_1, [1, 2])


# sx and sz entropies
# -------------------
def sz(th):
    p0 = 0.5 * (1.0 + cos(2.0 * th))
    p1 = 0.5 * (1.0 - cos(2.0 * th))
    return -p0 * log(p0) / log(2.) - p1 * log(p1) / log(2.)

Exemple #24
0
def GHZ(L, config):
    s1 = ['1'] * L
    s2 = ['0'] * L
    state = 1.0 / sqrt(2.0) * (listkron([bvecs[key] for key in s1]) +
                               listkron([bvecs[key] for key in s2]))
    return state