Skip to content

Conversation

@Shivam-Bhardwaj
Copy link

Description

This PR refactors the Target::instruction_supported method to follow a cleaner, more natural flow as suggested in issue #15322.

Changes

Refactored the flow to:

  1. If name not in _gate_name_map → return false
  2. If non-global instructions and mismatched qargs → return false
  3. If parameters don't match → return false
  4. Return true

Improvements

  • Simplified flow: The code now follows a linear progression that's easier to understand
  • Eliminated redundant checks: Removed the early return for Variadic operations with parameters, which simplifies the code
  • Safer indexing: Replaced gate_map[operation_name] with gate_map.get(operation_name) to avoid potential panics
  • Better comments: Added clear comments indicating each step of the validation process

Testing

  • ✅ Code compiles without errors
  • ✅ No linter errors
  • ✅ Logic flow verified through code review
  • ✅ All edge cases preserved (Variadic operations, Global qargs, parameter validation, angle bounds)

The refactoring preserves all existing functionality while improving code readability and maintainability.

Fixes #15322

@qiskit-bot qiskit-bot added the Community PR PRs from contributors that are not 'members' of the Qiskit repo label Nov 16, 2025
@qiskit-bot
Copy link
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

CLAassistant commented Nov 16, 2025

CLA assistant check
All committers have signed the CLA.

@CLAassistant
Copy link

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.


root seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

Refactored the instruction_supported method to follow a more natural
flow as suggested in issue Qiskit#15322:

1. If name not in _gate_name_map - return false
2. If non-global instructions and mismatched qargs - return false
3. If parameters don't match - return false
4. Return true

This simplifies the code by:
- Eliminating early returns for Variadic operations with parameters
- Making the qargs checking logic clearer and more straightforward
- Following a more linear flow that's easier to understand

The refactoring preserves all existing functionality while improving
code readability and maintainability.
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

None yet

Development

Successfully merging this pull request may close these issues.

Improve the logic of Target::instruction_supported.

3 participants