-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Improve speed of random circuit generation #4428
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
Conversation
mpharrigan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand the logic of how this works
cirq-core/cirq/experiments/random_quantum_circuit_generation.py
Outdated
Show resolved
Hide resolved
|
Technically a breaking change because of the change of API for the gate factories and the seed issue you noted. I think it should be fine |
|
Do you have profiling data? Does this indeed speed things up? |
|
Improves generation of 5 circuits of depth 13000 from around 7.3s to around 5.1s on my machine. The time lost due to the "retry" strategy compared to the deterministic strategy was insignificant. |
|
Sweet. I'm a little surprised the retry logic doesn't cause a slowdown; but I guess it's exceedingly unlikely for you to have to retry more than a couple times. Thanks for profiling it. |
|
FWIW I also tried an alternate approach, just caching the canonicalization of the XZPowGate, since that is called by the equality checker, and the same gates were reused over and over. That reduced the time from 7.3s to 6.1s. So that's about half the overhead in the equality tester for XZPowGates. Don't think we should do anything since we've solved the problem better already. Just a data point. |
|
Wait, this was really dumb. After reading the above again, I realized all we had to do for this is change |
This reverts commit 75eccd3.
|
I'll remove the breaking change label since this was reverted |
Fixes #4337 (again) Changes equality check to identity check to give the perf improvement. Since the gate instances are reused, and since equality checking if XZPowGate is very expensive, we change equality check to identity check and get a big perf boost. This issue was originally fixed in a different way in #4428, but that has been reverted in llieu of this fix which is simpler, faster, and not a breaking change. ref #4428 (comment) @mpharrigan
Fixes quantumlib#4337 Changes single-qubit layer generation into two steps. First step creates the `{qid: gate_index}` lookup so that we can compare against gate_index equality instead of gate equality. Then the second step is generating the moment from that lookup. ~~Note the change in algo will cause the random circuits generated by a specific seed to change (hence the change in one test case). If this is a blocker, it should be possible to revert to the old retry algo but just compare indexes instead of gates.~~ Reverted to the retry algo since some of the xeb tests were tied to the generated circuit. Also note any change like this assumes that each gate only appears once in the allowed-gates list. I assume that's a safe assumption. @mpharrigan
Fixes quantumlib#4337 (again) Changes equality check to identity check to give the perf improvement. Since the gate instances are reused, and since equality checking if XZPowGate is very expensive, we change equality check to identity check and get a big perf boost. This issue was originally fixed in a different way in quantumlib#4428, but that has been reverted in llieu of this fix which is simpler, faster, and not a breaking change. ref quantumlib#4428 (comment) @mpharrigan
Fixes quantumlib#4337 Changes single-qubit layer generation into two steps. First step creates the `{qid: gate_index}` lookup so that we can compare against gate_index equality instead of gate equality. Then the second step is generating the moment from that lookup. ~~Note the change in algo will cause the random circuits generated by a specific seed to change (hence the change in one test case). If this is a blocker, it should be possible to revert to the old retry algo but just compare indexes instead of gates.~~ Reverted to the retry algo since some of the xeb tests were tied to the generated circuit. Also note any change like this assumes that each gate only appears once in the allowed-gates list. I assume that's a safe assumption. @mpharrigan
Fixes quantumlib#4337 (again) Changes equality check to identity check to give the perf improvement. Since the gate instances are reused, and since equality checking if XZPowGate is very expensive, we change equality check to identity check and get a big perf boost. This issue was originally fixed in a different way in quantumlib#4428, but that has been reverted in llieu of this fix which is simpler, faster, and not a breaking change. ref quantumlib#4428 (comment) @mpharrigan
Fixes #4337
Changes single-qubit layer generation into two steps. First step creates the
{qid: gate_index}lookup so that we can compare against gate_index equality instead of gate equality. Then the second step is generating the moment from that lookup.Note the change in algo will cause the random circuits generated by a specific seed to change (hence the change in one test case). If this is a blocker, it should be possible to revert to the old retry algo but just compare indexes instead of gates.Reverted to the retry algo since some of the xeb tests were tied to the generated circuit.Also note any change like this assumes that each gate only appears once in the allowed-gates list. I assume that's a safe assumption.
@mpharrigan