def test_get_compiled_configuration(self): """Test compiled_configuration. If all correct should return lenght 6 dictionary. """ QP_program = QuantumProgram(specs=QPS_SPECS) qc = QP_program.get_circuit("circuitName") qr = QP_program.get_quantum_register("qname") cr = QP_program.get_classical_register("cname") qc.h(qr[0]) qc.cx(qr[0], qr[1]) qc.measure(qr[0], cr[0]) qc.measure(qr[1], cr[1]) backend = 'local_qasm_simulator' coupling_map = None qobj = QP_program.compile(['circuitName'], backend=backend, coupling_map=coupling_map) result = QP_program.get_compiled_configuration(qobj, 'circuitName') # print(result) self.assertEqual(len(result), 4)
def test_get_compiled_configuration(self): """Test compiled_configuration. If all correct should return lenght 6 dictionary. """ QP_program = QuantumProgram(specs=QPS_SPECS) qc = QP_program.get_circuit("circuitName") qr = QP_program.get_quantum_register("qname") cr = QP_program.get_classical_register("cname") qc.h(qr[0]) qc.cx(qr[0], qr[1]) qc.measure(qr[0], cr[0]) qc.measure(qr[1], cr[1]) backend = 'local_qasm_simulator' coupling_map = None qobj = QP_program.compile(['circuitName'], backend=backend, coupling_map=coupling_map) result = QP_program.get_compiled_configuration(qobj, 'circuitName') # print(result) self.assertEqual(len(result), 4)
("qr", 0): ("q", 0), ("qr", 1): ("q", 1), ("qr", 2): ("q", 2) } initial_layout_2 = { ("qr2", 0): ("q", 0), ("qr2", 1): ("q", 1), ("qr2", 2): ("q", 2) } coupling_map = [[1, 0], [2, 0], [2, 1], [3, 2], [3, 4], [4, 2]] #Compile the circuit to ibmqx4 to test #FTSWAP_comp = Q_program.compile(['FTSWAP'],coupling_map=coupling_map ,initial_layout=initial_layout_1) FTSWAP_comp = Q_program.compile(['FTSWAP'], backend=backendreal) print(Q_program.get_compiled_qasm(FTSWAP_comp, 'FTSWAP')) print(Q_program.get_compiled_configuration(FTSWAP_comp, 'FTSWAP')) #Compile non compiled version of circuit to ibmqx4 to test #FTSWAPnoncomp_comp = Q_program.compile(['FTSWAPnoncomp'],coupling_map=coupling_map ,initial_layout=initial_layout_2) FTSWAPnoncomp_comp = Q_program.compile(['FTSWAPnoncomp'], backend=backendreal) print(Q_program.get_compiled_qasm(FTSWAPnoncomp_comp, 'FTSWAPnoncomp')) print(Q_program.get_compiled_configuration(FTSWAPnoncomp_comp, 'FTSWAPnoncomp')) ################################################################################ # Create tomo set and tomo circuits; put them in the quantum program tomo_set = tomo.process_tomography_set([1, 0], 'Pauli', 'Pauli') tomo_circuits = tomo.create_tomography_circuits(Q_program, 'FTSWAP', q, c, tomo_set) # Execute the tomo circuits
def Grover(): if sys.version_info < (3, 5): raise Exception('Please use Python version 3.5 or greater.') #Create an object qp = QuantumProgram() backend = 'local_qasm_simulator' # backend = 'ibmqx4' max_credits = 15 QX_TOKEN = "ee6100e19629678494bd4c9f4f0f3dc3038fe389b08eee456b8a8be280e08884f6b6228825afa60dda60bf7ee5995ce9e5ae6473f31137a0e94780669bce9707" QX_URL = "https://quantumexperience.ng.bluemix.net/api" # Set up the API and execute the program. # qp.set_api(QX_TOKEN, QX_URL) # quantum register for the circuit(3->5) q1 = qp.create_quantum_register('q1', 5) c1 = qp.create_classical_register('c1', 5) # making the circuit qc1 = qp.create_circuit('Grover', [q1], [c1]) # line one qc1.x(q1[0]) # line two qc1.h(q1[0]) qc1.h(q1[1]) qc1.h(q1[2]) # line three qc1.x(q1[0]) qc1.x(q1[1]) # line four qc1.ccx(q1[2], q1[1], q1[0]) qc1.x(q1[2]) # qc1.x(q1[1]) # line five qc1.h(q1[2]) qc1.h(q1[1]) # line six qc1.x(q1[2]) qc1.x(q1[1]) # line seven qc1.h(q1[1]) # line eight qc1.cx(q1[2], q1[1]) # line nine qc1.h(q1[1]) # line ten qc1.x(q1[2]) qc1.x(q1[1]) # line eleven qc1.h(q1[0]) qc1.h(q1[1]) qc1.h(q1[2]) # Measure for i in range(5): qc1.measure(q1[i], c1[i]) # printing the circuits print(qp.get_qasm('Grover')) qobj = qp.compile('Grover', backend=backend, shots=1000, max_credits=15) qp.get_execution_list(qobj) qp.get_execution_list(qobj, verbose=True) qp.get_compiled_configuration(qobj, 'Grover') #new result = qp.execute('Grover', backend=backend, shots=1000, max_credits=15) #print result: print(qp.get_compiled_qasm(qobj, 'Grover')) #print info: #print(api.backend_status(backend)) #print(api.backend_parameters(backend)) #new # print(result) # print(result.get_data("Grover")) #Record information in text.txt(Create text.txt file in your repository) res = result.get_data("Grover") quasm = qp.get_qasm('Grover') b = ascii(res) c = ascii(quasm) with open('Fourth(111).txt', 'w') as ouf: ouf.write('\n' + b)
# quantum register for the first circuit q_register1 = program.create_quantum_register('q_register1', 4) c_register1 = program.create_classical_register('c_register1', 4) # quantum register for the second circuit q_register2 = program.create_quantum_register('q_register2', 4) c_register2 = program.create_classical_register('c_register2', 4) # making the first circuits circuit1 = program.create_circuit('GHZ', [q_register1], [c_register1]) circuit2 = program.create_circuit('superpostion', [q_register2], [c_register2]) circuit1.h(q_register1[0]) circuit1.cx(q_register1[0], q_register1[1]) circuit1.cx(q_register1[1], q_register1[2]) circuit1.cx(q_register1[2], q_register1[3]) for i in range(4): circuit1.measure(q_register1[i], c_register1[i]) # making the second circuits circuit2.h(q_register2) for i in range(2): circuit2.measure(q_register2[i], c_register2[i]) # printing the circuits print(program.get_qasm('GHZ')) print(program.get_qasm('superpostion')) object = program.compile(['GHZ','superpostion'], backend='local_qasm_simulator') program.get_execution_list(object, verbose=True) print(program.get_compiled_configuration(object, 'GHZ')) print(program.get_compiled_qasm(object, 'GHZ'))