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

Add new API for inserting multiple operations into the DAGCircuit in Rust. #13335

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

raynelfss
Copy link
Contributor

Summary

Adds a new struct DAGCircuitConcat (name can be changed 😄) that enables chained addition of instructions both valid and invalid into the DAGCircuit. Also, adapts existing structures to those new changes.

Details and comments

  • Add struct that allows continuous addition of instructions into the back of the DAGCircuit by performing edge modifications in the output nodes at the end of the additions.
  • The new struct includes the following new methods:
    • push_operation_back which pushes a valid PackedInstruction into the back of the DAGCircuit. It behaves very similarly to push_back.
    • apply_operation_back which inserts a new operation into the back of the DAGCircuit. It has two variants which depend on the ownership of the bit indices (Qubit, Clbit).
    • pack_instruction: private method that does just that, it creates a valid instance of PackedInstruction based on other provided attributes.
  • Modified DAGCircuit::extend to use this new API, without any considerable losses.

What about front additions?

This struct currently does not support adding instructions continuously to the front of the DAGCircuit because the methodology for that is a little different. It requires doing much more shifting than adding to the back, therefore I suggest this could be done in a follow-up.

Questions and comments?

Feel free to add these below as a review or comment 😸

- Add struct that allows continuous addition of instructions into the back of the `DAGCircuit` by performing edge modifications in the output nodes at the end of the additions.
- The new struct includes the following new methods:
    - `push_operation_back` which pushes a valid `PackedInstruction` into the back of the `DAGCircuit`. It behaves very similarly to `push_back`.
    - `apply_operation_back` which inserts a new operation into the back of the `DAGCircuit`. It has two variants which depend on the ownership of the bit indices (`Qubit`, `Clbit`).
    - `pack_instruction`: private method that basically does just that, it creates a valid instance of `PackedInstruction` based on other provided atributes.
- Modified `DAGCircuit::extend` to use this new API, without any considerable losses.
@raynelfss raynelfss added Changelog: None Do not include in changelog Rust This PR or issue is related to Rust code in the repository labels Oct 16, 2024
@raynelfss raynelfss added this to the 1.3.0 milestone Oct 16, 2024
@raynelfss raynelfss requested a review from a team as a code owner October 16, 2024 16:40
@qiskit-bot
Copy link
Collaborator

One or more of the following people are relevant to this code:

  • @Qiskit/terra-core

@raynelfss raynelfss changed the title [DAGCircuit improvements] Add new API for inserting multiple operations in Rust. Add new API for inserting multiple operations into the DAGCircuit in Rust. Oct 16, 2024
@coveralls
Copy link

coveralls commented Oct 16, 2024

Pull Request Test Coverage Report for Build 11619497041

Details

  • 326 of 328 (99.39%) changed or added relevant lines in 3 files are covered.
  • 7 unchanged lines in 3 files lost coverage.
  • Overall coverage increased (+0.03%) to 88.764%

Changes Missing Coverage Covered Lines Changed/Added Lines %
crates/circuit/src/dag_circuit.rs 258 260 99.23%
Files with Coverage Reduction New Missed Lines %
crates/accelerate/src/two_qubit_decompose.rs 1 92.09%
crates/accelerate/src/unitary_synthesis.rs 1 92.44%
crates/qasm2/src/lex.rs 5 92.73%
Totals Coverage Status
Change from base Build 11617024653: 0.03%
Covered Lines: 76532
Relevant Lines: 86220

💛 - Coveralls

@raynelfss raynelfss modified the milestones: 1.3.0, 1.4.0 Oct 18, 2024
@raynelfss raynelfss mentioned this pull request Oct 18, 2024
4 tasks
- Add struct that allows usage of both slice or owned collections of bit indices.
- Leverage use of `as_concat()` in `circuit_to_dag`.
- Leverage usage of new methods in `UnitarySynthesis` after Qiskit#13141 merged.
@ElePT ElePT self-assigned this Oct 21, 2024
@raynelfss
Copy link
Contributor Author

raynelfss commented Oct 31, 2024

After rewriting the logic of the BasisTranslator pass to use this new API, there was some minor speedup within the pass:

Change Before [f3bac5a] After [c91d45b] Ratio Benchmark (Parameter)
- 17.0±0.1ms 15.3±0.2ms 0.9 passes.MultipleBasisPassBenchmarks.time_basis_translator(5, 1024, ['rz', 'x', 'sx', 'cx', 'id'])
- 15.1±0.3ms 13.0±0.2ms 0.86 passes.MultipleBasisPassBenchmarks.time_basis_translator(5, 1024, ['u', 'cx', 'id'])
- 42.8±0.8ms 36.4±0.4ms 0.85 passes.MultipleBasisPassBenchmarks.time_basis_translator(14, 1024, ['rz', 'x', 'sx', 'cx', 'id'])
- 36.7±0.3ms 30.9±0.2ms 0.84 passes.MultipleBasisPassBenchmarks.time_basis_translator(14, 1024, ['u', 'cx', 'id'])
- 51.1±0.4ms 42.9±0.3ms 0.84 passes.MultipleBasisPassBenchmarks.time_basis_translator(20, 1024, ['u', 'cx', 'id'])
- 21.6±0.1ms 17.7±0.1ms 0.82 passes.MultipleBasisPassBenchmarks.time_basis_translator(5, 1024, ['rx', 'ry', 'rz', 'r', 'rxx', 'id'])
- 59.3±0.9ms 48.0±0.2ms 0.81 passes.MultipleBasisPassBenchmarks.time_basis_translator(20, 1024, ['rz', 'x', 'sx', 'cx', 'id'])
- 81.3±0.3ms 64.0±1ms 0.79 passes.MultipleBasisPassBenchmarks.time_basis_translator(20, 1024, ['rx', 'ry', 'rz', 'r', 'rxx', 'id'])
- 59.2±1ms 45.8±0.6ms 0.77 passes.MultipleBasisPassBenchmarks.time_basis_translator(14, 1024, ['rx', 'ry', 'rz', 'r', 'rxx', 'id'])

@raynelfss raynelfss modified the milestones: 1.4.0, 2.0.0 Nov 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: None Do not include in changelog Rust This PR or issue is related to Rust code in the repository
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants