-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Create a new condition that allows easy control by bitmasks and Add a new classical Update the notebook for 'Classical control' to reflect new features" #7166
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
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #7166 +/- ##
=======================================
Coverage 98.14% 98.14%
=======================================
Files 1100 1100
Lines 96147 96241 +94
=======================================
+ Hits 94365 94459 +94
Misses 1782 1782 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Lgtm. All my concerns were addressed in previous PR.
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.
LGTM minus some nits.
def attrs_json_dict(obj: Any) -> Dict[str, Any]: | ||
"""Return a dictionary suitable for `_json_dict_` from an attrs dataclass.""" | ||
attribute_names = [f.name for f in attrs.fields(type(obj))] | ||
return obj_to_dict_helper(obj, attribute_names) |
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 add a unit test for this function?
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
"""A multiqubit classical control condition with a bitmask. | ||
|
||
The control is based on a single measurement key and allows comparing equality or inequality | ||
after taking the bitwise and with a bitmask. |
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 we have a short blurb about the bit order of the measurement (or a reference to the measurement code that explains)?
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.
added
@staticmethod | ||
def create_equal_mask( | ||
key: 'cirq.MeasurementKey', bitmask: int, *, index: int = -1 | ||
) -> 'BitMaskKeyCondition': |
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.
Add docstring.
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
@staticmethod | ||
def create_not_equal_mask( | ||
key: 'cirq.MeasurementKey', bitmask: int, *, index: int = -1 | ||
) -> 'BitMaskKeyCondition': |
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.
Add docstring.
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
… new classical Update the notebook for 'Classical control' to reflect new features" (quantumlib#7166) * Create a new condition that allows easy control by bitmasks * add tests * docstring * add missing files * swith from dataclasses to attrs * mypy * Update the notebook for 'Classical control' to reflect new features * nit * nit * tests * nit * fix doc regex * format * address comments * lint
This PR creates
BitMaskKeyCondition
a condition that can be used to create multiqubit classical conditions with bitmasks. This will be much easier than using sympy indexedbasecc: @ikd-sci
Examples:
Any bit from 0, 2, 3 => 0b1101 = 13
Contains 0b1011 = 11 as bitmask
Doesn't contain 11 as a bitmask
update the notebook to reflect the upgraded sympy support from #6914 and the new bitmask condition from #7165