Skip to content

v0.17.4

Latest

Choose a tag to compare

@YigitElma YigitElma released this 17 Nov 02:24
· 6 commits to master since this release
3c39221

New Features

  • Adds desc.external.agni.AgniStability, the squared growth rate of the most unstable finite-n ideal MHD mode computed by the external AGNI solver (pip install agnimhd), with its gradient for optimization.
  • Added warning for when deriv_mode="batched" is used in an ObjectiveFunction where one or more sub-objectives is using rev mode differentiation. Also adds more info about the derivative mode and Jacobian chunk sizes when building the objective with verbose>1.
  • Adds scale_invariant argument to quasi-symmetry objectives (i.e. QuasisymmetryTwoTerm, QuasisymmetryTripleProduct and QuasisymmetryBoozer) that introduces the normalized alternatives for the objective functions with the actual evaluated local magnetic field information instead of the precomputed constant normalization. Similarly, the definition of f_C and f_T of plot_qs_error is changed, the flux surface average is now take over the normalized quantity whereas previously the flux surface average was applied to each term separately before normalization. For more details on these quantities, see Basic Optimization tutorial.
  • Adds NeutronWallLoading objective to compute the neutron wall loading (MW/m²) on a chosen/optimized surface.
  • Adds Python type hints for many API functions. Allows for better autocomplete and error checking when writing DESC scripts in common IDEs.

