code: def register_gate(name, gateclass, allow_overwrite=False):
          
          if hasattr(Circuit, name):
              if allow_overwrite:
                  warnings.warn(f"Circuit has attribute `{name}`.")
              else:
                  raise ValueError(f"Circuit has attribute `{name}`.")
          if name.startswith("run_with_"):
              if allow_overwrite:
                  warnings.warn(f"Gate name `{name}` may conflict with run of backend.")
              else:
                  raise ValueError(f"Gate name `{name}` shall not start with 'run_with_'.")
          if not allow_overwrite:
              if name in GATE_SET:
                  raise ValueError(f"Gate '{name}' is already exists in gate set.")
              if name in GLOBAL_MACROS:
                  raise ValueError(f"Macro '{name}' is already exists.")
          GATE_SET[name] = gateclass
docs: Register new gate to gate set.
  
          Args:
              name (str): The name of gate.
              gateclass (type): The type object of gate.
              allow_overwrite (bool, optional): If True, allow to overwrite the existing gate.
                  Otherwise, raise the ValueError.
  
          Raises:
              ValueError: The name is duplicated with existing gate.
                  When `allow_overwrite=True`, this error is not raised.