experiment_runner.optimizers ============================ .. py:module:: experiment_runner.optimizers .. autoapi-nested-parse:: Optimizer lookup: the config string to a ``torch.optim`` factory. Unlike a loss, an optimizer cannot be fully constructed here: it needs ``model.parameters()``, which only exists inside :meth:`~xai4tsc.models.base.ModelBase.train_model`. So this returns the class, or a :func:`functools.partial` carrying the configured arguments, and the package calls it with ``(self.parameters(), lr=learn_rate)``. That keeps the package API at one object per family - the same shape as the loss and the encoder - and uses the ``partial`` idiom the metric registry already relies on. Attributes ---------- .. autoapisummary:: experiment_runner.optimizers.logger experiment_runner.optimizers.OPTIMIZERS Functions --------- .. autoapisummary:: experiment_runner.optimizers.build_optimizer Module Contents --------------- .. py:data:: logger .. py:data:: OPTIMIZERS :type: dict[str, type[torch.optim.Optimizer]] Config name -> optimizer class. Anything else resolves by dotted path. .. py:function:: build_optimizer(name: str | None, params: dict | None = None) -> collections.abc.Callable | None Return the optimizer factory for the config value *name*. :param name: A key of :data:`OPTIMIZERS` (matched case-insensitively), or a dotted import path to an optimizer class. ``None`` returns ``None``, which leaves :meth:`~xai4tsc.models.base.ModelBase.train_model` on its own default so the default lives in one place. :type name: str or None :param params: Constructor arguments beyond the parameters and the learning rate, e.g. ``{"momentum": 0.9, "nesterov": true}``. They are bound into a :func:`functools.partial`; ``learn_rate`` stays a ``train_model`` parameter and is applied there. :type params: dict, optional :returns: The class, a partial of it, or ``None`` when no name was given. :rtype: Callable or None :raises ValueError: If *name* resolves to nothing, or if *params* were given without a *name* to apply them to.