m7-jax 0.2.0__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.
- m7_jax-0.2.0/LICENSE +202 -0
- m7_jax-0.2.0/LICENSES/BSD-3-Clause-HAMMOZ.txt +28 -0
- m7_jax-0.2.0/MANIFEST.in +3 -0
- m7_jax-0.2.0/NOTICE +28 -0
- m7_jax-0.2.0/PKG-INFO +154 -0
- m7_jax-0.2.0/README.md +123 -0
- m7_jax-0.2.0/pyproject.toml +45 -0
- m7_jax-0.2.0/setup.cfg +4 -0
- m7_jax-0.2.0/setup.py +31 -0
- m7_jax-0.2.0/src/m7_jax/__init__.py +8 -0
- m7_jax-0.2.0/src/m7_jax/_ad.py +90 -0
- m7_jax-0.2.0/src/m7_jax/coagulation.py +784 -0
- m7_jax-0.2.0/src/m7_jax/condensation.py +186 -0
- m7_jax-0.2.0/src/m7_jax/constants.py +97 -0
- m7_jax-0.2.0/src/m7_jax/data/lut_kappa.nc +4 -0
- m7_jax-0.2.0/src/m7_jax/interface.py +145 -0
- m7_jax-0.2.0/src/m7_jax/model.py +497 -0
- m7_jax-0.2.0/src/m7_jax/nucleation.py +571 -0
- m7_jax-0.2.0/src/m7_jax/precision.py +35 -0
- m7_jax-0.2.0/src/m7_jax/properties.py +499 -0
- m7_jax-0.2.0/src/m7_jax/redistribution.py +251 -0
- m7_jax-0.2.0/src/m7_jax.egg-info/PKG-INFO +154 -0
- m7_jax-0.2.0/src/m7_jax.egg-info/SOURCES.txt +24 -0
- m7_jax-0.2.0/src/m7_jax.egg-info/dependency_links.txt +1 -0
- m7_jax-0.2.0/src/m7_jax.egg-info/requires.txt +9 -0
- m7_jax-0.2.0/src/m7_jax.egg-info/top_level.txt +1 -0
m7_jax-0.2.0/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2026, Reflective
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026, HAMMOZ Consortium
|
|
4
|
+
|
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
|
6
|
+
modification, are permitted provided that the following conditions are met:
|
|
7
|
+
|
|
8
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
9
|
+
list of conditions and the following disclaimer.
|
|
10
|
+
|
|
11
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
12
|
+
this list of conditions and the following disclaimer in the documentation
|
|
13
|
+
and/or other materials provided with the distribution.
|
|
14
|
+
|
|
15
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
16
|
+
contributors may be used to endorse or promote products derived from
|
|
17
|
+
this software without specific prior written permission.
|
|
18
|
+
|
|
19
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
20
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
21
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
22
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
23
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
24
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
25
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
26
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
27
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
28
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
m7_jax-0.2.0/MANIFEST.in
ADDED
m7_jax-0.2.0/NOTICE
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
M7-JAX
|
|
2
|
+
Copyright 2026 Reflective
|
|
3
|
+
|
|
4
|
+
This product is licensed under the Apache License, Version 2.0 (see LICENSE).
|
|
5
|
+
|
|
6
|
+
The JAX kernels in src/m7_jax/ and the native oracle in tools/m7_oracle.py
|
|
7
|
+
are translated from, or embed fragments of, the HAMMOZ M7 aerosol
|
|
8
|
+
microphysics Fortran modules (https://github.com/reflective-org/SALSA,
|
|
9
|
+
commit d87dc072084336fd351d00a2ade863304c6f313d):
|
|
10
|
+
|
|
11
|
+
Copyright (c) 2021 hammoz
|
|
12
|
+
Copyright (c) 2026, HAMMOZ Consortium
|
|
13
|
+
|
|
14
|
+
Those portions remain subject to the BSD 3-Clause License, reproduced in
|
|
15
|
+
LICENSES/BSD-3-Clause-HAMMOZ.txt.
|
|
16
|
+
|
|
17
|
+
The unmodified upstream sources and data in reference/ are distributed under
|
|
18
|
+
the BSD 3-Clause License; their provenance is recorded in
|
|
19
|
+
reference/manifest.json. reference/fortran/mo_math_constants.F90 and
|
|
20
|
+
reference/fortran/mo_physical_constants.F90 still carry their earlier MPI-M
|
|
21
|
+
Software License headers. These ICON modules have since been released under
|
|
22
|
+
the BSD 3-Clause License (https://gitlab.dkrz.de/icon/icon-model), and
|
|
23
|
+
BSD 3-Clause licensing of the copies here has been confirmed:
|
|
24
|
+
|
|
25
|
+
Copyright (C) 2004-2024, DWD, MPI-M, DKRZ, KIT, ETH, MeteoSwiss
|
|
26
|
+
|
|
27
|
+
The names of HAMMOZ, the ICON partners and their contributors are not used to
|
|
28
|
+
endorse or promote this product.
|
m7_jax-0.2.0/PKG-INFO
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: m7-jax
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Fortran-validated ECHAM-HAM M7 aerosol microphysics in JAX
|
|
5
|
+
Author: Reflective
|
|
6
|
+
License-Expression: Apache-2.0 AND BSD-3-Clause
|
|
7
|
+
Project-URL: Repository, https://github.com/reflective-org/M7-JAX
|
|
8
|
+
Project-URL: Documentation, https://github.com/reflective-org/M7-JAX/blob/main/docs/model.md
|
|
9
|
+
Project-URL: Changelog, https://github.com/reflective-org/M7-JAX/blob/main/CHANGELOG.md
|
|
10
|
+
Project-URL: Issues, https://github.com/reflective-org/M7-JAX/issues
|
|
11
|
+
Keywords: aerosol,microphysics,M7,ECHAM-HAM,JAX,climate
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
17
|
+
Classifier: Topic :: Scientific/Engineering :: Atmospheric Science
|
|
18
|
+
Requires-Python: >=3.11
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
License-File: NOTICE
|
|
22
|
+
License-File: LICENSES/BSD-3-Clause-HAMMOZ.txt
|
|
23
|
+
Requires-Dist: jax>=0.10.2
|
|
24
|
+
Requires-Dist: numpy>=2
|
|
25
|
+
Requires-Dist: scipy>=1.14
|
|
26
|
+
Provides-Extra: test
|
|
27
|
+
Requires-Dist: pytest>=8; extra == "test"
|
|
28
|
+
Provides-Extra: plot
|
|
29
|
+
Requires-Dist: matplotlib>=3.8; extra == "plot"
|
|
30
|
+
Dynamic: license-file
|
|
31
|
+
|
|
32
|
+
# M7-JAX
|
|
33
|
+
|
|
34
|
+
A Python/JAX port of the **ECHAM6.3-HAM2.3 M7 aerosol microphysics**, validated
|
|
35
|
+
against the original Fortran routines and the complete native `m7` call. This
|
|
36
|
+
repository is independent of SALSA-JAX.
|
|
37
|
+
|
|
38
|
+
`step_all` advances HAM's 18-component, seven-mode state: sulfate, black
|
|
39
|
+
carbon, organic carbon, sea salt and dust in the four soluble and three
|
|
40
|
+
insoluble lognormal modes, plus H₂SO₄ gas. It includes coagulation,
|
|
41
|
+
condensation, binary (Vehkamäki) and ion-mediated (Kazil–Lovejoy) sulfuric-acid
|
|
42
|
+
nucleation, organic nucleation, insoluble-to-soluble ageing, particle
|
|
43
|
+
properties, kappa hydration and modal redistribution in the native process
|
|
44
|
+
order, and the host-tracer conversions of HAM's `ham_subm_interface`. The
|
|
45
|
+
original pure-sulfate `step` (four soluble modes, empty insoluble modes, both
|
|
46
|
+
hydration options) remains. The rest of HAM (chemistry, emissions,
|
|
47
|
+
deposition, the box and GCM drivers), secondary organic aerosol and radiation
|
|
48
|
+
are outside this scope.
|
|
49
|
+
|
|
50
|
+
## Install
|
|
51
|
+
|
|
52
|
+
```sh
|
|
53
|
+
pip install m7-jax
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
The wheel includes the authentic 45 MB kappa lookup table
|
|
57
|
+
(`m7_jax.properties.default_kappa_table_path()`). The Fortran reference
|
|
58
|
+
harness, the recorded configurations and the test suite need a checkout of
|
|
59
|
+
this repository.
|
|
60
|
+
|
|
61
|
+
## Develop and test
|
|
62
|
+
|
|
63
|
+
Use this repository's own virtual environment. GNU Fortran must be on `PATH`;
|
|
64
|
+
NetCDF Python reading uses SciPy, so the reference harness does not require
|
|
65
|
+
NetCDF Fortran libraries. The authentic 45 MB kappa lookup table is included.
|
|
66
|
+
|
|
67
|
+
```sh
|
|
68
|
+
python3 -m venv .venv
|
|
69
|
+
.venv/bin/python -m pip install -r requirements-dev.txt
|
|
70
|
+
.venv/bin/python -m pip install --no-deps -e .
|
|
71
|
+
.venv/bin/python -m pytest -q
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Run commands from this checkout. Enable JAX double precision before constructing
|
|
75
|
+
arrays. `requirements-dev.txt` records the tested environment; the editable
|
|
76
|
+
checkout includes the reference inputs used by command-line tools.
|
|
77
|
+
|
|
78
|
+
## Run the sulfate experiment
|
|
79
|
+
|
|
80
|
+
```sh
|
|
81
|
+
.venv/bin/python -m tools.run_m7_sulfate \
|
|
82
|
+
--config configs/m7-sulfate.toml --output outputs/sulfate
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Use a fresh output directory. The command runs **both JAX and checked/optimized
|
|
86
|
+
Fortran**, saves every timestep to NPZ and CSV, records source/compiler hashes,
|
|
87
|
+
and checks parity, physical state and sulfur budgets. It exits nonzero if a
|
|
88
|
+
comparison or budget gate fails, retaining the report for inspection.
|
|
89
|
+
|
|
90
|
+
The example starts with 100 and 900 particles/cm³ in the nucleation and Aitken
|
|
91
|
+
modes, dry count-median diameters 3 and 25 nm, 280 K, 101325 Pa, RH 50%, and
|
|
92
|
+
10⁸ H₂SO₄ molecules/cm³. Gas production is 10⁵ molecules/cm³/s; the gas evolves
|
|
93
|
+
rather than remaining constant. It runs 600 one-second steps. Other checked
|
|
94
|
+
configurations are in `configs/`.
|
|
95
|
+
|
|
96
|
+
## Python API
|
|
97
|
+
|
|
98
|
+
```python
|
|
99
|
+
import jax
|
|
100
|
+
jax.config.update('jax_enable_x64', True)
|
|
101
|
+
from m7_jax.model import initialize, step, STATIC_OPTIONS
|
|
102
|
+
from m7_jax.properties import default_kappa_table_path, load_kappa_table
|
|
103
|
+
|
|
104
|
+
state = initialize(dry_diameter_nm=(3., 25., 200., 2000.))
|
|
105
|
+
table = load_kappa_table(default_kappa_table_path())
|
|
106
|
+
advance = jax.jit(step, static_argnames=STATIC_OPTIONS)
|
|
107
|
+
result = advance(state, 280., 101325., .5, 1., production=1e5, table=table)
|
|
108
|
+
assert bool(result.valid)
|
|
109
|
+
state = result.state
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Independent APIs: `coagulation.coaset`/`dnum`,
|
|
113
|
+
`condensation.condensation_sink`/`produce_and_condense`, and
|
|
114
|
+
`nucleation.vehkamaeki`/`nucleate`. Use native concentrations in **cm⁻³**, radii
|
|
115
|
+
in **cm**, pressure in Pa, temperature in K and timestep in seconds. Leading
|
|
116
|
+
array dimensions represent independent cells. Host validation rejects insoluble
|
|
117
|
+
populations; check `StepResult.valid` inside repeated integration.
|
|
118
|
+
|
|
119
|
+
## Evidence and limits
|
|
120
|
+
|
|
121
|
+
**353 tests pass** on JAX 0.10.2, 0.11.0 and 0.12.1, with 8 real-PARNUC-table
|
|
122
|
+
variants skipped; **361 pass** when `HAM_INPUT_DIR` names the table.
|
|
123
|
+
All six recorded trajectories pass every-step Fortran comparison and sulfur
|
|
124
|
+
budgets. This establishes compatibility with the Fortran for the tested
|
|
125
|
+
configurations, not independent physical accuracy. The
|
|
126
|
+
[validation report](https://github.com/reflective-org/M7-JAX/blob/main/docs/validation.md) has the measured errors.
|
|
127
|
+
|
|
128
|
+
- [Architecture, units and scientific limitations](https://github.com/reflective-org/M7-JAX/blob/main/docs/model.md)
|
|
129
|
+
- [Validation results, timestep refinement and CPU measurements](https://github.com/reflective-org/M7-JAX/blob/main/docs/validation.md)
|
|
130
|
+
- [Commit-sized implementation and verification plan](https://github.com/reflective-org/M7-JAX/blob/main/docs/PLAN.md)
|
|
131
|
+
- [Reference provenance](https://github.com/reflective-org/M7-JAX/blob/main/reference/manifest.json)
|
|
132
|
+
|
|
133
|
+
JAX is slower for the measured single-cell workloads. Native cancellation and
|
|
134
|
+
lookup discretization are preserved in float64. The float32 path of
|
|
135
|
+
`step_all` uses algebraically identical forms that avoid the cancellations
|
|
136
|
+
([model contract](https://github.com/reflective-org/M7-JAX/blob/main/docs/model.md#float32-precision-adaptations)). The Kazil/Lovejoy lookup option
|
|
137
|
+
(`nucleate_all`/`step_all`, `scheme=2`) is supported given its PARNUC table
|
|
138
|
+
(`HAM_INPUT_DIR`, not shipped -- see `docs/validation.md`); without one it is
|
|
139
|
+
rejected there too, and the independent `nucleate`/`step` APIs reject it
|
|
140
|
+
unconditionally. Coupled nucleation with condensation disabled is also
|
|
141
|
+
rejected because native M7 leaves its sink uninitialized; the independent
|
|
142
|
+
nucleation API accepts an explicit sink. One native defect is corrected, as
|
|
143
|
+
the r7492 reference configuration itself corrects it (the insoluble-mode
|
|
144
|
+
radius, TUT-ISI/SALSA#6); every other native formula, including the known
|
|
145
|
+
defects listed in the [model contract](https://github.com/reflective-org/M7-JAX/blob/main/docs/model.md#native-defects-retained),
|
|
146
|
+
is unchanged. Original source/license notices are retained in `reference/`.
|
|
147
|
+
|
|
148
|
+
## License
|
|
149
|
+
|
|
150
|
+
M7-JAX is licensed under the [Apache License 2.0](https://github.com/reflective-org/M7-JAX/blob/main/LICENSE). The JAX kernels
|
|
151
|
+
and native oracle are derived from HAMMOZ M7 and also remain subject to the
|
|
152
|
+
[BSD 3-Clause License](https://github.com/reflective-org/M7-JAX/blob/main/LICENSES/BSD-3-Clause-HAMMOZ.txt); see [NOTICE](https://github.com/reflective-org/M7-JAX/blob/main/NOTICE).
|
|
153
|
+
Upstream sources and data under `reference/` are BSD 3-Clause; see NOTICE
|
|
154
|
+
for the two ICON constant modules that still carry older MPI-M headers.
|
m7_jax-0.2.0/README.md
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# M7-JAX
|
|
2
|
+
|
|
3
|
+
A Python/JAX port of the **ECHAM6.3-HAM2.3 M7 aerosol microphysics**, validated
|
|
4
|
+
against the original Fortran routines and the complete native `m7` call. This
|
|
5
|
+
repository is independent of SALSA-JAX.
|
|
6
|
+
|
|
7
|
+
`step_all` advances HAM's 18-component, seven-mode state: sulfate, black
|
|
8
|
+
carbon, organic carbon, sea salt and dust in the four soluble and three
|
|
9
|
+
insoluble lognormal modes, plus H₂SO₄ gas. It includes coagulation,
|
|
10
|
+
condensation, binary (Vehkamäki) and ion-mediated (Kazil–Lovejoy) sulfuric-acid
|
|
11
|
+
nucleation, organic nucleation, insoluble-to-soluble ageing, particle
|
|
12
|
+
properties, kappa hydration and modal redistribution in the native process
|
|
13
|
+
order, and the host-tracer conversions of HAM's `ham_subm_interface`. The
|
|
14
|
+
original pure-sulfate `step` (four soluble modes, empty insoluble modes, both
|
|
15
|
+
hydration options) remains. The rest of HAM (chemistry, emissions,
|
|
16
|
+
deposition, the box and GCM drivers), secondary organic aerosol and radiation
|
|
17
|
+
are outside this scope.
|
|
18
|
+
|
|
19
|
+
## Install
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
pip install m7-jax
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
The wheel includes the authentic 45 MB kappa lookup table
|
|
26
|
+
(`m7_jax.properties.default_kappa_table_path()`). The Fortran reference
|
|
27
|
+
harness, the recorded configurations and the test suite need a checkout of
|
|
28
|
+
this repository.
|
|
29
|
+
|
|
30
|
+
## Develop and test
|
|
31
|
+
|
|
32
|
+
Use this repository's own virtual environment. GNU Fortran must be on `PATH`;
|
|
33
|
+
NetCDF Python reading uses SciPy, so the reference harness does not require
|
|
34
|
+
NetCDF Fortran libraries. The authentic 45 MB kappa lookup table is included.
|
|
35
|
+
|
|
36
|
+
```sh
|
|
37
|
+
python3 -m venv .venv
|
|
38
|
+
.venv/bin/python -m pip install -r requirements-dev.txt
|
|
39
|
+
.venv/bin/python -m pip install --no-deps -e .
|
|
40
|
+
.venv/bin/python -m pytest -q
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Run commands from this checkout. Enable JAX double precision before constructing
|
|
44
|
+
arrays. `requirements-dev.txt` records the tested environment; the editable
|
|
45
|
+
checkout includes the reference inputs used by command-line tools.
|
|
46
|
+
|
|
47
|
+
## Run the sulfate experiment
|
|
48
|
+
|
|
49
|
+
```sh
|
|
50
|
+
.venv/bin/python -m tools.run_m7_sulfate \
|
|
51
|
+
--config configs/m7-sulfate.toml --output outputs/sulfate
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Use a fresh output directory. The command runs **both JAX and checked/optimized
|
|
55
|
+
Fortran**, saves every timestep to NPZ and CSV, records source/compiler hashes,
|
|
56
|
+
and checks parity, physical state and sulfur budgets. It exits nonzero if a
|
|
57
|
+
comparison or budget gate fails, retaining the report for inspection.
|
|
58
|
+
|
|
59
|
+
The example starts with 100 and 900 particles/cm³ in the nucleation and Aitken
|
|
60
|
+
modes, dry count-median diameters 3 and 25 nm, 280 K, 101325 Pa, RH 50%, and
|
|
61
|
+
10⁸ H₂SO₄ molecules/cm³. Gas production is 10⁵ molecules/cm³/s; the gas evolves
|
|
62
|
+
rather than remaining constant. It runs 600 one-second steps. Other checked
|
|
63
|
+
configurations are in `configs/`.
|
|
64
|
+
|
|
65
|
+
## Python API
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
import jax
|
|
69
|
+
jax.config.update('jax_enable_x64', True)
|
|
70
|
+
from m7_jax.model import initialize, step, STATIC_OPTIONS
|
|
71
|
+
from m7_jax.properties import default_kappa_table_path, load_kappa_table
|
|
72
|
+
|
|
73
|
+
state = initialize(dry_diameter_nm=(3., 25., 200., 2000.))
|
|
74
|
+
table = load_kappa_table(default_kappa_table_path())
|
|
75
|
+
advance = jax.jit(step, static_argnames=STATIC_OPTIONS)
|
|
76
|
+
result = advance(state, 280., 101325., .5, 1., production=1e5, table=table)
|
|
77
|
+
assert bool(result.valid)
|
|
78
|
+
state = result.state
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Independent APIs: `coagulation.coaset`/`dnum`,
|
|
82
|
+
`condensation.condensation_sink`/`produce_and_condense`, and
|
|
83
|
+
`nucleation.vehkamaeki`/`nucleate`. Use native concentrations in **cm⁻³**, radii
|
|
84
|
+
in **cm**, pressure in Pa, temperature in K and timestep in seconds. Leading
|
|
85
|
+
array dimensions represent independent cells. Host validation rejects insoluble
|
|
86
|
+
populations; check `StepResult.valid` inside repeated integration.
|
|
87
|
+
|
|
88
|
+
## Evidence and limits
|
|
89
|
+
|
|
90
|
+
**353 tests pass** on JAX 0.10.2, 0.11.0 and 0.12.1, with 8 real-PARNUC-table
|
|
91
|
+
variants skipped; **361 pass** when `HAM_INPUT_DIR` names the table.
|
|
92
|
+
All six recorded trajectories pass every-step Fortran comparison and sulfur
|
|
93
|
+
budgets. This establishes compatibility with the Fortran for the tested
|
|
94
|
+
configurations, not independent physical accuracy. The
|
|
95
|
+
[validation report](https://github.com/reflective-org/M7-JAX/blob/main/docs/validation.md) has the measured errors.
|
|
96
|
+
|
|
97
|
+
- [Architecture, units and scientific limitations](https://github.com/reflective-org/M7-JAX/blob/main/docs/model.md)
|
|
98
|
+
- [Validation results, timestep refinement and CPU measurements](https://github.com/reflective-org/M7-JAX/blob/main/docs/validation.md)
|
|
99
|
+
- [Commit-sized implementation and verification plan](https://github.com/reflective-org/M7-JAX/blob/main/docs/PLAN.md)
|
|
100
|
+
- [Reference provenance](https://github.com/reflective-org/M7-JAX/blob/main/reference/manifest.json)
|
|
101
|
+
|
|
102
|
+
JAX is slower for the measured single-cell workloads. Native cancellation and
|
|
103
|
+
lookup discretization are preserved in float64. The float32 path of
|
|
104
|
+
`step_all` uses algebraically identical forms that avoid the cancellations
|
|
105
|
+
([model contract](https://github.com/reflective-org/M7-JAX/blob/main/docs/model.md#float32-precision-adaptations)). The Kazil/Lovejoy lookup option
|
|
106
|
+
(`nucleate_all`/`step_all`, `scheme=2`) is supported given its PARNUC table
|
|
107
|
+
(`HAM_INPUT_DIR`, not shipped -- see `docs/validation.md`); without one it is
|
|
108
|
+
rejected there too, and the independent `nucleate`/`step` APIs reject it
|
|
109
|
+
unconditionally. Coupled nucleation with condensation disabled is also
|
|
110
|
+
rejected because native M7 leaves its sink uninitialized; the independent
|
|
111
|
+
nucleation API accepts an explicit sink. One native defect is corrected, as
|
|
112
|
+
the r7492 reference configuration itself corrects it (the insoluble-mode
|
|
113
|
+
radius, TUT-ISI/SALSA#6); every other native formula, including the known
|
|
114
|
+
defects listed in the [model contract](https://github.com/reflective-org/M7-JAX/blob/main/docs/model.md#native-defects-retained),
|
|
115
|
+
is unchanged. Original source/license notices are retained in `reference/`.
|
|
116
|
+
|
|
117
|
+
## License
|
|
118
|
+
|
|
119
|
+
M7-JAX is licensed under the [Apache License 2.0](https://github.com/reflective-org/M7-JAX/blob/main/LICENSE). The JAX kernels
|
|
120
|
+
and native oracle are derived from HAMMOZ M7 and also remain subject to the
|
|
121
|
+
[BSD 3-Clause License](https://github.com/reflective-org/M7-JAX/blob/main/LICENSES/BSD-3-Clause-HAMMOZ.txt); see [NOTICE](https://github.com/reflective-org/M7-JAX/blob/main/NOTICE).
|
|
122
|
+
Upstream sources and data under `reference/` are BSD 3-Clause; see NOTICE
|
|
123
|
+
for the two ICON constant modules that still carry older MPI-M headers.
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "m7-jax"
|
|
7
|
+
version = "0.2.0"
|
|
8
|
+
description = "Fortran-validated ECHAM-HAM M7 aerosol microphysics in JAX"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
|
+
license = "Apache-2.0 AND BSD-3-Clause"
|
|
12
|
+
license-files = ["LICENSE", "NOTICE", "LICENSES/*"]
|
|
13
|
+
authors = [{ name = "Reflective" }]
|
|
14
|
+
keywords = ["aerosol", "microphysics", "M7", "ECHAM-HAM", "JAX", "climate"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 4 - Beta",
|
|
17
|
+
"Intended Audience :: Science/Research",
|
|
18
|
+
"Operating System :: OS Independent",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
21
|
+
"Topic :: Scientific/Engineering :: Atmospheric Science",
|
|
22
|
+
]
|
|
23
|
+
dependencies = ["jax>=0.10.2", "numpy>=2", "scipy>=1.14"]
|
|
24
|
+
|
|
25
|
+
[project.urls]
|
|
26
|
+
Repository = "https://github.com/reflective-org/M7-JAX"
|
|
27
|
+
Documentation = "https://github.com/reflective-org/M7-JAX/blob/main/docs/model.md"
|
|
28
|
+
Changelog = "https://github.com/reflective-org/M7-JAX/blob/main/CHANGELOG.md"
|
|
29
|
+
Issues = "https://github.com/reflective-org/M7-JAX/issues"
|
|
30
|
+
|
|
31
|
+
[project.optional-dependencies]
|
|
32
|
+
test = ["pytest>=8"]
|
|
33
|
+
plot = ["matplotlib>=3.8"]
|
|
34
|
+
|
|
35
|
+
[tool.setuptools.packages.find]
|
|
36
|
+
where = ["src"]
|
|
37
|
+
|
|
38
|
+
[tool.setuptools.package-data]
|
|
39
|
+
# The authentic version-2 kappa lookup (reference/input/lut_kappa.nc, linked
|
|
40
|
+
# here) ships in the wheel so a host can load it without this checkout.
|
|
41
|
+
m7_jax = ["data/lut_kappa.nc"]
|
|
42
|
+
|
|
43
|
+
[tool.pytest.ini_options]
|
|
44
|
+
testpaths = ["tests"]
|
|
45
|
+
pythonpath = ["src", "."]
|
m7_jax-0.2.0/setup.cfg
ADDED
m7_jax-0.2.0/setup.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Copyright 2026 Reflective
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
"""Build hook: refuse to build a package without the kappa lookup table.
|
|
4
|
+
|
|
5
|
+
``src/m7_jax/data/lut_kappa.nc`` is a link to ``reference/input/lut_kappa.nc``.
|
|
6
|
+
Without ``reference/`` (a subtree or vendored copy, ``git archive`` of part of
|
|
7
|
+
the tree, a checkout without symlink support) the link dangles, and setuptools
|
|
8
|
+
would otherwise build a wheel without the table and without a warning.
|
|
9
|
+
Everything else is configured in ``pyproject.toml``.
|
|
10
|
+
"""
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
|
|
13
|
+
KAPPA_TABLE = Path('src') / 'm7_jax' / 'data' / 'lut_kappa.nc'
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def check_kappa_table(root):
|
|
17
|
+
"""Raise ``SystemExit`` unless ``root`` holds a readable NetCDF kappa table."""
|
|
18
|
+
path = Path(root) / KAPPA_TABLE
|
|
19
|
+
if not path.is_file():
|
|
20
|
+
raise SystemExit(f'{path} is missing or a dangling link to reference/input/lut_kappa.nc; '
|
|
21
|
+
'refusing to build m7-jax without the kappa lookup table.')
|
|
22
|
+
with path.open('rb') as table:
|
|
23
|
+
if table.read(3) != b'CDF':
|
|
24
|
+
raise SystemExit(f'{path} is not a NetCDF file; refusing to build m7-jax without the kappa table.')
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
if __name__ == '__main__':
|
|
28
|
+
from setuptools import setup
|
|
29
|
+
|
|
30
|
+
check_kappa_table(Path(__file__).resolve().parent)
|
|
31
|
+
setup()
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Copyright 2026 Reflective
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
"""Fortran-validated ECHAM-HAM M7 aerosol microphysics in JAX.
|
|
4
|
+
|
|
5
|
+
Enable jax_enable_x64 to reproduce the float64 Fortran; ``step_all`` also runs
|
|
6
|
+
in float32. Native units are molecules/cm3, particles/cm3, ug/m3 for non-sulfate
|
|
7
|
+
mass, radii cm, temperature K and pressure Pa.
|
|
8
|
+
"""
|