def extract_gate_times_ns_from_device(
    device: cirq_google.GridDevice,
) -> dict[type[cirq.Gate], float]:
    """Extract a dictionary of gate durations in nanoseconds from GridDevice object.

    The durations are obtained from `GridDevice.metadata` field which is
    provided for devices obtained with `create_device_from_processor_id`.

    Args:
        device: Object representing Google devices with a grid qubit layout.

    Returns:
        A dictionary of gate durations versus supported gate types.  Returns an
        empty dictionary when `device.metadata` do not provide gate durations.
    """
    gate_times_ns: dict[type[cirq.Gate], float] = {}
    if not device.metadata.gate_durations:
        return gate_times_ns
    gate_type: type[cirq.Gate]  # pragma: no cover
    for gate_family, duration in device.metadata.gate_durations.items():
        if isinstance(gate_family, fsim_gate_family.FSimGateFamily):
            for g in gate_family.gates_to_accept:
                gate_type = g if isinstance(g, type) else type(g)
                gate_times_ns[gate_type] = duration.total_nanos()
            continue
        # ordinary GateFamily here
        gate_type = (
            gate_family.gate if isinstance(gate_family.gate, type) else type(gate_family.gate)
        )
        gate_times_ns[gate_type] = duration.total_nanos()
    # cirq.IdentityGate can leak from FSimGateFamily.  Exclude to default to zero duration.
    _ = gate_times_ns.pop(cirq.IdentityGate, None)
    # cirq.WaitGate has variable duration and should not be included here.
    _ = gate_times_ns.pop(cirq.WaitGate, None)
    return gate_times_ns
Extract a dictionary of gate durations in nanoseconds from GridDevice object.

    The durations are obtained from `GridDevice.metadata` field which is
    provided for devices obtained with `create_device_from_processor_id`.

    Args:
        device: Object representing Google devices with a grid qubit layout.

    Returns:
        A dictionary of gate durations versus supported gate types.  Returns an
        empty dictionary when `device.metadata` do not provide gate durations.
    
cirq-google/cirq_google/engine/virtual_engine_factory.py