Skip to content

Commit

Permalink
Merge branch 'master' into dd/external
Browse files Browse the repository at this point in the history
  • Loading branch information
ddudt authored Dec 17, 2024
2 parents 021106d + bc0654e commit 0f35919
Show file tree
Hide file tree
Showing 31 changed files with 1,703 additions and 195 deletions.
23 changes: 15 additions & 8 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,28 +58,35 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Check full Python version
run: |
python --version
python_version=$(python --version 2>&1 | cut -d' ' -f2)
echo "Python version: $python_version"
echo "version=$python_version" >> $GITHUB_ENV
- name: Restore Python environment cache
if: env.has_changes == 'true'
id: restore-env
uses: actions/cache/restore@v4
with:
path: .venv-${{ matrix.python-version }}
key: ${{ runner.os }}-venv-${{ matrix.python-version }}-${{ hashFiles('devtools/dev-requirements.txt', 'requirements.txt') }}
path: .venv-${{ env.version }}
key: ${{ runner.os }}-venv-${{ env.version }}-${{ hashFiles('devtools/dev-requirements.txt', 'requirements.txt') }}

- name: Set up virtual environment if not restored from cache
if: steps.restore-env.outputs.cache-hit != 'true' && env.has_changes == 'true'
run: |
gh cache list
python -m venv .venv-${{ matrix.python-version }}
source .venv-${{ matrix.python-version }}/bin/activate
python -m venv .venv-${{ env.version }}
source .venv-${{ env.version }}/bin/activate
python -m pip install --upgrade pip
pip install -r devtools/dev-requirements.txt
pip install matplotlib==3.9.2
- name: Benchmark with pytest-benchmark (PR)
if: env.has_changes == 'true'
run: |
source .venv-${{ matrix.python-version }}/bin/activate
source .venv-${{ env.version }}/bin/activate
pwd
lscpu
pip list
Expand All @@ -106,7 +113,7 @@ jobs:
- name: Benchmark with pytest-benchmark (MASTER)
if: env.has_changes == 'true'
run: |
source .venv-${{ matrix.python-version }}/bin/activate
source .venv-${{ env.version }}/bin/activate
pwd
lscpu
pip list
Expand All @@ -122,7 +129,7 @@ jobs:
- name: Put benchmark results in same folder
if: env.has_changes == 'true'
run: |
source .venv-${{ matrix.python-version }}/bin/activate
source .venv-${{ env.version }}/bin/activate
pwd
cd tests/benchmarks
find .benchmarks/ -type f -printf "%T@ %p\n" | sort -n | cut -d' ' -f 2- | tail -n 1 > temp1
Expand All @@ -143,7 +150,7 @@ jobs:
- name: Compare latest commit results to the master branch results
if: env.has_changes == 'true'
run: |
source .venv-${{ matrix.python-version }}/bin/activate
source .venv-${{ env.version }}/bin/activate
cd tests/benchmarks
pwd
python compare_bench_results.py
Expand Down
17 changes: 12 additions & 5 deletions .github/workflows/black.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,32 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Check full Python version
run: |
python --version
python_version=$(python --version 2>&1 | cut -d' ' -f2)
echo "Python version: $python_version"
echo "version=$python_version" >> $GITHUB_ENV
- name: Restore Python environment cache
id: restore-env
uses: actions/cache/restore@v4
with:
path: .venv-${{ matrix.python-version }}
key: ${{ runner.os }}-venv-${{ matrix.python-version }}-${{ hashFiles('devtools/dev-requirements.txt', 'requirements.txt') }}
path: .venv-${{ env.version }}
key: ${{ runner.os }}-venv-${{ env.version }}-${{ hashFiles('devtools/dev-requirements.txt', 'requirements.txt') }}

