ExoGibbs 0.2.2__tar.gz → 0.2.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. {exogibbs-0.2.2 → exogibbs-0.2.3}/MANIFEST.in +1 -2
  2. {exogibbs-0.2.2/src/exogibbs.egg-info → exogibbs-0.2.3}/PKG-INFO +1 -1
  3. exogibbs-0.2.3/documents/_static/exogibbs_logo.png +0 -0
  4. {exogibbs-0.2.2 → exogibbs-0.2.3}/documents/conf.py +1 -1
  5. exogibbs-0.2.3/documents/exogibbs/conf.py +36 -0
  6. exogibbs-0.2.3/documents/index.rst +47 -0
  7. exogibbs-0.2.3/documents/presets/ykb4.rst +196 -0
  8. exogibbs-0.2.3/examples/benchmark/clfac_yk.py +73 -0
  9. {exogibbs-0.2.2 → exogibbs-0.2.3}/examples/comparisons/comparison_with_ykcode.py +27 -8
  10. exogibbs-0.2.3/examples/layers/layer_ykb4.py +44 -0
  11. {exogibbs-0.2.2 → exogibbs-0.2.3}/src/exogibbs/api/chemistry.py +2 -2
  12. {exogibbs-0.2.2 → exogibbs-0.2.3}/src/exogibbs/api/equilibrium.py +63 -2
  13. exogibbs-0.2.3/src/exogibbs/exogibbs_version.py +1 -0
  14. {exogibbs-0.2.2 → exogibbs-0.2.3}/src/exogibbs/optimize/minimize.py +61 -80
  15. {exogibbs-0.2.2 → exogibbs-0.2.3}/src/exogibbs/presets/ykb4.py +22 -11
  16. {exogibbs-0.2.2 → exogibbs-0.2.3}/src/exogibbs/thermo/stoichiometry.py +2 -2
  17. {exogibbs-0.2.2 → exogibbs-0.2.3/src/exogibbs.egg-info}/PKG-INFO +1 -1
  18. {exogibbs-0.2.2 → exogibbs-0.2.3}/src/exogibbs.egg-info/SOURCES.txt +6 -1
  19. {exogibbs-0.2.2 → exogibbs-0.2.3}/tests/unittests/api/chemsetup_smoke_test.py +1 -1
  20. {exogibbs-0.2.2 → exogibbs-0.2.3}/tests/unittests/api/equilibrium_api_test.py +2 -2
  21. exogibbs-0.2.3/tests/unittests/api/equilibrium_profile_test.py +61 -0
  22. exogibbs-0.2.2/examples/benchmark/clfac_yk.py +0 -61
  23. exogibbs-0.2.2/src/exogibbs/data/number_of_species.sample.list +0 -1
  24. exogibbs-0.2.2/src/exogibbs/exogibbs_version.py +0 -1
  25. {exogibbs-0.2.2 → exogibbs-0.2.3}/.github/workflows/main.yml +0 -0
  26. {exogibbs-0.2.2 → exogibbs-0.2.3}/.gitignore +0 -0
  27. {exogibbs-0.2.2 → exogibbs-0.2.3}/AGENTS.md +0 -0
  28. {exogibbs-0.2.2 → exogibbs-0.2.3}/CLAUDE.md +0 -0
  29. {exogibbs-0.2.2 → exogibbs-0.2.3}/LICENSE +0 -0
  30. {exogibbs-0.2.2 → exogibbs-0.2.3}/README.md +0 -0
  31. {exogibbs-0.2.2 → exogibbs-0.2.3}/documents/Makefile +0 -0
  32. {exogibbs-0.2.2 → exogibbs-0.2.3}/documents/ipynb/chemical_potential.ipynb +0 -0
  33. {exogibbs-0.2.2 → exogibbs-0.2.3}/documents/ipynb/tce_two_species.ipynb +0 -0
  34. {exogibbs-0.2.2 → exogibbs-0.2.3}/examples/GALLERY_HEADER.rst +0 -0
  35. {exogibbs-0.2.2 → exogibbs-0.2.3}/examples/comparisons/comparison_with_hcosystem.py +0 -0
  36. {exogibbs-0.2.2 → exogibbs-0.2.3}/examples/comparisons/comparison_with_hsystem.py +0 -0
  37. {exogibbs-0.2.2 → exogibbs-0.2.3}/examples/data/p10.txt +0 -0
  38. {exogibbs-0.2.2 → exogibbs-0.2.3}/examples/data/yk.list +0 -0
  39. {exogibbs-0.2.2 → exogibbs-0.2.3}/examples/numpyro/example_nuts.py +0 -0
  40. {exogibbs-0.2.2 → exogibbs-0.2.3}/pyproject.toml +0 -0
  41. {exogibbs-0.2.2 → exogibbs-0.2.3}/results/README.md +0 -0
  42. {exogibbs-0.2.2 → exogibbs-0.2.3}/setup.cfg +0 -0
  43. {exogibbs-0.2.2 → exogibbs-0.2.3}/src/exogibbs/ExoGibbs_version.py +0 -0
  44. {exogibbs-0.2.2 → exogibbs-0.2.3}/src/exogibbs/__init__.py +0 -0
  45. {exogibbs-0.2.2 → exogibbs-0.2.3}/src/exogibbs/api/__init__.py +0 -0
  46. {exogibbs-0.2.2 → exogibbs-0.2.3}/src/exogibbs/data/gibbs_matrices.npz +0 -0
  47. {exogibbs-0.2.2 → exogibbs-0.2.3}/src/exogibbs/data/janaf_raw_sample.txt +0 -0
  48. {exogibbs-0.2.2 → exogibbs-0.2.3}/src/exogibbs/data/matrix_v3.dat +0 -0
  49. {exogibbs-0.2.2 → exogibbs-0.2.3}/src/exogibbs/data/molecule_names.csv +0 -0
  50. {exogibbs-0.2.2 → exogibbs-0.2.3}/src/exogibbs/data/testdata.dat +0 -0
  51. {exogibbs-0.2.2 → exogibbs-0.2.3}/src/exogibbs/equilibrium/__init__.py +0 -0
  52. {exogibbs-0.2.2 → exogibbs-0.2.3}/src/exogibbs/equilibrium/gibbs.py +0 -0
  53. {exogibbs-0.2.2 → exogibbs-0.2.3}/src/exogibbs/io/__init__.py +0 -0
  54. {exogibbs-0.2.2 → exogibbs-0.2.3}/src/exogibbs/io/load_data.py +0 -0
  55. {exogibbs-0.2.2 → exogibbs-0.2.3}/src/exogibbs/optimize/__init__.py +0 -0
  56. {exogibbs-0.2.2 → exogibbs-0.2.3}/src/exogibbs/optimize/core.py +0 -0
  57. {exogibbs-0.2.2 → exogibbs-0.2.3}/src/exogibbs/optimize/vjpgibbs.py +0 -0
  58. {exogibbs-0.2.2 → exogibbs-0.2.3}/src/exogibbs/presets/__init__.py +0 -0
  59. {exogibbs-0.2.2 → exogibbs-0.2.3}/src/exogibbs/test/__init__.py +0 -0
  60. {exogibbs-0.2.2 → exogibbs-0.2.3}/src/exogibbs/test/analytic_hcosystem.py +0 -0
  61. {exogibbs-0.2.2 → exogibbs-0.2.3}/src/exogibbs/test/analytic_hsystem.py +0 -0
  62. {exogibbs-0.2.2 → exogibbs-0.2.3}/src/exogibbs/test/generate_gibbs.py +0 -0
  63. {exogibbs-0.2.2 → exogibbs-0.2.3}/src/exogibbs/test/reference_data.py +0 -0
  64. {exogibbs-0.2.2 → exogibbs-0.2.3}/src/exogibbs/thermo/__init__.py +0 -0
  65. {exogibbs-0.2.2 → exogibbs-0.2.3}/src/exogibbs/thermo/providers.py +0 -0
  66. {exogibbs-0.2.2 → exogibbs-0.2.3}/src/exogibbs/utils/__init__.py +0 -0
  67. {exogibbs-0.2.2 → exogibbs-0.2.3}/src/exogibbs/utils/constants.py +0 -0
  68. {exogibbs-0.2.2 → exogibbs-0.2.3}/src/exogibbs.egg-info/dependency_links.txt +0 -0
  69. {exogibbs-0.2.2 → exogibbs-0.2.3}/src/exogibbs.egg-info/requires.txt +0 -0
  70. {exogibbs-0.2.2 → exogibbs-0.2.3}/src/exogibbs.egg-info/top_level.txt +0 -0
  71. {exogibbs-0.2.2 → exogibbs-0.2.3}/tests/unittests/equilibrium/gibbs_test.py +0 -0
  72. {exogibbs-0.2.2 → exogibbs-0.2.3}/tests/unittests/io/formula_matrix_reference_vs_computed_test.py +0 -0
  73. {exogibbs-0.2.2 → exogibbs-0.2.3}/tests/unittests/io/load_data_test.py +0 -0
  74. {exogibbs-0.2.2 → exogibbs-0.2.3}/tests/unittests/optimize/lagrange/hcosystem_test.py +0 -0
  75. {exogibbs-0.2.2 → exogibbs-0.2.3}/tests/unittests/optimize/lagrange/lagrange_test.py +0 -0
  76. {exogibbs-0.2.2 → exogibbs-0.2.3}/tests/unittests/optimize/lagrange/minimize_test.py +0 -0
  77. {exogibbs-0.2.2 → exogibbs-0.2.3}/tests/unittests/optimize/lagrange/minimize_vmap_test.py +0 -0
@@ -2,5 +2,4 @@ include src/exogibbs/data/janaf_raw_sample.txt
2
2
  include src/exogibbs/data/testdata.dat
3
3
  include src/exogibbs/data/matrix_v3.dat
4
4
  include src/exogibbs/data/molecule_names.csv
5
- include src/exogibbs/data/gibbs_matrices.npz
6
- include src/exogibbs/data/number_of_species.sample.list
5
+ include src/exogibbs/data/gibbs_matrices.npz
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: exogibbs
3
- Version: 0.2.2
3
+ Version: 0.2.3
4
4
  Summary: Differentiable Thermochemical Equilibrium Solver for Exoplanet Atmospheres
5
5
  Author-email: Hajime Kawahara <divrot@gmail.com>
6
6
  Maintainer-email: Hajime Kawahara <divrot@gmail.com>
@@ -58,7 +58,7 @@ html_theme = "sphinx_rtd_theme"
58
58
  # relative to this directory. They are copied after the builtin static files,
59
59
  # so a file named "default.css" will overwrite the builtin "default.css".
60
60
  html_static_path = ["_static"]
61
- html_logo = "_static/logo.png"
61
+ html_logo = "_static/exogibbs_logo.png"
62
62
 
63
63
  # html_theme_options = {
64
64
  # 'style_nav_header_background': '#333',
