Utilities
variables_as_yaml(input_variables, output_variables, file=None)
Returns and optionally saves YAML formatted string defining the in- and output variables.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_variables
|
list[ScalarVariable]
|
List of input variables. |
required |
output_variables
|
list[ScalarVariable]
|
List of output variables. |
required |
file
|
Union[str, PathLike]
|
If not None, YAML formatted string is saved to given file path. |
None
|
Returns:
Type | Description |
---|---|
str
|
YAML formatted string defining the in- and output variables. |
Source code in lume_model/utils.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
|
variables_from_dict(config)
Parses given config and returns in- and output variable lists.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
dict
|
Variable configuration. |
required |
Returns:
Type | Description |
---|---|
tuple[list[ScalarVariable], list[ScalarVariable]]
|
In- and output variable lists. |
Source code in lume_model/utils.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
|
variables_from_yaml(yaml_obj)
Parses YAML object and returns in- and output variable lists.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
yaml_obj
|
Union[str, PathLike]
|
YAML formatted string or file path. |
required |
Returns:
Type | Description |
---|---|
tuple[list[ScalarVariable], list[ScalarVariable]]
|
In- and output variable lists. |
Source code in lume_model/utils.py
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
|
try_import_module(name)
Tries to import module if required.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Module name. |
required |
Returns:
Type | Description |
---|---|
Imported module if successful, None otherwise. |
Source code in lume_model/utils.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
|
verify_unique_variable_names(variables)
Verifies that variable names are unique.
Raises a ValueError if any reoccurring variable names are found.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
variables
|
list[ScalarVariable]
|
List of scalar variables. |
required |
Source code in lume_model/utils.py
29 30 31 32 33 34 35 36 37 38 39 40 |
|
serialize_variables(v)
Performs custom serialization for in- and output variables.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
v
|
dict
|
Object to serialize. |
required |
Returns:
Type | Description |
---|---|
Dictionary with serialized in- and output variables. |
Source code in lume_model/utils.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
|
deserialize_variables(v)
Performs custom deserialization for in- and output variables.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
v
|
Object to deserialize. |
required |
Returns:
Type | Description |
---|---|
Dictionary with deserialized in- and output variables. |
Source code in lume_model/utils.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
|
get_valid_path(path, directory='')
Validates path exists either as relative or absolute path and returns the first valid option.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
Union[str, PathLike]
|
Path to validate. |
required |
directory
|
Union[str, PathLike]
|
Directory against which relative paths are checked. |
''
|
Returns:
Type | Description |
---|---|
Union[str, PathLike]
|
The first valid path option as an absolute path. |
Source code in lume_model/utils.py
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
|
replace_relative_paths(d, model_fields=None, directory='')
Replaces dictionary entries with absolute paths where the model field annotation is not string or path-like.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
d
|
dict
|
Dictionary to process. |
required |
model_fields
|
dict
|
Model fields dictionary used to check expected type. |
None
|
directory
|
Union[str, PathLike]
|
Directory against which relative paths are checked. |
''
|
Returns:
Type | Description |
---|---|
dict
|
Dictionary with replaced paths. |
Source code in lume_model/utils.py
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
|