Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests vs sympy #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 32 additions & 19 deletions .github/workflows/build-wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,29 @@ jobs:
rust-target: x86_64-pc-windows-msvc
platform-name: win_amd64
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: setup rust
uses: actions-rs/toolchain@v1
uses: dtolnay/rust-toolchain@master
with:
profile: minimal
toolchain: stable
default: true
target: ${{ matrix.rust-target }}
- name: Set up Python
uses: actions/setup-python@v2

- name: setup Python
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: "3.11"

- name: build wheel
run: |
pip install wheel
python setup.py bdist_wheel --plat-name ${{ matrix.platform-name }} --rust-target ${{ matrix.rust-target }}
- uses: actions/upload-artifact@v2

- uses: actions/upload-artifact@v3
with:
name: wheels
path: dist/*.whl

- name: upload wheel to GitHub release
if: startsWith(github.ref, 'refs/tags/')
uses: softprops/action-gh-release@v1
Expand All @@ -61,19 +64,25 @@ jobs:
# TODO: add other arch for linux?
name: x86_64 manylinux2010
steps:
- uses: actions/checkout@v2
- name: build manylinux2010 with rust docker image
run: docker build -t manylinux2010-with-rust python/build-wheels
- uses: actions/checkout@v3

- name: build manylinux2014 with rust docker image
run: docker build -t manylinux2014-with-rust python/rustc-manylinux2014_x86_64

- name: build wheel in docker
run: docker run --rm -v $(pwd):/code manylinux2010-with-rust bash -c "cd /code && /opt/python/cp38-cp38/bin/python setup.py bdist_wheel --rust-target x86_64-unknown-linux-gnu"
run: docker run --rm -v $(pwd):/code manylinux2014-with-rust bash -c "cd /code && /opt/python/cp38-cp38/bin/python setup.py bdist_wheel --rust-target x86_64-unknown-linux-gnu"

- name: run auditwheel in docker
run: docker run --rm -v $(pwd):/code manylinux2010-with-rust bash -c "auditwheel repair /code/dist/*.whl -w /code/dist"
run: docker run --rm -v $(pwd):/code manylinux2014-with-rust bash -c "auditwheel repair /code/dist/*.whl -w /code/dist"

- name: remove wheel with wrong tag
run: sudo rm dist/*linux_x86_64.whl
- uses: actions/upload-artifact@v2

- uses: actions/upload-artifact@v3
with:
name: wheels
path: dist/*.whl

- name: upload wheel to GitHub release
if: startsWith(github.ref, 'refs/tags/')
uses: softprops/action-gh-release@v1
Expand All @@ -86,19 +95,23 @@ jobs:
runs-on: ubuntu-20.04
name: sdist
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
- uses: actions/checkout@v3

- name: setup Python
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: "3.11"

- name: build sdist
run: |
pip install wheel
python setup.py sdist
- uses: actions/upload-artifact@v2

- uses: actions/upload-artifact@v3
with:
name: wheels
path: dist/*.tar.gz

- name: upload sdist to GitHub release
if: startsWith(github.ref, 'refs/tags/')
uses: softprops/action-gh-release@v1
Expand Down
33 changes: 20 additions & 13 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,34 @@ jobs:
include:
- os: ubuntu-22.04
rust-version: stable
rust-target: x86_64-unknown-linux-gnu
build-type: debug
- os: ubuntu-22.04
rust-version: stable
rust-target: x86_64-unknown-linux-gnu
build-type: release
cargo-build-flags: --release
- os: ubuntu-22.04
rust-version: 1.61
rust-target: x86_64-unknown-linux-gnu
rust-version: 1.64
build-type: debug

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: setup rust
uses: actions-rs/toolchain@v1
uses: dtolnay/rust-toolchain@master
with:
profile: minimal
toolchain: ${{ matrix.rust-version }}
default: true
target: ${{ matrix.rust-target }}

- name: setup Python
uses: actions/setup-python@v4
with:
python-version: "3.11"

- name: run tests
run: cargo test --target ${{ matrix.rust-target }} ${{ matrix.cargo-build-flags }}
run: cargo test ${{ matrix.cargo-build-flags }}

- name: check the code against sympy
run: |
pip install .
pip install sympy
python test_vs_sympy.py

- name: check that benchmarks compile and run once
if: matrix.build-type == 'release'
run: |
Expand Down
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
[package]
name = "wigners"
version = "0.3.0"
edition = "2018"
edition = "2021"
rust-version = "1.64"

authors = ["Guillaume Fraux <guillaume.fraux@epfl.ch>"]
repository = "https://github.com/luthaf/wigners"
license = "MIT/Apache-2.0"
Expand Down
13 changes: 0 additions & 13 deletions python/build-wheels/Dockerfile

This file was deleted.

11 changes: 11 additions & 0 deletions python/rustc-manylinux2014_x86_64/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Use manylinux docker image as a base
FROM quay.io/pypa/manylinux2014_x86_64

RUN yum install git -y
RUN git config --global --add safe.directory /code

# Download rustup-init asn install
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y --profile minimal --default-toolchain 1.64

ENV PATH="/root/.cargo/bin:${PATH}"
ENV RUST_BUILD_TARGET="x86_64-unknown-linux-gnu"
75 changes: 75 additions & 0 deletions test_vs_sympy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import random
import sys

import numpy as np
from sympy.physics.wigner import wigner_3j as sympy_wigner_3j

import wigners

N_ERRORS = 0


def error(j1, j2, j3, m1, m2, m3, expected, actual):
global N_ERRORS
N_ERRORS += 1
print(
f"error for j1={j1} j2={j2} j3={j3} m1={m1} m2={m2} m3={m3}:",
f"expected {expected}, got {actual}",
)


def get_m(j1, j2, j3):
m1 = random.randint(-j1, j1)
m2 = random.randint(-j2, j2)
m3 = min(max(-(m1 + m2), -j3), j3)

return m1, m2, m3


if __name__ == "__main__":
max_angular = 30
print(f"running all J combinations below J={max_angular}")
for j1 in range(max_angular):
for j2 in range(max_angular):
for j3 in range(max_angular):
m1, m2, m3 = get_m(j1, j2, j3)

expected = float(sympy_wigner_3j(j1, j2, j3, m1, m2, m3))
actual = wigners.wigner_3j(j1, j2, j3, m1, m2, m3)
if not np.isclose(expected, actual, rtol=1e-6, atol=1e-16):
error(j1, j2, j2, m1, m2, m3, expected, actual)

n_combinations = 500
print(
f"running {n_combinations} random J combinations for {max_angular} <= J <= 100"
)
for _ in range(n_combinations):
j1 = random.randint(max_angular, 100)
j2 = random.randint(max_angular, 100)
j3 = random.randint(max_angular, 100)
m1, m2, m3 = get_m(j1, j2, j3)

expected = float(sympy_wigner_3j(j1, j2, j3, m1, m2, m3))
actual = wigners.wigner_3j(j1, j2, j3, m1, m2, m3)
if not np.isclose(expected, actual, rtol=1e-6, atol=1e-16):
error(j1, j2, j2, m1, m2, m3, expected, actual)

print(
f"running {n_combinations} random J combinations for {max_angular} <= J <= 500"
)
for _ in range(n_combinations):
j1 = random.randint(max_angular, 500)
j2 = random.randint(max_angular, 500)
j3 = random.randint(max_angular, 500)
m1, m2, m3 = get_m(j1, j2, j3)

expected = float(sympy_wigner_3j(j1, j2, j3, m1, m2, m3))
actual = wigners.wigner_3j(j1, j2, j3, m1, m2, m3)
if not np.isclose(expected, actual, rtol=1e-6, atol=1e-16):
error(j1, j2, j2, m1, m2, m3, expected, actual)

if N_ERRORS != 0:
print(f"got {N_ERRORS} errors!")
sys.exit(1)
else:
print("all good!")
Loading