@@ -0,0 +1,36 @@
1
+ # Configuration file for the Sphinx documentation builder.
2
+ #
3
+ # For the full list of built-in configuration values, see the documentation:
4
+ # https://www.sphinx-doc.org/en/master/usage/configuration.html
5
+
6
+ # -- Project information -----------------------------------------------------
7
+ # https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
8
+
9
+ project = 'exogibbs'
10
+ copyright = '2025, Author'
11
+ author = 'Author'
12
+
13
+ # -- General configuration ---------------------------------------------------
14
+ # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
15
+
16
+ extensions = [
17
+ 'sphinx.ext.autodoc',
18
+ 'sphinx.ext.viewcode',
19
+ 'sphinx.ext.todo',
20
+ ]
21
+
22
+ templates_path = ['_templates']
23
+ exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
24
+
25
+ language = 'en'
26
+
27
+ # -- Options for HTML output -------------------------------------------------
28
+ # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
29
+
30
+ html_theme = 'alabaster'
31
+ html_static_path = ['_static']
32
+
33
+ # -- Options for todo extension ----------------------------------------------
34
+ # https://www.sphinx-doc.org/en/master/usage/extensions/todo.html#configuration
35
+
36
+ todo_include_todos = True
@@ -0,0 +1,47 @@
1
+ .. exojax documentation master file, created by
2
+ sphinx-quickstart on Mon Jan 11 14:38:51 2021.
3
+ You can adapt this file completely to your liking, but it should at least
4
+ contain the root `toctree` directive.
5
+
6
+ ExoGibbs
7
+ ==================================
8
+
9
+ Version 0.2
10
+
11
+ |:frog:| `DeepWiki for ExoGibbs <https://deepwiki.com/HajimeKawahara/exogibbs>`_
12
+
13
+
14
+ `ExoGibbs <https://github.com/HajimeKawahara/exogibbs>`_ provides an auto-differentiable thermalchemical equilibrium solver
15
+ based on the Gibbs free energy minimization method, powered by `JAX <https://github.com/google/jax>`_.
16
+
17
+
18
+ Contents
19
+ ==================================
20
+
21
+ .. toctree::
22
+ :maxdepth: 2
23
+ :caption: PRESETS:
24
+
25
+ presets/ykb4.rst
26
+
27
+
28
+ .. toctree::
29
+ :maxdepth: 1
30
+ :caption: API:
31
+
32
+ exogibbs/exogibbs.rst
33
+
34
+
35
+
36
+
37
+ License & Attribution
38
+ ---------------------
39
+
40
+ Copyright 2025-, Contributors
41
+
42
+ - `Hajime Kawahara <http://secondearths.sakura.ne.jp/en/index.html>`_ (@HajimeKawahara, maintainer)
43
+ - `Yui Kawashima <https://sites.google.com/view/yuikawashima/home>`_ (@ykawashima, the reference code author we inherit, the presets ykb4 originally comes from this code.)
44
+ -
45
+
46
+ ExoGibbs is free software made available under the MIT License.
47
+
@@ -0,0 +1,196 @@
1
+ YKB4 Preset
2
+ ===========
3
+
4
+ Overview
5
+ --------
6
+ The ykb4 preset bundles a ready-to-use ChemicalSetup based on JANAF-like
7
+ Gibbs tables. It exposes a device-friendly stoichiometric matrix and a
8
+ JAX-differentiable h(T) interpolator for equilibrium calculations.
9
+
10
+ Quick Start
11
+ -----------
12
+ .. code-block:: python
13
+
14
+ from exogibbs.presets.ykb4 import prepare_ykb4_setup
15
+ from exogibbs.api.equilibrium import equilibrium
16
+
17
+ setup = prepare_ykb4_setup()
18
+ T, P = 1500.0, 1.0 # K, bar
19
+ b = setup.b_element_vector_reference # or your own jnp.array([...])
20
+ result = equilibrium(setup, T=T, P=P, b=b)
21
+ print(result.x) # mole fractions (K,)
22
+
23
+ Elements
24
+ --------
25
+ The following elements are included in this preset (including electrons as "e-"):
26
+
27
+ ``C, H, He, K, N, Na, O, P, S, Ti, V, e-``
28
+
29
+ The reference elemental abundances (`b_element_vector_ref`) are taken from Asplund, Amarsi & Grevesse (2021).
30
+
31
+ Species (JANAF key)
32
+ -------------------
33
+ The species list corresponds to the ``JANAF`` column in ``molecule_names.csv``.
34
+
35
+ .. code-block:: text
36
+
37
+ 000: C1
38
+ 001: H2
39
+ 002: He1
40
+ 003: K1
41
+ 004: N2
42
+ 005: Na1
43
+ 006: O2
44
+ 007: Ti1
45
+ 008: V1
46
+ 009: P1
47
+ 010: S1
48
+ 011: e1-
49
+ 012: C1H1
50
+ 013: C1H1N1
51
+ 014: C1H1N1O1
52
+ 015: C1H1O1
53
+ 016: C1H2
54
+ 017: C1H2O1
55
+ 018: C1H3
56
+ 019: C1H4
57
+ 020: C1K1N1
58
+ 021: C1N1
59
+ 022: C1N1Na1
60
+ 023: C1N1O1
61
+ 024: C1N2(CNN)
62
+ 025: C1N2(NCN)
63
+ 026: C1O1
64
+ 027: C1O2
65
+ 028: C2
66
+ 029: C2H1
67
+ 030: C2H2
68
+ 031: C2H4
69
+ 032: C2H4O1
70
+ 033: C2K2N2
71
+ 034: C2N1
72
+ 035: C2N2
73
+ 036: C2N2Na2
74
+ 037: C2O1
75
+ 038: C3
76
+ 039: C3O2
77
+ 040: C4
78
+ 041: C4N2
79
+ 042: C5
80
+ 043: H1
81
+ 044: H1K1
82
+ 045: H1K1O1
83
+ 046: H1N1
84
+ 047: H1N1O1
85
+ 048: H1N1O2(cis)
86
+ 049: H1N1O2(trans)
87
+ 050: H1N1O3
88
+ 051: H1Na1
89
+ 052: H1Na1O1
90
+ 053: H1O1
91
+ 054: H1O2
92
+ 055: H2K2O2
93
+ 056: H2N1
94
+ 057: H2N2
95
+ 058: H2Na2O2
96
+ 059: H2O1
97
+ 060: H2O2
98
+ 061: H3N1
99
+ 062: H4N2
100
+ 063: K1O1
101
+ 064: K2
102
+ 065: N1
103
+ 066: N1O1
104
+ 067: N1O2
105
+ 068: N1O3
106
+ 069: N2O1
107
+ 070: N2O3
108
+ 071: N2O4
109
+ 072: N2O5
110
+ 073: N3
111
+ 074: Na1O1
112
+ 075: Na2
113
+ 076: O1
114
+ 077: O3
115
+ 078: N1V1
116
+ 079: O1Ti1
117
+ 080: O1V1
118
+ 081: O2Ti1
119
+ 082: O2V1
120
+ 083: C1H1P1
121
+ 084: C1O1S1
122
+ 085: C1P1
123
+ 086: C1S1
124
+ 087: C1S2
125
+ 088: H1P1
126
+ 089: H1S1
127
+ 090: H2O4S1
128
+ 091: H2P1
129
+ 092: H2S1
130
+ 093: H3P1
131
+ 094: K2O4S1
132
+ 095: N1P1
133
+ 096: N1S1
134
+ 097: Na2O4S1
135
+ 098: O1P1
136
+ 099: O1S1
137
+ 100: O1S2
138
+ 101: O2P1
139
+ 102: O2S1
140
+ 103: O3S1
141
+ 104: O6P4
142
+ 105: O10P4
143
+ 106: P1S1
144
+ 107: P2
145
+ 108: P4
146
+ 109: P4S3
147
+ 110: S2
148
+ 111: S3
149
+ 112: S4
150
+ 113: S5
151
+ 114: S6
152
+ 115: S7
153
+ 116: S8
154
+ 117: C1+
155
+ 118: C1-
156
+ 119: C1H1+
157
+ 120: C1H1O1+
158
+ 121: C1N1+
159
+ 122: C1N1-
160
+ 123: C1O2-
161
+ 124: C2-
162
+ 125: H1+
163
+ 126: H1-
164
+ 127: H1K1O1+
165
+ 128: H1Na1O1+
166
+ 129: H1O1+
167
+ 130: H1O1-
168
+ 131: H2+
169
+ 132: H2-
170
+ 133: H3O1+
171
+ 134: He1+
172
+ 135: K1+
173
+ 136: K1-
174
+ 137: K1O1-
175
+ 138: N1+
176
+ 139: N1-
177
+ 140: N1O1+
178
+ 141: N1O2-
179
+ 142: N2+
180
+ 143: N2-
181
+ 144: N2O1+
182
+ 145: Na1+
183
+ 146: Na1-
184
+ 147: Na1O1-
185
+ 148: O1+
186
+ 149: O1-
187
+ 150: O2+
188
+ 151: O2-
189
+ 152: P1+
190
+ 153: P1-
191
+ 154: S1+
192
+ 155: S1-
193
+ 156: Ti1+
194
+ 157: Ti1-
195
+ 158: V1+
196
+ 159: V1-
@@ -0,0 +1,73 @@
1
+ """
2
+ Validation of Gibbs Minimization Against ykawashima's B4 code
3
+ ============================================================
4
+
5
+ This example demonstrates and validates the ExoGibbs thermochemical equilibrium
6
+ solver against the code by ykawashima when she was at B4.
7
+
8
+ Updated to use the high-level API: exogibbs.api.equilibrium.equilibrium.
9
+ """
10
+ from exogibbs.presets.ykb4 import prepare_ykb4_setup
11
+ import jax.numpy as jnp
12
+ from exogibbs.api.chemistry import ThermoState
13
+ from exogibbs.optimize.minimize import minimize_gibbs_core
14
+
15
+ from exogibbs.optimize.core import compute_ln_normalized_pressure
16
+
17
+ from jax import config
18
+
19
+ config.update("jax_enable_x64", True)
20
+
21
+ #chemical setup
22
+ chem = prepare_ykb4_setup()
23
+
24
+ # Thermodynamic conditions
25
+ temperature = 500.0 # K
26
+ P = 10.0 # bar
27
+ Pref = 1.0 # bar, reference pressure
28
+ ln_normalized_pressure = compute_ln_normalized_pressure(P, Pref)
29
+
30
+ # Initial guess for log number densities
31
+ ln_nk = jnp.zeros(chem.formula_matrix.shape[1]) # log(n_species)
32
+ ln_ntot = 0.0 # log(total number density)
33
+
34
+ # old reference elemental abundance b from yk's sample number densities
35
+ b_old_ref = jnp.array(
36
+ [
37
+ 4.8774824e-04,
38
+ 1.6749767e00,
39
+ 1.6143440e-01,
40
+ 2.5438149e-07,
41
+ 1.3435642e-04,
42
+ 3.9624806e-06,
43
+ 9.7356725e-04,
44
+ 5.7690579e-07,
45
+ 3.0653933e-05,
46
+ 1.6687756e-07,
47
+ 1.9870969e-08,
48
+ 0.0000000e00,
49
+ ]
50
+ )
51
+ # ThermoState instance
52
+ thermo_state = ThermoState(
53
+ temperature=temperature,
54
+ ln_normalized_pressure=ln_normalized_pressure,
55
+ b_element_vector=b_old_ref,
56
+ )
57
+
58
+ # Convergence criteria
59
+ epsilon_crit = 1e-11
60
+ max_iter = 1000
61
+
62
+ ln_nk_result, _, icount = minimize_gibbs_core(
63
+ thermo_state,
64
+ ln_nk,
65
+ ln_ntot,
66
+ chem.formula_matrix,
67
+ chem.hvector_func,
68
+ epsilon_crit=epsilon_crit,
69
+ max_iter=max_iter,
70
+ )
71
+ nk_result = jnp.exp(ln_nk_result)
72
+ print("icount", icount)
73
+ #702 for clfac = 0.1, 347 for _cea_lambda
@@ -11,7 +11,7 @@ Updated to use the high-level API: exogibbs.api.equilibrium.equilibrium.
11
11
  from exogibbs.presets.ykb4 import prepare_ykb4_setup
