Skip to content

Commit

Permalink
deps(workflows): bump pypa/cibuildwheel from 2.18 to 2.19 (#225)
Browse files Browse the repository at this point in the history
* 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] <[email protected]>

* chore(pre-commit): update pre-commit hooks

* chore(CMakeLists.txt): set default `pybind11` tag to stable

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Xuehai Pan <[email protected]>
  • Loading branch information
dependabot[bot] and XuehaiPan authored Jun 17, 2024
1 parent d24792d commit 7a605a9
Show file tree
Hide file tree
Showing 78 changed files with 538 additions and 291 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ jobs:
run: python .github/workflows/set_cibw_build.py

- name: Build wheels
uses: pypa/cibuildwheel@v2.18
uses: pypa/cibuildwheel@v2.19
env:
CIBW_BUILD: ${{ env.CIBW_BUILD }}
with:
Expand Down Expand Up @@ -190,7 +190,7 @@ jobs:
run: python .github/workflows/set_cibw_build.py

- name: Build wheels
uses: pypa/cibuildwheel@v2.18
uses: pypa/cibuildwheel@v2.19
env:
CIBW_BUILD: ${{ env.CIBW_BUILD }}
with:
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ jobs:
USE_FP16: "ON"
TORCH_CUDA_ARCH_LIST: "Common"
run: |
python -m pip install -vvv -e .
python -m pip install -vvv --editable .
- name: Test with pytest
run: |
make pytest
- name: Upload coverage to Codecov
if: runner.os == 'Linux'
uses: codecov/codecov-action@v4
if: ${{ matrix.os == 'ubuntu-latest' }}
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./tests/coverage.xml
Expand Down Expand Up @@ -127,7 +127,7 @@ jobs:
- name: Install TorchOpt
run: |
python -m pip install -vvv -e .
python -m pip install -vvv --editable .
env:
TORCHOPT_NO_EXTENSIONS: "true"

Expand All @@ -136,8 +136,8 @@ jobs:
make pytest
- name: Upload coverage to Codecov
if: runner.os == 'Linux'
uses: codecov/codecov-action@v4
if: ${{ matrix.os == 'ubuntu-latest' }}
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./tests/coverage.xml
Expand Down
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ repos:
- id: debug-statements
- id: double-quote-string-fixer
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v18.1.5
rev: v18.1.6
hooks:
- id: clang-format
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.7
rev: v0.4.9
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand All @@ -43,7 +43,7 @@ repos:
hooks:
- id: black-jupyter
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.2
rev: v3.16.0
hooks:
- id: pyupgrade
args: [--py38-plus] # sync with requires-python
Expand All @@ -52,7 +52,7 @@ repos:
^examples/
)
- repo: https://github.com/pycqa/flake8
rev: 7.0.0
rev: 7.1.0
hooks:
- id: flake8
additional_dependencies:
Expand Down
18 changes: 13 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ cmake_minimum_required(VERSION 3.11) # for FetchContent
project(torchopt LANGUAGES CXX)

include(FetchContent)
set(PYBIND11_VERSION v2.12.0)

set(THIRD_PARTY_DIR "${CMAKE_SOURCE_DIR}/third-party")
if(NOT DEFINED PYBIND11_VERSION AND NOT "$ENV{PYBIND11_VERSION}" STREQUAL "")
set(PYBIND11_VERSION "$ENV{PYBIND11_VERSION}")
endif()
if(NOT PYBIND11_VERSION)
set(PYBIND11_VERSION stable)
endif()

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
Expand Down Expand Up @@ -172,7 +179,7 @@ endif()

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

message(STATUS "Use Python version: ${PYTHON_VERSION}")
Expand Down Expand Up @@ -216,11 +223,12 @@ if("${PYBIND11_CMAKE_DIR}" STREQUAL "")
GIT_REPOSITORY https://github.com/pybind/pybind11.git
GIT_TAG "${PYBIND11_VERSION}"
GIT_SHALLOW TRUE
SOURCE_DIR "${CMAKE_SOURCE_DIR}/third-party/pybind11"
BINARY_DIR "${CMAKE_SOURCE_DIR}/third-party/.cmake/pybind11/build"
STAMP_DIR "${CMAKE_SOURCE_DIR}/third-party/.cmake/pybind11/stamp"
SOURCE_DIR "${THIRD_PARTY_DIR}/pybind11"
BINARY_DIR "${THIRD_PARTY_DIR}/.cmake/pybind11/build"
STAMP_DIR "${THIRD_PARTY_DIR}/.cmake/pybind11/stamp"
)
FetchContent_GetProperties(pybind11)

