Skip to content

Commit

Permalink
Merge branch 'master' into dd/hotfix
Browse files Browse the repository at this point in the history
  • Loading branch information
dpanici authored Jun 25, 2024
2 parents 0b0588f + c94aa20 commit 80c40ab
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
4 changes: 1 addition & 3 deletions desc/compute/_curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -1061,9 +1061,7 @@ def _torsion(params, transforms, profiles, data, **kwargs):
coordinates="",
data=["ds", "x_s"],
parameterization=[
"desc.geometry.curve.FourierRZCurve",
"desc.geometry.curve.FourierXYZCurve",
"desc.geometry.curve.FourierPlanarCurve",
"desc.geometry.core.Curve",
],
)
def _length(params, transforms, profiles, data, **kwargs):
Expand Down
17 changes: 13 additions & 4 deletions desc/compute/data_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,20 @@ def _decorator(func):
flag = False
for base_class, superclasses in _class_inheritance.items():
if p in superclasses or p == base_class:
# already registered ?
if name in data_index[base_class]:
raise ValueError(
f"Already registered function with parameterization {p} and name {name}."
)
if p == data_index[base_class][name]["parameterization"]:
raise ValueError(
f"Already registered function with parameterization {p} and name {name}."
)
# if it was already registered from a parent class, we prefer
# the child class.
inheritance_order = [base_class] + superclasses
if inheritance_order.index(p) > inheritance_order.index(
data_index[base_class][name]["parameterization"]
):
continue
d["parameterization"] = p
data_index[base_class][name] = d.copy()
all_kwargs[base_class][name] = kwargs
for alias in aliases:
Expand Down Expand Up @@ -228,7 +238,6 @@ def _decorator(func):
],
"desc.magnetic_fields._core.OmnigenousField": [],
}

data_index = {p: {} for p in _class_inheritance.keys()}
all_kwargs = {p: {} for p in _class_inheritance.keys()}
allowed_kwargs = set()
10 changes: 8 additions & 2 deletions docs/adding_compute_funs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,14 @@ metadata about the quantity. The necessary fields are detailed below:
are specified in ``axis_limit_data``. The dependencies specified in this list are
marked to be computed only when there is a node at the magnetic axis.
* ``parameterization``: what sorts of DESC objects is this function for. Most functions
will just be for ``Equilibrium``, but some methods may also be for ``desc.geometry.Curve``,
or specific types eg ``desc.geometry.FourierRZCurve``.
will just be for ``Equilibrium``, but some methods may also be for ``desc.geometry.core.Curve``,
or specific types eg ``desc.geometry.curve.FourierRZCurve``. If a quantity is computed differently
for a subclass versus a superclass, then one may define a compute function for the superclass
(e.g. for ``desc.geometry.Curve``) which will be used for that class and any of its subclasses,
and then if a specific subclass requires a different method, one may define a second compute function for
the same quantity, with a parameterization for that subclass (e.g. ``desc.geometry.curve.SplineXYZCurve``).
See the compute definitions for the ``length`` quantity in ``compute/_curve.py`` for an example of this,
which is similar to the inheritance structure of Python classes.
* ``kwargs``: If the compute function requires any additional arguments they should
be specified like ``kwarg="description"`` where ``kwarg`` is replaced by the actual
keyword argument, and ``"description"`` is a string describing what it is.
Expand Down

0 comments on commit 80c40ab

Please sign in to comment.