- name: Set up virtual environment if not restored from cache
if: steps.restore-env.outputs.cache-hit != 'true'
run: |
gh cache list
python -m venv .venv-${{ matrix.python-version }}
source .venv-${{ matrix.python-version }}/bin/activate
python -m venv .venv-${{ env.version }}
source .venv-${{ env.version }}/bin/activate
python -m pip install --upgrade pip
pip install -r devtools/dev-requirements.txt
- name: Check files using the black formatter
run: |
source .venv-${{ matrix.python-version }}/bin/activate
source .venv-${{ env.version }}/bin/activate
black --version
black --check desc/ tests/ || black_return_code=$?
echo "BLACK_RETURN_CODE=$black_return_code" >> $GITHUB_ENV
Expand Down
22 changes: 15 additions & 7 deletions .github/workflows/cache_dependencies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,28 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Check full Python version
run: |
python --version
python_version=$(python --version 2>&1 | cut -d' ' -f2)
echo "Python version: $python_version"
echo "version=$python_version" >> $GITHUB_ENV
- name: Delete old cached file with same python version
run: |
echo "Current Cached files list"
gh cache list
echo "Deleting cached files with pattern: ${{ runner.os }}-venv-${{ matrix.python-version }}-"
for cache_key in $(gh cache list --json key -q ".[] | select(.key | startswith(\"${{ runner.os }}-venv-${{ matrix.python-version }}-\")) | .key"); do
echo "Deleting cached files with pattern: ${{ runner.os }}-venv-${{ env.version }}-"
for cache_key in $(gh cache list --json key -q ".[] | select(.key | startswith(\"${{ runner.os }}-venv-${{ env.version }}-\")) | .key"); do
echo "Deleting cache with key: $cache_key"
gh cache delete "$cache_key"
done
# Update the matplotlib version if needed later
- name: Set up virtual environment
run: |
python -m venv .venv-${{ matrix.python-version }}
source .venv-${{ matrix.python-version }}/bin/activate
python -m venv .venv-${{ env.version }}
source .venv-${{ env.version }}/bin/activate
python -m pip install --upgrade pip
pip install -r devtools/dev-requirements.txt
pip install matplotlib==3.9.2
Expand All @@ -47,12 +54,13 @@ jobs:
id: cache-env
uses: actions/cache@v4
with:
path: .venv-${{ matrix.python-version }}
key: ${{ runner.os }}-venv-${{ matrix.python-version }}-${{ hashFiles('devtools/dev-requirements.txt', 'requirements.txt') }}
path: .venv-${{ env.version }}
key: ${{ runner.os }}-venv-${{ env.version }}-${{ hashFiles('devtools/dev-requirements.txt', 'requirements.txt') }}

- name: Verify virtual environment activation
run: |
source .venv-${{ matrix.python-version }}/bin/activate
source .venv-${{ env.version }}/bin/activate
which python
python --version
pip --version
pip list
17 changes: 12 additions & 5 deletions .github/workflows/notebook_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,28 +51,35 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Check full Python version
run: |
python --version
python_version=$(python --version 2>&1 | cut -d' ' -f2)
echo "Python version: $python_version"
echo "version=$python_version" >> $GITHUB_ENV
- name: Restore Python environment cache
if: env.has_changes == 'true'
id: restore-env
uses: actions/cache/restore@v4
with:
path: .venv-${{ matrix.python-version }}
key: ${{ runner.os }}-venv-${{ matrix.python-version }}-${{ hashFiles('devtools/dev-requirements.txt', 'requirements.txt') }}
path: .venv-${{ env.version }}
key: ${{ runner.os }}-venv-${{ env.version }}-${{ hashFiles('devtools/dev-requirements.txt', 'requirements.txt') }}

- name: Set up virtual environment if not restored from cache
if: steps.restore-env.outputs.cache-hit != 'true' && env.has_changes == 'true'
run: |
gh cache list
python -m venv .venv-${{ matrix.python-version }}
source .venv-${{ matrix.python-version }}/bin/activate
python -m venv .venv-${{ env.version }}
source .venv-${{ env.version }}/bin/activate
python -m pip install --upgrade pip
pip install -r devtools/dev-requirements.txt
pip install matplotlib==3.9.2
- name: Test notebooks with pytest and nbmake
if: env.has_changes == 'true'
run: |
source .venv-${{ matrix.python-version }}/bin/activate
source .venv-${{ env.version }}/bin/activate
pwd
lscpu
pip list
Expand Down
17 changes: 12 additions & 5 deletions .github/workflows/regression_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,27 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Check full Python version
run: |
python --version
python_version=$(python --version 2>&1 | cut -d' ' -f2)
echo "Python version: $python_version"
echo "version=$python_version" >> $GITHUB_ENV
- name: Restore Python environment cache
if: env.has_changes == 'true'
id: restore-env
uses: actions/cache/restore@v4
with:
path: .venv-${{ matrix.python-version }}
key: ${{ runner.os }}-venv-${{ matrix.python-version }}-${{ hashFiles('devtools/dev-requirements.txt', 'requirements.txt') }}
path: .venv-${{ env.version }}
key: ${{ runner.os }}-venv-${{ env.version }}-${{ hashFiles('devtools/dev-requirements.txt', 'requirements.txt') }}

