Skip to content

Resolvers

Native resolvers

hya.resolvers

Implement some resolvers using features from standard libraries.

hya.resolvers.add_resolver

add_resolver(*args: Any) -> Any

Return the addition of several objects.

Parameters:

Name Type Description Default
*args Any

The values to add.

()

Returns:

Type Description
Any

arg1 + arg2 + arg3 + ... + argN

Example
>>> import hya
>>> from omegaconf import OmegaConf
>>> conf = OmegaConf.create({"key": "${hya.add:1,2}"})
>>> conf.key
3
>>> conf = OmegaConf.create({"key": "${hya.add:1,2,3,4}"})
>>> conf.key
10

hya.resolvers.asinh_resolver

asinh_resolver(number: float) -> float

Return the inverse hyperbolic sine.

Parameters:

Name Type Description Default
number float

The number to transform.

required

Returns:

Type Description
float

The inverse hyperbolic sine of the input number.

Example
>>> import hya
>>> from omegaconf import OmegaConf
>>> conf = OmegaConf.create({"key": "${hya.asinh:1}"})
>>> conf.key
0.881373...

hya.resolvers.ceildiv_resolver

ceildiv_resolver(dividend: float, divisor: float) -> float

Compute the ceiling division of two numbers.

Ceiling division rounds the result up to the nearest integer, which is useful for calculating the minimum number of chunks needed to accommodate a given total.

Parameters:

Name Type Description Default
dividend float

The dividend (numerator).

required
divisor float

The divisor (denominator).

required

Returns:

Type Description
float

The ceiling of dividend / divisor. Equivalent to

float

math.ceil(dividend / divisor).

Example
>>> import hya
>>> from omegaconf import OmegaConf
>>> conf = OmegaConf.create({"key": "${hya.ceildiv:11,4}"})
>>> conf.key
3
>>> # Useful for calculating number of batches
>>> conf = OmegaConf.create({"batches": "${hya.ceildiv:100,32}"})
>>> conf.batches
4

hya.resolvers.exp_resolver

exp_resolver(number: float) -> float

Return the exponential value of the input.

Parameters:

Name Type Description Default
number float

The number to transform.

required

Returns:

Type Description
float

The exponential value of the input.

Example
>>> import hya
>>> from omegaconf import OmegaConf
>>> conf = OmegaConf.create({"key": "${hya.exp:0}"})
>>> conf.key
1.0

hya.resolvers.floordiv_resolver

floordiv_resolver(dividend: float, divisor: float) -> float

Compute the floor division of two numbers.

Floor division rounds the result down to the nearest integer, equivalent to the // operator in Python.

Parameters:

Name Type Description Default
dividend float

The dividend (numerator).

required
divisor float

The divisor (denominator).

required

Returns:

Type Description
float

The floor of dividend / divisor, i.e., dividend // divisor.

Example
>>> import hya
>>> from omegaconf import OmegaConf
>>> conf = OmegaConf.create({"key": "${hya.floordiv:11,4}"})
>>> conf.key
2
>>> conf = OmegaConf.create({"key": "${hya.floordiv:10,3}"})
>>> conf.key
3

hya.resolvers.iter_join_resolver

iter_join_resolver(
    iterable: Iterable[Any], separator: str
) -> str

Convert all items in an iterable to strings and join them.

This resolver takes an iterable (e.g., list, tuple) and concatenates all elements into a single string, separated by the specified separator. Each element is converted to a string using str().

Parameters:

Name Type Description Default
iterable Iterable[Any]

Any iterable object where all the returned values are strings or can be converted to string. Common examples include lists, tuples, or OmegaConf ListConfig objects.

required
separator str

The separator string to use between the items. Can be any string including empty string, space, comma, etc.

required

Returns:

Type Description
str

A single string with all iterable elements joined by the separator.

Example
>>> import hya
>>> from omegaconf import OmegaConf
>>> conf = OmegaConf.create({"key": "${hya.iter_join:[abc,2,def],-}"})
>>> conf.key
abc-2-def
>>> conf = OmegaConf.create({"path": "${hya.iter_join:[data,models,v1],/}"})
>>> conf.path
data/models/v1

hya.resolvers.len_resolver

len_resolver(obj: Any) -> int

Return the length of an object.

Parameters:

Name Type Description Default
obj Any

The object.

required

Returns:

Type Description
int

The length of the object.

Example
>>> import hya
>>> from omegaconf import OmegaConf
>>> conf = OmegaConf.create({"key": "${hya.len:[1,2,3]}"})
>>> conf.key
3

hya.resolvers.log10_resolver

log10_resolver(number: float) -> float

Compute base 10 logarithm of the input value.

Parameters:

Name Type Description Default
number float

The number to transform.

required

Returns:

Type Description
float

The base 10 logarithm of the input value.

Example
>>> import hya
>>> from omegaconf import OmegaConf
>>> conf = OmegaConf.create({"key": "${hya.log10:1}"})
>>> conf.key
0.0

hya.resolvers.log_resolver

log_resolver(number: float, base: float = e) -> float

Compute logarithm of the input value to the given base.

Parameters:

Name Type Description Default
number float

The number to transform.

required
base float

The base.

e

Returns:

Type Description
float

The logarithm of the input value to the given base.

Example
>>> import hya
>>> from omegaconf import OmegaConf
>>> conf = OmegaConf.create({"key": "${hya.log:1}"})
>>> conf.key
0.0

hya.resolvers.max_resolver

max_resolver(*args: Any) -> Any

Return the maximum between multiple values.

Parameters:

Name Type Description Default
*args Any

The values.

()

Returns:

Type Description
Any

max(arg1, arg2, arg3, ..., argN)

Example
>>> import hya
>>> from omegaconf import OmegaConf
>>> conf = OmegaConf.create({"key": "${hya.max:1,2,3}"})
>>> conf.key
3

hya.resolvers.min_resolver

min_resolver(*args: Any) -> Any

Return the minimum between multiple values.

Parameters:

Name Type Description Default
*args Any

The values.

()

Returns:

Type Description
Any

min(arg1, arg2, arg3, ..., argN)

Example
>>> import hya
>>> from omegaconf import OmegaConf
>>> conf = OmegaConf.create({"key": "${hya.min:1,2,3}"})
>>> conf.key
1

hya.resolvers.mul_resolver

mul_resolver(*args: Any) -> Any

Return the multiplication of several objects.

Parameters:

Name Type Description Default
*args Any

The values to multiply.

()

Returns:

Type Description
Any

arg1 * arg2 * arg3 * ... * argN

Example
>>> import hya
>>> from omegaconf import OmegaConf
>>> conf = OmegaConf.create({"key": "${hya.mul:1,2}"})
>>> conf.key
2
>>> conf = OmegaConf.create({"key": "${hya.mul:1,2,3}"})
>>> conf.key
6

hya.resolvers.neg_resolver

neg_resolver(number: float) -> float

Return the negation (-number).

Parameters:

Name Type Description Default
number float

The number to transform.

required

Returns:

Type Description
float

The negated input number.

Example
>>> import hya
>>> from omegaconf import OmegaConf
>>> conf = OmegaConf.create({"key": "${hya.neg:1}"})
>>> conf.key
-1

hya.resolvers.path_resolver

path_resolver(path: str) -> Path

Return a resolved path object from a string path.

This resolver converts a string path to a pathlib.Path object, expanding user home directory references (~) and resolving to an absolute path.

Parameters:

Name Type Description Default
path str

The target path as a string. Supports tilde (~) for home directory expansion.

required

Returns:

Type Description
Path

A fully resolved pathlib.Path object with expanded user

Path

directory and converted to absolute path.

Note

The tilde (~) expansion works when the path is passed as a regular string, but may not work correctly when used within OmegaConf interpolation syntax due to grammar restrictions. For paths with tilde, consider using direct Python code or configuration string values.

Example
>>> import hya
>>> from omegaconf import OmegaConf
>>> conf = OmegaConf.create({"key": "${hya.path:/my/path}"})
>>> conf.key
PosixPath('/my/path')

hya.resolvers.pi_resolver

pi_resolver() -> float

Return the value PI.

Returns:

Type Description
float

The value of PI.

Example
>>> import hya
>>> from omegaconf import OmegaConf
>>> conf = OmegaConf.create({"key": "${hya.pi:}"})
>>> conf.key
3.14159...

hya.resolvers.pow_resolver

pow_resolver(value: float, exponent: float) -> float

Return a value to a given power.

Parameters:

Name Type Description Default
value float

