def set_gcl_options(opts, gcl_options=None):
  """Set the IPU options for the Graphcore Communication Library.

  Args:
    gcl_options: A dictionary with options for configuring the GCL collective
      operations.

  Returns:
    The IpuOptions configuration protobuf.
  """

  if gcl_options:
    if not isinstance(gcl_options, dict):
      raise TypeError("`gcl_options` must be a dictionary")

    for (option_name, value) in gcl_options.items():
      opt = opts.gcl_options.add()
      opt.option = option_name
      opt.value = value

  return opts