- name: Set up virtual environment if not restored from cache
if: steps.restore-env.outputs.cache-hit != 'true' && env.has_changes == 'true'
run: |
gh cache list
python -m venv .venv-${{ matrix.python-version }}
source .venv-${{ matrix.python-version }}/bin/activate
python -m venv .venv-${{ env.version }}
source .venv-${{ env.version }}/bin/activate
python -m pip install --upgrade pip
pip install -r devtools/dev-requirements.txt
pip install matplotlib==3.9.2
Expand All @@ -77,7 +84,7 @@ jobs:
- name: Test with pytest
if: env.has_changes == 'true'
run: |
source .venv-${{ matrix.python-version }}/bin/activate
source .venv-${{ env.version }}/bin/activate
pwd
lscpu
pip list
Expand Down
26 changes: 20 additions & 6 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,27 @@ jobs:
with:
python-version: ${{ matrix.combos.python_version }}

- name: Check full Python version
run: |
python --version
python_version=$(python --version 2>&1 | cut -d' ' -f2)
echo "Python version: $python_version"
echo "version=$python_version" >> $GITHUB_ENV
- name: Restore Python environment cache
if: env.has_changes == 'true'
id: restore-env
uses: actions/cache/restore@v4
with:
path: .venv-${{ matrix.combos.python_version }}
key: ${{ runner.os }}-venv-${{ matrix.combos.python_version }}-${{ hashFiles('devtools/dev-requirements.txt', 'requirements.txt') }}
path: .venv-${{ env.version }}
key: ${{ runner.os }}-venv-${{ env.version }}-${{ hashFiles('devtools/dev-requirements.txt', 'requirements.txt') }}

- name: Set up virtual environment if not restored from cache
if: steps.restore-env.outputs.cache-hit != 'true' && env.has_changes == 'true'
run: |
gh cache list
python -m venv .venv-${{ matrix.combos.python_version }}
source .venv-${{ matrix.combos.python_version }}/bin/activate
python -m venv .venv-${{ env.version }}
source .venv-${{ env.version }}/bin/activate
python -m pip install --upgrade pip
pip install -r devtools/dev-requirements.txt
pip install matplotlib==3.9.2
Expand All @@ -80,13 +87,20 @@ jobs:
with:
swap-size-gb: 10

- name: Test with pytest
- name: Action Details
if: env.has_changes == 'true'
run: |
source .venv-${{ matrix.combos.python_version }}/bin/activate
source .venv-${{ env.version }}/bin/activate
which python
python --version
pwd
lscpu
pip list
- name: Test with pytest
if: env.has_changes == 'true'
run: |
source .venv-${{ env.version }}/bin/activate
python -m pytest -v -m unit \
--durations=0 \
--cov-report xml:cov.xml \
Expand Down
20 changes: 11 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@ Changelog
New Feature

- Adds a new profile class ``PowerProfile`` for raising profiles to a power.
- Add ``desc.objectives.LinkingCurrentConsistency`` for ensuring that coils in a stage 2 or single stage optimization provide the required linking current for a given equilibrium.
- Adds an option ``scaled_termination`` (defaults to True) to all of the desc optimizers to measure the norms for ``xtol`` and ``gtol`` in the scaled norm provided by ``x_scale`` (which defaults to using an adaptive scaling based on the Jacobian or Hessian). This should make things more robust when optimizing parameters with widely different magnitudes. The old behavior can be recovered by passing ``options={"scaled_termination": False}``.
- ``desc.objectives.Omnigenity`` is now vectorized and able to optimize multiple surfaces at the same time. Previously it was required to use a different objective for each surface.
- Adds a new objective ``desc.objectives.MirrorRatio`` for targeting a particular mirror ratio on each flux surface, for either an ``Equilibrium`` or ``OmnigenousField``.

Bug Fixes

- Small bug fix to use the correct normalization length ``a`` in the BallooningStability objective
- Small bug fix to use the correct normalization length ``a`` in the BallooningStability objective.
- Fixed I/O bug when saving/loading ``_Profile`` classes that do not have a ``_params`` attribute.

v0.13.0
-------

New Features

