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

[cirqflow] Provide concrete ExecutableSpec #4559

Merged
merged 5 commits into from Oct 11, 2021

Conversation

mpharrigan
Copy link
Collaborator

ExecutableSpec is a newly-introduced abstract class. The design was each application would subclass it for application-dependent data attributes.

  1. Writing all the serialization tests is a nightmare without a full-fledged lives-in-Cirq concrete implementation of this
  2. You could imagine users might want a lower-touch way to put together an executable using an untyped, implicit-schema version of the spec.

Ergo: this PR introduces KeyValueExecutableSpec to address these two concerns.

 - writing serialization tests
 - could be usefull
@mpharrigan mpharrigan requested a review from maffoo October 7, 2021 21:11
@google-cla google-cla bot added the cla: yes Makes googlebot stop complaining. label Oct 7, 2021
@CirqBot CirqBot added the size: XL lines changed >1000 label Oct 7, 2021
@mpharrigan mpharrigan removed the request for review from maffoo October 7, 2021 21:12
@@ -197,7 +232,7 @@ def __str__(self) -> str:
if len(self.executables) > 2:
exe_str += ', ...'

return f'QuantumExecutable(executables=[{exe_str}])'
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 was an unrelated bug I found while updating the tests

@mpharrigan
Copy link
Collaborator Author

Lint failure is in an unrelated file

@mpharrigan
Copy link
Collaborator Author

@MichaelBroughton ptal

Copy link
Collaborator

@MichaelBroughton MichaelBroughton left a comment

Choose a reason for hiding this comment

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

LGTM with a few minor nits.

Comment on lines +55 to +56
with pytest.raises(TypeError, match='unhashable.*'):
hash(KeyValueExecutableSpec(executable_family='', key_value_pairs=[('name', 'test')]))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: Why have this check ?

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 want all these dataclasses to be immutable as possible. We use hashability as a proxy. If you pass a list of key value pairs instead of a tuple of key value pairs, it should raise an exception.

Copy link
Collaborator

Choose a reason for hiding this comment

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

hashing a list will always raise an exception. To me this feels like we're breaking the API requirements and then testing for the failures that emerge because of that, which doesn't seem like a great practice, but there's only one such instance so I'm easy either way.

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 do that all the time to hit our coverage requirements

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's also not "hashing a list". It's hashing a class whose constructor has been provided a list. If we had a check like this for ParamResolver we wouldn't have #4327 :)

@mpharrigan
Copy link
Collaborator Author

@MichaelBroughton ; pushed fixes. PTAL if you want. Otherwise I'll merge this afternoon

@mpharrigan mpharrigan added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Oct 11, 2021
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Oct 11, 2021
@CirqBot CirqBot merged commit 3d50921 into quantumlib:master Oct 11, 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 Oct 11, 2021
rht pushed a commit to rht/Cirq that referenced this pull request May 1, 2023
`ExecutableSpec` is a newly-introduced abstract class. The design was each application would subclass it for application-dependent data attributes. 

1. Writing all the serialization tests is a nightmare without a full-fledged lives-in-Cirq concrete implementation of this
2. You could imagine users might want a lower-touch way to put together an executable using an untyped, implicit-schema version of the spec.

Ergo: this PR introduces `KeyValueExecutableSpec` to address these two concerns.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/workflow cla: yes Makes googlebot stop complaining. size: XL lines changed >1000
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants