Skip to content

Use CIRCUIT_SERIALIZER as default serializer for quantum engine#4983

Merged
CirqBot merged 6 commits intomasterfrom
u/maffoo/circuit-serializer
Feb 15, 2022
Merged

Use CIRCUIT_SERIALIZER as default serializer for quantum engine#4983
CirqBot merged 6 commits intomasterfrom
u/maffoo/circuit-serializer

Conversation

@maffoo
Copy link
Copy Markdown
Contributor

@maffoo maffoo commented Feb 11, 2022

CIRCUIT_SERIALIZER can serialize gates from any other gateset, uses a more compact proto serialization that doesn't embed redundant string literals, and can serialize more complicated constructs such as CircuitOperation. It is meant to provide serialization separate from the notion of which gates are supported by a particular device, two concepts which were previously conflated. Having this as a default is a big UX improvement when using quantum engine, as the gate_set argument can be omitted on most calls. The gate_set argument could be removed in the future, as specifying the serializer once on EngineContext, along with the protobuf version, is sufficient to customize the serialization when needed.

CIRCUIT_SERIALIZER can serialize gates from any other gateset, uses a
more compact proto serialization that doesn't embed redundant string
literals, and can serialize more complicated constructs such as
CircuitOperation. It is meant to provide serialization separate from the
notion of which gates are supported by a particular device, two concepts
which were previously conflated. Having this as a default is a big UX
improvement when using quantum engine, as the gate_set argument can be
omitted on most calls. The gate_set argument could be removed in the
future, as specifying the serializer once on EngineContext, along with
the protobuf version, is sufficient to customize the serialization when
needed.
@maffoo maffoo requested review from a team, cduck, verult, vtomole and wcourtney as code owners February 11, 2022 14:50
@maffoo maffoo requested a review from dstrain115 February 11, 2022 14:50
@CirqBot CirqBot added the size: M 50< lines changed <250 label Feb 11, 2022
verbose: Optional[bool] = None,
timeout: Optional[int] = None,
context: Optional[EngineContext] = None,
serializer: Serializer = CIRCUIT_SERIALIZER,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

In the future we'd like to remove SerializableGateset, making CIRCUIT_SERIALIZER the only serializer AFAIK. What if we don't provide an option to configure the serializer and always use CIRCUIT_SERIALIZER?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We could certainly do that, though having it configurable gives us a way to test out CircuitSerializer2 when that comes out...

(I kid, but only slightly)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I would lean towards keeping the code simpler now and adding this back when the use case comes up.

Another reason to keep the parameter is if we want to inject a mock to test that Engine calls the serializer with the expected circuit, but it doesn't look like we do that today. And I'm not sure if we should - if the logic for prepping the serializer call isn't complicated then such a test is probably overkill.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed the option to customize this on Engine. I've kept it on EngineContext since that gets passed around to various places where needed and I'd prefer to access the serializer in one way on the context instead of hard-coding CIRCUIT_SERIALIZER everywhere it is used.

repetitions: int = 1,
processor_ids: Sequence[str] = ('xmonsim',),
gate_set: Optional[Serializer] = None,
gate_set: Serializer = None,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If it's not too much hassle, could you add deprecation notices to these fields? In my discussions I haven't heard arguments against removing this field in the future.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Could do that here, of in a separate PR; which do you prefer? I think there are probably still some usages of this parameter in tests and example notebooks that we'd want to change, so I might prefer making a separate PR to track all that down.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Separate PR sounds good!

@maffoo maffoo requested a review from verult February 14, 2022 17:27
@maffoo
Copy link
Copy Markdown
Contributor Author

maffoo commented Feb 15, 2022

@verult, PTAL.

Copy link
Copy Markdown
Collaborator

@verult verult left a comment

Choose a reason for hiding this comment

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

Thanks!

@maffoo maffoo added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Feb 15, 2022
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Feb 15, 2022
@CirqBot CirqBot merged commit 72f9a5b into master Feb 15, 2022
@CirqBot CirqBot removed the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Feb 15, 2022
@CirqBot CirqBot deleted the u/maffoo/circuit-serializer branch February 15, 2022 20:56
@CirqBot CirqBot removed the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Feb 15, 2022
95-martin-orion pushed a commit to 95-martin-orion/Cirq that referenced this pull request Mar 2, 2022
…tumlib#4983)

`CIRCUIT_SERIALIZER` can serialize gates from any other gateset, uses a more compact proto serialization that doesn't embed redundant string literals, and can serialize more complicated constructs such as `CircuitOperation`. It is meant to provide serialization separate from the notion of which gates are supported by a particular device, two concepts which were previously conflated. Having this as a default is a big UX improvement when using quantum engine, as the `gate_set` argument can be omitted on most calls. The `gate_set` argument could be removed in the future, as specifying the serializer once on `EngineContext`, along with the protobuf version, is sufficient to customize the serialization when needed.
rht pushed a commit to rht/Cirq that referenced this pull request May 1, 2023
…tumlib#4983)

`CIRCUIT_SERIALIZER` can serialize gates from any other gateset, uses a more compact proto serialization that doesn't embed redundant string literals, and can serialize more complicated constructs such as `CircuitOperation`. It is meant to provide serialization separate from the notion of which gates are supported by a particular device, two concepts which were previously conflated. Having this as a default is a big UX improvement when using quantum engine, as the `gate_set` argument can be omitted on most calls. The `gate_set` argument could be removed in the future, as specifying the serializer once on `EngineContext`, along with the protobuf version, is sufficient to customize the serialization when needed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: M 50< lines changed <250

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants