Ejemplo n.º 1
0
def state_tomography(qc, qubit_list):
    """
    A function for the state tomography for the given circuit 
    which the qubit_list are the qubits for the main system
    
    Parameters
        qc[QuantumCircuit]: a quantum circuit
          qubit_list[list]: a list of qubits in the system
          
    """

    qc_tomo = state_tomography_circuits(qc, qubit_list)
    job = execute(qc_tomo, Aer.get_backend('qasm_simulator'), shots=10000)
    result = job.result()
    state_tomo = StateTomographyFitter(result, qc_tomo)
    state_tomo_fit = state_tomo.fit()
    return state_tomo_fit
Ejemplo n.º 2
0
    def _state_tomography(self):
        """The state tomography.

        The HHL result gets extracted via state tomography. Available for
        qasm simulator and real hardware backends.
        """

        # Preparing the state tomography circuits
        tomo_circuits = state_tomography_circuits(self._circuit,
                                                  self._io_register)
        tomo_circuits_noanc = deepcopy(tomo_circuits)
        ca = ClassicalRegister(1)
        for circ in tomo_circuits:
            circ.add_register(ca)
            circ.measure(self._reciprocal._anc, ca[0])

        # Extracting the probability of successful run
        results = self._quantum_instance.execute(tomo_circuits)
        probs = []
        for circ in tomo_circuits:
            counts = results.get_counts(circ)
            s, f = 0, 0
            for k, v in counts.items():
                if k[0] == "1":
                    s += v
                else:
                    f += v
            probs.append(s/(f+s))
        probs = self._resize_vector(probs)
        self._ret["probability_result"] = np.real(probs)

        # Filtering the tomo data for valid results with ancillary measured
        # to 1, i.e. c1==1
        results_noanc = self._tomo_postselect(results)
        tomo_data = StateTomographyFitter(results_noanc, tomo_circuits_noanc)
        rho_fit = tomo_data.fit()
        vec = np.sqrt(np.diag(rho_fit))
        self._hhl_results(vec)
Ejemplo n.º 3
0
def createQC2(r):
    #parameter setting lis
    paraLis16 = [0.196, 0.379, 0.981, 0.589, 1.178, 16]
    paraLis8 = [1.963, 1.115, 1.963, 2.615, 1.178, 8]
    paraLis4 = [-0.785, 1.017, 3.927, 2.517, 2.356, 4]
    paraLis2 = [-9.014 * 10**(-9), -0.75, 1.571, 0.75, -1.571, 2]
    paraLis = [paraLis16, paraLis8, paraLis4, paraLis2]
    #Register and circuit
    s = QuantumRegister(1, name='s')
    j = QuantumRegister(4, name='j')
    q = QuantumRegister(2, name='q')
    #cr = ClassicalRegister(1,name='cr')
    #crtmp= ClassicalRegister(2,name='crtmp')
    qc = QuantumCircuit(s, j, q)
    #Gate preparation
    qft = QFT(4, inverse=False)
    iqft = QFT(4, inverse=True)
    gateLis = []
    gateinvLis = []
    for i in range(4):
        toPut = Agate(paraLis[i]).control()
        gateLis.append(toPut)
    qc.h(j)
    qc.h(q)
    for i in range(4):
        gate = gateLis[i]
        qc.append(gate, qargs=[j[i]] + q[:])
    qc.append(iqft, qargs=j[:])
    #qc.swap(j[1],j[3])
    for i in range(4):
        angle = 2**(3 - i) * np.pi
        angle *= 2**(-r + 1)
        qc.cry(angle, j[i], s[0])
    qc.append(qft, qargs=j[:])

    for i in range(4):
        gate = gateLis[3 - i].inverse()
        qc.append(gate, qargs=[j[3 - i]] + q[:])
    qc.barrier()
    qc.h(j)

    #qc.measure(s,cr)
    qc.barrier()
    print(qc)
    tomo_circuits = state_tomography_circuits(qc, q)
    tomo_circuits_noanc = deepcopy(tomo_circuits)
    to_put = ClassicalRegister(1)
    for i in tomo_circuits:
        i.add_register(to_put)
        i.measure(s, to_put[0])
        print(i)

    backend = Aer.get_backend('qasm_simulator')
    results = execute(tomo_circuits, backend, shots=10**5).result()
    print(results.get_counts())
    probs = []
    for circ in tomo_circuits:
        counts = results.get_counts(circ)
        s, f = 0, 0
        for k, v in counts.items():
            if k[0] == "1":
                s += v
            else:
                f += v
        probs.append(s / (f + s))
    #results_noanc = tomo_postselect(results)
    data = StateTomographyFitter(results, tomo_circuits)
    print(data)
    #omo_data = StateTomographyFitter(results_noanc,tomo_circuits_noanc)
    rho_fit = data.fit()
    print(rho_fit)
    '''
Ejemplo n.º 4
0
# exec state tomography experiments
job = execute(tomo_circuits, backend = backend_qasm, shots = 8192)


# In[10]:


job.status()


# In[51]:


# get rho(density matrix) from tomography data
tomo_data = StateTomographyFitter(job.result(), tomo_circuits)
rho = tomo_data.fit()
psi = get_psi(rho)
new_params = optimize.fmin(diff(psi), params) # minimize 1 - |<Psi|RY(theta1,..,theta4)>|^2
print("new params",new_params)
new_params


# In[59]:


new_Hamiltonian = eval_H(psi, h_matrix)
print("new_Hamiltonian",new_Hamiltonian)


# In[58]: