Verified Commit 4676b8e8 authored by Chris Kerr's avatar Chris Kerr

Remove tests for the F2Py wignerSymbols module

parent 98dafc91
"""Test various mathematical formulae used in GALUMPH.
This uses symbolic algebra to verify various simplified formulae.
"""
# SPDX-FileCopyrightText: 2018 Christopher Kerr
#
# SPDX-License-Identifier: LGPL-3.0-or-later
from hypothesis import assume, given, HealthCheck, settings
import hypothesis.strategies as st
import pytest
from galumph import wignerSymbols
sympy = pytest.importorskip('sympy')
from sympy.physics.wigner import wigner_3j # noqa: E402
LMAX_TEST = 63
def iLMKP(L, M, K, P, check=True):
......@@ -37,25 +34,6 @@ def assert_sympy_equal(a, b):
assert sympy.simplify(a - b) == 0
@pytest.fixture(scope='module')
def wigner_matrix_large():
"""Fixture to calculate the Wigner matrix once and reuse it."""
mat = wignerSymbols.shzmat(LMAX_TEST)
LMAX1 = LMAX_TEST + 1
LMAX2 = LMAX_TEST + 2
LMAX3 = LMAX_TEST + 3
assert mat.shape == (LMAX1 * LMAX2**2 * LMAX3 / 12,)
return mat
def sympy_matrix_element(L, M, K, P):
"""Calculate an element of the dlmkp matrix using sympy."""
wigner0 = wigner_3j(L, P, K, 0, 0, 0)
wignerM = wigner_3j(L, P, K, -M, 0, M)
prefactor = (2*P+1) * sympy.sqrt((2*L+1) * (2*K+1))
return prefactor * wigner0 * wignerM
def test_packed_sizes_offsets():
"""Check formulae for sizes of and offsets into packed dlmkp matrices."""
def psize(K):
......@@ -147,28 +125,3 @@ def test_packed_sizes_offsets():
check_sizes()
check_formulae()
@settings(suppress_health_check=[HealthCheck.filter_too_much])
@given(
L=st.integers(min_value=0, max_value=LMAX_TEST),
K=st.integers(min_value=0, max_value=LMAX_TEST),
M=st.integers(min_value=0, max_value=LMAX_TEST),
P=st.integers(min_value=0, max_value=2*LMAX_TEST),
)
def test_wigner_sympy_large(wigner_matrix_large, L, K, M, P):
"""Test elements of the dlmkp matrix using sympy."""
assume(L >= M)
assume(M >= 0)
assume(K >= M)
assume((L+K) >= P)
assume(abs(L-K) <= P)
expected_symbolic = sympy_matrix_element(L, M, K, P)
if (L+K+P) % 2 != 0:
assert expected_symbolic == 0
return
expected = float(expected_symbolic)
if L >= K:
assert wigner_matrix_large[iLMKP(L, M, K, P)] == pytest.approx(expected)
else:
assert wigner_matrix_large[iLMKP(K, M, L, P)] == pytest.approx(expected)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment