Skip to content
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
wants to merge 27 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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 Dec 27, 2024
cf673db
Add: `bits` method for register.
raynelfss Dec 30, 2024
00eeb7d
Use interners for registry
raynelfss Dec 31, 2024
bfa7389
Fix: Add functional python `Bits`
raynelfss Jan 2, 2025
db42bab
Initial Python registers
raynelfss Jan 3, 2025
20f0ebf
Finalize Python Registers, prepare for replacements.
raynelfss Jan 3, 2025
66bee69
Fix serialization in registers
raynelfss Jan 4, 2025
3a0c5bb
`BitData` refactor: Store Registers
raynelfss Jan 16, 2025
f8bdfa6
Add new `BitData` to `CircuitData`
raynelfss Jan 17, 2025
53a7979
Add more rust native connections to `CircuitData` and `QuantumCircuit`.
raynelfss Jan 21, 2025
8b80738
Fix: Do not re-add bits when adding registers.
raynelfss Jan 21, 2025
ff9958f
Fix: Incorrect addition of register cache
raynelfss Jan 22, 2025
8c6c2ea
Fix: Incorrect serialization and mutability
raynelfss Jan 22, 2025
1744b12
Merge remote-tracking branch 'upstream/main' into bit_u32_sequel
raynelfss Jan 22, 2025
e5ebe22
Refactor `BitInfo` to account for bits added from registers.
raynelfss Jan 23, 2025
2162f1f
Fix: Resolve strange behavior of `BitLocations`.
raynelfss Jan 27, 2025
03fbbc2
Update bit.rs
raynelfss Jan 28, 2025
02c4d1a
Merge remote-tracking branch 'upstream/main' into bit_u32_sequel
raynelfss Jan 28, 2025
2cd46a5
Fix: Add registers correctly in `circuit_to_instruction`.
raynelfss Jan 28, 2025
8283370
Fix: Remaining tests (-1)
raynelfss Jan 28, 2025
a353334
Fix: incorrect circuit initalization on the rust-side.
raynelfss Jan 28, 2025
6be25c5
Fix: Regenerate cache if any rust bits are missing.
raynelfss Jan 29, 2025
5169fc6
Lint: Remove unused `Qubit` import
raynelfss Jan 29, 2025
c2461ba
Docs: Add header strings in `bit.rs` and `register.rs`
raynelfss Jan 29, 2025
ae3385e
Merge branch 'main' into bit_u32_sequel
raynelfss Jan 30, 2025
b18c5ab
Merge branch 'main' into bit_u32_sequel
raynelfss Jan 30, 2025
f1ffc16
Fix: Remove changes to the `Interner`
raynelfss Jan 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions crates/circuit/src/bit.rs
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>,
}
Comment on lines +20 to +23
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The BitInfo struct and its registers field may be somewhat ambiguous in conveying their true purpose.It appears that BitInfo 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.

Copy link
Contributor Author

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.


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
}
}
Loading