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

Allow creating new gatesets with added gates #2458

Merged
merged 11 commits into from
Nov 6, 2019

Conversation

maffoo
Copy link
Contributor

@maffoo maffoo commented Oct 30, 2019

This will let us create "pre-release" gatesets to deploy server-side support for new gates that are not yet supported by the API.

@maffoo maffoo requested review from Strilanc and dstrain115 October 30, 2019 23:03
@googlebot googlebot added the cla: yes Makes googlebot stop complaining. label Oct 30, 2019
Copy link
Collaborator

@dstrain115 dstrain115 left a comment

Choose a reason for hiding this comment

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

Looks like it is still WIP as the title states, but I like the general idea of where it is going.

self.deserializers = {d.serialized_gate_id: d for d in deserializers}

def with_gates(
self,
*,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we need this asterisk? Is there a reason to have an empty args?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This forces using keyword args, which I think helps clarity. You're correct that caling this with no arguments is not very useful because it just returns an equivalent gateset. I could also make serializers and deserializers be positional args and put the optional name last. Do you have a preference?

return SerializableGateSet(
name or self.gate_set_name,
serializers=[*self._all_serializers(), *serializers],
deserializers=[*self.deserializers.values(), *deserializers])
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we need _all_serializers() but not deserializers?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Serializers are stored as a map from gate_id to list of serializers, so we have to flatten those into one list. Deserializers are stored as a map from gate id to deserializer, so we can just use .values(). I will refactor to just inline the expression, since it's probably not worth having a whole method for the serializer flattening.

self.deserializers = {d.serialized_gate_id: d for d in deserializers}

def with_gates(
Copy link
Collaborator

Choose a reason for hiding this comment

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

This function needs tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added.

@maffoo maffoo changed the title [WIP] Allow creating new gatesets with extra gates Allow creating new gatesets with extra gates Oct 31, 2019
@maffoo maffoo requested a review from dstrain115 October 31, 2019 17:20
self.deserializers = {d.serialized_gate_id: d for d in deserializers}

def with_gates(
Copy link
Contributor

Choose a reason for hiding this comment

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

Rename this to with_more_gates or something similar, to make it clearer that the original gates are not being discarded.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to with_added_gates.

@maffoo maffoo changed the title Allow creating new gatesets with extra gates Allow creating new gatesets with added gates Nov 1, 2019
@maffoo maffoo requested a review from Strilanc November 1, 2019 22:16
@Strilanc Strilanc added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Nov 6, 2019
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Nov 6, 2019
@CirqBot CirqBot merged commit 94f7fd2 into master Nov 6, 2019
@CirqBot CirqBot removed the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Nov 6, 2019
@CirqBot CirqBot deleted the u/maffoo/gateset-with-gates branch November 6, 2019 01:25
@CirqBot CirqBot removed the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Nov 6, 2019
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants