Skip to content

Commit 80e95f9

Browse files
committed
Add sparse vs dense test
1 parent 3a7e183 commit 80e95f9

File tree

2 files changed

+45
-5
lines changed

2 files changed

+45
-5
lines changed

python/featomic/tests/clebsch_gordan/cartesian_spherical.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,9 @@ def test_cartesian_to_spherical_rank_2_by_equation(cg_backend):
314314
)
315315
]
316316
)
317-
rank_2_input_sph = cartesian_to_spherical(rank_2_input_cart, ["xyz1", "xyz2"])
317+
rank_2_input_sph = cartesian_to_spherical(
318+
rank_2_input_cart, ["xyz1", "xyz2"], cg_backend=cg_backend
319+
)
318320

319321
# Extract the lambda = 2 component
320322
l2_input = operations.drop_blocks(
@@ -364,7 +366,9 @@ def test_cartesian_to_spherical_rank_3_by_equation(cg_backend):
364366
)
365367
]
366368
)
367-
rank_3_input_sph = cartesian_to_spherical(rank_3_input_cart, ["xyz1", "xyz2", "xyz3"])
369+
rank_3_input_sph = cartesian_to_spherical(
370+
rank_3_input_cart, ["xyz1", "xyz2", "xyz3"], cg_backend=cg_backend
371+
)
368372

369373
# Extract the lambda = 3 component
370374
l3_input = operations.drop_blocks(

python/featomic/tests/clebsch_gordan/cg_product.py

+39-3
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,16 @@ def spherical_expansion_by_pair(frames: List[ase.Atoms]):
8585
calculator = featomic.SphericalExpansionByPair(**SPHEX_HYPERS)
8686
return calculator.compute(frames)
8787

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):
9090
"""
9191
Tests that key dimensions named the same in two tensors are matched.
9292
"""
9393
# Set up
9494
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+
)
9698

9799
# Compute lambda-SOAP
98100
density = spherical_expansion(frames)
@@ -431,3 +433,37 @@ def test_device_dtype(dtype, device):
431433
o3_lambda_1_new_name="l_1",
432434
o3_lambda_2_new_name="l_2",
433435
)
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

Comments
 (0)