Skip to content

Fix spherical-to-Cartesian derivative at the south pole (phi = pi) - #353

Open
syahra712 wants to merge 2 commits into
theochem:masterfrom
syahra712:hunt/grid
Open

syahra712 wants to merge 2 commits into
theochem:masterfrom
syahra712:hunt/grid

Conversation

@syahra712

Copy link
Copy Markdown
Contributor

convert_derivative_from_spherical_to_cartesian divides by sin(phi) in the Jacobian. It already zeroes the theta column at phi == 0, but sin(phi) also vanishes at phi = pi, where the function returned values of order 1e15 (e.g. [-2.4e15, 7.8e15, -1.0]).

The guard now checks abs(sin(phi)) < 1e-10, covering both poles. Added a regression test parametrised over phi = 0, pi; it fails at pi without the fix.

The Jacobian divides by sin(phi), which vanishes at phi = pi as well as
phi = 0, but only the phi = 0 case was guarded. Evaluating at the south pole
returned ~1e15 garbage. Drop the theta term whenever sin(phi) ~ 0.
@syahra712

Copy link
Copy Markdown
Contributor Author

A note on the red check: "Python 3.11 on OS ubuntu-latest" failed in test_ode.py::test_transform_and_rearrange_to_explicit_ode_with_simple_boundary[transform3-fx_ones-coeffs3], which is not related to this change.

  • The failing run is for the second commit, which only reformats the new regression test with ruff.
  • The run for the first commit passed the same test on the same job, with the same numpy 2.4.6 and scipy 1.17.1.
  • That parametrization uses np.random.uniform(0, 100, (3,)) coefficients drawn without a seed when the tests are collected, so some draws give a boundary-value problem where the two solve_bvp solutions differ by more than atol=1e-4.

A re-run should pass. If it would help, I can open a separate small PR that seeds those coefficients so the test is deterministic.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant