-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve packaging, logging, style (#838)
* Update logger and add quiet mode * Improve packaging and some cleanup
- Loading branch information
Showing
4 changed files
with
34 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
############################################################################# | ||
## © Copyright CERN 2023. All rights not expressly granted are reserved. ## | ||
## ## | ||
## This program is free software: you can redistribute it and/or modify it ## | ||
## under the terms of the GNU General Public License as published by the ## | ||
## Free Software Foundation, either version 3 of the License, or (at your ## | ||
## option) any later version. This program is distributed in the hope that ## | ||
## it will be useful, but WITHOUT ANY WARRANTY; without even the implied ## | ||
## warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ## | ||
## See the GNU General Public License for more details. ## | ||
## You should have received a copy of the GNU General Public License ## | ||
## along with this program. if not, see <https://www.gnu.org/licenses/>. ## | ||
############################################################################# | ||
|
||
import sys | ||
from machine_learning_hep.steer_analysis import main | ||
|
||
sys.exit(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
############################################################################# | ||
## © Copyright CERN 2018. All rights not expressly granted are reserved. ## | ||
## © Copyright CERN 2023. All rights not expressly granted are reserved. ## | ||
## Author: [email protected] ## | ||
## This program is free software: you can redistribute it and/or modify it ## | ||
## under the terms of the GNU General Public License as published by the ## | ||
|
@@ -55,8 +55,9 @@ class MLLoggerFormatter(logging.Formatter): | |
reset = '\x1b[0m' | ||
|
||
# Define default format string | ||
def __init__(self, fmt='%(levelname)s in %(pathname)s:%(lineno)d:\n ↳ %(message)s', | ||
def __init__(self, fmt=None, | ||
datefmt=None, style='%', color=False): | ||
fmt = fmt or '%(levelname)s in %(pathname)s:%(lineno)d:\n ↳ %(message)s' | ||
logging.Formatter.__init__(self, fmt, datefmt, style) | ||
self.color = color | ||
|
||
|
@@ -86,7 +87,7 @@ def format(self, record): | |
return logging.Formatter.format(self, cached_record) | ||
|
||
|
||
def configure_logger(debug, logfile=None): | ||
def configure_logger(debug, logfile=None, quiet=False): | ||
""" | ||
Basic configuration adding a custom formatted StreamHandler and turning on | ||
debug info if requested. | ||
|
@@ -95,14 +96,11 @@ def configure_logger(debug, logfile=None): | |
if logger.hasHandlers(): | ||
return | ||
|
||
# Turn on debug info only on request | ||
if debug: | ||
logger.setLevel(logging.DEBUG) | ||
else: | ||
logger.setLevel(logging.INFO) | ||
logger.setLevel(logging.DEBUG if debug else logging.INFO) | ||
|
||
sh = logging.StreamHandler() | ||
formatter = MLLoggerFormatter(color=lambda : getattr(sh.stream, 'isatty', None)) | ||
formatter = MLLoggerFormatter(color=lambda : getattr(sh.stream, 'isatty', None), | ||
fmt = '%(levelname)s ➞ %(message)s' if quiet else None) | ||
|
||
sh.setFormatter(formatter) | ||
logger.addHandler(sh) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
############################################################################# | ||
## © Copyright CERN 2018. All rights not expressly granted are reserved. ## | ||
## © Copyright CERN 2023. All rights not expressly granted are reserved. ## | ||
## Author: [email protected] ## | ||
## This program is free software: you can redistribute it and/or modify it ## | ||
## under the terms of the GNU General Public License as published by the ## | ||
|
@@ -25,7 +25,7 @@ | |
|
||
def xgboost_classifier(model_config): # pylint: disable=W0613 | ||
return XGBClassifier(verbosity=1, | ||
n_gpus=0, | ||
# n_gpus=0, | ||
**model_config) | ||
|
||
|
||
|
@@ -55,7 +55,8 @@ def yield_model_(self, model_config, space): | |
|
||
def save_model_(self, model, out_dir): | ||
out_filename = join(out_dir, "xgboost_classifier.sav") | ||
pickle.dump(model, open(out_filename, 'wb'), protocol=4) | ||
with open(out_filename, 'wb') as outfile: | ||
pickle.dump(model, outfile, protocol=4) | ||
out_filename = join(out_dir, "xgboost_classifier.model") | ||
model.save_model(out_filename) | ||
|
||
|