def deregister_default_hook(self, hook: Hook, as_group: bool = True, ignore_errors: bool = False): """ De-register hook for the generator. Args: hook (Hook): The list of hooks to register as_group (bool): Whether to de-register this hook for all the generators in the group (if any). ``True`` by default. ignore_errors (bool): Do not raise exception if the hook was not registered before """ if all(i is not hook for i in self.hooks): if not ignore_errors: raise ValueError("Hook was not registered.") else: self.hooks.remove(hook) if as_group and self.group is not None: for g in get_group_by_name(self.group): if g is not self: g.deregister_hook(hook, as_group=False, ignore_errors=True)
def register_default_hooks(self, *hooks: Hook, as_group: bool = True): """ Register hooks for the generator. Args: *hooks (Hook): The list of hooks to register as_group (bool): Whether to set this strategy for all the generators in the group (if any). ``True`` by default. """ self.hooks.extend(hooks) if as_group and self.group is not None: for g in get_group_by_name(self.group): if g is not self: g.register_hooks(*hooks, as_group=False)
def set_default_strategy(self, strategy: Union[str, Strategy], as_group: bool = True): """ Set a new strategy for the generator. This is useful for exploring different behaviors of the generator without redefining the function. Args: strategy (Union[str, Strategy]): The new strategy to set. as_group (bool): Whether to set this strategy for all the generators in the group (if any). ``True`` by default. """ self.strategy = make_strategy(strategy) if as_group and self.group is not None: for g in get_group_by_name(self.group): if g is not self: g.set_strategy(self.strategy, as_group=False) self._default_exec_env = None