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:

%pip install qiskit
%pip install tergite

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"
API_URL = "https://api.qal9000.se"
# API token for connecting to tergite
API_TOKEN = "<your Tergite API key >"
# The name of the Quantum Computer to use from the available quantum computers
BACKEND_NAME = "SimulatorC"
# the name of this service. For your own bookkeeping.
SERVICE_NAME = "local"
# the timeout in seconds for how long to keep checking for results
POLL_TIMEOUT = 100

Create the Qiskit Circuit

qc = circuit.QuantumCircuit(1)
qc.x(0)
qc.h(0)
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.
account = ProviderAccount(service_name=SERVICE_NAME, url=API_URL, token=API_TOKEN)

provider = Tergite.use_provider_account(account)
# 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)
backend = provider.get_backend(BACKEND_NAME)
backend.set_options(shots=1024)
backend

Compile Circuit

tc = compiler.transpile(qc, backend=backend)
tc.draw()

Run the Circuit

job = backend.run(tc, meas_level=2, meas_return="single")
Tergite: Job has been successfully submitted

See the Results

elapsed_time = 0
result = None
while result is None:
    if elapsed_time > POLL_TIMEOUT:
        raise TimeoutError(f"result polling timeout {POLL_TIMEOUT} seconds exceeded")

    time.sleep(1)
    elapsed_time += 1
    result = job.result()

result.get_counts()

Acknowledgement

This notebook was prepared by:

Back to top