-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add tutorial on selecting qubits and calibrating for an experiment #4108
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
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
@@ -0,0 +1,799 @@ | |||
{ |
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.
@mpharrigan, should the defaults be set to the cycle depths above in Cirq?
Why do you use just one processor?
Reply via ReviewNB
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.
Not specifying n_processes=1
leads to a hanging response on Colab.
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.
You can probably see improved performance if you set characterize_{angle}
to false except for zeta, chi, gamma (like is done for floquet). Although floquet is also set to false fo chi
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.
Another option is to change the ndefault in XEB wrapper to n_processes=max(1, #of processors - 1)
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.
it's currently the multiprocessing default of # of processors
@@ -0,0 +1,799 @@ | |||
{ |
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 would be against doing characterizations together: they take a long time and the fresher the results are, the better resulting quality.
After each characterization the corresponding calibrated circuits should be executed immediately. The code here should be merged with the code below with loop over options being the outermost one.
Reply via ReviewNB
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.
Good feedback, thanks! Perhaps this will make the results closer to what is expected...
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 would split these up so folks following along can pick one or the other to copy-paste without having to disentangle a for loop
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.
Agree. It's split up now and should be easy to skip/comment out either calibration.
I still do both calibrations then run Loschmidt instead of [calibrate, Loschmidt] x 2. Results are looking much better now I think, so maybe this is fine. Let me know what you think @mrwojtek.
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 see what you've been trying to do. I'll do some adjustments to the calibration methods to make your workflow easier.
However, I propose some refactor which will simplify things significantly in this tutorial. It will also probably improve the performance (I expect that Floquet calibration can be improved if ran separately):
- "Floquet calibration" section should just have the first cell, the one which defines floquet_options. Remove the second cell.
- "XEB calibration" section should just have the first cell, the one which defines xeboptions. Remove the second cell.
- In the "Run Loschmidt echo benchmark" you can just define:
calibrations = {
"No calibration": None,
"Floquet calibration": floquet_options,
"XEB calibration": xeb_options`
}
Then you just need to do:
batch_to_compensate, characterization_requests = cg.prepare_characterization_for_circuits_moments(loschmidt_echo_batch, options)
characterizations = cg.run_calibrations(
characterization_requests,
sampler,
)
batch = [
cg.make_zeta_chi_gamma_compensation_for_moments(circ, characterizations).circuit
for circ in batch_to_calibrate
]
results = sampler.run_batch(programs=batch, repetitions=nreps)
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.
This is now done, with a note to update after https://github.com//pull/4118 is merged.
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 also added another calibration for the user-defined circuit, instead of reusing one of the characterizations from the Loschmidt echo, as we discussed offline.
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.
@rmlarose I don't see the changes mentioned here in this document? Did you forget to push your changes?
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.
Just to document it here, they were in dfbe326 which was reverted.
@@ -0,0 +1,799 @@ | |||
{ |
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 think that it might be better to use sampler.run_batch, there is less boiler-plate that way. Is there a particular reason that you're using engine.run_batch?
Reply via ReviewNB
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.
Agree. I tried moving to sampler.run_batch
but, if I recall correctly, the return type was different and didn't work with to_ground_state_prob
. Just being lazy though, I'll move to sampler
only semantics.
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.
All engine
s replaced by sampler
s.
@@ -0,0 +1,799 @@ | |||
{ |
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.
This is strange, the results are unexpected. Does your branch include https://github.com//pull/4092 which contain a fix for poor XEB performance?
Reply via ReviewNB
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.
That was in the v0.11 release, so yes it should. (My branch is just cirq==0.11.0.)
@@ -0,0 +1,799 @@ | |||
{ |
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.
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.
Done (note this was taken from https://quantumai.google/cirq/tutorials/google/start).
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.
Yeah I assumed this was a copy paste but good to have it fixed here at least
@@ -0,0 +1,799 @@ | |||
{ |
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.
worth opening an issue to support this function natively? namely: provide a list of metrics and generate a grid of plots. Note that if you add a third metric it looks rather squished.
Reply via ReviewNB
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.
At least for tutorials I think this is much better than plotting them sequentially and having to scroll through everything. Not sure if useful outside of this, though.
@@ -0,0 +1,799 @@ | |||
{ |
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.
A rather important bug, that I think is prevalent in the loschmidt echos notebook as well: try doing cycles=1. How many two-qubit layers do you see? How about cylces=2?
This is because you are using grid_staggered_pattern but a horizontal line of qubits (instead of a grid). Related but not necessarily sufficient: https://github.com//issues/3833
Options:
- have the random generation function ignore the gridinteractionlayers that don't produce interactions. This would solve the issue at hand but wouldn't produce optimal circuits if you had a line of qubits that was snaked on a diagonal or something
- Have a special function or pattern to do random circuits on linear topologies
- Have a be-all-end-all random circuit generation function that works on arbitrary planar topologies by doing edge coloring to figure out activation orders.
- Make cycles always a multiple of 4
Reply via ReviewNB
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.
Thanks for pointing this out. Discovering this was the main reason the Loschmidt tutorial took so long.
For now I kept cycles as a multiple of 4, but the topology is also no longer linear.
Would you really call this a bug, though? It makes computing the per-two-qubit-gate error harder, but every circuit in the Loschmidt batch has the same number of two-qubit gates, so its valid to compare.
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.
It's surprising. I added a variant of the above comment to #3342
@@ -0,0 +1,799 @@ | |||
{ |
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.
yeah definitely use sampler. Also you should pass project_id to get_engine (or get_engine_sampler) since you go through the effort of allowing it to be input as a variable.
I wish we had some indication of progress or visual indication that something is happening when you run this cell.
Reply via ReviewNB
@@ -0,0 +1,799 @@ | |||
{ |
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.
'o-' is a little heavy-handed for so many lines. Maybe '.-' or even '-'. Then you can back off the lw for average. 5 is a lot
Reply via ReviewNB
@@ -0,0 +1,799 @@ | |||
{ |
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.
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.
Done
Other changes:
|
docs/_book.yaml
Outdated
@@ -186,6 +186,8 @@ upper_tabs: | |||
path: /cirq/tutorials/google/echoes | |||
- title: "Visualizing Calibration Metrics" | |||
path: /cirq/tutorials/google/visualizing_calibration_metrics | |||
- title: "Advanced calibration" |
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.
nit: this doesn't really match the title given in the notebook
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.
updated to match notebook title
…uantumlib#4108) This tutorial shows how to run XEB and Floquet calibrations and compare the results with a Loschmidt echo. Still a bit WIP but asking @mrwojtek @mpharrigan and @XiaoMiQC for initial comments. Example data saved with disclaimer - ok'd by @karlunho.
…uantumlib#4108) This tutorial shows how to run XEB and Floquet calibrations and compare the results with a Loschmidt echo. Still a bit WIP but asking @mrwojtek @mpharrigan and @XiaoMiQC for initial comments. Example data saved with disclaimer - ok'd by @karlunho.
This tutorial shows how to run XEB and Floquet calibrations and compare the results with a Loschmidt echo.
Still a bit WIP but asking @mrwojtek @mpharrigan and @XiaoMiQC for initial comments.
Example data saved with disclaimer - ok'd by @karlunho.