forked from Qiskit/qiskit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor
BitInfo
to account for bits added from registers.
- Fix bug with `BlueprintCircuit` that discarded most instances of `QuantumRegister`. - Rename `RegisterAsKey::index()` to size, since it was erroneously named.
- Loading branch information
Showing
6 changed files
with
159 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,65 @@ | ||
use std::fmt::Debug; | ||
|
||
/// Keeps information about where a qubit is located within the circuit. | ||
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Ord, Eq, Hash)] | ||
/// Keeps informatyion about where a bit is located within the circuit. | ||
/// | ||
/// This information includes whether the bit was added by a register, | ||
/// which register it belongs to and where it is located within it. | ||
#[derive(Debug, Clone, PartialEq, PartialOrd, Ord, Eq, Hash)] | ||
pub struct BitInfo { | ||
register_idx: u32, | ||
index: u32, | ||
added_by_reg: bool, | ||
registers: Vec<BitLocation>, | ||
} | ||
|
||
impl BitInfo { | ||
pub fn new(register_idx: u32, index: u32) -> Self { | ||
Self { | ||
register_idx, | ||
index, | ||
pub fn new(orig_reg: Option<(u32, u32)>) -> Self { | ||
// If the instance was added by a register, add it and prefil its locator | ||
if let Some((reg_idx, idx)) = orig_reg { | ||
Self { | ||
added_by_reg: true, | ||
registers: vec![BitLocation::new(reg_idx, idx)], | ||
} | ||
} else { | ||
Self { | ||
added_by_reg: false, | ||
registers: vec![], | ||
} | ||
} | ||
} | ||
|
||
/// Add a register to the bit instance | ||
pub fn add_register(&mut self, register: u32, index: u32) { | ||
self.registers.push(BitLocation(register, index)) | ||
} | ||
|
||
/// Returns a list with all the [BitLocation] instances | ||
pub fn get_registers(&self) -> &[BitLocation] { | ||
&self.registers | ||
} | ||
|
||
/// Returns the index of the original register if any exists | ||
pub fn orig_register_index(&self) -> Option<&BitLocation> { | ||
if self.added_by_reg { | ||
Some(&self.registers[0]) | ||
} else { | ||
None | ||
} | ||
} | ||
} | ||
|
||
/// Keeps information about where a qubit is located within a register. | ||
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Ord, Eq, Hash)] | ||
pub struct BitLocation(u32, u32); | ||
|
||
impl BitLocation { | ||
pub fn new(register_idx: u32, index: u32) -> Self { | ||
Self(register_idx, index) | ||
} | ||
|
||
pub fn register_index(&self) -> u32 { | ||
self.register_idx | ||
self.0 | ||
} | ||
|
||
pub fn index(&self) -> u32 { | ||
self.index | ||
self.1 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.