Exemplo n.º 1
0
 def __init__(self, maxiter, shots):
     self.qx = qxelarator.QX()
     self.minimizer = minimize
     self.minimizer_kwargs = {'method':'Nelder-Mead', 'options':{'maxiter':maxiter, 
                              'ftol':1.0e-6, 'xtol':1.0e-6, 'disp':True, 'return_all':True}}
     self.p_name = "test_output/qaoa_run.qasm"
     self.shots = shots 
     self.expt = 0    
Exemplo n.º 2
0
def test_02():
    p_name = "test_output/multi_run_02.qasm"  # Works with/without kernel encapsulation
    qx = qxelarator.QX()
    for p_loop in range(0, 6):
        qx.set(p_name)
        # qx.execute(1) # Doesn't work with get_state()
        qx.execute()
        isv = qx.get_state()
        print(isv)
Exemplo n.º 3
0
 def __init__(self, maxiter):
     
     self.qx = qxelarator.QX()
     self.minimizer = minimize
     self.minimizer_kwargs = {'method':'Nelder-Mead', 'options':{'maxiter':maxiter, 
                              'ftol':1.0e-6, 'xtol':1.0e-6, 'disp':True, 'return_all':True}}
     # self.minimizer_kwargs = {'method':'Powell', 'options':{'maxiter':maxiter, 
     #                          'ftol':1.0e-6, 'xtol':1.0e-6, 'disp':True}}
     self.p_name = my_file = os.path.join(THIS_FOLDER, "test_output/qaoa_run.qasm") 
     self.expt = 0    
     self.probs = []
     self.optstep = 0
Exemplo n.º 4
0
def t_trial():

    qx = qxelarator.QX()
    qx.set('test_output/tomo.qasm')
    p = np.zeros(2**NUM_QUBIT)
    c = np.zeros(NUM_QUBIT, dtype=bool)
    for i in range(NUM_TRIAL):
        qx.execute()
        for i in range(NUM_QUBIT):
            c[i] = qx.get_measurement_outcome(i)
        idx = sum(v << i for i, v in enumerate(c[::-1]))
        p[idx] += 1 / NUM_TRIAL
    return p
Exemplo n.º 5
0
def test_03():
    p_name = "test_output/multi_run_02.qasm"  # Works with/without kernel encapsulation
    n_qubits = 3

    ptrn = re.compile('\(([+-]\d+.*\d*),([+-]\d+.*\d*)\)\s[|]([0-1]*)>')

    qx = qxelarator.QX()
    isv_p = []
    for p_loop in range(0, 2):
        isv_p = np.zeros(2**n_qubits)
        qx.set(p_name)
        # qx.execute(1) # Doesn't work with get_state()
        qx.execute()
        isv = re.findall(ptrn, qx.get_state())
        for basis in iter(isv):
            isv_p[int(basis[2], 2)] = float(basis[0])**2 + float(
                basis[1]
            )**2  # Probability is square of modulus of complex amplitude
        print(isv_p)
Exemplo n.º 6
0
def test_01():
    p_name = "test_output/multi_run.qasm"
    n_qubits = 3
    shots = 400

    qx = qxelarator.QX()
    for p_loop in range(0, 40):
        # qx = qxelarator.QX()	# Inside loop cause problems
        qx.set(p_name)
        p = np.zeros(2**n_qubits)
        c = np.zeros(n_qubits, dtype=bool)
        for i in range(shots):
            print(p_loop, i)
            # qx.execute(1)
            qx.execute()  # Both works for p_loop 40 x shots 400
            for i in range(n_qubits):
                c[i] = qx.get_measurement_outcome(i)
            idx = sum(v << i for i, v in enumerate(c[::-1]))
            p[idx] += 1 / shots

    print(p)