-
Notifications
You must be signed in to change notification settings - Fork 982
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 MeasurementKey
in CircuitOperation
#4086
Conversation
…d CircuitOperations. Also add `with_key_path` protocol.
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.
A few notes on this but otherwise it looks very clean.
@@ -40,40 +40,18 @@ def default_repetition_ids(repetitions: int) -> Optional[List[str]]: | |||
return None | |||
|
|||
|
|||
def cartesian_product_of_string_lists(list1: Optional[List[str]], list2: Optional[List[str]]): | |||
def full_join_string_lists(list1: Optional[List[str]], list2: Optional[List[str]]): |
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 be a private method (i.e. with leading "_")?
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 test uses it. Not sure what the python convention for this is. Is it okay for unit tests to depend on private methods?
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.
If it's just the tests using it, I'd prefer making it private. We're not particularly strict about the "no private methods in tests" rule in Cirq.
After converting |
Done. @balopat seems to be from last week's Cirq sync when I was trying to demonstrate the issue with adding reviewers. More reviews are definitely welcome but I'd be good with merging this as well. |
* Add the concept of measurement key path and use it for nested/repeated CircuitOperations. Also add `with_key_path` protocol. * Format and docstrings * json and other fixes * Change to immutable default for pylint * Make full_join_string_lists private
Phase 2a of #4040 RFC.
path
. Similar to file path, denotes the path to this particular key in the circuit and distinguishes from other keys with the same name in other paths.with_key_path
protocol and the required magic methods to make it work across Cirq.CircuitOperation
to simplify the logic and remove the need for any string parsing.measurement_keys
protocol still speaksstr
rather thanMeasurementKey
we need to serialize to and from string at the boundaries of this protocol, leading to some string parsing. These are aims to be removed in future phases by introducing an equivalent protocol API withMeasurementKey
representations, rather than string.MeasurementKey.parse_serialized
helps in constructing the objects at the above boundaries and is the only way to parse nested key string, directly passing them to the constructor will raiseValueError
. This is to avoid users from accidentally using the separator character in their keys, thereby confusing our logic that relies on a specific meaning of that character.-
. For e.g.subcircuit.repeat('a', 'b').repeat('c', 'd')
used to create a non-nestedCircuitOperation
withrepetition_ids=['a:c', 'a:d', 'b:c', 'b:d']
. But since we want to reserve the character:
for separating different nesting levels, we will now haverepetition_ids=['a-c', 'a-d', 'b-c', 'b-d']
.path
and added new test cases there as well.