Skip to content

Commit

Permalink
Add warning in counterfactual manager when unable to load explainer (#…
Browse files Browse the repository at this point in the history
…1412)

* Add warning in counterfactual manager when unable to load explainer

Signed-off-by: Gaurav Gupta <[email protected]>

* Fix linting

Signed-off-by: Gaurav Gupta <[email protected]>
  • Loading branch information
gaugup authored May 10, 2022
1 parent cbe8a03 commit 9441f9b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""Defines the Counterfactual Manager class."""
import json
import pickle
import warnings
from pathlib import Path
from typing import Any, List, Optional, Union

Expand Down Expand Up @@ -723,6 +724,13 @@ def _load(path, rai_insights):
)

if counterfactual_config.explainer is None:
explainer_load_err = (
'ERROR-LOADING-COUNTERFACTUAL-EXPLAINER: '
'There was an error loading the '
'counterfactual explainer model. '
'Retraining the counterfactual '
'explainer.')
warnings.warn(explainer_load_err)
counterfactual_config.explainer = \
inst._create_diceml_explainer(
counterfactual_config.method,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,13 @@ def test_counterfactual_manager_save_load(self, tmpdir):
directory_manager.get_generators_directory() / "explainer.pkl"
os.remove(explainer_pkl_path)

rai_insights_copy_new = RAIInsights.load(save_dir)
with pytest.warns(UserWarning,
match='ERROR-LOADING-COUNTERFACTUAL-EXPLAINER: '
'There was an error loading the '
'counterfactual explainer model. '
'Retraining the counterfactual '
'explainer.'):
rai_insights_copy_new = RAIInsights.load(save_dir)
counterfactual_config_list = \
rai_insights_copy_new.counterfactual._counterfactual_config_list
assert len(counterfactual_config_list) == 2
Expand Down

0 comments on commit 9441f9b

Please sign in to comment.