def merge_swap_rzz_and_2q_unitaries(
    circuit: cirq.AbstractCircuit,
    *,
    context: cirq.TransformerContext | None = None,
    merged_swap_rzz_tag: str = "_merged_swap_rzz",
    merged_2q_component_tag: str = "_merged_2q_unitaries",
    intermediate_result_tag: str | None = None,
) -> cirq.Circuit:
    """Merges 2-qubit connected components and adjacent `cirq.SWAP` and `cirq.ZZPowGate` gates.

    Does the following two transformations, in that order:
    1. Merges adjacent occurrences of `cirq.SWAP` and `cirq.ZZPowGate` into a
    `cirq.CircuitOperation` tagged with `merged_swap_rzz_tag`.
    2. Merges connected components of 1 and 2 qubit unitaries in the circuit into a
    `cirq.CircuitOperation` tagged with `merged_2q_component_tag`, ignoring the newly
    introduced tagged circuit operations added in Step-1.

    Args:
        circuit: Input circuit to transform. It will not be modified.
        context: `cirq.TransformerContext` storing common configurable options for transformers.
        merged_swap_rzz_tag: Tag to apply on newly introduced circuit operations wrapping adjacent
            `cirq.SWAP` and `cirq.ZZPowGate`s.
        merged_2q_component_tag: Tag to apply on newly introduced circuit operations wrapping
            connected components of 1 and 2 qubit unitaries.
        intermediate_result_tag: If specified, the tag is added to newly introduced both the newly
            introduced circuit operations encapsulating swap_rzz or 2q connected component.

    Returns:
        Copy of the transformed input circuit.

    Raises:
          ValueError: If merged_2q_component_tag and merged_swap_rzz_tag are equal.
    """
    if merged_2q_component_tag == merged_swap_rzz_tag:
        raise ValueError("merged_swap_rzz_tag and merged_2q_component_tag should be different.")

    def merge_func_swap_rzz(ops1: Sequence[cirq.Operation], ops2: Sequence[cirq.Operation]) -> bool:
        if not (len(ops1) == 1 and len(ops2) == 1):
            return False
        for op1, op2 in itertools.permutations([ops1[0], ops2[0]]):
            if op1.gate == cirq.SWAP and isinstance(op2.gate, cirq.ZZPowGate):
                return True
        return False

    tags_to_ignore = context.tags_to_ignore if context else ()
    deep = context.deep if context else False
    circuit = cirq.merge_operations_to_circuit_op(
        circuit,
        merge_func_swap_rzz,
        tags_to_ignore=tags_to_ignore,
        merged_circuit_op_tag=merged_swap_rzz_tag,
        deep=deep,
    )

    circuit = cirq.merge_k_qubit_unitaries_to_circuit_op(
        circuit,
        k=2,
        tags_to_ignore=tuple(tags_to_ignore) + (merged_swap_rzz_tag,),
        merged_circuit_op_tag=merged_2q_component_tag,
        deep=deep,
    )

    if intermediate_result_tag is not None:
        merged_cop_tags = {merged_swap_rzz_tag, merged_2q_component_tag}
        circuit = cirq.map_operations(
            circuit,
            map_func=lambda op, _: (
                op if merged_cop_tags.isdisjoint(op.tags) else op.with_tags(intermediate_result_tag)
            ),
            tags_to_ignore=tags_to_ignore,
            deep=True,
        )
    return circuit.unfreeze(copy=False)
Merges 2-qubit connected components and adjacent `cirq.SWAP` and `cirq.ZZPowGate` gates.

    Does the following two transformations, in that order:
    1. Merges adjacent occurrences of `cirq.SWAP` and `cirq.ZZPowGate` into a
    `cirq.CircuitOperation` tagged with `merged_swap_rzz_tag`.
    2. Merges connected components of 1 and 2 qubit unitaries in the circuit into a
    `cirq.CircuitOperation` tagged with `merged_2q_component_tag`, ignoring the newly
    introduced tagged circuit operations added in Step-1.

    Args:
        circuit: Input circuit to transform. It will not be modified.
        context: `cirq.TransformerContext` storing common configurable options for transformers.
        merged_swap_rzz_tag: Tag to apply on newly introduced circuit operations wrapping adjacent
            `cirq.SWAP` and `cirq.ZZPowGate`s.
        merged_2q_component_tag: Tag to apply on newly introduced circuit operations wrapping
            connected components of 1 and 2 qubit unitaries.
        intermediate_result_tag: If specified, the tag is added to newly introduced both the newly
            introduced circuit operations encapsulating swap_rzz or 2q connected component.

    Returns:
        Copy of the transformed input circuit.

    Raises:
          ValueError: If merged_2q_component_tag and merged_swap_rzz_tag are equal.
    
cirq-google/cirq_google/transformers/target_gatesets/sycamore_gateset.py