Skip to content

Use rust-native error for UnitarySynthesis#16281

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

Use rust-native error for UnitarySynthesis#16281
raynelfss wants to merge 2 commits into
Qiskit:mainfrom
raynelfss:use-unitary-synthesis-error

Conversation

@raynelfss
Copy link
Copy Markdown
Contributor

@raynelfss raynelfss commented May 26, 2026

The following commits modify UnitarySynthesis to use rust-native errors throughout its pipeline. We implement the UnitarySynthesisError enumeration which derives from:

  • DAGError;
  • PyErr for XXDecomposer and python gates purposes only;
  • QSDError from Synthesis;
  • and implements two variants: NoPreferredDirection and SynthesisFidelityOutOfRange used with decomposers.

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:

The following commits modify `UnitarySynthesis` to use rust-native errors throughout its pipeline.
We implement the `UnitarySynthesisError` enumeration which derives from `DAGError`; `PyErr` for `XXDecomposer` and python gates purposes only; QSDError from Synthesis, and implements two variants: `NoPreferredDirection` and `SynthesisFidelityOutOfRange` used with decomposers.
@raynelfss raynelfss added this to the 2.5.0 milestone May 26, 2026
@raynelfss raynelfss requested a review from a team as a code owner May 26, 2026 17:35
@raynelfss raynelfss requested a review from gadial May 26, 2026 17:35
@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 26, 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

coveralls commented May 26, 2026

Coverage Report for CI Build 26655587578

Warning

Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes.
Quick fix: rebase this PR. Learn more →

Coverage decreased (-0.007%) to 87.551%

Details

  • Coverage decreased (-0.007%) from the base build.
  • Patch coverage: 5 uncovered changes across 1 file (28 of 33 lines covered, 84.85%).
  • 28 coverage regressions across 5 files.

Uncovered Changes

File Changed Covered %
crates/transpiler/src/passes/unitary_synthesis/mod.rs 24 19 79.17%
Total (2 files) 33 28 84.85%

Coverage Regressions

28 previously-covered lines in 5 files lost coverage.

File Lines Losing Coverage Coverage
crates/qasm2/src/parse.rs 12 97.15%
crates/circuit/src/parameter/symbol_expr.rs 8 73.93%
crates/qasm2/src/lex.rs 6 91.77%
crates/circuit/src/parameter/parameter_expression.rs 1 91.04%
crates/transpiler/src/passes/unitary_synthesis/mod.rs 1 96.55%

Coverage Stats

Coverage Status
Relevant Lines: 123934
Covered Lines: 108505
Line Coverage: 87.55%
Coverage Strength: 963978.36 hits per line

💛 - Coveralls

gadial
gadial previously approved these changes May 27, 2026
Copy link
Copy Markdown
Contributor

@gadial gadial left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. One question about which errors are raised (which is actually a legacy of the old code).

fn from(value: UnitarySynthesisError) -> Self {
match value {
UnitarySynthesisError::NoPreferredDirection(_) => {
QiskitError::new_err(value.to_string())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we using QiskitError for one and PyValueError for the other?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how the original error was.

This is what it looked like for NoPreferredDirection:

return Err(QiskitError::new_err(format!(
concat!(
"No preferred direction of gate on qubits {:?} ",
"could be determined from coupling map or gate lengths / gate errors."
),
qubits
)));

This is for SynthesisFidelityOutOfRange

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 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.

4 participants