%pip install qiskit
%pip install tergite
Hello Tergite
This is a showcase of connecting to tergite via the tergite
SDK and running a basic circuit.
Install dependencies
This example depends on:
Import the basic dependencies
import time
import qiskit.circuit as circuit
import qiskit.compiler as compiler
from tergite.qiskit.providers import Tergite
from tergite.qiskit.providers.provider_account import ProviderAccount
Update Some Variables
# the Tergite API URL e.g. "https://api.tergite.example"
= "https://api.qal9000.se"
API_URL # API token for connecting to tergite
= "<your Tergite API key >"
API_TOKEN # The name of the Quantum Computer to use from the available quantum computers
= "SimulatorC"
BACKEND_NAME # the name of this service. For your own bookkeeping.
= "local"
SERVICE_NAME # the timeout in seconds for how long to keep checking for results
= 100 POLL_TIMEOUT
Create the Qiskit Circuit
= circuit.QuantumCircuit(1)
qc 0)
qc.x(0)
qc.h(
qc.measure_all() qc.draw()
Get the Tergite Backend
# provider account creation can be skipped in case you already saved
# your provider account to the `~/.qiskit/tergiterc` file.
# See below how that is done.
= ProviderAccount(service_name=SERVICE_NAME, url=API_URL, token=API_TOKEN)
account
= Tergite.use_provider_account(account)
provider # to save this account to the `~/.qiskit/tergiterc` file, add the `save=True`
# provider = Tergite.use_provider_account(account, save=True)
# Get the tergite backend in case you skipped provider account creation
# provider = Tergite.get_provider(service_name=SERVICE_NAME)
= provider.get_backend(BACKEND_NAME)
backend =1024)
backend.set_options(shots backend
Compile Circuit
= compiler.transpile(qc, backend=backend)
tc tc.draw()
Run the Circuit
= backend.run(tc, meas_level=2, meas_return="single") job
Tergite: Job has been successfully submitted
See the Results
= 0
elapsed_time = None
result while result is None:
if elapsed_time > POLL_TIMEOUT:
raise TimeoutError(f"result polling timeout {POLL_TIMEOUT} seconds exceeded")
1)
time.sleep(+= 1
elapsed_time = job.result()
result
result.get_counts()
Acknowledgement
This notebook was prepared by: