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

Make sure cirq gates and operations decompose to XPow/YPow/ZPow/CZPow + Measurement #5057

Closed

Conversation

tanujkhattar
Copy link
Collaborator

Fixes #4858

This PR makes sure that most cirq gates and operations decompose to a default cirq gateset, which is defined to be XPow/YPow/ZPow/CZPow/Measurement and GlobalPhaseGate.

cirq.testing.assert_implements_consistent_protocols is extended to also check that if an object (gate / operation) has a _decompose_ method defined, then it should always end up decomposing to the cirq default gateset.

Note that some gates, like MatrixGates on more than 3 qubits, Controlled gates acting on qudits / multi-qubit matrix gates etc. can still not be decomposed into the default gateset always.

@tanujkhattar tanujkhattar requested review from a team, vtomole and cduck as code owners March 5, 2022 00:07
@tanujkhattar tanujkhattar requested a review from viathor March 5, 2022 00:08
@CirqBot CirqBot added the size: L 250< lines changed <1000 label Mar 5, 2022
@tanujkhattar tanujkhattar changed the title Make sure all cirq gates decompose to XPow/YPow/ZPow/CZPow + Measurement Make sure cirq gates and operations decompose to XPow/YPow/ZPow/CZPow + Measurement Mar 5, 2022
Copy link
Collaborator

@MichaelBroughton MichaelBroughton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we split this up into two PRs ? one for Matrix and one for Controlled ?

@tanujkhattar
Copy link
Collaborator Author

This cannot be split into two parallel PRs because I'm adding the new assert_decompose_ends_at_default_gateset to the standard assert_implements_consistent_protocols, which in-turn is then used in tests for all gates to make sure that their decomposition ends at the target gateset.

I can split it into 3 sequential PRs -- one that adds decomposition for Matrix gates, one for Controlled Gates and third which adds assert_decompose_ends_at_default_gateset, but I'll need to add redundant tests in the first 2 PRs for coverage, which will then be replaced by the standard assert_implements_consistent_protocols in the 3rd PR.

Let me know your preference.

@MichaelBroughton
Copy link
Collaborator

Hmmm could we do three just to be on the safe side ?

@tanujkhattar
Copy link
Collaborator Author

sure, I'll send the individual PRs shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: L 250< lines changed <1000
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make sure all cirq gates decompose to XPow/YPow/ZPow/CZPow + Measurement
3 participants