Sorts gate array to have deterministic gate selection#16139
Conversation
|
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:
|
|
Thanks! That was fast. Do you think there is any meaningful test we could add? Could you also add a (short) bugfix release note? |
|
Sure, maybe we can add a test case that runs it twice and compares the gate count? |
|
The randomisation of |
| gates_1q = sorted(set(_BASIS_1Q.keys()) - {"v", "w", "id", "iden", "sinv"}) | ||
| gates_2q = sorted(_BASIS_2Q.keys()) |
There was a problem hiding this comment.
sorted is perhaps a bit unnecessarily heavy as a normalisation step; dict is already consistently ordered (including the dict_keys iterator), so the sort of gates_2q isn't needed, and the top line can be something along the lines of
ignore_1q = {"v", "w", "id", "iden", "sinv"}
gates_1q = [gate for gate in _BASIS_1Q if gate not in ignore_1q]and avoid the extra
There was a problem hiding this comment.
I updated it to the snippet you mentioned, I was thinking it was straightforward to just sort it it to be consistent across any changes in the source dictionary as well.
|
Lol, Jake beat me at replying :) |
Coverage Report for CI Build 26029779428Coverage decreased (-0.002%) to 87.694%Details
Uncovered ChangesNo uncovered changes found. Coverage Regressions16 previously-covered lines in 5 files lost coverage.
Coverage Stats
💛 - Coveralls |
|
I added a test case that passes in different seeds to a subprocess, without the change the test case failed and it was passing with it. |
|
Thanks @amruthpremjith. I think the fix and the test look ok now (taking the comparing to a "blessed" value approach from Jake's comment, but I would like to have @jakelishman take another look as well. |
|
Some of the tests fail because we seem to get different blessed values on different platforms. @amruthpremjith, consider changing the test to check that all the results come back the same. |
|
@alexanderivrii, I've updated the test to first generate the circuit and then use that with varying hashes. |
alexanderivrii
left a comment
There was a problem hiding this comment.
Thanks! I have retriggered CI, let's see what happens. The fix itself looks good, but I believe formatting might complain, please run black if you have not done so already.
| check=True | ||
| ) | ||
|
|
||
| # self.assertEqual(result.stdout, "OrderedDict({'sxdg': 10, 'sdg': 10, 'iswap': 9, 'cz': 9, 'id': 9, 'h': 8, 'cy': 8, 'x': 6, 'ecr': 6, 'cx': 6, 'dcx': 4, 'swap': 4, 's': 4, 'y': 3, 'sx': 3, 'z': 1})\n") |
There was a problem hiding this comment.
You should remove this comment now.
…emjith/qiskit into random-cliff-array-sort
|
@alexanderivrii, I ran lint and added a bugfix note, could you please check now? |
alexanderivrii
left a comment
There was a problem hiding this comment.
Thanks for remembering to add the release note. I have left a few minor suggestions.
| # Delete all sections that you do not need. You can have more than one section in a file, and | ||
| # more than one bullet point per section. This is a regular YAML file, and all text should use | ||
| # Sphinx's flavor of rST (restructured text). Each bullet point is a separate "release note". | ||
| # | ||
| # Each public bug fix, feature, deprecation, and behavior change needs a release note. | ||
| # Documentation- or internal-only changes do not need release notes. | ||
| # | ||
| # Each bullet point appears without any context, so make sure each can be read in isolation. The | ||
| # reader will not see your code change, the issue, or any other bullet points in this file. You | ||
| # might need to repeat yourself between bullets. | ||
| # | ||
| # Use Sphinx cross-references like :meth:`.YourClass.your_method` whenever mentioning a | ||
| # function/class/method by name. | ||
| # | ||
| # Use `- |` for multiline YAML strings (like in the "fixes" example in this template) to preserve | ||
| # newlines, which you need for Sphinx syntax. | ||
| # | ||
| # There are some rare additional sections listed in `releasenotes/config.yaml` not included here. |
There was a problem hiding this comment.
You can delete this comment (but pay attention not to delete the initial "---" line).
|
|
||
| fixes: | ||
| - | | ||
| Always return consistent clifford circuits while calling ``random_clifford_circuit()`` with same inputs |
There was a problem hiding this comment.
I think "deterministic" might be a bit more precise than "consistent", maybe something like:
| Always return consistent clifford circuits while calling ``random_clifford_circuit()`` with same inputs | |
| Fixed :func:`.random_clifford_circuit` to produce deterministic results across multiple runs given the same ``seed``. |
| - | | ||
| Always return consistent clifford circuits while calling ``random_clifford_circuit()`` with same inputs | ||
|
|
||
| Fixes `#16138 <https://github.com/Qiskit/qiskit/issues/16138>`. No newline at end of file |
There was a problem hiding this comment.
You need the two trailing underscores for this to render nicely:
| Fixes `#16138 <https://github.com/Qiskit/qiskit/issues/16138>`. | |
| Fixes `#16138 <https://github.com/Qiskit/qiskit/issues/16138>`__. |
Also you want an empty trailing line (see the circled minus sign when you look at the changed files).
There was a problem hiding this comment.
updated the comments, pls check
AI/LLM disclosure
Fix #16138
Sort the gate array before selecting from it to return the same gates for the same set of inputs.
Tested with and without changes.
Without change
With change