Skip to content

Commit 7a605a9

Browse files
deps(workflows): bump pypa/cibuildwheel from 2.18 to 2.19 (#225)
* deps(workflows): bump pypa/cibuildwheel from 2.18 to 2.19 Bumps [pypa/cibuildwheel](https://github.com/pypa/cibuildwheel) from 2.18 to 2.19. - [Release notes](https://github.com/pypa/cibuildwheel/releases) - [Changelog](https://github.com/pypa/cibuildwheel/blob/main/docs/changelog.md) - [Commits](pypa/cibuildwheel@v2.18...v2.19) --- updated-dependencies: - dependency-name: pypa/cibuildwheel dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * chore(pre-commit): update pre-commit hooks * chore(CMakeLists.txt): set default `pybind11` tag to stable --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Xuehai Pan <XuehaiPan@pku.edu.cn>
1 parent d24792d commit 7a605a9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+538
-291
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ jobs:
136136
run: python .github/workflows/set_cibw_build.py
137137

138138
- name: Build wheels
139-
uses: pypa/cibuildwheel@v2.18
139+
uses: pypa/cibuildwheel@v2.19
140140
env:
141141
CIBW_BUILD: ${{ env.CIBW_BUILD }}
142142
with:
@@ -190,7 +190,7 @@ jobs:
190190
run: python .github/workflows/set_cibw_build.py
191191

192192
- name: Build wheels
193-
uses: pypa/cibuildwheel@v2.18
193+
uses: pypa/cibuildwheel@v2.19
194194
env:
195195
CIBW_BUILD: ${{ env.CIBW_BUILD }}
196196
with:

.github/workflows/tests.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,15 @@ jobs:
8080
USE_FP16: "ON"
8181
TORCH_CUDA_ARCH_LIST: "Common"
8282
run: |
83-
python -m pip install -vvv -e .
83+
python -m pip install -vvv --editable .
8484
8585
- name: Test with pytest
8686
run: |
8787
make pytest
8888
8989
- name: Upload coverage to Codecov
90-
if: runner.os == 'Linux'
9190
uses: codecov/codecov-action@v4
91+
if: ${{ matrix.os == 'ubuntu-latest' }}
9292
with:
9393
token: ${{ secrets.CODECOV_TOKEN }}
9494
file: ./tests/coverage.xml
@@ -127,7 +127,7 @@ jobs:
127127
128128
- name: Install TorchOpt
129129
run: |
130-
python -m pip install -vvv -e .
130+
python -m pip install -vvv --editable .
131131
env:
132132
TORCHOPT_NO_EXTENSIONS: "true"
133133

@@ -136,8 +136,8 @@ jobs:
136136
make pytest
137137
138138
- name: Upload coverage to Codecov
139-
if: runner.os == 'Linux'
140139
uses: codecov/codecov-action@v4
140+
if: ${{ matrix.os == 'ubuntu-latest' }}
141141
with:
142142
token: ${{ secrets.CODECOV_TOKEN }}
143143
file: ./tests/coverage.xml

.pre-commit-config.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ repos:
2626
- id: debug-statements
2727
- id: double-quote-string-fixer
2828
- repo: https://github.com/pre-commit/mirrors-clang-format
29-
rev: v18.1.5
29+
rev: v18.1.6
3030
hooks:
3131
- id: clang-format
3232
- repo: https://github.com/astral-sh/ruff-pre-commit
33-
rev: v0.4.7
33+
rev: v0.4.9
3434
hooks:
3535
- id: ruff
3636
args: [--fix, --exit-non-zero-on-fix]
@@ -43,7 +43,7 @@ repos:
4343
hooks:
4444
- id: black-jupyter
4545
- repo: https://github.com/asottile/pyupgrade
46-
rev: v3.15.2
46+
rev: v3.16.0
4747
hooks:
4848
- id: pyupgrade
4949
args: [--py38-plus] # sync with requires-python
@@ -52,7 +52,7 @@ repos:
5252
^examples/
5353
)
5454
- repo: https://github.com/pycqa/flake8
55-
rev: 7.0.0
55+
rev: 7.1.0
5656
hooks:
5757
- id: flake8
5858
additional_dependencies:

CMakeLists.txt

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,14 @@ cmake_minimum_required(VERSION 3.11) # for FetchContent
1717
project(torchopt LANGUAGES CXX)
1818

1919
include(FetchContent)
20-
set(PYBIND11_VERSION v2.12.0)
20+
21+
set(THIRD_PARTY_DIR "${CMAKE_SOURCE_DIR}/third-party")
22+
if(NOT DEFINED PYBIND11_VERSION AND NOT "$ENV{PYBIND11_VERSION}" STREQUAL "")
23+
set(PYBIND11_VERSION "$ENV{PYBIND11_VERSION}")
24+
endif()
25+
if(NOT PYBIND11_VERSION)
26+
set(PYBIND11_VERSION stable)
27+
endif()
2128

2229
if(NOT CMAKE_BUILD_TYPE)
2330
set(CMAKE_BUILD_TYPE Release)
@@ -172,7 +179,7 @@ endif()
172179

173180
system(
174181
STRIP OUTPUT_VARIABLE PYTHON_VERSION
175-
COMMAND "${PYTHON_EXECUTABLE}" -c "print(__import__('platform').python_version())"
182+
COMMAND "${PYTHON_EXECUTABLE}" -c "print('.'.join(map(str, __import__('sys').version_info[:3])))"
176183
)
177184

178185
message(STATUS "Use Python version: ${PYTHON_VERSION}")
@@ -216,11 +223,12 @@ if("${PYBIND11_CMAKE_DIR}" STREQUAL "")
216223
GIT_REPOSITORY https://github.com/pybind/pybind11.git
217224
GIT_TAG "${PYBIND11_VERSION}"
218225
GIT_SHALLOW TRUE
219-
SOURCE_DIR "${CMAKE_SOURCE_DIR}/third-party/pybind11"
220-
BINARY_DIR "${CMAKE_SOURCE_DIR}/third-party/.cmake/pybind11/build"
221-
STAMP_DIR "${CMAKE_SOURCE_DIR}/third-party/.cmake/pybind11/stamp"
226+
SOURCE_DIR "${THIRD_PARTY_DIR}/pybind11"
227+
BINARY_DIR "${THIRD_PARTY_DIR}/.cmake/pybind11/build"
228+
STAMP_DIR "${THIRD_PARTY_DIR}/.cmake/pybind11/stamp"
222229
)
223230
FetchContent_GetProperties(pybind11)
231+
224232
if(NOT pybind11_POPULATED)
225233
message(STATUS "Populating Git repository pybind11@${PYBIND11_VERSION} to third-party/pybind11...")
226234
FetchContent_MakeAvailable(pybind11)

pyproject.toml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ extend-exclude = ["examples"]
235235
select = [
236236
"E", "W", # pycodestyle
237237
"F", # pyflakes
238+
"C90", # mccabe
238239
"UP", # pyupgrade
239240
"ANN", # flake8-annotations
240241
"S", # flake8-bandit
@@ -243,14 +244,21 @@ select = [
243244
"COM", # flake8-commas
244245
"C4", # flake8-comprehensions
245246
"EXE", # flake8-executable
247+
"FA", # flake8-future-annotations
248+
"LOG", # flake8-logging
246249
"ISC", # flake8-implicit-str-concat
250+
"INP", # flake8-no-pep420
247251
"PIE", # flake8-pie
248252
"PYI", # flake8-pyi
249253
"Q", # flake8-quotes
250254
"RSE", # flake8-raise
251255
"RET", # flake8-return
252256
"SIM", # flake8-simplify
253257
"TID", # flake8-tidy-imports
258+
"TCH", # flake8-type-checking
259+
"PERF", # perflint
260+
"FURB", # refurb
261+
"TRY", # tryceratops
254262
"RUF", # ruff
255263
]
256264
ignore = [
@@ -268,9 +276,9 @@ ignore = [
268276
# S101: use of `assert` detected
269277
# internal use and may never raise at runtime
270278
"S101",
271-
# PLR0402: use from {module} import {name} in lieu of alias
272-
# use alias for import convention (e.g., `import torch.nn as nn`)
273-
"PLR0402",
279+
# TRY003: avoid specifying long messages outside the exception class
280+
# long messages are necessary for clarity
281+
"TRY003",
274282
]
275283
typing-modules = ["torchopt.typing"]
276284

@@ -296,6 +304,9 @@ typing-modules = ["torchopt.typing"]
296304
"F401", # unused-import
297305
"F811", # redefined-while-unused
298306
]
307+
"docs/source/conf.py" = [
308+
"INP001", # flake8-no-pep420
309+
]
299310

300311
[tool.ruff.lint.flake8-annotations]
301312
allow-star-arg-any = true

tests/helpers.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import itertools
2121
import os
2222
import random
23-
from typing import Iterable
23+
from typing import TYPE_CHECKING, Iterable
2424

2525
import numpy as np
2626
import pytest
@@ -30,7 +30,10 @@
3030
from torch.utils import data
3131

3232
from torchopt import pytree
33-
from torchopt.typing import TensorTree
33+
34+
35+
if TYPE_CHECKING:
36+
from torchopt.typing import TensorTree
3437

3538

3639
BATCH_SIZE = 64

tests/test_alias.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
from __future__ import annotations
1717

18-
from typing import Callable
18+
from typing import TYPE_CHECKING, Callable
1919

2020
import functorch
2121
import pytest
@@ -26,7 +26,10 @@
2626
import torchopt
2727
from torchopt import pytree
2828
from torchopt.alias.utils import _set_use_chain_flat
29-
from torchopt.typing import TensorTree
29+
30+
31+
if TYPE_CHECKING:
32+
from torchopt.typing import TensorTree
3033

3134

3235
@helpers.parametrize(

tests/test_implicit.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import copy
1919
import re
2020
from collections import OrderedDict
21-
from types import FunctionType
21+
from typing import TYPE_CHECKING
2222

2323
import functorch
2424
import numpy as np
@@ -47,6 +47,10 @@
4747
HAS_JAX = False
4848

4949

50+
if TYPE_CHECKING:
51+
from types import FunctionType
52+
53+
5054
BATCH_SIZE = 8
5155
NUM_UPDATES = 3
5256

@@ -123,7 +127,7 @@ def get_rr_dataset_torch() -> data.DataLoader:
123127
inner_lr=[2e-2, 2e-3],
124128
inner_update=[20, 50, 100],
125129
)
126-
def test_imaml_solve_normal_cg(
130+
def test_imaml_solve_normal_cg( # noqa: C901
127131
dtype: torch.dtype,
128132
lr: float,
129133
inner_lr: float,
@@ -251,7 +255,7 @@ def outer_level(p, xs, ys):
251255
inner_update=[20, 50, 100],
252256
ns=[False, True],
253257
)
254-
def test_imaml_solve_inv(
258+
def test_imaml_solve_inv( # noqa: C901
255259
dtype: torch.dtype,
256260
lr: float,
257261
inner_lr: float,
@@ -375,7 +379,12 @@ def outer_level(p, xs, ys):
375379
inner_lr=[2e-2, 2e-3],
376380
inner_update=[20, 50, 100],
377381
)
378-
def test_imaml_module(dtype: torch.dtype, lr: float, inner_lr: float, inner_update: int) -> None:
382+
def test_imaml_module( # noqa: C901
383+
dtype: torch.dtype,
384+
lr: float,
385+
inner_lr: float,
386+
inner_update: int,
387+
) -> None:
379388
np_dtype = helpers.dtype_torch2numpy(dtype)
380389

381390
jax_model, jax_params = get_model_jax(dtype=np_dtype)
@@ -763,7 +772,7 @@ def solve(self):
763772
make_optimality_from_objective(MyModule2)
764773

765774

766-
def test_module_abstract_methods() -> None:
775+
def test_module_abstract_methods() -> None: # noqa: C901
767776
class MyModule1(torchopt.nn.ImplicitMetaGradientModule):
768777
def objective(self):
769778
return torch.tensor(0.0)
@@ -809,7 +818,7 @@ def solve(self):
809818

810819
class MyModule5(torchopt.nn.ImplicitMetaGradientModule):
811820
@classmethod
812-
def optimality(self):
821+
def optimality(cls):
813822
return ()
814823

815824
def solve(self):
@@ -846,7 +855,7 @@ def solve(self):
846855

847856
class MyModule8(torchopt.nn.ImplicitMetaGradientModule):
848857
@classmethod
849-
def objective(self):
858+
def objective(cls):
850859
return ()
851860

852861
def solve(self):

tests/test_utils.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
# limitations under the License.
1414
# ==============================================================================
1515

16+
import operator
17+
1618
import torch
1719

1820
import torchopt
@@ -80,7 +82,7 @@ def test_module_clone() -> None:
8082
assert y.is_cuda
8183

8284

83-
def test_extract_state_dict():
85+
def test_extract_state_dict(): # noqa: C901
8486
fc = torch.nn.Linear(1, 1)
8587
state_dict = torchopt.extract_state_dict(fc, by='reference', device=torch.device('meta'))
8688
for param_dict in state_dict.params:
@@ -121,7 +123,7 @@ def test_extract_state_dict():
121123
loss = fc(torch.ones(1, 1)).sum()
122124
optim.step(loss)
123125
state_dict = torchopt.extract_state_dict(optim)
124-
same = pytree.tree_map(lambda x, y: x is y, state_dict, tuple(optim.state_groups))
126+
same = pytree.tree_map(operator.is_, state_dict, tuple(optim.state_groups))
125127
assert all(pytree.tree_flatten(same)[0])
126128

127129

0 commit comments

Comments
 (0)