Create a new condition that allows easy control by bitmasks#7165
Create a new condition that allows easy control by bitmasks#71650 commit merged intoquantumlib:mainfrom
Conversation
cirq-core/cirq/value/condition.py
Outdated
|
|
||
| @property | ||
| def qasm(self): | ||
| raise ValueError('QASM is defined only for SympyConditions of type key == constant.') |
There was a problem hiding this comment.
Looks like this is doable in OpenQASM 3.0.
There was a problem hiding this comment.
(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.
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:
|
cirq-core/cirq/value/condition.py
Outdated
| ) | ||
| index: int = -1 | ||
| target_value: int = 0 | ||
| equal_target: bool = False |
There was a problem hiding this comment.
Maybe make this an enum instead of bool in case it needs extended?
There was a problem hiding this comment.
I think if we get to a point where we want to do
cirq-core/cirq/value/condition.py
Outdated
|
|
||
|
|
||
| @attrs.frozen | ||
| class BitMaskKeyCondition(Condition): |
There was a problem hiding this comment.
Curious why create a new class rather than add the functionality to KeyCondition?
There was a problem hiding this comment.
I prefer to leave KeyCondition as a simple condition and not overload it
2bfa1cd
This PR creates
BitMaskKeyConditiona 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