Skip to content

Commit 049d1f7

Browse files
committed
Add indexing of NLayout
This allows `NLayout` to be indexed by `VirtualQubit` and `PhysicalQubit`, which is a shorter way of writing `VirtualQubit::to_phys` and `PhysicalQubit::to_virt`.
1 parent c501d55 commit 049d1f7

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

crates/circuit/src/nlayout.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,18 @@ impl NLayout {
267267
}
268268
}
269269
}
270+
impl ::std::ops::Index<VirtualQubit> for NLayout {
271+
type Output = PhysicalQubit;
272+
fn index(&self, index: VirtualQubit) -> &PhysicalQubit {
273+
&self.virt_to_phys[index.index()]
274+
}
275+
}
276+
impl ::std::ops::Index<PhysicalQubit> for NLayout {
277+
type Output = VirtualQubit;
278+
fn index(&self, index: PhysicalQubit) -> &VirtualQubit {
279+
&self.phys_to_virt[index.index()]
280+
}
281+
}
270282

271283
pub fn nlayout(m: &Bound<PyModule>) -> PyResult<()> {
272284
m.add_class::<NLayout>()?;

0 commit comments

Comments
 (0)