12
12
  from exogibbs.api.equilibrium import equilibrium, EquilibriumOptions
13
13
  import numpy as np
14
-
14
+ import jax.numpy as jnp
15
15
  from jax import config
16
16
 
17
17
  config.update("jax_enable_x64", True)
@@ -22,9 +22,28 @@ temperature = 500.0 # K
22
22
  P = 10.0 # bar
23
23
  Pref = 1.0 # bar, reference pressure
24
24
 
25
- #chemical setup
25
+ # chemical setup
26
26
  chem = prepare_ykb4_setup()
27
27
 
28
+ # old reference elemental abundance b from yk's sample number densities
29
+ b_old_ref = jnp.array(
30
+ [
31
+ 4.8774824e-04,
32
+ 1.6749767e00,
33
+ 1.6143440e-01,
34
+ 2.5438149e-07,
35
+ 1.3435642e-04,
36
+ 3.9624806e-06,
37
+ 9.7356725e-04,
38
+ 5.7690579e-07,
39
+ 3.0653933e-05,
40
+ 1.6687756e-07,
41
+ 1.9870969e-08,
42
+ 0.0000000e00,
43
+ ]
44
+ )
45
+
46
+
28
47
  ##############################################################################
29
48
  # Solve equilibrium via high-level API
30
49
  # ------------------------------------
@@ -33,7 +52,7 @@ res = equilibrium(
33
52
  chem,
34
53
  T=temperature,
35
54
  P=P,
36
- b=chem.b_element_vector_reference,
55
+ b=b_old_ref,
37
56
  Pref=Pref,
38
57
  options=opts,
39
58
  )
@@ -43,21 +62,22 @@ nk_result = res.n
43
62
 
44
63
  # load yk's results for 10 bar
45
64
  dat = np.loadtxt("../data/p10.txt", delimiter=",")
46
- mask = dat > 1.e-14
65
+ mask = dat > 1.0e-14
47
66
  mask_nk_result = nk_result[mask]
48
67
  mask_dat = dat[mask]
49
68
 
50
- res = mask_nk_result/mask_dat - 1.0
51
- print(res,"diff for n>1.e-14")
69
+ res = mask_nk_result / mask_dat - 1.0
70
+ print(res, "diff for n>1.e-14")
52
71
  assert np.max(np.abs(res)) < 0.051
53
72
  # 8/9/2025
54
- #[-0.00163185 -0.00163185 0.02571018 -0.00203837 -0.05069541 -0.00163185
73
+ # [-0.00163185 -0.00163185 0.02571018 -0.00203837 -0.05069541 -0.00163185
55
74
  # -0.00481986 -0.00420364 -0.00161074 -0.00163182 -0.00163185 -0.00163183
56
75
  # -0.00163184 -0.00163178 -0.00163185 -0.00163184]
57
76
 
58
77
 
59
78
  ind = np.arange(len(nk_result))
60
79
  import matplotlib.pyplot as plt
80
+
61
81
  plt.plot(ind, nk_result, "+", label="ExoGibbs")
62
82
  plt.plot(ind, dat, ".", alpha=0.5, label="yk B4 code")
63
83
  plt.xlabel("Species Index")
@@ -66,4 +86,3 @@ plt.yscale("log")
66
86
  plt.legend()
67
87
  plt.grid()
