Skip to content

Commit

Permalink
chore(lib): use uv, fix base class issues and lint
Browse files Browse the repository at this point in the history
Closes #92
  • Loading branch information
jeertmans committed Nov 29, 2024
1 parent 5fc52f0 commit 50917f4
Show file tree
Hide file tree
Showing 38 changed files with 4,188 additions and 1,175 deletions.
15 changes: 5 additions & 10 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,13 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Rye
env:
RYE_INSTALL_OPTION: --yes
run: |
curl -sSf https://rye.astral.sh/get | bash
echo "$HOME/.rye/shims" >> $GITHUB_PATH
- name: Configure Rye
run: rye config --set-bool behavior.use-uv=true
- name: Setup uv
uses: astral-sh/setup-uv@v3
with:
enable-cache: true

- name: Build package
run: rye build
run: uv build

- name: Publish to PyPI
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
Expand Down
87 changes: 12 additions & 75 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,19 @@ jobs:
fail-fast: false
matrix:
os: [macos-latest, ubuntu-latest]
pyversion: ['3.9', '3.10', '3.11', '3.12']
pyversion: ['3.10', '3.11', '3.12']
runs-on: ${{ matrix.os }}
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Rye
env:
RYE_TOOLCHAIN_VERSION: ${{ matrix.pyversion}}
RYE_INSTALL_OPTION: --yes
run: |
curl -sSf https://rye.astral.sh/get | bash
echo "$HOME/.rye/shims" >> $GITHUB_PATH
- name: Configure Rye
run: |
rye config --set-bool behavior.use-uv=true
rye pin ${{ matrix.pyversion }}
- name: Install Differt2D
run: rye sync
- name: Setup uv
uses: astral-sh/setup-uv@v3
with:
enable-cache: true

- name: Run Pytest
run: rye run pytest
run: uv run --python ${{ matrix.pyversion }} --frozen --no-dev --extra tests pytest

- name: Upload to codecov.io
uses: codecov/codecov-action@v4
Expand All @@ -43,71 +32,19 @@ jobs:

benchmark:
runs-on: ubuntu-latest
permissions:
pull-requests: write
env:
JAX_PLATFORM_NAME: cpu
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Rye
env:
RYE_TOOLCHAIN_VERSION: '3.11'
RYE_INSTALL_OPTION: --yes
run: |
curl -sSf https://rye.astral.sh/get | bash
echo "$HOME/.rye/shims" >> $GITHUB_PATH
- name: Configure Rye
run: |
rye config --set-bool behavior.use-uv=true
rye pin '3.11'
- name: Install Differt2D (on changes)
run: rye sync --reset -f

- name: Run Benchmarks on changes
run: rye run pytest --benchmark-only --benchmark-save=changes tests/benchmarks

- uses: actions/checkout@v4
- name: Setup uv
uses: astral-sh/setup-uv@v3
with:
ref: ${{ github.event.pull_request.base.sha }}
clean: false

- name: Install Differt2D (before changes)
run: rye sync --reset -f

- name: Run Benchmarks before changes
run: rye run pytest --benchmark-only --benchmark-save=before tests/benchmarks
enable-cache: true

- name: Compare benchmarks
run: |
echo 'results<<EOF' >> $GITHUB_OUTPUT
rye run pytest-benchmark compare --group-by=name --columns="mean,stddev,ops" >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
id: compare

- name: Comment PR with benchmarks
uses: thollander/actions-comment-pull-request@v2
continue-on-error: true
- name: Run CodSpeed benchmarks
uses: CodSpeedHQ/action@v3
with:
message: |
Benchmark results:
```
${{ steps.compare.outputs.results }}
```
comment_tag: benchmarks

id: comment

- name: If PR comment failed, write to PR summary
if: steps.comment.outcome != 'success'
run: |
echo '### Benchmark results' >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo '${{ steps.compare.outputs.results }}' >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
run: uv run --python ${{ matrix.pyversion }} --frozen --no-dev --extra tests pytest tests/benchmarks --codspeed

markdown-link-check:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ repos:
- id: pretty-format-toml
args: [--autofix, --trailing-commas]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.4
rev: v0.8.0
hooks:
- id: ruff
args: [--fix]
Expand Down
6 changes: 6 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ build:
- optipng
- libxcb-cursor0
- xvfb
jobs:
post_create_environment:
- asdf plugin add uv
- asdf install uv latest
- asdf global uv latest
- uv pip install -r pyproject.toml --extra docs --no-cache --python $READTHEDOCS_VIRTUALENV_PATH
sphinx:
builder: html
configuration: docs/source/conf.py
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

+ Changed `pyperf` to `pytest-benchmark` for benchmarks.
[#83](https://github.com/jeertmans/DiffeRT2d/pull/83)
+ Changed Rye to uv.
[#93](https://github.com/jeertmans/DiffeRT2d/pull/93)
+ Removed support for Python 3.9 (as a consequence of bumping JAX).
[#93](https://github.com/jeertmans/DiffeRT2d/pull/93)
+ Use `typing.Self` instead of string annotation, to include subclasses.
[#93](https://github.com/jeertmans/DiffeRT2d/pull/93)

(unreleased-fixed)=
### Fixed

+ Fixed issues with `jax>0.4.28`.
[#81](https://github.com/jeertmans/DiffeRT2d/pull/81)
+ Fixed layout issue [#92](https://github.com/jeertmans/DiffeRT2d/pull/92).
[#93](https://github.com/jeertmans/DiffeRT2d/pull/93)
+ Fixed `Scene.square_scene_will_wall` not using `ratio` argument.
[#93](https://github.com/jeertmans/DiffeRT2d/pull/93)

(v0.3.4)=
## [v0.3.4](https://github.com/jeertmans/DiffeRT2d/compare/v0.3.3...v0.3.4)
Expand Down
45 changes: 22 additions & 23 deletions differt2d/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def plot(self, ax: Axes, *args: Any, **kwargs: Any) -> MutableSequence[Artist]:
function.
:return: The artist(s).
"""
pass # pragma: no cover
# pragma: no cover

@abstractmethod
def bounding_box(self) -> Float[Array, "2 2"]:
Expand All @@ -52,7 +52,7 @@ def bounding_box(self) -> Float[Array, "2 2"]:
:return: The min. and max. coordinates of this object.
"""
pass # pragma: no cover
# pragma: no cover

@eqx.filter_jit
@jaxtyped(typechecker=typechecker)
Expand Down Expand Up @@ -111,17 +111,17 @@ def get_location(self, location: Loc) -> Float[Array, "2"]:
xavg = 0.5 * (xmin + xmax)
yavg = 0.5 * (ymin + ymax)

x, y = dict(
N=(xavg, ymax),
E=(xmax, yavg),
S=(xavg, ymin),
W=(xmin, yavg),
C=(xavg, yavg),
NE=(xmax, ymax),
NW=(xmin, ymax),
SE=(xmax, ymin),
SW=(xmin, ymin),
)[location]
x, y = {
"N": (xavg, ymax),
"E": (xmax, yavg),
"S": (xavg, ymin),
"W": (xmin, yavg),
"C": (xavg, yavg),
"NE": (xmax, ymax),
"NW": (xmin, ymax),
"SE": (xmax, ymin),
"SW": (xmin, ymin),
}[location]

return jnp.array([x, y])

Expand All @@ -139,7 +139,7 @@ def parameters_count() -> int:
:return: The number of parameters.
"""
pass # pragma: no cover
# pragma: no cover

@abstractmethod
def parametric_to_cartesian(
Expand All @@ -152,7 +152,7 @@ def parametric_to_cartesian(
:param param_coords: Parametric coordinates.
:return: Cartesian coordinates.
"""
pass # pragma: no cover
# pragma: no cover

@eqx.filter_jit
@jaxtyped(typechecker=typechecker)
Expand All @@ -174,20 +174,21 @@ def sample(self, key: PRNGKeyArray) -> Float[Array, "2"]:
Array([0.88359046, 1.1781206 ], dtype=float32)
"""
return self.parametric_to_cartesian(
jax.random.uniform(key=key, shape=(self.parameters_count(),))
jax.random.uniform(key=key, shape=(self.parameters_count(),)),
)

@abstractmethod
def cartesian_to_parametric(
self, carte_coords: Float[Array, "2"]
self,
carte_coords: Float[Array, "2"],
) -> Float[Array, " {self.parameters_counts()}"]: # type: ignore[reportUndefinedVariable]
"""
Converts cartesian coordinates to parametric coordinates.
:param carte_coords: Cartesian coordinates.
:return: Parametric coordinates.
"""
pass # pragma: no cover
# pragma: no cover

@abstractmethod
def contains_parametric(
Expand All @@ -205,7 +206,7 @@ def contains_parametric(
:func:`activation<differt2d.logic.activation>`.
:return: True if object contains these coordinates.
"""
pass # pragma: no cover
# pragma: no cover

@abstractmethod
def intersects_cartesian(
Expand All @@ -231,7 +232,7 @@ def intersects_cartesian(
:func:`activation<differt2d.logic.activation>`.
:return: True if it intersects.
"""
pass # pragma: no cover
# pragma: no cover

@abstractmethod
def evaluate_cartesian(self, ray_path: Float[Array, "3 2"]) -> Float[Array, " "]:
Expand All @@ -252,7 +253,7 @@ def evaluate_cartesian(self, ray_path: Float[Array, "3 2"]) -> Float[Array, " "]
:param ray_path: Ray path coordinates.
:return: Interaction score.
"""
pass # pragma: no cover
# pragma: no cover


class Object(Plottable, Interactable):
Expand All @@ -263,5 +264,3 @@ class Object(Plottable, Interactable):
using :python:`typing.Union[Plottable, Interactable]` is understood
as implementing one of either classes, not both.
"""

pass
Loading

0 comments on commit 50917f4

Please sign in to comment.