3
$\begingroup$

Apologies for what I feel is a very simple question, So I've figured out how to work with simulating a quantum circuit in Qiskit, but now I'm trying to figure out how I would actually send the code to the queue for a quantum computer.

Say I have the following simple code.

from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit, Aer, execute
from numpy import pi

qreg_q = QuantumRegister(1, 'q')
creg_c = ClassicalRegister(1, 'c')
circuit = QuantumCircuit(qreg_q, creg_c)

circuit.h(qreg_q[0])
circuit.measure(qreg_q[0], creg_c[0])
backend = Aer.get_backend('qasm_simulator')
job = execute(circuit, Aer.get_backend('qasm_simulator'), shots=20000, memory=True)
output=[]
result_list=job.result().get_memory()
for entry in result_list:
    output.append(int(entry))
print(output)

What do I need to change about the code and/or what would I need to do to actually run this on a quantum computer.

$\endgroup$

1 Answer 1

3
$\begingroup$

1. Load your account and select provider

The Qiskit IBMQ account object is the local reference for accessing your IBM Quantum account, and all of the providers, backends, etc., that are available to you.

The IBM Quantum account has functions for handling administrative tasks. The credentials can be saved to disk, or used in a session and never saved.

from qiskit import IBMQ

# IBMQ.save_account(TOKEN)
IBMQ.load_account() # Load account from disk
IBMQ.providers()    # List all available providers

where we have assumed that the user has stored their IBM Quantum account information locally ahead of time using IBMQ.save_account(TOKEN). TOKEN here is the API token you obtain from your IBM Quantum account.

To access a given provider one should use the get_provider() method of the IBMQ account, filtering by hub, group, or project:

IBMQ.get_provider(hub='ibm-q')
IBMQ.get_provider(group='open')

Calling IBMQ.load_account() or IBMQ.enable_account() will return the default public provider instance <AccountProvider for IBMQ(hub='ibm-q', group='open', project='main')>.

2. Choose backend and send job

All providers inherit from qiskit.providers.BaseProvider and implement the methods backends() (returns all backend objects known to the provider) and get_backend(NAME) (returns the named backend).

Using the public provider instance from above:

provider = IBMQ.get_provider(hub='ibm-q')
provider.backends()

Selecting a backend is done by name using the get_backend(NAME) method:

backend = provider.get_backend('ibmq_vigo')
backend

Then all you need to do is substitute the Aer simulator with this backend in your code and your job will be run on an actual quantum computer!

Source: Access systems with your account

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.