Skip to content

Improve ConsolidateBlocks error messages for NaN/Inf gate parameters#16584

Open
Pranava-Kumar wants to merge 1 commit into
Qiskit:mainfrom
Pranava-Kumar:fix/transpiler-nan-error-message
Open

Improve ConsolidateBlocks error messages for NaN/Inf gate parameters#16584
Pranava-Kumar wants to merge 1 commit into
Qiskit:mainfrom
Pranava-Kumar:fix/transpiler-nan-error-message

Conversation

@Pranava-Kumar

Copy link
Copy Markdown

Summary

When a circuit contains gates with NaN or Inf parameters, ConsolidateBlocks currently fails with a non-descript NoConvergence error (from scipy's eigenvalue decomposition in the Weyl decomposition), giving no indication of the root cause. This makes debugging circuits with invalid parameters very difficult.

This PR:

  1. Detects NaN/Inf in gate matrices before attempting decomposition and raises a clear error with block context
  2. Adds block context (gate names, parameters, qubit indices) to existing decomposition errors

Before

QiskitError: 'NoConvergence'

After

QiskitError: 'ConsolidateBlocks failed because the 2-qubit block contains a circuit gate with NaN or Inf parameters: rz(nan) on qubits [0]; cx() on qubits [0, 1]'

Related Issues

Fixes #16236

…iskit#16236)

Add explicit NaN/Inf detection in the ConsolidateBlocks pass and include
block context (gate name, parameters, qubits) in error messages, instead
of propagating a non-descript NoConvergence from scipy.

The error now shows which gate has NaN/Inf parameters, making debugging
significantly easier.

Fixes Qiskit#16236
@Pranava-Kumar
Pranava-Kumar requested a review from a team as a code owner July 13, 2026 19:38
@Pranava-Kumar
Pranava-Kumar requested a review from mtreinish July 13, 2026 19:38
@qiskit-bot qiskit-bot added the Community PR PRs from contributors that are not 'members' of the Qiskit repo label Jul 13, 2026
@qiskit-bot

Copy link
Copy Markdown
Collaborator

Thank you for opening a new pull request.

Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient.

While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone.

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

  • @Qiskit/terra-core

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

1 similar comment
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Community PR PRs from contributors that are not 'members' of the Qiskit repo

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Transpiler raises NoConvergence error due to NaN and Inf

3 participants