def _create_grid_device_from_diagram(
    ascii_grid: str,
    gateset: cirq.Gateset,
    gate_durations: dict[cirq.GateFamily, cirq.Duration] | None = None,
) -> grid_device.GridDevice:
    """Parse ASCIIart device layout into a GridDevice instance.

    This function assumes that all pairs of adjacent qubits are valid targets
    for two-qubit gates.

    Args:
        ascii_grid: ASCII version of the grid (see _parse_device for details).
        gateset: The device's gate set.
        gate_durations: A map of durations for each gate in the gate set.
        out: If given, populate this proto, otherwise create a new proto.
    """
    qubits, _ = _parse_device(ascii_grid)

    # Create a list of all adjacent pairs on the grid for two-qubit gates.
    qubit_set = frozenset(qubits)
    pairs: list[tuple[cirq.GridQubit, cirq.GridQubit]] = []
    for qubit in qubits:
        for neighbor in sorted(qubit.neighbors()):
            if neighbor > qubit and neighbor in qubit_set:
                pairs.append((qubit, cast(cirq.GridQubit, neighbor)))

    return grid_device.GridDevice._from_device_information(
        qubit_pairs=pairs, gateset=gateset, gate_durations=gate_durations
    )
Parse ASCIIart device layout into a GridDevice instance.

    This function assumes that all pairs of adjacent qubits are valid targets
    for two-qubit gates.

    Args:
        ascii_grid: ASCII version of the grid (see _parse_device for details).
        gateset: The device's gate set.
        gate_durations: A map of durations for each gate in the gate set.
        out: If given, populate this proto, otherwise create a new proto.
    
cirq-google/cirq_google/devices/known_devices.py