Doing nothing with Qiskit Terra


We are going to use Qiskit to do nothing.


In [ ]:
import qiskit

First we set up an empty program for one qubit.


In [ ]:
qr = qiskit.QuantumRegister(1)
cr = qiskit.ClassicalRegister(1)
program = qiskit.QuantumCircuit(qr, cr)

We don't want to do anything to the qubit, so we'll skip straight to reading it out.


In [ ]:
program.measure(qr,cr)

Now we'll tell the local simulator to execute this entirely trivial program.


In [ ]:
job = qiskit.execute( program, qiskit.Aer.get_backend('qasm_simulator') )

And then print out the result. Since qubits are initialized as 0, and we did nothing to our qubit before readout, we'll just get the result 0 many times.


In [ ]:
print( job.result().get_counts() )

Now let's try it on the least busy real device. This will have a few samples which output 1 due to noise, but most of the samples should be for an output of 0.


In [ ]:
qiskit.IBMQ.load_accounts()
backend = qiskit.backends.ibmq.least_busy(qiskit.IBMQ.backends(simulator=False))
print("We'll use the least busy device:",backend.name())
job = qiskit.execute( program, backend )
print( job.result().get_counts() )

If this all ran successfully, you are now ready to create and execute programs that actually do something!