From 75585b210ff377b4c91dcc7ebdd4cc3342e7518f Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Tue, 28 Jan 2025 21:41:30 +0100 Subject: [PATCH 1/4] Add ruff to the testing --- .github/workflows/main.yml | 4 +++- Pipfile | 2 +- compiler_opt/es/blackbox_evaluator.py | 14 ++++++-------- compiler_opt/es/blackbox_test_utils.py | 2 +- pyproject.toml | 9 +++++++-- 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index cd3b5a95..f72a7cce 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -43,12 +43,14 @@ jobs: strategy: matrix: python-version: ${{ fromJSON(needs.Envvars.outputs.version_matrix) }} - task: [Typecheck, Lint, Yapf, Test] + task: [Typecheck, Lint, Ruff, Yapf, Test] include: - task: Typecheck cmd: pytype -j auto . - task: Lint cmd: pylint --rcfile .pylintrc --recursive yes . + - task: Ruff + cmd: pipx run ruff==0.9.3 check - task: Yapf cmd: yapf . -drp - task: Test diff --git a/Pipfile b/Pipfile index 044b3d1e..1ce8f96d 100644 --- a/Pipfile +++ b/Pipfile @@ -15,9 +15,9 @@ dm-reverb = "==0.14.0" pylint = "==3.3.2" pytest = "==8.3.4" pytype = "==2024.10.11" +ruff = "==0.9.3" yapf = "==0.43.0" [ci] joblib = "==1.4.2" shap = "==0.46.0" - diff --git a/compiler_opt/es/blackbox_evaluator.py b/compiler_opt/es/blackbox_evaluator.py index 953a8152..35de7500 100644 --- a/compiler_opt/es/blackbox_evaluator.py +++ b/compiler_opt/es/blackbox_evaluator.py @@ -124,14 +124,12 @@ def __init__(self, train_corpus: corpus.Corpus, def get_results( self, pool: FixedWorkerPool, perturbations: List[policy_saver.Policy] ) -> List[concurrent.futures.Future]: - job_args = [] - for perturbation in perturbations: - job_args.append({ - 'modules': self._train_corpus.module_specs, - 'function_index_path': self._function_index_path, - 'bb_trace_path': self._bb_trace_path, - 'tflite_policy': perturbation - }) + job_args = [{ + 'modules': self._train_corpus.module_specs, + 'function_index_path': self._function_index_path, + 'bb_trace_path': self._bb_trace_path, + 'tflite_policy': perturbation + } for perturbation in perturbations] _, futures = buffered_scheduler.schedule_on_worker_pool( action=lambda w, args: w.compile_corpus_and_evaluate(**args), diff --git a/compiler_opt/es/blackbox_test_utils.py b/compiler_opt/es/blackbox_test_utils.py index 3a0a2ca4..404525e9 100644 --- a/compiler_opt/es/blackbox_test_utils.py +++ b/compiler_opt/es/blackbox_test_utils.py @@ -45,7 +45,7 @@ def compile(self, policy: policy_saver.Policy, class ESTraceWorker(worker.Worker): """Temporary placeholder worker. - + This is a test worker for TraceBlackboxEvaluator that expects a slightly different interface than other workers. """ diff --git a/pyproject.toml b/pyproject.toml index bdf58d2c..4fd17dba 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,12 @@ -# DO always create a tracking issue when allow-listing warnings -# DO NOT disable warnings-as-error: warnings of today are tomorrow's evolvability blocker. +[tool.ruff] +line-length = 103 +lint.select = [ "C40", "C9", "E", "F", "PERF", "W" ] +lint.ignore = [ "E722", "E731", "E741", "F401", "PERF203" ] +lint.mccabe.max-complexity = 18 [tool.pytest.ini_options] +# DO always create a tracking issue when allow-listing warnings +# DO NOT disable warnings-as-error: warnings of today are tomorrow's evolvability blocker. filterwarnings = [ # Treat warnings as errors "error", From a45a6d4fd8b75c69cc34432adbf30fb2e25f4c70 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Wed, 29 Jan 2025 08:00:57 +0100 Subject: [PATCH 2/4] Update blackbox_evaluator.py --- compiler_opt/es/blackbox_evaluator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler_opt/es/blackbox_evaluator.py b/compiler_opt/es/blackbox_evaluator.py index 35de7500..78edc545 100644 --- a/compiler_opt/es/blackbox_evaluator.py +++ b/compiler_opt/es/blackbox_evaluator.py @@ -129,7 +129,7 @@ def get_results( 'function_index_path': self._function_index_path, 'bb_trace_path': self._bb_trace_path, 'tflite_policy': perturbation - } for perturbation in perturbations] + } for perturbation in perturbations] _, futures = buffered_scheduler.schedule_on_worker_pool( action=lambda w, args: w.compile_corpus_and_evaluate(**args), From 01243b2e2b8f30e84ec3ae836f7f8cd7b7950f73 Mon Sep 17 00:00:00 2001 From: Aiden Grossman Date: Wed, 29 Jan 2025 08:02:18 +0000 Subject: [PATCH 3/4] Add ruff to pipfile.lock --- Pipfile | 2 +- Pipfile.lock | 28 ++++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/Pipfile b/Pipfile index 1ce8f96d..db2e9bf8 100644 --- a/Pipfile +++ b/Pipfile @@ -15,8 +15,8 @@ dm-reverb = "==0.14.0" pylint = "==3.3.2" pytest = "==8.3.4" pytype = "==2024.10.11" -ruff = "==0.9.3" yapf = "==0.43.0" +ruff = "==0.9.3" [ci] joblib = "==1.4.2" diff --git a/Pipfile.lock b/Pipfile.lock index 43eb06a3..fa68d3db 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "d87c1c9dcf050c36af0ec282b601a1e4fed2f46bf24260a257fda6e3c04bd9af" + "sha256": "bd6e055867dec0deae82ed0df60f1bf49a2e09acc7a8ef15c1c94b274662293d" }, "pipfile-spec": 6, "requires": {}, @@ -1792,6 +1792,31 @@ "markers": "python_version >= '3.8'", "version": "==6.0.2" }, + "ruff": { + "hashes": [ + "sha256:006e5de2621304c8810bcd2ee101587712fa93b4f955ed0985907a36c427e0c2", + "sha256:040ceb7f20791dfa0e78b4230ee9dce23da3b64dd5848e40e3bf3ab76468dcf4", + "sha256:2dc153c25e715be41bb228bc651c1e9b1a88d5c6e5ed0194fa0dfea02b026439", + "sha256:33866c3cc2a575cbd546f2cd02bdd466fed65118e4365ee538a3deffd6fcb730", + "sha256:5a5a46e09355695fbdbb30ed9889d6cf1c61b77b700a9fafc21b41f097bfbba4", + "sha256:646909a1e25e0dc28fbc529eab8eb7bb583079628e8cbe738192853dbbe43af5", + "sha256:7f39b879064c7d9670197d91124a75d118d00b0990586549949aae80cdc16624", + "sha256:800d773f6d4d33b0a3c60e2c6ae8f4c202ea2de056365acfa519aa48acf28e0b", + "sha256:8293f89985a090ebc3ed1064df31f3b4b56320cdfcec8b60d3295bddb955c22a", + "sha256:90230a6b8055ad47d3325e9ee8f8a9ae7e273078a66401ac66df68943ced029b", + "sha256:96a87ec31dc1044d8c2da2ebbed1c456d9b561e7d087734336518181b26b3aa5", + "sha256:9bb7554aca6f842645022fe2d301c264e6925baa708b392867b7a62645304df4", + "sha256:a187171e7c09efa4b4cc30ee5d0d55a8d6c5311b3e1b74ac5cb96cc89bafc43c", + "sha256:ba6eea4459dbd6b1be4e6bfc766079fb9b8dd2e5a35aff6baee4d9b1514ea519", + "sha256:c4bb09d2bbb394e3730d0918c00276e79b2de70ec2a5231cd4ebb51a57df9ba1", + "sha256:c59ab92f8e92d6725b7ded9d4a31be3ef42688a115c6d3da9457a5bda140e2b4", + "sha256:cabc332b7075a914ecea912cd1f3d4370489c8018f2c945a30bcc934e3bc06a6", + "sha256:eabe5eb2c19a42f4808c03b82bd313fc84d4e395133fb3fc1b1516170a31213c" + ], + "index": "pypi", + "markers": "python_version >= '3.7'", + "version": "==0.9.3" + }, "tabulate": { "hashes": [ "sha256:0095b12bf5966de529c0feb1fa08671671b3368eec77d7ef7ab114be2c068b3c", @@ -1873,4 +1898,3 @@ } } } - From 31cedbc5b83aaf0c00028c602566e98a14b5af5f Mon Sep 17 00:00:00 2001 From: Aiden Grossman Date: Wed, 29 Jan 2025 08:03:05 +0000 Subject: [PATCH 4/4] Fix workflow file --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f72a7cce..2f7c5ef5 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -50,7 +50,7 @@ jobs: - task: Lint cmd: pylint --rcfile .pylintrc --recursive yes . - task: Ruff - cmd: pipx run ruff==0.9.3 check + cmd: ruff check - task: Yapf cmd: yapf . -drp - task: Test