Skip to content

Use rust-native error for CommutationCancellation#16196

Open
raynelfss wants to merge 3 commits into
Qiskit:mainfrom
raynelfss:use-cancellation-error
Open

Use rust-native error for CommutationCancellation#16196
raynelfss wants to merge 3 commits into
Qiskit:mainfrom
raynelfss:use-cancellation-error

Conversation

@raynelfss
Copy link
Copy Markdown
Contributor

The following commits modify CommutationCancellation to use rust-native errors throughout its pipeline.
We implement the CommutationCancelError enumeration which derives from both DAGCircuitError and CommutationError as well as adding two new variants for operations with parameter expressions or undefined angles.

Pre-requisites

AI/LLM disclosure

  • I didn't use LLM tooling, or only used it privately.
  • I used the following tool to help write this PR description:
  • I used the following tool to generate or modify code:

raynelfss added 3 commits May 15, 2026 17:03
Use rust-native errors in `DAGCircuit`

This should be step 1 for splitting `PyDAGCircuit` from `DAGCircuit`.
The following commits assure that any rust accessible method for `DAGCircuit` that:
1. Does not take a `py` token;
2. Is a public method.
does not need to depend on `PyErr` to process any errors.
It is ensured that these errors:
- Maintain the level of detail that the previous ones did.
- Correctly map to the same Python exceptions as before.

The enumeration for these errors is called `DAGCircuitInnerError` (subject to change) and is implemented with `thiserror`. I chose this over `anyhow` because it is better for specifying where the error comes from based on its variant rather than the message it contains.

Lint: Use names instead of underscores

Add: `anyhow!` usage for `DAGCircuitError
- Use `anyhow!` for any error types that don't require tracking of any variables coming from the `DAG` or that are part of the function arguments.
- Consolidate the amount of `DAG` error variants down from 40+ to 21. Can be consolidated further.

Fix: Existing error formatting
- Use `this_error` to fix the formatting of current errors causing conflicts with their messages.
- Add `is_var` argument to differentiate Variables and Stretches in `VariableNotInlined`.

Fix: consolidate `RegistryAbsentObject` error.

Add: errors for `size` and `depth`.
The following commits modify `CommutationAnalysis` to use rust-native errors throughout its pipeline.
This is done mostly by implementing `DAGCircuitInnerError` based on Qiskit#16134 as a possible error in `CommutationError`.
The following commits modify `CommutationCancellation` to use rust-native errors throughout its pipeline.
We implement the `CommutationCancelError` enumeration which derives from both `DAGCircuitError` and `CommutationError` as well as adding two new variants for operations with parameter expressions or undefined angles.
@raynelfss raynelfss requested a review from a team as a code owner May 16, 2026 15:04
@raynelfss raynelfss requested a review from Cryoris May 16, 2026 15:04
@raynelfss raynelfss added on hold Can not fix yet Changelog: None Do not include in the GitHub Release changelog. Rust This PR or issue is related to Rust code in the repository mod: transpiler Issues and PRs related to Transpiler labels May 16, 2026
@qiskit-bot
Copy link
Copy Markdown
Collaborator

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

  • @Qiskit/terra-core

@raynelfss raynelfss added this to the 2.5.0 milestone May 16, 2026
@coveralls
Copy link
Copy Markdown

Coverage Report for CI Build 25965198003

Coverage decreased (-0.02%) to 87.694%

Details

  • Coverage decreased (-0.02%) from the base build.
  • Patch coverage: 103 uncovered changes across 4 files (260 of 363 lines covered, 71.63%).
  • 40 coverage regressions across 7 files.

Uncovered Changes

File Changed Covered %
crates/circuit/src/dag_circuit.rs 325 239 73.54%
crates/transpiler/src/passes/commutation_cancellation.rs 28 13 46.43%
crates/transpiler/src/commutation_checker.rs 1 0 0.0%
crates/transpiler/src/passes/unroll_3q_or_more.rs 1 0 0.0%

Coverage Regressions

40 previously-covered lines in 7 files lost coverage.

File Lines Losing Coverage Coverage
crates/qasm2/src/parse.rs 12 97.15%
crates/circuit/src/parameter/symbol_expr.rs 9 73.97%
crates/qasm2/src/lex.rs 9 91.52%
crates/circuit/src/dag_circuit.rs 7 84.91%
crates/circuit/src/parameter/parameter_expression.rs 1 91.04%
crates/transpiler/src/commutation_checker.rs 1 88.66%
crates/transpiler/src/passes/unitary_synthesis/decomposers.rs 1 94.71%

Coverage Stats

Coverage Status
Relevant Lines: 123093
Covered Lines: 107945
Line Coverage: 87.69%
Coverage Strength: 954903.04 hits per line

💛 - Coveralls

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 the GitHub Release changelog. mod: transpiler Issues and PRs related to Transpiler on hold Can not fix yet Rust This PR or issue is related to Rust code in the repository

Projects

Status: Ready

Development

Successfully merging this pull request may close these issues.

3 participants