68
88
  plt.show()
69
-
@@ -0,0 +1,44 @@
1
+ """
2
+ Validation of Gibbs Minimization for Layered Systems
3
+ ===================================================================================
4
+
5
+ This example demonstrates and validates the ExoGibbs thermochemical equilibrium for the layered system
6
+
7
+ Updated to use the high-level API: exogibbs.api.equilibrium.equilibrium.
8
+ """
9
+
10
+ from exogibbs.presets.ykb4 import prepare_ykb4_setup
11
+ from exogibbs.api.equilibrium import equilibrium_profile, EquilibriumOptions
12
+ import numpy as np
13
+ import jax.numpy as jnp
14
+ from jax import config
15
+
16
+ config.update("jax_enable_x64", True)
17
+
18
+
19
+ # Thermodynamic conditions
20
+ Pref = 1.0 # bar, reference pressure
21
+ Parr = jnp.logspace(-8, 2, 10)/Pref # bar
22
+ Tarr = 1500*Parr**0.1
23
+
24
+
25
+ #chemical setup
26
+ chem = prepare_ykb4_setup()
27
+
28
+ ##############################################################################
29
+ # Solve equilibrium via high-level API
30
+ # ------------------------------------
31
+ opts = EquilibriumOptions(epsilon_crit=1e-11, max_iter=1000)
32
+
33
+ res = equilibrium_profile(
34
+ chem,
35
+ Tarr,
36
+ Parr,
37
+ chem.b_element_vector_reference,
38
+ Pref=Pref,
39
+ options=opts,
40
+ )
41
+
42
+ ##############################################################################
43
+ nk_result = res.n
44
+ print(nk_result)
@@ -46,7 +46,7 @@ class ChemicalSetup:
46
46
  hvector_func : Callable[[float|Array], Array]
47
47
  h(T) used by the optimizer (JAX-differentiable).
48
48
 
49
- elems : Optional[tuple[str, ...]]
49
+ elements : Optional[tuple[str, ...]]
50
50
  Element symbols (E,) if available.
51
51
  species : Optional[tuple[str, ...]]
52
52
  Species names (K,) if available.
@@ -59,7 +59,7 @@ class ChemicalSetup:
59
59
  hvector_func: Callable[[Union[float, Array]], Array]
60
60
 
61
61
  # Optional metadata (host-side; NOT traced)
62
- elems: Optional[Tuple[str, ...]] = None
62
+ elements: Optional[Tuple[str, ...]] = None
63
63
  species: Optional[Tuple[str, ...]] = None
64
64
  b_element_vector_reference: Optional["np.ndarray"] = None # host-side
65
65
  metadata: Optional[Mapping[str, str]] = None
@@ -60,7 +60,9 @@ class EquilibriumResult:
60
60
 
61
61
  # Make this dataclass a JAX pytree (so vmap/jit can pass it around)
62
62
  def tree_flatten(self):
63
- children = (self.ln_n, self.n, self.x, jnp.asarray(self.ntot))
63
+ # Avoid coercing to jnp.asarray here to keep compatibility with
64
+ # transformation-time abstract values (e.g., vmap/jit tracing).
65
+ children = (self.ln_n, self.n, self.x, self.ntot)
64
66
  aux = (self.iterations, self.metadata)
65
67
  return children, aux
66
68
 
@@ -148,4 +150,63 @@ def equilibrium(
148
150
  ln_n=ln_n, n=n, x=x, ntot=ntot, iterations=None, metadata=None
149
151
  )
150
152
 
