Skip to content

Commit 3c1ed9e

Browse files
authored
Merge branch 'master' into yge/writing-inputfiles
2 parents 5e1b937 + 24aa7b9 commit 3c1ed9e

5 files changed

Lines changed: 104 additions & 7 deletions

File tree

.github/workflows/benchmark.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ jobs:
2121
benchmark:
2222
if: ${{ contains(github.event.pull_request.labels.*.name, 'run_benchmarks') || github.event_name == 'workflow_dispatch' }}
2323
runs-on: ubuntu-latest
24+
permissions:
25+
pull-requests: write # allows posting the benchmark comment on the PR
26+
contents: read # allows checkout; prevents the token from pushing code or modifying workflows if exfiltrated by fork code
27+
actions: read # allows `gh cache list`; all other scopes default to none
2428
env:
2529
GH_TOKEN: ${{ github.token }}
2630
strategy:
@@ -38,6 +42,7 @@ jobs:
3842
- uses: actions/checkout@v7
3943
with:
4044
ref: ${{ github.event.pull_request.head.sha }}
45+
allow-unsafe-pr-checkout: true
4146

4247
- name: Filter changes
4348
id: changes
@@ -50,6 +55,7 @@ jobs:
5055
- 'tests/benchmarks/compare_bench_results.py'
5156
- 'setup.cfg'
5257
- '.github/workflows/benchmark.yml'
58+
- 'requirements.txt'
5359
5460
- name: Check for relevant changes
5561
id: check_changes
@@ -119,6 +125,38 @@ jobs:
119125
if: env.has_changes == 'true'
120126
run: git checkout ${{ github.event.pull_request.head.sha }} -- tests/benchmarks
121127

128+
- name: Remove PR virtual environment before master setup
129+
if: env.has_changes == 'true'
130+
run: rm -rf .venv-${{ env.version }}
131+
132+
- name: Restore Python environment cache
133+
if: env.has_changes == 'true'
134+
id: restore-env2
135+
uses: actions/cache/restore@v5
136+
with:
137+
path: .venv-${{ env.version }}
138+
key: ${{ runner.os }}-venv-${{ env.version }}-${{ hashFiles('devtools/dev-requirements.txt', 'requirements.txt') }}
139+
140+
- name: Set up virtual environment if not restored from cache
141+
if: steps.restore-env2.outputs.cache-hit != 'true' && env.has_changes == 'true'
142+
run: |
143+
gh cache list
144+
python -m venv .venv-${{ env.version }}
145+
source .venv-${{ env.version }}/bin/activate
146+
python -m pip install --upgrade pip
147+
pip install -r devtools/dev-requirements.txt
148+
pip install matplotlib==3.10.8
149+
150+
- name: Action Details
151+
if: env.has_changes == 'true'
152+
run: |
153+
source .venv-${{ env.version }}/bin/activate
154+
which python
155+
python --version
156+
pwd
157+
lscpu
158+
pip list
159+
122160
- name: Benchmark with pytest-benchmark (MASTER)
123161
if: env.has_changes == 'true'
124162
run: |

.github/workflows/memory_benchmark.yml

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ on:
1010
jobs:
1111
memory-benchmark:
1212
runs-on: ubuntu-latest
13+
permissions:
14+
pull-requests: write # allows posting the benchmark comment on the PR
15+
contents: read # allows checkout; prevents the token from pushing code or modifying workflows if exfiltrated by fork code
16+
actions: read # allows `gh cache list`; all other scopes default to none
1317
env:
1418
GH_TOKEN: ${{ github.token }}
1519
strategy:
@@ -20,6 +24,7 @@ jobs:
2024
- uses: actions/checkout@v7
2125
with:
2226
ref: ${{ github.event.pull_request.head.sha }}
27+
allow-unsafe-pr-checkout: true
2328

2429
- name: Filter changes
2530
id: changes
@@ -32,7 +37,7 @@ jobs:
3237
- 'requirements.txt'
3338
- 'devtools/dev-requirements.txt'
3439
- 'setup.cfg'
35-
- '.github/workflows/memory_benchmarks.yml'
40+
- '.github/workflows/memory_benchmark.yml'
3641
3742
- name: Check for relevant changes
3843
id: check_changes
@@ -103,6 +108,38 @@ jobs:
103108
if: env.has_changes == 'true'
104109
run: git checkout ${{ github.event.pull_request.head.sha }} -- tests/benchmarks
105110

111+
- name: Remove PR virtual environment before master setup
112+
if: env.has_changes == 'true'
113+
run: rm -rf .venv-${{ env.version }}
114+
115+
- name: Restore Python environment cache
116+
if: env.has_changes == 'true'
117+
id: restore-env2
118+
uses: actions/cache/restore@v5
119+
with:
120+
path: .venv-${{ env.version }}
121+
key: ${{ runner.os }}-venv-${{ env.version }}-${{ hashFiles('devtools/dev-requirements.txt', 'requirements.txt') }}
122+
123+
- name: Set up virtual environment if not restored from cache
124+
if: steps.restore-env2.outputs.cache-hit != 'true' && env.has_changes == 'true'
125+
run: |
126+
gh cache list
127+
python -m venv .venv-${{ env.version }}
128+
source .venv-${{ env.version }}/bin/activate
129+
python -m pip install --upgrade pip
130+
pip install -r devtools/dev-requirements.txt
131+
pip install matplotlib==3.10.8
132+
133+
- name: Action Details
134+
if: env.has_changes == 'true'
135+
run: |
136+
source .venv-${{ env.version }}/bin/activate
137+
which python
138+
python --version
139+
pwd
140+
lscpu
141+
pip list
142+
106143
- name: Benchmark with pytest-benchmark (MASTER)
107144
if: env.has_changes == 'true'
108145
run: |

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ Performance Improvements
88
Bug Fixes
99

1010
- Fixes bug that was always setting NFP=1 in ``to_FourierRZ`` methods.
11+
- Fixes ``VMECIO.save`` metadata for current-density variables and corrects the
12+
asymmetric ``currvmns`` magnetic-axis extrapolation.
1113

1214

1315
v0.17.2

desc/vmec.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,11 @@ def load(
5353
boundary is loaded and the DESC Equilibrium R,Z are constrained to
5454
match the given VMEC boundary.
5555
56-
NOTE: This is only a fit, so the DESC Equilibrium returned is not
57-
expected to be in force balance. It is recommended to solve the
58-
Equilibrium once loaded before using the Equilibrium for any
59-
analysis.
56+
NOTE: This is only a fit of the VMEC R, Z and lambda, so the DESC
57+
Equilibrium returned is not expected to be in force balance. It is
58+
recommended to solve the Equilibrium once loaded before using the
59+
Equilibrium for any analysis or computing any derived quantities in
60+
DESC (e.g. anything that is not just R, Z or lambda).
6061
6162
Parameters
6263
----------
@@ -734,7 +735,7 @@ def save( # noqa: C901
734735
jcuru[0] = 0
735736

736737
jcurv = file.createVariable("jcurv", np.float64, ("radius",))
737-
jcuru.long_name = "flux surface average of sqrt(g)*J^zeta, on full mesh"
738+
jcurv.long_name = "flux surface average of sqrt(g)*J^zeta, on full mesh"
738739
jcurv.units = "A/m^3"
739740
jcurv[:] = surface_averages(
740741
grid_full,
@@ -1331,7 +1332,7 @@ def fullfit(x):
13311332
# TODO (#1379): evaluate current at rho=0 nodes instead of extrapolation
13321333
if not eq.sym:
13331334
currvmns[:, :] = -s
1334-
currumns[0, :] = -(
1335+
currvmns[0, :] = -(
13351336
s[1, :] - (s[2, :] - s[1, :]) / (s_full[2] - s_full[1]) * s_full[1]
13361337
)
13371338
timer.stop("J^zeta*sqrt(g)")

tests/test_vmec.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,25 @@ def test_vmec_save_asym(VMEC_save_asym):
10271027
np.testing.assert_allclose(
10281028
vmec.variables["jcurv"][20:100], desc.variables["jcurv"][20:100], rtol=2
10291029
)
1030+
assert desc.variables["jcuru"].long_name == (
1031+
"flux surface average of sqrt(g)*J^theta, on full mesh"
1032+
)
1033+
assert desc.variables["jcurv"].long_name == (
1034+
"flux surface average of sqrt(g)*J^zeta, on full mesh"
1035+
)
1036+
s_full = np.linspace(0, 1, desc.dimensions["radius"].size)
1037+
expected_currumns_axis = desc.variables["currumns"][1, :] - (
1038+
(desc.variables["currumns"][2, :] - desc.variables["currumns"][1, :])
1039+
/ (s_full[2] - s_full[1])
1040+
* s_full[1]
1041+
)
1042+
expected_currvmns_axis = desc.variables["currvmns"][1, :] - (
1043+
(desc.variables["currvmns"][2, :] - desc.variables["currvmns"][1, :])
1044+
/ (s_full[2] - s_full[1])
1045+
* s_full[1]
1046+
)
1047+
np.testing.assert_allclose(desc.variables["currumns"][0, :], expected_currumns_axis)
1048+
np.testing.assert_allclose(desc.variables["currvmns"][0, :], expected_currvmns_axis)
10301049
np.testing.assert_allclose(
10311050
vmec.variables["DShear"][20:100], desc.variables["DShear"][20:100], rtol=6e-2
10321051
)

0 commit comments

Comments
 (0)