automl / automl/Auto-PyTorch

[refactor] `_search` function in autoPytorch/api/base_task.py

Open
#148 2 comments 0 reactions 1 assignee Claimed by @nabenabe0928 View on GitHub
enhancement not urgent refactoring
Dominant language
Python
Stars
2.5k
Forks
300
PR merge metrics
No merged PRs in 30d

Description

Currently, comments complement the information what we are doing inside the code, but we can split these sections into functions.
In fact, too long function typically violates flake8 C901.
Also you can check why it is not good to write a long function [here](https://en.wikipedia.org/wiki/Cyclomatic_complexity).

Currently, the code looks like this:
```
def _search(self, ...):
# Initialise information needed for the experiment
process 1

# Print debug information to log
process 2

# Handle time resource allocation
process 3

# Make sure that at least 2 models are created for the ensemble process
process 4

# ============> Run dummy predictions
process 5

# ============> Run traditional ml
process 6

# ============> Starting ensemble
process 7

# ==> Run SMAC
process 8

post process

return results
```

However, we can split like this (I do not think we need to split everything):
```
def _init_experiment_info(self, ...):
process 1
return results

def _run_dummy_predictions(self, ...):
process 5
return results

def _run_traditional_ml(self, ...):
process 6
return results

def _start_ensemble(self, ...):
process 7
return results

def _run_smac(self, ...):
process 8
return results

def _post_processing(self, ...):
post processing
return results

def _search(self, ...):
self._init_experiment_info(...):

# Print debug information to log
process 2

# Handle time resource allocation
process 3

# Make sure that at least 2 models are created for the ensemble process
process 4

self._run_dummy_predictions(...)
self._run_traditional_ml(...)
self._start_ensemble(...)
self._run_smac(...)
self._post_processing(...)

```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.