From 763a98c915bd1ac1928495a1be117ac9a5a55ce2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Eertmans?= Date: Thu, 21 Dec 2023 16:29:05 +0100 Subject: [PATCH] wip wip wip --- .bumpversion.cfg | 14 +---- .github/workflows/test.yml | 69 +++++++++++++++++++++--- Cargo.toml | 10 ++-- benches/main.rs | 2 +- docs/source/reference/differt-core.rst | 11 ---- python/differt/__init__.py | 4 +- python/differt/geometry/triangle_mesh.py | 26 ++------- python/differt/rt/utils.py | 3 +- python/differt/version.py | 2 +- 9 files changed, 78 insertions(+), 63 deletions(-) delete mode 100644 docs/source/reference/differt-core.rst diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 67680fe8..15abac41 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -7,18 +7,6 @@ serialize = commit = True message = chore(version): bump {current_version} to {new_version} -[bumpversion:file:pyproject.toml] +[bumpversion:file:Cargo.toml] search = version = "{current_version}" replace = version = "{new_version}" - -[bumpversion:file:differt/__init__.py] -search = __version__ = "{current_version}" -replace = __version__ = "{new_version}" - -[bumpversion:file:differt-core/Cargo.toml] -search = version = "{current_version}" -replace = version = "{new_version}" - -[bumpversion:file:differt-core/src/lib.rs] -search = const VERSION: &str = "{current_version}" -replace = const VERSION: &str = "{new_version}" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 94b8b2ac..c1961f32 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -57,12 +57,12 @@ jobs: - name: Install dependencies run: | - pdm install -G test,github-action + pdm install --no-self - name: Run Cargo test run: | cargo test --no-default-features --features test - benchmark: + python-benchmark: runs-on: ubuntu-latest permissions: pull-requests: write @@ -81,7 +81,7 @@ jobs: - name: Install dependencies run: | - pdm install -G test,github-action # TODO: build in release mode? + pdm install -G test,github-action - name: Run Benchmarks on changes run: pdm run pytest --benchmark-only --benchmark-save=changes @@ -97,7 +97,62 @@ jobs: - name: Compare benchmarks run: | echo 'results<> $GITHUB_OUTPUT - pdm run pytest --benchmark-only --benchmark-compare=changes >> $GITHUB_OUTPUT + pdm run pytest-benchmark compare before changes >> $GITHUB_OUTPUT + echo 'EOF' >> $GITHUB_OUTPUT + id: compare + + - name: Comment PR with benchmarks + uses: thollander/actions-comment-pull-request@v2 + continue-on-error: true + with: + message: | + Python benchmark results: + ${{ steps.compare.outputs.results }} + comment_tag: python-benchmarks + + id: comment + + - name: If PR comment failed, write to PR summary + if: steps.comment.outcome != 'success' + run: | + echo '### Python benchmark results' >> $GITHUB_STEP_SUMMARY + echo '${{ steps.compare.outputs.results }}' >> $GITHUB_STEP_SUMMARY + rust-benchmark: + runs-on: ubuntu-latest + permissions: + pull-requests: write + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install PDM + uses: pdm-project/setup-pdm@v3 + with: + python-version: '3.11' + cache: true + + - name: Install Rust + uses: dtolnay/rust-toolchain@nightly + + - name: Install dependencies + run: | + pdm install --no-self + + - name: Run Benchmarks on changes + run: cargo bench > changes + + - uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.base.sha }} + clean: false + + - name: Run Benchmarks before changes + run: cargo bench > before + + - name: Compare benchmarks + run: | + echo 'results<> $GITHUB_OUTPUT + cargo benchcmp before changes >> $GITHUB_OUTPUT echo 'EOF' >> $GITHUB_OUTPUT id: compare @@ -106,14 +161,14 @@ jobs: continue-on-error: true with: message: | - Benchmark results: + Rust benchmark results: ${{ steps.compare.outputs.results }} - comment_tag: benchmarks + comment_tag: rust-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 '### Rust benchmark results' >> $GITHUB_STEP_SUMMARY echo '${{ steps.compare.outputs.results }}' >> $GITHUB_STEP_SUMMARY diff --git a/Cargo.toml b/Cargo.toml index 88599d17..42f9fcd1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,11 +20,11 @@ edition = "2021" name = "_core" version = "0.0.5" -[profile.release] -lto = "fat" -codegen-units = 1 -strip = true - [profile.bench] debug = true strip = false + +[profile.release] +codegen-units = 1 +lto = "fat" +strip = true diff --git a/benches/main.rs b/benches/main.rs index 3713caca..fcb7e039 100644 --- a/benches/main.rs +++ b/benches/main.rs @@ -6,7 +6,7 @@ use test::{black_box, Bencher}; use numpy::PyArray2; use pyo3::{types::IntoPyDict, Python}; -use differt_core::rt::utils as rt_utils; +use differt::rt::utils as rt_utils; fn large_visibility_matrix<'py>(py: Python<'py>) -> &'py PyArray2 { let np = py.import("numpy").unwrap(); diff --git a/docs/source/reference/differt-core.rst b/docs/source/reference/differt-core.rst deleted file mode 100644 index e9c55b67..00000000 --- a/docs/source/reference/differt-core.rst +++ /dev/null @@ -1,11 +0,0 @@ -differt-core package -==================== - - -Module contents ---------------- - -.. automodule:: differt_core - :members: - :undoc-members: - :show-inheritance: diff --git a/python/differt/__init__.py b/python/differt/__init__.py index 7d4d9556..e69ff78e 100644 --- a/python/differt/__init__.py +++ b/python/differt/__init__.py @@ -1,6 +1,4 @@ from .version import VERSION __version__ = VERSION -__all__ = ( - 'VERSION', -) +__all__ = ("VERSION",) diff --git a/python/differt/geometry/triangle_mesh.py b/python/differt/geometry/triangle_mesh.py index 127803c4..7e51f023 100644 --- a/python/differt/geometry/triangle_mesh.py +++ b/python/differt/geometry/triangle_mesh.py @@ -4,12 +4,11 @@ from pathlib import Path import jax.numpy as jnp -import open3d as o3d import plotly.graph_objects as go from chex import dataclass from jaxtyping import Array, Bool, Float, UInt -from .utils import pairwise_cross +from .. import _core def triangles_contain_vertices_assuming_inside_same_plane( @@ -89,7 +88,7 @@ def paths_intersect_triangles( @dataclass class TriangleMesh: - mesh: o3d.geometry.TriangleMesh + mesh: _core.geometry.triangle_mesh.TriangleMesh @cached_property def triangles(self) -> UInt[Array, "num_triangles 3"]: @@ -107,30 +106,15 @@ def normals(self) -> Float[Array, "num_triangles 3"]: @cached_property def diffraction_edges(self) -> UInt[Array, "num_edges 3"]: - all_vertices = jnp.take(self.vertices, self.indices, axis=0) - normals = self.normals - - print(normals) - - cross = pairwise_cross(normals, normals) - n = jnp.linalg.norm(cross, axis=-1) - print(n) - print(n.shape) - print(cross) - print(cross.shape) - - print(all_vertices) - return len(all_vertices) - return jnp.asarray(self.mesh.get_non_manifold_edges(False)) + raise NotImplementedError @classmethod def load_geojson(cls, file: Path, default_height: float = 1.0) -> TriangleMesh: - pass + raise NotImplementedError @classmethod def load_obj(cls, file: Path) -> TriangleMesh: - mesh = o3d.io.read_triangle_mesh(str(file)).compute_triangle_normals() - return cls(mesh=mesh) + return cls(mesh=_core.geometry.triangle_mesh.TriangleMesh.load_obj(str(file))) def plot(self, *args, **kwargs): x, y, z = self.vertices.T diff --git a/python/differt/rt/utils.py b/python/differt/rt/utils.py index 51aff37a..91a5a0c1 100644 --- a/python/differt/rt/utils.py +++ b/python/differt/rt/utils.py @@ -32,7 +32,8 @@ def generate_all_path_candidates( ``num_primitives * ((num_primitives - 1) ** (order - 1))``. """ return jnp.asarray( - _core.rt.utils.generate_all_path_candidates(num_primitives, order), dtype=jnp.uint32 + _core.rt.utils.generate_all_path_candidates(num_primitives, order), + dtype=jnp.uint32, ) diff --git a/python/differt/version.py b/python/differt/version.py index 50e4e760..b000034e 100644 --- a/python/differt/version.py +++ b/python/differt/version.py @@ -1,5 +1,5 @@ from ._core import __version__ -__all__ = ('VERSION',) +__all__ = ("VERSION",) VERSION = __version__