Skip to content

Commit

Permalink
make fixes for default values
Browse files Browse the repository at this point in the history
  • Loading branch information
YigitElma committed Sep 28, 2024
1 parent 2291615 commit 72f256a
Show file tree
Hide file tree
Showing 9 changed files with 182 additions and 79 deletions.
4 changes: 3 additions & 1 deletion desc/objectives/_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ class BootstrapRedlConsistency(_Objective):
"""

__doc__ = __doc__.rstrip() + collect_docs()
__doc__ = __doc__.rstrip() + collect_docs(
target_default="``target=0``.", bounds_default="``target=0``."
)

_coordinates = "r"
_units = "(T A m^-2)"
Expand Down
81 changes: 32 additions & 49 deletions desc/objectives/_coils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,9 @@ class _CoilObjective(_Objective):
"""

overwrite = {
"loss_function": """
loss_function : {None, 'mean', 'min', 'max'}, 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.
""",
}
__doc__ = __doc__.rstrip() + collect_docs(overwrite=overwrite)
__doc__ = __doc__.rstrip() + collect_docs(
coil=True,
)

def __init__(
self,
Expand Down Expand Up @@ -201,16 +194,6 @@ def compute(self, params, constants=None):
return data


overwrite_coil_length = _CoilObjective.overwrite.copy()
overwrite_coil_length[
"target"
] = """
target : float, ndarray, optional
Target value(s) of the objective. Only used if bounds is None.
Must be broadcastable to Objective.dim_f. If array, it has to
be flattened according to the number of inputs. """


class CoilLength(_CoilObjective):
"""Coil length.
Expand All @@ -224,11 +207,11 @@ class CoilLength(_CoilObjective):
"""

overwrite = overwrite_coil_length.copy()
overwrite["target"] = (
overwrite["target"].rstrip() + " Defaults to ``target=2*np.pi``.\n"
__doc__ = __doc__.rstrip() + collect_docs(
target_default="``target=2*np.pi``.",
bounds_default="``target=2*np.pi``.",
coil=True,
)
__doc__ = __doc__.rstrip() + collect_docs(overwrite=overwrite)

_scalar = False # Not always a scalar, if a coilset is passed in
_units = "(m)"
Expand Down Expand Up @@ -328,9 +311,11 @@ class CoilCurvature(_CoilObjective):
"""

overwrite = overwrite_coil_length
overwrite["target"] = overwrite["target"].rstrip() + "\n"
__doc__ = __doc__.rstrip() + collect_docs(overwrite=overwrite)
__doc__ = __doc__.rstrip() + collect_docs(
target_default="``bounds=(0,1).``",
bounds_default="``bounds=(0,1).``",
coil=True,
)

_scalar = False
_units = "(m^-1)"
Expand Down Expand Up @@ -425,9 +410,11 @@ class CoilTorsion(_CoilObjective):
"""

overwrite = overwrite_coil_length.copy()
overwrite["target"] = overwrite["target"].rstrip() + " Defaults to ``target=0``.\n"
__doc__ = __doc__.rstrip() + collect_docs(overwrite=overwrite)
__doc__ = __doc__.rstrip() + collect_docs(
target_default="``target=0``.",
bounds_default="``target=0``.",
coil=True,
)

_scalar = False
_units = "(m^-1)"
Expand Down Expand Up @@ -522,9 +509,11 @@ class CoilCurrentLength(CoilLength):
"""

overwrite = overwrite_coil_length.copy()
overwrite["target"] = overwrite["target"].rstrip() + " Defaults to ``target=0``.\n"
__doc__ = __doc__.rstrip() + collect_docs(overwrite=overwrite)
__doc__ = __doc__.rstrip() + collect_docs(
target_default="``target=0``.",
bounds_default="``target=0``.",
coil=True,
)

_scalar = False
_units = "(A*m)"
Expand Down Expand Up @@ -628,9 +617,7 @@ class CoilSetMinDistance(_Objective):
"""

overwrite = overwrite_coil_length.copy()
overwrite["target"] = overwrite["target"].rstrip() + "\n"
__doc__ = __doc__.rstrip() + collect_docs(overwrite=overwrite)
__doc__ = __doc__.rstrip() + collect_docs(coil=True)

_scalar = False
_units = "(m)"
Expand Down Expand Up @@ -780,8 +767,7 @@ class PlasmaCoilSetMinDistance(_Objective):
"""

overwrite = {"loss_function": overwrite_coil_length["loss_function"]}
__doc__ = __doc__.rstrip() + collect_docs(overwrite=overwrite)
__doc__ = __doc__.rstrip() + collect_docs(coil=True)

_scalar = False
_units = "(m)"
Expand Down Expand Up @@ -997,8 +983,11 @@ class QuadraticFlux(_Objective):
"""

overwrite = {"loss_function": ""}
__doc__ = __doc__.rstrip() + collect_docs(overwrite=overwrite)
__doc__ = __doc__.rstrip() + collect_docs(
target_default="``target=0``.",
bounds_default="``target=0``.",
loss_detail=" Note: has no effect for this objective.",
)

_scalar = False
_linear = False
Expand Down Expand Up @@ -1186,15 +1175,9 @@ class ToroidalFlux(_Objective):
"""

overwrite = {
"loss_function": """
loss_function : {None, 'mean', 'min', 'max'}, optional
Loss function to apply to the objective values once computed. This function
is called on the raw compute value, before any shifting, scaling, or
normalization. Note: has no effect for this objective.
"""
}
__doc__ = __doc__.rstrip() + collect_docs(overwrite=overwrite)
__doc__ = __doc__.rstrip() + collect_docs(
loss_detail=" Note: has no effect for this objective."
)

_coordinates = "rtz"
_units = "(Wb)"
Expand Down
24 changes: 18 additions & 6 deletions desc/objectives/_equilibrium.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ class ForceBalance(_Objective):
"""

__doc__ = __doc__.rstrip() + collect_docs()
__doc__ = __doc__.rstrip() + collect_docs(
target_default="``target=0``.", bounds_default="``target=0``."
)

_equilibrium = True
_coordinates = "rtz"
Expand Down Expand Up @@ -192,7 +194,9 @@ class ForceBalanceAnisotropic(_Objective):
"""

__doc__ = __doc__.rstrip() + collect_docs()
__doc__ = __doc__.rstrip() + collect_docs(
target_default="``target=0``.", bounds_default="``target=0``."
)

_units = "(N)"
_coordinates = "rtz"
Expand Down Expand Up @@ -327,7 +331,9 @@ class RadialForceBalance(_Objective):
"""

__doc__ = __doc__.rstrip() + collect_docs()
__doc__ = __doc__.rstrip() + collect_docs(
target_default="``target=0``.", bounds_default="``target=0``."
)

_equilibrium = True
_coordinates = "rtz"
Expand Down Expand Up @@ -462,7 +468,9 @@ class HelicalForceBalance(_Objective):
"""

__doc__ = __doc__.rstrip() + collect_docs()
__doc__ = __doc__.rstrip() + collect_docs(
target_default="``target=0``.", bounds_default="``target=0``."
)

_equilibrium = True
_coordinates = "rtz"
Expand Down Expand Up @@ -595,7 +603,9 @@ class Energy(_Objective):
"""

__doc__ = __doc__.rstrip() + collect_docs()
__doc__ = __doc__.rstrip() + collect_docs(
target_default="``target=0``.", bounds_default="``target=0``."
)

_scalar = True
_coordinates = ""
Expand Down Expand Up @@ -739,7 +749,9 @@ class CurrentDensity(_Objective):
"""

__doc__ = __doc__.rstrip() + collect_docs()
__doc__ = __doc__.rstrip() + collect_docs(
target_default="``target=0``.", bounds_default="``target=0``."
)

_equilibrium = True
_coordinates = "rtz"
Expand Down
12 changes: 9 additions & 3 deletions desc/objectives/_free_boundary.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ class VacuumBoundaryError(_Objective):
"""

__doc__ = __doc__.rstrip() + collect_docs()
__doc__ = __doc__.rstrip() + collect_docs(
target_default="``target=0``.", bounds_default="``target=0``."
)

_scalar = False
_linear = False
Expand Down Expand Up @@ -363,7 +365,9 @@ class BoundaryError(_Objective):
"""

__doc__ = __doc__.rstrip() + collect_docs()
__doc__ = __doc__.rstrip() + collect_docs(
target_default="``target=0``.", bounds_default="``target=0``."
)
__doc__ += """
Examples
--------
Expand Down Expand Up @@ -798,7 +802,9 @@ class BoundaryErrorNESTOR(_Objective):
"""

__doc__ = __doc__.rstrip() + collect_docs()
__doc__ = __doc__.rstrip() + collect_docs(
target_default="``target=0``.", bounds_default="``target=0``."
)

_scalar = False
_linear = False
Expand Down
12 changes: 9 additions & 3 deletions desc/objectives/_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ class GenericObjective(_Objective):
"""

__doc__ = __doc__.rstrip() + collect_docs()
__doc__ = __doc__.rstrip() + collect_docs(
target_default="``target=0``.", bounds_default="``target=0``."
)

_print_value_fmt = "Generic objective value: "

Expand Down Expand Up @@ -166,7 +168,9 @@ class LinearObjectiveFromUser(_FixedObjective):
"""

__doc__ = __doc__.rstrip() + collect_docs()
__doc__ = __doc__.rstrip() + collect_docs(
target_default="``target=0``.", bounds_default="``target=0``."
)

_scalar = False
_linear = True
Expand Down Expand Up @@ -278,7 +282,9 @@ class ObjectiveFromUser(_Objective):
"""

__doc__ = __doc__.rstrip() + collect_docs()
__doc__ = __doc__.rstrip() + collect_docs(
target_default="``target=0``.", bounds_default="``target=0``."
)
__doc__ += """
Examples
--------
Expand Down
47 changes: 39 additions & 8 deletions desc/objectives/_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ class AspectRatio(_Objective):
"""

__doc__ = __doc__.rstrip() + collect_docs()
__doc__ = __doc__.rstrip() + collect_docs(
target_default="``target=2``.",
bounds_default="``target=2``.",
normalize_detail=" Note: Has no effect for this objective.",
normalize_target_detail=" Note: Has no effect for this objective.",
loss_detail=" Note: Has no effect for this objective.",
)

_scalar = True
_units = "(dimensionless)"
Expand Down Expand Up @@ -166,7 +172,13 @@ class Elongation(_Objective):
"""

__doc__ = __doc__.rstrip() + collect_docs()
__doc__ = __doc__.rstrip() + collect_docs(
target_default="``target=1``.",
bounds_default="``target=1``.",
normalize_detail=" Note: Has no effect for this objective.",
normalize_target_detail=" Note: Has no effect for this objective.",
loss_detail=" Note: Has no effect for this objective.",
)

_scalar = True
_units = "(dimensionless)"
Expand Down Expand Up @@ -303,7 +315,11 @@ class Volume(_Objective):
"""

__doc__ = __doc__.rstrip() + collect_docs()
__doc__ = __doc__.rstrip() + collect_docs(
target_default="``target=1``.",
bounds_default="``target=1``.",
loss_detail=" Note: Has no effect for this objective.",
)

_scalar = True
_units = "(m^3)"
Expand Down Expand Up @@ -490,7 +506,10 @@ class PlasmaVesselDistance(_Objective):
"""

__doc__ = __doc__.rstrip() + collect_docs()
__doc__ = __doc__.rstrip() + collect_docs(
target_default="``bounds=(1,np.inf)``.",
bounds_default="``bounds=(1,np.inf)``.",
)

_coordinates = "rtz"
_units = "(m)"
Expand Down Expand Up @@ -806,7 +825,10 @@ class MeanCurvature(_Objective):
"""

__doc__ = __doc__.rstrip() + collect_docs()
__doc__ = __doc__.rstrip() + collect_docs(
target_default="``bounds=(-np.inf,0)``.",
bounds_default="``bounds=(-np.inf,0)``.",
)

_coordinates = "rtz"
_units = "(m^-1)"
Expand Down Expand Up @@ -943,7 +965,10 @@ class PrincipalCurvature(_Objective):
"""

__doc__ = __doc__.rstrip() + collect_docs()
__doc__ = __doc__.rstrip() + collect_docs(
target_default="``target=1``.",
bounds_default="``target=1``.",
)

_coordinates = "rtz"
_units = "(m^-1)"
Expand Down Expand Up @@ -1075,7 +1100,10 @@ class BScaleLength(_Objective):
"""

__doc__ = __doc__.rstrip() + collect_docs()
__doc__ = __doc__.rstrip() + collect_docs(
target_default="``bounds=(1,np.inf)``.",
bounds_default="``bounds=(1,np.inf)``.",
)

_coordinates = "rtz"
_units = "(m)"
Expand Down Expand Up @@ -1203,7 +1231,10 @@ class GoodCoordinates(_Objective):
"""

__doc__ = __doc__.rstrip() + collect_docs()
__doc__ = __doc__.rstrip() + collect_docs(
target_default="``target=0``.",
bounds_default="``target=0``.",
)

_scalar = False
_units = "(dimensionless)"
Expand Down
Loading

0 comments on commit 72f256a

Please sign in to comment.