The value or base.

required
exponent float

The exponent.

required

Returns:

Type Description
float

x ** y

Example
>>> import hya
>>> from omegaconf import OmegaConf
>>> conf = OmegaConf.create({"key": "${hya.pow:2,3}"})
>>> conf.key
8

hya.resolvers.sha256_resolver

sha256_resolver(obj: Any) -> str

Compute the SHA-256 hash of an input object.

This resolver converts the object to a string representation and computes its SHA-256 hash. Useful for generating consistent identifiers or cache keys from configuration values.

Parameters:

Name Type Description Default
obj Any

The object to compute the SHA-256 hash. The object will be converted to a string using str() before hashing.

required

Returns:

Type Description
str

The SHA-256 hash as a hexadecimal string (64 characters).

Example
>>> import hya
>>> from omegaconf import OmegaConf
>>> conf = OmegaConf.create({"key": "${hya.sha256:mystring}"})
>>> conf.key
bd3ff47540b31e62d4ca6b07794e5a886b0f655fc322730f26ecd65cc7dd5c90
>>> # Useful for generating consistent IDs
>>> conf = OmegaConf.create({"id": "${hya.sha256:experiment_v1}"})

hya.resolvers.sinh_resolver

sinh_resolver(number: float) -> float

Return the hyperbolic sine.

Parameters:

Name Type Description Default
number float

The number to transform.

required

Returns:

Type Description
float

The hyperbolic sine of the input number.

Example
>>> import hya
>>> from omegaconf import OmegaConf
>>> conf = OmegaConf.create({"key": "${hya.sinh:1}"})
>>> conf.key
1.175201...

hya.resolvers.sqrt_resolver

sqrt_resolver(number: float) -> float

Return the square root of a number.

Parameters:

Name Type Description Default
number float

The number to compute the square root.

required

Returns:

Type Description
float

The square root of the input number.

Example
>>> import hya
>>> from omegaconf import OmegaConf
>>> conf = OmegaConf.create({"key": "${hya.sqrt:4}"})
>>> conf.key
2.0

hya.resolvers.sub_resolver

sub_resolver(object1: Any, object2: Any) -> Any

Return the subtraction of two objects.

Parameters:

Name Type Description Default
object1 Any

The first object.

required
object2 Any

The second object.

required

Returns:

Type Description
Any

object1 - object2

Example
>>> import hya
>>> from omegaconf import OmegaConf
>>> conf = OmegaConf.create({"key": "${hya.sub:3,1}"})
>>> conf.key
2

hya.resolvers.to_path_resolver

to_path_resolver(path: str) -> Path

Convert a path string (including URLs) into a pathlib.Path.

This resolver handles both regular file paths and file:// URLs, converting them to pathlib.Path objects. It also expands user home directory references and resolves to absolute paths.

Parameters:

Name Type Description Default
path str

The path to convert. Can be a regular file path or a file:// URL. URL encoding (e.g., %20 for spaces) is automatically decoded. Supports tilde (~) for home directory expansion.

required

Returns:

Type Description
Path

A fully resolved pathlib.Path object with URL decoding,

Path

expanded user directory, and converted to absolute path.

Example
>>> import hya
>>> from omegaconf import OmegaConf
>>> conf = OmegaConf.create({"key": "${hya.to_path:/my/path}"})
>>> conf.key
PosixPath('/my/path')
>>> conf = OmegaConf.create({"key": "${hya.to_path:file:///my/path}"})
>>> conf.key
PosixPath('/my/path')

hya.resolvers.truediv_resolver

truediv_resolver(dividend: float, divisor: float) -> float

Return the true division of two numbers.

Parameters:

Name Type Description Default
dividend float

The dividend.

required
divisor float

The divisor.

required

Returns:

Type Description
float

dividend / divisor

Example
>>> import hya
>>> from omegaconf import OmegaConf
>>> conf = OmegaConf.create({"key": "${hya.truediv:1,2}"})
>>> conf.key
0.5

Optional resolvers

hya.braceexpand

Implement a braceexpand resolver for brace expansion patterns.

This module provides OmegaConf resolvers that use the braceexpand library to expand string patterns with brace notation (similar to bash brace expansion). The resolver is registered only if the braceexpand package is available.

hya.braceexpand.braceexpand_resolver

braceexpand_resolver(pattern: str) -> Iterator[str]

Return an iterator from a brace expansion of pattern.

This resolver expands a string with brace patterns similar to bash brace expansion, generating multiple strings from a single pattern. Useful for generating lists of similar configuration values.

Please check https://github.com/trendels/braceexpand for more information about the syntax.

Parameters:

Name Type Description Default
pattern str

Specifies the pattern of the brace expansion. Supports numeric ranges (e.g., "file{1..3}.txt"), character sequences (e.g., "{a,b,c}"), and nested patterns.

required

Returns:

Type Description
Iterator[str]

An iterator yielding strings resulting from brace expansion

Iterator[str]

of the pattern.

Note

When using brace expansion patterns in OmegaConf, you may need to escape or quote the pattern string to avoid conflicts with OmegaConf's own syntax for curly braces.

hya.numpy

Implement NumPy resolvers for array creation and manipulation.

This module provides OmegaConf resolvers that use NumPy for array operations. The resolvers are registered only if the numpy package is available, allowing users to create NumPy arrays directly from configuration files. registry.register_resolvers()

    # Then in your OmegaConf config:
    # data: ${hya.np.array:[1, 2, 3]}

hya.numpy.to_array_resolver

to_array_resolver(data: ArrayLike) -> ndarray

Implement a resolver to transform the input to a numpy.ndarray.

Parameters:

Name Type Description Default
data ArrayLike

Specifies the data to transform in numpy.ndarray. This value should be compatible with numpy.array

required

Returns:

Type Description
ndarray

The input in a numpy.ndarray object.

Example
>>> import hya
>>> from omegaconf import OmegaConf
>>> conf = OmegaConf.create({"key": "${hya.np.array:[1, 2, 3]}"})
>>> conf.key
array([1, 2, 3])

hya.torch

Implement PyTorch resolvers for tensor creation and dtype handling.

This module provides OmegaConf resolvers that use PyTorch for tensor operations and data type specifications. The resolvers are registered only if the torch package is available, enabling users to create PyTorch tensors and specify dtypes directly from configuration files.

hya.torch.get_dtypes

get_dtypes() -> set[dtype]

Get all available PyTorch data types.

This function introspects the torch module to find all available dtype objects. It's useful for validation and error messages when working with torch dtype resolvers.

Returns:

Type Description
set[dtype]

A set containing all PyTorch dtype objects available in the

set[dtype]

current torch installation (e.g., torch.float32, torch.int64,

set[dtype]

torch.bool, etc.).

Example
>>> import hya
>>> from hya.torch import get_dtypes
>>> dtypes = get_dtypes()
>>> torch.float32 in dtypes
True

hya.torch.to_tensor_resolver

to_tensor_resolver(data: Any) -> Tensor

Implement a resolver to transform the input to a torch.Tensor.

Parameters:

Name Type Description Default
data Any

Specifies the data to transform in torch.Tensor. This value should be compatible with torch.tensor

required

Returns:

Type Description
Tensor

The input in a torch.Tensor object.

Example
>>> import hya
>>> from omegaconf import OmegaConf
>>> conf = OmegaConf.create({"key": "${hya.torch.tensor:[1,2,3,4,5]}"})
>>> conf.key
tensor([1, 2, 3, 4, 5])

hya.torch.torch_dtype_resolver

torch_dtype_resolver(target: str) -> dtype

Create a torch.dtype from its string representation.

This resolver converts a string name to the corresponding PyTorch data type object. The string must match an attribute name in the torch module that represents a dtype (e.g., "float32", "int64").

Parameters:

Name Type Description Default
target str

The target data type as a string. Must be a valid torch dtype attribute name such as "float", "float32", "float64", "int32", "int64", "bool", etc. The string should match the attribute name in torch (e.g., use "float32" not "torch.float32").

required

Returns:

Type Description
dtype

The corresponding torch.dtype object.

Raises:

Type Description
InterpolationResolutionError

If the target string doesn't correspond to a valid torch dtype.

Example
>>> import hya
>>> from omegaconf import OmegaConf
>>> conf = OmegaConf.create({"key": "${hya.torch.dtype:float}"})
>>> conf.key
torch.float32
>>> conf = OmegaConf.create({"key": "${hya.torch.dtype:int64}"})
>>> conf.key
torch.int64