Skip to content

Commit

Permalink
Merge pull request #126 from Infleqtion/update-checks
Browse files Browse the repository at this point in the history
Use `ruff` for formatting and linting
  • Loading branch information
perlinm authored Aug 9, 2024
2 parents 8c7b8d2 + 39b6692 commit 1d1b80a
Show file tree
Hide file tree
Showing 28 changed files with 233 additions and 267 deletions.
33 changes: 5 additions & 28 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ on:

jobs:
format:
name: Format check
name: Formatting check
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest
timeout-minutes: 3
Expand All @@ -37,7 +37,7 @@ jobs:
checks/format_.py
lint:
name: Lint check
name: Linting check
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest
timeout-minutes: 3
Expand All @@ -55,32 +55,9 @@ jobs:
run: |
python3 -m pip install --upgrade pip
python3 -m pip install '.[dev]'
- name: Pylint
- name: Lint
run: |
checks/pylint_.py --all
flake8:
name: Flake8 check
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest
timeout-minutes: 3
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: '3.11'
- uses: actions/cache@v4
with:
path: ${{ env.pythonLocation }}
key: ${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}
- name: Install dependencies
run: |
python3 -m pip install --upgrade pip
python3 -m pip install '.[dev]'
- name: Flake8
run: |
checks/flake8_.py
checks/lint_.py
mypy:
name: Type check
Expand All @@ -106,7 +83,7 @@ jobs:
checks/mypy_.py
coverage:
name: Pytest and Coverage check
name: Pytest and coverage check
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest
timeout-minutes: 3
Expand Down
2 changes: 1 addition & 1 deletion checks/all_.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
import checks_superstaq

if __name__ == "__main__":
skip_args = ["--skip", "requirements", "--"]
skip_args = ["--ruff", "--skip", "requirements", "--"]
exit(checks_superstaq.all_.run(*skip_args, *sys.argv[1:], sphinx_paths=["../qldpc"]))
2 changes: 1 addition & 1 deletion checks/format_.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
import checks_superstaq

if __name__ == "__main__":
exit(checks_superstaq.format_.run(*sys.argv[1:]))
exit(checks_superstaq.ruff_format_.run(*sys.argv[1:]))
2 changes: 1 addition & 1 deletion checks/flake8_.py → checks/lint_.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
import checks_superstaq

if __name__ == "__main__":
exit(checks_superstaq.flake8_.run(*sys.argv[1:]))
exit(checks_superstaq.ruff_lint_.run(*sys.argv[1:]))
7 changes: 0 additions & 7 deletions checks/pylint_.py

This file was deleted.

20 changes: 10 additions & 10 deletions experiments/bivariate_bicycle/collect_results.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#!/usr/bin/env python3
"""Script to save bivariate bicycle code search results to data files
Copyright 2023 The qLDPC Authors and Infleqtion Inc.
Copyright 2023 The qLDPC Authors and Infleqtion Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

from __future__ import annotations
Expand Down
21 changes: 10 additions & 11 deletions experiments/bivariate_bicycle/run_search.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#!/usr/bin/env python3
"""Script to perform a brute-force search for bivariate bicycle codes
Copyright 2023 The qLDPC Authors and Infleqtion Inc.
Copyright 2023 The qLDPC Authors and Infleqtion Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

from __future__ import annotations
Expand Down Expand Up @@ -120,7 +120,6 @@ def redundant_or_trivial(dims: tuple[int, int], exponents: tuple[int, int, int,

# run multiple jobs in parallel
with concurrent.futures.ProcessPoolExecutor(max_workers=max_concurrent_jobs) as executor:

for dim_y in range(MIN_ORDER, dim_x + 1):
dims = (dim_x, dim_y)
for exponents in itertools.product(
Expand Down
20 changes: 10 additions & 10 deletions experiments/quantum_tanner/collect_results.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#!/usr/bin/env python3
"""Script to collect search results into a local database
Copyright 2023 The qLDPC Authors and Infleqtion Inc.
Copyright 2023 The qLDPC Authors and Infleqtion Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

from __future__ import annotations
Expand Down
22 changes: 10 additions & 12 deletions experiments/quantum_tanner/run_randomized_search.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#!/usr/bin/env python3
"""Script to perform a randomized search for quantum Tanner codes
Copyright 2023 The qLDPC Authors and Infleqtion Inc.
Copyright 2023 The qLDPC Authors and Infleqtion Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

from __future__ import annotations
Expand Down Expand Up @@ -139,12 +139,10 @@ def run_and_save(

# run multiple jobs in parallel
with concurrent.futures.ProcessPoolExecutor(max_workers=max_concurrent_jobs) as executor:

# iterate over all combinations of group, base code, and sample index
for group_order, group_index in get_small_groups():
for base_code, base_code_id in get_base_codes():
for sample in range(NUM_SAMPLES):

# submit this job to the job queue
executor.submit(
run_and_save,
Expand Down
20 changes: 10 additions & 10 deletions experiments/quantum_tanner/verify_codes.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#!/usr/bin/env python3
"""Script to verify the reproducibility of saved quantum Tanner codes
Copyright 2023 The qLDPC Authors and Infleqtion Inc.
Copyright 2023 The qLDPC Authors and Infleqtion Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

from __future__ import annotations
Expand Down
7 changes: 5 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ platformdirs = ">=4.0.0"
pymatching = ">=2.1.0"
sympy = ">=1.12"

checks-superstaq = { version = ">=0.5.22", optional = true }
checks-superstaq = { version = ">=0.5.23", optional = true }

[tool.poetry.extras]
dev = ["checks-superstaq"]
Expand All @@ -53,6 +53,9 @@ filterwarnings = [
"ignore::PendingDeprecationWarning:ruamel.yaml.main",
]

[tool.ruff]
line-length = 100

[tool.black]
color = true
line_length = 100
Expand Down Expand Up @@ -146,7 +149,7 @@ enable = [
"no-value-for-parameter",
"nonexistent-operator",
"not-in-loop",
# "parameter_documentation", # REPO-SPECIFIC CONFIG
"parameter_documentation",
"pointless-statement",
"redefined-builtin",
"relative-beyond-top-level",
Expand Down
20 changes: 10 additions & 10 deletions qldpc/abstract_test.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
"""Unit tests for abstract.py
Copyright 2023 The qLDPC Authors and Infleqtion Inc.
Copyright 2023 The qLDPC Authors and Infleqtion Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

from __future__ import annotations
Expand Down
22 changes: 10 additions & 12 deletions qldpc/cache.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
"""Helper function(s) for caching results
Copyright 2023 The qLDPC Authors and Infleqtion Inc.
Copyright 2023 The qLDPC Authors and Infleqtion Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

from __future__ import annotations
Expand All @@ -39,10 +39,8 @@ def use_disk_cache(
"""Decorator to cache results to disk."""

def decorator(function: Callable[..., Any]) -> Callable[..., Any]:

@functools.wraps(function)
def function_with_cache(*args: Hashable, **kwargs: Hashable) -> Any:

# retrieve results from cache, if available
cache = get_disk_cache(cache_name, cache_dir=cache_dir)
key = args + tuple(kwargs.items())
Expand Down
20 changes: 10 additions & 10 deletions qldpc/cache_test.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
"""Unit tests for cache.py
Copyright 2023 The qLDPC Authors and Infleqtion Inc.
Copyright 2023 The qLDPC Authors and Infleqtion Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

from __future__ import annotations
Expand Down
Loading

0 comments on commit 1d1b80a

Please sign in to comment.