Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev guide #353

Draft
wants to merge 49 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
94d7e43
start writing development guide for DESC explaining various aspects a…
dpanici Sep 1, 2022
09bb145
add to the compute section of dev guide
dpanici Sep 1, 2022
1b0e56c
make note about objectives
dpanici Sep 7, 2022
602b5f7
updated guide
dpanici Sep 7, 2022
98d81de
add info on optimization prob
dpanici Sep 8, 2022
a2a38da
start adding info on constrained opt method for equilibrium solve (ho…
dpanici Sep 8, 2022
588cd64
update Dev guide
dpanici Sep 12, 2022
e7d1790
Merge branch 'master' into dev_guide
unalmis Sep 22, 2022
360cda2
Merge branch 'master' into dev_guide
unalmis Sep 23, 2022
3d944e3
Merge branch 'master' into dev_guide
dpanici Dec 14, 2022
73bcd98
split dev guide into smaller notebooks
dpanici Dec 14, 2022
8966db3
update compute notebook
dpanici Dec 17, 2022
023eb1e
Merge branch 'master' into dev_guide
dpanici Dec 18, 2022
b7bb59c
update compute notes
dpanici Dec 18, 2022
9ef9983
Merge branch 'master' into dev_guide
unalmis Jan 11, 2023
0080140
clarify dim_f on objective creation docs
unalmis Jan 11, 2023
03dc381
Merge branch 'master' into dev_guide
unalmis Feb 13, 2023
9cd0cee
Merge branch 'master' into dev_guide
unalmis Feb 13, 2023
861de40
Merge branch 'master' into dev_guide
unalmis Feb 23, 2023
b2316ca
Update part of the guides
unalmis Apr 12, 2023
91cf72a
Merge branch 'master' into dev_guide
unalmis Apr 12, 2023
c284f6a
add missing grid info
unalmis Apr 12, 2023
c0232f4
fix typo
unalmis Apr 12, 2023
45f7379
Merge branch 'master' into dev_guide
unalmis Aug 26, 2023
60935d9
Fix tex labels of some compute funs
unalmis Aug 26, 2023
0651329
Merge branch 'master' into dev_guide
YigitElma Oct 20, 2024
326d331
fix after merge conflict
YigitElma Oct 20, 2024
739b4fc
add new notebooks to index.rst, delete some extra copies
YigitElma Oct 20, 2024
b4b6aa1
fix some build problems
YigitElma Oct 20, 2024
3b991f8
fix errors
YigitElma Oct 21, 2024
c986268
fix more errors
YigitElma Oct 21, 2024
4ffc092
change title versions
YigitElma Oct 21, 2024
6efe224
Merge branch 'master' into dev_guide
YigitElma Oct 21, 2024
3c1e23b
move dev_guide notebooks inside dev_guide folder
YigitElma Oct 21, 2024
9e2e7de
remove redundant stuff
YigitElma Nov 6, 2024
d5d4ee5
remove more
YigitElma Nov 6, 2024
14a9aef
Merge branch 'master' into dev_guide
YigitElma Nov 6, 2024
f9a9c7e
add notes
YigitElma Nov 6, 2024
1db7b6b
Merge branch 'master' into dev_guide
YigitElma Nov 12, 2024
8a9e128
remove some outdated notebooks
YigitElma Nov 27, 2024
a854cce
update index
YigitElma Nov 27, 2024
4365340
remove outdated one
YigitElma Nov 27, 2024
46b63e2
remove more outdated stuf
YigitElma Nov 27, 2024
0e72132
make backend stuff a notebook
YigitElma Nov 27, 2024
8c2d454
Merge remote-tracking branch 'origin/master' into dev_guide
YigitElma Nov 27, 2024
871a11a
move files
YigitElma Nov 27, 2024
f434485
take grid from master
YigitElma Nov 27, 2024
8c7194c
take adding_objectives from master
YigitElma Nov 27, 2024
0fb0d21
some minor update to transform and titles
YigitElma Nov 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions desc/compute/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1843,7 +1843,7 @@ def _omega_rr(params, transforms, profiles, data, **kwargs):

@register_compute_fun(
name="omega_rrr",
label="\\partial_{\rho \\rho \\rho} \\omega",
label="\\partial_{\\rho \\rho \\rho} \\omega",
units="rad",
units_long="radians",
description="Toroidal stream function, third radial derivative",
Expand All @@ -1861,7 +1861,7 @@ def _omega_rrr(params, transforms, profiles, data, **kwargs):

@register_compute_fun(
name="omega_rrrr",
label="\\partial_{\rho \\rho \\rho \\rho} \\omega",
label="\\partial_{\\rho \\rho \\rho \\rho} \\omega",
units="rad",
units_long="radians",
description="Toroidal stream function, fourth radial derivative",
Expand All @@ -1879,7 +1879,7 @@ def _omega_rrrr(params, transforms, profiles, data, **kwargs):

@register_compute_fun(
name="omega_rrrt",
label="\\partial_{\rho \\rho \\rho \\theta} \\omega",
label="\\partial_{\\rho \\rho \\rho \\theta} \\omega",
units="rad",
units_long="radians",
description="Toroidal stream function, fourth derivative wrt radial coordinate"
Expand All @@ -1898,7 +1898,7 @@ def _omega_rrrt(params, transforms, profiles, data, **kwargs):

@register_compute_fun(
name="omega_rrrz",
label="\\partial_{\rho \\rho \\rho \\zeta} \\omega",
label="\\partial_{\\rho \\rho \\rho \\zeta} \\omega",
units="rad",
units_long="radians",
description="Toroidal stream function, fourth derivative wrt radial coordinate"
Expand Down
2 changes: 1 addition & 1 deletion desc/compute/_equil.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ def _F_zeta(params, transforms, profiles, data, **kwargs):

@register_compute_fun(
name="F_helical",
label="F_{helical}",
label="F_{\\mathrm{helical}}",
units="A",
units_long="Amperes",
description="Covariant helical component of force balance error",
Expand Down
2 changes: 1 addition & 1 deletion desc/compute/_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -3225,7 +3225,7 @@ def _min_tz_modB(params, transforms, profiles, data, **kwargs):

@register_compute_fun(
name="effective r/R0",
label="(r / R_0)_{effective}",
label="(r / R_0)_{\\mathrm{effective}}",
units="~",
units_long="None",
description="Effective local inverse aspect ratio, based on max and min |B|",
Expand Down
2 changes: 1 addition & 1 deletion desc/compute/_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ def _R0_over_a(params, transforms, profiles, data, **kwargs):

@register_compute_fun(
name="a_major/a_minor",
label="a_{major} / a_{minor}",
label="a_{\\mathrm{major}} / a_{\\mathrm{minor}}",
units="~",
units_long="None",
description="Maximum elongation",
Expand Down
50 changes: 25 additions & 25 deletions desc/compute/_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def _sqrtg_pest(params, transforms, profiles, data, **kwargs):

@register_compute_fun(
name="|e_theta x e_zeta|",
label="|e_{\\theta} \\times e_{\\zeta}|",
label="|\\mathbf{e}_{\\theta} \\times \\mathbf{e}_{\\zeta}|",
units="m^{2}",
units_long="square meters",
description="2D Jacobian determinant for constant rho surface",
Expand All @@ -79,7 +79,7 @@ def _e_theta_x_e_zeta(params, transforms, profiles, data, **kwargs):

@register_compute_fun(
name="|e_theta x e_zeta|_r",
label="\\partial_{\\rho} |e_{\\theta} \\times e_{\\zeta}|",
label="\\partial_{\\rho} |\\mathbf{e}_{\\theta} \\times \\mathbf{e}_{\\zeta}|",
units="m^{2}",
units_long="square meters",
description="2D Jacobian determinant for constant rho surface"
Expand Down Expand Up @@ -113,7 +113,7 @@ def _e_theta_x_e_zeta_r(params, transforms, profiles, data, **kwargs):

@register_compute_fun(
name="|e_theta x e_zeta|_rr",
label="\\partial_{\\rho \\rho} |e_{\\theta} \\times e_{\\zeta}|",
label="\\partial_{\\rho\\rho} |\\mathbf{e}_{\\theta} \\times \\mathbf{e}_{\\zeta}|",
units="m^{2}",
units_long="square meters",
description="2D Jacobian determinant for constant rho surface"
Expand Down Expand Up @@ -152,7 +152,7 @@ def _e_theta_x_e_zeta_rr(params, transforms, profiles, data, **kwargs):

@register_compute_fun(
name="|e_zeta x e_rho|",
label="|e_{\\zeta} \\times e_{\\rho}|",
label="|\\mathbf{e}_{\\zeta} \\times \\mathbf{e}_{\\rho}|",
units="m^{2}",
units_long="square meters",
description="2D Jacobian determinant for constant theta surface",
Expand All @@ -174,7 +174,7 @@ def _e_zeta_x_e_rho(params, transforms, profiles, data, **kwargs):

@register_compute_fun(
name="|e_rho x e_theta|",
label="|e_{\\rho} \\times e_{\\theta}|",
label="|\\mathbf{e}_{\\rho} \\times \\mathbf{e}_{\\theta}|",
units="m^{2}",
units_long="square meters",
description="2D Jacobian determinant for constant zeta surface",
Expand All @@ -198,7 +198,7 @@ def _e_rho_x_e_theta(params, transforms, profiles, data, **kwargs):

@register_compute_fun(
name="|e_rho x e_theta|_r",
label="\\partial_{\\rho} |e_{\\rho} \\times e_{\\theta}|",
label="\\partial_{\\rho} |\\mathbf{e}_{\\rho} \\times \\mathbf{e}_{\\theta}|",
units="m^{2}",
units_long="square meters",
description="2D Jacobian determinant for constant zeta surface"
Expand Down Expand Up @@ -232,7 +232,7 @@ def _e_rho_x_e_theta_r(params, transforms, profiles, data, **kwargs):

@register_compute_fun(
name="|e_rho x e_theta|_rr",
label="\\partial_{\\rho \\rho} |e_{\\rho} \\times e_{\\theta}|",
label="\\partial_{\\rho \\rho} |\\mathbf{e}_{\\rho} \\times \\mathbf{e}_{\\theta}|",
units="m^{2}",
units_long="square meters",
description="2D Jacobian determinant for constant zeta surface"
Expand Down Expand Up @@ -1349,7 +1349,7 @@ def _g_sup_tz(params, transforms, profiles, data, **kwargs):

@register_compute_fun(
name="g^rr_r",
label="g^{\\rho}{\\rho}_{\\rho}",
label="\\partial_{\\rho} g^{\\rho}{\\rho}",
units="m^-2",
units_long="inverse square meters",
description="Radial/Radial element of contravariant metric tensor, "
Expand All @@ -1368,7 +1368,7 @@ def _g_sup_rr_r(params, transforms, profiles, data, **kwargs):

@register_compute_fun(
name="g^rt_r",
label="g^{\\rho}{\\theta}_{\\rho}",
label="\\partial_{\\rho} g^{\\rho}{\\theta}",
units="m^-2",
units_long="inverse square meters",
description="Radial/Poloidal element of contravariant metric tensor, "
Expand All @@ -1389,7 +1389,7 @@ def _g_sup_rt_r(params, transforms, profiles, data, **kwargs):

@register_compute_fun(
name="g^rz_r",
label="g^{\\rho}{\\zeta}_{\\rho}",
label="\\partial_{\\rho} g^{\\rho}{\\zeta}",
units="m^-2",
units_long="inverse square meters",
description="Radial/Toroidal element of contravariant metric tensor, "
Expand All @@ -1410,7 +1410,7 @@ def _g_sup_rz_r(params, transforms, profiles, data, **kwargs):

@register_compute_fun(
name="g^tt_r",
label="g^{\\theta}{\\theta}_{\\rho}",
label="\\partial_{\\rho} g^{\\theta}{\\theta}",
units="m^-2",
units_long="inverse square meters",
description="Poloidal/Poloidal element of contravariant metric tensor, "
Expand All @@ -1429,7 +1429,7 @@ def _g_sup_tt_r(params, transforms, profiles, data, **kwargs):

@register_compute_fun(
name="g^tz_r",
label="g^{\\theta}{\\zeta}_{\\rho}",
label="\\partial_{\\rho} g^{\\theta}{\\zeta}",
units="m^-2",
units_long="inverse square meters",
description="Poloidal/Toroidal element of contravariant metric tensor, "
Expand All @@ -1450,7 +1450,7 @@ def _g_sup_tz_r(params, transforms, profiles, data, **kwargs):

@register_compute_fun(
name="g^zz_r",
label="g^{\\zeta}{\\zeta}_{\\rho}",
label="\\partial_{\\rho} g^{\\zeta}{\\zeta}",
units="m^-2",
units_long="inverse square meters",
description="Toroidal/Toroidal element of contravariant metric tensor, "
Expand All @@ -1469,7 +1469,7 @@ def _g_sup_zz_r(params, transforms, profiles, data, **kwargs):

@register_compute_fun(
name="g^rr_t",
label="g^{\\rho}{\\rho}_{\\theta}",
label="\\partial_{\\theta} g^{\\rho}{\\rho}",
units="m^-2",
units_long="inverse square meters",
description="Radial/Radial element of contravariant metric tensor, "
Expand All @@ -1488,7 +1488,7 @@ def _g_sup_rr_t(params, transforms, profiles, data, **kwargs):

@register_compute_fun(
name="g^rt_t",
label="g^{\\rho}{\\theta}_{\\theta}",
label="\\partial_{\\theta} g^{\\rho}{\\theta}",
units="m^-2",
units_long="inverse square meters",
description="Radial/Poloidal element of contravariant metric tensor, "
Expand All @@ -1509,7 +1509,7 @@ def _g_sup_rt_t(params, transforms, profiles, data, **kwargs):

@register_compute_fun(
name="g^rz_t",
label="g^{\\rho}{\\zeta}_{\\theta}",
label="\\partial_{\\theta} g^{\\rho}{\\zeta}",
units="m^-2",
units_long="inverse square meters",
description="Radial/Toroidal element of contravariant metric tensor, "
Expand All @@ -1530,7 +1530,7 @@ def _g_sup_rz_t(params, transforms, profiles, data, **kwargs):

@register_compute_fun(
name="g^tt_t",
label="g^{\\theta}{\\theta}_{\\theta}",
label="\\partial_{\\theta} g^{\\theta}{\\theta}",
units="m^-2",
units_long="inverse square meters",
description="Poloidal/Poloidal element of contravariant metric tensor, "
Expand All @@ -1549,7 +1549,7 @@ def _g_sup_tt_t(params, transforms, profiles, data, **kwargs):

@register_compute_fun(
name="g^tz_t",
label="g^{\\theta}{\\zeta}_{\\theta}",
label="\\partial_{\\theta} g^{\\theta}{\\zeta}",
units="m^-2",
units_long="inverse square meters",
description="Poloidal/Toroidal element of contravariant metric tensor, "
Expand All @@ -1570,7 +1570,7 @@ def _g_sup_tz_t(params, transforms, profiles, data, **kwargs):

@register_compute_fun(
name="g^zz_t",
label="g^{\\zeta}{\\zeta}_{\\theta}",
label="\\partial_{\\theta} g^{\\zeta}{\\zeta}",
units="m^-2",
units_long="inverse square meters",
description="Toroidal/Toroidal element of contravariant metric tensor, "
Expand All @@ -1589,7 +1589,7 @@ def _g_sup_zz_t(params, transforms, profiles, data, **kwargs):

@register_compute_fun(
name="g^rr_z",
label="g^{\\rho}{\\rho}_{\\zeta}",
label="\\partial_{\\zeta} g^{\\rho}{\\rho}",
units="m^-2",
units_long="inverse square meters",
description="Radial/Radial element of contravariant metric tensor, "
Expand All @@ -1608,7 +1608,7 @@ def _g_sup_rr_z(params, transforms, profiles, data, **kwargs):

@register_compute_fun(
name="g^rt_z",
label="g^{\\rho}{\\theta}_{\\zeta}",
label="\\partial_{\\zeta} g^{\\rho}{\\theta}",
units="m^-2",
units_long="inverse square meters",
description="Radial/Poloidal element of contravariant metric tensor, "
Expand All @@ -1629,7 +1629,7 @@ def _g_sup_rt_z(params, transforms, profiles, data, **kwargs):

@register_compute_fun(
name="g^rz_z",
label="g^{\\rho}{\\zeta}_{\\zeta}",
label="\\partial_{\\zeta} g^{\\rho}{\\zeta}",
units="m^-2",
units_long="inverse square meters",
description="Radial/Toroidal element of contravariant metric tensor, "
Expand All @@ -1650,7 +1650,7 @@ def _g_sup_rz_z(params, transforms, profiles, data, **kwargs):

@register_compute_fun(
name="g^tt_z",
label="g^{\\theta}{\\theta}_{\\zeta}",
label="\\partial_{\\zeta} g^{\\theta}{\\theta}",
units="m^-2",
units_long="inverse square meters",
description="Poloidal/Poloidal element of contravariant metric tensor, "
Expand All @@ -1669,7 +1669,7 @@ def _g_sup_tt_z(params, transforms, profiles, data, **kwargs):

@register_compute_fun(
name="g^tz_z",
label="g^{\\theta}{\\zeta}_{\\zeta}",
label="\\partial_{\\zeta} g^{\\theta}{\\zeta}",
units="m^-2",
units_long="inverse square meters",
description="Poloidal/Toroidal element of contravariant metric tensor, "
Expand All @@ -1690,7 +1690,7 @@ def _g_sup_tz_z(params, transforms, profiles, data, **kwargs):

@register_compute_fun(
name="g^zz_z",
label="g^{\\zeta}{\\zeta}_{\\zeta}",
label="\\partial_{\\zeta} g^{\\zeta}{\\zeta}",
units="m^-2",
units_long="inverse square meters",
description="Toroidal/Toroidal element of contravariant metric tensor, "
Expand Down
11 changes: 8 additions & 3 deletions docs/adding_objectives.rst
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ A full example objective with comments describing key points is given below:
name="QS triple product",
):
# we don't have to do much here, mostly just call ``super().__init__()``
# to inherit common initialization logic from ``desc.objectives._Objective``
if target is None and bounds is None:
target = 0 # default target value
self.grid = grid
Expand Down Expand Up @@ -118,9 +119,13 @@ A full example objective with comments describing key points is given below:
self.grid = LinearGrid(M=eq.M_grid, N=eq.N_grid, NFP=eq.NFP, sym=eq.sym)

# dim_f = size of the output vector returned by self.compute
# usually the same as self.grid.num_nodes, unless you're doing some downsampling
# or averaging etc.
self._dim_f = self.grid.num_nodes
# self.compute refers to the objective's own compute method
# Typically an objective returns the output of a quantity computed in
# ``desc.compute``, with some additional scale factor.
# In these cases dim_f should match the size of the quantity calculated in
# ``desc.compute`` (for example self.grid.num_nodes).
# If the objective does post-processing on the quantity, like downsampling or
# averaging, then dim_f should be changed accordingly.
# What data from desc.compute is needed? Here we want the QS triple product.
self._data_keys = ["f_T"]
# what arguments should be passed to self.compute
Expand Down
23 changes: 23 additions & 0 deletions docs/dev_guide/backend.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Backend
-------


DESC uses JAX for faster compile times, automatic differentiation, and other scientific computing tools.
The purpose of ``backend.py`` is to determine whether DESC may take advantage of JAX and GPUs or default to standard ``numpy`` and CPUs.

JAX provides a ``numpy`` style API for array operations.
In many cases, to take advantage of JAX, one only needs to replace calls to ``numpy`` with calls to ``jax.numpy``.
A convenient way to do this is with the import statement ``import jax.numpy as jnp``.

Of course if such an import statement is used in DESC, and DESC is run on a machine where JAX is not installed, then a runtime error is thrown.
We would prefer if DESC still works on machines where JAX is not installed.
With that goal, in functions which can benefit from JAX, we use the following import statement: ``from desc.backend import jnp``.
``desc.backend.jnp`` is an alias to ``jax.numpy`` if JAX is installed and ``numpy`` otherwise.

While ``jax.numpy`` attempts to serve as a drop in replacement for ``numpy``, it imposes some constraints on how the code is written.
For example, ``jax.numpy`` arrays are immutable.
This means in-place updates to elements in arrays is not possible.
To update elements in ``jax.numpy`` arrays, memory needs to be allocated to create a new array with the updated element.
Similarly, JAX's JIT compilation requires code flow structures such as loops and conditionals to be written in a specific way.

The utility functions in ``desc.backend`` provide a simple interface to perform these operations.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add answers to (good) questions like this here:
#854 (comment)
#854 (comment)

Loading