|
1 | | -using LinearAlgebra, StaticArrays, Test, Printf, Polynomials4ML |
2 | | -using Polynomials4ML: evaluate, evaluate_ed |
3 | | -using Polynomials4ML.Testing: print_tf, println_slim |
4 | | -using ForwardDiff |
5 | | -using ACEbase.Testing: fdtest |
6 | | - |
| 1 | +using Test |
| 2 | +using StaticArrays |
| 3 | +using LinearAlgebra |
| 4 | +using LuxCore |
7 | 5 | import Polynomials4ML as P4ML |
| 6 | +using Polynomials4ML: evaluate, evaluate_ed |
8 | 7 |
|
9 | | -## |
10 | | - |
11 | | -@info("Testing GaussianBasis") |
12 | | -basis = P4ML._rand_gaussian_basis() |
13 | | - |
14 | | -@info(" correctness of evaluation") |
15 | | -x = P4ML._generate_input(basis) |
16 | | -P = evaluate(basis, x) |
17 | | -P1, dP1 = evaluate_ed(basis, x) |
18 | | - |
19 | | -P4ML.Testing.test_evaluate_xx(basis) |
20 | | -P4ML.Testing.test_chainrules(basis) |
21 | | - |
22 | | -# Test is broken - reshape is causing this, hence single-input test is turned off |
23 | | -P4ML.Testing.test_withalloc(basis; allowed_allocs = 0, single=false) |
24 | | - |
25 | | -# Still fails with single=true, but btime doesn't show the allocation |
26 | | -# even stranger, re-evaluating `_reshape` into P4ML also makes the allocation |
27 | | -# disappear. Probably best to drop this for now, and revisit in a few months. |
28 | | -# P4ML.Testing.test_withalloc(basis; allowed_allocs = 0, single=true) |
29 | | - |
30 | | -## |
31 | | -# these are scripts to replicate and check this allocation problem. |
32 | | -# strangely it doesn't occur for the other bases. Only for AtomicOrbtials. |
33 | | -# |
34 | | -# using BenchmarkTools |
35 | | - |
36 | | -# P, dP = evaluate_ed(basis, x) |
37 | | -# @btime P4ML.evaluate_ed!($P, $dP, $basis, $x) |
38 | | - |
39 | | -# @profview let basis=basis, X=x, P=P, dP=dP |
40 | | -# for _ = 1:1_000_000 |
41 | | -# P4ML.evaluate_ed!(P, dP, basis, X) |
42 | | -# end |
43 | | -# end |
44 | | - |
45 | | -## |
46 | | - |
47 | | -@info("Testing SlaterBasis") |
48 | | -basis = P4ML._rand_slater_basis() |
49 | | - |
50 | | -@info(" correctness of evaluation") |
51 | | -x = P4ML._generate_input(basis) |
52 | | -P = evaluate(basis, x) |
53 | | -P1, dP1 = evaluate_ed(basis, x) |
54 | 8 |
|
55 | | -P4ML.Testing.test_evaluate_xx(basis) |
56 | | -P4ML.Testing.test_chainrules(basis) |
57 | | -P4ML.Testing.test_withalloc(basis; allowed_allocs = 0, single=false) |
| 9 | +@testset "GaussianBasis + HyperDual matches evaluate/evaluate_ed" begin |
| 10 | + basis = P4ML._rand_gaussian_basis() |
| 11 | + P4ML.Testing.test_hyperdual_consistency(basis) |
| 12 | + P4ML.Testing.test_evaluate_xx(basis) |
| 13 | + P4ML.Testing.test_chainrules(basis) |
| 14 | + P4ML.Testing.test_withalloc(basis; allowed_allocs = 0, single=false) |
| 15 | +end |
58 | 16 |
|
59 | | -## |
| 17 | +@testset "SlaterBasis + HyperDual matches evaluate/evaluate_ed" begin |
| 18 | + basis = P4ML._rand_slater_basis() |
| 19 | + P4ML.Testing.test_hyperdual_consistency(basis) |
| 20 | + P4ML.Testing.test_evaluate_xx(basis) |
| 21 | + P4ML.Testing.test_chainrules(basis) |
| 22 | + P4ML.Testing.test_withalloc(basis; allowed_allocs = 0, single=false) |
| 23 | +end |
60 | 24 |
|
61 | | -@info("Testing STOBasis") |
62 | | -basis = P4ML._rand_sto_basis() |
| 25 | +@testset "STOBasis + HyperDual matches evaluate/evaluate_ed" begin |
| 26 | + basis = P4ML._rand_sto_basis() |
| 27 | + P4ML.Testing.test_hyperdual_consistency(basis) |
| 28 | + P4ML.Testing.test_evaluate_xx(basis) |
| 29 | + P4ML.Testing.test_chainrules(basis) |
| 30 | + P4ML.Testing.test_withalloc(basis; allowed_allocs = 0, single=false) |
| 31 | +end |
63 | 32 |
|
64 | | -@info(" correctness of evaluation") |
65 | | -x = P4ML._generate_input(basis) |
66 | | -P = evaluate(basis, x) |
67 | | -P1, dP1 = evaluate_ed(basis, x) |
68 | 33 |
|
69 | 34 |
|
70 | | -P4ML.Testing.test_evaluate_xx(basis) |
71 | | -P4ML.Testing.test_chainrules(basis) |
72 | | -P4ML.Testing.test_withalloc(basis; allowed_allocs = 0, single=false) |
0 commit comments