Skip to content

Commit 5379632

Browse files
committed
[temporal] [cont] Fix errors
[test] Add the tests for the instantiation of abstract evaluator 1 -- 3 [test] Add the tests for util 1 -- 2 [test] Add the tests for train_evaluator 1 -- 2 [refactor] [test] Clean up the pipeline classes and add tests for it 1 -- 2 [test] Add the tests for tae 1 -- 4 [fix] Fix an error due to the change in extract learning curve [experimental] Increase the coverage [test] Add tests for pipeline repr Since the modifications in tests removed the coverage on pipeline repr, I added tests to increase those parts. Basically, the decrease in the coverage happened due to the usage of dummy pipelines.
1 parent 5371f5f commit 5379632

16 files changed

+775
-279
lines changed

autoPyTorch/api/base_task.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1044,7 +1044,7 @@ def _search(
10441044
DisableFileOutputParameters.y_opt in self._disable_file_output
10451045
and self.ensemble_size > 1
10461046
):
1047-
self._logger.warning(f"No ensemble will be created when {DisableFileOutputParameters.y_optimization}"
1047+
self._logger.warning(f"No ensemble will be created when {DisableFileOutputParameters.y_opt}"
10481048
f" is in disable_file_output")
10491049

10501050
self._memory_limit = memory_limit

autoPyTorch/evaluation/abstract_evaluator.py

+17-6
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,16 @@ def with_default_pipeline_config(
193193
f'{cls.__name__}.with_default_pipeline_config() got multiple values for argument `budget_type`'
194194
)
195195

196+
budget_type_choices = ('epochs', 'runtime')
196197
if pipeline_config is None:
197198
pipeline_config = get_default_pipeline_config(choice=choice)
199+
if 'budget_type' not in pipeline_config:
200+
raise ValueError('pipeline_config must have `budget_type`')
198201

199202
budget_type = pipeline_config['budget_type']
203+
if pipeline_config['budget_type'] not in budget_type_choices:
204+
raise ValueError(f"budget_type must be in {budget_type_choices}, but got {budget_type}")
205+
200206
kwargs.update(pipeline_config=pipeline_config, budget_type=budget_type)
201207
return cls(**kwargs)
202208

@@ -307,6 +313,9 @@ def _init_dataset_properties(self) -> None:
307313
))
308314

309315
self.X_train, self.y_train = datamanager.train_tensors
316+
self.unique_train_labels = [
317+
list(np.unique(self.y_train[train_indices])) for train_indices, _ in self.splits
318+
]
310319
self.X_valid, self.y_valid, self.X_test, self.y_test = None, None, None, None
311320
if datamanager.val_tensors is not None:
312321
self.X_valid, self.y_valid = datamanager.val_tensors
@@ -377,7 +386,7 @@ def predict(
377386
self,
378387
X: Optional[np.ndarray],
379388
pipeline: BaseEstimator,
380-
label_examples: Optional[np.ndarray] = None
389+
unique_train_labels: Optional[List[int]] = None
381390
) -> Optional[np.ndarray]:
382391
"""
383392
A wrapper function to handle the prediction of regression or classification tasks.
@@ -387,7 +396,8 @@ def predict(
387396
A set of features to feed to the pipeline
388397
pipeline (BaseEstimator):
389398
A model that will take the features X return a prediction y
390-
label_examples (Optional[np.ndarray]):
399+
unique_train_labels (Optional[List[int]]):
400+
The unique labels included in the train split.
391401
392402
Returns:
393403
(np.ndarray):
@@ -411,7 +421,7 @@ def predict(
411421
prediction=pred,
412422
num_classes=self.num_classes,
413423
output_type=self.output_type,
414-
label_examples=label_examples
424+
unique_train_labels=unique_train_labels
415425
)
416426

417427
return pred
@@ -435,6 +445,10 @@ def _get_pipeline(self) -> BaseEstimator:
435445
A scikit-learn compliant pipeline which is not yet fit to the data.
436446
"""
437447
config = self.evaluator_params.configuration
448+
if not isinstance(config, (int, str, Configuration)):
449+
raise TypeError("The type of configuration must be either (int, str, Configuration), "
450+
f"but got type {type(config)}")
451+
438452
kwargs = dict(
439453
config=config,
440454
random_state=np.random.RandomState(self.fixed_pipeline_params.seed),
@@ -452,9 +466,6 @@ def _get_pipeline(self) -> BaseEstimator:
452466
exclude=self.fixed_pipeline_params.exclude,
453467
search_space_updates=self.fixed_pipeline_params.search_space_updates,
454468
**kwargs)
455-
else:
456-
raise ValueError("The type of configuration must be either (int, str, Configuration), "
457-
f"but got type {type(config)}")
458469

459470
def _loss(self, labels: np.ndarray, preds: np.ndarray) -> Dict[str, float]:
460471
"""SMAC follows a minimization goal, so the make_scorer

0 commit comments

Comments
 (0)