151
- __all__ = ["equilibrium", "EquilibriumOptions", "EquilibriumInit", "EquilibriumResult"]
153
+ def equilibrium_profile(
154
+ setup: ChemicalSetup,
155
+ T: Array,
156
+ P: Array,
157
+ b: Array,
158
+ *,
159
+ Pref: float = 1.0,
160
+ options: Optional[EquilibriumOptions] = None,
161
+ ) -> EquilibriumResult:
162
+ """Vectorized equilibrium along a 1D T/P profile (layers).
163
+
164
+ This computes equilibrium independently for each (T[i], P[i]) pair while
165
+ keeping the elemental abundances ``b`` fixed across layers.
166
+
167
+ Args:
168
+ setup: ChemicalSetup with formula matrix and hvector_func(T).
169
+ T: Temperatures, shape (N,).
170
+ P: Pressures, shape (N,).
171
+ b: Elemental abundances, shape (E,), shared across layers.
172
+ Pref: Reference pressure (bar).
173
+ options: Solver options.
174
+
175
+ Returns:
176
+ Batched EquilibriumResult with fields stacked over the leading dimension N:
177
+ - ln_n: (N, K)
178
+ - n: (N, K)
179
+ - x: (N, K)
180
+ - ntot: (N,)
181
+ """
182
+ T = jnp.asarray(T)
183
+ P = jnp.asarray(P)
184
+ if T.ndim != 1 or P.ndim != 1:
185
+ raise ValueError("T and P must be 1D arrays of equal length.")
186
+ if T.shape[0] != P.shape[0]:
187
+ raise ValueError("T and P must have the same length.")
188
+ if b.ndim != 1:
189
+ raise ValueError("b must be a 1D array shared across layers.")
190
+
191
+ # Vectorize over T and P; keep setup and b static. Pass Pref/options as kwargs.
192
+ layer_fn = jax.vmap(
193
+ lambda Ti, Pi: equilibrium(
194
+ setup,
195
+ Ti,
196
+ Pi,
197
+ b,
198
+ Pref=Pref,
199
+ options=options,
200
+ ),
201
+ in_axes=(0, 0),
202
+ )
203
+ return layer_fn(T, P)
204
+
205
+
206
+ __all__ = [
207
+ "equilibrium",
208
+ "equilibrium_profile",
209
+ "EquilibriumOptions",
210
+ "EquilibriumInit",
211
+ "EquilibriumResult",
212
+ ]
@@ -0,0 +1 @@
1
+ __version__ = "0.2.3"
@@ -191,7 +191,9 @@ def minimize_gibbs_core(
191
191
  return ln_nk, ln_tot, counter
192
192
 
193
193
 
194
- @partial(custom_vjp, nondiff_argnums=(1, 2, 3, 4, 5, 6))
194
+ # Only function and scalar options are non-differentiable.
195
+ # Array-valued args (init vectors, matrices) must NOT be in nondiff_argnums
196
+ # to avoid UnexpectedTracerError under vmap/jit.
195
197
  def minimize_gibbs(
196
198
  state: ThermoState,
197
199
  ln_nk_init: jnp.ndarray,
@@ -215,87 +217,66 @@ def minimize_gibbs(
215
217
  Returns:
216
218
  Final log number of species vector (n_species,).
217
219
  """
220
+ # Define an inner custom_vjp function that captures static arrays
221
+ # (ln_nk_init, ln_ntot_init, formula_matrix) to avoid passing them as
222
+ # arguments, which can become JAX Tracers under vmap/jit.
223
+ @custom_vjp
224
+ def _solve(inner_state: ThermoState) -> jnp.ndarray:
225
+ ln_nk, _, _ = minimize_gibbs_core(
226
+ inner_state,
227
+ ln_nk_init,
228
+ ln_ntot_init,
229
+ formula_matrix,
230
+ hvector_func,
231
+ epsilon_crit,
232
+ max_iter,
233
+ )
234
+ return ln_nk
218
235
 
219
- ln_nk, _, _ = minimize_gibbs_core(
220
- state,
221
- ln_nk_init,
222
- ln_ntot_init,
223
- formula_matrix,
224
- hvector_func,
225
- epsilon_crit,
226
- max_iter,
227
- )
228
-
229
- return ln_nk
230
-
231
-
232
- def minimize_gibbs_fwd(
233
- state,
234
- ln_nk_init,
235
- ln_ntot_init,
236
- formula_matrix,
237
- hvector_func,
238
- epsilon_crit=1.0e-11,
239
- max_iter=1000,
240
- ):
241
- ln_nk, ln_ntot, _ = minimize_gibbs_core(
242
- state,
243
- ln_nk_init,
244
- ln_ntot_init,
245
- formula_matrix,
246
- hvector_func,
247
- epsilon_crit,
248
- max_iter,
249
- )
250
- dfunc = jacrev(hvector_func)
251
- hdot = dfunc(state.temperature)
236
+ def _solve_fwd(inner_state: ThermoState):
237
+ ln_nk, ln_ntot, _ = minimize_gibbs_core(
238
+ inner_state,
239
+ ln_nk_init,
240
+ ln_ntot_init,
241
+ formula_matrix,
242
+ hvector_func,
243
+ epsilon_crit,
244
+ max_iter,
245
+ )
246
+ dfunc = jacrev(hvector_func)
247
+ hdot = dfunc(inner_state.temperature)
248
+ residuals = (ln_nk, hdot, inner_state.b_element_vector, ln_ntot)
249
+ return ln_nk, residuals
250
+
251
+ def _solve_bwd(res, g):
252
+ ln_nk, hdot, b_element_vector, ln_ntot = res
253
+
254
+ nk = jnp.exp(ln_nk)
255
+ ntot_result = jnp.exp(ln_ntot)
256
+
257
+ Bmatrix = _A_diagn_At(nk, formula_matrix)
258
+ c, lower = cho_factor(Bmatrix)
259
+ alpha = cho_solve((c, lower), formula_matrix @ g)
260
+ beta = cho_solve((c, lower), b_element_vector)
261
+ beta_dot_b_element = jnp.vdot(beta, b_element_vector)
262
+
263
+ cot_T = vjp_temperature(
264
+ g,
265
+ nk,
266
+ formula_matrix,
267
+ hdot,
268
+ alpha,
269
+ beta,
270
+ b_element_vector,
271
+ beta_dot_b_element,
272
+ )
273
+ cot_P = vjp_pressure(g, ntot_result, alpha, b_element_vector, beta_dot_b_element)
274
+ cot_b = vjp_elements(g, alpha, beta, b_element_vector, beta_dot_b_element)
275
+ return (ThermoState(jnp.asarray(cot_T), jnp.asarray(cot_P), cot_b),)
252
276
 
253
- residuals = (ln_nk, hdot, state.b_element_vector, ln_ntot)
254
- return ln_nk, residuals
277
+ _solve.defvjp(_solve_fwd, _solve_bwd)
255
278
 
279
+ return _solve(state)
256
280
 
257
- def minimize_gibbs_bwd(
258
- ln_nk_init,
259
- ln_ntot_init,
260
- formula_matrix,
261
- hvector_func,
262
- epsilon_crit,
263
- max_iter,
264
- res,
265
- g,
266
- ):
267
281
 
268
- ln_nk, hdot, b_element_vector, ln_ntot = res
269
-
270
- # Guard against underflow and ensure strictly positive species for SPD matrix
271
- # dtype = ln_nk.dtype
272
- #tiny = jnp.finfo(dtype).tiny
273
- # nk = jnp.maximum(jnp.exp(ln_nk), tiny)
274
- # ntot_result = jnp.maximum(jnp.exp(ln_ntot), tiny)
275
- nk = jnp.exp(ln_nk)
276
- ntot_result = jnp.exp(ln_ntot)
277
-
278
- # solves the linear systems
279
- Bmatrix = _A_diagn_At(nk, formula_matrix)
280
-
281
- # Add a tiny diagonal jitter to stabilize Cholesky for near-singular cases
282
- # size_e = Bmatrix.shape[0]
283
- # Scale jitter relative to matrix magnitude
284
- #rel = jnp.maximum(jnp.linalg.norm(Bmatrix, ord=jnp.inf), 1.0)
285
- #jitter = jnp.asarray(1e-12, dtype=Bmatrix.dtype) * rel
286
- #Bmatrix = Bmatrix + jitter * jnp.eye(size_e, dtype=Bmatrix.dtype)
287
-
288
- c, lower = cho_factor(Bmatrix)
289
- alpha = cho_solve((c, lower), formula_matrix @ g)
290
- beta = cho_solve((c, lower), b_element_vector)
291
- beta_dot_b_element = jnp.vdot(beta, b_element_vector)
292
-
293
- #VJPs
294
- cot_T = vjp_temperature(g, nk, formula_matrix, hdot, alpha, beta, b_element_vector, beta_dot_b_element)
295
- cot_P = vjp_pressure(g, ntot_result, alpha, b_element_vector, beta_dot_b_element)
296
- cot_b = vjp_elements(g, alpha, beta, b_element_vector, beta_dot_b_element)
297
-
298
- return (ThermoState(jnp.asarray(cot_T), jnp.asarray(cot_P), cot_b),)
299
-
300
-
301
- minimize_gibbs.defvjp(minimize_gibbs_fwd, minimize_gibbs_bwd)
282
+ # Note: custom_vjp is defined inside minimize_gibbs to capture static arrays.
@@ -11,10 +11,10 @@ import jax.numpy as jnp
11
11
  import jax
12
12
 
13
13
  JANAF_GIBBS_MATRICES_YKB4 = "gibbs_matrices.npz"
14
- NUMBER_OF_SPECIES_SAMPLE = "number_of_species.sample.list" # this is a sample file of number_of_species for testing
15
14
  MOLNAME_YKB4 = "molecule_names.csv"
16
15
  JANAF_NAME_KEY = "JANAF" # key for JANAF name in the molecule names file
17
16
 
17
+
18
18
  def load_molname_ykb4() -> pd.DataFrame:
19
19
  """Load the YKB4 molecular names table.
20
20
 
@@ -30,7 +30,6 @@ def load_molname_ykb4() -> pd.DataFrame:
30
30
  return df_molname
31
31
 
32
32
 
33
-
34
33
  def prepare_ykb4_setup() -> ChemicalSetup:
35
34
  """
36
35
  Prepare a JAX-friendly ChemicalSetup from JANAF-like Gibbs matrices.
@@ -43,16 +42,28 @@ def prepare_ykb4_setup() -> ChemicalSetup:
43
42
  """
44
43
  # Species / formula matrix (fixed)
45
44
  df_molname = load_molname_ykb4()
46
- formula_matrix_np, elems, species = build_formula_matrix(df_molname)
45
+ formula_matrix_np, elements, species = build_formula_matrix(df_molname)
47
46
  # Keep the matrix fixed as requested, but move to device
48
47
  formula_matrix = jnp.asarray(formula_matrix_np)
49
-
50
- # Reference elemental abundance b from the provided sample number densities
51
- npath = get_data_filepath(NUMBER_OF_SPECIES_SAMPLE)
52
- number_of_species_init = pd.read_csv(npath, header=None, sep=",").values[0]
53
- b_element_vector_np = formula_matrix_np @ number_of_species_init
54
- b_element_vector_ref = jnp.asarray(b_element_vector_np)
55
-
48
+
49
+ # Reference elemental solar abundance b from AAG21 (from exojax.utils.zsol import nsol)
50
+ # AAG21 = Asplund, M., Amarsi, A. M., & Grevesse, N. 2021, arXiv:2105.01661
51
+ b_element_vector_ref = jnp.array(
52
+ [
53
+ 2.6627135e-04,
54
+ 9.2326087e-01,
55
+ 7.5739846e-02,
56
+ 1.0847369e-07,
57
+ 6.2420098e-05,
58
+ 1.5322316e-06,
59
+ 4.5219361e-04,
60
+ 2.3731458e-07,
61
+ 1.2170949e-05,
62
+ 8.6163716e-08,
63
+ 7.3337216e-09,
64
+ 0.0,
65
+ ]
66
+ )
56
67
  # Gibbs matrices -> (molecules, T_table, mu_table, grid_lens)
57
68
  path = get_data_filepath(JANAF_GIBBS_MATRICES_YKB4)
58
69
  gibbs_matrices = np.load(path, allow_pickle=True)["arr_0"].item()
@@ -87,7 +98,7 @@ def prepare_ykb4_setup() -> ChemicalSetup:
87
98
  return ChemicalSetup(
88
99
  formula_matrix=formula_matrix,
89
100
  hvector_func=hvector_func_jit,
90
- elems=tuple(elems) if elems is not None else None,
101
+ elements=tuple(elements) if elements is not None else None,
91
102
  species=tuple(species) if species is not None else None,
92
103
  b_element_vector_reference=b_element_vector_ref,
93
104
  metadata={"source": "JANAF"},
@@ -171,8 +171,8 @@ def build_formula_matrix(
171
171
  # Parse using the clean base (never use raw for parsing)
172
172
  parsed_list = [parse_formula_with_charge(s) for s in species_clean]
173
173
 
174
- all_elems = set().union(*parsed_list) if parsed_list else set()
175
- elements = sorted(all_elems) if element_order is None else list(element_order)
174
+ all_elements = set().union(*parsed_list) if parsed_list else set()
175
+ elements = sorted(all_elements) if element_order is None else list(element_order)
176
176
 
177
177
  A = np.zeros((len(elements), len(species_clean)), dtype=np.int64)
178
178
  elem_index = {e: i for i, e in enumerate(elements)}
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: exogibbs
3
- Version: 0.2.2
3
+ Version: 0.2.3
4
4
  Summary: Differentiable Thermochemical Equilibrium Solver for Exoplanet Atmospheres
5
5
  Author-email: Hajime Kawahara <divrot@gmail.com>
6
6
  Maintainer-email: Hajime Kawahara <divrot@gmail.com>
@@ -8,8 +8,12 @@ pyproject.toml
8
8
  .github/workflows/main.yml
9
9
  documents/Makefile
10
10
  documents/conf.py
11
+ documents/index.rst
12
+ documents/_static/exogibbs_logo.png
13
+ documents/exogibbs/conf.py
11
14
  documents/ipynb/chemical_potential.ipynb
12
15
  documents/ipynb/tce_two_species.ipynb
16
+ documents/presets/ykb4.rst
13
17
  examples/GALLERY_HEADER.rst
14
18
  examples/benchmark/clfac_yk.py
15
19
  examples/comparisons/comparison_with_hcosystem.py
@@ -17,6 +21,7 @@ examples/comparisons/comparison_with_hsystem.py
17
21
  examples/comparisons/comparison_with_ykcode.py
18
22
  examples/data/p10.txt
19
23
  examples/data/yk.list
24
+ examples/layers/layer_ykb4.py
20
25
  examples/numpyro/example_nuts.py
21
26
  results/README.md
22
27
  src/exogibbs/ExoGibbs_version.py
@@ -34,7 +39,6 @@ src/exogibbs/data/gibbs_matrices.npz
34
39
  src/exogibbs/data/janaf_raw_sample.txt
35
40
  src/exogibbs/data/matrix_v3.dat
36
41
  src/exogibbs/data/molecule_names.csv
37
- src/exogibbs/data/number_of_species.sample.list
38
42
  src/exogibbs/data/testdata.dat
39
43
  src/exogibbs/equilibrium/__init__.py
40
44
  src/exogibbs/equilibrium/gibbs.py
@@ -58,6 +62,7 @@ src/exogibbs/utils/__init__.py
58
62
  src/exogibbs/utils/constants.py
59
63
  tests/unittests/api/chemsetup_smoke_test.py
60
64
  tests/unittests/api/equilibrium_api_test.py
65
+ tests/unittests/api/equilibrium_profile_test.py
61
66
  tests/unittests/equilibrium/gibbs_test.py
62
67
  tests/unittests/io/formula_matrix_reference_vs_computed_test.py
63
68
  tests/unittests/io/load_data_test.py
@@ -22,7 +22,7 @@ def test_prepare_ykb4_setup_basic():
22
22
  assert E > 0 and K > 0
23
23
 
24
24
  # optional metadata
25
- assert (setup.elems is None) or isinstance(setup.elems, tuple)
25
+ assert (setup.elements is None) or isinstance(setup.elements, tuple)
26
26
  assert (setup.species is None) or isinstance(setup.species, tuple)
27
27
  assert (setup.b_element_vector_reference is None) or isinstance(
28
28
  setup.b_element_vector_reference, (np.ndarray, jnp.ndarray)
@@ -41,9 +41,9 @@ from exogibbs.api.equilibrium import EquilibriumInit, EquilibriumOptions
41
41
 
42
42
  class FakeSetup:
43
43
  """Minimal stand-in for ChemicalSetup for interface testing."""
44
- def __init__(self, A, elems=None):
44
+ def __init__(self, A, elements=None):
45
45
  self.formula_matrix = A
46
- self.elems = elems
46
+ self.elements = elements
47
47
 
48
48
  def hvector_func(self, T):
49
49
  # Shape must be (K,), but values are irrelevant for these tests
@@ -0,0 +1,61 @@
1
+ import importlib
2
+ import jax.numpy as jnp
3
+
4
+ import exogibbs.api.equilibrium as eqmod
5
+ from exogibbs.api.equilibrium import EquilibriumOptions
6
+
7
+
8
+ class FakeSetup:
9
+ """Minimal stand-in for ChemicalSetup for vectorized API testing."""
10
+
11
+ def __init__(self, A):
12
+ self.formula_matrix = A
13
+
14
+ def hvector_func(self, T):
15
+ K = self.formula_matrix.shape[1]
16
+ return jnp.zeros((K,))
17
+
18
+
19
+ def test_equilibrium_profile_shapes_and_values(monkeypatch):
20
+ """Simple happy-path test for equilibrium_profile with a stubbed minimizer.
21
+
22
+ Ensures batched shapes are correct and values match the stub behavior
23
+ (ln_n = 0 => n = 1, x uniform, ntot = K) across all layers.
24
+ """
25
+ E, K, N = 2, 3, 4
26
+ A = jnp.array([[1, 0, 1], [0, 1, 0]], dtype=jnp.float64)
27
+ setup = FakeSetup(A)
28
+
29
+ def stub_minimize_gibbs(state, ln_nk0, ln_ntot0, A_in, hfunc, **kwargs):
30
+ # Basic sanity checks on inputs
31
+ assert A_in.shape == A.shape
32
+ assert ln_nk0.shape == (K,)
33
+ assert ln_ntot0.shape == ()
34
+ return jnp.zeros((K,), dtype=jnp.result_type(ln_nk0, A_in.dtype))
35
+
36
+ monkeypatch.setattr(
37
+ "exogibbs.api.equilibrium.minimize_gibbs", stub_minimize_gibbs, raising=True
38
+ )
39
+
40
+ # Profile inputs (N layers)
41
+ T = jnp.linspace(1000.0, 2000.0, N)
42
+ P = jnp.linspace(0.1, 1.0, N)
43
+ b = jnp.array([1.0, 2.0], dtype=jnp.float64)
44
+
45
+ out = eqmod.equilibrium_profile(
46
+ setup, T, P, b, options=EquilibriumOptions(epsilon_crit=1e-11, max_iter=50)
47
+ )
48
+
49
+ # Batched shapes
50
+ assert out.ln_n.shape == (N, K)
51
+ assert out.n.shape == (N, K)
52
+ assert out.x.shape == (N, K)
53
+ assert out.ntot.shape == (N,)
54
+
55
+ # Stub behavior reflected across layers
56
+ assert jnp.allclose(out.ln_n, 0.0)
57
+ assert jnp.allclose(out.n, 1.0)
58
+ assert jnp.allclose(out.x, jnp.ones((N, K)) / K)
59
+ assert jnp.allclose(out.ntot, K)
60
+ assert jnp.allclose(jnp.sum(out.x, axis=1), 1.0)
61
+
@@ -1,61 +0,0 @@
1
- """
2
- Validation of Gibbs Minimization Against ykawashima's B4 code
3
- ============================================================
4
-
5
- This example demonstrates and validates the ExoGibbs thermochemical equilibrium
6
- solver against the code by ykawashima when she was at B4.
7
-
8
- Updated to use the high-level API: exogibbs.api.equilibrium.equilibrium.
9
- """
10
- from exogibbs.presets.ykb4 import prepare_ykb4_setup
11
- from exogibbs.api.equilibrium import equilibrium, EquilibriumOptions
12
- import numpy as np
13
- import jax.numpy as jnp
14
-
15
- from jax import config
16
-
17
- config.update("jax_enable_x64", True)
18
-
19
- #chemical setup
20
- chem = prepare_ykb4_setup()
21
-
22
- # Thermodynamic conditions
23
- temperature = 500.0 # K
24
- P = 10.0 # bar
25
- Pref = 1.0 # bar, reference pressure
26
- opts = EquilibriumOptions(epsilon_crit=1e-11, max_iter=1000)
27
- res = equilibrium(
28
- chem,
29
- T=temperature,
30
- P=P,
31
- b=chem.b_element_vector_reference,
32
- Pref=Pref,
33
- options=opts,
34
- )
35
- nk_result = res.n
36
-
37
- # load yk's results for 10 bar
38
- dat = np.loadtxt("../data/p10.txt", delimiter=",")
39
-
40
- mask = dat > 1.e-14
41
- mask_nk_result = nk_result[mask]
42
- mask_dat = dat[mask]
43
-
44
- res = mask_nk_result/mask_dat - 1.0
45
- print(res,"diff for n>1.e-14")
46
- assert np.max(np.abs(res)) < 0.051
47
- # 8/9/2025, 0.1
48
- #[-0.00163185 -0.00163185 0.02571018 -0.00203837 -0.05069541 -0.00163185
49
- # -0.00481986 -0.00420364 -0.00161074 -0.00163182 -0.00163185 -0.00163183
50
- # -0.00163184 -0.00163178 -0.00163185 -0.00163184]
51
-
52
- import matplotlib.pyplot as plt
53
- plt.plot(nk_result, "+", label="ExoGibbs")
54
- plt.plot(dat, ".", alpha=0.5, label="yk B4 code")
55
- plt.xlabel("Species Index")
56
- plt.ylabel("Number (log scale)")
57
- plt.yscale("log")
58
- plt.legend()
59
- plt.grid()
60
- plt.show()
61
-
@@ -1 +0,0 @@
1
- 4.8771844088134374E-004,0.83748832109661187,0.16143440365984060,2.4842019364382504E-007,6.7166286367535330E-005,3.9565195261941036E-006,4.8675855005686264E-004,1.6588401261773752E-007,1.8380646975815483E-008,5.6349288368902435E-007,3.0627107689945438E-005,0.0,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0
@@ -1 +0,0 @@
1
- __version__ = "0.2.2"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes