Architectures

Utility functions to detect architecture and verify their names in metatrain.

metatrain.utils.architectures.check_architecture_name(name: str) None[source]

Check if the requested architecture is available.

If the architecture is not found an ValueError() is raised. If an architecture with the same name as an experimental or deprecated architecture exist, this architecture is suggested. If no architecture exist the closest architecture is given to help debugging typos.

Parameters:

name (str) – name of the architecture

Raises:

ValueError – if the architecture is not found

Return type:

None

metatrain.utils.architectures.check_architecture_options(name: str, options: Dict) None[source]

Verifies that an options instance only contains valid keys

If the architecture developer does not provide a validation scheme the options will not checked.

Parameters:
  • name (str) – name of the architecture

  • options (Dict) – architecture options to check

Return type:

None

metatrain.utils.architectures.get_architecture_name(path: str | Path) str[source]

Name of an architecture based on path to pointing inside an architecture.

The function should be used to determine the ARCHITECTURE_NAME based on the name of the folder.

Parameters:

path (str | Path) – absolute path of the architecture directory

Returns:

architecture name

Raises:

ValueError – if path does not point to a valid architecture directory.

Return type:

str

See also

get_architecture_path() to get the relative path within the metatrain project of an architecture name.

metatrain.utils.architectures.import_architecture(name: str) ModuleType[source]

Import an architecture.

Parameters:

name (str) – name of the architecture

Raises:

ImportError – if the architecture dependencies are not met

Returns:

Imported architecture module

Return type:

ModuleType

metatrain.utils.architectures.get_architecture_path(name: str) Path[source]

Return the relative path to the architecture directory.

Path based on the name within the metatrain project directory.

Parameters:

name (str) – name of the architecture

Returns:

path to the architecture directory

Return type:

Path

See also

get_architecture_name() to get the name based on an absolute path of an architecture.

metatrain.utils.architectures.find_all_architectures() List[str][source]

Find all currently available architectures.

To find the architectures the function searches for directories that are not part of the shared code of metatrain.

Returns:

List of architectures names

Return type:

List[str]

metatrain.utils.architectures.preload_documentation_module(name: str) ModuleType[source]

This preloads the documentation module for a given architecture.

It imports the documentation.py file in an isolated manner and adds it to sys.modules.

The reason one might do this is because the documentation module does not have extra dependencies, so importing it separately is always possible, while if we didn’t preload it, importing the documentation would trigger the architecture’s __init__.py which might have extra dependencies that are not installed.

Doing this preloading is useful especially in the context of generating the documentation, where we want to be able to document architectures even if their dependencies are not installed.

Parameters:

name (str) – Name of the architecture

Returns:

The documentation module for the architecture.

Return type:

ModuleType

metatrain.utils.architectures.get_hypers_classes(name: str) Dict[str, type][source]

Returns the default architecture hyperparameters.

Parameters:

name (str) – Name of the architecture

Returns:

Default hyperparameters of the architectures

Return type:

Dict[str, type]

metatrain.utils.architectures.get_default_hypers(name: str) Dict[source]

Returns the default architecture hyperparameters.

Parameters:

name (str) – Name of the architecture

Returns:

Default hyperparameters of the architectures

Return type:

Dict

metatrain.utils.architectures.write_hypers_yaml(name: str, output_path: Path | str) None[source]

Write YAML file with defaults for a given architecture.

Given a model name, this function imports the corresponding module, finds out what the hyperparameters are for the model and its trainer, and generates a YAML file with the default hyperparameters.

Parameters:
  • name (str) – The model to generate the files for.

  • output_path (Path | str) – The path to write the YAML file to.

Return type:

None