%pip install qiskit
%pip install tergiteHello 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 qiskit.circuit as circuit
import qiskit.compiler as compiler
from qiskit.visualization import plot_histogram
from tergite import Job, TergiteUpdate Some Variables
# the Tergite API URL e.g. "https://qpu.wacqt.se/"
API_URL = "https://api.qpu.wacqt.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 = "wacqt-25"
# 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 = 600Create the Qiskit Circuit
qc = circuit.QuantumCircuit(5, 5)
qc.h(0)
qc.cx(0, 1)
qc.cx(1, 2)
qc.cx(2, 3)
qc.cx(3, 4)
qc.measure(0, 0)
qc.measure(1, 1)
qc.measure(2, 2)
qc.measure(3, 3)
qc.measure(4, 4)
qc.draw()Get the Tergite Backend
# create a provider
# 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.
provider = Tergite.use_provider_account(service_name=SERVICE_NAME, url=API_URL, token=API_TOKEN)
# to save this account to the `~/.qiskit/tergiterc` file, add the `save=True`
# provider = Tergite.use_provider_account(service_name=SERVICE_NAME, url=API_URL, token=API_TOKEN, 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)
backendCompile Circuit
tc = compiler.transpile(qc, backend=backend, optimization_level=0)
tc.draw()Compile Circuit
schedules = compiler.schedule(tc, backend=backend)
schedules.draw()Run the Circuit
job: Job = backend.run([schedules], meas_level=2, meas_return="single")
job.wait_for_final_state(timeout=POLL_TIMEOUT)Tergite: Job has been successfully submitted
See the Results
result = job.result()
counts = result.get_counts()
countsPlot histogram
hist1 = plot_histogram(counts)
hist1Acknowledgement
This notebook was prepared by: