Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/validate_refnx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
python3 -m pip install --upgrade pip
python3 -m pip install wheel setuptools
python3 -m pip install numpy scipy cython pytest black
python3 -m pip install refnx
python3 -m pip install git+https://github.com/refnx/refnx.git@main

- name: Validate
run: |
Expand Down
3 changes: 1 addition & 2 deletions validation/scripts/test_genx.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,7 @@ def kernel_test_pol(slabs, data, backend):
magn_ang=theta,
)
)
# layers.reverse() # the layer order in pol tests
# is currently reversed compared to unpol
layers.reverse()
stack = model.Stack(Layers=list(layers[1:-1]), Repetitions=1)
sample = model.Sample(
Stacks=[stack], Ambient=layers[-1], Substrate=layers[0]
Expand Down
2 changes: 1 addition & 1 deletion validation/scripts/test_refl1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def test_pol_refl1d(nsd, backend):
"""
test_name, slabs, data, AGUIDE, H = nsd

Rmm, Rmp, Rpm, Rpp = pol_kernel_test(slabs[::-1], data, AGUIDE, H, backend)
Rmm, Rmp, Rpm, Rpp = pol_kernel_test(slabs, data, AGUIDE, H, backend)


def pol_kernel_test(slabs, data, AGUIDE, H, backend):
Expand Down
80 changes: 78 additions & 2 deletions validation/scripts/test_refnx.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@
import warnings
import pytest
import numpy as np
from test_discovery import get_test_data
from test_discovery import get_test_data, get_polarised_test_data

from refnx.reflect import use_reflect_backend, SLD, ReflectModel, Structure
from refnx.reflect import (
use_reflect_backend,
SLD,
ReflectModel,
Structure,
MagneticSlab,
PolarisedReflectModel,
)


# cython backend may or may not be present on all systems
Expand Down Expand Up @@ -78,6 +85,75 @@ def resolution_test(slabs, data, backend):
np.testing.assert_allclose(R, data[:, 1], rtol=0.03)


pol_tests = list(get_polarised_test_data())
pol_ids = [f"{t[0]}" for t in pol_tests]


@pytest.mark.parametrize("nsd", pol_tests, ids=pol_ids)
def test_refnx_pol(nsd):
"""
Run validation for genx.

Parameters
----------
nsd: tuple
test_name, slabs, data
"""
# NCOLS of data:
# 2 - test kernel only
# 3 - test kernel and chi2 calculation
# 4 - test resolution smearing and chi2 calculation
test_name, slabs, data, AGUIDE, H = nsd
if H > 0:
pytest.skip("refnx does not support Zeeman splitting (yet)")
return

slabs = np.array(slabs)
kernel_test_pol(slabs, data, AGUIDE)


def kernel_test_pol(slabs, data, AGUIDE):
"""
Test the polarised reflectivity kernel for refnx.

Parameters
----------
slabs: np.ndarray
Slab representation of the system
data: np.ndarray
Q, R arrays (--, -+, +-, ++)
AGUIDE: float
AGUIDE (degrees)
"""
Q = data[:, 0]
npts = len(Q)

layers = []
for thickness, rsld, isld, theta, sldm, sigma in slabs:
slab = MagneticSlab(
thickness, rsld + 1j * isld, sigma, sldm, thetaM=theta
)
layers.append(slab)
s = Structure(components=layers)
model = PolarisedReflectModel(s, bkgs=0.0, dq=0.0, Aguide=AGUIDE)
qq = np.full((len(Q) * 4, 4), np.nan)
qq[0:npts, 0] = Q
qq[npts : 2 * npts, 1] = Q
qq[2 * npts : 3 * npts, 2] = Q
qq[3 * npts : 4 * npts, 3] = Q
R = model(qq)
Ruu = R[0:npts]
Rud = R[npts : 2 * npts]
Rdu = R[2 * npts : 3 * npts]
Rdd = R[3 * npts : 4 * npts]
np.testing.assert_allclose(Ruu, data[:, 4], rtol=8e-5)
np.testing.assert_allclose(Rdd, data[:, 1], rtol=8e-5)
np.testing.assert_allclose(Rud, data[:, 3], rtol=8e-5)
np.testing.assert_allclose(Rdu, data[:, 2], rtol=8e-5)


if __name__ == "__main__":
for nsd, backend in tests_backends:
test_refnx(nsd, backend)
for nsd, backend in pol_tests_backends:
test_refnx_pol(nsd, backend)
6 changes: 3 additions & 3 deletions validation/test/polarised/layers/test0.layers
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#thickness sld mu thetaM sldm roughness
0.000 0.000 0.000 90.00 0.000 0.000
50.00 4.000 0.000 90.00 0.000 0.000
0.000 2.070 0.000 90.00 0.000 0.000
825.0 9.060 0.000 90.00 0.000 0.000
0.000 2.070 0.000 90.00 0.000 0.000
50.00 4.000 0.000 90.00 0.000 0.000
0.000 0.000 0.000 90.00 0.000 0.000
6 changes: 3 additions & 3 deletions validation/test/polarised/layers/test1.layers
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#thickness sldn sldi thetaM sldm roughness
0 4 0 90.00 0 0
200 2 0 90.00 1 0
200 4 0 180.0 1 0
0 0 0 90.00 0 0
200 4 0 180.0 1 0
200 2 0 90.00 1 0
0 4 0 90.00 0 0
Loading