env
optimus_dl.core.env
¶
get_device_from_env(env, name)
¶
Return the value of an environment variable as :class:torch.device.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
env
|
Mapping[str, str]
|
The environment mapping. |
required |
name
|
str
|
The name of the environment variable. |
required |
Returns:
| Type | Description |
|---|---|
device | None
|
The torch.device, or None if the variable is not present. |
Raises:
| Type | Description |
|---|---|
InvalidEnvironmentVariableError
|
If the value is not a valid device string. |
Source code in optimus_dl/core/env.py
get_int_from_env(env, name, allow_zero=False)
¶
Return the value of an environment variable as int.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
env
|
Mapping[str, str]
|
The environment mapping (e.g. os.environ). |
required |
name
|
str
|
The name of the environment variable. |
required |
allow_zero
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
int | None
|
The integer value, or None if the variable is not present. |
Raises:
| Type | Description |
|---|---|
InvalidEnvironmentVariableError
|
If the value is not a valid integer or violates constraints (e.g. negative when allow_zero is False). |
Source code in optimus_dl/core/env.py
get_path_from_env(env, name)
¶
Return the value of an environment variable as :class:~pathlib.Path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
env
|
Mapping[str, str]
|
The environment mapping. |
required |
name
|
str
|
The name of the environment variable. |
required |
Returns:
| Type | Description |
|---|---|
Path | None
|
The path, or None if the variable is not present. |
Raises:
| Type | Description |
|---|---|
InvalidEnvironmentVariableError
|
If the value cannot be converted to a Path. |