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

Use v2 protos in cirq.google.Engine #1779

Merged
merged 18 commits into from
Jul 11, 2019

Conversation

wcourtney
Copy link
Collaborator

Update cirq Engine to optionally use new proto definitions in cirq.api.google.v2 when communicating with the API.

@googlebot googlebot added the cla: yes Makes googlebot stop complaining. label Jul 8, 2019
@wcourtney wcourtney requested review from maffoo, Strilanc and dabacon July 8, 2019 23:58
cirq/google/engine/engine.py Outdated Show resolved Hide resolved
cirq/google/engine/engine.py Outdated Show resolved Hide resolved
def results_from_proto(
msg: result_pb2.Result,
measurements: List[MeasureInfo],
measurements: List[MeasureInfo] = None,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think instead of making this optional and relying on ordering, we should use the api_v2.find_measurements function to find measurements in the program before sending to the quantum engine, and store this in the EngineJob. Then when getting results the list of measurements can be passed in to results_from_proto.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't all the info about the measurements be accessible from the results?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

What is your concern with relying on the order in the result? If we want to support re-ordering, could it be a feature/utility rather than a requirement to parse a result?

Copy link
Contributor

Choose a reason for hiding this comment

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

We want to be sure that the order in which results appear in TrialResult match the original measurement operation. The measurements arg on results_from_proto is here so we can check the qubit order in the results against the original measure ops, and it's as easy to reorder as to check so that's what it does. If we want to specify that the engine will not reorder (and then assume but not check this), then I'd suggest we remove this argument entirely rather than making it optional.

I think it would be good to include the qubit order in TrialResult itself to make the results more self-describing. That would alleviate some of my concern because we won't have so many assumptions about parallel ordering between various objects. I know TrialResult is getting an overhaul, so maybe we can include the qubit order as part of that change.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

+1 to including qubit order details in the result.

I'd prefer to remove the measurements arg, but that would be a breaking change for existing external dependencies (I found one). My plan was to make this optional to continue support, then, if it was acceptable, remove all references, then clean up by removing the param. LMK if it's fine to just make the breaking change, otherwise I can add comments to that effect.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with @dabacon, making this optional for now is fine. We can remove in a future PR.

cirq/google/api/v2/results.py Show resolved Hide resolved
cirq/google/api/v2/results.py Outdated Show resolved Hide resolved
cirq/google/engine/engine.py Outdated Show resolved Hide resolved
from cirq.google.convert_to_xmon_gates import ConvertToXmonGates
from cirq.google.params import sweep_to_proto_dict
from cirq.google.programs import schedule_to_proto_dicts, unpack_results
from cirq.google.serializable_gate_set import SerializableGateSet
from cirq.schedules import Schedule, moment_by_moment_schedule
from cirq.study import ParamResolver, Sweep, Sweepable, TrialResult
from cirq.study.sweeps import Points, UnitSweep, Zip

Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: this follows a very different import strategy than we follow in Cirq. No need to fix now, but generally we don't import classes / method

cirq/google/engine/engine.py Outdated Show resolved Hide resolved
program_dict['operations'] = [
op for op in schedule_to_proto_dicts(schedule)
]
return program_dict, None # run context included in program
Copy link
Collaborator

Choose a reason for hiding this comment

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

is there a reason to do this for v1 protos? It would be nice to always just the the run context.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We previously talked about making these changes separately, so I left it as-is. It should be straightforward, so I'll address this after attending to the other comments.

Copy link
Collaborator

Choose a reason for hiding this comment

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

SGTM.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added. PTAL.

def results_from_proto(
msg: result_pb2.Result,
measurements: List[MeasureInfo],
measurements: List[MeasureInfo] = None,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't all the info about the measurements be accessible from the results?

@Strilanc Strilanc changed the title Engine v2 protos Use v2 protos in cirq.google.QuantumEngine Jul 10, 2019
@Strilanc Strilanc changed the title Use v2 protos in cirq.google.QuantumEngine Use v2 protos in cirq.google.Engine Jul 10, 2019
@dabacon dabacon added the Ready for Re-Review For when reviewers take their time. label Jul 11, 2019
@dabacon
Copy link
Collaborator

dabacon commented Jul 11, 2019

I'm fine with the None if we eventually migrate it away in external code. @maffoo ?

Copy link
Contributor

@maffoo maffoo left a comment

Choose a reason for hiding this comment

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

LGTM

def results_from_proto(
msg: result_pb2.Result,
measurements: List[MeasureInfo],
measurements: List[MeasureInfo] = None,
Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with @dabacon, making this optional for now is fine. We can remove in a future PR.

@wcourtney wcourtney merged commit bb03b68 into quantumlib:master Jul 11, 2019
@wcourtney wcourtney deleted the engine-v2-protos branch July 11, 2019 20:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Makes googlebot stop complaining. Ready for Re-Review For when reviewers take their time.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants