Repository navigation
Stabilize cell volumes for highly skew lattice bases - #137
srijan2607 wants to merge 4 commits into
Conversation
|
The test-typing follow-up is pushed at @pkienzle could you approve the pending fork workflow when appropriate? The current-head run is waiting for approval with zero jobs executed; hosted CI is not yet verified. |
pkienzle
left a comment
There was a problem hiding this comment.
Code looks okay and tests pass. I checked some of the conditions against high precision math.
I'm approving as is, but I'll wait a bit before merging in case you want to tighten the relative error in the tests.
| assert volume == pytest.approx(expected*1e-24, rel=1e-12, abs=0) | ||
| density = crystal.molecular_mass/volume | ||
| assert density == pytest.approx(crystal.molecular_mass/1e-24, rel=1e-12) | ||
|
|
There was a problem hiding this comment.
These three asserts pass on mac M2 with rel=5e-16 (≈2 ULP)
| ]) | ||
| def test_cartesian_volume(vectors): | ||
| expected = abs(_dot(vectors[0], _cross(vectors[1], vectors[2]))) | ||
| assert cell_volume(*_parameters(vectors)) == pytest.approx(expected, rel=1e-10) |
There was a problem hiding this comment.
The first two tests also pass with rel=5e-16, but the third requires rel=1e-12
| expected = float(Decimal(12)*Decimal(2).sqrt()) | ||
| assert cell_volume(2, 3, 4, *angles) == pytest.approx(expected, rel=2e-15) | ||
| assert formula("Si").volume(2, 3, 4, *angles) == pytest.approx( | ||
| expected*1e-24, rel=2e-15) |
There was a problem hiding this comment.
These tests pass with rel=5e-16
Evaluate crystal-cell volume using the equivalent four-sine factorization of the Gram determinant. Compensated degree-space sums reduce cancellation for extreme or near-degenerate cell descriptions; this is not a typical reduced-cell density-corruption claim.
Exact orthogonal results are preserved:
cell_volume(2) == 8.0andcell_volume(2, 3, 4) == 24.0. Flat cells with angles(30, 60, 90),(90, 90, 180)and(120, 120, 120)return exactly0.0. Real-angle conversion occurs before negation so NumPy unsigned scalars do not wrap.Verification
The configured default command,
python -m pytest, passes 279 tests, including the project's doctests, coverage and mypy checks. Mypy reports no issues in 33 source files; overall coverage is 87%, withperiodictable/util.pyat 100%. This was rerun on Python 3.13.13, NumPy 2.5.4 and mypy 2.4.0.The previous head produced 2 failed, 277 passed, with three typing errors in
REAL_ANGLE_CASES. The follow-up changes only test-constructor annotations; production code, test configuration and checks are unchanged. Hosted CI has passed: all four test jobs and the wheel build completed successfully; the PyPI upload job was skipped.No new angle-range validation or general length-product overflow guarantee is added. Known behavior outside the principal angle domain remains outside this repair.
Research basis: NIST DLMF §4.21 supplies the addition/product identities; the IUCr coreCIF cell-volume definition supplies the Gram determinant. Floating-point accuracy is tested separately from the algebraic identity.