Skip to content

Commit

Permalink
fix: Improve logging
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianMichelsen committed Oct 28, 2022
1 parent 3515083 commit 40b6341
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 33 deletions.
12 changes: 11 additions & 1 deletion src/metaDMG/fit/fits.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,30 @@
import numpyro
import pandas as pd
from logger_tt import logger
from tqdm import tqdm
from tqdm.rich import tqdm
from tqdm.std import TqdmExperimentalWarning

from metaDMG.errors import BadDataError, FittingError
from metaDMG.fit import bayesian, fit_utils, frequentist
from metaDMG.fit.mismatches import add_reference_count
from metaDMG.utils import Config


# from tqdm import tqdm

numpyro.enable_x64()

#%%

BAYESIAN_MAXIMUM_SIZE = 100

#%%

# XXX Works, but should be a better way
# with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=TqdmExperimentalWarning)


#%%


Expand Down
26 changes: 13 additions & 13 deletions src/metaDMG/fit/serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ def run_LCA(config: Config, force: bool = False) -> None:

def run_damage_no_lca(config: Config, force: bool = False) -> None:

logger.info(f"Getting damage.")
# logger.info(f"Getting damage.")

targets = [
config["path_mismatches_txt"],
Expand All @@ -349,7 +349,7 @@ def run_damage_no_lca(config: Config, force: bool = False) -> None:
if not metaDMG_cpp_is_valid(config):
raise metadamageError()

logger.info(f"Computing damage. NOTE: NO LCA.")
logger.info(f"Computing mismatch matrices (without LCA).")

command_damage = get_damage_command(config)
command_damage_ugly = get_damage_ugly_command(config)
Expand All @@ -366,7 +366,7 @@ def run_damage_no_lca(config: Config, force: bool = False) -> None:
delete_tmp_dir(config)

else:
logger.info(f"Damage has already been computed before. NOTE: NO LCA.")
logger.info(f"Loading mismatch matrices (without LCA).")


#%%
Expand All @@ -384,18 +384,18 @@ def run_cpp(config: Config, force: bool = False) -> None:

def get_df_mismatches(config: Config, force: bool = False) -> pd.DataFrame:

logger.info(f"Getting df_mismatches")
# logger.info(f"Getting df_mismatches")

target = data_dir(config, name="mismatches")

if do_run(target, force=force):
logger.info(f"Computing df_mismatches.")
logger.info(f"Computing mismatch matrix dataframes.")
df_mismatches = mismatches.compute(config)
target.parent.mkdir(parents=True, exist_ok=True)
df_mismatches.to_parquet(target)

else:
logger.info(f"Loading df_mismatches.")
logger.info(f"Loading mismatch matrix dataframes.")
df_mismatches = pd.read_parquet(target)

return df_mismatches
Expand All @@ -414,21 +414,21 @@ def get_df_fit_results(
force: bool = False,
) -> pd.DataFrame:

logger.info(f"Getting df_fit_results.")
# logger.info(f"Getting df_fit_results.")

target = data_dir(config, name="fit_results")
if do_load(target, force=force):
logger.info(f"Try to load df_fit_results.")
logger.info(f"Try to load fit results.")
df_fit_results = pd.read_parquet(target)

# if frequentist fits only, return immediately
if not config["bayesian"]:
logger.info(f"Loading df_fit_results (frequentist).")
logger.info(f"Loading fit results (MAP).")
return df_fit_results

# if df_fit_results has already been run with Bayesian, return this
if dataframe_columns_contains(df_fit_results, "damage"):
logger.info(f"Loading df_fit_results (Bayesian).")
logger.info(f"Loading fit results (Bayesian).")
return df_fit_results

# Compute the fits
Expand Down Expand Up @@ -456,12 +456,12 @@ def get_df_results(
force: bool = False,
) -> pd.DataFrame:

logger.info(f"Getting df_results.")
# logger.info(f"Getting df_results.")

target = data_dir(config, name="results")

if do_load(target, force=force):
logger.info(f"Loading df_results.")
logger.info(f"Loading results as dataframe.")
df_results = pd.read_parquet(target)

# if frequentist fits only, return immediately
Expand All @@ -473,7 +473,7 @@ def get_df_results(
return df_results

# Compute the results:
logger.info(f"Computing df_results.")
logger.info(f"Computing final results.")
df_results = results.merge(config, df_mismatches, df_fit_results)
target.parent.mkdir(parents=True, exist_ok=True)
df_results.to_parquet(target)
Expand Down
29 changes: 10 additions & 19 deletions src/metaDMG/loggers/log_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,25 @@ formatters:
format: "[%(asctime)s] | %(name)s:%(lineno)d | %(levelname)s | %(message)s"
datefmt: "%Y-%m-%d %H:%M:%S"
brief:
format: "[%(asctime)s] | %(levelname)s | %(message)s"
# format: "[%(asctime)s] | %(levelname)s | %(message)s"
format: "%(message)s"
datefmt: "%Y-%m-%d %H:%M:%S"

handlers:
console:
class: logging.StreamHandler
class: rich.logging.RichHandler
level: INFO
formatter: brief
stream: ext://sys.stdout

error_file_handler:
class: logging.handlers.TimedRotatingFileHandler
level: DEBUG
formatter: simple
filename: logs/log.txt
backupCount: 15
encoding: utf8
when: midnight

loggers:
urllib3:
level: WARNING
handlers: [console, error_file_handler]
propagate: no
# stream: ext://sys.stdout
show_time: true
show_level: true
show_path: false
rich_tracebacks: true
log_time_format: "%Y-%m-%d %H:%M:%S"

root:
level: DEBUG
handlers: [console, error_file_handler]
handlers: [console]

logger_tt:
suppress: ["exchangelib", "numba", "matplotlib", "absl"]
Expand Down

0 comments on commit 40b6341

Please sign in to comment.