An object that can be decomposed into simpler operations.All decomposition methods should ultimately terminate on basic 1-qubit and2-qubit gates included by default in Cirq. Cirq does not make any guaranteesabout what the final gate set is. Currently, decompositions within Cirqhappen to converge towards the X, Y, Z, CZ, PhasedX, specified-matrix gates,and others. This set will vary from release to release. Because of thisvariability, it is important for consumers of decomposition to look forgeneric properties of gates, such as “two qubit gate with a unitary matrix”,instead of specific gate types such as CZ gates (though a consumer isof course free to handle CZ gates in a special way, and consumers cangive an
cirq.decomposethat attempts totarget a specific gate set).For example,
_decompose_method that returns a pairof Hadamard gates surrounding a
cirq.CCZis not a1-qubit or 2-qubit operation, it specifies its own
_decompose_methodthat only returns 1-qubit or 2-qubit operations. This means that iterativelydecomposing
cirq.TOFFOLIterminates in 1-qubit and 2-qubit operations, andso almost all decomposition-aware code will be able to handle
cirq.TOFFOLIinstances.Callers are responsible for iteratively decomposing until they are givenoperations that they understand. The
cirq.decomposemethod is a simple wayto do this, because it has logic to recursively decompose until a given
keeppredicate is satisfied.Code implementing
_decompose_MUST NOT create cycles, such as a gate Adecomposes into a gate B which decomposes back into gate A. This will resultin infinite loops when calling
cirq.decompose.It is permitted (though not recommended) for the chain of decompositionsresulting from an operation to hit a dead end before reaching 1-qubit or2-qubit operations. When this happens,
TypeErrorby default, but can be configured to ignore the issue orraise a caller-provided error.
Initialize self. See help(type(self)) for accurate signature.