Skip to content

Conversation

mergify[bot]
Copy link
Contributor

@mergify mergify bot commented May 7, 2025

Summary

Fixes a problem described here: running the SolovayKitaevSynthesis unitary synthesis plugin repeatedly incorrectly reuses the set of basis gates specified on the very first run. For example,

circuit = QuantumCircuit(1)
circuit.rx(0.8, 0)
unitary = Operator(circuit).data
plugin = SolovayKitaevSynthesis()

# First, use the ["h", "t", "tdg"] set
out = plugin.run(unitary, basis_gates=["h", "t", "tdg"])
print(out.count_ops())
self.assertLessEqual(set(out.count_ops().keys()), {"h", "t", "tdg"})

# Second, use the ["h", "s"] set
out = plugin.run(unitary, basis_gates=["h", "s", "sdg"])
self.assertLessEqual(set(out.count_ops().keys()), {"h", "s", "sdg"})
print(out.count_ops())

synthesizes both times to the first specified basis set of ["h", "t", "tdg"]. Creating two different SolovayKitaevSynthesis plugins does not solve this, since the caching is done via a class-level attribute.

The fix (many thanks to @eliarbel for the suggestion!) consists of storing a dictionary from the basis gate sets to the correspoding basis approximations. UPDATE: after review and online discussion, we have decided not to store the dictionary but instead to regenerate the basic approximations whenever the set of basis gates or the depth used for generation changes from the previous run.

Needed for #14225.


This is an automatic backport of pull request #14304 done by [Mergify](https://mergify.com).

* extending SolovayKitaevSynthesis plugin caching logic to take the basis gates into account

* regenerating cached values following review comment

(cherry picked from commit 6d4c928)
@mergify mergify bot requested a review from a team as a code owner May 7, 2025 13:46
@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

@github-actions github-actions bot added the Changelog: Bugfix Include in the "Fixed" section of the changelog label May 7, 2025
@github-actions github-actions bot added this to the 1.4.3 milestone May 7, 2025
@Cryoris Cryoris enabled auto-merge May 7, 2025 13:55
@coveralls
Copy link

Pull Request Test Coverage Report for Build 14885010665

Details

  • 9 of 9 (100.0%) changed or added relevant lines in 1 file are covered.
  • 3 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.005%) to 88.119%

Files with Coverage Reduction New Missed Lines %
crates/accelerate/src/unitary_synthesis.rs 1 94.79%
crates/qasm2/src/lex.rs 2 93.23%
Totals Coverage Status
Change from base Build 14846667426: 0.005%
Covered Lines: 72900
Relevant Lines: 82729

💛 - Coveralls

@Cryoris Cryoris added this pull request to the merge queue May 7, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 7, 2025
@alexanderivrii alexanderivrii added this pull request to the merge queue May 8, 2025
Merged via the queue into stable/2.0 with commit 4523ef9 May 8, 2025
27 checks passed
@mtreinish mtreinish deleted the mergify/bp/stable/2.0/pr-14304 branch May 8, 2025 08:47
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.

4 participants