hyrax

Submodules

Classes

Hyrax

Overall class that represents an interface into hyrax. Currently this encapsulates a configuration and is

Functions

log_runtime_config(runtime_config, output_path[, ...])

Log a runtime configuration.

get_or_load_class(→ Union[T, Any])

Given a configuration dictionary and a registry dictionary, attempt to return

import_module_from_string(→ Any)

Dynamically import a module from a string.

update_registry(registry, name, class_type)

Add a class to a given registry dictionary.

Package Contents

log_runtime_config(runtime_config: dict, output_path: pathlib.Path, file_name: str = 'runtime_config.toml')[source]

Log a runtime configuration.

Parameters:
  • runtime_config (dict) – A dictionary object containing runtime configuration values.

  • output_path (str) – The path to put the config file

  • file_name (str, Optional) – Optional name for the config file, defaults to “runtime_config.toml”

class Hyrax(*, config_file: pathlib.Path | str | None = None, setup_logging: bool = True)[source]

Overall class that represents an interface into hyrax. Currently this encapsulates a configuration and is the external interface to all verbs in a programmatic or notebook context.

CLI functions in hyrax_cli are implemented by calling this class

__init__()[source]

Initialize hyrax. Always applies the default config, and merges it with any provided config file.

Parameters:
  • config_file (Union[Path, str], optional) – filename or pathlib.Path to a config file, by default None

  • setup_logging (bool, optional) – Logging setup for a hyrax object is global loggers named “hyrax.*” If you want to turn off logging config for “hyrax.*” python loggers, pass False here. By default True.

Notes

You may want to set setup_logging manually if: - You have multiple Hyrax objects in your application or notebook, and would like to control which of their logging configs is used globally. By creating one of your objects with setup_logging=True and the others with setup_logging=False, the single object created with setup_logging=True will control where the log is emitted to and what the threshold level is. - You have another library which needs overall control over python logging’s config, and you do not want hyrax to alter any global logging config. In this case you should always pass setup_logging=False. Hyrax will still send logs into python logging; however, the other system will be responsible for where those logs are emitted, and what the threshold level is.

You may want to leave the default of setup_logging=True if: - You have a single Hyrax object in use at any time. This is true in most notebook like environments.

config_manager
config
logger
set_config(key: str, value)[source]

Set a config value at runtime. This modifies the in-memory config object. Once the configuration is updated, the entire config is re-rendered to ensure that any requested external library default configs are incorporated.

Would be used like: hyrax.set_config(“model.name”, “external_hyrax_example.example_model.ExampleModel”) hyrax.set_config(“train.epochs”, 42)

Parameters:
  • key (str) – The dotted key to set, e.g. “model.name”

  • value (Any) – The value to set the key to.

_initialize_log_handlers()[source]

Private initialization helper, Adds handlers and level setting to the global self.logger object

raw_data_dimensions() tuple[list[int], list[int]][source]

Gives the dimensions of underlying data that forms input to the training, and inference steps. This is the raw data that the data loader must normalize to the model

Returns:

widths and heights of all images available locally.

Return type:

tuple[list[int],list[int]]

download(**kwargs)[source]

See Hyrax.download.run()

prepare(**kwargs)[source]

See Hyrax.prepare.run()

rebuild_manifest(**kwargs)[source]

See Hyrax.rebuild_manifest.run()

__dir__()[source]
__getattr__(name)[source]
get_or_load_class(class_name: str, registry: dict[str, T] | None = None) T | Any[source]

Given a configuration dictionary and a registry dictionary, attempt to return the requested class either from the registry or by dynamically importing it.

Parameters:
  • class_name (str) – The name of the class to load.

  • registry (dict) – The registry dictionary of <class name> : <class type> pairs.

Returns:

The returned class to be instantiated

Return type:

type

import_module_from_string(module_path: str) Any[source]

Dynamically import a module from a string.

Parameters:

module_path (str) – The import spec for the requested class. Should be of the form: “module.submodule.ClassName”

Returns:

returned_cls – The class type that was loaded.

Return type:

type

Raises:
  • AttributeError – If the class is not found in the module that is loaded.

  • ModuleNotFoundError – If the module is not found using the provided import spec.

update_registry(registry: dict, name: str, class_type: type)[source]

Add a class to a given registry dictionary.

Parameters:
  • registry (dict) – The registry to update.

  • name (str) – The name of the class.

  • class_type (type) – The class type to be instantiated.