Skip to content
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

Make BarrierBeforeFinalMeasurements deterministic #9568

Merged
merged 2 commits into from
Feb 10, 2023

Conversation

jakelishman
Copy link
Member

Summary

The barrier-merging step at the end directly converted its inner (unordered) sets of bits into (ordered) lists, which is an operation dependent on PYTHONHASHSEED. This can have an impact on subsequent topological iteration orders, if there are any barriers that are not full-width in the circuit, which can in turn cause later stochastic transpiler passes to have different outputs for fixed random seeds, depending on PYTHONHASHSEED.

Details and comments

This is what's causing the non-determinism in the test on #9560.

The barrier-merging step at the end directly converted its inner
(unordered) sets of bits into (ordered) lists, which is an operation
dependent on `PYTHONHASHSEED`.  This can have an impact on subsequent
topological iteration orders, if there are any barriers that are not
full-width in the circuit, which can in turn cause later stochastic
transpiler passes to have different outputs for fixed random seeds,
depending on `PYTHONHASHSEED`.
@jakelishman jakelishman added Changelog: Bugfix Include in the "Fixed" section of the changelog mod: transpiler Issues and PRs related to Transpiler labels Feb 10, 2023
@jakelishman jakelishman requested a review from a team as a code owner February 10, 2023 16:28
@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 the following people are requested to review this:

  • @Qiskit/terra-core

@@ -57,6 +57,7 @@ class MergeAdjacentBarriers(TransformationPass):

def run(self, dag):
"""Run the MergeAdjacentBarriers pass on `dag`."""
indices = {qubit: index for index, qubit in enumerate(dag.qubits)}
Copy link
Member

Choose a reason for hiding this comment

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

Lol, it strikes again. This also was a likely source of a performance regression in how I implemented #9569 . We really need to implement #9389 and cache this in the dagcircuit.

@coveralls
Copy link

coveralls commented Feb 10, 2023

Pull Request Test Coverage Report for Build 4145966758

  • 2 of 2 (100.0%) changed or added relevant lines in 1 file are covered.
  • 2 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-0.002%) to 85.271%

Files with Coverage Reduction New Missed Lines %
qiskit/transpiler/passes/synthesis/unitary_synthesis.py 2 93.97%
Totals Coverage Status
Change from base Build 4135306650: -0.002%
Covered Lines: 67241
Relevant Lines: 78856

💛 - Coveralls

Copy link
Member

@mtreinish mtreinish left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the quick update. Do you think this is applicable for 0.23.2 and we should tag this for backport?

@jakelishman
Copy link
Member Author

I'm nervous about backporting because of the RNG changes, but I think we're technically within our rights to if we wanted, because it is a bugfix.

@mergify mergify bot merged commit 26886a1 into Qiskit:main Feb 10, 2023
@jakelishman jakelishman deleted the deterministic-merge-barriers branch February 10, 2023 18:05
nbronn pushed a commit to nbronn/qiskit-terra that referenced this pull request Feb 13, 2023
* Make `BarrierBeforeFinalMeasurements` deterministic

The barrier-merging step at the end directly converted its inner
(unordered) sets of bits into (ordered) lists, which is an operation
dependent on `PYTHONHASHSEED`.  This can have an impact on subsequent
topological iteration orders, if there are any barriers that are not
full-width in the circuit, which can in turn cause later stochastic
transpiler passes to have different outputs for fixed random seeds,
depending on `PYTHONHASHSEED`.

* Add direct test of MergeAdjacentBarriers
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 mod: transpiler Issues and PRs related to Transpiler
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants