@@ -85,14 +85,16 @@ def spherical_expansion_by_pair(frames: List[ase.Atoms]):
85
85
calculator = featomic .SphericalExpansionByPair (** SPHEX_HYPERS )
86
86
return calculator .compute (frames )
87
87
88
-
89
- def test_keys_are_matched ():
88
+ @ pytest . mark . parametrize ( "cg_backend" , [ "python-sparse" , "python-dense" ])
89
+ def test_keys_are_matched (cg_backend ):
90
90
"""
91
91
Tests that key dimensions named the same in two tensors are matched.
92
92
"""
93
93
# Set up
94
94
frames = h2o_isolated ()
95
- calculator = ClebschGordanProduct (max_angular = MAX_ANGULAR * 2 )
95
+ calculator = ClebschGordanProduct (
96
+ max_angular = MAX_ANGULAR * 2 , cg_backend = cg_backend
97
+ )
96
98
97
99
# Compute lambda-SOAP
98
100
density = spherical_expansion (frames )
@@ -431,3 +433,37 @@ def test_device_dtype(dtype, device):
431
433
o3_lambda_1_new_name = "l_1" ,
432
434
o3_lambda_2_new_name = "l_2" ,
433
435
)
436
+
437
+
438
+ def test_dense_sparse_agree ():
439
+ """
440
+ Tests that the max_angular is sufficient to correlate the two tensors when not large
441
+ enough to cover MAX_ANGULAR, but when an angular cutoff is applied.
442
+ """
443
+ frames = h2o_isolated ()
444
+ density = spherical_expansion (frames )
445
+
446
+ results = []
447
+ for cg_backend in ["python-sparse" , "python-dense" ]:
448
+
449
+
450
+ # max_angular to be twice as big here if not using an angular cutoff
451
+ calculator = ClebschGordanProduct (
452
+ max_angular = MAX_ANGULAR ,
453
+ cg_backend = cg_backend ,
454
+ )
455
+ results .append (
456
+ calculator .compute (
457
+ metatensor .rename_dimension (density , "properties" , "n" , "n_1" ),
458
+ metatensor .rename_dimension (density , "properties" , "n" , "n_2" ),
459
+ o3_lambda_1_new_name = "l_1" ,
460
+ o3_lambda_2_new_name = "l_2" ,
461
+ selected_keys = Labels (
462
+ names = ["o3_lambda" ],
463
+ values = np .arange (MAX_ANGULAR + 1 ).reshape (- 1 , 1 ),
464
+ ),
465
+ )
466
+ )
467
+
468
+ assert metatensor .equal_metadata (results [0 ], results [1 ])
469
+ assert metatensor .allclose (results [0 ], results [1 ])
0 commit comments