A library to use Qiskit Transpiler service(https://docs.quantum.ibm.com/transpile/qiskit-transpiler-service) and the AI transpiler passes(https://docs.quantum.ibm.com/transpile/ai-transpiler-passes)
Project description
qiskit_transpiler_service
A library to use Qiskit Transpiler service and the AI transpiler passes.
Note The Qiskit transpiler service and the AI transpiler passes use different experimental services that are only available for IBM Quantum Premium Plan users. This library and the releated services are an alpha release, subject to change.
Installing the qiskit-transpiler-service
To use the Qiskit transpiler service, install the qiskit-transpiler-service
package:
pip install qiskit-transpiler-service
By default, the package tries to authenticate to IBM Quantum services with the defined Qiskit API token, and uses your token from the QISKIT_IBM_TOKEN
environment variable or from the file ~/.qiskit/qiskit-ibm.json
(under the section default-ibm-quantum
).
How to use the library?
Using the Qiskit Transpiler service
The following examples demonstrate how to transpile circuits using the Qiskit transpiler service with different parameters.
-
Create a random circuit and call the Qiskit transpiler service to transpile the circuit with
ibm_cairo
as thetarget
, 1 as theoptimization_level
, and not using AI during the transpilation.from qiskit.circuit.random import random_circuit from qiskit_transpiler_service.transpiler_service import TranspilerService random_circ = random_circuit(5, depth=3, seed=42).decompose(reps=3) cloud_transpiler_service = TranspilerService( target="ibm_cairo", ai=False, optimization_level=1, ) transpiled_circuit = cloud_transpiler_service.run(random_circ)
Note: you only can use target
devices you are allowed to with your IBM Quantum Account. Apart from the target
, the TranspilerService
also allows coupling_map as parameter.
-
Produce a similar random circuit and transpile it, requesting AI transpiling capabilities by setting the flag
ai
toTrue
:from qiskit.circuit.random import random_circuit from qiskit_transpiler_service.transpiler_service import TranspilerService random_circ = random_circuit(5, depth=3, seed=42).decompose(reps=3) cloud_transpiler_service = TranspilerService( target="ibm_cairo", ai=True, optimization_level=1, ) transpiled_circuit = cloud_transpiler_service.run(random_circ)
Using the AIRouting pass manually
The AIRouting
pass acts both as a layout stage and a routing stage. It can be used within a PassManager
as follows:
from qiskit.transpiler import PassManager
from qiskit_transpiler_service.ai.routing import AIRouting
from qiskit.circuit.library import EfficientSU2
ai_passmanager = PassManager([
AIRouting(target="ibm_sherbrooke", optimization_level=2, layout_mode="optimize")
])
circuit = EfficientSU2(120, entanglement="circular", reps=1).decompose()
transpiled_circuit = ai_passmanager.run(circuit)
Here, the target
determines which backend to route for, the optimization_level
(1, 2, or 3) determines the computational effort to spend in the process (higher usually gives better results but takes longer), and the layout_mode
specifies how to handle the layout selection.
The layout_mode
includes the following options:
keep
: This respects the layout set by the previous transpiler passes (or uses the trivial layout if not set). It is typically only used when the circuit must be run on specific qubits of the device. It often produces worse results because it has less room for optimization.improve
: This uses the layout set by the previous transpiler passes as a starting point. It is useful when you have a good initial guess for the layout; for example, for circuits that are built in a way that approximately follows the device's coupling map. It is also useful if you want to try other specific layout passes combined with theAIRouting
pass.optimize
: This is the default mode. It works best for general circuits where you might not have good layout guesses. This mode ignores previous layout selections.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for qiskit-transpiler-service-0.2.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 75d1237bb491cabca81110f43de877e427c83b81a836eb0a14c6b247f054023f |
|
MD5 | 7b3fe64bc5f190e7c71a563f7481ea6d |
|
BLAKE2b-256 | b167530e16edc631c27c31865401d338ac882e05b057a67ee8c51d64a105c7dc |
Hashes for qiskit_transpiler_service-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9dd99768554d5a98704d1e7048703304c04db5c9a53aa965556babc998d48ddd |
|
MD5 | 0fd14f7f8fc82556bb1db084666f8d12 |
|
BLAKE2b-256 | 731c10e1283ae25829ac9488e0c56d7388a9aba3ed66d0d41b9a2418137a7a35 |