Skip to content

Commit

Permalink
Inherit local basf2 log level in gbasf2 grid jobs
Browse files Browse the repository at this point in the history
Local basf2 log level setting is now passed over to the grid jobs. You can now
limit the log size of jobs with many warnings via
`basf2.set_log_level(basf2.LogLevel.ERROR)`. This could fix some errors due to
too large log sizes. Implemented by pickling local `basf2.logging.log_level`.
  • Loading branch information
meliache committed Oct 26, 2023
1 parent 7483e1e commit 5e8d2df
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

[#203](https://github.com/nils-braun/b2luigi/pull/203) @AlexanderHeidelbach
* **gbasf2:** Fix `gbasf2_setup_path` setting not being passed through in some function calls.
* **gbasf2:** Local basf2 log level setting is now passed over to the grid jobs. You can now limit the log size of jobs with many warnings via `basf2.set_log_level(basf2.LogLevel.ERROR)`. This could fix some errors due to too large log sizes. Implemented by pickling local `basf2.logging.log_level`.

**Full Changelog**: https://github.com/nils-braun/b2luigi/compare/v0.10.1...main

Expand Down
5 changes: 3 additions & 2 deletions b2luigi/batch/processes/gbasf2_utils/pickle_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pickle

from basf2 import conditions as b2conditions
from basf2 import conditions as b2conditions, logging
from basf2.pickle_path import serialize_path
from variables import variables as vm

Expand All @@ -16,7 +16,7 @@ def get_alias_dict_from_variable_manager():

def write_path_and_state_to_file(basf2_path, file_path):
"""
Serialize basf2 path and variables from variable manager to file.
Serialize basf2 path, aliases and log_level to file.
Variant of ``basf2.pickle_path.write_path_to_file``, only with additional
serialization of the basf2 variable aliases and global tags.
Expand All @@ -32,5 +32,6 @@ def write_path_and_state_to_file(basf2_path, file_path):
serialized = serialize_path(basf2_path)
serialized["aliases"] = get_alias_dict_from_variable_manager()
serialized["globaltags"] = b2conditions.globaltags
serialized["log_level"] = logging.log_level
# serialized["conditions"] = b2conditions
pickle.dump(serialized, pickle_file)
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,25 @@ def get_global_tags_from_file(file_path):
except KeyError:
pass

def set_log_level_from_file(file_path):
"""
Extract and set global basf2 log level from pickle file.
"""
with open(file_path, 'br') as pickle_file:
serialized = pickle.load(pickle_file)
try:
basf2.set_log_level(serialized["log_level"])
except KeyError:
pass

pickle_file_path = "{{ pickle_file_path }}"
if not os.path.isfile(pickle_file_path):
raise FileNotFoundError(f"No pickle file found in {pickle_file_path}")

apply_alias_dict_from_file(pickle_file_path)
get_global_tags_from_file(pickle_file_path)
set_log_level_from_file(pickle_file_path)

path = b2pp.get_path_from_file(pickle_file_path)

basf2.print_path(path)
Expand Down

0 comments on commit 5e8d2df

Please sign in to comment.