desc.external.terpsichore.TERPSICHORE
- class desc.external.terpsichore.TERPSICHORE(eq, *, target=None, bounds=None, weight=1, normalize=False, normalize_target=False, loss_function=None, abs_step=0.0001, rel_step=0, processes=1, path, exec, mode_family=-1, surfs=101, M_nyq=None, N_nyq=None, M_booz_max=None, N_booz_max=None, M_max=8, N_min=-4, N_max=4, lssl=None, lssd=None, awall=2.0, deltaJp=0.0001, modelk=0, al0=-0.5, timeout=60, tmp_dir='tmp_TERPS', save_tmp=False, name='terpsichore')Source
Computes ideal MHD linear stability from calls to the code TERPSICHORE.
Returns the linear growth rate of the fastest growing instability, normalized by the Alfven frequency. A negative growth rate denotes stability and a positive growth rate denotes instability.
TERPSICHORE reference: https://doi.org/10.1007/978-1-4613-0659-7_8
TERPSICHORE documentation: https://princetonuniversity.github.io/STELLOPT/TERPSICHORE.html
- Parameters:
eq (Equilibrium) – Equilibrium that will be optimized to satisfy the Objective.
abs_step (float, optional) – Absolute finite difference step size. Default = 1e-4. Total step size is
abs_step + rel_step * mean(abs(x)).rel_step (float, optional) – Relative finite difference step size. Default = 0. Total step size is
abs_step + rel_step * mean(abs(x)).processes (int, optional) – Maximum number of CPU threads to use for multiprocessing. Default = 1.
path (str) – Path to the directory where temporary files will be stored.
exec (str) – File name of the TERPSICHORE executable. Must be located in the directory specified by
path.mode_family (int, optional) – The mode family of the instabilities to consider. The toroidal modes included in a mode family are n_i = i * eq.NFP ± k, where i = …, -1, 0, +1, … and k ∈ [0, mode_family]. Possible mode families are in the range [0, eq.NFP // 2]. If mode_family < 0 then all mode families are considered. Default = -1.
surfs (int, optional) – Number of surfaces to include in the equilibrium input. More surfaces provides more accuracy at the cost of longer compute times. Default = 101.
M_nyq (int) – The max poloidal and toroidal mode numbers to use in the Nyquist spectrum of the equilibrium input. Defaults to
eq.M + 4andeq.N + 2.N_nyq (int) – The max poloidal and toroidal mode numbers to use in the Nyquist spectrum of the equilibrium input. Defaults to
eq.M + 4andeq.N + 2.M_booz_max (int, optional) – Maximum poloidal and toroidal mode numbers of Boozer spectrum. Will include modes with m ∈ [0, M_booz_max] and n ∈ [-N_booz_max, N_booz_max]. Defaults to
2 * eq.Mand2 * eq.N.N_booz_max (int, optional) – Maximum poloidal and toroidal mode numbers of Boozer spectrum. Will include modes with m ∈ [0, M_booz_max] and n ∈ [-N_booz_max, N_booz_max]. Defaults to
2 * eq.Mand2 * eq.N.M_max (int, optional) – Maximum poloidal mode number of stability modes to consider. Will include modes with m ∈ [0, M_max] (if
mode_family < 0). Default = 8.N_min (int, optional) – Minimum toroidal mode number of stability modes to consider. Will include modes with n ∈ [N_min, N_max] (if
mode_family < 0). Default = -4.N_max (int, optional) – Maximum toroidal mode number of stability modes to consider. Will include modes with n ∈ [N_min, N_max] (if
mode_family < 0). Default = 4.lssl (int, optional) – Minimum number of possible permutations of Boozer mode combinations (determined by
M_booz_maxandN_booz_max). If TERPSICHORE fails to run, try increasing this parameter. Default =20 * M_booz_max * N_booz_max.lssd (int, optional) – Minimum number of possible permutations of stability mode combinations (determined by
M_maxandN_max). If TERPSICHORE fails to run, try increasing this parameter. Default =20 * M_max * N_max.awall (float, optional) – Ratio of the radius of the conformal conducting wall to the plasma minor radius. The conducting wall is obtained by scaling the m ≠ 0 Fourier components of the plasma boundary by
awall. A shorter wall offset will help stabilize the plasma. If TERPSICHORE fails to run, try decreasing this parameter. Default = 2.deltaJp (float) – Resonance detuning parameter to resolve parallel current density singularities. A larger value can artificially improve the stability. Default = 1e-4.
modelk (int, optional) – 0 = Noninteracting anisotropic fast particle stability model with reduced kinetic energy. 1 = Kruskal-Oberman anisotropic energy principle model with reduced kinetic energy. 2 = Noninteracting anisotropic fast particle stability model with physical kinetic energy. 3 = Kruskal-Oberman anisotropic energy principle model with physical kinetic energy. Default = 0.
al0 (float, optional) – Initial guess of the eigenvalue. Use a sufficiently negative value to find the most unstable growth rate. If TERPSICHORE fails to run, the objective will return a growth rate of
abs(al0). Default = -0.5.timeout (float, optional) – Time in seconds to wait for TERPSICHORE to execute before terminating its run. See
timeoutargument ofsubprocess.runfor more info. Default = 60.tmp_dir (str, optional) – Name of directory where temporary files used and generated by TERPSICHORE are stored. This will be a sub-directory within the directory specified by
path. Default = “tmp_TERPS”.save_tmp (bool, optional) – If True,
tmp_diris preserved to record the TERPSICHORE I/O files. It will contain sub-directories named by a timestamp for each time the function was evaluated. Those contain another layer of sub-directories named by integers ranging from 0 tolen(eq)with the files used in each TERPSICHORE call. If False,tmp_dirand all of its contents are removed at the end of the function evaluation. Default = False.target ({float, ndarray}, optional) – Target value(s) of the objective. Only used if
boundsisNone. Must be broadcastable toObjective.dim_f. Defaults tobounds=(-np.inf, 0)bounds (tuple of {float, ndarray}, optional) – Lower and upper bounds on the objective. Overrides
target. Both bounds must be broadcastable toObjective.dim_f. Defaults tobounds=(-np.inf, 0)weight ({float, ndarray}, optional) – Weighting to apply to the Objective, relative to other Objectives. Must be broadcastable to
Objective.dim_f.normalize (bool, optional) – Whether to compute the error in physical units or non-dimensionalize.
normalize_target (bool, optional) – Whether target and bounds should be normalized before comparing to computed values. If
normalizeisTrueand the target is in physical units, this should also be set toTrue.loss_function ({None, 'mean', 'min', 'max','sum'}, optional) – Loss function to apply to the objective values once computed. This loss function is called on the raw compute value, before any shifting, scaling, or normalization.
deriv_mode ({"auto", "fwd", "rev"}) – Specify how to compute Jacobian matrix, either forward mode or reverse mode AD.
autoselects forward or reverse mode based on the size of the input and output of the objective. Has no effect onself.gradorself.hesswhich always use reverse mode and forward over reverse mode respectively.name (str, optional) – Name of the objective.
jac_chunk_size (int or
auto, optional) – Will calculate the Jacobianjac_chunk_sizecolumns at a time, instead of all at once. The memory usage of the Jacobian calculation is roughlymemory usage = m0+m1*jac_chunk_size: the smaller the chunk size, the less memory the Jacobian calculation will require (with some baseline memory usage). The time it takes to compute the Jacobian is roughlyt = t0+t1/jac_chunk_sizeso the larger thejac_chunk_size, the faster the calculation takes, at the cost of requiring more memory. IfNone, it will use the largest size i.eobj.dim_x. Can also help with Hessian computation memory, as Hessian is essentiallyjacfwd(jacrev(f)), and each of these operations may be chunked. Defaults tochunk_size=None. Note: When running on a CPU (not a GPU) on a HPC cluster, DESC is unable to accurately estimate the available device memory, so theautochunk_size option will yield a larger chunk size than may be needed. It is recommended to manually choose a chunk_size if an OOM error is experienced in this case.
- __init__(eq, *, target=None, bounds=None, weight=1, normalize=False, normalize_target=False, loss_function=None, abs_step=0.0001, rel_step=0, processes=1, path, exec, mode_family=-1, surfs=101, M_nyq=None, N_nyq=None, M_booz_max=None, N_booz_max=None, M_max=8, N_min=-4, N_max=4, lssl=None, lssd=None, awall=2.0, deltaJp=0.0001, modelk=0, al0=-0.5, timeout=60, tmp_dir='tmp_TERPS', save_tmp=False, name='terpsichore')Source
Methods
__init__(eq, *[, target, bounds, weight, ...])build([use_jit, verbose])Build constant arrays.
compute(params[, constants])Compute the quantity.
compute_scalar(*args, **kwargs)Compute the scalar form of the objective.
compute_scaled(*args, **kwargs)Compute and apply weighting and normalization.
compute_scaled_error(*args, **kwargs)Compute and apply the target/bounds, weighting, and normalization.
compute_unscaled(*args, **kwargs)Compute the raw value of the objective.
copy([deepcopy])Return a (deep)copy of this object.
equiv(other)Compare equivalence between DESC objects.
grad(*args, **kwargs)Compute gradient vector of self.compute_scalar wrt x.
hess(*args, **kwargs)Compute Hessian matrix of self.compute_scalar wrt x.
jac_scaled(*args, **kwargs)Compute Jacobian matrix of self.compute_scaled wrt x.
jac_scaled_error(*args, **kwargs)Compute Jacobian matrix of self.compute_scaled_error wrt x.
jac_unscaled(*args, **kwargs)Compute Jacobian matrix of self.compute_unscaled wrt x.
jvp_scaled(v, x[, constants])Compute Jacobian-vector product of self.compute_scaled.
jvp_scaled_error(v, x[, constants])Compute Jacobian-vector product of self.compute_scaled_error.
jvp_unscaled(v, x[, constants])Compute Jacobian-vector product of self.compute_unscaled.
load(load_from[, file_format])Initialize from file.
print_value(args[, args0])Print the value of the objective and return a dict of values.
save(file_name[, file_format, file_mode])Save the object.
xs(*things)Return a tuple of args required by this objective from optimizable things.
Attributes
boundsLower and upper bounds of the objective.
builtWhether the transforms have been precomputed (or not).
constantsConstant parameters such as transforms and profiles.
dim_fNumber of objective equations.
fixedWhether the objective fixes individual parameters (or linear combo).
linearWhether the objective is a linear function (or nonlinear).
nameName of objective (str).
normalizationnormalizing scale factor.
scalarWhether default "compute" method is a scalar or vector.
targetTarget value(s) of the objective.
thingsOptimizable things that this objective is tied to.
weightWeighting to apply to the Objective, relative to other Objectives.