One of the best ways to drive different behavior in an application is to instantiate different implementations of an interface. The code using the instantiated object only knows the interface which remains constant, but the behavior is determined by the actual object instance.
hydra.utils.call() (and its alias
hydra.utils.instantiate()) for instantiating objects and calling functions. Prefer
instantiate for creating objects and
call for invoking functions.
- Class names : Call the
- Callables like functions, static functions, class methods and objects
The config passed to these functions must have a key called
_target_, with the value of a fully qualified class name, class method, static method or callable.
Any additional parameters are passed as keyword arguments to tha target.
For example, your application may have a User class that looks like this:
For convenience, instantiate/call returns
None when receiving
None as input.