Beispiel #1
0
def get_bisection(state, prob, dim):
    # to calculate bisection

    if typex(state) == 'oper':
        rs = np.zeros((5, dim, dim))
        for i in range(5):
            for j in range(dim):
                for k in range(dim):
                    rs[i, j, k] = randunit() / prob[i, j, k]
    else:
        rs = np.zeros((5, dim))
        for i in range(5):
            for j in range(dim):
                rs[i, j] = randunit() / prob[i, j]
    return rs
Beispiel #2
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)
Beispiel #3
0
 def get_qmeas_simul(self):
     res = []
     for i in range(len(self.qmeas)):
         if self.backend == 'mc':
             res.append(mc(np.real(self.qmeas[i]), self.niter))
         elif self.backend == 'cdf':
             temp = []
             for j in range(self.niter):
                 temp.append(randunit() / np.real(self.qmeas[i]))
             res.append(cdf(temp))
         else:
             raise TypeError('no ', backend)
     return res