Cirq icon indicating copy to clipboard operation
Cirq copied to clipboard

Simplify controlled gate for SumOfProducts

Open daxfohl opened this issue 3 years ago • 1 comments

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

daxfohl avatar Sep 11 '22 17:09 daxfohl

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

NoureldinYosri avatar Sep 23 '22 15:09 NoureldinYosri

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 avatar Oct 31 '22 20:10 CirqBot