if __name__ == '__main__': n = 2 f = lambda rep: rep[-1] # f = lambda rep: "1" if rep[0:2] == "01" or rep[0:2] == "10" else "0" # f = lambda rep: "0" prog = make_circuit(n, f) sample_shot =2800 IBMQ.load_account() provider = IBMQ.get_provider(hub='ibm-q') provider.backends() backend = provider.get_backend("ibmq_belem") circuit1 = transpile(prog,FakeVigo()) circuit1.x(qubit=3) circuit1.x(qubit=3) circuit1.measure_all() prog = circuit1 info = execute(prog, backend=backend, shots=sample_shot).result().get_counts() writefile = open("../data/startQiskit_QC92.csv","w") print(info,file=writefile) print("results end", file=writefile) print(circuit1.depth(),file=writefile) print(circuit1,file=writefile) writefile.close()
prog.measure(input_qubit[i], classical[i]) return prog if __name__ == '__main__': a = "111" b = "0" f = lambda rep: bitwise_xor(bitwise_dot(a, rep), b) prog = make_circuit(4, f) IBMQ.load_account() provider = IBMQ.get_provider(hub='ibm-q') provider.backends() backend = least_busy( provider.backends( filters=lambda x: x.configuration().n_qubits >= 2 and not x. configuration().simulator and x.status().operational == True)) sample_shot = 8000 info = execute(prog, backend=backend, shots=sample_shot).result().get_counts() backend = FakeVigo() circuit1 = transpile(prog, backend, optimization_level=2) writefile = open("../data/startQiskit_QC2414.csv", "w") print(info, file=writefile) print("results end", file=writefile) print(circuit1.__len__(), file=writefile) print(circuit1, file=writefile) writefile.close()
if __name__ == "__main__": n = 2 a = "11" b = "1" f = lambda rep: \ bitwise_xor(bitwise_dot(a, rep), b) prog = build_circuit(n, f) sample_shot = 4000 writefile = open("../data/startQiskit_QC195.csv", "w") # prog.draw('mpl', filename=(kernel + '.png')) IBMQ.load_account() provider = IBMQ.get_provider(hub='ibm-q') provider.backends() backend = provider.get_backend("ibmq_belem") circuit1 = transpile(prog, FakeYorktown()) circuit1.h(qubit=2) circuit1.x(qubit=3) circuit1.measure_all() info = execute(circuit1, backend=backend, shots=sample_shot).result().get_counts() print(info, file=writefile) print("results end", file=writefile) print(circuit1.depth(), file=writefile) print(circuit1, file=writefile) writefile.close()
def randomize(qpu_name, num_of_qubits, shots, min_depth_of_circuit, max_depth_of_circuit, num_of_circuits, token): """Create randomized circuits with given properties and jobs to run them on IBM backends.""" sim_name = 'ibmq_qasm_simulator' backend_sim = ibmq_handler.get_qpu(token, sim_name) backend_real = ibmq_handler.get_qpu(token, qpu_name) locations = [] # create the given number of circuits of given width and depth for i in range(min_depth_of_circuit, max_depth_of_circuit + 1): for j in range(num_of_circuits): rowcount = db.session.query(Benchmark).count() benchmark_id = rowcount // 2 # create randomized circuits and transpile them for both backends qx = random_circuit(num_qubits=num_of_qubits, depth=i, measure=True) original_number_of_multi_qubit_gates = qx.num_nonlocal_gates() qcircuit_sim = transpile(qx, backend=backend_sim, optimization_level=3) qcircuit_real = transpile(qx, backend=backend_real, optimization_level=3) # ensure that the width of the circuit is correctly saved in the db remove_final_meas = RemoveFinalMeasurements() active_qubits_real = [ qubit for qubit in qcircuit_real.qubits if qubit not in remove_final_meas.run( circuit_to_dag(qcircuit_real)).idle_wires() ] transpiled_depth_sim = qcircuit_sim.depth() transpiled_width_sim = qcircuit_sim.num_qubits transpiled_number_of_multi_qubit_gates_sim = qcircuit_sim.num_nonlocal_gates( ) transpiled_depth_real = qcircuit_real.depth() transpiled_width_real = len(active_qubits_real) transpiled_number_of_multi_qubit_gates_real = qcircuit_real.num_nonlocal_gates( ) location_sim = run(circuit=qcircuit_sim, backend=sim_name, token=token, shots=shots, benchmark_id=benchmark_id, original_depth=i, original_width=num_of_qubits, original_number_of_multi_qubit_gates= original_number_of_multi_qubit_gates, transpiled_depth=transpiled_depth_sim, transpiled_width=transpiled_width_sim, transpiled_number_of_multi_qubit_gates= transpiled_number_of_multi_qubit_gates_sim) location_real = run(circuit=qcircuit_real, backend=qpu_name, token=token, shots=shots, benchmark_id=benchmark_id, original_depth=i, original_width=num_of_qubits, original_number_of_multi_qubit_gates= original_number_of_multi_qubit_gates, transpiled_depth=transpiled_depth_real, transpiled_width=transpiled_width_real, transpiled_number_of_multi_qubit_gates= transpiled_number_of_multi_qubit_gates_real) location_benchmark = '/qiskit-service/api/v1.0/benchmarks/' + str( benchmark_id) locations.append({ 'result-simulator': str(location_sim), 'result-real-backend': str(location_real), 'result-benchmark': str(location_benchmark) }) return locations
prog.x(input_qubit[0]) # number=19 prog.x(input_qubit[0]) # number=20 # circuit end return prog if __name__ == '__main__': prog = make_circuit(1) backend = BasicAer.get_backend('statevector_simulator') sample_shot = 1974 info = execute(prog, backend=backend).result().get_statevector() qubits = round(log2(len(info))) info = { np.binary_repr(i, qubits): round( (info[i] * (info[i].conjugate())).real, 3) for i in range(2**qubits) } backend = FakeVigo() circuit1 = transpile(prog, backend) writefile = open("../data/startQiskit_Class381.csv", "w") print(info, file=writefile) print("results end", file=writefile) print(circuit1.depth(), file=writefile) print(circuit1, file=writefile) writefile.close()
import matplotlib.pyplot as plt simulator = Aer.get_backend('qasm_simulator') circuit = QuantumCircuit(3, 3) circuit.x(0) circuit.x(1) circuit.x(2) circuit.barrier() circuit.x(0) circuit.cnot(0, 2) circuit.x(0) circuit.barrier() # Map the quantum measurement to the classical bits circuit.measure([0, 1, 2], [2, 1, 0]) compiled_circuit = transpile(circuit, simulator) job = simulator.run(compiled_circuit, shots=1000) result = job.result() counts = result.get_counts(circuit) print(circuit) plot_histogram(counts) plt.show()