pub fn sabre_layout(
circuit: &Circuit,
device: &Device,
objective: &LayoutObjective,
config: &SabreConfig,
) -> Result<LayoutResult, CompilerError>Expand description
Selects an initial layout with fused SABRE refinement and routing search.
The search completes every configured refinement iteration before routing
the resulting layout. Complete routes are never created for intermediate
refinement states.
This layout-only API returns the winning route’s initial layout;
crate::compile::transform::route_sabre consumes the same fused result
directly and does not route the winner a second time.
Candidate layouts include deterministic component-feasible anchors,
reachable greedy/VF2 and interaction-aware layouts, plus the full randomized
budget controlled by SabreConfig::layout_trials. Each candidate is
refined through SABRE forward/backward passes; complete trials are ranked by
predicted native two-qubit count, native two-qubit depth, native total
depth, and stable candidate/trial order. LayoutObjective contributes
candidate generation and diagnostics, but is not the final selection key.
§Errors
Returns CompilerError::InvalidInput for invalid SABRE layout
configuration, insufficient usable physical qubits, unreachable
interactions in the usable topology, or unsupported circuit operations.
§Examples
use cqlib_core::circuit::{Circuit, Qubit};
use cqlib_core::compile::sabre::SabreConfig;
use cqlib_core::compile::transform::{LayoutObjective, sabre_layout};
use cqlib_core::device::Device;
let mut circuit = Circuit::new(3);
circuit.cx(Qubit::new(0), Qubit::new(2)).unwrap();
let device = Device::line("line-3", 3).unwrap();
let result = sabre_layout(
&circuit,
&device,
&LayoutObjective::topology_only(),
&SabreConfig::default(),
)
.unwrap();
assert!(result.score.is_some());