コード例 #1
0
def GHZ(L, congif):
    s1 = ['1'] * (L)
    s2 = ['0'] * (L)
    state = (1.0/sqrt(2.0)) \
            * (mx.listkron([bvecs[key] for key in s1]) \
                + mx.listkron([bvecs[key] for key in s2]))

    return state
コード例 #2
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 = mx.listkron(qubits)
    return state
コード例 #3
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 = mx.listkron([bg_qubit for _ in range(len_L)])
    cent = make_state(len_cent, cent_IC)
    right = mx.listkron([bg_qubit for _ in range(len_R)])
    if len_back == 0:
        return cent
    elif len_back == 1:
        return mx.listkron([cent, right])
    else:
        return mx.listkron([left, cent, right])
コード例 #4
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) * (mx.listkron([qubit(0.0, 0.0)] * L) +
                               coeff * fock(L, jk))
    return state
コード例 #5
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 mx.listkron(qubit_list)
コード例 #6
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 mx.listkron([state_dict[i] for i in distrib])