Skip to content

Commit

Permalink
improve some log messages in cache logging
Browse files Browse the repository at this point in the history
  • Loading branch information
dbrakenhoff committed Dec 24, 2024
1 parent 3e3d2a2 commit 1ee715b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions nlmod/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,13 +447,13 @@ def _same_function_arguments(func_args_dic, func_args_dic_cache):
for key, item in func_args_dic.items():
# check if cache and function call have same argument names
if key not in func_args_dic_cache:
msg = f"cache was created using different function argument {key}, do not use cached data"
msg = f"cache was created using different function argument '{key}' not in cached arguments, do not use cached data"
logger.info(msg)
return False

# check if cache and function call have same argument types
if not isinstance(item, type(func_args_dic_cache[key])):
msg = f"cache was created using different function argument type: {key}: {type(func_args_dic_cache[key])}, do not use cached data"
msg = f"cache was created using different function argument types for {key}: current '{type(item)}' cache: '{type(func_args_dic_cache[key])}', do not use cached data"
logger.info(msg)
return False

Expand All @@ -469,11 +469,16 @@ def _same_function_arguments(func_args_dic, func_args_dic_cache):
else:
msg = f"cache was created using different function argument: {key}, do not use cached data"
logger.info(msg)
logger.debug(f"{key}: {item} != {func_args_dic_cache[key]}")
return False
elif isinstance(item, np.ndarray):
if not np.allclose(item, func_args_dic_cache[key]):
msg = f"cache was created using different numpy array for: {key}, do not use cached data"
logger.info(msg)
logger.debug(
f"array '{key}' max difference with stored copy is "
f"{np.max(np.abs(item - func_args_dic_cache[key]))}"
)
return False
elif isinstance(item, (pd.DataFrame, pd.Series, xr.DataArray)):
if not item.equals(func_args_dic_cache[key]):
Expand Down
2 changes: 1 addition & 1 deletion nlmod/sim/sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def sim(ds, exe_name=None, version_tag=None, **kwargs):
sim_name=ds.model_name,
exe_name=exe_name,
version=ds.mfversion,
sim_ws=ds.model_ws,
sim_ws=kwargs.pop("sim_ws", ds.model_ws),
**kwargs,
)

Expand Down

0 comments on commit 1ee715b

Please sign in to comment.