Skip to content

Fix construction of IQP circuits #14363

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 3 commits into from
May 15, 2025
Merged

Fix construction of IQP circuits #14363

merged 3 commits into from
May 15, 2025

Conversation

alexanderivrii
Copy link
Member

Summary

As documented in https://docs.quantum.ibm.com/api/qiskit/qiskit.circuit.library.iqp_function, an Instantaneous quantum polynomial time (IQP) circuit consists of Hadamard gates, powers of T-gate, powers of CS-gate, and more Hadamard gates. However, a T-gate is P($\pi$/4), not P($\pi$/8), see https://docs.quantum.ibm.com/api/qiskit/qiskit.circuit.library.PhaseGate. This PR fixes the construction as used both within iqp_function and IQP.

Trivia

The bug was introduced in the original commit #4266 and survived porting to Rust #13241. Incidentally, the original commit pertains to one of the questions from (the internal) Qiskit 2.0 quiz.

@alexanderivrii alexanderivrii requested a review from a team as a code owner May 14, 2025 13:06
@alexanderivrii alexanderivrii added the Changelog: Bugfix Include in the "Fixed" section of the changelog label May 14, 2025
@qiskit-bot
Copy link
Collaborator

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

  • @Cryoris
  • @Qiskit/terra-core
  • @ajavadia

@coveralls
Copy link

coveralls commented May 14, 2025

Pull Request Test Coverage Report for Build 15022677549

Details

  • 2 of 2 (100.0%) changed or added relevant lines in 1 file are covered.
  • 15 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.002%) to 88.692%

Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/lex.rs 3 91.98%
crates/qasm2/src/parse.rs 12 97.15%
Totals Coverage Status
Change from base Build 15001620749: 0.002%
Covered Lines: 76037
Relevant Lines: 85732

💛 - Coveralls

Copy link
Contributor

@Cryoris Cryoris left a comment

Choose a reason for hiding this comment

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

wtf -- nice catch! Just to be sure: the example in the docs page has an odd number on the diagonals? Otherwise the IQP circuit is not very interesting, since it only has Clifford gates 🙂

Comment on lines 4 to 6
Fixed the construction of Instantaneous Quantum Polynomial time (IQP) circuits
in :class:`~qiskit.circuit.library.IQP` and by :func:`~qiskit.circuit.library.iqp`:
T-gate is equivalent to P(pi/4) and not to P(pi/8).
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this is a little clearer for users to understand (who didn't know the bug was a wrong angle)? 🙂

Suggested change
Fixed the construction of Instantaneous Quantum Polynomial time (IQP) circuits
in :class:`~qiskit.circuit.library.IQP` and by :func:`~qiskit.circuit.library.iqp`:
T-gate is equivalent to P(pi/4) and not to P(pi/8).
Fixed the construction of Instantaneous Quantum Polynomial time (IQP) circuits
in :class:`~qiskit.circuit.library.IQP` and by :func:`~qiskit.circuit.library.iqp`:
which was using powers of :math:`\sqrt{T}` gates instead of powers
of :math:`T` gates as single qubit operations.

Copy link
Member Author

Choose a reason for hiding this comment

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

This makes sense, I have reworded the note following your suggestion. I got rid of "single qubit operations" since H-gates are also single-qubit operations present in the circuit.

@ShellyGarion
Copy link
Member

perhaps you should also update the code of random_iqp ?

@alexanderivrii
Copy link
Member Author

@Cryoris:

Just to be sure: the example in the docs page has an odd number on the diagonals? Otherwise the IQP circuit is not very interesting, since it only has Clifford gates 🙂

Yes, one of the 3 numbers on the diagonal is odd. There are also odd off-diagonal entries which correspond to CS/CSdg gates, each requiring 3 T/Tdg gates.

@ShellyGarion:

perhaps you should also update the code of random_iqp ?

There is nothing left to be done for random_iqp as it first creates a random interaction matrix (which was already correct) and then creates the corresponding IQP circuit (which got fixed). The example in the docs should get fixed automatically. I also decided against explicitly mentioning random_iqp in the release notes as this function did not change.

@Cryoris Cryoris added this pull request to the merge queue May 15, 2025
Merged via the queue into Qiskit:main with commit 6ca3d22 May 15, 2025
24 checks passed
@kevinhartman kevinhartman added the stable backport potential The bug might be minimal and/or import enough to be port to stable label May 15, 2025
@kevinhartman kevinhartman added this to the 2.0.1 milestone May 15, 2025
mergify bot pushed a commit that referenced this pull request May 15, 2025
* Fix construction of IQP circuits

* release notes

* rewording release notes based on suggestion

(cherry picked from commit 6ca3d22)

# Conflicts:
#	crates/accelerate/src/circuit_library/iqp.rs
@Cryoris
Copy link
Contributor

Cryoris commented May 15, 2025

@Mergifyio backport stable/1.4

Copy link
Contributor

mergify bot commented May 15, 2025

backport stable/1.4

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request May 15, 2025
* Fix construction of IQP circuits

* release notes

* rewording release notes based on suggestion

(cherry picked from commit 6ca3d22)

# Conflicts:
#	crates/accelerate/src/circuit_library/iqp.rs
github-merge-queue bot pushed a commit that referenced this pull request May 15, 2025
* Fix construction of IQP circuits (#14363)

* Fix construction of IQP circuits

* release notes

* rewording release notes based on suggestion

(cherry picked from commit 6ca3d22)

# Conflicts:
#	crates/accelerate/src/circuit_library/iqp.rs

* Fix merge conflicts

---------

Co-authored-by: Alexander Ivrii <alexi@il.ibm.com>
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
* Fix construction of IQP circuits

* release notes

* rewording release notes based on suggestion
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 stable backport potential The bug might be minimal and/or import enough to be port to stable
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants