def get_circuit_connectivity(circuit: cirq.Circuit) -> nx.Graph:
    """Return a graph of all 2q interactions in a circuit.

    Nodes are qubits and undirected edges correspond to any two-qubit
    operation.
    """
    g = nx.Graph()
    for op in circuit.all_operations():
        n_qubits = len(op.qubits)
        if n_qubits > 2:
            raise ValueError(  # pragma: no cover
                f"Cannot build a graph out of a circuit that "
                f"contains {n_qubits}-qubit operations"
            )
        if n_qubits == 2:
            g.add_edge(*op.qubits)
    return g
Return a graph of all 2q interactions in a circuit.

    Nodes are qubits and undirected edges correspond to any two-qubit
    operation.
    
cirq-core/cirq/contrib/routing/utils.py