Skip to main content

Exact solvers of the qubit routing problem

Project description

Quariadne Qiskit Plugins

This README provides basic usage instructions for the Quariadne MILP-based layout and routing plugins for Qiskit transpilation.

Installation

Install Quariadne using pip:

pip install quariadne

The plugins are automatically registered as Qiskit transpiler entry points upon installation.

Plugin Overview

Quariadne provides two transpiler plugins:

  • Layout Plugin: quariadne_milp - MILP-based initial qubit placement
  • Routing Plugin: quariadne_milp - MILP-based SWAP insertion for circuit routing

Both plugins are registered as entry points in pyproject.toml and must be used together - they do not work when separated.

Basic Usage

Using with Preset Pass Manager

The plugins must be used together with Qiskit's generate_preset_pass_manager():

import qiskit
from qiskit_ibm_runtime.fake_provider import FakeManilaV2
from qiskit_ibm_runtime import Session
from qiskit_ibm_runtime import SamplerV2 as Sampler


# Create a quantum circuit
circuit = qiskit.QuantumCircuit(3)
circuit.h(0)
circuit.cx(0, 1)
circuit.cx(1, 2)
circuit.cx(0, 2) # NOT POSSIBLE ON THE CHOSEN BACKEND!


# Set up backend
backend = FakeManilaV2()

# Generate pass manager with BOTH Quariadne plugins
pass_manager = qiskit.transpiler.generate_preset_pass_manager(
    backend=backend,
    optimization_level=3,
    layout_method="quariadne_milp",
    routing_method="quariadne_milp"  # Both must be used together
)

# Transpile the circuit
transpiled_circuit = pass_manager.run(circuit)

# Proper testing cycle with real sampler
with Session(backend=backend) as session:
    sampler = Sampler(mode=session)
    job = sampler.run([transpiled_circuit])
    result = job.result()[0]
    print(result)

Important Limitations

Circuit Size Constraints

For optimal performance, test with circuits that have:

  • Less than 50 gates
  • Less than 5 qubits

Larger circuits may experience significant performance degradation due to MILP complexity.

Plugin Dependencies

Critical: The layout and routing plugins are interdependent and cannot be used separately. Using only one plugin will result in failure.

Example Workflow

A complete example is available in notebook/Testing.ipynb, demonstrating:

  1. Circuit creation with random Clifford gates (within size limits)
  2. Backend setup using IBM's Manila fake provider
  3. Transpilation using both Quariadne MILP plugins together
  4. Proper validation using real sampler execution

Technical Details

  • Layout Plugin: Converts Qiskit DAG to Quariadne's internal representation, solves MILP optimisation, and returns optimal qubit layout
  • Routing Plugin: Uses MILP-determined SWAP operations from the layout stage and applies them layer-by-layer to the circuit

The routing plugin depends on results from the layout plugin, making them inseparable.

Requirements

  • Python >=3.13
  • Qiskit >=2.0.1
  • Backend with defined coupling map
  • Both plugins must be used together in the same pass manager
  • Test circuits should be small (< 50 gates, < 5 qubits)
  • Use real samplers for proper testing validation

For more details on Qiskit transpiler plugins, refer to the Qiskit Transpiler Documentation.

IMPORTANT DISCLAIMER: This code was written by me, with a serious help of Claude Code. Every bit of code was verified, but still there are risks. Use at your own risk.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

quariadne-1.0.1.tar.gz (848.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

quariadne-1.0.1-py3-none-any.whl (20.2 kB view details)

Uploaded Python 3

File details

Details for the file quariadne-1.0.1.tar.gz.

File metadata

  • Download URL: quariadne-1.0.1.tar.gz
  • Upload date:
  • Size: 848.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.17

File hashes

Hashes for quariadne-1.0.1.tar.gz
Algorithm Hash digest
SHA256 ef5e936e4f3d361e07356a598ff6ba6202b82d843ab9c3bfd4d42ec151c2280d
MD5 99df7a26a04cc8e40bc5cf86bb4619b6
BLAKE2b-256 fccbf3968c9feac37bcbf4dfdc40db54fb70ed551f19a0ee6836d9e34cc07046

See more details on using hashes here.

File details

Details for the file quariadne-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: quariadne-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 20.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.17

File hashes

Hashes for quariadne-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b0ad8c8d7a6b40c03e2b80846c98561937c35151f66aeecfdc900a3e8d528463
MD5 56bb1a67fda4feb2d7ab44d44ab96618
BLAKE2b-256 f34dd99c4f89d7d00470b78d75791755e550ff1828e3e6812744f14ab70773e4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page