Skip to content

Commit e51b264

Browse files
authored
Merge branch 'main' into origin/Ash
2 parents 3d82977 + 0fa00c1 commit e51b264

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

test/Core/calculators.jl

+11-15
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,9 @@ using NQCDynamics.Calculators
44
using LinearAlgebra: tr, Diagonal, eigvecs, eigvals
55
using RingPolymerArrays: RingPolymerArrays
66

7-
# For the allocation tests check against both backends as we can't be sure which is in use.
8-
const MKL_EIGEN_ALLOCATIONS = 54912
9-
# Julia 1.10 has slightly different eigen allocations
10-
if VERSION>v"1.9"
11-
const OPENBLAS_EIGEN_ALLOCATIONS = 57216
12-
else
13-
const OPENBLAS_EIGEN_ALLOCATIONS = 56896
14-
end
7+
# Allocation-based tests aren't great - change these values if there's a good reason to.
8+
# Eigenvalue allocations limit: Regardless of maths backend and Julia version, eigenvalues should take fewer allocations than this or something might be wrong
9+
const MAX_EIGEN_ALLOCATIONS = 60000
1510

1611
@testset "General constructors" begin
1712
model = NQCModels.DoubleWell()
@@ -275,8 +270,9 @@ end
275270
@test @allocated(Calculators.evaluate_potential!(calc, r)) == 0
276271
@test @allocated(Calculators.evaluate_derivative!(calc, r)) == 0
277272
eigen_allocations = @allocated(Calculators.evaluate_eigen!(calc, r))
278-
@info "Non-zero allocations test LargeDiabaticCalculator: eigen_allocations returned $(eigen_allocations)"
279-
@test (eigen_allocations MKL_EIGEN_ALLOCATIONS) || (eigen_allocations OPENBLAS_EIGEN_ALLOCATIONS)
273+
global allocs_LargeDiabatic = eigen_allocations
274+
@debug "LargeDiabaticCalculator: $(eigen_allocations) needed for eigenvalues"
275+
@test eigen_allocations < MAX_EIGEN_ALLOCATIONS
280276
@test @allocated(Calculators.evaluate_adiabatic_derivative!(calc, r)) == 0
281277
@test @allocated(Calculators.evaluate_nonadiabatic_coupling!(calc, r)) == 0
282278
end
@@ -298,9 +294,7 @@ end
298294

299295
@test @allocated(Calculators.evaluate_potential!(calc, r)) == 0
300296
@test @allocated(Calculators.evaluate_derivative!(calc, r)) == 0
301-
eigen_allocations = @allocated(Calculators.evaluate_eigen!(calc, r)) / 10
302-
@info "Non-zero allocations test RingPolymerLargeDiabaticCalculator: eigen_allocations returned $(eigen_allocations)"
303-
@test (eigen_allocations MKL_EIGEN_ALLOCATIONS) || (eigen_allocations OPENBLAS_EIGEN_ALLOCATIONS)
297+
@test @allocated(Calculators.evaluate_eigen!(calc, r)) == 10 * allocs_LargeDiabatic
304298
@test @allocated(Calculators.evaluate_adiabatic_derivative!(calc, r)) == 0
305299
@test @allocated(Calculators.evaluate_nonadiabatic_coupling!(calc, r)) == 0
306300
end
@@ -320,7 +314,9 @@ end
320314
Calculators.evaluate_friction!(calc, r)
321315
@test @allocated(Calculators.evaluate_potential!(calc, r)) == 0
322316
@test @allocated(Calculators.evaluate_derivative!(calc, r)) == 0
323-
@test @allocated(Calculators.evaluate_friction!(calc, r)) == 192
317+
global allocs_Friction = @allocated(Calculators.evaluate_friction!(calc, r))
318+
@debug "FrictionCalculator.evaluate_friction made $(allocs_Friction) allocations. This should be around 250."
319+
@test allocs_Friction 250
324320
end
325321

326322
@testset "RingPolymerFrictionCalculator" begin
@@ -338,5 +334,5 @@ end
338334
Calculators.evaluate_friction!(calc, r)
339335
@test @allocated(Calculators.evaluate_potential!(calc, r)) == 0
340336
@test @allocated(Calculators.evaluate_derivative!(calc, r)) == 0
341-
@test @allocated(Calculators.evaluate_friction!(calc, r)) == 1920
337+
@test @allocated(Calculators.evaluate_friction!(calc, r)) == 10 * allocs_Friction
342338
end

0 commit comments

Comments
 (0)