def route_circuit(
    circuit: circuits.Circuit,
    device_graph: nx.Graph,
    *,
    algo_name: str | None = None,
    router: Callable[..., SwapNetwork] | None = None,
    **kwargs,
) -> SwapNetwork:
    """Routes a circuit on a given device.

    Exactly one of algo_name and router must be specified.

    Args:
        circuit: The circuit to route.
        device_graph: The device's graph, in which each vertex is a qubit and each edge indicates
            the ability to do an operation on those qubits.
        algo_name: The name of a routing algorithm. Must be in ROUTERS.
        router: The function that actually does the routing.
        **kwargs: Arguments to pass to the routing algorithm.

    Raises:
        ValueError: If the circuit contains operations on more than two qubits, the number of
            qubits in the circuit are more than those of the device, both `algo_name` and `router`
            are specified, or no routing algorithm is specified.
    """

    if any(protocols.num_qubits(op) > 2 for op in circuit.all_operations()):
        raise ValueError('Can only route circuits with operations that act on at most 2 qubits.')

    if len(list(circuit.all_qubits())) > device_graph.number_of_nodes():
        raise ValueError('Number of logical qubits is greater than number of physical qubits.')

    if not (algo_name is None or router is None):
        raise ValueError('At most one of algo_name or router can be specified.')
    if algo_name is not None:
        router = ROUTERS[algo_name]
    elif router is None:
        raise ValueError('No routing algorithm specified.')
    return router(circuit, device_graph, **kwargs)
Routes a circuit on a given device.

    Exactly one of algo_name and router must be specified.

    Args:
        circuit: The circuit to route.
        device_graph: The device's graph, in which each vertex is a qubit and each edge indicates
            the ability to do an operation on those qubits.
        algo_name: The name of a routing algorithm. Must be in ROUTERS.
        router: The function that actually does the routing.
        **kwargs: Arguments to pass to the routing algorithm.

    Raises:
        ValueError: If the circuit contains operations on more than two qubits, the number of
            qubits in the circuit are more than those of the device, both `algo_name` and `router`
            are specified, or no routing algorithm is specified.
    
cirq-core/cirq/contrib/routing/router.py