- Adds ``from_input_file`` method to ``Equilibrium`` class to generate an ``Equilibrium`` object with boundary, profiles, resolution and flux specified in a given DESC or VMEC input file
- Adds function ``solve_regularized_surface_current`` to ``desc.magnetic_fields`` module that implements the REGCOIL algorithm (Landreman, (2017)) for surface current normal field optimization
* Can specify the tuple ``current_helicity=(M_coil, N_coil)`` to determine if resulting contours correspond to helical topology (both ``(M_coil, N_coil)`` not equal to 0), modular (``N_coil`` equal to 0 and ``M_coil`` nonzero) or windowpane/saddle (``M_coil`` and ``N_coil`` both zero)
Expand Down Expand Up @@ -298,7 +300,7 @@ optimization. Set to False by default.
non-singular, non-degenerate) coordinate mappings for initial guesses. This is applied
automatically when creating a new `Equilibrium` if the default initial guess of scaling
the boundary surface produces self-intersecting surfaces. This can be disabled by
passing `ensure_nested=False` when constructing the `Equilibrum`.
passing `ensure_nested=False` when constructing the `Equilibrium`.
- Adds `loss_function` argument to all `Objective`s for applying one of min/max/mean
to objective function values (for targeting the average value of a profile, etc).
- `Equilibrium.get_profile` now allows user to choose a profile type (power series, spline, etc)
Expand Down Expand Up @@ -450,7 +452,7 @@ Breaking changes
- Renames ``theta_sfl`` to ``theta_PEST`` in compute functions to avoid confusion with
other straight field line coordinate systems.
- Makes plotting kwargs a bit more uniform. ``zeta``, ``nzeta``, ``nphi`` have all been
superceded by ``phi`` which can be an integer for equally spaced angles or a float or
superseded by ``phi`` which can be an integer for equally spaced angles or a float or
array of float to specify angles manually.

Bug fixes
Expand Down Expand Up @@ -520,7 +522,7 @@ the future all quantities should evaluate correctly at the magnetic axis. Note t
evaluating quantities at the axis generally requires higher order derivatives and so
can be much more expensive than evaluating at nonsingular points, so during optimization
it is not recommended to include a grid point at the axis. Generally a small finite value
such as ``rho = 1e-6`` will avoid the singuarlity with a negligible loss in accuracy for
such as ``rho = 1e-6`` will avoid the singularity with a negligible loss in accuracy for
analytic quantities.
- Adds new optimizers ``fmin-auglag`` and ``lsq-auglag`` for performing constrained
optimization using the augmented Lagrangian method. These generally perform much better
Expand All @@ -536,7 +538,7 @@ the existing methods ``compute_theta_coordinates`` and ``compute_flux_coordinate
but allows mapping between arbitrary coordinates.
- Adds calculation of $\nabla \mathbf{B}$ tensor and corresponding $L_{\nabla B}$ metric
- Adds objective ``BScaleLength`` for penalizing strong magnetic field curvature.
- Adds objective ``ObjectiveFromUser`` for wrapping an arbitary user defined function.
- Adds objective ``ObjectiveFromUser`` for wrapping an arbitrary user defined function.
- Adds utilities ``desc.grid.find_least_rational_surfaces`` and
``desc.grid.find_most_rational_surfaces`` for finding the least/most rational surfaces
for a given rotational transform profile.
Expand Down Expand Up @@ -1072,7 +1074,7 @@ New Features:
- Updates `Equilibrium` to make creating them more straightforward.
- Instead of a dictionary of arrays and values, init method now
takes individual arguments. These can either be objects of the
correct type (ie `Surface` objects for boundary condiitons,
correct type (ie `Surface` objects for boundary conditions,
`Profile` for pressure and iota etc,) or ndarrays which will get
parsed into objects of the correct type (for backwards
compatibility)
Expand Down Expand Up @@ -1356,7 +1358,7 @@ Major changes:
indexing, where only M+1 points were used instead of the correct
2\*M+1
- Rotated concentric grids by 2pi/3M to avoid symmetry plane at
theta=0,pi. Previously, for stellarator symmetic cases, the nodes at
theta=0,pi. Previously, for stellarator symmetric cases, the nodes at
theta=0 did not contribute to helical force balance.
- Added [L\_grid]{.title-ref} parameter to specify radial resolution
of grid nodes directly and making the API more consistent.
Expand Down Expand Up @@ -1522,7 +1524,7 @@ saved, and objectives getting compiled more often than necessary

Major Changes:

- Changes to Equilibium/EquilibriaFamily:
- Changes to Equilibrium/EquilibriaFamily:
- general switching to using properties rather than direct
attributes when referencing things (ie, `eq.foo`, not
`eq._foo`). This allows getter methods to have safeguards if
Expand Down
Loading

0 comments on commit 0f35919

Please sign in to comment.