Skip to content

Commit

Permalink
Suppress all user warnings in routine instantiation for now
Browse files Browse the repository at this point in the history
  • Loading branch information
zhe-slac committed Mar 18, 2024
1 parent 9caea71 commit 87f5c64
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 15 deletions.
11 changes: 10 additions & 1 deletion src/badger/archive.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import warnings
import logging
logger = logging.getLogger(__name__)
from .db import save_run, remove_run_by_filename
Expand Down Expand Up @@ -90,7 +91,15 @@ def load_run(run_fname):
third_level,
run_fname)

routine = Routine.from_file(filename)
with warnings.catch_warnings(record=True) as caught_warnings:
routine = Routine.from_file(filename)

# Check if any user warnings were caught
for warning in caught_warnings:
if warning.category == UserWarning:
pass
else:
print(f"Caught user warning: {warning.message}")

return routine

Expand Down
13 changes: 12 additions & 1 deletion src/badger/db.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import warnings
from datetime import datetime
import logging
logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -166,7 +167,17 @@ def load_routine(name: str):
# return yaml.safe_load(records[0][1]), records[0][2]
routine_dict = yaml.safe_load(records[0][1])
# routine_dict['evaluator'] = None
return Routine(**routine_dict), records[0][2]
with warnings.catch_warnings(record=True) as caught_warnings:
routine = Routine(**routine_dict)

# Check if any user warnings were caught
for warning in caught_warnings:
if warning.category == UserWarning:
pass
else:
print(f"Caught user warning: {warning.message}")

return routine, records[0][2]
elif len(records) == 0:
# logger.warning(f'Routine {name} not found in the database!')
return None, None
Expand Down
37 changes: 24 additions & 13 deletions src/badger/gui/default/components/routine_page.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import warnings
import sqlite3
import traceback
from typing import List
Expand Down Expand Up @@ -600,19 +601,29 @@ def _compose_routine(self) -> Routine:
else:
script = None

return Routine(
# Xopt part
vocs=vocs,
generator={"name": generator_name} | generator_params,
# Badger part
name=name,
description=description,
environment={"name": env_name} | env_params,
initial_points=init_points_df.astype("double"),
critical_constraint_names=critical_constraints,
tags=None,
script=script,
)
with warnings.catch_warnings(record=True) as caught_warnings:
routine = Routine(
# Xopt part
vocs=vocs,
generator={"name": generator_name} | generator_params,
# Badger part
name=name,
description=description,
environment={"name": env_name} | env_params,
initial_points=init_points_df.astype("double"),
critical_constraint_names=critical_constraints,
tags=None,
script=script,
)

# Check if any user warnings were caught
for warning in caught_warnings:
if warning.category == UserWarning:
pass
else:
print(f"Caught user warning: {warning.message}")

return routine

def review(self):
try:
Expand Down

0 comments on commit 87f5c64

Please sign in to comment.