if(NOT pybind11_POPULATED)
message(STATUS "Populating Git repository pybind11@${PYBIND11_VERSION} to third-party/pybind11...")
FetchContent_MakeAvailable(pybind11)
Expand Down
17 changes: 14 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ extend-exclude = ["examples"]
select = [
"E", "W", # pycodestyle
"F", # pyflakes
"C90", # mccabe
"UP", # pyupgrade
"ANN", # flake8-annotations
"S", # flake8-bandit
Expand All @@ -243,14 +244,21 @@ select = [
"COM", # flake8-commas
"C4", # flake8-comprehensions
"EXE", # flake8-executable
"FA", # flake8-future-annotations
"LOG", # flake8-logging
"ISC", # flake8-implicit-str-concat
"INP", # flake8-no-pep420
"PIE", # flake8-pie
"PYI", # flake8-pyi
"Q", # flake8-quotes
"RSE", # flake8-raise
"RET", # flake8-return
"SIM", # flake8-simplify
"TID", # flake8-tidy-imports
"TCH", # flake8-type-checking
"PERF", # perflint
"FURB", # refurb
"TRY", # tryceratops
"RUF", # ruff
]
ignore = [
Expand All @@ -268,9 +276,9 @@ ignore = [
# S101: use of `assert` detected
# internal use and may never raise at runtime
"S101",
# PLR0402: use from {module} import {name} in lieu of alias
# use alias for import convention (e.g., `import torch.nn as nn`)
"PLR0402",
# TRY003: avoid specifying long messages outside the exception class
# long messages are necessary for clarity
"TRY003",
]
typing-modules = ["torchopt.typing"]

Expand All @@ -296,6 +304,9 @@ typing-modules = ["torchopt.typing"]
"F401", # unused-import
"F811", # redefined-while-unused
]
"docs/source/conf.py" = [
"INP001", # flake8-no-pep420
]

[tool.ruff.lint.flake8-annotations]
allow-star-arg-any = true
Expand Down
7 changes: 5 additions & 2 deletions tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import itertools
import os
import random
from typing import Iterable
from typing import TYPE_CHECKING, Iterable

import numpy as np
import pytest
Expand All @@ -30,7 +30,10 @@
from torch.utils import data

from torchopt import pytree
from torchopt.typing import TensorTree


if TYPE_CHECKING:
from torchopt.typing import TensorTree


BATCH_SIZE = 64
Expand Down
7 changes: 5 additions & 2 deletions tests/test_alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

from __future__ import annotations

from typing import Callable
from typing import TYPE_CHECKING, Callable

import functorch
import pytest
Expand All @@ -26,7 +26,10 @@
import torchopt
from torchopt import pytree
from torchopt.alias.utils import _set_use_chain_flat
from torchopt.typing import TensorTree


if TYPE_CHECKING:
from torchopt.typing import TensorTree


@helpers.parametrize(
Expand Down
23 changes: 16 additions & 7 deletions tests/test_implicit.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import copy
import re
from collections import OrderedDict
from types import FunctionType
from typing import TYPE_CHECKING

import functorch
import numpy as np
Expand Down Expand Up @@ -47,6 +47,10 @@
HAS_JAX = False


if TYPE_CHECKING:
from types import FunctionType


BATCH_SIZE = 8
NUM_UPDATES = 3

Expand Down Expand Up @@ -123,7 +127,7 @@ def get_rr_dataset_torch() -> data.DataLoader:
inner_lr=[2e-2, 2e-3],
inner_update=[20, 50, 100],
)
def test_imaml_solve_normal_cg(
def test_imaml_solve_normal_cg( # noqa: C901
dtype: torch.dtype,
lr: float,
inner_lr: float,
Expand Down Expand Up @@ -251,7 +255,7 @@ def outer_level(p, xs, ys):
inner_update=[20, 50, 100],
ns=[False, True],
)
def test_imaml_solve_inv(
def test_imaml_solve_inv( # noqa: C901
dtype: torch.dtype,
lr: float,
inner_lr: float,
Expand Down Expand Up @@ -375,7 +379,12 @@ def outer_level(p, xs, ys):
inner_lr=[2e-2, 2e-3],
inner_update=[20, 50, 100],
)
def test_imaml_module(dtype: torch.dtype, lr: float, inner_lr: float, inner_update: int) -> None:
def test_imaml_module( # noqa: C901
dtype: torch.dtype,
lr: float,
inner_lr: float,
inner_update: int,
) -> None:
np_dtype = helpers.dtype_torch2numpy(dtype)

jax_model, jax_params = get_model_jax(dtype=np_dtype)
Expand Down Expand Up @@ -763,7 +772,7 @@ def solve(self):
make_optimality_from_objective(MyModule2)


def test_module_abstract_methods() -> None:
def test_module_abstract_methods() -> None: # noqa: C901
class MyModule1(torchopt.nn.ImplicitMetaGradientModule):
def objective(self):
return torch.tensor(0.0)
Expand Down Expand Up @@ -809,7 +818,7 @@ def solve(self):

class MyModule5(torchopt.nn.ImplicitMetaGradientModule):
@classmethod
def optimality(self):
def optimality(cls):
return ()

def solve(self):
Expand Down Expand Up @@ -846,7 +855,7 @@ def solve(self):

class MyModule8(torchopt.nn.ImplicitMetaGradientModule):
@classmethod
def objective(self):
def objective(cls):
return ()

def solve(self):
Expand Down
6 changes: 4 additions & 2 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# limitations under the License.
# ==============================================================================

import operator

import torch

import torchopt
Expand Down Expand Up @@ -80,7 +82,7 @@ def test_module_clone() -> None:
assert y.is_cuda


def test_extract_state_dict():
def test_extract_state_dict(): # noqa: C901
fc = torch.nn.Linear(1, 1)
state_dict = torchopt.extract_state_dict(fc, by='reference', device=torch.device('meta'))
for param_dict in state_dict.params:
Expand Down Expand Up @@ -121,7 +123,7 @@ def test_extract_state_dict():
loss = fc(torch.ones(1, 1)).sum()
optim.step(loss)
state_dict = torchopt.extract_state_dict(optim)
same = pytree.tree_map(lambda x, y: x is y, state_dict, tuple(optim.state_groups))
same = pytree.tree_map(operator.is_, state_dict, tuple(optim.state_groups))
assert all(pytree.tree_flatten(same)[0])


Expand Down
Loading

0 comments on commit 7a605a9

Please sign in to comment.