Example #1
0
def center(L, config):
    len_cent = int(config[0])
    len_back = L - len_cent
    len_L = int(len_back / 2)
    len_R = len_back - len_L
    cent_IC = [(config[1:], 1.0)]
    left = fock(len_L, 0)
    cent = make_state(len_cent, cent_IC)
    right = fock(len_R, 0)
    if len_back == 0:
        return cent
    elif len_back == 1:
        return mx.listkron([cent, right])
    else:
        return mx.listkron([left, cent, right])
Example #2
0
def fock(L, config, zero='0', one='1'):
    dec = int(config)
    state = [
        el.replace('0', zero).replace('1', one)
        for el in list('{0:0b}'.format(dec).rjust(L, '0'))
    ]
    return mx.listkron([bvecs[key] for key in state])
Example #3
0
def qubits(L, config):
    Tt, Pp = config.split('_')
    ang_dict = {
        'T': np.linspace(0.0, pi * float(Tt[1:]), L),
        't': [float(Tt[1:]) * pi / 180.0] * L,
        'P': np.linspace(0.0, 2 * pi * float(Pp[1:]), L),
        'p': [float(Pp[1:]) * pi / 180.0] * 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)
Example #4
0
def rand_state(L, config):
    # default background state (DOWN state)
    bg = np.array([0, 1], dtype=complex)
    # default state to be distribute among the background
    state = np.array([1, 0], dtype=complex)
    # get the probability specified in config
    state_prob = eval('.' + config)
    # array to hold the probabilities of state and bg
    prob = [state_prob, 1 - state_prob]
    # get random distribution of states based on prob
    states = [state, bg]
    distrib = np.random.choice([0, 1], size=L, p=prob)

    # kronecker the states in the distribution and return
    return mx.listkron([states[i] for i in distrib])
Example #5
0
def ghz(L, congif):
    s1 = ['1'] * (L)
    s2 = ['0'] * (L)
    return (1.0/sqrt(2.0)) \
            * ((mx.listkron([bvecs[key] for key in s1]) \
                + mx.listkron([bvecs[key] for key in s2])))