Skip to main content

Module routing

Module routing 

Source
Expand description

Device-aware routing transforms.

Routing transforms rebuild a logical Circuit into a physical circuit that satisfies a target Device topology. A routing algorithm selects or consumes a logical-to-physical layout and inserts SWAP operations when needed.

This module is an algorithm boundary, not a compiler workflow. It does not choose when routing should run, lower operations to a target basis, or mutate device topology facts. Concrete algorithms live in submodules such as sabre.

§Entry Points

  • route_sabre selects an initial layout with SABRE layout refinement, then routes the circuit from that layout.
  • route_with_layout routes from a caller-supplied initial layout and skips automatic layout selection.

The public compiler workflow uses route_with_layout when DeviceCompileTarget::initial_layout is set, otherwise it uses route_sabre. Routed circuits use physical qubit identifiers and guarantee undirected physical adjacency for routed two-qubit operations. Target-basis translation and exact directed device lowering remain separate compiler stages.

§Example

use cqlib_core::circuit::{Circuit, Qubit};
use cqlib_core::compile::sabre::SabreConfig;
use cqlib_core::compile::transform::LayoutObjective;
use cqlib_core::compile::transform::routing::route_sabre;
use cqlib_core::device::{Device, PhysicalQubit, Topology};
use std::collections::HashSet;

let physical = vec![
    PhysicalQubit::new(0),
    PhysicalQubit::new(1),
    PhysicalQubit::new(2),
];
let topology = Topology::new(
    physical.clone(),
    vec![
        (PhysicalQubit::new(0), PhysicalQubit::new(1), "cx".to_string()),
        (PhysicalQubit::new(1), PhysicalQubit::new(2), "cx".to_string()),
    ],
)?;
let device = Device::new(
    "line3",
    physical.iter().copied().collect::<HashSet<_>>(),
    topology,
)?;

let mut circuit = Circuit::new(3);
circuit.cx(Qubit::new(0), Qubit::new(2))?;

let routed = route_sabre(
    &circuit,
    &device,
    &LayoutObjective::topology_only(),
    &SabreConfig::default(),
)?;

assert_all_two_qubit_ops_are_local(routed.circuit());

Re-exports§

pub use sabre::RoutedCircuit;
pub use sabre::SabreRouteResult;
pub use sabre::route_sabre;
pub use sabre::route_with_layout;

Modules§

sabre
SABRE routing transform.