Skip to content

Commit 58ddaed

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 572045f commit 58ddaed

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
@@ -291,6 +291,18 @@ impl NLayout {
291291
}
292292
}
293293
}
294+
impl ::std::ops::Index<VirtualQubit> for NLayout {
295+
type Output = PhysicalQubit;
296+
fn index(&self, index: VirtualQubit) -> &PhysicalQubit {
297+
&self.virt_to_phys[index.index()]
298+
}
299+
}
300+
impl ::std::ops::Index<PhysicalQubit> for NLayout {
301+
type Output = VirtualQubit;
302+
fn index(&self, index: PhysicalQubit) -> &VirtualQubit {
303+
&self.phys_to_virt[index.index()]
304+
}
305+
}
294306

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

0 commit comments

Comments
 (0)