Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
galumph
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
30
Issues
30
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
grp-svergun
galumph
Commits
c04ae832
Verified
Commit
c04ae832
authored
May 24, 2020
by
Chris Kerr
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add initial tests for the Gaunt coefficients code
parent
cd5df099
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
70 additions
and
0 deletions
+70
-0
test/test_gaunt.py
test/test_gaunt.py
+70
-0
No files found.
test/test_gaunt.py
0 → 100644
View file @
c04ae832
# SPDX-FileCopyrightText: 2018 Christopher Kerr
#
# SPDX-License-Identifier: LGPL-3.0-or-later
from
hypothesis
import
given
import
hypothesis.strategies
as
st
import
pytest
import
sympy.physics.wigner
from
galumph
import
gaunt
LMAX_TEST
=
63
def
assert_sympy_equal
(
a
,
b
):
"""Assert that two sympy expressions are equal."""
assert
sympy
.
simplify
(
a
-
b
)
==
0
@
st
.
composite
def
LMKP
(
draw
):
L
=
draw
(
st
.
integers
(
min_value
=
0
,
max_value
=
LMAX_TEST
))
M
=
draw
(
st
.
integers
(
min_value
=
0
,
max_value
=
L
))
K
=
draw
(
st
.
integers
(
min_value
=
M
,
max_value
=
L
))
iP
=
draw
(
st
.
integers
(
min_value
=
0
,
max_value
=
K
))
P
=
L
-
K
+
2
*
iP
return
(
L
,
M
,
K
,
P
)
def
sympy_matrix_element_W
(
L
,
M
,
K
,
P
):
"""Calculate an element of the dlmkp matrix using sympy."""
wigner0
=
sympy
.
physics
.
wigner
.
wigner_3j
(
L
,
P
,
K
,
0
,
0
,
0
)
wignerM
=
sympy
.
physics
.
wigner
.
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
sympy_matrix_element_G
(
L
,
M
,
K
,
P
):
"""Calculate an element of the dlmkp matrix using sympy."""
standard_gaunt
=
sympy
.
physics
.
wigner
.
gaunt
(
L
,
K
,
P
,
M
,
-
M
,
0
)
prefactor
=
sympy
.
sqrt
((
2
*
P
+
1
)
*
4
*
sympy
.
pi
)
return
prefactor
*
standard_gaunt
@
given
(
lmkp
=
LMKP
())
def
test_sympy_gaunt_vs_wigner
(
lmkp
):
L
,
M
,
K
,
P
=
lmkp
assert_sympy_equal
(
sympy_matrix_element_W
(
L
,
M
,
K
,
P
),
sympy_matrix_element_G
(
L
,
M
,
K
,
P
),
)
@
given
(
lmkp
=
LMKP
())
def
test_python_vs_sympy_gaunt2
(
lmkp
):
L
,
M
,
K
,
P
=
lmkp
sympy_result
=
sympy_matrix_element_G
(
L
,
M
,
K
,
P
)
**
2
sympy_float
=
float
(
sympy_result
.
n
(
10
))
python_result
=
gaunt
.
_modified_gaunt_squared
(
L
,
K
,
P
,
M
)
assert
python_result
==
pytest
.
approx
(
sympy_float
)
@
given
(
lmkp
=
LMKP
())
def
test_python_vs_sympy_gaunt
(
lmkp
):
L
,
M
,
K
,
P
=
lmkp
sympy_result
=
sympy_matrix_element_G
(
L
,
M
,
K
,
P
)
sympy_float
=
float
(
sympy_result
.
n
(
10
))
python_result
=
gaunt
.
modified_gaunt
(
L
,
K
,
P
,
M
)
assert
python_result
==
pytest
.
approx
(
sympy_float
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment