-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Move serialize_program and serialize_run_context into EngineContext #5034
Conversation
program = serializer.serialize(program) | ||
return _pack_any(program) | ||
|
||
def serialize_run_context(self, sweeps: List[cirq.Sweep], repetitions: int) -> any_pb2.Any: |
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.
Since these are now public, can you add unit tests to cirq-google/cirq_google/engine/engine_test.py?
@@ -126,6 +126,28 @@ def copy(self) -> 'EngineContext': | |||
def _value_equality_values_(self): | |||
return self.proto_version, self.client | |||
|
|||
def serialize_program( |
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 find the name "program" confusing here. Since it's moving to public visibility, what do you think of making it something like serialize_circuit
and let the weird naming in create_program
be its own problem?
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.
The term "program" is fairly well-established, for example it is used in all the cirq.Sampler
methods, so I'm inclined to leave this, but I could be persuaded.
program = serializer.serialize(program) | ||
return _pack_any(program) | ||
|
||
def serialize_run_context(self, sweeps: List[cirq.Sweep], repetitions: int) -> any_pb2.Any: |
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.
Should this also accept a serializer for consistency with the serialize_program
method above?
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.
The serializer is only used for circuits, so not needed for serializing the run context.
Also move pack_any into a utility module and use it in more places.
I reworked this a bit when thinking about testing:
|
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.
Nice rework! LGTM % additional test coverage.
@@ -134,3 +134,37 @@ def test_sweep_with_flattened_sweep(): | |||
param_sweep1 = cirq.Linspace('t', start=0, stop=1, length=20) | |||
(_, param_sweep2) = cirq.flatten_with_sweep(circuit, param_sweep1) | |||
assert v2.sweep_to_proto(param_sweep2) is not None | |||
|
|||
|
|||
def test_run_context_to_proto(): |
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.
Can you also add a test to demonstrate that specifying the out
parameter is appended to? Same for the batch case.
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.
from google.protobuf.message import Message | ||
|
||
|
||
def pack_any(message: Message) -> any_pb2.Any: |
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.
Shocking that there's not a standard utility for this, but it doesn't look like there is...
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 know, right?
It's convenient to be able to use these functions outside of having an
EngineProgram
object or callingEngine.create_program
, for example when testing direct use of the streaming API with the combinedCreateQuantumProgramAndJobRequest
call.@wcourtney, @verult