Performance Improvements

  • Avoids numerous small JAX compilations when building and solving an equilibrium at a new resolution, by doing index and mode bookkeeping in Grid, Optimizable.x_idx and compute_scaling_factors with NumPy instead of eager JAX operations.
  • Reduces memory use of Boozer harmonic projections and their derivatives by contracting the poloidal and toroidal Fourier factors separately.
  • Improves memory management to reduce the base memory used during optimization while using lsq-exact, lsq-auglag and fmin-auglag optimizers.
  • Sparse reverse-mode differentiation was introduced to yield significant performance improvements #2170
  • Speeds up field_line_integrate and trace_particles for filamentary coils (Coil, CoilSet, MixedCoilSet) by precomputing the constant source information, so that the ODE right-hand side only evaluates a single fused Biot-Savart kernel instead of recomputing the coil geometry at every solver step.
  • Improves the non-singular Biot-Savart kernel which should give a speed/memory improvement to objectives that compute magnetic field from coils such as QuadraticFlux.
  • ideal ballooning lambda now computes only the requested Neigvals largest eigenpairs of each tridiagonal ballooning matrix (bisection + twisted factorization) instead of a dense eigh of every matrix. Memory of the eigensolve drops from O(N²) to O(N) per field line (peak GPU memory of the ballooning tutorial's evaluation: 14.5 GB -> 0.16 GB); results are unchanged and run times are about the same (the eigensolve is a small part of the total).
  • More efficient ProximalProjection jacobians if the ForceBalance constraint uses a small jac_chunk_size and if there are many non-equilibrium degrees of freedom (i.e. single stage optimization).
  • Additional memory reductions for LinearConstraintProjection base memory usage.
  • Reduces the compilation time of custom qr_multiply algorithm.
  • Removes a temporary copy of the full output in chunked computations (e.g. Jacobians with jac_chunk_size) when the chunk size does not evenly divide the batched dimension.
  • lsq-exact (and proximal-lsq-exact) stops when a rejected step is already smaller than xtol instead of shrinking the trust region until a step of negligible size is accepted. This saves many function evaluations at the end of an optimization when the objective is only evaluated approximately, as with ProximalProjection.
  • field_line_integrate no longer recompiles its ODE solver on every call: repeated calls with the same inputs reuse the compiled solver.
  • Stores the surface labels rho and zeta as floats, so that surfaces labelled with an int or a float share compiled code.

Important

Recent jax versions (particularly after 0.10.0) can negatively impact DESC optimization performance. While the improvements in this release should result in a net speedup and memory reduction, we recommend benchmarking your workload across different jax versions rather than defaulting to the latest release. To mitigate known slowdowns, DESC now sets the following XLA flags by default:

  • --xla_cpu_experimental_ynn_fusion_type=-reduce
  • --xla_gpu_enable_triton_gemm=false

User-defined values for these flags will be respected and will not be overridden by DESC.

Breaking Changes and Deprecations

  • The parameter num_transit in EffectiveRipple, Gamma_c, Bounce2D and related functions has been changed to field_period_transits. This should make using a consistent resolution across different equilibria easier. The now-deprecated num_transit may still be used but note the equivalence field_period_transits = num_transit * grid.NFP.
  • The parameter Y_B in EffectiveRipple, Gamma_c, Bounce2D is now the resolution over a single field period rather than a full toroidal transit. This should make using a consistent resolution across different equilibria easier.
  • Objectives using Bounce2D now do not support forward ("fwd") mode differentiation for JAX versions <0.11.0.
  • desc.utils.rotation_matrix utility function now accepts either an axis and an angle as arguments (previous behavior), OR a vector and a vector. In the latter case, the rotation matrix returned will rotate the first vector onto the second, using quaternions which avoids the NaN gradient issue that the axis-angle form can have at vertical normals. Note that these are positional arguments, and the kwargs axis and angle are now deprecated.
  • Public modules now define __all__ matching the API documentation, which makes the public API explicit for IDEs, type checkers and other tools. Note that from desc.<module> import * now only imports the documented public names.

Bug Fixes

  • Fixes 2nd and 3rd order terms of perturb (and so of Equilibrium.perturb, solve_continuation and ProximalProjection) being evaluated along a tangent that included the full value of any fixed parameter of magnitude above 100 (eg pressure, density, temperature or current profiles in SI units), which made the higher order terms worse than no correction. Note that this did not make old results incorrect, rather it just made the optimizations inefficient
  • Fixes VMECIO.load(profile="current") fitting VMEC's half-mesh buco on the full radial mesh, which shifted the current profile and its edge value.
  • Fixes solve_continuation(verbose=0) raising UnboundLocalError on its first step.
  • Fixes the Curve.rotmat setter, which crashed for list input and silently accepted arrays that were not 3x3 or of length 9.
  • Fixes two sign errors in c ballooning that made ideal ballooning lambda wrong for equilibria with ψ < 0 or ι < 0 #2342: an extra sign(ψ) made the result depend on the direction of B, and for ι < 0 the zeta0 shift of ∇α in c ballooning had the opposite sign from gds2, so the growth rate grew without bound with zeta0. Results for ψ > 0 and ι > 0 are unchanged.
  • Fixes VMECIO.load fitting lambda as if lmns were on the full radial mesh. VMEC stores lambda on the half mesh, so the fitted lambda was shifted by half a radial cell and pulled towards the zero placeholder row at the axis, which gave errors of order 0.1% in |B| of loaded equilibria. See #2351. Note that the VMECIO.load guidance remains the same as before: re-solving the equilibrium in DESC after loading from a VMEC wout is recommended given the representation differences between the two codes.
  • Fixes SplineMagneticField with a single toroidal plane (axisymmetric mgrid): the cubic 2D interpolation now uses the Z derivatives instead of the zero phi derivatives, so its error between nodes falls from about 1e-3 to the expected cubic level #2357.
  • Corrects the labels of e^helical and e^helical*sqrt(g) (and their magnitudes), which showed the opposite sign to the computed vectors, and the units of the Jacobian-weighted quantities from T m^2 to T m.
  • Fixes bug in auglag optimizers which prevented them from accepting solver hyperparameters.
  • Improves planar coil representation (desc.coils.FourierPlanarCoil and desc.coils.FourierXYCoil) internal rotation methods to avoid potential NaNs which could occur when the normal is parallel or antiparallel to Z-axis( to within machine epsilon), and also ensure the gradient at those edge cases is not only not NaN but also non-zero to avoid optimizer stalls at those cases.
  • Fixes potential scaling-based issue in DESC-based optimization methods which use adaptive Hessian scaling (e.g. "fmintr") that could occur when the problem size was small and there were directions of near-zero derivative in the problem.
  • Fixes computation of CoilSetLinkingNumber to exclude coil writhe.
  • Adjusts the quad_weights of coil objectives of type _broadcast_input = "node" to ensure their outputs are roughly independent of grid resolution.
  • Fixes bug in modified Cholesky factorization used by the trust-region subproblems when the Gershgorin lower bound of the Hessian was exactly zero (e.g. a Hessian with an all-zero row), producing NaN steps in fmintr and fmin-auglag with the default tr_method="exact", and in lsq-exact/lsq-auglag with tr_method="cho".
  • Fixes the Levenberg-Marquardt parameter update in the Cholesky trust-region subproblem, which often failed to converge and returned inexact steps in fmintr and fmin-auglag with the default tr_method="exact", and in lsq-exact/lsq-auglag with tr_method="cho".
  • Stops ProximalProjection from mutating solve_options during iterations.
  • Fixes FourierRZCoil, SplineXYZCoil and other coils' compute_magnetic_field and compute_magnetic_vector_potential removing current from the caller's params dictionary when it was used to override the coil current, which made repeated calls with the same params silently use the coil's stored current instead.
  • Fixes bug that occured when passing in _surf_batch_size kwarg to Omnigenity and QuasisymmetryBoozer objectives
  • Fixes pitch_batch_size argument getting ignored in compute functions.
  • Stopped wiping the CUDA_VISIBLE_DEVICES environment variable when set_device("cpu") is used, which should now allow DESC to be used on CPU concurrently with e.g. pytorch or some other code using the GPU.
  • Improves the handling of failed Cholesky factorizations in the "cho" trust-region method.
  • Adds a warning when sub-objectives with bounds can make the Jacobian rank-deficient, since the default "qr" trust-region method may then fail to solve the subproblem, suggesting options={"tr_method": "svd"} instead.
  • Fixes InputReader rejecting DESC input files whose lines are indented, which previously failed with The following line is not a valid input.
  • Fixes wrong signs in w_Boozer_mn for non-stellarator-symmetric equilibria, which made the Boozer transform (nu, theta_B, zeta_B, the Boozer harmonics such as |B|_mn_B, QuasisymmetryBoozer, make_boozmn_output etc.) incorrect for asymmetric equilibria. Results for stellarator-symmetric equilibria are unchanged. Asymmetric make_boozmn_output outputs (including pmnc_b) now agree with the hidden symmetries booz_xform, so the warning about the sign of numnc has been removed.
  • Ensures that SurfaceCurrentRegularization.normalization has the correct units for every regularization option.
  • Fixes inaccuracy in derivative when equilibrium boundary sheet current is present and non-negligible in BoundaryError objective.

New Contributors

Full Changelog: v0.17.3...v0.17.4