Skip to content

Commit

Permalink
Merge branch 'master' into dp/nangrad-bdryerr-coils
Browse files Browse the repository at this point in the history
  • Loading branch information
YigitElma authored Dec 12, 2024
2 parents e8726db + 7778894 commit 4b00cd2
Show file tree
Hide file tree
Showing 51 changed files with 221 additions and 196 deletions.
30 changes: 30 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,36 @@ updates:
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
groups:
# group similar dependencies together into fewer PRs
docs:
patterns:
- "sphinx"
linting:
patterns:
- "flake8"
- "black"
- "pre-commit"
testing:
patterns:
- "pytest"
- "qic"
- "qsc"
- "shapely"
minor_packages:
patterns:
- "colorama"
- "nvgpu"
- "psutil"
- "pylatexenc"
- "termcolor"
jax:
patterns:
- "jax"
- "diffrax"
- "interpax"
- "orthax"
- "quadax"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
Expand Down
75 changes: 75 additions & 0 deletions .github/workflows/update_notebook_examples.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Update Notebooks and Examples
on:
schedule:
# runs on the first of every month at noon
- cron: '00 12 1 * *'

jobs:
create_issue:
name: Create issues to update notebooks and examples
runs-on: ubuntu-latest
permissions:
issues: write
steps:
- name: Create issue to update notebooks
run: |
if [[ $CLOSE_PREVIOUS == true ]]; then
previous_issue_number=$(gh issue list \
--label "$LABELS" \
--json number \
--jq '.[0].number')
if [[ -n $previous_issue_number ]]; then
gh issue close "$previous_issue_number"
gh issue unpin "$previous_issue_number"
fi
fi
new_issue_url=$(gh issue create \
--title "$TITLE" \
--assignee "$ASSIGNEES" \
--label "$LABELS" \
--body "$BODY")
if [[ $PINNED == true ]]; then
gh issue pin "$new_issue_url"
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
TITLE: Update Notebooks
ASSIGNEES: f0uriest, dpanici, ddudt, rahulgaur104, kianorr, YigitElma
LABELS: monthly_update_notebooks
BODY: |
Reminder to check that notebooks evaluate correctly, and to update
if necessary.
PINNED: false
CLOSE_PREVIOUS: true
- name: Create issue to update notebooks
run: |
if [[ $CLOSE_PREVIOUS == true ]]; then
previous_issue_number=$(gh issue list \
--label "$LABELS" \
--json number \
--jq '.[0].number')
if [[ -n $previous_issue_number ]]; then
gh issue close "$previous_issue_number"
gh issue unpin "$previous_issue_number"
fi
fi
new_issue_url=$(gh issue create \
--title "$TITLE" \
--assignee "$ASSIGNEES" \
--label "$LABELS" \
--body "$BODY")
if [[ $PINNED == true ]]; then
gh issue pin "$new_issue_url"
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
TITLE: Update Examples
ASSIGNEES: f0uriest, dpanici, ddudt, rahulgaur104, kianorr, YigitElma
LABELS: monthly_update_examples
BODY: |
Reminder to check that examples run correctly, and to update
if necessary.
PINNED: false
CLOSE_PREVIOUS: true
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
repos:
- repo: https://github.com/psf/black
rev: 24.3.0
rev: 24.10.0
hooks:
- id: black-jupyter
log_file: devtools/pre-commit.log
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
rev: v5.0.0
hooks:
- id: check-added-large-files
log_file: devtools/pre-commit.log
Expand All @@ -22,20 +22,20 @@ repos:
- id: no-commit-to-branch
log_file: devtools/pre-commit.log
- repo: https://github.com/pycqa/isort
rev: 5.12.0
rev: 5.13.2
hooks:
- id: isort
name: isort (python)
args: ["--profile", "black"]
log_file: devtools/pre-commit.log
- repo: https://github.com/PyCQA/flake8
rev: "5.0.4"
rev: "7.1.1"
hooks:
- id: flake8
additional_dependencies: ["flake8-docstrings", "flake8-eradicate", "flake8-isort"]
log_file: devtools/pre-commit.log
- repo: https://github.com/asottile/pyupgrade
rev: v3.2.0
rev: v3.19.0
hooks:
- id: pyupgrade
log_file: devtools/pre-commit.log
Expand Down
2 changes: 1 addition & 1 deletion desc/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def main(cl_args=sys.argv[1:]):
and (inputs[-1]["pres_ratio"] is None)
and (inputs[-1]["bdry_ratio"] is None)
):
eq = Equilibrium(**inputs[-1], check_kwargs=False)
eq = Equilibrium(**inputs[-1], check_kwargs=False, ensure_nested=False)
equil_fam = EquilibriaFamily.solve_continuation_automatic(
eq,
objective=inputs[-1]["objective"],
Expand Down
1 change: 1 addition & 0 deletions desc/equilibrium/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ def parse_axis(axis, NFP=1, sym=True, surface=None):
axis[:, 1],
axis[:, 2],
axis[:, 0].astype(int),
axis[:, 0].astype(int),
NFP=NFP,
sym=sym,
name="axis",
Expand Down
Binary file modified desc/examples/ARIES-CS_output.h5
Binary file not shown.
4 changes: 0 additions & 4 deletions desc/examples/ATF
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ l: 0 p = 5.00000000E+05 i = -3.50000000E-01
l: 2 p = -1.00000000E+06 i = -6.50000000E-01
l: 4 p = 5.00000000E+05 i = 0.00000000E+00

# magnetic axis initial guess
n: 0 R0 = 2.10000000E+00 Z0 = 0.00000000E+00
n: 1 R0 = 0.10000000E+00 Z0 = 0.10000000E+00

# fixed-boundary surface shape
m: -2 n: -1 R1 = -2.50000000E-02 Z1 = 0.00000000E+00
m: -2 n: 0 R1 = 0.00000000E+00 Z1 = -6.75000000E-03
Expand Down
Binary file modified desc/examples/ATF_output.h5
Binary file not shown.
Binary file modified desc/examples/DSHAPE_CURRENT_output.h5
Binary file not shown.
Binary file modified desc/examples/DSHAPE_output.h5
Binary file not shown.
Binary file modified desc/examples/ESTELL_output.h5
Binary file not shown.
4 changes: 2 additions & 2 deletions desc/examples/HELIOTRON
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ M_grid = 12, 18
N_grid = 0, 0, 6

# continuation parameters
bdry_ratio = 0, 0, 1
bdry_ratio = 0, 0, 0.5, 1
pres_ratio = 0, 1, 1
pert_order = 2

# solver tolerances
ftol = 1e-2
xtol = 1e-6
gtol = 1e-6
maxiter = 100
maxiter = 50

# solver methods
optimizer = lsq-exact
Expand Down
Binary file modified desc/examples/HELIOTRON_output.h5
Binary file not shown.
Binary file modified desc/examples/HSX_output.h5
Binary file not shown.
2 changes: 1 addition & 1 deletion desc/examples/NCSX
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pert_order = 2.0
# solver tolerances
ftol = 1e-2
xtol = 1e-6
gtol = 1e-2
gtol = 1e-8
maxiter = 50

# solver methods
Expand Down
Binary file modified desc/examples/NCSX_output.h5
Binary file not shown.
Binary file modified desc/examples/SOLOVEV_output.h5
Binary file not shown.
14 changes: 4 additions & 10 deletions desc/examples/W7-X
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,19 @@ NFP = 5
Psi = -2.13300000E+00

# spectral resolution
L_rad = 12,16,24
L_rad = 12
M_pol = 12
N_tor = 12
M_grid = 16
N_grid = 16
N_tor = 12
M_grid = 16
N_grid = 16

# continuation parameters
# because we specify these and a sequence for L_rad, it will not use the automatic continuation
bdry_ratio=1.0
pert_order = 2


# solver methods
optimizer = lsq-exact
objective = force
spectral_indexing = fringe
ftol=1e-4
xtol= 1e-6
maxiter=150

# pressure and rotational transform profiles
l: 0 p = 1.85596929e+05 i = -8.56047021e-01
Expand Down
Binary file modified desc/examples/W7-X_output.h5
Binary file not shown.
Binary file modified desc/examples/WISTELL-A_output.h5
Binary file not shown.
Binary file modified desc/examples/precise_QA_output.h5
Binary file not shown.
Binary file modified desc/examples/precise_QH_output.h5
Binary file not shown.
88 changes: 56 additions & 32 deletions desc/examples/regenerate_all_equilibria.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,67 @@
python3 regenerate_all_equilibria.py
Copy the two lines below to the main code to run it on a GPU
from desc import set_device
set_device("gpu")
"""
import argparse
import glob
import os
import subprocess as spr
import sys
from pathlib import Path

from desc.__main__ import main
from desc.io import load
from desc.vmec import VMECIO
parser = argparse.ArgumentParser(
prog="regenerate_all_equilibria",
)
parser.add_argument(
"-o",
"--output",
metavar="output_dir",
help="Path to output files. If not specified, defaults to input dir",
)
parser.add_argument(
"--gpu",
"-g",
action="store_true",
help="Use GPU if available. If more than one are available, selects the "
+ "GPU with most available memory. ",
)
parser.add_argument(
"--noprecise",
action="store_true",
help="Don't regenerate precise QS equilibria.",
)


args = parser.parse_args(sys.argv[1:])

pwd = os.getcwd()
if args.output:
output_path = os.path.abspath(args.output)
else:
output_path = pwd

Path(output_path).mkdir(parents=True, exist_ok=True)

files = sorted(glob.glob(pwd + "/*.h5"))
print("Regenerating files:")
for f in files:
print(f)
print("saving to: ", output_path)
names = [f.split("/")[-1].split(".")[0].replace("_output", "") for f in files]
names = [f for f in names if "precise" not in f]

for fname in names:
print(f"Running the input file {fname} \n")
cargs = [
"desc",
fname,
"-vv",
f"-o {os.path.join(output_path, fname + '_output.h5')}",
]
if args.gpu:
cargs += ["-g"]
spr.run(cargs)

for fname in glob.glob(pwd + "/*.h5"):
if (
fname.split(".")[-1] == "h5"
and os.path.isfile(fname.split(".")[-1] + ".nc") is True
and fname.split(".")[0].split("/")[-1].split("_")[0] != "precise"
):
finputname = fname.split(".")[0].split("/")[-1].split("_")[0]
print(f"Running the input file {finputname} \n")
main(cl_args=[str(f"{finputname}"), "-vv"])
# save wout file
eq = load(f"{pwd}/{finputname}")[-1]
VMECIO.save(eq, "wout_" + fname + ".nc", surfs=256)
elif (
fname.split(".")[-1] == "h5"
and os.path.isfile(fname + ".nc") is False
and fname.split(".")[0].split("/")[-1].split("_")[0] != "precise"
):
finputname = fname.split(".")[0].split("/")[-1].split("_")[0]
print(f"Running the input file {finputname} \n")
main(cl_args=[str(f"{finputname}"), "-vv"])
else:
continue

main(cl_args=["DSHAPE_CURRENT", "-vv"])
spr.call(["python3 -u precise_QA.py"], shell=True)
spr.call(["python3 -u precise_QH.py"], shell=True)
if not args.noprecise:
spr.run(["python3", "-u", "precise_QA.py"])
spr.run(["python3", "-u", "precise_QH.py"])
Loading

0 comments on commit 4b00cd2

Please sign in to comment.