def metadata_from_proto(metadata_pb: run_context_pb2.Metadata) -> Metadata:
    """Convert the metadata proto to the metadata dataclass."""
    device_parameters: list[DeviceParameter] = []
    for param in metadata_pb.device_parameters:
        device_parameters.append(
            DeviceParameter(path=param.path, idx=param.idx if param.HasField("idx") else None)
        )
    return Metadata(
        device_parameters=device_parameters or None,
        label=metadata_pb.label if metadata_pb.HasField("label") else None,
        is_const=metadata_pb.is_const,
        unit=metadata_pb.unit if metadata_pb.HasField("unit") else None,
    )
Convert the metadata proto to the metadata dataclass.
cirq-google/cirq_google/api/v2/sweeps.py