diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c10a5b3..a742812 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,12 +33,8 @@ permissions: contents: read jobs: - buid-and-test: - runs-on: ubuntu-24.04 - - strategy: - fail-fast: false - + code-health: + runs-on: ubuntu-24.04 steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 @@ -66,6 +62,26 @@ jobs: - name: Check modified protos run: ci/build_changed_protos.sh origin/main + + build-and-test-correctness: + strategy: + fail-fast: false + matrix: + os: ["ubuntu-24.04", "ubuntu-24.04-arm", "macos-13", "macos-14"] + + runs-on: ${{ matrix.os }} + + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 + + - name: Set up Python 3.12 + uses: actions/setup-python@3542bca2639a428e1796aaa6a2ffef0c0f575566 # v3 + with: + python-version: '3.12' + + - name: Install Dependencies + run: | + pip install -r dev_tools/dev.env.txt # # Install @@ -75,14 +91,40 @@ jobs: run: | pip install . --user - - name: pytest run: ci/pytest_unit.sh - - name: test performance - run: ci/pytest_perf.sh - - name: test compatibility with Cirq run: | pip install cirq-core pytest test/* -m cirq + + + build-and-test-performance: + strategy: + fail-fast: false + + runs-on: ubuntu-24.04 + + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 + + - name: Set up Python 3.12 + uses: actions/setup-python@3542bca2639a428e1796aaa6a2ffef0c0f575566 # v3 + with: + python-version: '3.12' + + - name: Install Dependencies + run: | + pip install -r dev_tools/dev.env.txt + + # + # Install + # + + - name: install + run: | + pip install . --user + + - name: test performance + run: ci/pytest_perf.sh diff --git a/test_perf/test_value_performance.py b/test_perf/test_value_performance.py index 47c8e21..38a7c49 100644 --- a/test_perf/test_value_performance.py +++ b/test_perf/test_value_performance.py @@ -74,7 +74,7 @@ def test_perf_repr(a: Value) -> str: return repr(a) -@perf_goal(avg_nanos=830) +@perf_goal(avg_nanos=850) def test_perf_parse_atom() -> Value: return Value(1, 'kilogram') diff --git a/tunits/core/cython/frac.pyx b/tunits/core/cython/frac.pyx index 79406f7..08d7d84 100644 --- a/tunits/core/cython/frac.pyx +++ b/tunits/core/cython/frac.pyx @@ -15,7 +15,6 @@ cimport cython from libc.math cimport floor as c_floor, pow as c_pow - # A ratio that should always be canonicalized into least terms with the sign # on the numerator. cdef struct frac: @@ -85,10 +84,10 @@ cpdef frac float_to_twelths_frac(a) except *: return frac_least_terms(a, 1) cdef double d = float(a) - cdef long long x = c_floor(12*d + 0.5) - if abs(12*d - x) > 1e-5: - raise ValueError("Not a twelfth.") - + cdef double raised_d = 12.0*d + cdef long long x = c_floor(raised_d + 0.5) + if not (-1e-5 < raised_d - x < 1e-5): + raise ValueError(f"{a} with 12*a={raised_d} Not a twelfth.") return frac_least_terms(x, 12)