From 07030f2be5b5c20ec32162443af45416ddfcbe5c Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Thu, 2 May 2024 09:07:49 -0700 Subject: [PATCH] Build macOS x86_64 Python wheels with macOS 14 (#517) --- .github/workflows/build.yml | 85 ++++++++++++++++++----- jormungandr/test/autodiff/hessian_test.py | 6 +- test/src/autodiff/HessianTest.cpp | 5 +- 3 files changed, 72 insertions(+), 24 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a9b13f72..ce8788e3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,15 +12,23 @@ jobs: strategy: fail-fast: false matrix: - # Windows, Linux, macOS x86_64, macOS arm64 - os: [windows-2022, ubuntu-22.04, macOS-13, macOS-14] - - name: "${{ matrix.os }} - native" + include: + - name: Windows x86_64 + os: windows-2022 + cmake-args: + - name: Linux x86_64 + os: ubuntu-22.04 + cmake-args: + - name: macOS universal + os: macOS-14 + cmake-args: -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" + + name: ${{ matrix.name }} - native runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 - - run: cmake -B build -S . -DBUILD_EXAMPLES=ON + - run: cmake -B build -S . -DBUILD_EXAMPLES=ON ${{ matrix.cmake-args }} - run: cmake --build build --config RelWithDebInfo --parallel $(nproc) - run: ctest -C RelWithDebInfo --output-on-failure working-directory: build @@ -28,7 +36,7 @@ jobs: - uses: actions/upload-artifact@v4 with: - name: ${{ matrix.os }} - native + name: ${{ matrix.name }} - native path: pkg build-python-wheel: @@ -36,14 +44,53 @@ jobs: strategy: fail-fast: false matrix: - # Windows, Linux, macOS x86_64, macOS arm64 - os: [windows-2022, ubuntu-22.04, macOS-13, macOS-14] - version: ['3.9', '3.10', '3.11', '3.12'] - exclude: - - os: macOS-14 - version: '3.9' - - name: "${{ matrix.os }} - Python ${{ matrix.version }} wheel" + include: + - name: Windows x86_64 + os: windows-2022 + version: "3.9" + cmake-env: + - name: Windows x86_64 + os: windows-2022 + version: "3.10" + cmake-env: + - name: Windows x86_64 + os: windows-2022 + version: "3.11" + cmake-env: + - name: Windows x86_64 + os: windows-2022 + version: "3.12" + cmake-env: + - name: Linux x86_64 + os: ubuntu-22.04 + version: "3.9" + cmake-env: + - name: Linux x86_64 + os: ubuntu-22.04 + version: "3.10" + cmake-env: + - name: Linux x86_64 + os: ubuntu-22.04 + version: "3.11" + cmake-env: + - name: Linux x86_64 + os: ubuntu-22.04 + version: "3.12" + cmake-env: + - name: macOS universal + os: macOS-14 + version: "3.10" + cmake-env: CMAKE_OSX_ARCHITECTURES="x86_64;arm64" + - name: macOS universal + os: macOS-14 + version: "3.11" + cmake-env: CMAKE_OSX_ARCHITECTURES="x86_64;arm64" + - name: macOS universal + os: macOS-14 + version: "3.12" + cmake-env: CMAKE_OSX_ARCHITECTURES="x86_64;arm64" + + name: ${{ matrix.name }} - Python ${{ matrix.version }} wheel runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 @@ -56,7 +103,7 @@ jobs: - run: python3 ./tools/update_version.py - run: pip3 install build tox - - run: python3 -m build --wheel + - run: ${{ matrix.cmake-env }} python3 -m build --wheel - run: python3 ../.github/workflows/repair_wheel.py sleipnirgroup_jormungandr-*.whl if: startsWith(matrix.os, 'ubuntu') || startsWith(matrix.os, 'macOS') working-directory: dist @@ -64,13 +111,13 @@ jobs: - uses: actions/upload-artifact@v4 with: - name: ${{ matrix.os }} - Python ${{ matrix.version }} wheel + name: ${{ matrix.name }} - Python ${{ matrix.version }} wheel path: dist build-python-sdist: timeout-minutes: 10 - name: "Python sdist" + name: Python sdist runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -123,7 +170,7 @@ jobs: container: wpilib/roborio-cross-ubuntu:2024-22.04 toolchain: /usr/local/toolchain-config.cmake - name: "${{ matrix.artifact-name }}" + name: ${{ matrix.artifact-name }} runs-on: ubuntu-22.04 container: ${{ matrix.container }} steps: @@ -139,7 +186,7 @@ jobs: path: pkg build-wasm: - name: "Wasm" + name: Wasm runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v4 diff --git a/jormungandr/test/autodiff/hessian_test.py b/jormungandr/test/autodiff/hessian_test.py index cc3fa30c..a8748ca2 100644 --- a/jormungandr/test/autodiff/hessian_test.py +++ b/jormungandr/test/autodiff/hessian_test.py @@ -103,9 +103,9 @@ def test_product_of_sines(): # y = prod(sin(x)) y = prod(x.cwise_transform(autodiff.sin)) - assert y.value() == math.sin(1) * math.sin(2) * math.sin(3) * math.sin( - 4 - ) * math.sin(5) + assert y.value() == pytest.approx( + math.sin(1) * math.sin(2) * math.sin(3) * math.sin(4) * math.sin(5), abs=1e-15 + ) g = Gradient(y, x) for i in range(x.rows()): diff --git a/test/src/autodiff/HessianTest.cpp b/test/src/autodiff/HessianTest.cpp index 55e20335..651f1d2b 100644 --- a/test/src/autodiff/HessianTest.cpp +++ b/test/src/autodiff/HessianTest.cpp @@ -122,8 +122,9 @@ TEST_CASE("Hessian - Product of sines", "[Hessian]") { auto temp = x.CwiseTransform(sleipnir::sin); auto y = std::accumulate(temp.begin(), temp.end(), sleipnir::Variable{1.0}, std::multiplies{}); - CHECK(y.Value() == - std::sin(1) * std::sin(2) * std::sin(3) * std::sin(4) * std::sin(5)); + CHECK(y.Value() == Catch::Approx(std::sin(1) * std::sin(2) * std::sin(3) * + std::sin(4) * std::sin(5)) + .margin(1e-15)); auto g = sleipnir::Gradient(y, x); for (int i = 0; i < x.Rows(); ++i) {