-
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
Add rust-native apply_operation
methods
#13143
Conversation
…_back methods. - These methods allow rust users to add an operation to either the front or the back of the circuit without needing to have valid interned indices for the Qargs/Qargs of said operations. - Leverage the new methods in the existing python variants of them.
One or more of the following people are relevant to this code:
|
Pull Request Test Coverage Report for Build 10886394187Warning: 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
💛 - Coveralls |
- To avoid an ownership issue, usage of the new methods from the Python variants has been removed. - As requested, the insertion check in the rust `apply_op` has been removed.
apply_operation
methodsapply_operation
methods
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.
This looks good to me. Thanks for doing this work and for the changes, @raynelfss!
) * Initial: Add `compose_transforms` and `get_example_gates` to Rust. * Add: `compose_transform` logic in rust * Fix: Correct the behavior of `compose_transforms`. - Use `PackedOperation.control_flow` instead of `CONTROL_FLOW_OP_NAMES` to check if an instructuion is a control flow operation. - Remove panic statement when checking for example gates. - Use qreg when adding an instruction to the mock_dag in `compose_transforms`. - Add missing comparison check in for loop to compare the mapped instructions. - Use borrowed `DAGCircuit` instances in the recursion of `get_example_gates`, do not use extract. - Fix behavior of `get_example_gates` to return `PackedInstruction` instances instead of `NodeIndex`. * Fix: Leverage rust-based `circuit_to_dag` converters. - Use `circuit_to_dag` and `DAGCircuit::from_circuit_data` to convert `QuantumCircuit` instances. * Format: Fix indentation of import lines in `compose_transforms.rs` * Formatting: Separate complicated type aliases * Fix: Adapt to new `DAGCircuit` limitations * Format: Remove unused imports in BasisTranslator * Fix: Adapt to #13143 * Fix: Code review comments - Remove unused `circuit_to_dag` and `OperationRef` imports. - Streamline complex types into simpler aliases. - Rename `CircuitRep` to `CircuitFromPython`. - Reshape `get_example_gates` to work with `CircuitData` instances during its recursion. - Remove unnecessary clone of `gate_name` in `compose_transform`. - Use `mapped_instructions` values when iterating in `compose_transforms`. - Rename `DAGCircuit::substitute_node_with_dag` to `DAGCircuit::py_*` in rust. - Adapted `_basis_search` to return a tuple of tuples instead of a 4-tuple. * Fix: More commments from code review - Remove stale comment related to #3947 - Rename tuple instances to `GateIdentifier`. - Rename `doomed_nodes` to `nodes_to_replace`. - Add docstring for `get_example_gates`. - Rename `get_example_gates` to `get_gate_num_params`. Co-authored-by: Kevin Hartman <[email protected]> * Refactor: Rename `example_gates` to `gate_param_counts` - Remove `CircuitFromPython` and re-use original instance from `EquivalenceLibrary` after #12585 merged. --------- Co-authored-by: Kevin Hartman <[email protected]>
…kit#13137) * Initial: Add `compose_transforms` and `get_example_gates` to Rust. * Add: `compose_transform` logic in rust * Fix: Correct the behavior of `compose_transforms`. - Use `PackedOperation.control_flow` instead of `CONTROL_FLOW_OP_NAMES` to check if an instructuion is a control flow operation. - Remove panic statement when checking for example gates. - Use qreg when adding an instruction to the mock_dag in `compose_transforms`. - Add missing comparison check in for loop to compare the mapped instructions. - Use borrowed `DAGCircuit` instances in the recursion of `get_example_gates`, do not use extract. - Fix behavior of `get_example_gates` to return `PackedInstruction` instances instead of `NodeIndex`. * Fix: Leverage rust-based `circuit_to_dag` converters. - Use `circuit_to_dag` and `DAGCircuit::from_circuit_data` to convert `QuantumCircuit` instances. * Format: Fix indentation of import lines in `compose_transforms.rs` * Formatting: Separate complicated type aliases * Fix: Adapt to new `DAGCircuit` limitations * Format: Remove unused imports in BasisTranslator * Fix: Adapt to Qiskit#13143 * Fix: Code review comments - Remove unused `circuit_to_dag` and `OperationRef` imports. - Streamline complex types into simpler aliases. - Rename `CircuitRep` to `CircuitFromPython`. - Reshape `get_example_gates` to work with `CircuitData` instances during its recursion. - Remove unnecessary clone of `gate_name` in `compose_transform`. - Use `mapped_instructions` values when iterating in `compose_transforms`. - Rename `DAGCircuit::substitute_node_with_dag` to `DAGCircuit::py_*` in rust. - Adapted `_basis_search` to return a tuple of tuples instead of a 4-tuple. * Fix: More commments from code review - Remove stale comment related to Qiskit#3947 - Rename tuple instances to `GateIdentifier`. - Rename `doomed_nodes` to `nodes_to_replace`. - Add docstring for `get_example_gates`. - Rename `get_example_gates` to `get_gate_num_params`. Co-authored-by: Kevin Hartman <[email protected]> * Refactor: Rename `example_gates` to `gate_param_counts` - Remove `CircuitFromPython` and re-use original instance from `EquivalenceLibrary` after Qiskit#12585 merged. --------- Co-authored-by: Kevin Hartman <[email protected]>
…kit#13137) * Initial: Add `compose_transforms` and `get_example_gates` to Rust. * Add: `compose_transform` logic in rust * Fix: Correct the behavior of `compose_transforms`. - Use `PackedOperation.control_flow` instead of `CONTROL_FLOW_OP_NAMES` to check if an instructuion is a control flow operation. - Remove panic statement when checking for example gates. - Use qreg when adding an instruction to the mock_dag in `compose_transforms`. - Add missing comparison check in for loop to compare the mapped instructions. - Use borrowed `DAGCircuit` instances in the recursion of `get_example_gates`, do not use extract. - Fix behavior of `get_example_gates` to return `PackedInstruction` instances instead of `NodeIndex`. * Fix: Leverage rust-based `circuit_to_dag` converters. - Use `circuit_to_dag` and `DAGCircuit::from_circuit_data` to convert `QuantumCircuit` instances. * Format: Fix indentation of import lines in `compose_transforms.rs` * Formatting: Separate complicated type aliases * Fix: Adapt to new `DAGCircuit` limitations * Format: Remove unused imports in BasisTranslator * Fix: Adapt to Qiskit#13143 * Fix: Code review comments - Remove unused `circuit_to_dag` and `OperationRef` imports. - Streamline complex types into simpler aliases. - Rename `CircuitRep` to `CircuitFromPython`. - Reshape `get_example_gates` to work with `CircuitData` instances during its recursion. - Remove unnecessary clone of `gate_name` in `compose_transform`. - Use `mapped_instructions` values when iterating in `compose_transforms`. - Rename `DAGCircuit::substitute_node_with_dag` to `DAGCircuit::py_*` in rust. - Adapted `_basis_search` to return a tuple of tuples instead of a 4-tuple. * Fix: More commments from code review - Remove stale comment related to Qiskit#3947 - Rename tuple instances to `GateIdentifier`. - Rename `doomed_nodes` to `nodes_to_replace`. - Add docstring for `get_example_gates`. - Rename `get_example_gates` to `get_gate_num_params`. Co-authored-by: Kevin Hartman <[email protected]> * Refactor: Rename `example_gates` to `gate_param_counts` - Remove `CircuitFromPython` and re-use original instance from `EquivalenceLibrary` after Qiskit#12585 merged. --------- Co-authored-by: Kevin Hartman <[email protected]>
Fixes #13134
Summary
The following commits add
apply_operation_front
andapply_operation_back
as methods with rust-native arguments, and use them in the existent Python variants of these functions.Details and comments
With the DAGCircuit living completely in Rust as of now, we need to continue expanding its functionality across both environments (Python and Rust). As we continue to work on transpiler passes, we need methods that allow us to add operations using rust-native datatypes instead of using Python.
These commits focus on adding two methods:
apply_operation_front
to apply an operation to the front of the circuit.apply_operation_back
which applies the operation to the back of the circuit.These methods allow rust users to use native data types and add instructions to the circuit without needing to have valid interned indices for the Cargs/Qargs of said operations, as the current methods
push_front
andpush_back
do currently. This will decidedly enable us to build circuits more easily from Rust as transpiler passes, such as theBasisTranslator
, need to be able to do.Blockers
Option<Box<_>>
intoExtraInstructionAttributes
. #13127