Esempio n. 1
0
def _up_down():
    # to generate up and down state
    up = np.zeros((2, 1))
    up[0, 0] = 1.0
    down = np.zeros((2, 1))
    down[1, 0] = 1.0
    return qx(up), qx(down)
Esempio n. 2
0
def dicke(n, e):
    """ to generate Dicke state
    Parameters
    ----------
    n: number of qubits
    e: excited qubits

    Return: dicke state

    """
    dim = 2**n
    comb_array = _place_ones(n, e)
    #array of possible values of qubits
    row, col = comb_array.shape
    temp_sum = np.zeros((dim, 1))

    for i in range(row):
        temp_vec = _upside_down(comb_array[i, 0])
        for j in range(1, col):
            temp_vec0 = kron(temp_vec, _upside_down(comb_array[i, j]))
            temp_vec = temp_vec0
        temp_sum += temp_vec

    dicke = temp_sum / (np.sqrt(row))
    return qx(dicke)
Esempio n. 3
0
def zbasis(j, m):
    """to generate Zeeman basis |j,m> of Sz spin operator
    ie., Sz|j,m> = j|j,m>
    Parameters
    -----------
    j: real number
    m: integer number
    """
    return qx(obasis(int(2 * j + 1), int(j - m)))
Esempio n. 4
0
def squeezed(d, alpha, beta):
    """ to generate squeezed state
    Parameters
    ----------
    alpha: complex number
    d: number of dimensions
    """
    ground = obasis(d, 0)
    squeezed = dotx(displacement(d, alpha), squeezing(d, beta), ground)
    squeezed = normx(squeezed)
    return qx(squeezed)
Esempio n. 5
0
def coherent(d, alpha):
    """ to generate coherent state
    Parameters
    ----------
    alpha: complex number
    d: number of dimensions
    """
    ground = obasis(d, 0)
    coherent = dotx(displacement(d, alpha), ground)
    coherent = normx(coherent)
    return qx(coherent)
Esempio n. 6
0
def position(d, x):
    """ to generate position state
    ie., X|x> = x|x>
    Parameters
    -----------
    x: position coordinate, real number
    d: number of dimensions
    """
    ground = obasis(d, 0)
    power = -0.5 * dotx(raising(d),raising(d)) + \
            sqrt(2) * x * raising(d)
    exponential = expx(power)
    position = exp(-x**2 / 2) / (pi**(1. / 4)) * dotx(exponential, ground)
    position = normx(position)
    return qx(position)
Esempio n. 7
0
def add_white_noise(state, p=0.0):
    """ add white noise to quantum state
    Parameters:
    ----------
    state: quantum state
    p: error
    
    Return
    ------
    (1-p)*state + p*I/d
    """
    if typex(state) != 'oper':
        state = operx(state)
    dim = state.shape[0]
    return qx((1 - p) * state + p * eyex(dim) / dim)
Esempio n. 8
0
def obasis(d, e=0):
    """ to generate an orthogonal basis of d dimension at e
    For example:
    base(2,0) = [[1]
                 [0]
                 [0]]
    """
    if (not isinstance(d, int)) or d < 0:
        raise ValueError("d must be integer d >= 0")
    if (not isinstance(e, int)) or e < 0:
        raise ValueError("e must be interger e>= 0")
    if e > d - 1:
        raise ValueError("basis vector index need to be in d-1")
    ba = np.zeros((d, 1))  #column vector
    ba[e, 0] = 1.0
    return qx(ba)
Esempio n. 9
0
def ghz(n):
    """ to generate GHZ state
    Parameters
    ----------
    n: number of qubits

    Return: GHZ state, 
    ie. (|00...0> + |11...1>)/sqrt(2)

    """
    dim = 2**n
    up, down = _up_down()
    ups, upd = up, down
    for i in range(n - 1):
        ups = kron(ups, up)
        upd = kron(upd, down)
    GHZ = (ups + upd) / sqrt(2.0)
    return qx(GHZ)
Esempio n. 10
0
def random(d):
    """ to generate a random state
    Parameters:
    ----------
    d: dimension

    Return: random state

    """
    rpsi = np.zeros((d, 1))
    ipsi = np.zeros((d, 1))
    for i in range(d):
        rpsi[i, 0] = randunit()
        ipsi[i, 0] = randunit()
    ppsi = rpsi + 1j * ipsi
    ppsi = normx(ppsi)
    M = haar(d)
    prime = dotx((eyex(d) + M), ppsi)
    prime = normx(prime)
    return qx(prime)
Esempio n. 11
0
def get_post_state(dim, m=0.0, st=0.01):
    """
   to generate a post-selected state
   >>> |c0> = 1/√N ∑(1+detal_m)|m>,
   which was used for both pure and mixed states.

   Parameters:
   -----------
   dim : dimension
   detal_m : normal Distribusion 
   st: standard deviation (default 0.01)
   N: normalization factor

   -----------
   Return quantum object |c0>
   qtype = 'bra'
   isnorm = 'true'
   """
    post_state = 1 + randnormal(m, st, dim)
    post_state /= np.linalg.norm(post_state)
    return qx(post_state)
Esempio n. 12
0
def add_random_noise(psi, m=0.0, st=0.0):
    """ to generate 1 perturbed random state from psi
    Parameters:
    ----------
    d: dims
    m: mean
    st: standard derivative
    """
    if isqx(psi):
        dim = psi.shape[0]
        per = [randnormal(m, st, dim) + 1j * randnormal(m, st, dim)]
        if typex(psi) == 'ket':
            per = daggx(per)  #to get ket
        elif typex(psi) == 'oper':
            per = dotx(daggx(per), per)

        psi = psi + per
        psi = normx(psi)
        return qx(psi)
    else:
        msg = 'psi is not a quantum object'
        raise TypeError(msg)