Skip to content

Use rust-native error for CommutationAnalysis #16193

Open
raynelfss wants to merge 2 commits into
Qiskit:mainfrom
raynelfss:use-commutation-error
Open

Use rust-native error for CommutationAnalysis #16193
raynelfss wants to merge 2 commits into
Qiskit:mainfrom
raynelfss:use-commutation-error

Conversation

@raynelfss
Copy link
Copy Markdown
Contributor

@raynelfss raynelfss commented May 15, 2026

The following commits modify CommutationAnalysis to use rust-native errors throughout its pipeline.
This is done mostly by implementing DAGCircuitInnerError based on #16134 as a possible error in CommutationError.

Click here to see the actual diff of this PR.

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 2 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`.
@raynelfss raynelfss requested a review from a team as a code owner May 15, 2026 21:19
@raynelfss raynelfss added the on hold Can not fix yet label May 15, 2026
@raynelfss raynelfss requested a review from mtreinish May 15, 2026 21:19
@raynelfss raynelfss added 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 15, 2026
@qiskit-bot
Copy link
Copy Markdown
Collaborator

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

  • @Qiskit/terra-core

@coveralls
Copy link
Copy Markdown

Coverage Report for CI Build 25941913648

Coverage increased (+0.005%) to 87.715%

Details

  • Coverage increased (+0.005%) from the base build.
  • Patch coverage: 88 uncovered changes across 3 files (247 of 335 lines covered, 73.73%).
  • 17 coverage regressions across 6 files.

Uncovered Changes

File Changed Covered %
crates/circuit/src/dag_circuit.rs 325 239 73.54%
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

17 previously-covered lines in 6 files lost coverage.

File Lines Losing Coverage Coverage
crates/circuit/src/dag_circuit.rs 7 84.91%
crates/qasm2/src/lex.rs 5 92.54%
crates/circuit/src/parameter/symbol_expr.rs 2 74.17%
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: 123075
Covered Lines: 107955
Line Coverage: 87.71%
Coverage Strength: 953612.71 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