Skip to content
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

bitwise operations for classically conditioned gates #6434

Open
ikd-sci opened this issue Jan 31, 2024 · 9 comments · May be fixed by #6914
Open

bitwise operations for classically conditioned gates #6434

ikd-sci opened this issue Jan 31, 2024 · 9 comments · May be fixed by #6914
Assignees
Labels
kind/feature-request Describes new functionality kind/task A task that's part of a larger effort triage/needs-more-evidence [Feature requests] Seems plausible, but maintainers are not convinced about the use cases yet

Comments

@ikd-sci
Copy link

ikd-sci commented Jan 31, 2024

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
sympy/sympy#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:

q01 ^ q03 ^ q05 ^ q07 ^ q09...

Another approach consist in calculating a truth table. Example:

sympy.Eq(a, 64) | sympy.Eq(a, 63) | sympy.Eq(a, 62) | ...

Both approaches work and are correctly simulated.

Yet another way consists in bit shifting as the following is technically allowed by SymPy:

(sympy.Integer(0b1000) >> 2) & (sympy.Interger(0b1011) >> 1)

[optional] Additional context (e.g. screenshots)
The approach of adding bit registers doesn't scale gracefully even for a small system size:
image
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)

@ikd-sci ikd-sci added the kind/feature-request Describes new functionality label Jan 31, 2024
@pavoljuhas pavoljuhas added the triage/discuss Needs decision / discussion, bring these up during Cirq Cynque label Jan 31, 2024
@NoureldinYosri
Copy link
Collaborator

@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.

@senecameeks senecameeks added triage/accepted A consensus emerged that this bug report, feature request, or other action should be worked on triage/needs-more-evidence [Feature requests] Seems plausible, but maintainers are not convinced about the use cases yet triage/discuss Needs decision / discussion, bring these up during Cirq Cynque and removed triage/discuss Needs decision / discussion, bring these up during Cirq Cynque triage/accepted A consensus emerged that this bug report, feature request, or other action should be worked on labels Jan 31, 2024
@daxfohl
Copy link
Collaborator

daxfohl commented Feb 1, 2024

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

not isinstance(c, value.KeyCondition) for c in self._conditions
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).

@NoureldinYosri NoureldinYosri removed the triage/discuss Needs decision / discussion, bring these up during Cirq Cynque label Feb 14, 2024
Copy link

github-actions bot commented Apr 4, 2024

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

Copy link

github-actions bot commented May 5, 2024

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

Copy link

github-actions bot commented Jun 5, 2024

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

Copy link

github-actions bot commented Jul 6, 2024

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

Copy link

github-actions bot commented Aug 8, 2024

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

Copy link

github-actions bot commented Sep 7, 2024

Issue closed due to inactivity.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Sep 7, 2024
@NoureldinYosri NoureldinYosri reopened this Sep 9, 2024
@daxfohl
Copy link
Collaborator

daxfohl commented Jan 3, 2025

Does this look like it would be useful? https://github.com/quantumlib/Cirq/pull/6914/files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature-request Describes new functionality kind/task A task that's part of a larger effort triage/needs-more-evidence [Feature requests] Seems plausible, but maintainers are not convinced about the use cases yet
Projects
Status: No status
Development

Successfully merging a pull request may close this issue.

6 participants