diffpes.radial tests

Validation and regression tests for diffpes.radial.

Validate spherical Bessel functions.

Extended Summary

The tests compare spherical_bessel_jl for orders 0, 1, and 2 with closed-form expressions. They verify the singular k=0 limit and the autodiff gradient of j_0. chex.variants runs each closed-form test with and without JIT compilation.

class tests.test_diffpes.test_radial.test_bessel.TestSphericalBesselJl(*args, **kwargs) None[source]

Bases: TestCase

Validate low-order spherical Bessel j_l(x) behavior and derivatives.

The tests compare the three lowest spherical Bessel functions with their closed-form expressions. They verify the k=0 boundary condition and compare the j_0 autodiff gradient with its analytical derivative. Each variant runs with and without JAX JIT.

See:

spherical_bessel_jl()

test_j0_gradient_matches_analytic_derivative() None[source]

Verify autodiff gradient of j_0 matches the analytical derivative.

The test differentiates j_0(x) at x=1.3 with jax.grad. It compares the result with the closed-form derivative. The values agree within 1e-10. This agreement confirms that the Bessel implementation supports reverse-mode autodiff for radial integrals.

Notes

The test builds the inputs in the test body and checks the stated property with the documented numerical or structural assertions.

Return type:

None

test_j0_and_j1_match_closed_form__with_jit() None

Verify j_0 and j_1 match their closed-form expressions.

The test uses test points x = [0.2, 0.7, 1.5] (avoiding x=0 singularity). j_0(x) = sin(x)/x and j_1(x) = sin(x)/x^2 - cos(x)/x are the standard analytical forms. Asserts element-wise agreement to within 1e-10, run under both JIT and eager modes via chex.variants.

Notes

The test builds the inputs in the test body and checks the stated property with the documented numerical or structural assertions.

Return type:

None

test_j0_and_j1_match_closed_form__without_jit() None

Verify j_0 and j_1 match their closed-form expressions.

The test uses test points x = [0.2, 0.7, 1.5] (avoiding x=0 singularity). j_0(x) = sin(x)/x and j_1(x) = sin(x)/x^2 - cos(x)/x are the standard analytical forms. Asserts element-wise agreement to within 1e-10, run under both JIT and eager modes via chex.variants.

Notes

The test builds the inputs in the test body and checks the stated property with the documented numerical or structural assertions.

Return type:

None

test_j2_matches_closed_form__with_jit() None

Verify j_2 matches its closed-form expression.

The test uses test points x = [0.4, 1.1, 2.4]. The analytical form is j_2(x) = (3/x^3 - 1/x)*sin(x) - (3/x^2)*cos(x). Asserts element-wise agreement to within 1e-10, confirming the recursion or series implementation is accurate for the l=2 case.

Notes

The test builds the inputs in the test body and checks the stated property with the documented numerical or structural assertions.

Return type:

None

test_j2_matches_closed_form__without_jit() None

Verify j_2 matches its closed-form expression.

The test uses test points x = [0.4, 1.1, 2.4]. The analytical form is j_2(x) = (3/x^3 - 1/x)*sin(x) - (3/x^2)*cos(x). Asserts element-wise agreement to within 1e-10, confirming the recursion or series implementation is accurate for the l=2 case.

Notes

The test builds the inputs in the test body and checks the stated property with the documented numerical or structural assertions.

Return type:

None

test_zero_argument_limits__with_jit() None

Verify the x=0 boundary conditions: j_0(0)=1, j_l(0)=0 for l>0.

The test evaluates j_0, j_1, and j_3 at x=0.0. The mathematical limits are j_0(0) = 1 and j_l(0) = 0 for all l >= 1. This is a critical case because the direct sin(x)/x formula has no value at zero. The implementation handles this removable singularity. The test asserts agreement to within 1e-12. The l=3 case also confirms higher- order terms beyond the three tested in the closed-form tests.

Notes

The test builds the inputs in the test body and checks the stated property with the documented numerical or structural assertions.

Return type:

None

test_zero_argument_limits__without_jit() None

Verify the x=0 boundary conditions: j_0(0)=1, j_l(0)=0 for l>0.

The test evaluates j_0, j_1, and j_3 at x=0.0. The mathematical limits are j_0(0) = 1 and j_l(0) = 0 for all l >= 1. This is a critical case because the direct sin(x)/x formula has no value at zero. The implementation handles this removable singularity. The test asserts agreement to within 1e-12. The l=3 case also confirms higher- order terms beyond the three tested in the closed-form tests.

Notes

The test builds the inputs in the test body and checks the stated property with the documented numerical or structural assertions.

Return type:

None

class tests.test_diffpes.test_radial.test_bessel.TestBesselErrors[source]

Bases: object

Validate invalid input handling in the Bessel module.

Validates that spherical_bessel_jl and the private helper _odd_double_factorial raise ValueError for out-of-range inputs.

See:

spherical_bessel_jl()

test_negative_order_raises() None[source]

Verify that a negative order raises ValueError.

The test calls spherical_bessel_jl with order=-1 and expects a ValueError. This input covers the guard at the top of the function.

Notes

The test builds the inputs in the test body and checks the stated property with the documented numerical or structural assertions.

Return type:

None

test_odd_double_factorial_even_input_raises() None[source]

Verify that an even input to _odd_double_factorial raises ValueError.

The implementation uses _odd_double_factorial internally to compute the small-argument Taylor coefficient. It requires a positive odd integer; even inputs are invalid.

Notes

The test builds the inputs in the test body and checks the stated property with the documented numerical or structural assertions.

Return type:

None

test_odd_double_factorial_even_positive_raises() None[source]

Verify that a positive even input to _odd_double_factorial raises ValueError.

The test establishes the odd double factorial even positive raises contract for bessel errors with the concrete values and array shapes described below.

Notes

The test builds the inputs in the test body and checks the stated property with the documented numerical or structural assertions.

Return type:

None

Validate radial integrals.

Extended Summary

The tests validate radial_integral for a Slater radial wavefunction and a spherical Bessel function. They compare the l'=0 numerical integral with an analytical result for Slater 1s orbitals. They also compare the zeta autodiff gradient with a central finite difference.

class tests.test_diffpes.test_radial.test_integrate.TestRadialIntegral(*args, **kwargs) None[source]

Bases: TestCase

Validate radial-integral values and derivatives.

The tests compare the numerical radial overlap integral with analytical results for Slater-type orbitals. They also compare JAX autodiff gradients for zeta with finite differences.

See:

radial_integral()

test_gradient_wrt_zeta_matches_finite_difference() None[source]

Verify autodiff gradient w.r.t. zeta matches finite differences.

The test defines the real part of the l'=0 radial integral as a scalar objective. It uses a Slater 1s orbital at k=0.9 and zeta=1.1. The test differentiates with jax.grad and compares with a central finite-difference estimate with step eps=5e-4. Uses an 18000-point grid up to r=45 Bohr. Asserts agreement to within 5e-3 for both tolerances. This result confirms smooth derivatives through the integration, radial construction, and Bessel evaluation.

Notes

The test builds the inputs in the test body and checks the stated property with the documented numerical or structural assertions.

Return type:

None

test_l0_slater_matches_analytic_integral__with_jit() None

Verify the l’=0 radial integral matches the analytical Fourier transform.

The test uses a Slater 1s orbital with zeta=1.2. Its j_0(kr) overlap integral has a closed-form result. The test uses a dense 25000-point grid up to r=50 Bohr and test k-values [0.2, 0.8, 1.4]. Asserts the real part of the numerical integral agrees with the analytical expression to within 5e-3 in both absolute and relative tolerance. Run under both JIT and eager modes via chex.variants.

Notes

The test builds the inputs in the test body and checks the stated property with the documented numerical or structural assertions.

Return type:

None

test_l0_slater_matches_analytic_integral__without_jit() None

Verify the l’=0 radial integral matches the analytical Fourier transform.

The test uses a Slater 1s orbital with zeta=1.2. Its j_0(kr) overlap integral has a closed-form result. The test uses a dense 25000-point grid up to r=50 Bohr and test k-values [0.2, 0.8, 1.4]. Asserts the real part of the numerical integral agrees with the analytical expression to within 5e-3 in both absolute and relative tolerance. Run under both JIT and eager modes via chex.variants.

Notes

The test builds the inputs in the test body and checks the stated property with the documented numerical or structural assertions.

Return type:

None

class tests.test_diffpes.test_radial.test_integrate.TestRadialIntegrateErrors[source]

Bases: object

Validate invalid input handling in radial_integral.

Validates that radial_integral raises ValueError for negative l_prime values.

See:

radial_integral()

test_negative_l_prime_raises() None[source]

Verify that l_prime < 0 raises ValueError.

The test calls radial_integral with l_prime=-1 and expects a ValueError that matches “non-negative”. This input covers the guard at the top of the function.

Notes

The test builds the inputs in the test body and checks the stated property with the documented numerical or structural assertions.

Return type:

None

Validate radial wavefunction models.

Extended Summary

The tests validate the slater_radial and hydrogenic_radial constructors. The Slater tests verify normalization and compare autodiff gradients with finite differences. The hydrogenic tests compare the 1s and 2p radial functions with analytical expressions. They also verify the boundary condition R_{2p}(0) = 0.

class tests.test_diffpes.test_radial.test_wavefunctions.TestSlaterRadial(*args, **kwargs) None[source]

Bases: TestCase

Validate Slater radial normalization and autodiff gradients.

The tests verify the normalization of the Slater-type orbital. They also compare the jax.grad result for zeta with central finite differences.

See:

slater_radial()

test_gradient_wrt_zeta_matches_finite_difference() None[source]

Verify autodiff gradient of Slater sum w.r.t. zeta matches FD.

The test defines a scalar objective = sum(R(r; zeta)) for n=2, zeta=1.15 on a 500-point grid up to r=8 Bohr. Differentiates with jax.grad and compares against a central finite-difference estimate with step eps=1e-4. Asserts agreement to within 2e-4 (atol and rtol), confirming the normalization constant, power-law prefactor, and exponential are all smoothly differentiable.

Notes

The test builds the inputs in the test body and checks the stated property with the documented numerical or structural assertions.

Return type:

None

test_normalization__with_jit() None

Verify normalization of the Slater 2s orbital to unity.

The test constructs R(r) for n=2 and zeta=1.3 on a 20000-point grid through 30 Bohr. It integrates |R(r)|^2 * r^2 with trapezoidal rule. Asserts the integral is within 2e-3 of 1.0. The dense grid and large cutoff ensure the exponential tail contributes negligibly. Run under both JIT and eager modes.

Notes

The test builds the inputs in the test body and checks the stated property with the documented numerical or structural assertions.

Return type:

None

test_normalization__without_jit() None

Verify normalization of the Slater 2s orbital to unity.

The test constructs R(r) for n=2 and zeta=1.3 on a 20000-point grid through 30 Bohr. It integrates |R(r)|^2 * r^2 with trapezoidal rule. Asserts the integral is within 2e-3 of 1.0. The dense grid and large cutoff ensure the exponential tail contributes negligibly. Run under both JIT and eager modes.

Notes

The test builds the inputs in the test body and checks the stated property with the documented numerical or structural assertions.

Return type:

None

class tests.test_diffpes.test_radial.test_wavefunctions.TestHydrogenicRadial(*args, **kwargs) None[source]

Bases: TestCase

Validate hydrogenic radial wavefunctions against analytical expressions.

The tests compare hydrogenic_radial for hydrogen with closed-form expressions. They verify the 1s ground state and the 2p boundary condition. All radial functions with l > 0 vanish at the origin.

See:

hydrogenic_radial()

test_1s_matches_analytic_expression__with_jit() None

Verify R_{10}(r) = 2*exp(-r) for the hydrogen 1s orbital.

The test evaluates the hydrogenic radial function for n=1, l=0, and Z_eff=1. It uses four radii from 0.0 to 2.5 Bohr. It compares the result with the analytical 1s expression. The test asserts element-wise agreement to within 1e-10. The r=0 point tests the boundary condition R_{10}(0) = 2, and the larger r values test the exponential decay.

Notes

The test builds the inputs in the test body and checks the stated property with the documented numerical or structural assertions.

Return type:

None

test_1s_matches_analytic_expression__without_jit() None

Verify R_{10}(r) = 2*exp(-r) for the hydrogen 1s orbital.

The test evaluates the hydrogenic radial function for n=1, l=0, and Z_eff=1. It uses four radii from 0.0 to 2.5 Bohr. It compares the result with the analytical 1s expression. The test asserts element-wise agreement to within 1e-10. The r=0 point tests the boundary condition R_{10}(0) = 2, and the larger r values test the exponential decay.

Notes

The test builds the inputs in the test body and checks the stated property with the documented numerical or structural assertions.

Return type:

None

test_2p_is_zero_at_origin__with_jit() None

Verify the 2p (n=2, l=1) radial function vanishes at r=0.

The test evaluates R_{21}(r=0) for Z_eff=1. All hydrogenic radial functions with l > 0 contain a factor r^l and therefore must vanish at the origin. Asserts the output is zero to within 1e-12, testing this critical boundary condition / edge case.

Notes

The test builds the inputs in the test body and checks the stated property with the documented numerical or structural assertions.

Return type:

None

test_2p_is_zero_at_origin__without_jit() None

Verify the 2p (n=2, l=1) radial function vanishes at r=0.

The test evaluates R_{21}(r=0) for Z_eff=1. All hydrogenic radial functions with l > 0 contain a factor r^l and therefore must vanish at the origin. Asserts the output is zero to within 1e-12, testing this critical boundary condition / edge case.

Notes

The test builds the inputs in the test body and checks the stated property with the documented numerical or structural assertions.

Return type:

None

class tests.test_diffpes.test_radial.test_wavefunctions.TestSlaterRadialErrors[source]

Bases: object

Validate invalid input handling in slater_radial.

Validates that slater_radial raises ValueError when the principal quantum number n is less than 1.

See:

slater_radial()

test_n_zero_raises() None[source]

Verify that n=0 raises ValueError.

The test calls slater_radial with n=0 and expects a ValueError that matches “n must be >= 1”.

Notes

The test builds the inputs in the test body and checks the stated property with the documented numerical or structural assertions.

Return type:

None

class tests.test_diffpes.test_radial.test_wavefunctions.TestHydrogenicRadialErrors[source]

Bases: object

Validate invalid input handling in hydrogenic_radial.

Validates that hydrogenic_radial raises ValueError for invalid principal quantum numbers (n < 1) and for angular momentum that violates 0 <= l < n.

See:

hydrogenic_radial()

test_n_zero_raises() None[source]

Verify that n=0 raises ValueError for hydrogenic_radial.

The test calls hydrogenic_radial with n=0 and expects a ValueError that matches “n must be >= 1”.

Notes

The test builds the inputs in the test body and checks the stated property with the documented numerical or structural assertions.

Return type:

None

test_angular_momentum_equals_n_raises() None[source]

Verify that angular_momentum >= n raises ValueError.

The test calls hydrogenic_radial with n=2 and angular_momentum=2. This input violates the angular-momentum constraint. The test expects a matching ValueError.

Notes

The test builds the inputs in the test body and checks the stated property with the documented numerical or structural assertions.

Return type:

None

class tests.test_diffpes.test_radial.test_wavefunctions.TestLaguerreRecurrence[source]

Bases: object

Validate the Laguerre polynomial recurrence path.

Exercises the order >= 2 branch of _associated_laguerre that uses jax.lax.fori_loop for the recurrence, and validates the error paths for negative order or alpha.

See:

hydrogenic_radial()

test_negative_order_raises() None[source]

Verify that order < 0 raises ValueError in _associated_laguerre.

The test establishes the negative order raises contract for laguerre recurrence with the concrete values and array shapes described below.

Notes

The test builds the inputs in the test body and checks the stated property with the documented numerical or structural assertions.

Return type:

None

test_negative_alpha_raises() None[source]

Verify that alpha < 0 raises ValueError in _associated_laguerre.

The test establishes the negative alpha raises contract for laguerre recurrence with the concrete values and array shapes described below.

Notes

The test builds the inputs in the test body and checks the stated property with the documented numerical or structural assertions.

Return type:

None

test_order_one_early_return() None[source]

Verify that order=1 takes the early-return branch.

L_1^0(x) = 1 - x, so at x=0 the value is 1.0 and at x=1 it is 0.0. This exercises the if order == 1: return laguerre_one path.

Notes

The test builds the inputs in the test body and checks the stated property with the documented numerical or structural assertions.

Return type:

None

test_order_two_uses_recurrence() None[source]

Verify that order=2 executes the fori_loop recurrence branch.

The order=0 and order=1 branches return early; order >= 2 uses the upward recurrence. Checks the known value L_2^0(0) = 1 - 0 + 0 = 1.

Notes

The test builds the inputs in the test body and checks the stated property with the documented numerical or structural assertions.

Return type:

None