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:
TestCaseValidate 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=0boundary condition and compare thej_0autodiff gradient with its analytical derivative. Each variant runs with and without JAX JIT.- test_j0_gradient_matches_analytic_derivative() None[source]¶
Verify autodiff gradient of j_0 matches the analytical derivative.
The test differentiates
j_0(x)atx=1.3withjax.grad. It compares the result with the closed-form derivative. The values agree within1e-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:
- 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:
- 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:
- 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:
- 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:
- 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)/xformula 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:
- 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)/xformula 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:
- class tests.test_diffpes.test_radial.test_bessel.TestBesselErrors[source]¶
Bases:
objectValidate invalid input handling in the Bessel module.
Validates that
spherical_bessel_jland the private helper_odd_double_factorialraiseValueErrorfor out-of-range inputs.- test_negative_order_raises() None[source]¶
Verify that a negative order raises ValueError.
The test calls
spherical_bessel_jlwithorder=-1and expects aValueError. 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:
- 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_factorialinternally 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:
- 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:
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:
TestCaseValidate 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
zetawith finite differences.- See:
- 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'=0radial integral as a scalar objective. It uses a Slater 1s orbital atk=0.9andzeta=1.1. The test differentiates withjax.gradand 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 within5e-3for 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:
- 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. Itsj_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 viachex.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:
- 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. Itsj_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 viachex.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:
- class tests.test_diffpes.test_radial.test_integrate.TestRadialIntegrateErrors[source]¶
Bases:
objectValidate invalid input handling in radial_integral.
Validates that
radial_integralraisesValueErrorfor negativel_primevalues.- See:
- test_negative_l_prime_raises() None[source]¶
Verify that l_prime < 0 raises ValueError.
The test calls
radial_integralwithl_prime=-1and expects aValueErrorthat 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:
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:
TestCaseValidate Slater radial normalization and autodiff gradients.
The tests verify the normalization of the Slater-type orbital. They also compare the
jax.gradresult forzetawith central finite differences.- See:
- 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.gradand 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:
- test_normalization__with_jit() None¶
Verify normalization of the Slater 2s orbital to unity.
The test constructs
R(r)forn=2andzeta=1.3on a 20000-point grid through 30 Bohr. It integrates|R(r)|^2 * r^2with 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:
- test_normalization__without_jit() None¶
Verify normalization of the Slater 2s orbital to unity.
The test constructs
R(r)forn=2andzeta=1.3on a 20000-point grid through 30 Bohr. It integrates|R(r)|^2 * r^2with 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:
- class tests.test_diffpes.test_radial.test_wavefunctions.TestHydrogenicRadial(*args, **kwargs) None[source]¶
Bases:
TestCaseValidate hydrogenic radial wavefunctions against analytical expressions.
The tests compare
hydrogenic_radialfor hydrogen with closed-form expressions. They verify the 1s ground state and the 2p boundary condition. All radial functions withl > 0vanish at the origin.- See:
- 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, andZ_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:
- 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, andZ_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:
- 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:
- 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:
- class tests.test_diffpes.test_radial.test_wavefunctions.TestSlaterRadialErrors[source]¶
Bases:
objectValidate invalid input handling in slater_radial.
Validates that
slater_radialraisesValueErrorwhen the principal quantum numbernis less than 1.- See:
- test_n_zero_raises() None[source]¶
Verify that n=0 raises ValueError.
The test calls
slater_radialwithn=0and expects aValueErrorthat 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:
- class tests.test_diffpes.test_radial.test_wavefunctions.TestHydrogenicRadialErrors[source]¶
Bases:
objectValidate invalid input handling in hydrogenic_radial.
Validates that
hydrogenic_radialraisesValueErrorfor invalid principal quantum numbers (n < 1) and for angular momentum that violates 0 <= l < n.- See:
- test_n_zero_raises() None[source]¶
Verify that n=0 raises ValueError for hydrogenic_radial.
The test calls
hydrogenic_radialwithn=0and expects aValueErrorthat 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:
- test_angular_momentum_equals_n_raises() None[source]¶
Verify that angular_momentum >= n raises ValueError.
The test calls
hydrogenic_radialwithn=2andangular_momentum=2. This input violates the angular-momentum constraint. The test expects a matchingValueError.Notes
The test builds the inputs in the test body and checks the stated property with the documented numerical or structural assertions.
- Return type:
- class tests.test_diffpes.test_radial.test_wavefunctions.TestLaguerreRecurrence[source]¶
Bases:
objectValidate the Laguerre polynomial recurrence path.
Exercises the
order >= 2branch of_associated_laguerrethat usesjax.lax.fori_loopfor the recurrence, and validates the error paths for negative order or alpha.- See:
- 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:
- 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:
- 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_onepath.Notes
The test builds the inputs in the test body and checks the stated property with the documented numerical or structural assertions.
- Return type:
- 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: