From ecd2dcacb2e96ef9e7eefbecd8b222dd5ec64ebb Mon Sep 17 00:00:00 2001 From: yuejiaointel Date: Mon, 14 Apr 2025 15:10:58 -0700 Subject: [PATCH 1/9] fix: add margin check --- examples/python/example_vamana.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/examples/python/example_vamana.py b/examples/python/example_vamana.py index b988a07c..a88745a1 100644 --- a/examples/python/example_vamana.py +++ b/examples/python/example_vamana.py @@ -21,11 +21,12 @@ # [imports] DEBUG_MODE = False -def assert_equal(lhs, rhs, message: str = ""): +def assert_equal(lhs, rhs, message: str = "", epsilon = 0.05): if DEBUG_MODE: print(f"{message}: {lhs} == {rhs}") else: - assert lhs == rhs, message + assert lhs < rhs + epsilon, f"{message}" + assert lhs > rhs - epsilon, f"{message}" def run_test_float(index, queries, groundtruth): expected = { @@ -79,6 +80,7 @@ def run_test_build_two_level4_8(index, queries, groundtruth): test_data_dir = None def run(): + epsilon = 0.05 # ### # Generating test data @@ -159,7 +161,9 @@ def run(): # Compare with the groundtruth. recall = svs.k_recall_at(groundtruth, I, 10, 10) print(f"Recall = {recall}") - assert(recall == 0.8288) + expected_recall = 0.8288 + assert recall < expected_recall + epsilon + assert recall > expected_recall - epsilon # [perform-queries] # [search-window-size] @@ -213,7 +217,9 @@ def run(): # Compare with the groundtruth. recall = svs.k_recall_at(groundtruth, I, 10, 10) print(f"Recall = {recall}") - assert(recall == 0.8288) + expected_recall = 0.8288 + assert recall < expected_recall + epsilon + assert recall > expected_recall - epsilon # [loading] ##### Begin Test From 90ee121ce6fd09415bfdbb0116b2da370d012c2f Mon Sep 17 00:00:00 2001 From: yuejiaointel Date: Mon, 14 Apr 2025 15:18:39 -0700 Subject: [PATCH 2/9] fix: margin check for other python files and cpp tests check in pipeline --- .github/workflows/build-linux.yml | 5 +++++ examples/python/example_vamana_dynamic.py | 15 +++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build-linux.yml b/.github/workflows/build-linux.yml index 17af409c..a03bdd78 100644 --- a/.github/workflows/build-linux.yml +++ b/.github/workflows/build-linux.yml @@ -81,3 +81,8 @@ jobs: working-directory: ${{ runner.temp }}/build/tests run: ctest -C ${{ matrix.build_type }} + - name: Run Cpp Examples + env: + CTEST_OUTPUT_ON_FAILURE: 1 + working-directory: ${{ runner.temp }}/build/examples/cpp + run: ctest -C RelWithDebugInfo diff --git a/examples/python/example_vamana_dynamic.py b/examples/python/example_vamana_dynamic.py index 3d57bd12..1c58c0e7 100644 --- a/examples/python/example_vamana_dynamic.py +++ b/examples/python/example_vamana_dynamic.py @@ -22,11 +22,12 @@ # [imports] DEBUG_MODE = False -def assert_equal(lhs, rhs, message: str = ""): +def assert_equal(lhs, rhs, message: str = "", epsilon = 0.05): if DEBUG_MODE: print(f"{message}: {lhs} == {rhs}") else: - assert lhs == rhs, message + assert lhs < rhs + epsilon, f"{message}" + assert lhs > rhs - epsilon, f"{message}" def run_test_float(index, queries, groundtruth): expected = { @@ -48,6 +49,8 @@ def run_test_float(index, queries, groundtruth): test_data_dir = None def run(): + epsilon = 0.05 + # [generate-dataset] # Create a test dataset. # This will create a directory "example_data_vamana" and populate it with three @@ -118,7 +121,9 @@ def run(): # Compare with the groundtruth. recall = svs.k_recall_at(groundtruth, I, 10, 10) print(f"Recall = {recall}") - assert(recall == 0.8202) + expected_recall = 0.8202 + assert recall < expected_recall + epsilon + assert recall > expected_recall - epsilon # [perform-queries] ##### Begin Test @@ -158,7 +163,9 @@ def run(): # Compare with the groundtruth. recall = svs.k_recall_at(groundtruth, I, 10, 10) print(f"Recall = {recall}") - assert(recall == 0.8202) + expected_recall = 0.8202 + assert recall < expected_recall + epsilon + assert recall > expected_recall - epsilon ##### Begin Test From 86f117297394e942353913d7c4559d567d29307e Mon Sep 17 00:00:00 2001 From: yuejiaointel Date: Mon, 14 Apr 2025 15:32:39 -0700 Subject: [PATCH 3/9] feature: new pipeline for python example tests --- .github/workflows/build-python.yml | 83 ++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 .github/workflows/build-python.yml diff --git a/.github/workflows/build-python.yml b/.github/workflows/build-python.yml new file mode 100644 index 00000000..969a9502 --- /dev/null +++ b/.github/workflows/build-python.yml @@ -0,0 +1,83 @@ +# Copyright (C) 2025 Intel Corporation +# +# This software and the related documents are Intel copyrighted materials, +# and your use of them is governed by the express license under which they +# were provided to you ("License"). Unless the License provides otherwise, +# you may not use, modify, copy, publish, distribute, disclose or transmit +# this software or the related documents without Intel's prior written +# permission. +# +# This software and the related documents are provided as is, with no +# express or implied warranties, other than those that are expressly stated +# in the License. + +name: Python Test +run-name: ${{ github.event.inputs.run_name || github.event.pull_request.title }} + +on: + push: + branches: + - main + pull_request: + +permissions: + contents: read + +# This allows a subsequently queued workflow run to interrupt previous runs +concurrency: + group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}' + cancel-in-progress: true + +jobs: + python-build: + name: ${{ matrix.cxx }} + runs-on: ubuntu-22.04 + strategy: + matrix: + cxx: + - g++-11 + - clang++-15 + include: + - cxx: g++-11 + cc: gcc-11 + - cxx: clang++-15 + cc: clang-15 + + steps: + - uses: actions/checkout@v4 + + - name: Install MKL + timeout-minutes: 5 + run: | + .github/scripts/setup_apt_repo_linux.sh + sudo apt install intel-oneapi-mkl intel-oneapi-mkl-devel + # Setup environment variables for building against MKL. + # Persist the environment variables for use across multiple subsequent actions. + source /opt/intel/oneapi/setvars.sh + printenv >> $GITHUB_ENV + + # Install inside the temporary working directory. + - name: Build Wheel + env: + CXX: ${{ matrix.cxx }} + CC: ${{ matrix.cc }} + TEMP_WORKSPACE: ${{ runner.temp }}/usr + run: | + cd ${GITHUB_WORKSPACE}/bindings/python + python setup.py bdist_wheel --cmake-executable="cmake" --build-type=RelWithDebugInfo -- -- -j$(nproc) + pip install ./dist/scalable_vs*.whl --target=${TEMP_WORKSPACE} + + # Make sure to add the location of the generated wheel to the python path. + - name: Run tests + env: + PYTHONPATH: ${{ runner.temp }}/usr + CTEST_OUTPUT_ON_FAILURE: 1 + working-directory: ${{ runner.temp }} + run: python -m unittest discover -s ${GITHUB_WORKSPACE}/bindings/python + + - name: Run examples + env: + PYTHONPATH: ${{ runner.temp }}/usr + CTEST_OUTPUT_ON_FAILURE: 1 + working-directory: ${{ runner.temp }} + run: python -m unittest discover -p "example*.py" -s ${GITHUB_WORKSPACE}/examples/python \ No newline at end of file From 9cf65a13c011789961bd263dd85c512dcd8eb320 Mon Sep 17 00:00:00 2001 From: yuejiaointel Date: Mon, 14 Apr 2025 15:40:05 -0700 Subject: [PATCH 4/9] fix: use assert equal --- examples/python/example_vamana.py | 12 ++++-------- examples/python/example_vamana_dynamic.py | 13 ++++--------- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/examples/python/example_vamana.py b/examples/python/example_vamana.py index a88745a1..c6ececac 100644 --- a/examples/python/example_vamana.py +++ b/examples/python/example_vamana.py @@ -25,8 +25,8 @@ def assert_equal(lhs, rhs, message: str = "", epsilon = 0.05): if DEBUG_MODE: print(f"{message}: {lhs} == {rhs}") else: - assert lhs < rhs + epsilon, f"{message}" - assert lhs > rhs - epsilon, f"{message}" + assert lhs < rhs + epsilon, message + assert lhs > rhs - epsilon, message def run_test_float(index, queries, groundtruth): expected = { @@ -161,9 +161,7 @@ def run(): # Compare with the groundtruth. recall = svs.k_recall_at(groundtruth, I, 10, 10) print(f"Recall = {recall}") - expected_recall = 0.8288 - assert recall < expected_recall + epsilon - assert recall > expected_recall - epsilon + assert_equal(recall, 0.8288) # [perform-queries] # [search-window-size] @@ -217,9 +215,7 @@ def run(): # Compare with the groundtruth. recall = svs.k_recall_at(groundtruth, I, 10, 10) print(f"Recall = {recall}") - expected_recall = 0.8288 - assert recall < expected_recall + epsilon - assert recall > expected_recall - epsilon + assert_equal(recall, 0.8288) # [loading] ##### Begin Test diff --git a/examples/python/example_vamana_dynamic.py b/examples/python/example_vamana_dynamic.py index 1c58c0e7..726009aa 100644 --- a/examples/python/example_vamana_dynamic.py +++ b/examples/python/example_vamana_dynamic.py @@ -26,8 +26,8 @@ def assert_equal(lhs, rhs, message: str = "", epsilon = 0.05): if DEBUG_MODE: print(f"{message}: {lhs} == {rhs}") else: - assert lhs < rhs + epsilon, f"{message}" - assert lhs > rhs - epsilon, f"{message}" + assert lhs < rhs + epsilon, message + assert lhs > rhs - epsilon, message def run_test_float(index, queries, groundtruth): expected = { @@ -121,9 +121,7 @@ def run(): # Compare with the groundtruth. recall = svs.k_recall_at(groundtruth, I, 10, 10) print(f"Recall = {recall}") - expected_recall = 0.8202 - assert recall < expected_recall + epsilon - assert recall > expected_recall - epsilon + assert_equal(recall, 0.8202) # [perform-queries] ##### Begin Test @@ -163,10 +161,7 @@ def run(): # Compare with the groundtruth. recall = svs.k_recall_at(groundtruth, I, 10, 10) print(f"Recall = {recall}") - expected_recall = 0.8202 - assert recall < expected_recall + epsilon - assert recall > expected_recall - epsilon - + assert_equal(recall, 0.8202) ##### Begin Test run_test_float(index, queries, groundtruth) From 242c6dc68579ffdb2e8c6805757f410df20eccb2 Mon Sep 17 00:00:00 2001 From: yuejiaointel Date: Mon, 14 Apr 2025 15:43:29 -0700 Subject: [PATCH 5/9] fix: license header --- .github/workflows/build-python.yml | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/.github/workflows/build-python.yml b/.github/workflows/build-python.yml index 969a9502..9a34295d 100644 --- a/.github/workflows/build-python.yml +++ b/.github/workflows/build-python.yml @@ -1,15 +1,16 @@ -# Copyright (C) 2025 Intel Corporation +# Copyright 2025 Intel Corporation # -# This software and the related documents are Intel copyrighted materials, -# and your use of them is governed by the express license under which they -# were provided to you ("License"). Unless the License provides otherwise, -# you may not use, modify, copy, publish, distribute, disclose or transmit -# this software or the related documents without Intel's prior written -# permission. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# This software and the related documents are provided as is, with no -# express or implied warranties, other than those that are expressly stated -# in the License. +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. name: Python Test run-name: ${{ github.event.inputs.run_name || github.event.pull_request.title }} From 2c8181d6004b53047bf44bb963485891f4eee7a2 Mon Sep 17 00:00:00 2001 From: yuejiaointel Date: Mon, 14 Apr 2025 15:45:10 -0700 Subject: [PATCH 6/9] ci-test --- .github/workflows/build-python.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build-python.yml b/.github/workflows/build-python.yml index 9a34295d..f71f93db 100644 --- a/.github/workflows/build-python.yml +++ b/.github/workflows/build-python.yml @@ -32,17 +32,17 @@ concurrency: jobs: python-build: name: ${{ matrix.cxx }} - runs-on: ubuntu-22.04 + runs-on: self-hosted strategy: matrix: cxx: - g++-11 - - clang++-15 + - clang++-13 include: - cxx: g++-11 cc: gcc-11 - - cxx: clang++-15 - cc: clang-15 + - cxx: clang++-13 + cc: clang-13 steps: - uses: actions/checkout@v4 From 4a74e86d37a3da5f827c14a0195b9daff57e9349 Mon Sep 17 00:00:00 2001 From: yuejiaointel Date: Mon, 14 Apr 2025 21:34:04 -0700 Subject: [PATCH 7/9] fix: remove added file add in cibuildwheel instead --- .github/workflows/build-linux.yml | 6 --- .github/workflows/build-python.yml | 84 ------------------------------ .github/workflows/cibuildwheel.yml | 6 +++ 3 files changed, 6 insertions(+), 90 deletions(-) delete mode 100644 .github/workflows/build-python.yml diff --git a/.github/workflows/build-linux.yml b/.github/workflows/build-linux.yml index a03bdd78..ffc2fae1 100644 --- a/.github/workflows/build-linux.yml +++ b/.github/workflows/build-linux.yml @@ -80,9 +80,3 @@ jobs: CTEST_OUTPUT_ON_FAILURE: 1 working-directory: ${{ runner.temp }}/build/tests run: ctest -C ${{ matrix.build_type }} - - - name: Run Cpp Examples - env: - CTEST_OUTPUT_ON_FAILURE: 1 - working-directory: ${{ runner.temp }}/build/examples/cpp - run: ctest -C RelWithDebugInfo diff --git a/.github/workflows/build-python.yml b/.github/workflows/build-python.yml deleted file mode 100644 index f71f93db..00000000 --- a/.github/workflows/build-python.yml +++ /dev/null @@ -1,84 +0,0 @@ -# Copyright 2025 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -name: Python Test -run-name: ${{ github.event.inputs.run_name || github.event.pull_request.title }} - -on: - push: - branches: - - main - pull_request: - -permissions: - contents: read - -# This allows a subsequently queued workflow run to interrupt previous runs -concurrency: - group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}' - cancel-in-progress: true - -jobs: - python-build: - name: ${{ matrix.cxx }} - runs-on: self-hosted - strategy: - matrix: - cxx: - - g++-11 - - clang++-13 - include: - - cxx: g++-11 - cc: gcc-11 - - cxx: clang++-13 - cc: clang-13 - - steps: - - uses: actions/checkout@v4 - - - name: Install MKL - timeout-minutes: 5 - run: | - .github/scripts/setup_apt_repo_linux.sh - sudo apt install intel-oneapi-mkl intel-oneapi-mkl-devel - # Setup environment variables for building against MKL. - # Persist the environment variables for use across multiple subsequent actions. - source /opt/intel/oneapi/setvars.sh - printenv >> $GITHUB_ENV - - # Install inside the temporary working directory. - - name: Build Wheel - env: - CXX: ${{ matrix.cxx }} - CC: ${{ matrix.cc }} - TEMP_WORKSPACE: ${{ runner.temp }}/usr - run: | - cd ${GITHUB_WORKSPACE}/bindings/python - python setup.py bdist_wheel --cmake-executable="cmake" --build-type=RelWithDebugInfo -- -- -j$(nproc) - pip install ./dist/scalable_vs*.whl --target=${TEMP_WORKSPACE} - - # Make sure to add the location of the generated wheel to the python path. - - name: Run tests - env: - PYTHONPATH: ${{ runner.temp }}/usr - CTEST_OUTPUT_ON_FAILURE: 1 - working-directory: ${{ runner.temp }} - run: python -m unittest discover -s ${GITHUB_WORKSPACE}/bindings/python - - - name: Run examples - env: - PYTHONPATH: ${{ runner.temp }}/usr - CTEST_OUTPUT_ON_FAILURE: 1 - working-directory: ${{ runner.temp }} - run: python -m unittest discover -p "example*.py" -s ${GITHUB_WORKSPACE}/examples/python \ No newline at end of file diff --git a/.github/workflows/cibuildwheel.yml b/.github/workflows/cibuildwheel.yml index 378d0c8c..87198b98 100644 --- a/.github/workflows/cibuildwheel.yml +++ b/.github/workflows/cibuildwheel.yml @@ -60,3 +60,9 @@ jobs: working-directory: ${{ runner.temp }} run: python -m unittest discover -s ${GITHUB_WORKSPACE}/bindings/python + - name: Run examples + env: + PYTHONPATH: ${{ runner.temp }}/usr + CTEST_OUTPUT_ON_FAILURE: 1 + working-directory: ${{ runner.temp }} + run: python -m unittest discover -p "example*.py" -s ${GITHUB_WORKSPACE}/examples/python From fb09083a9464a5793f654c350b60fc087d185696 Mon Sep 17 00:00:00 2001 From: yuejiaointel Date: Mon, 14 Apr 2025 21:34:47 -0700 Subject: [PATCH 8/9] fix: format --- .github/workflows/build-linux.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build-linux.yml b/.github/workflows/build-linux.yml index ffc2fae1..17af409c 100644 --- a/.github/workflows/build-linux.yml +++ b/.github/workflows/build-linux.yml @@ -80,3 +80,4 @@ jobs: CTEST_OUTPUT_ON_FAILURE: 1 working-directory: ${{ runner.temp }}/build/tests run: ctest -C ${{ matrix.build_type }} + From 62e903bff6755d774d184ebc5d572f3db75a8cc0 Mon Sep 17 00:00:00 2001 From: yuejiaointel Date: Mon, 14 Apr 2025 21:37:53 -0700 Subject: [PATCH 9/9] fix: remove unsed var --- examples/python/example_vamana.py | 2 -- examples/python/example_vamana_dynamic.py | 2 -- 2 files changed, 4 deletions(-) diff --git a/examples/python/example_vamana.py b/examples/python/example_vamana.py index c6ececac..b8346bf9 100644 --- a/examples/python/example_vamana.py +++ b/examples/python/example_vamana.py @@ -80,8 +80,6 @@ def run_test_build_two_level4_8(index, queries, groundtruth): test_data_dir = None def run(): - epsilon = 0.05 - # ### # Generating test data # ### diff --git a/examples/python/example_vamana_dynamic.py b/examples/python/example_vamana_dynamic.py index 726009aa..45f087b2 100644 --- a/examples/python/example_vamana_dynamic.py +++ b/examples/python/example_vamana_dynamic.py @@ -49,8 +49,6 @@ def run_test_float(index, queries, groundtruth): test_data_dir = None def run(): - epsilon = 0.05 - # [generate-dataset] # Create a test dataset. # This will create a directory "example_data_vamana" and populate it with three