def test_get_execution_list_noname(self): """Test get_execution_list for circuits without name. """ q_program = QuantumProgram(specs=self.qps_specs_nonames) qc = q_program.get_circuit() qr = q_program.get_quantum_register() cr = q_program.get_classical_register() qc.h(qr[0]) qc.cx(qr[0], qr[1]) qc.measure(qr[0], cr[0]) qc.measure(qr[1], cr[1]) qobj = q_program.compile() result = q_program.get_execution_list(qobj, print_func=self.log.info) self.assertEqual(len(result), 1)
def test_get_execution_list_noname(self): """Test get_execution_list for circuits without name. """ q_program = QuantumProgram(specs=self.QPS_SPECS_NONAMES) qc = q_program.get_circuit() qr = q_program.get_quantum_register() cr = q_program.get_classical_register() qc.h(qr[0]) qc.cx(qr[0], qr[1]) qc.measure(qr[0], cr[0]) qc.measure(qr[1], cr[1]) qobj = q_program.compile() result = q_program.get_execution_list(qobj, print_func=self.log.info) self.assertEqual(len(result), 1)
def test_get_execution_list(self): """Test get_execution_list. If all correct should return {'local_qasm_simulator': ['circuitName']}. """ 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, qobjid="cooljob") result = QP_program.get_execution_list(qobj) # print(result) self.assertEqual(result, ['circuitName'])
def test_get_execution_list(self): """Test get_execution_list. If all correct should return {'local_qasm_simulator': ['circuitName']}. """ 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, qobjid="cooljob") result = QP_program.get_execution_list(qobj) # print(result) self.assertEqual(result, ['circuitName'])
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'))