Skip to content

Circuits with control flow now raise a proper error when circuit_to_instruction is called #13921

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 27, 2025

Conversation

1ucian0
Copy link
Member

@1ucian0 1ucian0 commented Feb 24, 2025

Summary

Fixes #11379

Details and comments

Converting a quantum circuit to a gate with circuit_to_instruction now fails properly when given circuit contains control flow instructions.

@1ucian0 1ucian0 requested a review from a team as a code owner February 24, 2025 23:10
@qiskit-bot
Copy link
Collaborator

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

  • @Qiskit/terra-core

@1ucian0 1ucian0 added this to the 2.0.0 milestone Feb 24, 2025
@coveralls
Copy link

coveralls commented Feb 25, 2025

Pull Request Test Coverage Report for Build 13564994279

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 4 of 4 (100.0%) changed or added relevant lines in 1 file are covered.
  • 474 unchanged lines in 26 files lost coverage.
  • Overall coverage decreased (-0.1%) to 87.874%

Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/expr.rs 1 94.23%
qiskit/pulse/builder.py 1 85.31%
qiskit/pulse/instructions/reference.py 1 90.32%
qiskit/user_config.py 1 86.87%
crates/qasm2/src/lex.rs 3 92.73%
qiskit/circuit/library/arithmetic/integer_comparator.py 4 94.67%
qiskit/circuit/library/arithmetic/piecewise_linear_pauli_rotations.py 5 92.09%
qiskit/qpy/binary_io/value.py 5 86.26%
qiskit/circuit/library/arithmetic/linear_pauli_rotations.py 6 89.04%
qiskit/circuit/library/arithmetic/linear_amplitude_function.py 8 92.31%
Totals Coverage Status
Change from base Build 13512719904: -0.1%
Covered Lines: 77547
Relevant Lines: 88248

💛 - Coveralls

Copy link
Contributor

@ElePT ElePT left a comment

Choose a reason for hiding this comment

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

LGTM, just one minor typo

Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com>
Copy link
Contributor

@ElePT ElePT left a comment

Choose a reason for hiding this comment

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

LGTM

@1ucian0 1ucian0 added this pull request to the merge queue Feb 27, 2025
Merged via the queue into Qiskit:main with commit a00279b Feb 27, 2025
19 checks passed
raynelfss added a commit to raynelfss/qiskit that referenced this pull request Feb 28, 2025
This method was added to fix a performance regression introduced by Qiskit#13921. This check should be quicker than the multiple calls to `isinstance`.
mtreinish added a commit to mtreinish/qiskit-core that referenced this pull request Mar 1, 2025
In Qiskit#13921 a check was added to circuit_to_instruction() for determining
if the circuit has a control flow op. This check was adding significant
overhead to the function, nightly asv benchmarks are showing up to a ~9x
slowdown. Qiskit#13921 attempted to fix this regression but did so by adding a
new API which isn't applicable at this point for 2.0. That PR could/should
still be used in 2.1. In the meantime this commit seeks to solve the
performance regression by adjusting how the check is performed to
mitigate the runtime regression for 2.0.
github-merge-queue bot pushed a commit that referenced this pull request Mar 2, 2025
In #13921 a check was added to circuit_to_instruction() for determining
if the circuit has a control flow op. This check was adding significant
overhead to the function, nightly asv benchmarks are showing up to a ~9x
slowdown. #13921 attempted to fix this regression but did so by adding a
new API which isn't applicable at this point for 2.0. That PR could/should
still be used in 2.1. In the meantime this commit seeks to solve the
performance regression by adjusting how the check is performed to
mitigate the runtime regression for 2.0.
@ElePT ElePT added the Changelog: Bugfix Include in the "Fixed" section of the changelog label Mar 31, 2025
github-merge-queue bot pushed a commit that referenced this pull request May 28, 2025
* Add: Add method has_control_flow_op(), to `QuantumCircuit`

This method was added to fix a performance regression introduced by #13921. This check should be quicker than the multiple calls to `isinstance`.

* Lint: Fix formatting

* Lint: Removed unused import and f-string

* Docs: Add release note
- Add `has_control_flow_op` to autogenerate docs.

* Fix: Addressing review comments

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>

* Docs: Fix formatting issue in `QuantumCircuit` docstring.

* Lint: Fix formatting bug in `QuantumCircuit`.

* Test: Add testcases
- One test case with a regular control flow operation and another with a custom one.

* Test: Remove unsupported test and extend original test.
- Implement a combinatorics based test for control flow operations.

* Fix: Import order in `test_circuit_operations`

* Update test/python/circuit/test_circuit_operations.py

---------

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
rahaman-quantum pushed a commit to rahaman-quantum/qiskit that referenced this pull request Jun 20, 2025
* Add: Add method has_control_flow_op(), to `QuantumCircuit`

This method was added to fix a performance regression introduced by Qiskit#13921. This check should be quicker than the multiple calls to `isinstance`.

* Lint: Fix formatting

* Lint: Removed unused import and f-string

* Docs: Add release note
- Add `has_control_flow_op` to autogenerate docs.

* Fix: Addressing review comments

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>

* Docs: Fix formatting issue in `QuantumCircuit` docstring.

* Lint: Fix formatting bug in `QuantumCircuit`.

* Test: Add testcases
- One test case with a regular control flow operation and another with a custom one.

* Test: Remove unsupported test and extend original test.
- Implement a combinatorics based test for control flow operations.

* Fix: Import order in `test_circuit_operations`

* Update test/python/circuit/test_circuit_operations.py

---------

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: Bugfix Include in the "Fixed" section of the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Control flow instructions don't work with circuit_to_instruction
4 participants