desc.objectives.PlasmaCoilSetDistanceBound

class desc.objectives.PlasmaCoilSetDistanceBound(eq, coil, mode='bound', target=None, bounds=None, weight=1, normalize=True, normalize_target=True, loss_function=None, deriv_mode='auto', plasma_grid=None, coil_grid=None, eq_fixed=False, coils_fixed=False, name='plasma-coil distance', jac_chunk_size=None, use_softmin=False, softmin_alpha=1.0, dist_chunk_size=None)Source

Target the distance between the plasma and coilset.

Will yield one or two values per coil in the coilset, depending on the mode variable, which is the minimum and/or maximum distance from that coil to the plasma boundary surface. If max or min mode is selected, only one value is returned. If bound mode is selected, two values are returned per coil, which are the minimum and maximum distance from the coil to the plasma boundary surface. The minima for all coils are returned first, then the maxima in a flattened array as applicable.

NOTE: By default, assumes the plasma boundary is not fixed and its coordinates are computed at every iteration, for example if the equilibrium is changing in a single-stage optimization. If the plasma boundary is fixed, set eq_fixed=True to precompute the last closed flux surface coordinates and improve the efficiency of the calculation.

Parameters:
  • eq (Equilibrium or FourierRZToroidalSurface) – Equilibrium (or FourierRZToroidalSurface) that will be optimized to satisfy the Objective.

  • coil (CoilSet) – Coil(s) that are to be optimized.

  • mode (string, optional) – One of bound, min, or max for bounding both min and max plasma-coil distance or targeting only min or max plasma-coil distance. Defaults to bound.

  • plasma_grid (Grid, optional) – Collocation grid containing the nodes to evaluate plasma geometry at. Defaults to LinearGrid(M=eq.M_grid, N=eq.N_grid).

  • coil_grid (Grid, list, optional) – Collocation grid containing the nodes to evaluate coilset geometry at. Defaults to the default grid for the given coil-type, see coils.py and curve.py for more details. If a list, must have the same structure as coils.

  • eq_fixed (bool, optional) – Whether the equilibrium is fixed or not. If True, the last closed flux surface is fixed and its coordinates are precomputed, which saves on computation time during optimization, and self.things = [coil] only. If False, the surface coordinates are computed at every iteration. False by default, so that self.things = [coil, eq].

  • coils_fixed (bool, optional) – Whether the coils are fixed or not. If True, the coils are fixed and their coordinates are precomputed, which saves on computation time during optimization, and self.things = [eq] only. If False, the coil coordinates are computed at every iteration. False by default, so that self.things = [coil, eq].

  • use_softmin (bool, optional) – Use softmin (softmax) or hard min (max). Softmin is a smooth approximation to the actual minimum distance that may give smoother gradients, at the expense of being slightly more expensive and only an approximate extremum.

  • softmin_alpha (float, optional) – Parameter used for softmin. The larger softmin_alpha, the closer the softmin (softmax) approximates the hardmin (hardmax). softmin -> hardmin as softmin_alpha -> infinity.

  • dist_chunk_size (int > 0, optional) – When computing distances, how many coils to consider at once. Default is all coils, which is generally the fastest but requires the most memory. If there are a large number of coils, or if the resolution is very high, setting this to a small value will reduce peak memory usage at the cost of slightly increased runtime.

  • target (float, list, optional) – Target values for the coil objective. If a float, target is applied to all coils. If a list, must have the same structure as coil. Defaults to bounds=(0,1).

  • bounds (tuple of {float, list}, optional) – Lower and upper bounds on the objective. Overrides target. Bounds given as floats are applied to all coils. Bounds given as lists must have the same structure as coil. Defaults to bounds=(0,1).

  • weight (float, list, optional) – Weight values for the coil objective. If a float, weight is applied to all coils. If a list, must have the same structure as coil. Set weights to zero to exclude coils from the objective.

  • 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 normalize is True and the target is in physical units, this should also be set to True.

  • 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. Operates over all coils, not each individual coil.

  • deriv_mode ({"auto", "fwd", "rev"}) – Specify how to compute Jacobian matrix, either forward mode or reverse mode AD. auto selects forward or reverse mode based on the size of the input and output of the objective. Has no effect on self.grad or self.hess which 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 Jacobian jac_chunk_size columns at a time, instead of all at once. The memory usage of the Jacobian calculation is roughly memory 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 roughly t = t0+t1/jac_chunk_size so the larger the jac_chunk_size, the faster the calculation takes, at the cost of requiring more memory. If None, it will use the largest size i.e obj.dim_x. Can also help with Hessian computation memory, as Hessian is essentially jacfwd(jacrev(f)), and each of these operations may be chunked. Defaults to chunk_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 the auto chunk_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.

Methods

build([use_jit, verbose])

Build constant arrays.

compute(params_1[, params_2, constants])

Compute minimum/maximum distance between coils and the plasma/surface.

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

bounds

Lower and upper bounds of the objective.

built

Whether the transforms have been precomputed (or not).

constants

Constant parameters such as transforms and profiles.

dim_f

Number of objective equations.

fixed

Whether the objective fixes individual parameters (or linear combo).

linear

Whether the objective is a linear function (or nonlinear).

name

Name of objective (str).

normalization

normalizing scale factor.

scalar

Whether default "compute" method is a scalar or vector.

target

Target value(s) of the objective.

things

Optimizable things that this objective is tied to.

weight

Weighting to apply to the Objective, relative to other Objectives.