Open ikd-sci opened 5 months ago
@ikd-sci is this for simulation or for circuit diagrams. for simulation we have the abstract class cirq.ops.AbstractControlValues
which can be extended to represent any control function and used in simulation.
Classical controls don't currently work with AbstractControlValues
, though I don't think it would be hard to add a subclass of Condition
that contains an AbstractControlValues
and a Seq[MeasurementKey]
.
The easiest option here though would be to add a bitmask field to KeyCondition
and update the resolve
there to handle it. This seems like a nice thing to have regardless, as it creates parity with the bitmask in MeasurementGate
. The only additional change you'd have to make outside of the KeyCondition
class is I think you'd have to update the code at https://github.com/quantumlib/Cirq/blob/2ef19094f2225b2f2707d169bafe75ecdcdc0537/cirq-core/cirq/ops/classically_controlled_operation.py#L164 to show any bitmasks nicely in the circuit diagram. But everything simulation related, and the deferred_measurements_transformer should just work, as they just call into resolve
(though it doesn't hurt to check).
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days
Is your feature request related to a use case or problem? Please describe.
The main use case is conditional circuits, however, this might be more broadly applicable as the task of splitting bits and doing bitwise operations is fairly common.
Describe the solution you'd like
There is a long-standing issue of limited out-of-the-box support of bitwise operations in sympy https://github.com/sympy/sympy/issues/5353 Currently, cirq doesn't provide ways to split integer register into individual bits in order to use those bits for classically conditioned operations. The typical example of such operations includes pairwise XOR (as in constant-depth feedforward protocols).
[optional] Describe alternatives/workarounds you've considered
Current workaround consists in creating individual bit registers for every single readout operation (LSB or MSB representation) and then performing pairwise sympy.Xor on those bits:
Another approach consist in calculating a truth table. Example:
Both approaches work and are correctly simulated.
Yet another way consists in bit shifting as the following is technically allowed by SymPy:
[optional] Additional context (e.g. screenshots) The approach of adding bit registers doesn't scale gracefully even for a small system size: Even though it does encode the correct circuit -- there is a lot of notation clutter in ASCII representation and suboptimal to work with due the growing number of sympy operations.
What is the urgency from your perspective for this issue? Is it blocking important work? P1 - I need this no later than the next release (end of quarter)