qiskit-transpiler-service


Nameqiskit-transpiler-service JSON
Version 0.3.0 PyPI version JSON
download
home_pagehttps://github.ibm.com/IBM-Q-Software/qiskit-transpiler-service
SummaryA 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)
upload_time2024-02-29 16:40:27
maintainer
docs_urlNone
authorData & Intelligence team, IBM Quantum
requires_python>=3.8
licenseApache 2.0
keywords qiskit ai transpiler routing
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # qiskit_transpiler_service

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).

**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:

```sh
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`).

*Note*: This library requires Qiskit 1.0 by default.

## 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.

1. Create a circuit and call the Qiskit transpiler service to transpile the circuit with `ibm_sherbrooke` as the `backend_name`, 3 as the `optimization_level`, and not using AI during the transpilation.

    ```python
    from qiskit.circuit.library import EfficientSU2
    from qiskit_transpiler_service.transpiler_service import TranspilerService

    circuit = EfficientSU2(101, entanglement="circular", reps=1).decompose()

    cloud_transpiler_service = TranspilerService(
        backend_name="ibm_sherbrooke",
        ai=False,
        optimization_level=3,
    )
    transpiled_circuit = cloud_transpiler_service.run(circuit)
    ```

_Note:_ you only can use `backend_name` devices you are allowed to with your IBM Quantum Account. Apart from the `backend_name`, the `TranspilerService` also allows `coupling_map` as parameter.

2. Produce a similar circuit and transpile it, requesting AI transpiling capabilities by setting the flag `ai` to `True`:

    ```python
    from qiskit.circuit.library import EfficientSU2
    from qiskit_transpiler_service.transpiler_service import TranspilerService

    circuit = EfficientSU2(101, entanglement="circular", reps=1).decompose()

    cloud_transpiler_service = TranspilerService(
        backend_name="ibm_sherbrooke",
        ai=True,
        optimization_level=1,
    )
    transpiled_circuit = cloud_transpiler_service.run(circuit)
    ```

### 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:

```python
from qiskit.transpiler import PassManager
from qiskit_transpiler_service.ai.routing import AIRouting
from qiskit.circuit.library import EfficientSU2

ai_passmanager = PassManager([
  AIRouting(backend_name="ibm_sherbrooke", optimization_level=2, layout_mode="optimize")
])

circuit = EfficientSU2(101, entanglement="circular", reps=1).decompose()

transpiled_circuit = ai_passmanager.run(circuit)
```

Here, the `backend_name` 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 the `AIRouting` 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.

### Using the AI circuit synthesis passes

