hartmax 2.0.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.
- hartmax-2.0.0/LICENSE +21 -0
- hartmax-2.0.0/MANIFEST.in +1 -0
- hartmax-2.0.0/PKG-INFO +142 -0
- hartmax-2.0.0/README.md +100 -0
- hartmax-2.0.0/pyproject.toml +105 -0
- hartmax-2.0.0/setup.cfg +4 -0
- hartmax-2.0.0/src/hartmax/__init__.py +147 -0
- hartmax-2.0.0/src/hartmax/__main__.py +6 -0
- hartmax-2.0.0/src/hartmax/_programs.py +636 -0
- hartmax-2.0.0/src/hartmax/axial.py +552 -0
- hartmax-2.0.0/src/hartmax/cli.py +30 -0
- hartmax-2.0.0/src/hartmax/config.py +439 -0
- hartmax-2.0.0/src/hartmax/core3d.py +1850 -0
- hartmax-2.0.0/src/hartmax/data/benchmarks/references/alex-b1-pipe.csv +17 -0
- hartmax-2.0.0/src/hartmax/data/benchmarks/references/alex-b2-square.csv +19 -0
- hartmax-2.0.0/src/hartmax/data/benchmarks/references/bluck2015-shercliff-nusselt.json +227 -0
- hartmax-2.0.0/src/hartmax/data/benchmarks/references/mistrangelo2025-case1.json +16 -0
- hartmax-2.0.0/src/hartmax/data/benchmarks/references/mistrangelo2025-case2.json +15 -0
- hartmax-2.0.0/src/hartmax/data/benchmarks/references/samper-table-i.toml +79 -0
- hartmax-2.0.0/src/hartmax/data/benchmarks/specs/alex-b1-pipe.toml +252 -0
- hartmax-2.0.0/src/hartmax/data/benchmarks/specs/alex-b2-square.toml +292 -0
- hartmax-2.0.0/src/hartmax/data/benchmarks/specs/hunt-ha20.toml +71 -0
- hartmax-2.0.0/src/hartmax/data/benchmarks/specs/mistrangelo2025.toml +148 -0
- hartmax-2.0.0/src/hartmax/data/benchmarks/specs/shercliff-ha20.toml +69 -0
- hartmax-2.0.0/src/hartmax/fields.py +222 -0
- hartmax-2.0.0/src/hartmax/grid.py +576 -0
- hartmax-2.0.0/src/hartmax/ops.py +966 -0
- hartmax-2.0.0/src/hartmax/output.py +564 -0
- hartmax-2.0.0/src/hartmax/pipe.py +270 -0
- hartmax-2.0.0/src/hartmax/poisson.py +1703 -0
- hartmax-2.0.0/src/hartmax/problem.py +665 -0
- hartmax-2.0.0/src/hartmax/py.typed +1 -0
- hartmax-2.0.0/src/hartmax/q2d.py +425 -0
- hartmax-2.0.0/src/hartmax/solver.py +761 -0
- hartmax-2.0.0/src/hartmax/steady.py +1073 -0
- hartmax-2.0.0/src/hartmax/thermal.py +1610 -0
- hartmax-2.0.0/src/hartmax/units.py +286 -0
- hartmax-2.0.0/src/hartmax.egg-info/PKG-INFO +142 -0
- hartmax-2.0.0/src/hartmax.egg-info/SOURCES.txt +41 -0
- hartmax-2.0.0/src/hartmax.egg-info/dependency_links.txt +1 -0
- hartmax-2.0.0/src/hartmax.egg-info/entry_points.txt +2 -0
- hartmax-2.0.0/src/hartmax.egg-info/requires.txt +26 -0
- hartmax-2.0.0/src/hartmax.egg-info/top_level.txt +1 -0
hartmax-2.0.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 HARTMAX contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
prune tests
|
hartmax-2.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: hartmax
|
|
3
|
+
Version: 2.0.0
|
|
4
|
+
Summary: JAX-native inductionless MHD toolkit for research, benchmarking, and differentiable simulation
|
|
5
|
+
Author: Rogerio Jorge
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/uwplasma/HARTMAX
|
|
8
|
+
Project-URL: Documentation, https://hartmax.readthedocs.io/
|
|
9
|
+
Project-URL: Issues, https://github.com/uwplasma/HARTMAX/issues
|
|
10
|
+
Project-URL: Source, https://github.com/uwplasma/HARTMAX
|
|
11
|
+
Keywords: magnetohydrodynamics,liquid-metal,jax,differentiable-simulation
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Requires-Python: <3.14,>=3.11
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Requires-Dist: filelock
|
|
20
|
+
Requires-Dist: jax>=0.7.2
|
|
21
|
+
Requires-Dist: numpy
|
|
22
|
+
Requires-Dist: solvax<1,>=0.36.2
|
|
23
|
+
Provides-Extra: dev
|
|
24
|
+
Requires-Dist: matplotlib; extra == "dev"
|
|
25
|
+
Requires-Dist: pytest; extra == "dev"
|
|
26
|
+
Requires-Dist: pytest-cov; extra == "dev"
|
|
27
|
+
Requires-Dist: pytest-timeout; extra == "dev"
|
|
28
|
+
Requires-Dist: pytest-xdist; extra == "dev"
|
|
29
|
+
Requires-Dist: ruff<1,>=0.16; extra == "dev"
|
|
30
|
+
Provides-Extra: docs
|
|
31
|
+
Requires-Dist: sphinx; extra == "docs"
|
|
32
|
+
Requires-Dist: myst-parser; extra == "docs"
|
|
33
|
+
Requires-Dist: furo; extra == "docs"
|
|
34
|
+
Requires-Dist: sphinx-copybutton; extra == "docs"
|
|
35
|
+
Requires-Dist: sphinx-design; extra == "docs"
|
|
36
|
+
Provides-Extra: release
|
|
37
|
+
Requires-Dist: build; extra == "release"
|
|
38
|
+
Requires-Dist: twine; extra == "release"
|
|
39
|
+
Provides-Extra: visualization
|
|
40
|
+
Requires-Dist: matplotlib; extra == "visualization"
|
|
41
|
+
Dynamic: license-file
|
|
42
|
+
|
|
43
|
+
# HARTMAX
|
|
44
|
+
|
|
45
|
+
[](https://pypi.org/project/hartmax/)
|
|
46
|
+
[](pyproject.toml)
|
|
47
|
+
[](LICENSE)
|
|
48
|
+
[](https://github.com/uwplasma/HARTMAX/actions/workflows/ci.yml)
|
|
49
|
+
[](https://hartmax.readthedocs.io/)
|
|
50
|
+
|
|
51
|
+
**Differentiable liquid-metal MHD in JAX, for the ducts of fusion blankets.**
|
|
52
|
+
|
|
53
|
+
HARTMAX solves liquid metal flowing through strong magnetic fields. It handles ducts and pipes with insulating or
|
|
54
|
+
conducting walls, three-dimensional ducts leaving a magnet, heat transfer through steel walls, and
|
|
55
|
+
quasi-two-dimensional vortex dynamics. Every result is differentiable end to end, so a design study can take
|
|
56
|
+
gradients through the solve. It runs on a CPU or a GPU, and [SOLVAX](https://github.com/uwplasma/SOLVAX) supplies
|
|
57
|
+
the solvers and implicit derivatives.
|
|
58
|
+
|
|
59
|
+

|
|
60
|
+
|
|
61
|
+
## Install and run
|
|
62
|
+
|
|
63
|
+
HARTMAX needs Python 3.11, 3.12 or 3.13. It was called LMhdX until 2.0: `pip install hartmax` replaces
|
|
64
|
+
`pip install lmhdx`, and the [migration guide](https://hartmax.readthedocs.io/en/latest/reference/migration.html)
|
|
65
|
+
lists what changed. The 1.x releases stay on PyPI as `lmhdx`.
|
|
66
|
+
|
|
67
|
+
```console
|
|
68
|
+
pip install hartmax # JAX runs on the CPU; for a GPU follow the JAX installation guide
|
|
69
|
+
hartmax examples/hartmann_case.toml
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
The same case from Python:
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
import hartmax
|
|
76
|
+
|
|
77
|
+
solution = hartmax.solve(hartmax.duct(100.0, 48, wall_conductance=0.027))
|
|
78
|
+
print(float(solution.velocity[0].data.max()))
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
`solve` takes a `Problem` and a `Solver`, and a TOML file builds the same objects. The
|
|
82
|
+
[first run](https://hartmax.readthedocs.io/en/latest/getting_started/first_run.html) walks through it and checks the
|
|
83
|
+
answer against the exact profile.
|
|
84
|
+
|
|
85
|
+
## What it does
|
|
86
|
+
|
|
87
|
+
- **Fully developed ducts and pipes,** with thin or resolved conducting walls and wall stacks, and meshes chosen from
|
|
88
|
+
the layer thicknesses `a/Ha` and `a/√Ha` rather than from a cell count.
|
|
89
|
+
- **Steady states as roots.** The steady solve is a differentiable root found by conjugate gradients or
|
|
90
|
+
Newton-Krylov, not a march in time.
|
|
91
|
+
- **Three-dimensional and open ducts,** with an inlet and an outlet through a field that varies along them, with or
|
|
92
|
+
without inertia (`method="auto"` picks Newton or marching the Runge-Kutta step).
|
|
93
|
+
- **Runs in time,** by `Solver(method="euler" | "rk3", dt=, steps=)`. An `Output` writes records, ParaView files and
|
|
94
|
+
a summary, and a later run restarts from them bit for bit.
|
|
95
|
+
- **Heat transfer,** with conduction through solid walls, Joule heat and Boussinesq buoyancy.
|
|
96
|
+
- **Quasi-two-dimensional flow** with Hartmann-layer friction, by a spectral time step.
|
|
97
|
+
|
|
98
|
+
## Validation
|
|
99
|
+
|
|
100
|
+

|
|
101
|
+
|
|
102
|
+
HARTMAX is checked against exact solutions, independent spectral references, experiments and other codes, and its
|
|
103
|
+
adjoints against finite differences. The [validation record](https://hartmax.readthedocs.io/en/latest/validation/index.html)
|
|
104
|
+
gives every result with its gate, what is still at the research stage, and the measured speed on a CPU and a GPU.
|
|
105
|
+
|
|
106
|
+
## Examples
|
|
107
|
+
|
|
108
|
+
| Command | Physics |
|
|
109
|
+
|---|---|
|
|
110
|
+
| `hartmax examples/hartmann_case.toml` | Hartmann duct from a TOML file |
|
|
111
|
+
| `hartmax examples/heated_duct.toml` | heated duct with buoyancy |
|
|
112
|
+
| `python examples/hunt_example.py` | conducting walls, side-layer jets |
|
|
113
|
+
| `python examples/fringe_duct_example.py` | duct leaving a magnet, its drop and the drop's field derivative |
|
|
114
|
+
| `python examples/open_duct_inertia_example.py` | inertial share of the fringe drop |
|
|
115
|
+
| `python examples/q2d_turbulence_demo.py` | Q2D vorticity evolution and energy decay |
|
|
116
|
+
| `python examples/duct_design_law.py` | optimum aspect ratio of an insulated duct |
|
|
117
|
+
|
|
118
|
+
[`examples/catalog.toml`](examples/catalog.toml) lists each example's parameters and evidence status, and
|
|
119
|
+
`python scripts/make_showcase_figures.py` regenerates the figures.
|
|
120
|
+
|
|
121
|
+
## Documentation
|
|
122
|
+
|
|
123
|
+
The [documentation](https://hartmax.readthedocs.io/) has
|
|
124
|
+
[getting started](https://hartmax.readthedocs.io/en/latest/getting_started/install.html) guides, step-by-step
|
|
125
|
+
[tutorials](https://hartmax.readthedocs.io/en/latest/tutorials/fully_developed.html), the
|
|
126
|
+
[equations and numerical methods](https://hartmax.readthedocs.io/en/latest/physics/numerics.html), the
|
|
127
|
+
[validation](https://hartmax.readthedocs.io/en/latest/validation/index.html) record and the
|
|
128
|
+
[API reference](https://hartmax.readthedocs.io/en/latest/reference/api.html).
|
|
129
|
+
|
|
130
|
+
## Citing
|
|
131
|
+
|
|
132
|
+
If you use HARTMAX in published work, cite the release you used and the benchmark sources your case relies on.
|
|
133
|
+
[CITATION.cff](CITATION.cff) holds the details, GitHub's "Cite this repository" button exports them, and the
|
|
134
|
+
[references page](https://hartmax.readthedocs.io/en/latest/reference/bibliography.html) has a BibTeX entry.
|
|
135
|
+
|
|
136
|
+
## Contributing
|
|
137
|
+
|
|
138
|
+
Install for development with `pip install -e ".[dev,docs]"`, then run the tests for your changes with
|
|
139
|
+
`python scripts/run_full_test_suite.py --changed-from HEAD`. [CONTRIBUTING.md](CONTRIBUTING.md) describes the
|
|
140
|
+
workflow, and the [plan](plan.md) shows what is in progress. Questions and bug reports go to the
|
|
141
|
+
[issue tracker](https://github.com/uwplasma/HARTMAX/issues). The code was LMX before 1.5 and LMhdX from 1.5
|
|
142
|
+
to 1.12; `import lmhdx` and `import lmx` are now `import hartmax`.
|
hartmax-2.0.0/README.md
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# HARTMAX
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/hartmax/)
|
|
4
|
+
[](pyproject.toml)
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
[](https://github.com/uwplasma/HARTMAX/actions/workflows/ci.yml)
|
|
7
|
+
[](https://hartmax.readthedocs.io/)
|
|
8
|
+
|
|
9
|
+
**Differentiable liquid-metal MHD in JAX, for the ducts of fusion blankets.**
|
|
10
|
+
|
|
11
|
+
HARTMAX solves liquid metal flowing through strong magnetic fields. It handles ducts and pipes with insulating or
|
|
12
|
+
conducting walls, three-dimensional ducts leaving a magnet, heat transfer through steel walls, and
|
|
13
|
+
quasi-two-dimensional vortex dynamics. Every result is differentiable end to end, so a design study can take
|
|
14
|
+
gradients through the solve. It runs on a CPU or a GPU, and [SOLVAX](https://github.com/uwplasma/SOLVAX) supplies
|
|
15
|
+
the solvers and implicit derivatives.
|
|
16
|
+
|
|
17
|
+

|
|
18
|
+
|
|
19
|
+
## Install and run
|
|
20
|
+
|
|
21
|
+
HARTMAX needs Python 3.11, 3.12 or 3.13. It was called LMhdX until 2.0: `pip install hartmax` replaces
|
|
22
|
+
`pip install lmhdx`, and the [migration guide](https://hartmax.readthedocs.io/en/latest/reference/migration.html)
|
|
23
|
+
lists what changed. The 1.x releases stay on PyPI as `lmhdx`.
|
|
24
|
+
|
|
25
|
+
```console
|
|
26
|
+
pip install hartmax # JAX runs on the CPU; for a GPU follow the JAX installation guide
|
|
27
|
+
hartmax examples/hartmann_case.toml
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
The same case from Python:
|
|
31
|
+
|
|
32
|
+
```python
|
|
33
|
+
import hartmax
|
|
34
|
+
|
|
35
|
+
solution = hartmax.solve(hartmax.duct(100.0, 48, wall_conductance=0.027))
|
|
36
|
+
print(float(solution.velocity[0].data.max()))
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
`solve` takes a `Problem` and a `Solver`, and a TOML file builds the same objects. The
|
|
40
|
+
[first run](https://hartmax.readthedocs.io/en/latest/getting_started/first_run.html) walks through it and checks the
|
|
41
|
+
answer against the exact profile.
|
|
42
|
+
|
|
43
|
+
## What it does
|
|
44
|
+
|
|
45
|
+
- **Fully developed ducts and pipes,** with thin or resolved conducting walls and wall stacks, and meshes chosen from
|
|
46
|
+
the layer thicknesses `a/Ha` and `a/√Ha` rather than from a cell count.
|
|
47
|
+
- **Steady states as roots.** The steady solve is a differentiable root found by conjugate gradients or
|
|
48
|
+
Newton-Krylov, not a march in time.
|
|
49
|
+
- **Three-dimensional and open ducts,** with an inlet and an outlet through a field that varies along them, with or
|
|
50
|
+
without inertia (`method="auto"` picks Newton or marching the Runge-Kutta step).
|
|
51
|
+
- **Runs in time,** by `Solver(method="euler" | "rk3", dt=, steps=)`. An `Output` writes records, ParaView files and
|
|
52
|
+
a summary, and a later run restarts from them bit for bit.
|
|
53
|
+
- **Heat transfer,** with conduction through solid walls, Joule heat and Boussinesq buoyancy.
|
|
54
|
+
- **Quasi-two-dimensional flow** with Hartmann-layer friction, by a spectral time step.
|
|
55
|
+
|
|
56
|
+
## Validation
|
|
57
|
+
|
|
58
|
+

|
|
59
|
+
|
|
60
|
+
HARTMAX is checked against exact solutions, independent spectral references, experiments and other codes, and its
|
|
61
|
+
adjoints against finite differences. The [validation record](https://hartmax.readthedocs.io/en/latest/validation/index.html)
|
|
62
|
+
gives every result with its gate, what is still at the research stage, and the measured speed on a CPU and a GPU.
|
|
63
|
+
|
|
64
|
+
## Examples
|
|
65
|
+
|
|
66
|
+
| Command | Physics |
|
|
67
|
+
|---|---|
|
|
68
|
+
| `hartmax examples/hartmann_case.toml` | Hartmann duct from a TOML file |
|
|
69
|
+
| `hartmax examples/heated_duct.toml` | heated duct with buoyancy |
|
|
70
|
+
| `python examples/hunt_example.py` | conducting walls, side-layer jets |
|
|
71
|
+
| `python examples/fringe_duct_example.py` | duct leaving a magnet, its drop and the drop's field derivative |
|
|
72
|
+
| `python examples/open_duct_inertia_example.py` | inertial share of the fringe drop |
|
|
73
|
+
| `python examples/q2d_turbulence_demo.py` | Q2D vorticity evolution and energy decay |
|
|
74
|
+
| `python examples/duct_design_law.py` | optimum aspect ratio of an insulated duct |
|
|
75
|
+
|
|
76
|
+
[`examples/catalog.toml`](examples/catalog.toml) lists each example's parameters and evidence status, and
|
|
77
|
+
`python scripts/make_showcase_figures.py` regenerates the figures.
|
|
78
|
+
|
|
79
|
+
## Documentation
|
|
80
|
+
|
|
81
|
+
The [documentation](https://hartmax.readthedocs.io/) has
|
|
82
|
+
[getting started](https://hartmax.readthedocs.io/en/latest/getting_started/install.html) guides, step-by-step
|
|
83
|
+
[tutorials](https://hartmax.readthedocs.io/en/latest/tutorials/fully_developed.html), the
|
|
84
|
+
[equations and numerical methods](https://hartmax.readthedocs.io/en/latest/physics/numerics.html), the
|
|
85
|
+
[validation](https://hartmax.readthedocs.io/en/latest/validation/index.html) record and the
|
|
86
|
+
[API reference](https://hartmax.readthedocs.io/en/latest/reference/api.html).
|
|
87
|
+
|
|
88
|
+
## Citing
|
|
89
|
+
|
|
90
|
+
If you use HARTMAX in published work, cite the release you used and the benchmark sources your case relies on.
|
|
91
|
+
[CITATION.cff](CITATION.cff) holds the details, GitHub's "Cite this repository" button exports them, and the
|
|
92
|
+
[references page](https://hartmax.readthedocs.io/en/latest/reference/bibliography.html) has a BibTeX entry.
|
|
93
|
+
|
|
94
|
+
## Contributing
|
|
95
|
+
|
|
96
|
+
Install for development with `pip install -e ".[dev,docs]"`, then run the tests for your changes with
|
|
97
|
+
`python scripts/run_full_test_suite.py --changed-from HEAD`. [CONTRIBUTING.md](CONTRIBUTING.md) describes the
|
|
98
|
+
workflow, and the [plan](plan.md) shows what is in progress. Questions and bug reports go to the
|
|
99
|
+
[issue tracker](https://github.com/uwplasma/HARTMAX/issues). The code was LMX before 1.5 and LMhdX from 1.5
|
|
100
|
+
to 1.12; `import lmhdx` and `import lmx` are now `import hartmax`.
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "hartmax"
|
|
7
|
+
version = "2.0.0"
|
|
8
|
+
description = "JAX-native inductionless MHD toolkit for research, benchmarking, and differentiable simulation"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
authors = [{name = "Rogerio Jorge"}]
|
|
11
|
+
requires-python = ">=3.11,<3.14"
|
|
12
|
+
license = "MIT"
|
|
13
|
+
keywords = ["magnetohydrodynamics", "liquid-metal", "jax", "differentiable-simulation"]
|
|
14
|
+
dependencies = [
|
|
15
|
+
"filelock",
|
|
16
|
+
"jax>=0.7.2",
|
|
17
|
+
"numpy",
|
|
18
|
+
"solvax>=0.36.2,<1",
|
|
19
|
+
]
|
|
20
|
+
classifiers = [
|
|
21
|
+
"Programming Language :: Python :: 3",
|
|
22
|
+
"Programming Language :: Python :: 3.11",
|
|
23
|
+
"Programming Language :: Python :: 3.12",
|
|
24
|
+
"Programming Language :: Python :: 3.13",
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
[project.urls]
|
|
28
|
+
Homepage = "https://github.com/uwplasma/HARTMAX"
|
|
29
|
+
Documentation = "https://hartmax.readthedocs.io/"
|
|
30
|
+
Issues = "https://github.com/uwplasma/HARTMAX/issues"
|
|
31
|
+
Source = "https://github.com/uwplasma/HARTMAX"
|
|
32
|
+
|
|
33
|
+
[project.optional-dependencies]
|
|
34
|
+
dev = [
|
|
35
|
+
"matplotlib",
|
|
36
|
+
"pytest",
|
|
37
|
+
"pytest-cov",
|
|
38
|
+
"pytest-timeout",
|
|
39
|
+
"pytest-xdist",
|
|
40
|
+
"ruff>=0.16,<1",
|
|
41
|
+
]
|
|
42
|
+
docs = [
|
|
43
|
+
"sphinx",
|
|
44
|
+
"myst-parser",
|
|
45
|
+
"furo",
|
|
46
|
+
"sphinx-copybutton",
|
|
47
|
+
"sphinx-design",
|
|
48
|
+
]
|
|
49
|
+
release = [
|
|
50
|
+
"build",
|
|
51
|
+
"twine",
|
|
52
|
+
]
|
|
53
|
+
visualization = [
|
|
54
|
+
"matplotlib",
|
|
55
|
+
]
|
|
56
|
+
|
|
57
|
+
[project.scripts]
|
|
58
|
+
hartmax = "hartmax.cli:main"
|
|
59
|
+
|
|
60
|
+
[tool.setuptools.packages.find]
|
|
61
|
+
where = ["src"]
|
|
62
|
+
include = ["hartmax*"]
|
|
63
|
+
|
|
64
|
+
[tool.setuptools.package-data]
|
|
65
|
+
hartmax = ["py.typed", "data/benchmarks/specs/*.toml", "data/benchmarks/references/*"]
|
|
66
|
+
|
|
67
|
+
[tool.pytest.ini_options]
|
|
68
|
+
addopts = "-ra -q --strict-markers"
|
|
69
|
+
testpaths = ["tests"]
|
|
70
|
+
pythonpath = ["."]
|
|
71
|
+
timeout = 120
|
|
72
|
+
timeout_method = "signal"
|
|
73
|
+
filterwarnings = ["error"]
|
|
74
|
+
markers = [
|
|
75
|
+
"curated: executes the complete curated user workflows",
|
|
76
|
+
"unit: isolated functionality; not a runtime classification",
|
|
77
|
+
"slow: complete workflows scheduled outside pull requests",
|
|
78
|
+
"scheduled: runs for hours; only its own workflow selects it",
|
|
79
|
+
"gpu: requires an actual accelerator",
|
|
80
|
+
"numerical: discretization, solver, conservation, and convergence checks",
|
|
81
|
+
"regression: deterministic golden-profile and serialized-output checks",
|
|
82
|
+
"physics: physics-level invariants for the current solver implementation",
|
|
83
|
+
"validation: validation and parity harness checks",
|
|
84
|
+
"external: requires an external solver, dataset, service, or accelerator",
|
|
85
|
+
]
|
|
86
|
+
|
|
87
|
+
[tool.coverage.run]
|
|
88
|
+
source = ["src/hartmax"]
|
|
89
|
+
branch = true
|
|
90
|
+
|
|
91
|
+
[tool.coverage.report]
|
|
92
|
+
fail_under = 95
|
|
93
|
+
show_missing = true
|
|
94
|
+
skip_covered = true
|
|
95
|
+
exclude_also = [
|
|
96
|
+
"if TYPE_CHECKING:",
|
|
97
|
+
"raise NotImplementedError",
|
|
98
|
+
]
|
|
99
|
+
|
|
100
|
+
[tool.ruff]
|
|
101
|
+
line-length = 110
|
|
102
|
+
target-version = "py311"
|
|
103
|
+
|
|
104
|
+
[tool.ruff.lint]
|
|
105
|
+
select = ["E4", "E7", "E9", "F", "I"]
|
hartmax-2.0.0/setup.cfg
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"""Small, lazy convenience API for HARTMAX.
|
|
2
|
+
|
|
3
|
+
Everything else lives in its named module, for example ``hartmax.axial``,
|
|
4
|
+
``hartmax.units`` and ``hartmax.q2d``. Keeping the package root deliberately
|
|
5
|
+
small makes supported concepts discoverable and avoids importing JAX-heavy
|
|
6
|
+
solver modules until a symbol is used.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import logging
|
|
12
|
+
import os
|
|
13
|
+
from importlib import import_module
|
|
14
|
+
|
|
15
|
+
__all__ = [
|
|
16
|
+
"Problem",
|
|
17
|
+
"Solver",
|
|
18
|
+
"Output",
|
|
19
|
+
"solve",
|
|
20
|
+
"duct",
|
|
21
|
+
"channel",
|
|
22
|
+
"fringe_duct",
|
|
23
|
+
"configure",
|
|
24
|
+
"enable_x64",
|
|
25
|
+
"enable_compilation_cache",
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def enable_x64() -> None:
|
|
30
|
+
"""Enable float64 arrays process-wide; call before constructing meshes or tracing.
|
|
31
|
+
|
|
32
|
+
This also sets JAX's ``jax_default_matmul_precision`` to ``'highest'`` when
|
|
33
|
+
that option is unset. ``'highest'`` is the same level as ``'float32'``.
|
|
34
|
+
Unset, JAX lets Ampere and newer GPUs run float32 matrix products and
|
|
35
|
+
convolutions in TensorFloat-32. On an RTX A4000, float32 contractions then
|
|
36
|
+
differed from float64 by 3e-4 relative. With the pinned precision the
|
|
37
|
+
difference was 2.6-6.1e-7. CPUs and float64 arrays are unaffected.
|
|
38
|
+
|
|
39
|
+
A value the user already chose is kept, whether set through
|
|
40
|
+
``jax.config.update`` or the ``JAX_DEFAULT_MATMUL_PRECISION`` environment
|
|
41
|
+
variable. Constructing a ``ChannelProblem`` or a ``Q2DProblem`` applies the same rule.
|
|
42
|
+
"""
|
|
43
|
+
from jax import config
|
|
44
|
+
|
|
45
|
+
config.update("jax_enable_x64", True)
|
|
46
|
+
_pin_matmul_precision()
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def configure(dtype: str | None = None, gpu_gemm: bool = False) -> None:
|
|
50
|
+
"""Set the process-wide choices that importing the package leaves alone, each announced once on ``hartmax``.
|
|
51
|
+
|
|
52
|
+
``dtype="float64"`` enables float64 and pins the matmul precision (:func:`enable_x64`); ``"float32"``
|
|
53
|
+
keeps JAX as it is. ``gpu_gemm=True`` adds ``--xla_gpu_enable_triton_gemm=false`` to ``XLA_FLAGS`` (cuBLAS
|
|
54
|
+
instead of Triton GEMMs halves the GPU compile of a steady solve, 9.4 s to 4.2 s on an RTX A4000, at about
|
|
55
|
+
10 % warm cost); XLA reads the flag when the GPU backend starts, so call it before the first array is
|
|
56
|
+
made, and a flag the user already set is kept. :func:`hartmax.solve` calls ``configure(dtype=solver.dtype)``.
|
|
57
|
+
"""
|
|
58
|
+
from jax import config
|
|
59
|
+
|
|
60
|
+
if dtype not in (None, "float32", "float64"):
|
|
61
|
+
raise ValueError("dtype is 'float32' or 'float64'")
|
|
62
|
+
if dtype == "float64" and not config.jax_enable_x64:
|
|
63
|
+
enable_x64()
|
|
64
|
+
logging.getLogger("hartmax").info("float64 enabled")
|
|
65
|
+
if gpu_gemm and "xla_gpu_enable_triton_gemm" not in os.environ.get("XLA_FLAGS", ""):
|
|
66
|
+
os.environ["XLA_FLAGS"] = (
|
|
67
|
+
os.environ.get("XLA_FLAGS", "") + " --xla_gpu_enable_triton_gemm=false"
|
|
68
|
+
).strip()
|
|
69
|
+
logging.getLogger("hartmax").info("XLA_FLAGS gained --xla_gpu_enable_triton_gemm=false")
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def _pin_matmul_precision() -> str:
|
|
73
|
+
"""Set ``jax_default_matmul_precision`` to ``'highest'`` if unset; return the value in effect.
|
|
74
|
+
|
|
75
|
+
The option is part of JAX's compilation key, so functions traced before the
|
|
76
|
+
pin are traced again afterwards rather than silently keeping TensorFloat-32.
|
|
77
|
+
"""
|
|
78
|
+
from jax import config
|
|
79
|
+
|
|
80
|
+
if config.jax_default_matmul_precision is None:
|
|
81
|
+
config.update("jax_default_matmul_precision", "highest")
|
|
82
|
+
_enable_default_cache(config)
|
|
83
|
+
return config.jax_default_matmul_precision
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def _enable_default_cache(config) -> None:
|
|
87
|
+
"""Keep compiled solves on disk unless the user chose otherwise, so a new process starts warm.
|
|
88
|
+
|
|
89
|
+
Programs are shared across field values, so a new Hartmann number on the same
|
|
90
|
+
mesh reuses them (compile 4.4 s to 0.45 s on an A4000) at a 35-60 % warm cost.
|
|
91
|
+
Only compiles over one second are kept, in at most 2 GiB. ``HARTMAX_COMPILATION_CACHE=0``
|
|
92
|
+
disables it; a path in it sets the directory. It stays off on macOS with jaxlib
|
|
93
|
+
older than 0.10, which can crash reading back a large cached CPU program.
|
|
94
|
+
"""
|
|
95
|
+
choice = os.environ.get("HARTMAX_COMPILATION_CACHE", "")
|
|
96
|
+
if choice == "0" or config.jax_compilation_cache_dir or _cache_read_unsafe():
|
|
97
|
+
return
|
|
98
|
+
from ._programs import enable_compilation_cache
|
|
99
|
+
|
|
100
|
+
enable_compilation_cache(choice or None, min_compile_time_secs=1.0, share_across_values=True)
|
|
101
|
+
config.update("jax_compilation_cache_max_size", 2**31)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def _cache_read_unsafe() -> bool:
|
|
105
|
+
import platform
|
|
106
|
+
|
|
107
|
+
import jaxlib
|
|
108
|
+
|
|
109
|
+
major, minor = (int(part) for part in jaxlib.__version__.split(".")[:2])
|
|
110
|
+
return platform.system() == "Darwin" and (major, minor) < (0, 10)
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
_EXPORTS = {
|
|
114
|
+
"enable_compilation_cache": ("hartmax._programs", "enable_compilation_cache"),
|
|
115
|
+
"solve": ("hartmax.solver", "solve"),
|
|
116
|
+
"Problem": ("hartmax.problem", "Problem"),
|
|
117
|
+
"channel": ("hartmax.problem", "channel"),
|
|
118
|
+
"duct": ("hartmax.problem", "duct"),
|
|
119
|
+
"fringe_duct": ("hartmax.problem", "fringe_duct"),
|
|
120
|
+
"Solver": ("hartmax.solver", "Solver"),
|
|
121
|
+
"Output": ("hartmax.output", "Output"),
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def __getattr__(name: str):
|
|
126
|
+
"""Load a root export, ``__version__`` or a submodule on first access."""
|
|
127
|
+
|
|
128
|
+
if name == "__version__":
|
|
129
|
+
from importlib.metadata import version
|
|
130
|
+
|
|
131
|
+
value = version("hartmax")
|
|
132
|
+
elif name in _EXPORTS:
|
|
133
|
+
module_name, attr_name = _EXPORTS[name]
|
|
134
|
+
value = getattr(import_module(module_name), attr_name)
|
|
135
|
+
else:
|
|
136
|
+
try:
|
|
137
|
+
value = import_module(f"hartmax.{name}")
|
|
138
|
+
except ModuleNotFoundError as exc:
|
|
139
|
+
raise AttributeError(f"module 'hartmax' has no attribute {name!r}") from exc
|
|
140
|
+
globals()[name] = value
|
|
141
|
+
return value
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def __dir__() -> list[str]:
|
|
145
|
+
"""Return module globals plus the lazy public surface for discovery."""
|
|
146
|
+
|
|
147
|
+
return sorted(set(globals()) | set(__all__))
|