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

[XEB] Support parallel execution #3760

Merged
merged 18 commits into from Feb 12, 2021
Merged

Conversation

mpharrigan
Copy link
Collaborator

Support parallel execution of XEB circuits.

  • Instead of generating a set of circuits for each pair, we generate one library of two-qubit circuits which are mixed-and-matched during execution. This speeds up circuit generation, circuit serialization (for historical record), and speeds up simulation (when not optimizing ... when you're optimizing each pair presumably gets its own set of angles and needs to be simulated separately)
  • As such, a new function is added to the random_circuit_generation module to create a combinations object that describes how to mix-and-match these two-qubit circuits
  • The sample function is modified to accept this combination description to on-the-fly zip the circuits, sample from them, and split out the results. This allows maximal code re-use between isolated and parallel XEB! Analysis is mostly shared! Huge caveat below
  • If you run the characterize_phased_fsim_parameters_with_xeb on the code in this PR, it will find only one set of angles that works for the average of all pairs. I've split up the modifications to that half of the code-base into a subsequent PR.

This can be reviewed independently of #3753

@mpharrigan mpharrigan requested review from cduck, vtomole and a team as code owners February 6, 2021 05:36
@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@google-cla google-cla bot added the cla: yes Makes googlebot stop complaining. label Feb 6, 2021
@karlunho
Copy link
Collaborator

karlunho commented Feb 9, 2021

The tutorials look good, and I suggest that we create entries into the book.yaml so they show up on the documentation site.

cirq/experiments/fidelity_estimation.py Outdated Show resolved Hide resolved
cirq/experiments/fidelity_estimation.py Show resolved Hide resolved
cirq/experiments/fidelity_estimation.py Show resolved Hide resolved
cirq/experiments/fidelity_estimation.py Show resolved Hide resolved
cirq/experiments/fidelity_estimation.py Show resolved Hide resolved
cirq/experiments/fidelity_estimation.py Show resolved Hide resolved
cirq/experiments/fidelity_estimation_test.py Outdated Show resolved Hide resolved
cirq/experiments/fidelity_estimation.py Show resolved Hide resolved
Copy link
Collaborator Author

@mpharrigan mpharrigan left a comment

Choose a reason for hiding this comment

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

address some of the comments

cirq/experiments/fidelity_estimation.py Outdated Show resolved Hide resolved
Args:
wide_circuit: The zipped circuit on all pairs
pairs: The pairs of qubits operated on in the wide circuit.
layer_i: The index of the GridInteractionLayer to which the pairs correspond.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This might become clear in a following PR, but let me try to explain and then I'll think about how to make it clearer in code.

The primary idea is that you have a number of different moments that define the spacial layout of simultaneous two-qubit gates. The essential essence of each of those moments/layers is just the list of pairs, here as pairs. Indeed, pairs (and the circuit) is really the only essential part of this dataclass. The other attributes are metadata to maintain the provenance of the particular set of pairs.

Previous XEB implementations relied heavily on these GridInteractionLayer objects to semi-implicitly define the set of pairs by making several assumptions (like you're operating on a nice grid, all the couplings on the grid work, you'll be using the whole device and/or the calling function will downsample only the pairs that actually exist). So in traditional XEB there are always four layers (one for each of the N, S, E, W set of pairs) and they're represented by these objects.

Of course, for the calibration API we re-purpose cirq.Moment as a "layer". What you'll see in a following PR is that these fields will either contain a GridInteractionLayer, a Moment, or even None since it's just metadata that doesn't really matter as long as you fill in pairs.

layer_i and combination_i are just propagated through to be part of the result object. Let me see if I can clarify that

cirq/experiments/fidelity_estimation.py Show resolved Hide resolved
cirq/experiments/fidelity_estimation.py Show resolved Hide resolved
Args:
wide_circuit: The zipped circuit on all pairs
pairs: The pairs of qubits operated on in the wide circuit.
layer_i: The index of the GridInteractionLayer to which the pairs correspond.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm changing the docstrings to be more clear about what layer_i and combination_i are. I've added a note to both that they don't modify any behavior, but are just propagated to the output. I'm also re-ordering the fields in this dataclass to put them last, because they are less important. I've added a note to combination that it's important to be able to "unzip" the circuit.

cirq/experiments/fidelity_estimation.py Show resolved Hide resolved
cirq/experiments/fidelity_estimation.py Show resolved Hide resolved
cirq/experiments/fidelity_estimation_test.py Outdated Show resolved Hide resolved
@mrwojtek
Copy link
Collaborator

Matthew, are you still working on the changes or this is ready for next round of review?

@mpharrigan
Copy link
Collaborator Author

Ready for review! I think I've addressed everything

cirq/experiments/fidelity_estimation.py Show resolved Hide resolved
cirq/experiments/fidelity_estimation.py Show resolved Hide resolved
# Slicing creates a copy, although this isn't documented
prepared_circuit = zipped_circuit.wide_circuit[:circuit_depth]
for pair_i, pair in enumerate(zipped_circuit.pairs):
prepared_circuit += ops.measure(*pair, key=str(pair_i))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Have you checked if this aligns all the measurements in one moment?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

for the current code, it should just because these are dense circuits by construction; but I've changed it to add the measure operations in one moment. Good spot!

cirq/experiments/fidelity_estimation.py Show resolved Hide resolved
cirq/experiments/fidelity_estimation.py Show resolved Hide resolved
@mpharrigan
Copy link
Collaborator Author

back at you @mrwojtek !

@mpharrigan mpharrigan added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Feb 11, 2021
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Feb 11, 2021
@CirqBot
Copy link
Collaborator

CirqBot commented Feb 12, 2021

Automerge cancelled: Merging is blocked (I don't understand why).

@CirqBot CirqBot removed automerge Tells CirqBot to sync and merge this PR. (If it's running.) front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. labels Feb 12, 2021
@balopat balopat added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Feb 12, 2021
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Feb 12, 2021
@CirqBot CirqBot merged commit e8697de into quantumlib:master Feb 12, 2021
@CirqBot CirqBot removed automerge Tells CirqBot to sync and merge this PR. (If it's running.) front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. labels Feb 12, 2021
CirqBot pushed a commit that referenced this pull request Feb 12, 2021
This PR is purely moving things around (on top of #3760) with one exception noted inline.

 - `random_quantum_circuit_generation` -- left alone; this is a well-scoped file
 - `xeb_sampling` - functionality related to sampling random circuits efficiently (for xeb)
 - `xeb_simulation` - functionality related to simulating 2-qubit circuits at various depths (for xeb) efficiently using multiprocessing
 - `xeb_fitting` - functionality related to using xeb to characterize gates by fitting parameters.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/xeb cla: yes Makes googlebot stop complaining.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants