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 usage:

>>> import hya
>>> from omegaconf import OmegaConf
>>> hya.register_resolvers()
>>> 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 usage:

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

hya.resolvers.ceildiv_resolver

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

Return the ceiling division of two numbers.

Parameters:

Name Type Description Default
dividend float

The dividend.

required
divisor float

The divisor.

required

Returns:

Name Type Description
int int

The output of the ceiling division.

Example usage:

>>> import hya
>>> from omegaconf import OmegaConf
>>> hya.register_resolvers()
>>> conf = OmegaConf.create({"key": "${hya.ceildiv:11,4}"})
>>> conf.key
3

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 usage:

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

hya.resolvers.floordiv_resolver

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

Return the floor division of two numbers.

Parameters:

Name Type Description Default
dividend float

The dividend.

required
divisor float

The divisor.

required

Returns:

Type Description
int

dividend // divisor

Example usage:

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

hya.resolvers.iter_join_resolver

iter_join_resolver(
    iterable: Iterable, separator: str
) -> str

Convert all items in an iterable to a string and joins them into one string.

Parameters:

Name Type Description Default
iterable Iterable

Any iterable object where all the returned values are strings or can be converted to string.

required
separator str

The separator to use between the items.

required

Returns:

Type Description
str

The generated string.

Example usage:

>>> import hya
>>> from omegaconf import OmegaConf
>>> hya.register_resolvers()
>>> conf = OmegaConf.create({"key": "${hya.iter_join:[abc,2,def],-}"})
>>> conf.key
abc-2-def

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 usage:

>>> import hya
>>> from omegaconf import OmegaConf
>>> hya.register_resolvers()
>>> 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 usage:

>>> import hya
>>> from omegaconf import OmegaConf
>>> hya.register_resolvers()
>>> 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 usage:

>>> import hya
>>> from omegaconf import OmegaConf
>>> hya.register_resolvers()
>>> 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 usage:

>>> import hya
>>> from omegaconf import OmegaConf
>>> hya.register_resolvers()
>>> 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 usage:

>>> import hya
>>> from omegaconf import OmegaConf
>>> hya.register_resolvers()
>>> 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 usage:

>>> import hya
>>> from omegaconf import OmegaConf
>>> hya.register_resolvers()
>>> 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 usage:

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

hya.resolvers.path_resolver

path_resolver(path: str) -> Path

Return a path object.

Parameters:

Name Type Description Default
path str

The target path.

required

Returns:

Type Description
Path

The path object.

Example usage:

>>> import hya
>>> from omegaconf import OmegaConf
>>> hya.register_resolvers()
>>> 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 usage:

>>> import hya
>>> from omegaconf import OmegaConf
>>> hya.register_resolvers()
>>> 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 usage:

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

hya.resolvers.sha256_resolver

sha256_resolver(obj: Any) -> str

Return the SHA-256 hash of the input object.

Parameters:

Name Type Description Default
obj Any

The object to compute the SHA-256 hash.

required

Returns:

Type Description
str

The SHA-256 hash of the object.

Example usage:

>>> import hya
>>> from omegaconf import OmegaConf
>>> hya.register_resolvers()
>>> conf = OmegaConf.create({"key": "${hya.sha256:mystring}"})
>>> conf.key
bd3ff47540b31e62d4ca6b07794e5a886b0f655fc322730f26ecd65cc7dd5c90

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 usage:

>>> import hya
>>> from omegaconf import OmegaConf
>>> hya.register_resolvers()
>>> 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 usage:

>>> import hya
>>> from omegaconf import OmegaConf
>>> hya.register_resolvers()
>>> 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 usage:

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

hya.resolvers.to_path_resolver

to_path_resolver(path: str) -> Path

Return the input path into a pathlib.Path.

Parameters:

Name Type Description Default
path str

The path to convert. This value should be compatible with pathlib.Path.

required

Returns:

Type Description
Path

The converted path.

Example usage:

>>> import hya
>>> from omegaconf import OmegaConf
>>> hya.register_resolvers()
>>> conf = OmegaConf.create({"key": "${hya.to_path:/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 usage:

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

Optional resolvers

hya.braceexpand_

Implement a braceexpand resolver.

The resolver is registered only if braceexpand is available.

hya.braceexpand_.braceexpand_resolver

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

Return an iterator from a brace expansion of pattern.

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.

required

Returns:

Type Description
Iterator[str]

The iterator resulting from brace expansion of pattern.

hya.torch_

Implement PyTorch resolvers.

The resolvers are registered only if torch is available.

hya.torch_.get_dtypes

get_dtypes() -> set[dtype]

Get all the data types.

Returns:

Type Description
set[dtype]

The data types.

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 usage:

>>> import hya
>>> from omegaconf import OmegaConf
>>> hya.register_resolvers()
>>> 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

Implement a resolver to create a torch.dtype from its string representation.

Parameters:

Name Type Description Default
target str

Specifies the target data type.

required

Returns:

Type Description
dtype

The data type.

Example usage:

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