desc.objectives.DeflationOperator
- class desc.objectives.DeflationOperator(thing, things_to_deflate, params_to_deflate_with=None, objective=None, sigma=1.0, power=2, target=None, bounds=None, weight=1, normalize=True, normalize_target=True, loss_function=None, deriv_mode='auto', name='Deflation', jac_chunk_size=None, deflation_type='power', multiple_deflation_type='prod', single_shift=False)Source
Deflation wrapper to be added to or to wrap objective to find new solutions.
If DeflationOperator is created while passing in an objective, the cost will be M*f where f is the objective’s computed value. If DeflationOperator is created without passing in an objective, the cost will be only M
Deflation is done on the passed-in list of parameters. This objective value will be large if the current state is close to one of the already-found states given by things_to_deflate, thus enabling new solutions to be found, and guarantees that old solutions are not found (as the objective increases without bound as an already-found solution is approached)
The deflation operator is defined as:
M(x;xₖ)=(||x−xₖ||₂)⁻ᵖ + σ
(if deflation_type=”power”)
or
M(𝐱;𝐱₁*) = exp(1/||𝐱−𝐱₁*||₂) + σ
(if deflation_type=”exp”)
where x is the state and xₖ the passed-in known state. If multiple known states are used for deflation, then M is computed for each deflated state, then either multipled or added together (depending on if multiple_deflation_type=”prod” or “sum”) to form the final cost. If an objective was passed in, this will then be multiplied by that objective’s compute.
- Parameters:
thing (Optimizable) – Optimizable that will be optimized to satisfy the Objective.
things_to_deflate (list containing elements of type {Optimizable, None}) – list of objects to use in deflation operator. Should be same type as thing. Can also contain None elements, in which case those will be ignored. The utility of allowing the None element and ignoring them is if one is using this objective in a loop with a pre-determined number of iterations and adding each result of the loop iterate to the things_to_deflate, it may trigger recompilation of the objective’s compute and jac/grad functions each time, which is wasteful. You can instead pass in a list containing None elements padding the list out to the max length it will attain. In this way, no recompilations will be triggered, and the entire loop will be completed much more quickly. If all things_to_deflate are None, this objective has zero cost (if not wrapping another objective) or simply returns the wrapped objective’s cost (if wrapping another objective)
params_to_deflate_with (nested list of dicts, optional) – Dict keys are the names of parameters to deflate (str), and dict values are the indices to deflate with for each corresponding parameter (int array). Use True (False) instead of an int array to deflate all (none) of the indices for that parameter. Must have the same pytree structure as thing.params_dict. The default is to deflate all indices of all parameters.
objective (_Objective, optional) – Objective to wrap with the DeflationOperator. If not None, the cost will be M(x;xₖ)f(x) where f(x) is the Objective’s cost. If None, then the cost returned will be M(x;xₖ). The objective must accept only one optimizable thing, and it must be the same as the thing passed to the DeflationOperator
sigma (float, optional) – shift parameter in deflation operator.
power (float, optional) – power parameter in deflation operator, ignored if deflation_type=”exp”.
deflation_type ({"power","exp"}) – What type of deflation to use. If “power”, uses the form pioneered by Farrell where M(𝐱;𝐱₁*) = ||𝐱−𝐱₁*||⁻ᵖ₂ + σ while “exp” uses the form from Riley 2024, where M(𝐱;𝐱₁*) = exp(1/||𝐱−𝐱₁*||₂) + σ. Defaults to “power”.
multiple_deflation_type ({"prod","sum"}) – When deflating multiple states, how to reduce the individual deflation terms Mᵢ(𝐱;𝐱ᵢ*). “prod” will multiply each individual deflation term together, while “sum” will add each individual term.
single_shift (bool,) – Whether to use a single shift or include the shift in each individual deflation term. i.e. whether to use M = σ + prod(||𝐱−𝐱_i*||⁻ᵖ₂) (if True) or to use M = prod( σ + ||𝐱−𝐱_i*||⁻ᵖ₂). Defaults to False.
target ({float, ndarray}, optional) – Target value(s) of the objective. Only used if
boundsisNone. Must be broadcastable toObjective.dim_f. Defaults totarget=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 totarget=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.
Methods
build([use_jit, verbose])Build constant arrays.
compute(params[, constants])Compute deflation error.
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, fse, f0se])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
Lower and upper bounds of the objective.
Whether the transforms have been precomputed (or not).
Constant parameters such as transforms and profiles.
Number of objective equations.
Whether the objective fixes individual parameters (or linear combo).
Whether the objective is a linear function (or nonlinear).
Name of objective (str).
normalizing scale factor.
Whether default "compute" method is a scalar or vector.
Target value(s) of the objective.
Optimizable things that this objective is tied to.
Weighting to apply to the Objective, relative to other Objectives.