-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Create a new condition that allows easy control by bitmasks #7165
base: main
Are you sure you want to change the base?
Conversation
|
||
@property | ||
def qasm(self): | ||
raise ValueError('QASM is defined only for SympyConditions of type key == constant.') |
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.
Looks like this is doable in OpenQASM 3.0.
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.
(FWIW I wish now that I hadn't made qasm
abstract, and instead just implemented _qasm_
directly in the subclasses. As-is, qasm
doesn't contain the args to check OpenQASM version, so you'd have to implement _qasm_
here anyway, but you still have to implement qasm
because it's abstract. I'd recommend deprecating and removing qasm
if it's possible.)
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.
for now I plan to just raise UnImplementedError and let the qasm decision for the people working on qasm integration
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #7165 +/- ##
=======================================
Coverage 98.13% 98.13%
=======================================
Files 1093 1093
Lines 95579 95666 +87
=======================================
+ Hits 93797 93883 +86
- Misses 1782 1783 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
) | ||
index: int = -1 | ||
target_value: int = 0 | ||
equal_target: bool = False |
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.
Maybe make this an enum instead of bool in case it needs extended?
@@ -135,6 +136,107 @@ def _qasm_(self, args: 'cirq.QasmArgs', **kwargs) -> Optional[str]: | |||
return f'{key}==1' | |||
|
|||
|
|||
@attrs.frozen | |||
class BitMaskKeyCondition(Condition): |
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.
Curious why create a new class rather than add the functionality to KeyCondition?
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