Skip to content

Commit 764a7bf

Browse files
committed
add logging warning
1 parent 2237ddd commit 764a7bf

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

autointent/_pipeline/_pipeline.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,14 @@ def _fit(self, context: Context, sampler: SamplerType) -> None:
144144
"""
145145
self.context = context
146146
self._logger.info("starting pipeline optimization...")
147+
148+
if context.logging_config.clear_ram:
149+
self._logger.warning(
150+
"Memory storage is not compatible with resuming optimization. "
151+
"Modules from previous runs won't be available. "
152+
"Set dump_modules=True in LoggingConfig to enable proper resuming."
153+
)
154+
147155
self.context.callback_handler.start_run(
148156
run_name=self.context.logging_config.get_run_name(),
149157
dirpath=self.context.logging_config.dirpath,

autointent/nodes/_node_optimizer.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ def fit(self, context: Context, sampler: SamplerType = "brute", n_jobs: int = 1)
113113
)
114114
self._counter = max(self._counter, finished_trials)
115115

116+
# if n_trials == 0:
117+
# config = self.suggest(Trial(), search_space)
118+
#
119+
# module = self.node_info.modules_available[module_name]
120+
# module.load()
121+
116122
optuna.logging.set_verbosity(optuna.logging.WARNING)
117123
obj = partial(self.objective, module_name=module_name, search_space=search_space, context=context)
118124

tests/pipeline/test_pipeline_interruption.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ def tracking_objective2(trial, *args, **kwargs):
9696
second_run_trials.add(trial.number)
9797
return original_objective2(trial, *args, **kwargs)
9898

99-
# pipeline_optimizer.nodes[NodeType.scoring].objective = tracking_objective2
10099
pipeline_optimizer.set_config(logging_config)
101100
pipeline_optimizer.set_config(DataConfig(scheme="ho", separation_ratio=None))
102101
with patch.object(pipeline_optimizer.nodes[NodeType.scoring], "objective", side_effect=tracking_objective2):
@@ -121,3 +120,30 @@ def tracking_objective2(trial, *args, **kwargs):
121120
f"Database {db_file.name} did not have more trials after second run "
122121
f"({trials_after_first_run[db_file.name]} vs {trials_after_second_run})"
123122
)
123+
124+
125+
def test_resuming_with_memory_storage_warning(dataset_no_oos, tmp_path, caplog):
126+
"""Test that a warning is issued when trying to resume with memory storage."""
127+
project_dir = tmp_path
128+
search_space = get_search_space("optuna")
129+
130+
# Setup first pipeline with memory storage
131+
logging_config = LoggingConfig(
132+
project_dir=project_dir,
133+
run_name="test_memory_storage_warning",
134+
dump_modules=False, # Keep modules in RAM
135+
clear_ram=False,
136+
)
137+
138+
pipeline_optimizer = Pipeline.from_search_space(search_space)
139+
pipeline_optimizer.set_config(logging_config)
140+
pipeline_optimizer.set_config(DataConfig(
141+
scheme="ho",
142+
separation_ratio=None,
143+
n_folds=2,
144+
validation_size=0.2
145+
))
146+
pipeline_optimizer.fit(dataset_no_oos, refit_after=False, sampler="random")
147+
148+
assert any("Memory storage is not compatible with resuming optimization" in record.message for record in caplog.records)
149+

0 commit comments

Comments
 (0)