aragog.jax
The aragog.jax package contains JAX-traceable replicas of the EOS, phase evaluator, and dSdt right-hand side. They are used to build an analytic Jacobian via jax.jacrev and feed it to SUNDIALS CVODE through the registered factory in aragog.solver.cvode_jax.
This module is loaded only when solver.use_jax_jacobian = true (the production default). The numpy path in aragog.solver.entropy_state remains the reference implementation and is exercised by the standalone tests; both must agree to numerical precision (see first-principles verification).
For when and why to opt into the JAX path, see CVODE and JAX-derived Jacobians.
| Submodule | Role |
|---|---|
aragog.jax.eos |
EntropyEOS_JAX, the JAX-traceable P-S table loader, and PhaseState, the per-cell phase cache. Mirrors the public surface of aragog.eos.EntropyEOS. |
aragog.jax.phase |
PhaseParams, MeshArrays, PhaseProperties, FluxOutput, compute_fluxes, compute_mlt, evaluate_phase. SPIDER-parity two-stage blend, mixing-length convection, and pure-functional flux assembly. |
aragog.jax.solver |
BoundaryParams, SolveResult. The standalone JAX solve path used by the verification suite; in production the JAX path supplies only the Jacobian and CVODE drives the integration. |
aragog.jax.nondim |
NonDimScales. Reference scales used to non-dimensionalise state and time before passing them to the integrator. |
aragog.jax.eos
JAX-traceable P-S equation of state. Loads SPIDER-format two-phase tables and provides temperature, density, melt_fraction, and the latent-heat / phase-boundary derivatives via jax.jit-compatible bilinear interpolation.
eos
JAX-based entropy EOS layer for PALEOS P-S tables.
Drop-in replacement for aragog.eos.entropy.EntropyEOS using JAX arrays and jax.scipy.interpolate.RegularGridInterpolator. All methods are JIT-compilable and differentiable via jax.grad.
Table loading uses the existing numpy loader (disk I/O is not JIT-compiled). The loaded grids are converted to JAX arrays and stored as equinox Module fields so the entire EOS object is a valid JAX pytree.
Dependencies: jax, equinox (both already in PROTEUS ecosystem via atmodeller).
EntropyEOS_JAX(eos_dir)
Bases: Module
JAX-based entropy EOS from PALEOS P-S tables.
Drop-in replacement for aragog.eos.entropy.EntropyEOS with all
lookups JIT-compilable and differentiable. Constructed from the same
SPIDER-format table files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
eos_dir
|
Path or str
|
Directory containing the SPIDER-format P-S table files. |
required |
Source code in src/aragog/jax/eos.py
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 | |
compute_phase_state(P, S, k_solid, k_liquid, matprop_smooth_width=0.0)
Single-pass SPIDER-parity phase evaluation (cp_blend='latent').
Bit-for-bit mirror of numpy EntropyPhaseEvaluator._update_eos
with cp_blend='latent'. All properties share the same
intermediates, and each is the smth-blend
smth * mixed + (1 - smth) * single matching SPIDER
combine_matprop (eos_composite.c:278-285).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
P
|
Array
|
Pressure [Pa] and entropy [J/kg/K], same shape. |
required |
S
|
Array
|
Pressure [Pa] and entropy [J/kg/K], same shape. |
required |
k_solid
|
float
|
Single-phase thermal conductivities [W/m/K]. |
required |
k_liquid
|
float
|
Single-phase thermal conductivities [W/m/K]. |
required |
matprop_smooth_width
|
float
|
SPIDER's |
0.0
|
Returns:
| Type | Description |
|---|---|
PhaseState
|
All blended properties and shared intermediates. |
Source code in src/aragog/jax/eos.py
567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 | |
dTdPs(P, S)
Adiabatic temperature gradient dT/dP|_S (P, S) [K/Pa].
Source code in src/aragog/jax/eos.py
539 540 541 | |
density(P, S)
Density rho(P, S) [kg/m^3], matching numpy EntropyEOS.density.
- Mushy zone (0 < phi < 1): harmonic mean of end-member
densities evaluated at phase-boundary entropies (Lever Rule,
SPIDER
eos_composite.c:236-237). - Pure phase (phi = 0 or phi = 1): evaluate the active single-
phase table at the actual S (clamped by the table itself).
SPIDER
combine_matprop(smth=0, mixed, single)selects the single-phase branch in this regime. Using the harmonic-mean form unconditionally biases the fully-molten density relative to the numpy EntropyEOS.
Source code in src/aragog/jax/eos.py
495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 | |
heat_capacity(P, S)
Specific heat capacity Cp(P, S) [J/kg/K].
Source code in src/aragog/jax/eos.py
535 536 537 | |
latent_heat(P)
Latent heat L(P) = T_fus x (S_liq - S_sol) [J/kg].
Source code in src/aragog/jax/eos.py
543 544 545 546 547 548 549 550 | |
liquidus_entropy(P)
Liquidus entropy S_liq(P) [J/kg/K].
Source code in src/aragog/jax/eos.py
391 392 393 | |
liquidus_entropy_dP(P)
dS_liq/dP at the given pressure(s), in J/(kg·K·Pa).
Source code in src/aragog/jax/eos.py
404 405 406 | |
melt_fraction(P, S)
Melt fraction phi from position between solidus and liquidus.
phi = 0 for S <= S_sol, phi = 1 for S >= S_liq, linear between.
Source code in src/aragog/jax/eos.py
408 409 410 411 412 413 414 415 416 | |
solidus_entropy(P)
Solidus entropy S_sol(P) [J/kg/K].
Source code in src/aragog/jax/eos.py
387 388 389 | |
solidus_entropy_dP(P)
dS_sol/dP at the given pressure(s), in J/(kg·K·Pa).
Needed by the SPIDER-parity bracket Jmix in
aragog.jax.phase.compute_fluxes. Mirrors numpy
EntropyEOS.solidus_entropy_dP (entropy.py:377-388).
Source code in src/aragog/jax/eos.py
395 396 397 398 399 400 401 402 | |
temperature(P, S)
Temperature T(P, S) [K].
Source code in src/aragog/jax/eos.py
491 492 493 | |
thermal_expansivity(P, S)
Thermal expansivity alpha(P, S) [1/K].
Derived: alpha = rho * Cp * |dTdPs| / T.
Source code in src/aragog/jax/eos.py
552 553 554 555 556 557 558 559 560 561 | |
PhaseState
Bases: NamedTuple
Material properties at (P, S) following SPIDER eos_composite.c convention.
All scalar properties (T, rho, Cp, alpha, dTdPs, k) result from a
smth-blend between two-phase mixed values (analytical formulas at
the phase boundaries) and single table values (looked up at the
actual P and at S_sol or S_liq when mushy). This matches numpy
EntropyPhaseEvaluator._update_eos step-for-step.
aragog.jax.phase
Phase-aware property evaluation and flux assembly. evaluate_phase performs the SPIDER two-stage tanh blend at one cell; compute_fluxes is the pure-functional RHS that returns heat flux at basic nodes, internal heating at staggered nodes, eddy diffusivity, and capacitance.
phase
JAX phase evaluator and flux computation for the entropy solver.
Pure-functional replacements for entropy_phase.py (phase properties)
and entropy_state.py (MLT convection, heat/mass fluxes). All functions
are JIT-compilable and differentiable.
The numpy versions mutate state arrays in-place. The JAX versions take arrays in and return NamedTuples out, with no side effects.
Dependencies: jax, equinox (already in PROTEUS ecosystem via atmodeller).
PhaseParams(phi_rheo=0.4, phi_width=0.15, viscosity_solid=1e+21, viscosity_liquid=0.1, grain_size=0.001, k_solid=4.0, k_liquid=2.0, matprop_smooth_width=0.0, conduction=True, convection=True, grav_sep=False, mixing=False, eddy_diff_thermal=1.0, eddy_diff_chemical=1.0, kappah_floor=0.0, bottom_up_grav_sep=True, phase_smoothing='tanh', phase_smoothing_width=0.01)
Bases: Module
Static parameters for phase evaluation and flux computation.
Constructed once from config, passed as args to JIT-compiled
functions. All fields are scalars or 1D JAX arrays.
Source code in src/aragog/jax/phase.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | |
MeshArrays(d_dr_matrix, quantity_matrix, area, volume, radii_basic, mixing_length, mixing_length_sq, mixing_length_cu, radii_stag, P_stag, P_basic, gravity, dP_dr_basic=None, gravity_stag=None)
Bases: Module
Static mesh geometry arrays, converted from numpy Mesh once.
All arrays are 1D JAX arrays. The transform matrices are 2D.
from P_basic and radii_basic via numpy gradient (matches
entropy_state._dP_dr_basic = np.gradient(P_basic, r_basic)).
Source code in src/aragog/jax/phase.py
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 | |
from_numpy_mesh(mesh)
staticmethod
Build from a numpy Aragog Mesh object.
Source code in src/aragog/jax/phase.py
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 | |
PhaseProperties
FluxOutput
compute_fluxes(S_stag, time, eos, params, mesh, heating_rate, S_basic_cmb_override=None, dSdr_cmb_override=None)
Compute all heat and mass fluxes from the entropy profile.
This is the physics kernel called by the ODE RHS. It is a pure function: no mutation, no side effects, fully JIT-compilable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
S_stag
|
Array
|
Entropy at staggered nodes [J/kg/K]. |
required |
time
|
float
|
Current time [yr] (used for radionuclide heating). |
required |
eos
|
EntropyEOS_JAX
|
JAX EOS tables. |
required |
params
|
PhaseParams
|
Static material parameters and transport flags. |
required |
mesh
|
MeshArrays
|
Mesh geometry and transform matrices. |
required |
heating_rate
|
Array
|
Internal heating rate at staggered nodes [W/kg] (radionuclide + tidal, pre-computed by caller). |
required |
S_basic_cmb_override
|
float or None
|
Optional override for the entropy at the CMB basic node (basic-node index 0). Used by the energy_balance core BC which reconstructs S_basic[0] from the state-tracked dSdr_cmb via S[0] + dSdr_cmb * (r_basic[0] - r_stag[0]). When None, the standard quantity_matrix mapping is used. |
None
|
dSdr_cmb_override
|
float or None
|
Optional override for the entropy gradient at the CMB basic node (dSdr[0]). Used by the energy_balance core BC where dSdr_cmb is a state-tracked variable. When None, the standard d_dr_matrix mapping is used. |
None
|
Returns:
| Type | Description |
|---|---|
FluxOutput
|
Heat flux, mass flux, eddy diffusivity, heating. |
Source code in src/aragog/jax/phase.py
715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 | |
compute_mlt(dSdr, phase_basic, mesh, params)
Compute MLT eddy diffusivity from the entropy gradient.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dSdr
|
Array
|
Entropy gradient at basic nodes [J/kg/K/m]. |
required |
phase_basic
|
PhaseProperties
|
Material properties at basic nodes. |
required |
mesh
|
MeshArrays
|
Mesh geometry. |
required |
params
|
PhaseParams
|
Static parameters. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
kappa_h |
Array
|
Thermal eddy diffusivity at basic nodes [m^2/s]. |
kappa_c |
Array
|
Chemical eddy diffusivity at basic nodes [m^2/s]. |
Source code in src/aragog/jax/phase.py
589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 | |
evaluate_phase(eos, params, P, S)
Compute all material properties at (P, S) nodes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
eos
|
EntropyEOS_JAX
|
JAX EOS tables. |
required |
params
|
PhaseParams
|
Static material parameters. |
required |
P
|
Array
|
Pressure [Pa], 1D. |
required |
S
|
Array
|
Entropy [J/kg/K], 1D. |
required |
Returns:
| Type | Description |
|---|---|
PhaseProperties
|
All material properties at the given nodes. |
Source code in src/aragog/jax/phase.py
454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 | |
aragog.jax.solver
Standalone JAX solve path used by the verification suite. The production path uses CVODE driven by aragog.solver.entropy_solver and only borrows the Jacobian from jax.jacrev; this module's solve_entropy is kept for parity tests and gradient-based sensitivity studies.
solver
JAX ODE solver for the entropy equation (research-only).
Direct-JAX integration of the entropy equation via diffrax Kvaerno5 (5th-order ESDIRK, A-L stable). The RHS applies boundary conditions, computes flux divergence, and adds internal heating, all in pure JAX.
Not production-ready: the diffrax ESDIRK solvers (kvaerno3, kvaerno5)
stall at the first crystallisation step on the cubic-Hermite J_grav
smoothing in coupled Earth-mantle runs. Kept for autodiff development. The
production JAX integration path is the CVODE Option-Z path in
aragog/solver/cvode_jax.py, selected by setting
EnergyParams.use_jax_jacobian = True (PROTEUS-side
backend="jax"), which uses CVODE for time stepping and JAX only
for the analytic Jacobian.
Dependencies: jax, equinox, diffrax, lineax (transitive via diffrax).
BoundaryParams(*, outer_bc_type, outer_bc_value, emissivity, T_eq, inner_bc_type, inner_bc_value, core_density, core_heat_capacity, tfac_core_avg, cmb_area=0.0, core_M=0.0, cmb_dr_cmb=0.0, param_utbl=False, param_utbl_const=0.0)
Bases: Module
Boundary condition configuration as a JAX pytree.
Surface BC types: 1 = grey-body (F = emissivity * sigma * (T^4 - T_eq^4)) 4 = prescribed flux (from atmosphere module)
CMB BC types:
0 = insulating (F = 0)
1 = core cooling (Bower+2018 Eq. 37)
2 = prescribed flux
3 = prescribed temperature (preserve conduction-derived flux)
5 = energy_balance (SPIDER bit-parity): F_cmb derived from
the boundary entropy gradient (state-tracked dSdr_cmb).
Used by dSdt_energy_balance.
All float fields are stored as JAX arrays (not Python floats) to avoid JIT recompilation when values change between coupling steps.
Energy-balance constants are optional (default 0); only used when
inner_bc_type == 5 via dSdt_energy_balance.
Source code in src/aragog/jax/solver.py
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | |
SolveResult
aragog.jax.nondim
Reference scales used internally to non-dimensionalise the state vector and time before they enter the integrator. The triplet (state_scale, rhs_scale, t_ref) is built from EntropySolver._S_ref, _dSdr_ref, and _t_ref_yr; it is not user-configurable.
nondim
Nondimensional scaling spec shared by the numpy and JAX RHS paths.
Single source of truth for the (state_scale, rhs_scale, t_ref) triplet that scales physical-units state into the BDF integrator's O(1) work space. Built once by the EntropySolver, consumed by both the scipy/CVODE wrapper (entropy_solver.py) and the JAX CVODE factory (cvode_jax.py).
Internal contract enforced by __post_init__:
rhs_scale = t_ref / state_scale (per component)
state_scale > 0, rhs_scale > 0, t_ref > 0
state_scale.shape == rhs_scale.shape
By construction, every NonDimScales instance enforces the internal
contract (rhs_scale = t_ref / state_scale, all positive, shapes
matching) inside its __post_init__ before any caller can use it. The
two callers that consume an instance --- the scipy/CVODE wrapper in
entropy_solver.py and the JAX CVODE factory in cvode_jax.py ---
therefore do NOT need to re-check those invariants on entry.
NonDimScales(state_scale, t_ref, rhs_scale=None)
dataclass
Per-component nondim scales for the entropy solver state vector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state_scale
|
(ndarray, shape(n))
|
Physical-units scale per state component:
|
required |
t_ref
|
float
|
Time scale: |
required |
rhs_scale
|
(ndarray, shape(n) or None)
|
Optional precomputed RHS scale |
None
|
n
property
Number of state-vector components.