Skip to content

Commit 0fb7786

Browse files
committed
Remove nested try: except: from fit
1 parent 655f98d commit 0fb7786

File tree

1 file changed

+24
-31
lines changed

1 file changed

+24
-31
lines changed

autosklearn/automl.py

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -709,15 +709,11 @@ def fit(
709709
)
710710

711711
# Check the re-sampling strategy
712-
try:
713-
self._check_resampling_strategy(
714-
X=X,
715-
y=y,
716-
task=self._task,
717-
)
718-
except Exception as e:
719-
self._fit_cleanup()
720-
raise e
712+
self._check_resampling_strategy(
713+
X=X,
714+
y=y,
715+
task=self._task,
716+
)
721717

722718
# Reset learnt stuff
723719
self.models_ = None
@@ -793,7 +789,6 @@ def fit(
793789
)
794790

795791
if only_return_configuration_space:
796-
self._fit_cleanup()
797792
return self.configuration_space
798793

799794
# == Perform dummy predictions
@@ -927,27 +922,21 @@ def fit(
927922
trials_callback=self._get_trials_callback,
928923
)
929924

930-
try:
931-
(
932-
self.runhistory_,
933-
self.trajectory_,
934-
self._budget_type,
935-
) = _proc_smac.run_smbo()
936-
trajectory_filename = os.path.join(
937-
self._backend.get_smac_output_directory_for_run(self._seed),
938-
"trajectory.json",
939-
)
940-
saveable_trajectory = [
941-
list(entry[:2])
942-
+ [entry[2].get_dictionary()]
943-
+ list(entry[3:])
944-
for entry in self.trajectory_
945-
]
946-
with open(trajectory_filename, "w") as fh:
947-
json.dump(saveable_trajectory, fh)
948-
except Exception as e:
949-
self._logger.exception(e)
950-
raise
925+
(
926+
self.runhistory_,
927+
self.trajectory_,
928+
self._budget_type,
929+
) = _proc_smac.run_smbo()
930+
trajectory_filename = os.path.join(
931+
self._backend.get_smac_output_directory_for_run(self._seed),
932+
"trajectory.json",
933+
)
934+
saveable_trajectory = [
935+
list(entry[:2]) + [entry[2].get_dictionary()] + list(entry[3:])
936+
for entry in self.trajectory_
937+
]
938+
with open(trajectory_filename, "w") as fh:
939+
json.dump(saveable_trajectory, fh)
951940

952941
self._logger.info("Starting shutdown...")
953942
# Wait until the ensemble process is finished to avoid shutting down
@@ -984,6 +973,10 @@ def fit(
984973
# in a try: finally: so that if something goes wrong, we at least close
985974
# down the logging server, preventing it from hanging and not closing
986975
# until ctrl+c is pressed
976+
except Exception as e:
977+
# This will be called before the _fit_cleanup
978+
self._logger.exception(e)
979+
raise e
987980
finally:
988981
self._fit_cleanup()
989982

0 commit comments

Comments
 (0)