from qiskit import QuantumCircuit from qiskit.circuit import QuantumRegister, ClassicalRegister, AncillaRegister import math # Create a quantum register object of size 2 qs = QuantumRegister(2) # Create a classical register of size 2 cs = ClassicalRegister(2) # Create an empty quantum circuit object based on a given # quantum register and a classical bit register. qc = QuantumCircuit(qs, cs) # Name the qubits of the register as a and b. (a, b) = (qs[0], qs[1]) qc.h(a) qc.cx(a, b) print(qc) # Note that to run it on the machine, we will # need to either specify classical register to store # the measurement reuslt, or use the following measure_all method. # qc.measure_all() qc.measure(a, cs[0]) qc.measure(b, cs[1]) print(qc) ########################################### # If we want to run it on IBM's simulator, # we can use the following. from qiskit_ibm_runtime import QiskitRuntimeService, Sampler service = QiskitRuntimeService() backend = service.get_backend("simulator_mps") bell = backend.run(qc) bell_result = bell.result() print(bell_result.get_counts()) # If you want to run it on the actual # quantum computer, you can use the following. # Note that there is a significant wait time for the job, # so I would use it only when it is absolutely necessary. # Moreover, I would make sure test your circuits with simulator # a few times before doing this. ''' from qiskit_ibm_provider import IBMProvider provider = IBMProvider() backend = provider.get_backend("ibm_brisbane") # Note: we have to traspile the code to the selected # backend in order to run "dynamic lifting" on hardware. from qiskit import transpile qc_transpiled = transpile(qc, backend) job = backend.run(qc_transpiled, dynamic=True) job_result = job.result() # retrieve the bitstring counts bit_counts = job_result.get_counts() # Note that to interpret the result, IBM's bit convention is # "little endian", i.e., the first bit in the # register will be printed at the right most position. print(f"Counts: {bit_counts}") '''