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] Bits and Registers #13860

Draft
wants to merge 18 commits into
base: main
Choose a base branch
from
Draft

[WIP] Bits and Registers #13860

wants to merge 18 commits into from

Conversation

raynelfss
Copy link
Contributor

Summary

Bits and registers in Rust (Part 2)

Details and comments

@coveralls
Copy link

coveralls commented Feb 17, 2025

Pull Request Test Coverage Report for Build 13479642251

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 1306 of 1501 (87.01%) changed or added relevant lines in 17 files are covered.
  • 271 unchanged lines in 14 files lost coverage.
  • Overall coverage decreased (-0.09%) to 88.032%

Changes Missing Coverage Covered Lines Changed/Added Lines %
crates/circuit/src/circuit_data.rs 73 76 96.05%
crates/circuit/src/dot_utils.rs 0 7 0.0%
crates/circuit/src/bit.rs 235 259 90.73%
crates/circuit/src/dag_circuit.rs 445 470 94.68%
crates/circuit/src/register.rs 463 599 77.3%
Files with Coverage Reduction New Missed Lines %
crates/accelerate/src/basis/basis_translator/basis_search.rs 1 99.31%
crates/accelerate/src/basis/basis_translator/compose_transforms.rs 1 99.16%
crates/qasm2/src/expr.rs 1 94.23%
crates/circuit/src/parameter_table.rs 5 94.02%
crates/accelerate/src/commutation_checker.rs 8 97.36%
crates/qasm2/src/lex.rs 9 90.73%
crates/circuit/src/dag_circuit.rs 11 87.84%
qiskit/circuit/instruction.py 13 94.66%
qiskit/transpiler/preset_passmanagers/builtin_plugins.py 13 95.77%
qiskit/visualization/timeline/interface.py 23 22.92%
Totals Coverage Status
Change from base Build 13433680747: -0.09%
Covered Lines: 79071
Relevant Lines: 89821

💛 - Coveralls

@raynelfss raynelfss added this to the 2.0.0 milestone Feb 17, 2025
- Rebalance currently available api to allow for superclasses `Bit` and `Register` to also live in Rust.
- Remove: `ShareableBit` triat and structs that implement it. Replace them with new structs.
- Add prefix class attribute for python `Register` instances.
- Add `BitExtraInfo` as a soft identifier for `BitInfo`, can be null to identify a `Bit`.
- Add `RegisterInfo::get` method to retrieve the information of a `Bit`.
- Have the rust registers own their counters instead of having them be Python exclusive.
- Make subclassing of `Regster` and `Bit` a bit more effective by helping the subclasses inherit most methods.
raynelfss and others added 7 commits February 20, 2025 15:02
…GCircuit`.

- Modify `BitData` to accept an extra generic value specifying a "sharable" object type that can also be turned into a `PyObject` to allow for compatibility with `Var`.
- Rename `BitAsKey` to `VarAsKey` as it is currently only used for `Var` instances.
- Modify methods in `CommutationChecker` and `GateDirection` passes to use the newer methods.
- Other tweaks and fixes.
…bit`.

- Remove imports of `QUBIT` and `CLBIT` from `DAGCircuit` and `CircuitData`.
- Discarded old equality and hashing methods for `PyBit` and `PyRegister`.
- Fix `replace_bits` to accept any iterator over `Qubits` and `Clbits` from Python.
- Add `is_empty` methods to Register data, wherever `len` is available.
- Add additional parsing during creation of `Register` to more closely match previous behavior.
- Modify `Bit` tests due to mocking no longer operating correctly.
- Add method `register` to `BitData` to better represent a register reference in an owned bit.
- Add missing quotation marks in `Register` repr().
- Bits and registers that live in Rust are not guaranteed to pass the `is` equality check in Python.
- Restore type checking in `DAGCircuit` when adding bits.
- `Bits` should retain their hash value upon deserialization to avoid incorrect retrievals via hash or indexing. Fixed by implementing correct `__reduce__` method in `PyBit`, `PyClbit`, and `PyQubit`.
- Replace `__getnnewargs__` methods with `__reduce__` for more versatile serialization.
- Extend `SliceOrVec` to include a method that allows a vec with negative indices to correctly iterate based on a provided size.
- Modify `FullAncillaAllocation` to not replace the `QuantumRegister` prefix.
- Add `instances_count` getter attribute to all registers.
- `is` comparisons are no longer guaranteed to work between bits and registers. So some tests have been modified to reflect that.
- When `apply_operation` in the `DAGCircuit` receives a clbit in place of a qubit and viceversa, it will throw a type error, not a Key error. This is handled by PyO3 directly during extraction.
- Create `RegisterData` struct which, similarly to how `BitData` works, stores the registers and allows to access them by key, in this case by name or index.
- Tweak `CircuitData` and `QuantumCircuit` api to allow for access of registers from within `CircuitData`.
- Add `qubit_indices` and `clbit_indices` structs to keep track of the locations of bits and registers within the circuit.
- Modify `circuit_to_dag` to obtain the registers directly from `CircuitData`.
- Modify `BlueprintCircuit` to rely on `CircuitData` to access `QuantumRegister` instances.
- Add setters and getters for registers.
- Modify `circuit_to_instruction` to bring over the registers into the definition of the `Instruction`.
- Add `contains` method to `BitData`.
- Add rust native `BitLocations` that can be converted to a `Python` version if needed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create a rust representation of QuantumRegister and ClassicalRegister
3 participants