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

Simplify controlled gate for SumOfProducts #5873

Merged
merged 5 commits into from
Oct 31, 2022

Conversation

daxfohl
Copy link
Contributor

@daxfohl daxfohl commented Sep 11, 2022

Simplify the SumOfProducts control value when possible (if there's only a single product in it) when constructing a ControlledGate. This allows the X.controlled() -> CX optimization when using a SumOfProducts control value.

Add a two-step test to check X.controlled(num_qubits=2) -> CCX optimization, and include SumOfProducts check there too.

Make use of this simplification where we were hacking it in previously.

Fixes #5883

@CirqBot CirqBot added the size: S 10< lines changed <50 label Sep 11, 2022
@daxfohl daxfohl marked this pull request as ready for review September 11, 2022 17:45
@daxfohl daxfohl requested review from a team, vtomole and cduck as code owners September 11, 2022 17:45
@daxfohl daxfohl requested a review from viathor September 11, 2022 17:45
@NoureldinYosri
Copy link
Collaborator

most optimization and inferences were implemented for the vanilla ways (as ints, lists ..etc) of defining control values, those were ported to ProductOfSums, but for SumOfProduct they didn't make sense in most cases, however in this case what you do in the constructor effectivelly transforms SumOfProducts to ProductOfSums representation, looks good to me

@tanujkhattar tanujkhattar added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Oct 31, 2022
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Oct 31, 2022
@CirqBot
Copy link
Collaborator

CirqBot commented Oct 31, 2022

Automerge cancelled: A required status check is not present.

Missing statuses: ['Misc check', 'Pytest Ubuntu (3.7)', 'Pytest Ubuntu (3.8)', 'Pytest Ubuntu (3.9)', 'Pytest Windows (3.7)', 'Pytest Windows (3.8)', 'Pytest Windows (3.9)', 'Typescript lint check', 'Typescript tests', 'Typescript tests coverage']

@CirqBot CirqBot removed automerge Tells CirqBot to sync and merge this PR. (If it's running.) front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. labels Oct 31, 2022
@tanujkhattar tanujkhattar merged commit f3a3167 into quantumlib:master Oct 31, 2022
@daxfohl daxfohl deleted the simplify-sum-of-products branch November 4, 2022 19:49
rht pushed a commit to rht/Cirq that referenced this pull request May 1, 2023
Co-authored-by: Cirq Bot <craiggidney+github+cirqbot@google.com>
harry-phasecraft pushed a commit to PhaseCraft/Cirq that referenced this pull request Oct 31, 2024
Co-authored-by: Cirq Bot <craiggidney+github+cirqbot@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: S 10< lines changed <50
Projects
None yet
Development

Successfully merging this pull request may close these issues.

X.controlled(cirq.SumOfProducts([[1]])) does not optimize to CX
4 participants