pytket-qiskit¶
IBM’s Qiskit is an open-source framework for quantum computation, ranging from high-level algorithms to low-level circuit representations, simulation and access to the IBM quantum devices and simulators.
pytket-qiskit is an extension to pytket that allows pytket circuits to be
run on IBM backends and simulators, as well as conversion to and from Qiskit
representations.
pytket-qiskit is available for Python 3.10, 3.11, 3.12 and 3.13, on Linux,
MacOS and Windows. To install, run:
pip install pytket-qiskit
This will install pytket if it isn’t already installed, and add new classes
and methods into the pytket.extensions namespace.
Available IBM Backends¶
A backend for running circuits on remote IBMQ devices. |
|
A backend which uses the AerBackend to locally emulate the behaviour of |
|
Backend for running simulations on the Qiskit Aer QASM simulator. |
|
Backend for running simulations on the Qiskit Aer Statevector simulator. |
|
Backend for running simulations on the Qiskit Aer Unitary simulator. |
|
Backend for running simulations on the Qiskit Aer density matrix simulator. |
An example using the shots-based AerBackend simulator is shown below.
from pytket.extensions.qiskit import AerBackend
from pytket import Circuit
backend = AerBackend()
circ = Circuit(2).H(0).CX(0, 1).measure_all()
# Compilation not needed here as both H and CX are supported gates
result = backend.run_circuit(circ, n_shots=1000)
This simulator supports a large set of gates and by default has no architectural constraints or quantum noise. However the user can pass in a noise model or custom architecture to more closely model a real quantum device.
The AerBackend also supports GPU simulation which can be configured as follows.
from pytket.extensions.qiskit import AerBackend
backend = AerBackend()
backend._qiskit_backend.set_option("device", "GPU")
Note
Making use of GPU simulation requires the qiskit-aer-gpu package. This can be installed with the command
pip install qiskit-aer-gpu
Access and Credentials¶
With the exception of the Aer simulators, accessing devices and simulators through the pytket-qiskit extension requires an IBM account. An account can be set up here: https://cloud.ibm.com/.
Once you have created an account you can obtain an API token which you can use to configure your credentials locally.
In this section we are assuming that you have set the following variables with the corresponding values:
# Replace the placeholders with your actual values
ibm_token = '<your_ibm_token_here>'
inst = '<your_instance_CRN_here>'
The instance CRN is the long string beginning with “crn:” which is shown on the “Instances” page for your account.
Method 1: Using QiskitRuntimeService¶
You can use the following qiskit commands to save your IBM credentials to disk:
from qiskit_ibm_runtime import QiskitRuntimeService
QiskitRuntimeService.save_account(channel="ibm_quantum_platform", token=ibm_token, instance=inst)
To see which devices you can access, use the available_devices() method. Note that it is possible to pass an optional instance argument to this method. This allows you to see which IBM devices are accessible with your credentials.
from pytket.extensions.qiskit import IBMQBackend
backend = IBMQBackend("ibm_kyiv") # Initialise backend for an IBM device
backendinfo_list = backend.available_devices(instance=inst)
print([backend.device_name for backend in backendinfo_list])
For more information, see the documentation for qiskit-ibm-runtime.
Method 2: Saving credentials in a local pytket config file¶
Alternatively, you can store your credentials in local pytket config using the set_ibmq_config() method.
from pytket.extensions.qiskit import set_ibmq_config
set_ibmq_config(ibmq_api_token=ibm_token)
After saving your credentials you can access pytket-qiskit backend repeatedly without having to re-initialise your credentials.
If you are a member of an IBM hub then you can add this information to set_ibmq_config() as well.
from pytket.extensions.qiskit import set_ibmq_config
set_ibmq_config(ibmq_api_token=ibm_token, instance=inst)
Holds config parameters for pytket-qiskit. |
|
Set default values for instance or API token for your IBMQ provider. |
Converting circuits between pytket and qiskit¶
Users may wish to port quantum circuits between pytket and qiskit. This allows the features of both libraries to be used. For instance those familiar with qiskit may wish to convert their circuits to pytket and use the available compilation passes to optimise circuits.
Converts a qiskit |
|
Converts a pytket |
Default Compilation¶
Every Backend in pytket has its own default_compilation_pass() method. This method applies a sequence of optimisations to a circuit depending on the value of an optimisation_level parameter. This default compilation will ensure that the circuit meets all the constraints required to run on the Backend. The passes applied by different levels of optimisation are specified in the table below. Note that optimisation levels 0, 1 and
2 preserve barriers in a circuit, while optimisation level 3 will remove them.
optimisation_level = 0 |
optimisation_level = 1 |
optimisation_level = 2 [1] |
optimisation_level = 3 |
|---|---|---|---|
|
|||
LightSabre [3] |
LightSabre [3] |
LightSabre [3] |
|
|
|||
|
|
||
LightSabre [3] |
|||
|
|||
|
|||
[1] If no value is specified then
optimisation_leveldefaults to a value of 2.[2]
AutoRebase()is a conversion to the gateset supported by the backend. For IBM quantum devices and emulators the supported gate set is either \(\{X, SX, Rz, CX\}\), \(\{X, SX, Rz, ECR\}\), or \(\{X, SX, Rz, CZ\}\). The more idealised Aer simulators have a much broader range of supported gates.[3] This is imported from qiskit and corresponds to the method in “LightSABRE: A Lightweight and Enhanced SABRE Algorithm”, Henry Zou, Matthew Treinish, Kevin Hartman, Alexander Ivrii, Jake Lishman, arXiv:2409.08368.
Note: The default_compilation_pass() for AerBackend is the same as above if a NoiseModel is used. A NoiseModel implicitly defines connectivity constraints via edge errors. If no NoiseModel is used then then any passes related to connectivity constraints are omitted from the default_compilation_pass() for AerBackend.
Noise Modelling¶
Stores various parameters for modelling crosstalk noise |
Using TKET directly on qiskit circuits¶
For usage of TketBackend see the qiskit integration notebook example.
Wraps a |
|
The tket compiler to be plugged in to the Qiskit compilation sequence |
|
The tket compiler to be plugged in to the Qiskit compilation sequence |
|
TketJob wraps a |
- API documentation
IBMQBackendIBMQBackend.__init__()IBMQBackend.available_devices()IBMQBackend.cancel()IBMQBackend.circuit_status()IBMQBackend.default_compilation_pass()IBMQBackend.default_compilation_pass_offline()IBMQBackend.get_compiled_circuit()IBMQBackend.get_compiled_circuits()IBMQBackend.get_result()IBMQBackend.process_circuits()IBMQBackend.rebase_pass()IBMQBackend.rebase_pass_offline()IBMQBackend.squash_pass_offline()IBMQBackend.backend_infoIBMQBackend.required_predicates
NoIBMQCredentialsErrorIBMQEmulatorBackendIBMQEmulatorBackend.__init__()IBMQEmulatorBackend.cancel()IBMQEmulatorBackend.circuit_status()IBMQEmulatorBackend.default_compilation_pass()IBMQEmulatorBackend.get_result()IBMQEmulatorBackend.process_circuits()IBMQEmulatorBackend.rebase_pass()IBMQEmulatorBackend.backend_infoIBMQEmulatorBackend.required_predicates
AerBackendAerBackend.__init__()AerBackend.available_devices()AerBackend.cancel()AerBackend.circuit_status()AerBackend.default_compilation_pass()AerBackend.empty_cache()AerBackend.empty_result()AerBackend.get_compiled_circuit()AerBackend.get_compiled_circuits()AerBackend.get_operator_expectation_value()AerBackend.get_pauli_expectation_value()AerBackend.get_result()AerBackend.get_results()AerBackend.pop_result()AerBackend.process_circuit()AerBackend.process_circuits()AerBackend.rebase_pass()AerBackend.run_circuit()AerBackend.run_circuits()AerBackend.valid_circuit()AerBackend.backend_infoAerBackend.expectation_allows_nonhermitianAerBackend.persistent_handlesAerBackend.required_predicatesAerBackend.supports_contextual_optimisationAerBackend.supports_countsAerBackend.supports_density_matrixAerBackend.supports_expectationAerBackend.supports_shotsAerBackend.supports_stateAerBackend.supports_unitary
AerStateBackendAerStateBackend.__init__()AerStateBackend.available_devices()AerStateBackend.cancel()AerStateBackend.circuit_status()AerStateBackend.default_compilation_pass()AerStateBackend.empty_cache()AerStateBackend.empty_result()AerStateBackend.get_compiled_circuit()AerStateBackend.get_compiled_circuits()AerStateBackend.get_operator_expectation_value()AerStateBackend.get_pauli_expectation_value()AerStateBackend.get_result()AerStateBackend.get_results()AerStateBackend.pop_result()AerStateBackend.process_circuit()AerStateBackend.process_circuits()AerStateBackend.rebase_pass()AerStateBackend.run_circuit()AerStateBackend.run_circuits()AerStateBackend.valid_circuit()AerStateBackend.backend_infoAerStateBackend.expectation_allows_nonhermitianAerStateBackend.persistent_handlesAerStateBackend.required_predicatesAerStateBackend.supports_contextual_optimisationAerStateBackend.supports_countsAerStateBackend.supports_density_matrixAerStateBackend.supports_expectationAerStateBackend.supports_shotsAerStateBackend.supports_stateAerStateBackend.supports_unitary
AerUnitaryBackendAerUnitaryBackend.__init__()AerUnitaryBackend.available_devices()AerUnitaryBackend.cancel()AerUnitaryBackend.circuit_status()AerUnitaryBackend.default_compilation_pass()AerUnitaryBackend.empty_cache()AerUnitaryBackend.empty_result()AerUnitaryBackend.get_compiled_circuit()AerUnitaryBackend.get_compiled_circuits()AerUnitaryBackend.get_operator_expectation_value()AerUnitaryBackend.get_pauli_expectation_value()AerUnitaryBackend.get_result()AerUnitaryBackend.get_results()AerUnitaryBackend.pop_result()AerUnitaryBackend.process_circuit()AerUnitaryBackend.process_circuits()AerUnitaryBackend.rebase_pass()AerUnitaryBackend.run_circuit()AerUnitaryBackend.run_circuits()AerUnitaryBackend.valid_circuit()AerUnitaryBackend.backend_infoAerUnitaryBackend.expectation_allows_nonhermitianAerUnitaryBackend.persistent_handlesAerUnitaryBackend.required_predicatesAerUnitaryBackend.supports_contextual_optimisationAerUnitaryBackend.supports_countsAerUnitaryBackend.supports_density_matrixAerUnitaryBackend.supports_expectationAerUnitaryBackend.supports_shotsAerUnitaryBackend.supports_stateAerUnitaryBackend.supports_unitary
AerDensityMatrixBackendAerDensityMatrixBackend.__init__()AerDensityMatrixBackend.available_devices()AerDensityMatrixBackend.cancel()AerDensityMatrixBackend.circuit_status()AerDensityMatrixBackend.default_compilation_pass()AerDensityMatrixBackend.empty_cache()AerDensityMatrixBackend.empty_result()AerDensityMatrixBackend.get_compiled_circuit()AerDensityMatrixBackend.get_compiled_circuits()AerDensityMatrixBackend.get_operator_expectation_value()AerDensityMatrixBackend.get_pauli_expectation_value()AerDensityMatrixBackend.get_result()AerDensityMatrixBackend.get_results()AerDensityMatrixBackend.pop_result()AerDensityMatrixBackend.process_circuit()AerDensityMatrixBackend.process_circuits()AerDensityMatrixBackend.rebase_pass()AerDensityMatrixBackend.run_circuit()AerDensityMatrixBackend.run_circuits()AerDensityMatrixBackend.valid_circuit()AerDensityMatrixBackend.backend_infoAerDensityMatrixBackend.expectation_allows_nonhermitianAerDensityMatrixBackend.persistent_handlesAerDensityMatrixBackend.required_predicatesAerDensityMatrixBackend.supports_contextual_optimisationAerDensityMatrixBackend.supports_countsAerDensityMatrixBackend.supports_density_matrixAerDensityMatrixBackend.supports_expectationAerDensityMatrixBackend.supports_shotsAerDensityMatrixBackend.supports_stateAerDensityMatrixBackend.supports_unitary
qiskit_aer_backend()NoiseModelCharacterisationqiskit_to_tk()tk_to_qiskit()process_characterisation()get_avg_characterisation()process_characterisation_from_config()append_tk_command_to_qiskit()TketBackendCrosstalkParamsTketAutoPassTketPassJobInfoTketJobbackendresult_to_qiskit_resultdata()qiskit_result_to_backendresult()qiskit_experimentresult_to_backendresult()QiskitConfigset_ibmq_config()
- Changelog
- UNRELEASED
- 0.72.0 (October 2025)
- 0.71.1 (September 2025)
- 0.71.0 (July 2025)
- 0.70.0 (July 2025)
- 0.69.0 (July 2025)
- 0.68.3 (June 2025)
- 0.68.2 (June 2025)
- 0.68.0 (May 2025)
- 0.67.0 (April 2025)
- 0.66.0 (March 2025)
- 0.65.0 (March 2025)
- 0.64.0
- 0.63.0 (January 2025)
- 0.62.0 (December 2024)
- 0.61.0 (December 2024)
- 0.60.0 (November 2024)
- 0.59.0 (November 2024)
- 0.58.0 (October 2024)
- 0.57.0 (October 2024)
- 0.56.0 (September 2024)
- 0.55.0 (July 2024)
- 0.54.1 (June 2024)
- 0.54.0 (June 2024)
- 0.53.0 (April 2024)
- 0.52.0 (April 2024)
- 0.51.0 (March 2024)
- 0.50.0 (March 2024)
- 0.49.0 (March 2024)
- 0.48.1rc1
- 0.48.0 (January 2024)
- 0.47.0 (January 2024)
- 0.46.0 (November 2023)
- 0.45.0 (October 2023)
- 0.44.0 (September 2023)
- 0.43.0 (August 2023)
- 0.42.0 (August 2023)
- 0.41.0 (July 2023)
- 0.40.0 (June 2023)
- 0.39.0 (May 2023)
- 0.38.0 (April 2023)
- 0.37.1 (March 2023)
- 0.37.0 (March 2023)
- 0.36.0 (February 2023)
- 0.35.0 (February 2023)
- 0.34.0 (January 2023)
- 0.33.0 (December 2022)
- 0.32.0 (December 2022)
- 0.31.0 (November 2022)
- 0.30.0 (November 2022)
- 0.29.0 (October 2022)
- 0.28.0 (August 2022)
- 0.27.0 (July 2022)
- 0.26.0 (June 2022)
- 0.25.0 (May 2022)
- 0.24.0 (April 2022)
- 0.23.0 (March 2022)
- 0.22.2 (February 2022)
- 0.22.1 (February 2022)
- 0.22.0 (February 2022)
- 0.21.0 (January 2022)
- 0.20.0 (November 2021)
- 0.19.0 (October 2021)
- 0.18.0 (September 2021)
- 0.17.0 (September 2021)
- 0.16.1 (July 2021)
- 0.16.0 (July 2021)
- 0.15.1 (July 2021)
- 0.15.0 (June 2021)
- 0.14.0 (unreleased)
- 0.13.0 (May 2021)
- 0.12.0 (unreleased)
- 0.11.0 (May 2021)
- 0.10.0 (April 2021)
Useful links