-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Use native bits and registers for CircuitData
.
#13686
Draft
raynelfss
wants to merge
27
commits into
Qiskit:main
Choose a base branch
from
raynelfss:bit_u32_sequel
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
af13dd2
Initial: Register Infrastructure in Rust
raynelfss cf673db
Add: `bits` method for register.
raynelfss 00eeb7d
Use interners for registry
raynelfss bfa7389
Fix: Add functional python `Bits`
raynelfss db42bab
Initial Python registers
raynelfss 20f0ebf
Finalize Python Registers, prepare for replacements.
raynelfss 66bee69
Fix serialization in registers
raynelfss 3a0c5bb
`BitData` refactor: Store Registers
raynelfss f8bdfa6
Add new `BitData` to `CircuitData`
raynelfss 53a7979
Add more rust native connections to `CircuitData` and `QuantumCircuit`.
raynelfss 8b80738
Fix: Do not re-add bits when adding registers.
raynelfss ff9958f
Fix: Incorrect addition of register cache
raynelfss 8c6c2ea
Fix: Incorrect serialization and mutability
raynelfss 1744b12
Merge remote-tracking branch 'upstream/main' into bit_u32_sequel
raynelfss e5ebe22
Refactor `BitInfo` to account for bits added from registers.
raynelfss 2162f1f
Fix: Resolve strange behavior of `BitLocations`.
raynelfss 03fbbc2
Update bit.rs
raynelfss 02c4d1a
Merge remote-tracking branch 'upstream/main' into bit_u32_sequel
raynelfss 2cd46a5
Fix: Add registers correctly in `circuit_to_instruction`.
raynelfss 8283370
Fix: Remaining tests (-1)
raynelfss a353334
Fix: incorrect circuit initalization on the rust-side.
raynelfss 6be25c5
Fix: Regenerate cache if any rust bits are missing.
raynelfss 5169fc6
Lint: Remove unused `Qubit` import
raynelfss c2461ba
Docs: Add header strings in `bit.rs` and `register.rs`
raynelfss ae3385e
Merge branch 'main' into bit_u32_sequel
raynelfss b18c5ab
Merge branch 'main' into bit_u32_sequel
raynelfss f1ffc16
Fix: Remove changes to the `Interner`
raynelfss File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// This code is part of Qiskit. | ||
// | ||
// (C) Copyright IBM 2025 | ||
// | ||
// This code is licensed under the Apache License, Version 2.0. You may | ||
// obtain a copy of this license in the LICENSE.txt file in the root directory | ||
// of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. | ||
// | ||
// Any modifications or derivative works of this code must retain this | ||
// copyright notice, and modified files need to carry a notice indicating | ||
// that they have been altered from the originals. | ||
|
||
use std::fmt::Debug; | ||
|
||
/// Keeps information 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 { | ||
added_by_reg: bool, | ||
registers: Vec<BitLocation>, | ||
} | ||
|
||
impl BitInfo { | ||
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.0 | ||
} | ||
|
||
pub fn index(&self) -> u32 { | ||
self.1 | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
BitInfo
struct and itsregisters
field may be somewhat ambiguous in conveying their true purpose.It appears thatBitInfo
primarily tracks how bits are associated with registers.You might consider renaming this
BitInfo
to something more indicative of its focus on bit-register relationships or placements.However, if you assume how to use it in another way, it is not necessary to rename this field.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You got the intended use correctly. I'm open to renaming this, since it is WiP you can leave any suggestions.