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)
@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:57
@Cryoris Cryoris added this pull request to the merge queue May 7, 2025
Merged via the queue into stable/1.4 with commit 13bce54 May 7, 2025
19 of 20 checks passed
@jakelishman jakelishman deleted the mergify/bp/stable/1.4/pr-14304 branch June 9, 2025 15:41
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.

3 participants