Skip to content

Use rust-native error for ConsolidateBlocks#16198

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

Use rust-native error for ConsolidateBlocks#16198
raynelfss wants to merge 2 commits into
Qiskit:mainfrom
raynelfss:use-consolidate-blocks-error

Conversation

@raynelfss
Copy link
Copy Markdown
Contributor

The following commits modify ConsolidateBlocks to use rust-native errors throughout its pipeline.
We implement the ConsolidateBlocksError enumeration which derives from DAGCircuitError, and CircuitDataError, as well as adding two new variants for python specific errors dealing with matrices and controlled u gates.

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 `ConsolidateBlocks` to use rust-native errors throughout its pipeline.
We implement the `ConsolidateBlocksError` enumeration which derives from `DAGCircuitError`, and `CircuitDataError`, as well as adding two new variants for python specific errors dealing with matrices and controlled u gates.
@raynelfss raynelfss added this to the 2.5.0 milestone May 16, 2026
@raynelfss raynelfss requested a review from a team as a code owner May 16, 2026 16:15
@raynelfss raynelfss requested a review from mtreinish May 16, 2026 16:15
@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

@coveralls
Copy link
Copy Markdown

Coverage Report for CI Build 25966756171

Coverage decreased (-0.01%) to 87.698%

Details

  • Coverage decreased (-0.01%) from the base build.
  • Patch coverage: 94 uncovered changes across 3 files (286 of 380 lines covered, 75.26%).
  • 37 coverage regressions across 5 files.

Uncovered Changes

File Changed Covered %
crates/circuit/src/dag_circuit.rs 325 239 73.54%
crates/transpiler/src/passes/consolidate_blocks.rs 50 43 86.0%
crates/transpiler/src/passes/unroll_3q_or_more.rs 1 0 0.0%

Coverage Regressions

37 previously-covered lines in 5 files lost coverage.

File Lines Losing Coverage Coverage
crates/qasm2/src/parse.rs 18 96.68%
crates/circuit/src/dag_circuit.rs 7 84.91%
crates/circuit/src/parameter/symbol_expr.rs 6 74.01%
crates/qasm2/src/lex.rs 5 92.54%
crates/transpiler/src/passes/unitary_synthesis/decomposers.rs 1 94.71%

Coverage Stats

Coverage Status
Relevant Lines: 123103
Covered Lines: 107959
Line Coverage: 87.7%
Coverage Strength: 955119.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