The Hypster Object#

  • When you decorate a function with @config, Hypster creates an object that wraps your configuration function.

  • This object, an instance of the Hypster class, provides additional functionality and allows for flexible usage of your configuration.

Creation#

The Hypster object is created automatically when you use the @config decorator:

from hypster import HP, config

@config
def hp_config(hp: HP):
    # Your configuration code here
    pass

In this example, hp_config is no longer a simple function - it’s now a Hypster object.

Features#

The Hypster object provides several key features:

  1. Callable: It can be called like a function, executing your configuration code with optional parameters:

    result = hp_config(selections={'param': 'value'}, overrides={'other_param': 42})
    
  2. Saving and Loading: It can be saved to and loaded from files:

    import hypster
    hypster.save(hp_config, "my_config.py")
    loaded_config = hypster.load("my_config.py")
    
  3. Propagation: It can be used in nested configurations:

    @config
    def parent_config(hp: HP):
        nested_result = hp.propagate(hp_config)
    

Accessing the Original Function#

If you need to access the original, undecorated function, you can use the func attribute of the Hypster object:

original_function = hp_config.func

This can be useful in certain advanced scenarios or for introspection.

Best Practices#

  1. Type Hinting: Always use hp: HP in your configuration function parameters. This helps with IDE autocomplete and type checking.

  2. Naming: Choose descriptive names for your configuration functions. They become part of your API.

  3. Modularity: Create separate Hypster objects for different components of your system. This allows for better organization and reusability.

By understanding the Hypster object, you can take full advantage of Hypster’s powerful configuration management capabilities.