Skip to content

Add documentation to cirq.decompose protocol regarding specific target gateset #6439

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

Merged
merged 5 commits into from
Mar 22, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions cirq-core/cirq/protocols/decompose_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,12 @@ class SupportsDecompose(Protocol):
"""An object that can be decomposed into simpler operations.

All decomposition methods should ultimately terminate on basic 1-qubit and
2-qubit gates included by default in Cirq. Cirq does not make any guarantees
about what the final gate set is. Currently, decompositions within Cirq
happen to converge towards the X, Y, Z, CZ, PhasedX, specified-matrix gates,
and others. This set will vary from release to release. Because of this
variability, it is important for consumers of decomposition to look for
generic properties of gates, such as "two qubit gate with a unitary matrix",
instead of specific gate types such as CZ gates (though a consumer is
of course free to handle CZ gates in a special way, and consumers can
give an `intercepting_decomposer` to `cirq.decompose` that attempts to
target a specific gate set).
2-qubit gates included by default in Cirq. If a custom decomposition is not
specified, Cirq will decompose all operations to X/Y/Z/CZ/Measurement + Global
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm confused since these aren't universal? Is it missing PhasedX?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I meant XPow/YPow/ZPow/CZPow; updated the docstring to clarify this.

phase gateset. However, the default decomposition in Cirq should be a last resort
fallback and it is recommended for consumers of decomposition to either not depend
upon a specific target gateset, or give an `intercepting_decomposer` to `cirq.decompose`
that attempts to target a specific gate set.

For example, `cirq.TOFFOLI` has a `_decompose_` method that returns a pair
of Hadamard gates surrounding a `cirq.CCZ`. Although `cirq.CCZ` is not a
Expand Down