diff --git a/.flake8 b/.flake8 deleted file mode 100644 index 1bcdb670a0a..00000000000 --- a/.flake8 +++ /dev/null @@ -1,4 +0,0 @@ -[flake8] -max-line-length = 128 -# ignore whitespaces in array slices (https://github.com/PyCQA/pycodestyle/issues/373) -ignore = E203,W503 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9b8f82a6d71..b2a20cb236a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,20 +4,21 @@ default_language_version: exclude: '^tools/(build_utils/fypp)' fail_fast: false repos: +- repo: https://github.com/charliermarsh/ruff-pre-commit + rev: 'v0.0.261' + hooks: + - id: ruff + args: [ --fix, --exit-non-zero-on-fix ] + exclude: >- + (?x)^( + .cp2k/.*| + )$ - repo: https://github.com/ambv/black rev: 22.6.0 hooks: - id: black name: Reformat Python files with the black code formatter files: '^.*(/PACKAGE)|(\.py)$' -- repo: https://github.com/pycqa/flake8 - rev: 5.0.4 - hooks: - - id: flake8 - exclude: >- - (?x)^( - .cp2k/.*| - )$ - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.3.0 hooks: diff --git a/.ruff.toml b/.ruff.toml new file mode 100644 index 00000000000..b4f434df244 --- /dev/null +++ b/.ruff.toml @@ -0,0 +1,3 @@ +select = ["E", "F", "B"] +line-length = 128 +ignore = ["B905"] diff --git a/src/acc/libsmm_acc/kernels/smm_acc.py b/src/acc/libsmm_acc/kernels/smm_acc.py index 2832537d784..4d71c7831e9 100644 --- a/src/acc/libsmm_acc/kernels/smm_acc.py +++ b/src/acc/libsmm_acc/kernels/smm_acc.py @@ -83,7 +83,7 @@ def compatible_mnk(algo, m, n, k): compatible = False else: if algo != "medium": - assert False, f"Cannot identify algorithm:{str(algo)}" + raise AssertionError(f"Cannot identify algorithm:{str(algo)}") return compatible diff --git a/src/acc/libsmm_acc/kernels/smm_acc_predict.py b/src/acc/libsmm_acc/kernels/smm_acc_predict.py index 51e230a9a5e..111b9a3c7df 100644 --- a/src/acc/libsmm_acc/kernels/smm_acc_predict.py +++ b/src/acc/libsmm_acc/kernels/smm_acc_predict.py @@ -247,14 +247,14 @@ def get_baseline_performances_per_mnk(data, algorithm, gpu, autotuning): & (data.v == baseline_pars["v"]) ].index.tolist() else: - assert False, f"Cannot recognize algorithm: {algorithm}" + raise AssertionError(f"Cannot recognize algorithm: {algorithm}") if len(idx_baseline) == 1: idx_baseline = idx_baseline[0] baseline_perf[mnk] = data["perf (Gflop/s)"][idx_baseline] elif len(idx_baseline) > 1: - assert False, "Found more than one corresponding index: " + str( - idx_baseline + raise AssertionError( + "Found more than one corresponding index: " + str(idx_baseline) ) else: pass # if none were found, they're in another data chunk. Do nothing. diff --git a/src/acc/libsmm_acc/notebooks/nb_helper.py b/src/acc/libsmm_acc/notebooks/nb_helper.py index de6757b4476..82f2145d279 100644 --- a/src/acc/libsmm_acc/notebooks/nb_helper.py +++ b/src/acc/libsmm_acc/notebooks/nb_helper.py @@ -57,7 +57,7 @@ def get_folders_to_read(to_read, autotuning_data_path): if to_read.match(f) is not None ] else: - assert False, "Cannot recognize option: " + to_read + raise AssertionError("Cannot recognize option: " + to_read) num_folders_to_read = len(folders_to_read) assert num_folders_to_read > 0 diff --git a/src/acc/libsmm_acc/predict/predict_train.py b/src/acc/libsmm_acc/predict/predict_train.py index 1e6a751bdda..27b99be8bee 100755 --- a/src/acc/libsmm_acc/predict/predict_train.py +++ b/src/acc/libsmm_acc/predict/predict_train.py @@ -582,7 +582,7 @@ def get_hyperparameter_grid(algo, model_name, n_features): "n_estimators": list(n_estimators), } else: - assert False, "Cannot recognize model: " + model_name + raise AssertionError("Cannot recognize model: " + model_name) return param_grid @@ -700,7 +700,9 @@ def get_model(model_to_train, algo, njobs, ntrees): elif model_to_train == "xgb-RF": model, model_name = get_xgb_RandomForest_model(algo, njobs, ntrees) else: - assert False, "Cannot recognize model: " + model_to_train + ". Options: DT, RF" + raise AssertionError( + "Cannot recognize model: " + model_to_train + ". Options: DT, RF" + ) return model, model_name @@ -849,7 +851,7 @@ def train_model(X, X_mnk, Y, algo, model_options, folder, log): # Hyperparameter Optimization param_grid = get_hyperparameter_grid(algo, model_name, n_features) if param_grid is None: - assert False, "param_grid object is None. Please implement!" + raise AssertionError("param_grid object is None. Please implement!") # At this point, we "cheat"/"take a shortcut" in 2 ways: # - we split into train/test partitions using the simple default splitter, not one that is aware of mnk-groups diff --git a/src/acc/libsmm_acc/predict/prepare_training_data.py b/src/acc/libsmm_acc/predict/prepare_training_data.py index bd0fe249701..e436ea1225e 100755 --- a/src/acc/libsmm_acc/predict/prepare_training_data.py +++ b/src/acc/libsmm_acc/predict/prepare_training_data.py @@ -113,10 +113,11 @@ def get_performance_closest_to_baseline( if len(idx_baseline) > 0: break else: - assert False, ( - 'Could not find closest baseline for mnk=({}x{}x{}) and for algorithm "{}".' - "\nLast baseline parameters searched:\n{}" - "\nParameter sets searched:\n".format(m, n, k, algorithm, baseline_pars) + raise AssertionError( + ( + 'Could not find closest baseline for mnk=({}x{}x{}) and for algorithm "{}".\n' + "Last baseline parameters searched:\n{}\nParameter sets searched:\n" + ).format(m, n, k, algorithm, baseline_pars) ) idx_baseline = idx_baseline[0] @@ -142,7 +143,7 @@ def process_chunk(data_chunk, algorithm, gpu_properties, autotuning_properties): # For each (mnk), ... baseline_performances = dict() max_performances = dict() - for i, mnk in enumerate(mnks): + for _i, mnk in enumerate(mnks): data_mnk = data_chunk[data_chunk["mnk"] == mnk] m, n, k = mnk_pattern.match(mnk).groups() @@ -433,7 +434,7 @@ def plot_baseline(baseline_perfs_by_algo, data_path, algorithms): # Get all mnks mnk_sequences = list() - for algo, baseline_dic in baseline_perfs_by_algo.items(): + for _algo, baseline_dic in baseline_perfs_by_algo.items(): mnk_sequences += list(baseline_dic.keys()) all_mnks = list(set.union(set(mnk_sequences))) @@ -451,9 +452,9 @@ def plot_baseline(baseline_perfs_by_algo, data_path, algorithms): baseline_perfs[mnk] = baseline_perfs_by_algo[algo][mnk] break else: - assert ( - False - ), "NOOOO this is actually impossible by def of all_mnks, isn't it?" + raise AssertionError( + "NOOOO this is actually impossible by def of all_mnks, isn't it?" + ) # Sort mnks = list() diff --git a/src/acc/opencl/smm/tune_multiply.py b/src/acc/opencl/smm/tune_multiply.py index 4efcea349bb..b75a90caef0 100755 --- a/src/acc/opencl/smm/tune_multiply.py +++ b/src/acc/opencl/smm/tune_multiply.py @@ -741,7 +741,7 @@ def handle_sigint(self, signum, frame): ) args = argparser.parse_args() # OPENCL_LIBSMM_SMM_xx=tune|enabled|on must be given to permit tuning) - if not os.getenv("OPENCL_LIBSMM_SMM_WS") in {"tune", "enabled", "on"}: + if os.getenv("OPENCL_LIBSMM_SMM_WS") not in {"tune", "enabled", "on"}: os.environ["OPENCL_LIBSMM_SMM_WS"] = "{}".format(args.ws) # if not os.getenv("OPENCL_LIBSMM_SMM_AL") in {"tune", "enabled", "on"}: # os.environ["OPENCL_LIBSMM_SMM_AL"] = "{}".format(args.al)