Job return
overrides_to_dict(overrides, remove_plus_prefix=False)
Convert a list of overrides to a dictionary.
Example
overrides = ["a=1", "b=2", "+c=3"] overrides_to_dict(overrides, remove_plus_prefix=True) {'a': '1', 'b': '2', 'c': '3'}
Args: overrides (list[str]): The list of overrides. remove_plus_prefix (bool, optional): If True, remove the '+' prefix from keys. Defaults to False. Returns: dict[str, str]: The dictionary of overrides.
Source code in src/kibad_llm/utils/job_return.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | |
dict_to_overrides(d, remove_na=False)
Convert a dictionary to a overrides. Example: >>> dict_to_overrides({"a": 1, "b": 2}) ['a=1', 'b=2'] >>> dict_to_overrides({"a": 1, "b": None}, remove_na=True) ['a=1'] >>> dict_to_overrides({"+c": 3, "d": float('nan')}, remove_na=True) ['+c=3']
Source code in src/kibad_llm/utils/job_return.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | |
load(directory, subdir_pattern='', filename='job_return_value.json', strip_id_keys=True, flatten=False, exclude_keys=None)
Load job return value json file(s) from the given directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
directory
|
Path
|
Path to the directory containing return value file(s). |
required |
subdir_pattern
|
str | list[str]
|
One or multiple pattern to match subdirectories (e.g., "*/" to load from all immediate subdirs). |
''
|
filename
|
Name of the file to load from each subdirectory. |
'job_return_value.json'
|
|
strip_id_keys
|
bool
|
Whether to strip the top-level identifier keys from loaded multi-run results. |
True
|
flatten
|
bool
|
Whether to flatten nested dictionaries in the loaded data. |
False
|
exclude_keys
|
list[str] | None
|
List of keys to exclude from the loaded data. Applied after flattening if enabled. |
None
|
Returns: A list of dictionaries containing the loaded data from each subdirectory.
Source code in src/kibad_llm/utils/job_return.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 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 108 109 110 111 112 | |
load_run(directory, filename='job_return_value.json', load_overrides=True)
Load a job return value json file from the given directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
directory
|
Path
|
Path to the directory containing the return value file. |
required |
filename
|
str
|
Name of the file to load. |
'job_return_value.json'
|
load_overrides
|
bool
|
Whether to load overrides from '.hydra/overrides.yaml' if it exists and |
True
|
Returns: A dictionary containing the loaded data.
Source code in src/kibad_llm/utils/job_return.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | |
load_runs(directory, subdir='', filename='job_return_value.json', load_overrides=True, flatten=True, exclude_keys=None)
Load job return value json file(s) from subdirectories of the given directory. Only the leaf subdirectories containing the specified filename are considered (i.e. multi-run results are excluded).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
directory
|
Path
|
Path to the directory containing return value file(s). |
required |
subdir
|
str | list[str]
|
One or multiple subdirectory names under |
''
|
filename
|
str
|
Name of the file to load from each subdirectory. |
'job_return_value.json'
|
load_overrides
|
bool
|
Whether to load overrides from '.hydra/overrides.yaml' if it exists. |
True
|
flatten
|
bool
|
Whether to flatten nested dictionaries in the loaded data. |
True
|
exclude_keys
|
list[str] | None
|
List of keys to exclude from the loaded data. Applied after flattening if enabled. |
None
|
Source code in src/kibad_llm/utils/job_return.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | |
multi_index_to_single(index, sep='.')
Convert a MultiIndex to a single Index by joining the levels with a separator and removing NaN values.
Example
index = pd.MultiIndex.from_tuples([('a', 'b'), ('c', np.nan)]) multi_index_to_single(index) Index(['a.b', 'c'], dtype='object')
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
MultiIndex
|
The MultiIndex to convert. |
required |
sep
|
str
|
The separator to use between the levels. Defaults to ".". |
'.'
|
Returns:
| Type | Description |
|---|---|
Index
|
pd.Index: The converted Index. |
Source code in src/kibad_llm/utils/job_return.py
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | |
mixed_group_by(data, by, numeric_agg_func='mean', numeric_fill_na=None, force_list_col_regex=None, columns_name=None)
Group a DataFrame by one or more columns and aggregate numeric vs. non-numeric columns differently.
This helper is meant for "mixed" tables where you want summary statistics for numeric columns (e.g., mean/std/min/max) while keeping all values for non-numeric columns as lists.
Behavior
byis normalized to a list of column names.- Dtypes are tightened via
DataFrame.convert_dtypes()(helps separate numeric vs. non-numeric columns reliably). - Missing values in grouping columns are filled with the empty string
""so rows with NA keys still participate in grouping. - Numeric columns (
np.number) are aggregated withnumeric_agg_func. If multiple functions are used, the resulting MultiIndex columns are flattened viamulti_index_to_single(..., sep="."). - All remaining columns are aggregated using
list(one list per group). - Columns that are entirely NA after aggregation are dropped.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame
|
Input DataFrame to group and aggregate. |
required |
by
|
list[str] | str
|
Column name or list of column names to group by. |
required |
numeric_agg_func
|
str | Callable | list[str | Callable]
|
Aggregation function(s) for numeric columns, passed to
|
'mean'
|
numeric_fill_na
|
Any | None
|
If not |
None
|
force_list_col_regex
|
str | None
|
Optional regex. Columns whose names match this pattern are treated as
non-numeric (i.e., aggregated as |
None
|
columns_name
|
str | None
|
Optional name for the resulting DataFrame columns. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Aggregated DataFrame with: |
Source code in src/kibad_llm/utils/job_return.py
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 | |