def _build_compilation_target_gatesets(
    gateset: cirq.Gateset,
) -> Sequence[cirq.CompilationTargetGateset]:
    """Detects compilation target gatesets based on what gates are inside the gateset."""

    # Include a particular target gateset if the device's gateset contains all required gates of
    # the target gateset.
    # Set all remaining gates in the device's gateset as `additional_gates` so that they are not
    # decomposed in the transformation process.
    target_gatesets: list[cirq.CompilationTargetGateset] = []
    if all(gate_family in gateset.gates for gate_family in _CZ_TARGET_GATES):
        target_gatesets.append(
            transformers.GoogleCZTargetGateset(
                additional_gates=list(gateset.gates - set(_CZ_TARGET_GATES))
            )
        )
    if all(gate_family in gateset.gates for gate_family in _SYC_TARGET_GATES):
        # TODO(#5050) SycamoreTargetGateset additional gates
        target_gatesets.append(transformers.SycamoreTargetGateset())
    if all(gate_family in gateset.gates for gate_family in _SQRT_ISWAP_TARGET_GATES):
        target_gatesets.append(
            cirq.SqrtIswapTargetGateset(
                additional_gates=list(gateset.gates - set(_SQRT_ISWAP_TARGET_GATES))
            )
        )
    if all(gate_family in gateset.gates for gate_family in _CZ_POW_TARGET_GATES):
        target_gatesets.append(
            cirq.CZTargetGateset(
                allow_partial_czs=True,
                additional_gates=list(gateset.gates - set(_CZ_POW_TARGET_GATES)),
            )
        )

    return tuple(target_gatesets)
Detects compilation target gatesets based on what gates are inside the gateset.
cirq-google/cirq_google/devices/grid_device.py