The AI circuit synthesis passes allow you to optimize pieces of different circuit types ([Clifford](https://docs.quantum.ibm.com/api/qiskit/qiskit.quantum_info.Clifford), [Linear Function](https://docs.quantum.ibm.com/api/qiskit/qiskit.circuit.library.LinearFunction), [Permutation](https://docs.quantum.ibm.com/api/qiskit/qiskit.circuit.library.Permutation#permutation)) by re-synthesizing them. The typical way one would use the synthesis pass is the following:

```python
from qiskit.transpiler import PassManager

from qiskit_transpiler_service.ai.routing import AIRouting
from qiskit_transpiler_service.ai.synthesis import AILinearFunctionSynthesis
from qiskit_transpiler_service.ai.collection import CollectLinearFunctions
from qiskit.circuit.library import EfficientSU2

ai_passmanager = PassManager([
  AIRouting(backend_name="ibm_cairo", optimization_level=3, layout_mode="optimize"),  # Route circuit
  CollectLinearFunctions(),  # Collect Linear Function blocks
  AILinearFunctionSynthesis(backend_name="ibm_cairo")  # Re-synthesize Linear Function blocks
])

circuit = EfficientSU2(10, entanglement="full", reps=1).decompose()

transpiled_circuit = ai_passmanager.run(circuit)
```

The synthesis respects the coupling map of the device: it can be run safely after other routing passes without "messing up" the circuit, so the overall circuit will still follow the device restrictions. By default, the synthesis will replace the original sub-circuit only if the synthesized sub-circuit improves the original (currently only checking cnot count), but this can be forced to always replace the circuit by setting `replace_only_if_better=False`.

The following synthesis passes are available from `qiskit_transpiler_service.ai.synthesis`:

- *AICliffordSynthesis*: Synthesis for [Clifford](https://docs.quantum.ibm.com/api/qiskit/qiskit.quantum_info.Clifford) circuits (blocks of `H`, `S` and `CX` gates). Currently up to 9 qubit blocks.
- *AILinearFunctionSynthesis*: Synthesis for [Linear Function](https://docs.quantum.ibm.com/api/qiskit/qiskit.circuit.library.LinearFunction) circuits (blocks of `CX` and `SWAP` gates). Currently up to 9 qubit blocks.
- *AIPermutationSynthesis*: Synthesis for [Permutation](https://docs.quantum.ibm.com/api/qiskit/qiskit.circuit.library.Permutation#permutation) circuits (blocks of `SWAP` gates). Currently available for 65, 33, and 27 qubit blocks.

We expect to gradually increase the size of the supported blocks.

All passes use a thread pool to send several requests in parallel. By default it will use as max threads as number of cores plus four (default values for `ThreadPoolExecutor` python object). However, you can set your own value with the `max_threads` argument at pass instantation. For example, the following line will instantiate the `AILinearFunctionSynthesis` pass allowing it to use a maximum of 20 threads.

```python
AILinearFunctionSynthesis(backend_name="ibm_cairo", max_threads=20)  # Re-synthesize Linear Function blocks using 20 threads max
```

You can also set the environment variable `AI_TRANSPILER_MAX_THREADS` to the desired number of maximum threads, and all synthesis passes instantiated after that will use that value.

For sub-circuit to be synthesized by the AI synthesis passes, it must lay on a connected subgraph of the coupling map (this can be ensured by just doing a routing pass previous to collecting the blocks, but this is not the only way to do it). The synthesis passes will automatically check if a the specific subgraph where the sub-circuit lays is supported, and if it is not supported it will raise a warning and just leave the original sub-circuit as it is.

To complement the synthesis passes we also provide custom collection passes for Cliffords, Linear Functions and Permutations that can be imported from `qiskit_transpiler_service.ai.collection`:

- *CollectCliffords*: Collects Clifford blocks as `Instruction` objects and stores the original sub-circuit to compare against it after synthesis.
- *CollectLinearFunctions*: Collects blocks of `SWAP` and `CX` as `LinearFunction` objects and stores the original sub-circuit to compare against it after synthesis.
- *CollectPermutations*: Collects blocks of `SWAP` circuits as `Permutations`.

These custom collection passes limit the sizes of the collected sub-circuits so that they are supported by the AI synthesis passes, so it is recommended to use them after the routing passes and before the synthesis passes to get a better optimization overall.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.ibm.com/IBM-Q-Software/qiskit-transpiler-service",
    "name": "qiskit-transpiler-service",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "qiskit,ai,transpiler,routing",
    "author": "Data & Intelligence team, IBM Quantum",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/7c/95/bab4e1fe92cf37782b2e9cee1d5a77843bd12e9184936bf56006ec972613/qiskit-transpiler-service-0.3.0.tar.gz",
    "platform": null,
    "description": "# qiskit_transpiler_service\n\nA 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).\n\n**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.\n\n## Installing the qiskit-transpiler-service\n\nTo use the Qiskit transpiler service, install the `qiskit-transpiler-service` package:\n\n```sh\npip install qiskit-transpiler-service\n```\n\nBy 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`).\n\n*Note*: This library requires Qiskit 1.0 by default.\n\n## How to use the library\n\n### Using the Qiskit Transpiler service\n\nThe following examples demonstrate how to transpile circuits using the Qiskit transpiler service with different parameters.\n\n1. Create a circuit and call the Qiskit transpiler service to transpile the circuit with `ibm_sherbrooke` as the `backend_name`, 3 as the `optimization_level`, and not using AI during the transpilation.\n\n    ```python\n    from qiskit.circuit.library import EfficientSU2\n    from qiskit_transpiler_service.transpiler_service import TranspilerService\n\n    circuit = EfficientSU2(101, entanglement=\"circular\", reps=1).decompose()\n\n    cloud_transpiler_service = TranspilerService(\n        backend_name=\"ibm_sherbrooke\",\n        ai=False,\n        optimization_level=3,\n    )\n    transpiled_circuit = cloud_transpiler_service.run(circuit)\n    ```\n\n_Note:_ you only can use `backend_name` devices you are allowed to with your IBM Quantum Account. Apart from the `backend_name`, the `TranspilerService` also allows `coupling_map` as parameter.\n\n2. Produce a similar circuit and transpile it, requesting AI transpiling capabilities by setting the flag `ai` to `True`:\n\n    ```python\n    from qiskit.circuit.library import EfficientSU2\n    from qiskit_transpiler_service.transpiler_service import TranspilerService\n\n    circuit = EfficientSU2(101, entanglement=\"circular\", reps=1).decompose()\n\n    cloud_transpiler_service = TranspilerService(\n        backend_name=\"ibm_sherbrooke\",\n        ai=True,\n        optimization_level=1,\n    )\n    transpiled_circuit = cloud_transpiler_service.run(circuit)\n    ```\n\n### Using the AIRouting pass manually\n\nThe `AIRouting` pass acts both as a layout stage and a routing stage. It can be used within a `PassManager` as follows:\n\n```python\nfrom qiskit.transpiler import PassManager\nfrom qiskit_transpiler_service.ai.routing import AIRouting\nfrom qiskit.circuit.library import EfficientSU2\n\nai_passmanager = PassManager([\n  AIRouting(backend_name=\"ibm_sherbrooke\", optimization_level=2, layout_mode=\"optimize\")\n])\n\ncircuit = EfficientSU2(101, entanglement=\"circular\", reps=1).decompose()\n\ntranspiled_circuit = ai_passmanager.run(circuit)\n```\n\nHere, the `backend_name` 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.\nThe `layout_mode` includes the following options:\n\n- `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.\n- `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 the `AIRouting` pass.\n- `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.\n\n### Using the AI circuit synthesis passes\n\nThe AI circuit synthesis passes allow you to optimize pieces of different circuit types ([Clifford](https://docs.quantum.ibm.com/api/qiskit/qiskit.quantum_info.Clifford), [Linear Function](https://docs.quantum.ibm.com/api/qiskit/qiskit.circuit.library.LinearFunction), [Permutation](https://docs.quantum.ibm.com/api/qiskit/qiskit.circuit.library.Permutation#permutation)) by re-synthesizing them. The typical way one would use the synthesis pass is the following:\n\n```python\nfrom qiskit.transpiler import PassManager\n\nfrom qiskit_transpiler_service.ai.routing import AIRouting\nfrom qiskit_transpiler_service.ai.synthesis import AILinearFunctionSynthesis\nfrom qiskit_transpiler_service.ai.collection import CollectLinearFunctions\nfrom qiskit.circuit.library import EfficientSU2\n\nai_passmanager = PassManager([\n  AIRouting(backend_name=\"ibm_cairo\", optimization_level=3, layout_mode=\"optimize\"),  # Route circuit\n  CollectLinearFunctions(),  # Collect Linear Function blocks\n  AILinearFunctionSynthesis(backend_name=\"ibm_cairo\")  # Re-synthesize Linear Function blocks\n])\n\ncircuit = EfficientSU2(10, entanglement=\"full\", reps=1).decompose()\n\ntranspiled_circuit = ai_passmanager.run(circuit)\n```\n\nThe synthesis respects the coupling map of the device: it can be run safely after other routing passes without \"messing up\" the circuit, so the overall circuit will still follow the device restrictions. By default, the synthesis will replace the original sub-circuit only if the synthesized sub-circuit improves the original (currently only checking cnot count), but this can be forced to always replace the circuit by setting `replace_only_if_better=False`.\n\nThe following synthesis passes are available from `qiskit_transpiler_service.ai.synthesis`:\n\n- *AICliffordSynthesis*: Synthesis for [Clifford](https://docs.quantum.ibm.com/api/qiskit/qiskit.quantum_info.Clifford) circuits (blocks of `H`, `S` and `CX` gates). Currently up to 9 qubit blocks.\n- *AILinearFunctionSynthesis*: Synthesis for [Linear Function](https://docs.quantum.ibm.com/api/qiskit/qiskit.circuit.library.LinearFunction) circuits (blocks of `CX` and `SWAP` gates). Currently up to 9 qubit blocks.\n- *AIPermutationSynthesis*: Synthesis for [Permutation](https://docs.quantum.ibm.com/api/qiskit/qiskit.circuit.library.Permutation#permutation) circuits (blocks of `SWAP` gates). Currently available for 65, 33, and 27 qubit blocks.\n\nWe expect to gradually increase the size of the supported blocks.\n\nAll passes use a thread pool to send several requests in parallel. By default it will use as max threads as number of cores plus four (default values for `ThreadPoolExecutor` python object). However, you can set your own value with the `max_threads` argument at pass instantation. For example, the following line will instantiate the `AILinearFunctionSynthesis` pass allowing it to use a maximum of 20 threads.\n\n```python\nAILinearFunctionSynthesis(backend_name=\"ibm_cairo\", max_threads=20)  # Re-synthesize Linear Function blocks using 20 threads max\n```\n\nYou can also set the environment variable `AI_TRANSPILER_MAX_THREADS` to the desired number of maximum threads, and all synthesis passes instantiated after that will use that value.\n\nFor sub-circuit to be synthesized by the AI synthesis passes, it must lay on a connected subgraph of the coupling map (this can be ensured by just doing a routing pass previous to collecting the blocks, but this is not the only way to do it). The synthesis passes will automatically check if a the specific subgraph where the sub-circuit lays is supported, and if it is not supported it will raise a warning and just leave the original sub-circuit as it is.\n\nTo complement the synthesis passes we also provide custom collection passes for Cliffords, Linear Functions and Permutations that can be imported from `qiskit_transpiler_service.ai.collection`:\n\n- *CollectCliffords*: Collects Clifford blocks as `Instruction` objects and stores the original sub-circuit to compare against it after synthesis.\n- *CollectLinearFunctions*: Collects blocks of `SWAP` and `CX` as `LinearFunction` objects and stores the original sub-circuit to compare against it after synthesis.\n- *CollectPermutations*: Collects blocks of `SWAP` circuits as `Permutations`.\n\nThese custom collection passes limit the sizes of the collected sub-circuits so that they are supported by the AI synthesis passes, so it is recommended to use them after the routing passes and before the synthesis passes to get a better optimization overall.\n",
    "bugtrack_url": null,
    "license": "Apache 2.0",
    "summary": "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)",
    "version": "0.3.0",
    "project_urls": {
        "Bug Tracker": "https://github.ibm.com/IBM-Q-Software/qiskit-transpiler-service/issues",
        "Documentation": "https://github.ibm.com/IBM-Q-Software/qiskit-transpiler-service",
        "Homepage": "https://github.ibm.com/IBM-Q-Software/qiskit-transpiler-service",
        "Source Code": "https://github.ibm.com/IBM-Q-Software/qiskit-transpiler-service"
    },
    "split_keywords": [
        "qiskit",
        "ai",
        "transpiler",
        "routing"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a40199f2020874e03b3be0bae4887da685c465c626b28c39d4ed23e0ca55dd21",
                "md5": "52e20e2dbfd057ed6cd9ffb05f2da84a",
                "sha256": "05636069c0610f53d9ba7a3d2a39e84ac93e992028e7a0ef4ad463a07209f226"
            },
            "downloads": -1,
            "filename": "qiskit_transpiler_service-0.3.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "52e20e2dbfd057ed6cd9ffb05f2da84a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 19728,
            "upload_time": "2024-02-29T16:40:26",
            "upload_time_iso_8601": "2024-02-29T16:40:26.130396Z",
            "url": "https://files.pythonhosted.org/packages/a4/01/99f2020874e03b3be0bae4887da685c465c626b28c39d4ed23e0ca55dd21/qiskit_transpiler_service-0.3.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7c95bab4e1fe92cf37782b2e9cee1d5a77843bd12e9184936bf56006ec972613",
                "md5": "9eae9f559f05624725c0efa999aa94eb",
                "sha256": "bf019142980c39bf8cb9524f9ded32133c9a4d21271184adf1248eabbe999835"
            },
            "downloads": -1,
            "filename": "qiskit-transpiler-service-0.3.0.tar.gz",
            "has_sig": false,
            "md5_digest": "9eae9f559f05624725c0efa999aa94eb",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 18025,
            "upload_time": "2024-02-29T16:40:27",
            "upload_time_iso_8601": "2024-02-29T16:40:27.447084Z",
            "url": "https://files.pythonhosted.org/packages/7c/95/bab4e1fe92cf37782b2e9cee1d5a77843bd12e9184936bf56006ec972613/qiskit-transpiler-service-0.3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-29 16:40:27",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "qiskit-transpiler-service"
}
        
Elapsed time: 0.19528s