simpok 0.1.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.
- simpok-0.1.0/.gitignore +15 -0
- simpok-0.1.0/LICENSE +21 -0
- simpok-0.1.0/PKG-INFO +173 -0
- simpok-0.1.0/README.md +144 -0
- simpok-0.1.0/examples/chc_quickstart.py +43 -0
- simpok-0.1.0/examples/quickstart.py +8 -0
- simpok-0.1.0/examples/tdgl_quickstart.py +42 -0
- simpok-0.1.0/pyproject.toml +55 -0
- simpok-0.1.0/simpok/__init__.py +6 -0
- simpok-0.1.0/simpok/_core_mojo/__init__.mojo +3 -0
- simpok-0.1.0/simpok/_core_mojo/_chc.mojo +336 -0
- simpok-0.1.0/simpok/_core_mojo/_tdgl.mojo +290 -0
- simpok-0.1.0/simpok/_core_mojo/_utils.mojo +49 -0
- simpok-0.1.0/simpok/_result.py +55 -0
- simpok-0.1.0/simpok/chc.py +131 -0
- simpok-0.1.0/simpok/device.py +16 -0
- simpok-0.1.0/simpok/mojo_module.mojo +71 -0
- simpok-0.1.0/simpok/tdgl.py +128 -0
simpok-0.1.0/.gitignore
ADDED
simpok-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Vijay Yadav
|
|
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.
|
simpok-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: simpok
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: High-level Python API for phase-ordering kinetics, with the computation in Mojo
|
|
5
|
+
Project-URL: Homepage, https://github.com/ivijayyadav/simpok
|
|
6
|
+
Project-URL: Repository, https://github.com/ivijayyadav/simpok
|
|
7
|
+
Project-URL: Issues, https://github.com/ivijayyadav/simpok/issues
|
|
8
|
+
Author-email: vijay <vijpiml@gmail.com>
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: cahn-hilliard,ginzburg-landau,gpu,mojo,phase-field,phase-ordering,spinodal-decomposition
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: Operating System :: MacOS :: MacOS X
|
|
15
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Topic :: Scientific/Engineering :: Physics
|
|
22
|
+
Requires-Python: >=3.10
|
|
23
|
+
Requires-Dist: max<27,>=26.5
|
|
24
|
+
Requires-Dist: mojo<2,>=1.0
|
|
25
|
+
Requires-Dist: numpy>=1.24
|
|
26
|
+
Provides-Extra: examples
|
|
27
|
+
Requires-Dist: matplotlib>=3.8; extra == 'examples'
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
|
|
30
|
+
# simpok
|
|
31
|
+
|
|
32
|
+
Phase-ordering kinetics in Python, with the computation in [Mojo](https://www.modular.com/mojo).
|
|
33
|
+
|
|
34
|
+
You write ordinary Python; the solvers run on your GPU if you have one, and on the CPU
|
|
35
|
+
otherwise, from the same code. The intent is to keep the modelling in a high-level API and push
|
|
36
|
+
the per-site arithmetic down to Mojo.
|
|
37
|
+
|
|
38
|
+
> **Status: alpha.** Two solvers, 2-d only, 5-point Laplacian, periodic boundaries. The API may
|
|
39
|
+
> still change.
|
|
40
|
+
|
|
41
|
+
## Install
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
pip install simpok
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Python 3.10+. The Mojo toolchain arrives as a dependency — there is nothing else to install, and
|
|
48
|
+
no compiler to set up by hand.
|
|
49
|
+
|
|
50
|
+
**The first `import simpok` takes about 20 seconds.** It is compiling the Mojo sources for your
|
|
51
|
+
machine; the result is cached and every later import is instant. It recompiles only when the
|
|
52
|
+
package is upgraded. This is deliberate rather than a packaging shortcut: whether an accelerator
|
|
53
|
+
is targeted is decided at Mojo compile time, so building on your machine is what lets one
|
|
54
|
+
universal wheel use whatever hardware you actually have.
|
|
55
|
+
|
|
56
|
+
## Quick start
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
from simpok import TDGL
|
|
60
|
+
|
|
61
|
+
sim = TDGL().ic(seed=0)
|
|
62
|
+
snaps, meta = sim.run(steps=90000, nevery=1000)
|
|
63
|
+
|
|
64
|
+
print(snaps.shape) # (90, 256, 256)
|
|
65
|
+
print(meta["backend"]) # 'accelerator' or 'cpu'
|
|
66
|
+
print(meta["times"][-1]) # 9000.0
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
`run` returns a `Result` — a named tuple of `snaps` (a `(nsnap, n, n)` NumPy array) and `meta`
|
|
70
|
+
(a dict of every parameter used, plus `times`, `backend`, `device` and `elapsed`).
|
|
71
|
+
|
|
72
|
+
Conserved dynamics works the same way:
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
from simpok import CHC
|
|
76
|
+
|
|
77
|
+
snaps, meta = CHC().ic(seed=0, psi0=-0.4).run(steps=50000, nevery=500)
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Check what you're running on:
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
from simpok import get_device
|
|
84
|
+
print(get_device()) # Device(available=True, name='NVIDIA RTX A5000', reason=None)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## The models
|
|
88
|
+
|
|
89
|
+
**`TDGL`** — nonconserved scalar order parameter (Model A). Domain coarsening in a quenched
|
|
90
|
+
ferromagnet; the Allen–Cahn growth law `L(t) ~ t^(1/2)`.
|
|
91
|
+
|
|
92
|
+
```
|
|
93
|
+
∂ψ/∂t = ψ − ψ³ + h + ∇²ψ + θ
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
**`CHC`** — conserved scalar order parameter (Model B). Spinodal decomposition in a binary
|
|
97
|
+
mixture; the Lifshitz–Slyozov growth law `L(t) ~ t^(1/3)`. The mean of ψ is conserved exactly,
|
|
98
|
+
so `psi0` sets the composition — `0.0` gives the bicontinuous critical quench, `-0.4` gives
|
|
99
|
+
minority droplets.
|
|
100
|
+
|
|
101
|
+
```
|
|
102
|
+
∂ψ/∂t = −∇²(ψ − ψ³ + ∇²ψ) + ∇·θ
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Thermal noise is off by default (`eps=0`) — it is asymptotically irrelevant to
|
|
106
|
+
the growth laws. Set `eps > 0` to switch it on; for `CHC` it is applied as a bond-centred current
|
|
107
|
+
so that conservation stays exact to round-off.
|
|
108
|
+
|
|
109
|
+
## API
|
|
110
|
+
|
|
111
|
+
```python
|
|
112
|
+
TDGL(n=256, dx=1.0, dt=0.1, h=0.0, eps=0.0, dtype=np.float64, device="auto")
|
|
113
|
+
CHC (n=256, dx=1.0, dt=0.01, eps=0.0, dtype=np.float64, device="auto")
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
| Method | |
|
|
117
|
+
|---|---|
|
|
118
|
+
| `.ic(seed=0, amplitude=0.01)` | random initial condition; `CHC` also takes `psi0=0.0`. Returns `self`, so it chains. |
|
|
119
|
+
| `.run(steps, nevery)` | evolve `steps` steps, saving every `nevery`. Returns `Result(snaps, meta)`. |
|
|
120
|
+
| `.t` | current simulation time |
|
|
121
|
+
| `.psi` | current field, carried across calls — successive `run` calls continue the trajectory |
|
|
122
|
+
|
|
123
|
+
`device` is `"auto"` (default), `"accelerator"`, or `"cpu"`. `"accelerator"` raises if none is
|
|
124
|
+
usable rather than silently falling back. `dtype` is `float64` (default) or `float32`.
|
|
125
|
+
|
|
126
|
+
Timesteps are checked against the explicit-Euler stability limit at construction — `dt <= dx²/4`
|
|
127
|
+
for `TDGL`, and the much tighter fourth-order bound for `CHC`, which is why its default `dt` is
|
|
128
|
+
ten times smaller.
|
|
129
|
+
|
|
130
|
+
## Hardware notes
|
|
131
|
+
|
|
132
|
+
- **NVIDIA** — both dtypes work.
|
|
133
|
+
- **Apple Silicon** — Metal has no float64 at all, so use `dtype=np.float32` to run on the GPU.
|
|
134
|
+
A float64 run falls back to the CPU automatically; asking for `device="accelerator"` with
|
|
135
|
+
float64 raises with an explanation.
|
|
136
|
+
- **No GPU** — everything runs on the CPU with identical results. Deterministic (`eps=0`) runs
|
|
137
|
+
are bit-identical between CPU and accelerator.
|
|
138
|
+
|
|
139
|
+
On float32, `CHC` is several times faster than float64 on consumer NVIDIA cards, whose
|
|
140
|
+
double-precision throughput is heavily reduced; the domain length scale agrees with float64 to
|
|
141
|
+
better than 0.01%. `TDGL` at small grids is limited by kernel-launch overhead rather than
|
|
142
|
+
arithmetic, so larger lattices use the GPU far more efficiently than small ones.
|
|
143
|
+
|
|
144
|
+
## Correctness
|
|
145
|
+
|
|
146
|
+
Both solvers are checked against analytic results, not just for plausibility:
|
|
147
|
+
|
|
148
|
+
- equilibrium interface `tanh(z/√2)`, second-order convergent in `dx`
|
|
149
|
+
- `TDGL`: droplet collapse `dR²/dt = −2(d−1)`; the `t^(1/2)` growth law
|
|
150
|
+
- `CHC`: the Cahn dispersion relation `σ(q) = q − q²` reproduced to 1 part in 10¹⁰; the mean
|
|
151
|
+
conserved to 1 part in 10¹⁷; the `t^(1/3)` growth law
|
|
152
|
+
- conserved noise verified against the discrete fluctuation–dissipation relation
|
|
153
|
+
- seed reproducibility, resumability, and CPU/accelerator agreement
|
|
154
|
+
|
|
155
|
+
## Examples
|
|
156
|
+
|
|
157
|
+
`examples/` contains runnable scripts that produce snapshot figures:
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
python -m examples.tdgl_quickstart # writes tdgl.png
|
|
161
|
+
python -m examples.chc_quickstart # writes chc.png
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
They need matplotlib: `pip install simpok[examples]`.
|
|
165
|
+
|
|
166
|
+
## Reference
|
|
167
|
+
|
|
168
|
+
Sanjay Puri, "Kinetics of Phase Transitions", Ch. 1 in *Kinetics of Phase Transitions*,
|
|
169
|
+
S. Puri and V. Wadhawan (eds.), CRC Press (2009).
|
|
170
|
+
|
|
171
|
+
## License
|
|
172
|
+
|
|
173
|
+
MIT — see [LICENSE](LICENSE).
|
simpok-0.1.0/README.md
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# simpok
|
|
2
|
+
|
|
3
|
+
Phase-ordering kinetics in Python, with the computation in [Mojo](https://www.modular.com/mojo).
|
|
4
|
+
|
|
5
|
+
You write ordinary Python; the solvers run on your GPU if you have one, and on the CPU
|
|
6
|
+
otherwise, from the same code. The intent is to keep the modelling in a high-level API and push
|
|
7
|
+
the per-site arithmetic down to Mojo.
|
|
8
|
+
|
|
9
|
+
> **Status: alpha.** Two solvers, 2-d only, 5-point Laplacian, periodic boundaries. The API may
|
|
10
|
+
> still change.
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pip install simpok
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Python 3.10+. The Mojo toolchain arrives as a dependency — there is nothing else to install, and
|
|
19
|
+
no compiler to set up by hand.
|
|
20
|
+
|
|
21
|
+
**The first `import simpok` takes about 20 seconds.** It is compiling the Mojo sources for your
|
|
22
|
+
machine; the result is cached and every later import is instant. It recompiles only when the
|
|
23
|
+
package is upgraded. This is deliberate rather than a packaging shortcut: whether an accelerator
|
|
24
|
+
is targeted is decided at Mojo compile time, so building on your machine is what lets one
|
|
25
|
+
universal wheel use whatever hardware you actually have.
|
|
26
|
+
|
|
27
|
+
## Quick start
|
|
28
|
+
|
|
29
|
+
```python
|
|
30
|
+
from simpok import TDGL
|
|
31
|
+
|
|
32
|
+
sim = TDGL().ic(seed=0)
|
|
33
|
+
snaps, meta = sim.run(steps=90000, nevery=1000)
|
|
34
|
+
|
|
35
|
+
print(snaps.shape) # (90, 256, 256)
|
|
36
|
+
print(meta["backend"]) # 'accelerator' or 'cpu'
|
|
37
|
+
print(meta["times"][-1]) # 9000.0
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
`run` returns a `Result` — a named tuple of `snaps` (a `(nsnap, n, n)` NumPy array) and `meta`
|
|
41
|
+
(a dict of every parameter used, plus `times`, `backend`, `device` and `elapsed`).
|
|
42
|
+
|
|
43
|
+
Conserved dynamics works the same way:
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
from simpok import CHC
|
|
47
|
+
|
|
48
|
+
snaps, meta = CHC().ic(seed=0, psi0=-0.4).run(steps=50000, nevery=500)
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Check what you're running on:
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
from simpok import get_device
|
|
55
|
+
print(get_device()) # Device(available=True, name='NVIDIA RTX A5000', reason=None)
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## The models
|
|
59
|
+
|
|
60
|
+
**`TDGL`** — nonconserved scalar order parameter (Model A). Domain coarsening in a quenched
|
|
61
|
+
ferromagnet; the Allen–Cahn growth law `L(t) ~ t^(1/2)`.
|
|
62
|
+
|
|
63
|
+
```
|
|
64
|
+
∂ψ/∂t = ψ − ψ³ + h + ∇²ψ + θ
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
**`CHC`** — conserved scalar order parameter (Model B). Spinodal decomposition in a binary
|
|
68
|
+
mixture; the Lifshitz–Slyozov growth law `L(t) ~ t^(1/3)`. The mean of ψ is conserved exactly,
|
|
69
|
+
so `psi0` sets the composition — `0.0` gives the bicontinuous critical quench, `-0.4` gives
|
|
70
|
+
minority droplets.
|
|
71
|
+
|
|
72
|
+
```
|
|
73
|
+
∂ψ/∂t = −∇²(ψ − ψ³ + ∇²ψ) + ∇·θ
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Thermal noise is off by default (`eps=0`) — it is asymptotically irrelevant to
|
|
77
|
+
the growth laws. Set `eps > 0` to switch it on; for `CHC` it is applied as a bond-centred current
|
|
78
|
+
so that conservation stays exact to round-off.
|
|
79
|
+
|
|
80
|
+
## API
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
TDGL(n=256, dx=1.0, dt=0.1, h=0.0, eps=0.0, dtype=np.float64, device="auto")
|
|
84
|
+
CHC (n=256, dx=1.0, dt=0.01, eps=0.0, dtype=np.float64, device="auto")
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
| Method | |
|
|
88
|
+
|---|---|
|
|
89
|
+
| `.ic(seed=0, amplitude=0.01)` | random initial condition; `CHC` also takes `psi0=0.0`. Returns `self`, so it chains. |
|
|
90
|
+
| `.run(steps, nevery)` | evolve `steps` steps, saving every `nevery`. Returns `Result(snaps, meta)`. |
|
|
91
|
+
| `.t` | current simulation time |
|
|
92
|
+
| `.psi` | current field, carried across calls — successive `run` calls continue the trajectory |
|
|
93
|
+
|
|
94
|
+
`device` is `"auto"` (default), `"accelerator"`, or `"cpu"`. `"accelerator"` raises if none is
|
|
95
|
+
usable rather than silently falling back. `dtype` is `float64` (default) or `float32`.
|
|
96
|
+
|
|
97
|
+
Timesteps are checked against the explicit-Euler stability limit at construction — `dt <= dx²/4`
|
|
98
|
+
for `TDGL`, and the much tighter fourth-order bound for `CHC`, which is why its default `dt` is
|
|
99
|
+
ten times smaller.
|
|
100
|
+
|
|
101
|
+
## Hardware notes
|
|
102
|
+
|
|
103
|
+
- **NVIDIA** — both dtypes work.
|
|
104
|
+
- **Apple Silicon** — Metal has no float64 at all, so use `dtype=np.float32` to run on the GPU.
|
|
105
|
+
A float64 run falls back to the CPU automatically; asking for `device="accelerator"` with
|
|
106
|
+
float64 raises with an explanation.
|
|
107
|
+
- **No GPU** — everything runs on the CPU with identical results. Deterministic (`eps=0`) runs
|
|
108
|
+
are bit-identical between CPU and accelerator.
|
|
109
|
+
|
|
110
|
+
On float32, `CHC` is several times faster than float64 on consumer NVIDIA cards, whose
|
|
111
|
+
double-precision throughput is heavily reduced; the domain length scale agrees with float64 to
|
|
112
|
+
better than 0.01%. `TDGL` at small grids is limited by kernel-launch overhead rather than
|
|
113
|
+
arithmetic, so larger lattices use the GPU far more efficiently than small ones.
|
|
114
|
+
|
|
115
|
+
## Correctness
|
|
116
|
+
|
|
117
|
+
Both solvers are checked against analytic results, not just for plausibility:
|
|
118
|
+
|
|
119
|
+
- equilibrium interface `tanh(z/√2)`, second-order convergent in `dx`
|
|
120
|
+
- `TDGL`: droplet collapse `dR²/dt = −2(d−1)`; the `t^(1/2)` growth law
|
|
121
|
+
- `CHC`: the Cahn dispersion relation `σ(q) = q − q²` reproduced to 1 part in 10¹⁰; the mean
|
|
122
|
+
conserved to 1 part in 10¹⁷; the `t^(1/3)` growth law
|
|
123
|
+
- conserved noise verified against the discrete fluctuation–dissipation relation
|
|
124
|
+
- seed reproducibility, resumability, and CPU/accelerator agreement
|
|
125
|
+
|
|
126
|
+
## Examples
|
|
127
|
+
|
|
128
|
+
`examples/` contains runnable scripts that produce snapshot figures:
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
python -m examples.tdgl_quickstart # writes tdgl.png
|
|
132
|
+
python -m examples.chc_quickstart # writes chc.png
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
They need matplotlib: `pip install simpok[examples]`.
|
|
136
|
+
|
|
137
|
+
## Reference
|
|
138
|
+
|
|
139
|
+
Sanjay Puri, "Kinetics of Phase Transitions", Ch. 1 in *Kinetics of Phase Transitions*,
|
|
140
|
+
S. Puri and V. Wadhawan (eds.), CRC Press (2009).
|
|
141
|
+
|
|
142
|
+
## License
|
|
143
|
+
|
|
144
|
+
MIT — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import matplotlib
|
|
3
|
+
matplotlib.use("Agg")
|
|
4
|
+
import matplotlib.pyplot as plt
|
|
5
|
+
from simpok import CHC
|
|
6
|
+
import numpy as np
|
|
7
|
+
|
|
8
|
+
steps = 500000
|
|
9
|
+
nevery = 5000
|
|
10
|
+
device = "auto"
|
|
11
|
+
|
|
12
|
+
sim = CHC(device=device).ic(seed=0)
|
|
13
|
+
snaps, meta = sim.run(steps=steps, nevery=nevery)
|
|
14
|
+
|
|
15
|
+
t = meta["times"]
|
|
16
|
+
|
|
17
|
+
for key in ("solver", "backend", "device", "dtype", "n", "dx", "dt",
|
|
18
|
+
"eps", "psi0", "seed", "steps", "nevery", "device_request"):
|
|
19
|
+
print(f"{key:<14}: {meta[key]}")
|
|
20
|
+
|
|
21
|
+
print(f"{'snapshots':<14}: {snaps.shape}")
|
|
22
|
+
print(f"{'elapsed':<14}: {meta['elapsed']:.3f} s (includes first-call warmup)")
|
|
23
|
+
|
|
24
|
+
fig, axes = plt.subplots(1, 4, figsize=(10, 2.9))
|
|
25
|
+
n_snaps = snaps.shape[0]
|
|
26
|
+
for ax, k in zip(axes, (4, 19, 49, n_snaps-1)):
|
|
27
|
+
im = ax.imshow(
|
|
28
|
+
snaps[k], cmap="RdBu_r", vmin=-1, vmax=1, interpolation="nearest"
|
|
29
|
+
)
|
|
30
|
+
ax.set_title(f"$t = {t[k]:.0f}$", fontsize=11)
|
|
31
|
+
ax.set_xticks([])
|
|
32
|
+
ax.set_yticks([])
|
|
33
|
+
|
|
34
|
+
cbar = fig.colorbar(
|
|
35
|
+
im, ax=axes, orientation="vertical", fraction=0.02, pad=0.012,
|
|
36
|
+
ticks=[-1, 0, 1],
|
|
37
|
+
)
|
|
38
|
+
cbar.set_label(r"$\psi$", fontsize=11, rotation=0, labelpad=10)
|
|
39
|
+
cbar.ax.tick_params(labelsize=9)
|
|
40
|
+
|
|
41
|
+
out = os.path.abspath("chc.png")
|
|
42
|
+
fig.savefig(out, dpi=150, bbox_inches="tight")
|
|
43
|
+
print(f"\nwrote {out}")
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import matplotlib
|
|
3
|
+
matplotlib.use("Agg")
|
|
4
|
+
import matplotlib.pyplot as plt
|
|
5
|
+
from simpok import TDGL
|
|
6
|
+
import numpy as np
|
|
7
|
+
|
|
8
|
+
steps = 90000
|
|
9
|
+
nevery = 1000
|
|
10
|
+
|
|
11
|
+
sim = TDGL().ic(seed=0)
|
|
12
|
+
snaps, meta = sim.run(steps=steps, nevery=nevery)
|
|
13
|
+
|
|
14
|
+
t = meta["times"]
|
|
15
|
+
|
|
16
|
+
for key in ("solver", "backend", "device", "dtype", "n", "dx", "dt",
|
|
17
|
+
"eps", "seed", "steps", "nevery", "device_request"):
|
|
18
|
+
print(f"{key:<14}: {meta[key]}")
|
|
19
|
+
|
|
20
|
+
print(f"{'snapshots':<14}: {snaps.shape}")
|
|
21
|
+
print(f"{'elapsed':<14}: {meta['elapsed']:.3f} s (includes first-call warmup)")
|
|
22
|
+
|
|
23
|
+
fig, axes = plt.subplots(1, 4, figsize=(10, 2.9))
|
|
24
|
+
n_snaps = snaps.shape[0]
|
|
25
|
+
for ax, k in zip(axes, (0, 4, 19, n_snaps-1)):
|
|
26
|
+
im = ax.imshow(
|
|
27
|
+
snaps[k], cmap="RdBu_r", vmin=-1, vmax=1, interpolation="nearest"
|
|
28
|
+
)
|
|
29
|
+
ax.set_title(f"$t = {t[k]:.0f}$", fontsize=11)
|
|
30
|
+
ax.set_xticks([])
|
|
31
|
+
ax.set_yticks([])
|
|
32
|
+
|
|
33
|
+
cbar = fig.colorbar(
|
|
34
|
+
im, ax=axes, orientation="vertical", fraction=0.02, pad=0.012,
|
|
35
|
+
ticks=[-1, 0, 1],
|
|
36
|
+
)
|
|
37
|
+
cbar.set_label(r"$\psi$", fontsize=11, rotation=0, labelpad=10)
|
|
38
|
+
cbar.ax.tick_params(labelsize=9)
|
|
39
|
+
|
|
40
|
+
out = os.path.abspath("tdgl.png")
|
|
41
|
+
fig.savefig(out, dpi=150, bbox_inches="tight")
|
|
42
|
+
print(f"\nwrote {out}")
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "simpok"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "High-level Python API for phase-ordering kinetics, with the computation in Mojo"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
authors = [{ name = "vijay", email = "vijpiml@gmail.com" }]
|
|
12
|
+
license = "MIT"
|
|
13
|
+
license-files = ["LICENSE"]
|
|
14
|
+
keywords = [
|
|
15
|
+
"phase-field",
|
|
16
|
+
"phase-ordering",
|
|
17
|
+
"spinodal-decomposition",
|
|
18
|
+
"cahn-hilliard",
|
|
19
|
+
"ginzburg-landau",
|
|
20
|
+
"mojo",
|
|
21
|
+
"gpu",
|
|
22
|
+
]
|
|
23
|
+
classifiers = [
|
|
24
|
+
"Development Status :: 3 - Alpha",
|
|
25
|
+
"Intended Audience :: Science/Research",
|
|
26
|
+
"Programming Language :: Python :: 3",
|
|
27
|
+
"Programming Language :: Python :: 3.10",
|
|
28
|
+
"Programming Language :: Python :: 3.11",
|
|
29
|
+
"Programming Language :: Python :: 3.12",
|
|
30
|
+
"Programming Language :: Python :: 3.13",
|
|
31
|
+
"Topic :: Scientific/Engineering :: Physics",
|
|
32
|
+
"Operating System :: POSIX :: Linux",
|
|
33
|
+
"Operating System :: MacOS :: MacOS X",
|
|
34
|
+
]
|
|
35
|
+
dependencies = [
|
|
36
|
+
"numpy>=1.24",
|
|
37
|
+
"mojo>=1.0,<2",
|
|
38
|
+
"max>=26.5,<27",
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
[project.optional-dependencies]
|
|
42
|
+
examples = ["matplotlib>=3.8"]
|
|
43
|
+
|
|
44
|
+
[project.urls]
|
|
45
|
+
Homepage = "https://github.com/ivijayyadav/simpok"
|
|
46
|
+
Repository = "https://github.com/ivijayyadav/simpok"
|
|
47
|
+
Issues = "https://github.com/ivijayyadav/simpok/issues"
|
|
48
|
+
|
|
49
|
+
[tool.hatch.build.targets.wheel]
|
|
50
|
+
packages = ["simpok"]
|
|
51
|
+
exclude = ["__mojocache__", "__pycache__"]
|
|
52
|
+
|
|
53
|
+
[tool.hatch.build.targets.sdist]
|
|
54
|
+
include = ["simpok", "examples", "README.md", "pyproject.toml"]
|
|
55
|
+
exclude = ["__mojocache__", "__pycache__"]
|