From e3ca3d376300403006080442a2139ecf5ae861cb Mon Sep 17 00:00:00 2001 From: ddahlbom Date: Thu, 5 Sep 2024 18:32:31 -0400 Subject: [PATCH 1/4] Fix wave vector pruning edge case --- src/SampledCorrelations/DataRetrieval.jl | 7 +++++-- test/test_correlation_sampling.jl | 8 ++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/SampledCorrelations/DataRetrieval.jl b/src/SampledCorrelations/DataRetrieval.jl index 89f32ee6d..2fb662dc8 100644 --- a/src/SampledCorrelations/DataRetrieval.jl +++ b/src/SampledCorrelations/DataRetrieval.jl @@ -14,8 +14,11 @@ function pruned_wave_vector_info(sc::SampledCorrelations, qs) # Convert to absolute units (for form factors) qabs_rounded = map(m -> sc.crystal.recipvecs * (m ./ sc.sys_dims), ms) - # List of "starting" pointers i where idcs[i-1] != idcs[i] - starts = findall(i -> i == 1 || idcs[i-1] != idcs[i], eachindex(idcs)) + # List of "starting" pointers i where qabs_rounded[i-1] != qabs_rounded[i] + # WARNING: This test cannot be done on idcs, since they wrap and a + # distinction must be made between wave vectors in different Brillouin + # zones which nonetheless index the same underlying data. + starts = findall(i -> i == 1 || !isapprox(qabs_rounded[i-1], qabs_rounded[i]), eachindex(qabs_rounded)) # Length of each run of repeated values counts = starts[2:end] - starts[1:end-1] diff --git a/test/test_correlation_sampling.jl b/test/test_correlation_sampling.jl index a2e24480d..257fad9f9 100644 --- a/test/test_correlation_sampling.jl +++ b/test/test_correlation_sampling.jl @@ -93,6 +93,14 @@ true_static_vals = intensities_static(res, qgrid) true_static_total = sum(true_static_vals.data) @test isapprox(true_static_total / prod(sys.dims), 1.0; atol=1e-12) + + # Make sure a list that contains successive wave vectors that rely on the + # same underlying data point (but require different treatment w.r.t. phase + # averaging and form factors) do not produce the same output. + formfactors = [1 => FormFactor("Fe2")] + sc.measure = ssf_trace(sys; apply_g=false, formfactors) + res = intensities_static(sc, [[0, 0, 1/2], [1, 0, 1/2]]; kT=nothing) + @test res.data[1] != res.data[2] end @testitem "Merge correlations" begin From 6a2f6b5d5e899c2f51421b98e7454e5ce011db5a Mon Sep 17 00:00:00 2001 From: ddahlbom Date: Thu, 5 Sep 2024 18:39:51 -0400 Subject: [PATCH 2/4] Tweak comments --- src/SampledCorrelations/DataRetrieval.jl | 7 +++---- test/test_correlation_sampling.jl | 6 +++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/SampledCorrelations/DataRetrieval.jl b/src/SampledCorrelations/DataRetrieval.jl index 2fb662dc8..a5b5c01ff 100644 --- a/src/SampledCorrelations/DataRetrieval.jl +++ b/src/SampledCorrelations/DataRetrieval.jl @@ -14,10 +14,9 @@ function pruned_wave_vector_info(sc::SampledCorrelations, qs) # Convert to absolute units (for form factors) qabs_rounded = map(m -> sc.crystal.recipvecs * (m ./ sc.sys_dims), ms) - # List of "starting" pointers i where qabs_rounded[i-1] != qabs_rounded[i] - # WARNING: This test cannot be done on idcs, since they wrap and a - # distinction must be made between wave vectors in different Brillouin - # zones which nonetheless index the same underlying data. + # List of "starting" pointers i where qabs_rounded[i-1] != qabs_rounded[i], + # i.e., indices where the desired wave vector is distinct from the previous + # one. starts = findall(i -> i == 1 || !isapprox(qabs_rounded[i-1], qabs_rounded[i]), eachindex(qabs_rounded)) # Length of each run of repeated values diff --git a/test/test_correlation_sampling.jl b/test/test_correlation_sampling.jl index 257fad9f9..75ce9fdde 100644 --- a/test/test_correlation_sampling.jl +++ b/test/test_correlation_sampling.jl @@ -94,9 +94,9 @@ true_static_total = sum(true_static_vals.data) @test isapprox(true_static_total / prod(sys.dims), 1.0; atol=1e-12) - # Make sure a list that contains successive wave vectors that rely on the - # same underlying data point (but require different treatment w.r.t. phase - # averaging and form factors) do not produce the same output. + # Test the case in which a list of wave vectors contains succesive elements + # that rely on the same underlying data point (same index into sc.data) but + # require different treatment w.r.t. phase averaging and/or form factors. formfactors = [1 => FormFactor("Fe2")] sc.measure = ssf_trace(sys; apply_g=false, formfactors) res = intensities_static(sc, [[0, 0, 1/2], [1, 0, 1/2]]; kT=nothing) From 332bf27b50b4b93772bf975e1f8035da458bdcd1 Mon Sep 17 00:00:00 2001 From: ddahlbom Date: Thu, 5 Sep 2024 18:43:37 -0400 Subject: [PATCH 3/4] Update comment --- test/test_correlation_sampling.jl | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/test_correlation_sampling.jl b/test/test_correlation_sampling.jl index 75ce9fdde..ab6b54506 100644 --- a/test/test_correlation_sampling.jl +++ b/test/test_correlation_sampling.jl @@ -94,9 +94,8 @@ true_static_total = sum(true_static_vals.data) @test isapprox(true_static_total / prod(sys.dims), 1.0; atol=1e-12) - # Test the case in which a list of wave vectors contains succesive elements - # that rely on the same underlying data point (same index into sc.data) but - # require different treatment w.r.t. phase averaging and/or form factors. + # Test whether two distinct wave vectors referencing the same underlying + # data point in sc.data are in fact treated differently. formfactors = [1 => FormFactor("Fe2")] sc.measure = ssf_trace(sys; apply_g=false, formfactors) res = intensities_static(sc, [[0, 0, 1/2], [1, 0, 1/2]]; kT=nothing) From 3ea504b4b67b96943440f2fbb685164945fb8341 Mon Sep 17 00:00:00 2001 From: Kipton Barros Date: Sun, 8 Sep 2024 08:32:09 -0400 Subject: [PATCH 4/4] Document fix --- docs/src/versions.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/src/versions.md b/docs/src/versions.md index 54b18f5ef..fa4cdf001 100644 --- a/docs/src/versions.md +++ b/docs/src/versions.md @@ -1,5 +1,11 @@ # Version History +## v0.7.2 +(In development) + +* Fix error in `SampledCorrelations` with a coarse ``𝐪``-grid. ([PR + #314](https://github.com/SunnySuite/Sunny.jl/pull/314)) + ## v0.7.1 (Sep 3, 2024)