pub fn greedy_layout(
circuit: &Circuit,
device: &Device,
objective: &LayoutObjective,
) -> Result<LayoutResult, CompilerError>Expand description
Builds a deterministic greedy initial layout from weighted interactions.
The algorithm places higher-weight logical interactions first. For each
interaction it chooses the closest currently feasible physical placement,
using the shared LayoutObjective as a local tie-breaker for direction
and calibration data. Routing remains a later pass: this function only
selects an initial logical-to-physical mapping.
This is a good default candidate generator for larger devices where VF2 may be too expensive or where a perfect topology embedding does not exist.
§Errors
Returns CompilerError::InvalidInput if there are fewer usable physical
qubits than logical qubits, no physical candidate can be selected for a
required placement, or if final objective scoring rejects the layout.
§Examples
use cqlib_core::circuit::{Circuit, Qubit};
use cqlib_core::compile::transform::{LayoutObjective, greedy_layout};
use cqlib_core::device::{Device, LogicalQubit, PhysicalQubit};
let device = Device::line("line-3", 3).unwrap();
let objective = LayoutObjective::topology_only();
let mut circuit = Circuit::new(3);
circuit.cx(Qubit::new(0), Qubit::new(1)).unwrap();
circuit.cx(Qubit::new(1), Qubit::new(2)).unwrap();
let result = greedy_layout(&circuit, &device, &objective).unwrap();
assert_eq!(
result.layout.get_physical(LogicalQubit::new(0)),
Some(PhysicalQubit::new(0)),
);
assert!(result.diagnostics.is_perfect);