8000 Adapt test tolerances to true Float64 precision by ddahlbom · Pull Request #360 · SunnySuite/Sunny.jl · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Adapt test tolerances to true Float64 precision #360

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 18, 2025
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
7 changes: 6 additions & 1 deletion src/SampledCorrelations/DataRetrieval.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,12 @@ function intensities(sc::SampledCorrelations, qpts; energies, kernel=nothing, kT
qpts = Base.convert(AbstractQPoints, qpts)
qs_reshaped = [to_reshaped_rlu(sc, q) for q in qpts.qs]

ffs = sc.measure.formfactors[1, :] # FIXME
# Check that form factors are uniform for each observable.
for col in eachcol(sc.measure.formfactors)
@assert allequal(col) "Observable-dependent form factors not yet supported."
end
ffs = sc.measure.formfactors[1, :]

intensities = zeros(eltype(sc.measure), isnan(sc.Δω) ? 1 : length(ωs), length(qpts.qs)) # N.B.: Inefficient indexing order to mimic LSWT
q_idx_info = pruned_wave_vector_info(sc, qs_reshaped)
crystal = @something sc.origin_crystal sc.crystal
Expand Down
6 changes: 3 additions & 3 deletions test/test_entangled_units.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ end

set_field!(esys, [0, 0, 0])
randomize_spins!(esys)
minimize_energy!(esys; g_abstol=1e-14)
@test norm(esys.sys_origin.dipoles[1]) < 1e-14
@test norm(esys.sys_origin.dipoles[2]) < 1e-14
minimize_energy!(esys)
@test norm(esys.sys_origin.dipoles[1]) < 1e-10
@test norm(esys.sys_origin.dipoles[2]) < 1e-10

# Test inter-bond exchange
pc = Sunny.as_general_pair_coupling(interactions.pair[1], esys.sys)
Expand Down
22 changes: 11 additions & 11 deletions test/test_lswt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,22 @@

sys.coherents .= reinterpret(reshape, Sunny.CVec{6}, ground_state)
minimize_energy!(sys)
@assert energy_per_site(sys) ≈ -328.38255
@test energy_per_site(sys) ≈ -328.38255

# Verify that this is a local minimum of energy
@test norm(Sunny.proj.(Sunny.energy_grad_coherents(sys), sys.coherents)) < 1e-8
@test norm(Sunny.proj.(Sunny.energy_grad_coherents(sys), sys.coherents)) < 1e-7

# Test energies at an arbitrary wave vector
qs = [[0.24331089495721447, 0.2818361515716459, 0.21954858411037714]]
swt = SpinWaveTheory(sys; measure=ssf_perp(sys; apply_g=false))

res = intensities_bands(swt, qs)
res = intensities_bands(swt, qs; kT=100.0)
# println(round.(vec(res.disp); digits=12))
# println(round.(vec(res.data); digits=12))
disps_golden = [1394.440092579932, 1393.728009951748, 1393.008551251227, 1392.919524974106, 1279.239919068656, 1279.094568472208, 1278.224518515369, 1277.691761482934, 1194.366336255048, 1193.750083625344, 1191.583519659752, 1189.794451340786, 1131.422439587814, 1131.202770074483, 1065.242927850645, 1065.095892446623, 1026.649340922942, 1024.028348558074, 1022.830406299683, 1020.767349639389, 945.202397530637, 944.795817851532, 835.545028394177, 832.001588695239, 827.939501409159, 827.307586947865, 821.216582166477, 820.430993567146, 820.294548776124, 818.594570998049, 810.207001090183, 808.553158273676, 766.524411071072, 766.516102750272, 766.51382585253, 766.508655558251, 758.5798541677, 754.683765885704, 750.572578891224, 750.47100625256, 665.954573008178, 662.421047653195, 651.465562549975, 651.417940124351, 581.258189152584, 568.105209800095, 559.053702296455, 558.493005822971, 552.043762736843, 550.131096070956, 539.733572947825, 530.698033192909, 499.661483510074, 494.928560823138, 435.233706061892, 427.702277064325, 408.128705853663, 399.856401749648, 370.069343063308, 369.845327686246, 365.049514240266, 363.639416669427, 354.648012591404, 346.609483927002, 341.989165167266, 339.373361067994, 318.363717384335, 276.219249203178, 263.1610538318, 257.409506246766, 230.539454193854, 229.778324172693, 203.971681278992, 197.504237153931, 193.879371534726, 189.866421875022, 189.815806967694, 167.94413443161, 154.923566498384, 146.21953884777]
data_golden = [0.00038665026, 0.0, 0.007231537047, 0.0, 0.008665001888, 0.0, 0.015340530772, 0.0, 0.0, 0.054200267869, 0.073309637341, 0.0, 0.005276014091, 0.0, 0.0, 0.026708463804, 0.0, 0.062332773978, 0.112027719874, 0.0, 0.031129659091, 0.0, 0.115569104228, 0.0, 0.0, 0.038994974901, 0.0, 0.031152494381, 0.029113142876, 0.0, 0.0, 0.00467095768, 0.000762927464, 0.000940556177, 0.0, 0.0, 0.00877327198, 0.0, 0.033263081608, 0.0, 0.066082588247, 0.0, 0.0, 0.059956690592, 0.334527718881, 0.007608761425, 0.0, 0.0, 0.0, 0.068446181755, 0.029366565904, 0.0, 0.0, 0.605679689903, 0.378667970539, 0.0, 0.858558512424, 0.0, 0.0, 0.290056738762, 0.349117318827, 0.0, 0.0, 0.955658357376, 0.0, 1.606184739756, 0.0, 0.201711065754, 0.181786511323, 0.0, 0.0, 0.313711125445, 0.769401980923, 0.0, 0.010377681107, 0.0, 0.151200728665, 0.327686235743, 0.0, 0.0]
@test isapprox(res.disp, disps_golden; atol=1e-9)
@test isapprox(res.data, data_golden; atol=1e-9)
disps_golden = [1394.440092579925, 1393.728009951747, 1393.008551251224, 1392.919524974098, 1279.239919068637, 1279.094568472202, 1278.224518515366, 1277.69176148292, 1194.366336255056, 1193.750083625346, 1191.583519659758, 1189.794451340792, 1131.422439587906, 1131.202770074575, 1065.242927850642, 1065.09589244662, 1026.649340922954, 1024.028348558092, 1022.830406299696, 1020.767349639404, 945.202397530689, 944.795817851584, 835.545028394171, 832.001588695236, 827.939501409146, 827.307586947863, 821.216582166429, 820.430993567084, 820.29454877608, 818.594570998006, 810.207001090189, 808.553158273681, 766.524411070996, 766.51610275022, 766.513825852464, 766.508655558188, 758.579854167682, 754.683765885699, 750.572578891218, 750.471006252543, 665.954573008179, 662.421047653194, 651.465562550036, 651.417940124412, 581.258189152574, 568.105209800088, 559.053702296449, 558.493005822973, 552.043762736839, 550.131096070953, 539.733572947827, 530.698033192904, 499.661483510112, 494.928560823174, 435.233706061902, 427.70227706432, 408.128705853668, 399.856401749667, 370.0693430633, 369.845327686247, 365.04951424025, 363.639416669404, 354.648012591371, 346.609483926993, 341.989165167298, 339.373361067981, 318.363717384318, 276.219249203163, 263.161053831818, 257.409506246762, 230.539454193868, 229.778324172696, 203.971681278995, 197.504237153905, 193.879371534689, 189.866421874996, 189.815806967662, 167.944134431612, 154.923566498395, 146.219538847758]
data_golden = [0.0003866506, 0.0, 0.007231543496, 0.0, 0.008665025993, 0.0, 0.015340573883, 0.0, 0.0, 0.054200622367, 0.073310127326, 0.0, 0.00527607845, 0.0, 0.0, 0.026709096225, 0.0, 0.062334999507, 0.112031767918, 0.0, 0.031132103909, 0.0, 0.115596282255, 0.0, 0.0, 0.039004932814, 0.0, 0.031161016058, 0.029121117571, 0.0, 0.0, 0.004672396604, 0.000763285324, 0.000940997393, 0.0, 0.0, 0.008777727636, 0.0, 0.033281383926, 0.0, 0.066167396885, 0.0, 0.0, 0.060045694629, 0.335530855821, 0.007634795842, 0.0, 0.0, 0.0, 0.068726684036, 0.02950016123, 0.0, 0.0, 0.610003683362, 0.383607563841, 0.0, 0.873304893237, 0.0, 0.0, 0.297421427631, 0.358428673038, 0.0, 0.0, 0.986474626382, 0.0, 1.661999771965, 0.0, 0.215308474961, 0.195882715465, 0.0, 0.0, 0.348754438732, 0.884436719117, 0.0, 0.012121723144, 0.0, 0.177850646384, 0.402799537928, 0.0, 0.0]
@test isapprox(res.disp, disps_golden; atol=1e-8)
@test isapprox(res.data, data_golden; atol=1e-8)

# Test first 5 output matrices
formfactors = [1 => FormFactor("Fe2")]
Expand All @@ -60,7 +60,7 @@
res = intensities_bands(swt, qs)
data_flat = reinterpret(ComplexF64, res.data[1:5])
# println(round.(data_flat; digits=12))
data_golden = natoms * ComplexF64[0.000768755803 + 0.0im, 0.000453313199 - 4.8935387e-5im, 0.000468535469 + 8.5812793e-5im, 0.000453313199 + 4.8935387e-5im, 0.00027042076 + 0.0im, 0.000270819458 + 8.0426107e-5im, 0.000468535469 - 8.5812793e-5im, 0.000270819458 - 8.0426107e-5im, 0.000295138353 + 0.0im, 0.0 + 0.0im, 0.0 - 0.0im, 0.0 + 0.0im, 0.0 + 0.0im, 0.0 + 0.0im, 0.0 + 0.0im, 0.0 - 0.0im, 0.0 - 0.0im, 0.0 + 0.0im, 0.00021794048 + 0.0im, -0.000114399503 - 0.000211293782im, -0.000126018935 + 0.000199895684im, -0.000114399503 + 0.000211293782im, 0.000264899429 + 0.0im, -0.000127650501 - 0.000227103219im, -0.000126018935 - 0.000199895684im, -0.000127650501 + 0.000227103219im, 0.000256212415 + 0.0im, 0.0 + 0.0im, -0.0 - 0.0im, -0.0 + 0.0im, -0.0 + 0.0im, 0.0 + 0.0im, -0.0 - 0.0im, -0.0 - 0.0im, -0.0 + 0.0im, 0.0 + 0.0im, 7.5017149e-5 + 0.0im, 0.000206625046 + 0.000158601356im, 0.000240055385 - 0.00011016714im, 0.000206625046 - 0.000158601356im, 0.000904437194 + 0.0im, 0.000428286033 - 0.000810966567im, 0.000240055385 + 0.00011016714im, 0.000428286033 + 0.000810966567im, 0.000929965845 + 0.0im]
data_golden = [0.003075023211 + 0.0im, 0.001813252796 - 0.000195741551im, 0.001874141877 + 0.000343251171im, 0.001813252796 + 0.000195741551im, 0.001081683041 + 0.0im, 0.001083277833 + 0.000321704428im, 0.001874141877 - 0.000343251171im, 0.001083277833 - 0.000321704428im, 0.001180553411 + 0.0im, 0.0 + 0.0im, 0.0 - 0.0im, 0.0 + 0.0im, 0.0 + 0.0im, 0.0 + 0.0im, 0.0 + 0.0im, 0.0 - 0.0im, 0.0 - 0.0im, 0.0 + 0.0im, 0.00087176192 + 0.0im, -0.000457598014 - 0.000845175127im, -0.000504075741 + 0.000799582738im, -0.000457598014 + 0.000845175127im, 0.001059597714 + 0.0im, -0.000510602006 - 0.000908412874im, -0.000504075741 - 0.000799582738im, -0.000510602006 + 0.000908412874im, 0.001024849661 + 0.0im, 0.0 + 0.0im, -0.0 - 0.0im, -0.0 + 0.0im, -0.0 + 0.0im, 0.0 + 0.0im, -0.0 - 0.0im, -0.0 - 0.0im, -0.0 + 0.0im, 0.0 + 0.0im, 0.000300068597 + 0.0im, 0.000826500187 + 0.000634405423im, 0.000960221539 - 0.000440668562im, 0.000826500187 - 0.000634405423im, 0.003617748774 + 0.0im, 0.001713144131 - 0.003243866269im, 0.000960221539 + 0.000440668562im, 0.001713144131 + 0.003243866269im, 0.003719863381 + 0.0im]

@test isapprox(data_flat, data_golden; atol=1e-9)
end
Expand Down Expand Up @@ -608,9 +608,9 @@ end
energies = 0:0.5:5
kernel = lorentzian(fwhm=0.3)
res = intensities(swt, qs; energies, kernel)
# println(round.(res.data; digits=10))
data_ref = [0.0425516442 0.148531187 0.0425516442; 0.1237107851 0.9444077155 0.1237107851; 1.0795751088 1.2612860859 1.0795751088; 0.4927038544 0.1685055314 0.4927038544; 0.0877705066 0.0606652185 0.0877705066; 0.0344619785 0.0308251889 0.0344619785; 0.0182142627 0.0185853576 0.0182142627; 0.0112300272 0.0124102892 0.0112300272; 0.0076073202 0.0088685106 0.0076073202; 0.0054909426 0.0066513058 0.0054909426; 0.0041486157 0.005172181 0.0041486157]
@test res.datadata_ref
# println(round.(res.data; digits=12))
data_ref = [0.042551644188 0.148531187027 0.042551644188; 0.123710785142 0.944407715529 0.123710785142; 1.079575108835 1.261286085876 1.079575108835; 0.492703854423 0.168505531387 0.492703854423; 0.087770506619 0.06066521855 0.087770506619; 0.034461978527 0.030825188879 0.034461978527; 0.018214262744 0.018585357642 0.018214262744; 0.011230027228 0.012410289203 0.011230027228; 0.007607320239 0.008868510563 0.007607320239; 0.005490942587 0.006651305827 0.005490942587; 0.004148615687 0.005172181047 0.004148615687]
isapprox(res.data, data_ref; atol=1e-9)
end


Expand Down
Loading
0