def _build_sweep_const(value: Any) -> run_context_pb2.ConstValue:
    """Build the sweep const message from a value."""
    if value is None:
        return run_context_pb2.ConstValue(is_none=True)
    elif isinstance(value, numbers.Integral):
        return run_context_pb2.ConstValue(int_value=int(value))
    elif isinstance(value, numbers.Real):
        return run_context_pb2.ConstValue(float_value=float(value))
    elif isinstance(value, str):
        return run_context_pb2.ConstValue(string_value=value)
    elif isinstance(value, tunits.Value):
        return run_context_pb2.ConstValue(with_unit_value=value.to_proto())
    else:
        raise ValueError(
            f"Unsupported type for serializing const sweep: {value=} and {type(value)=}"
        )
Build the sweep const message from a value.
cirq-google/cirq_google/api/v2/sweeps.py