hyrax
=====

.. py:module:: hyrax


Submodules
----------

.. toctree::
   :maxdepth: 1

   /autoapi/hyrax/config_migrations/index
   /autoapi/hyrax/config_schemas/index
   /autoapi/hyrax/config_utils/index
   /autoapi/hyrax/datasets/index
   /autoapi/hyrax/download/index
   /autoapi/hyrax/downloadCutout/index
   /autoapi/hyrax/download_stats/index
   /autoapi/hyrax/gpu_monitor/index
   /autoapi/hyrax/hyrax/index
   /autoapi/hyrax/model_exporters/index
   /autoapi/hyrax/models/index
   /autoapi/hyrax/plugin_utils/index
   /autoapi/hyrax/pytorch_ignite/index
   /autoapi/hyrax/rebuild_manifest/index
   /autoapi/hyrax/tensorboardx_logger/index
   /autoapi/hyrax/trace/index
   /autoapi/hyrax/vector_dbs/index
   /autoapi/hyrax/verbs/index


Classes
-------

.. autoapisummary::

   hyrax.Hyrax


Functions
---------

.. autoapisummary::

   hyrax.log_runtime_config
   hyrax.get_or_load_class
   hyrax.import_module_from_string
   hyrax.update_registry


Package Contents
----------------

.. py:function:: log_runtime_config(runtime_config: dict, output_path: pathlib.Path, file_name: str = 'runtime_config.toml')

   Log a runtime configuration.

   :param runtime_config: A dictionary object containing runtime configuration values.
   :type runtime_config: dict
   :param output_path: The path to put the config file
   :type output_path: str
   :param file_name: Optional name for the config file, defaults to "runtime_config.toml"
   :type file_name: str, Optional


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

   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

   .. py:method:: __init__

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

   :param config_file: filename or pathlib.Path to a config file, by default None
   :type config_file: Union[Path, str], optional
   :param setup_logging: 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.
   :type setup_logging: bool, optional

   .. rubric:: 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.


   .. py:attribute:: config_manager


   .. py:attribute:: config


   .. py:attribute:: logger


   .. py:method:: set_config(key: str, value, over_write: bool = False)

      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)

      :param key: The dotted key to set, e.g. "model.name"
      :type key: str
      :param value: The value to set the key to.
      :type value: Any
      :param over_write: Whether to allow overwriting existing keys in the config.
                         If True, this method overwrites the entire matching top-level config section with the new value.
                         If False, this method will merge the new setting into the existing ones.
                         Cannot be used with a value of True if the key does not already exist in the config.
                         By default False.
      :type over_write: bool, optional



   .. py:method:: _initialize_log_handlers()

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



   .. py:method:: raw_data_dimensions() -> tuple[list[int], list[int]]

      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.
      :rtype: tuple[list[int],list[int]]



   .. py:method:: download(**kwargs)

      See Hyrax.download.run()



   .. py:method:: rebuild_manifest(**kwargs)

      See Hyrax.rebuild_manifest.run()



   .. py:method:: list_models()

      Return the alphabetically sorted list of available model names.

      The list reflects all models currently registered in the model registry,
      including any models registered by external plugins.

      :returns: Alphabetically sorted list of model names.
      :rtype: list[str]



   .. py:method:: list_dataset_classes()

      Return the alphabetically sorted list of available dataset class names.

      The list reflects all dataset classes currently registered in the dataset
      registry, including any dataset classes registered by external plugins.

      :returns: Alphabetically sorted list of dataset class names.
      :rtype: list[str]



   .. py:method:: list_verbs()

      Return the alphabetically sorted list of available verbs.

      The list shows all classes in the verbs directory which extend the Verb class.
      Each element is simply the string given by the `information`
      method for that verb.

      :returns: Alphabetically sorted list of each verb along with
                required arguments, optional arguments, and short description.
                See `information()` method in verb_registry.py for more details.
      :rtype: list[str]



   .. py:method:: __dir__()


   .. py:method:: __getattr__(name)


.. py:function:: get_or_load_class(class_name: str, registry: dict[str, T] | None = None) -> Union[T, Any]

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

   :param class_name: The name of the class to load.
   :type class_name: str
   :param registry: The registry dictionary of <class name> : <class type> pairs.
   :type registry: dict

   :returns: The returned class to be instantiated
   :rtype: type


.. py:function:: import_module_from_string(module_path: str) -> Any

   Dynamically import a module from a string.

   :param module_path: The import spec for the requested class. Should be of the form:
                       "module.submodule.ClassName"
   :type module_path: str

   :returns: **returned_cls** -- The class type that was loaded.
   :rtype: type

   :raises AttributeError: If the class is not found in the module that is loaded.
   :raises ModuleNotFoundError: If the module is not found using the provided import spec.


.. py:function:: update_registry(registry: dict, name: str, class_type: type)

   Add a class to a given registry dictionary.

   :param registry: The registry to update.
   :type registry: dict
   :param name: The name of the class.
   :type name: str
   :param class_type: The class type to be instantiated.
   :type class_type: type


