experiment_runner.lookups ========================= .. py:module:: experiment_runner.lookups .. autoapi-nested-parse:: Shared resolution of a config string to the library object it names. The package is typed against the library types - a :class:`torch.nn.Module` loss, a :class:`torch.optim.Optimizer` subclass, an sklearn-style target encoder - so the only gap is that YAML cannot hold a Python object. That is a serialization problem rather than an abstraction, which is why each family is a table plus a dotted-path escape hatch instead of a registry: there is nothing to curate, and a loss that does not exist yet still works. This module owns what the three families share: the type check, the case-folded table lookup, the retired-name message, the dotted-path import, and the wording of the error that names the available keys. Each family then constructs in the way that suits it - an encoder takes no arguments, a loss is built with its parameters, an optimizer is deferred into a :func:`functools.partial` because it needs ``model.parameters()``, which only exists inside ``train_model``. Attributes ---------- .. autoapisummary:: experiment_runner.lookups.logger Classes ------- .. autoapisummary:: experiment_runner.lookups.Lookup Module Contents --------------- .. py:data:: logger .. py:class:: Lookup One config-string-to-object family. :param table: Config name (lower case) -> the class or factory it denotes. :type table: dict :param key: The config key this family is configured by, used in every message so an error names the YAML key the user wrote (``"encode"``, ``"loss_func"``). :type key: str :param label: The thing being named, article included (``"an encoder"``, ``"a loss"``), so the sentences read correctly. :type label: str :param example: A dotted path to show in the "available" line. :type example: str :param retired: Names that used to work, mapped to the reason they no longer do. A retired name must say what to use instead: a config carrying one stops running. :type retired: dict, optional .. py:attribute:: table :type: dict[str, collections.abc.Callable] .. py:attribute:: key :type: str .. py:attribute:: label :type: str .. py:attribute:: example :type: str .. py:attribute:: retired :type: dict[str, str] .. py:method:: resolve(name: str) -> collections.abc.Callable Return the class or factory that *name* denotes. Table lookups are case-folded, because configs in the wild spell a loss ``"CrossEntropy"``; a dotted path is left alone, since ``torch.nn.BCEWithLogitsLoss`` cannot resolve lower-cased. :param name: A key of :attr:`table`, or a dotted import path to a class. :type name: str :returns: The class or factory. Constructing it is the caller's business. :rtype: Callable :raises ValueError: If *name* is not a string, is retired, or resolves to nothing. Falling back to a default instead would run a different experiment and report plausible numbers for it. .. py:method:: construct(name: str, params: dict | None = None) -> object Resolve *name* and build it with *params*. :param name: As :meth:`resolve`. :type name: str :param params: Constructor keyword arguments. :type params: dict, optional :returns: The constructed instance. :rtype: object :raises ValueError: If construction fails. The parameters come from YAML, so a wrong name or a wrong shape is a config error and is reported as one.