def from_narrow_circuits(
        circuit_templates: Sequence[cirq.Circuit],
        permutation: np.ndarray,
        pairs: Sequence[_QUBIT_PAIR_T],
        target: _CANONICAL_TARGET_T,
    ) -> XEBWideCircuitInfo:
        """A static method that merges a sequence of narrow circuits into a wide circuit.

        Args:
            circuit_templates: A sequence of 2Q (i.e. narrow) circuits.
            permutation: A permutation that maps a qubit-pair to a narrow circuit.
            pairs: The list of qubit-pairs to benchmark.
            target: The target 2Q operation to benchmark.

        Returns:
            An XEBWideCircuitInfo instance representing the glued circuits.
        """
        transformed_circuits = []
        has_circuit_operations = False
        for i, pair in zip(permutation, pairs, strict=True):
            circuit = circuit_templates[i].transform_qubits(lambda q: pair[q.x])
            if isinstance(target, ops.Operation):
                xeb_op = target.with_qubits(*pair)
            else:
                if pair not in target:
                    continue
                xeb_op = target[pair]
                xeb_op = xeb_op.with_qubits(*pair)

            if isinstance(xeb_op, circuits.CircuitOperation):
                xeb_op = xeb_op.mapped_op()
                has_circuit_operations = True

            def _map_operation(op):
                num_qubits = protocols.num_qubits(op)
                if num_qubits <= 1:
                    return op
                assert num_qubits == 2
                return xeb_op

            circuit = circuit.map_operations(_map_operation)
            transformed_circuits.append(circuit)

        zipped_circuit = circuits.Circuit.zip(*transformed_circuits)
        if has_circuit_operations and len(circuit_templates) > 1:
            # Each moment must have at most one circuit operation.
            new_moments = []
            for moment in zipped_circuit:
                if any(isinstance(op, circuits.CircuitOperation) for op in moment):
                    new_moments.append(
                        _transform_moment_with_circuit_ops_to_moment_with_single_op(moment)
                    )
                else:
                    new_moments.append(moment)
            zipped_circuit = circuits.Circuit.from_moments(*new_moments)
        return XEBWideCircuitInfo(zipped_circuit, pairs, narrow_template_indices=permutation)
A static method that merges a sequence of narrow circuits into a wide circuit.

        Args:
            circuit_templates: A sequence of 2Q (i.e. narrow) circuits.
            permutation: A permutation that maps a qubit-pair to a narrow circuit.
            pairs: The list of qubit-pairs to benchmark.
            target: The target 2Q operation to benchmark.

        Returns:
            An XEBWideCircuitInfo instance representing the glued circuits.
        
cirq-core/cirq/experiments/benchmarking/parallel_xeb.py