Skip to content

Commit 472cc44

Browse files
authored
Merge pull request #241 from hiddenSymmetries/ml/docs_20220625
Improvements to documentation
2 parents c362ded + 8bab241 commit 472cc44

File tree

17 files changed

+352
-182
lines changed

17 files changed

+352
-182
lines changed

docs/source/example_coils.rst

Lines changed: 152 additions & 129 deletions
Large diffs are not rendered by default.

docs/source/example_quasisymmetry.rst

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ imports of the classes and functions we will need::
4141

4242
import numpy as np
4343
from simsopt.util import MpiPartition
44-
from simsopt.mhd import Vmec
45-
from simsopt.mhd import QuasisymmetryRatioResidual
44+
from simsopt.mhd import Vmec, QuasisymmetryRatioResidual
4645
from simsopt.objectives import LeastSquaresProblem
4746
from simsopt.solve import least_squares_mpi_solve
4847

@@ -235,8 +234,7 @@ As usual, we begin with the necessary imports::
235234

236235
import numpy as np
237236
from simsopt.util import MpiPartition
238-
from simsopt.mhd import Vmec
239-
from simsopt.mhd import QuasisymmetryRatioResidual
237+
from simsopt.mhd import Vmec, QuasisymmetryRatioResidual
240238
from simsopt.objectives import LeastSquaresProblem
241239
from simsopt.solve import least_squares_mpi_solve
242240

@@ -274,7 +272,7 @@ axisymmetric::
274272

275273
It can be seen here that we are seeking a configuration with aspect
276274
ratio 6, and average iota of 0.42, slightly above the resonance at 2 /
277-
5 = 0.4. The function :func:`simsopt.mhd.vmec.Vmec.mean_iota()` used
275+
5 = 0.4. The function :func:`simsopt.mhd.Vmec.mean_iota()` used
278276
here returns :math:`\int_0^1 \iota\, ds` where :math:`s` is the
279277
toroidal flux normalized by its value at the VMEC boundary.
280278

@@ -336,7 +334,7 @@ Bmn objective
336334

337335
Here we show an alternative method of quasisymmetry optimization using
338336
a different objective function,
339-
:obj:`simsopt.mhd.boozer.Quasisymmetry`, based on the
337+
:obj:`simsopt.mhd.Quasisymmetry`, based on the
340338
symmetry-breaking Fourier mode aplitudes :math:`B_{m,n}` in Boozer
341339
coordinates. This example can also be found in the
342340
``examples/2_Intermediate`` directory as
@@ -345,8 +343,7 @@ coordinates. This example can also be found in the
345343
In this case, the imports needed are::
346344

347345
from simsopt.util import MpiPartition
348-
from simsopt.mhd import Vmec
349-
from simsopt.mhd import Boozer, Quasisymmetry
346+
from simsopt.mhd import Vmec, Boozer, Quasisymmetry
350347
from simsopt.objectives import LeastSquaresProblem
351348
from simsopt.solve import least_squares_mpi_solve
352349

docs/source/example_vmec_only.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ For simplicity, MPI parallelization will not be used for now.
6060
To start, we must import several classes::
6161

6262
from simsopt.mhd import Spec
63-
from simsopt.objectives.least_squares import LeastSquaresProblem
64-
from simsopt.solve.serial import least_squares_serial_solve
63+
from simsopt.objectives import LeastSquaresProblem
64+
from simsopt.solve import least_squares_serial_solve
6565

6666
Then we create the equilibrium object, starting from an input file::
6767

@@ -141,15 +141,15 @@ computation, or both at the same time. To introduce MPI we first
141141
initialize an :obj:`simsopt.util.MpiPartition` object and choose
142142
the number of worker groups. The instance is then passed as an
143143
argument to the Vmec object and to the
144-
:meth:`simsopt.solver.mpi_solve.least_squares_mpi_solve` function.
144+
:meth:`simsopt.solve.least_squares_mpi_solve` function.
145145
For more details about MPI, see :doc:`mpi`.
146146

147147
The complete example is then as follows::
148148

149-
from simsopt.util.mpi import MpiPartition
149+
from simsopt.util import MpiPartition
150150
from simsopt.mhd import Vmec
151151
from simsopt.objectives import LeastSquaresProblem
152-
from simsopt.solve.mpi import least_squares_mpi_solve
152+
from simsopt.solve import least_squares_mpi_solve
153153

154154
# In the next line, we can adjust how many groups the pool of MPI
155155
# processes is split into.

docs/source/fields.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ operator creates the latter.)
194194

195195
Example::
196196

197-
from simsopt.field.magneticfieldclasses import ToroidalField, CircularCoil
197+
from simsopt.field import ToroidalField, CircularCoil
198198
199199
field1 = CircularCoil(I=1.e7, r0=1.)
200200
field2 = ToroidalField(R0=1., B0=1.)

docs/source/geo.rst

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@ the derivative of quantities such as curvature (via
5353
``Curve.dkappa_by_dcoeff()``) or torsion (via
5454
``Curve.dtorsion_by_dcoeff()``).
5555

56-
A number of quantities are implemented in
57-
:obj:`simsopt.geo.curveobjectives` and are computed on a
56+
A number of objective functions are available in
57+
:obj:`simsopt.geo` and are computed on a
5858
:obj:`simsopt.geo.Curve`:
5959

60-
- ``CurveLength``: computes the length of the ``Curve``.
61-
- ``LpCurveCurvature``: computes a penalty based on the :math:`L_p` norm of the curvature on a curve.
62-
- ``LpCurveTorsion``: computes a penalty based on the :math:`L_p` norm of the torsion on a curve.
63-
- ``CurveCurveDistance``: computes a penalty term on the minimum distance between a set of curves.
64-
- ``CurveSurfaceDistance``: computes a penalty term on the minimum distance between a set of curves and a surface.
60+
- :obj:`~simsopt.geo.CurveLength`: computes the length of the ``Curve``.
61+
- :obj:`~simsopt.geo.LpCurveCurvature`: computes a penalty based on the :math:`L_p` norm of the curvature on a curve.
62+
- :obj:`~simsopt.geo.LpCurveTorsion`: computes a penalty based on the :math:`L_p` norm of the torsion on a curve.
63+
- :obj:`~simsopt.geo.CurveCurveDistance`: computes a penalty term on the minimum distance between a set of curves.
64+
- :obj:`~simsopt.geo.CurveSurfaceDistance`: computes a penalty term on the minimum distance between a set of curves and a surface.
6565

6666
The value of the quantity and its derivative with respect to the curve
6767
dofs can be obtained by calling e.g., ``CurveLength.J()`` and
@@ -152,10 +152,10 @@ the :obj:`~simsopt.geo.Curve` class:
152152
- ``Surface.second_fund_form()``: returns a ``(n_phi, n_theta, 3)`` array containing :math:`[\hat{\textbf{n}}(\phi_i, \theta_j) \cdot \partial^2_{\phi,\phi} \Gamma(\phi_i, \theta_j), \hat{\textbf{n}}(\phi_i, \theta_j) \cdot \partial^2_{\phi,\theta} \Gamma(\phi_i, \theta_j), \hat{\textbf{n}}(\phi_i, \theta_j) \cdot \partial^2_{\theta,\theta} \Gamma(\phi_i, \theta_j)]` for :math:`i\in\{1, \ldots, n_\phi\}, j\in\{1, \ldots, n_\theta\}` where :math:`\hat{\textbf{n}}` is the unit normal.
153153
- ``Surface.surface_curvatures()``: returns a ``(n_phi, n_theta, 4)`` array containing :math:`[H(\phi_i, \theta_j),K(\phi_i, \theta_j),\kappa_1(\phi_i, \theta_j),\kappa_2(\phi_i, \theta_j)]` for :math:`i\in\{1, \ldots, n_\phi\}, j\in\{1, \ldots, n_\theta\}` where :math:`H` is the mean curvature, :math:`K` is the Gaussian curvature, and :math:`\kappa_{1,2}` are the principal curvatures with :math:`\kappa_1>\kappa_2`.
154154

155-
A number of quantities are implemented in :obj:`simsopt.geo.surfaceobjectives` and are computed on a :obj:`simsopt.geo.Surface`:
155+
A number of objective functions related to surfaces are available in :obj:`simsopt.geo`:
156156

157-
- ``ToroidalFlux``: computes the flux through a toroidal cross section of a ``Surface``.
158-
- ``PrincipalCurvature``: computes a metric which penalizes large values of the principal curvatures of a given ``Surface``.
157+
- :obj:`~simsopt.geo.ToroidalFlux`: computes the flux through a toroidal cross section of a ``Surface``.
158+
- :obj:`~simsopt.geo.PrincipalCurvature`: computes a metric which penalizes large values of the principal curvatures of a given ``Surface``.
159159

160160
The value of the quantity and its derivative with respect to the surface dofs can be obtained by calling e.g., ``ToroidalFlux.J()`` and ``ToroidalFlux.dJ_dsurfacecoefficients()``.
161161

@@ -185,12 +185,12 @@ plotting engine by passing the ``engine`` keyword argument, e.g. if
185185
can use the ``close`` argument to control whether segments are drawn
186186
between the last quadrature point and the first. For these and other
187187
options, see the API documentation for
188-
:func:`simsopt.geo.curve.Curve.plot()` and
189-
:func:`simsopt.geo.surface.Surface.plot()`.
188+
:func:`simsopt.geo.Curve.plot()` and
189+
:func:`simsopt.geo.Surface.plot()`.
190190

191191
If you have multiple curve and/or surface objects, a convenient way to
192192
plot them together on the same axes is the function
193-
:func:`simsopt.geo.plotting.plot()`, which accepts a list of objects as
193+
:func:`simsopt.geo.plot()`, which accepts a list of objects as
194194
its argument. Any keywords passed to this function are passed to the
195195
``.plot()`` methods of the individual objects, so you may wish to pass
196196
keywords such as ``engine`` or ``close``. Alternatively, you can also
@@ -201,6 +201,6 @@ It is also possible to export curve and surface objects in VTK format,
201201
so they can be viewed in Paraview. This functionality requires the
202202
python package ``pyevtk``, which can be installed via ``pip install
203203
pyevtk``. A list of curve objects can be exported using the function
204-
:func:`simsopt.geo.curve.curves_to_vtk()`. To export a VTK file for a
204+
:func:`simsopt.geo.curves_to_vtk()`. To export a VTK file for a
205205
surface, call the ``.to_vtk(filename)`` function of the object. See
206-
:func:`simsopt.geo.surface.Surface.to_vtk()` for more details.
206+
:func:`simsopt.geo.Surface.to_vtk()` for more details.

docs/source/index.rst

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,10 @@ optimization. Others include `STELLOPT
8787

8888
.. toctree::
8989
:maxdepth: 3
90-
:caption: API
90+
:caption: API reference
9191

92-
simsopt <simsopt_user>
93-
94-
.. toctree::
95-
:maxdepth: 3
96-
:caption: Developer's API
97-
98-
simsopt
92+
Public functions and classes <simsopt_user>
93+
Full listing (for developers) <simsopt>
9994

10095
Indices and tables
10196
==================

docs/source/optimizable.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ algorithms.
2525

2626
Users can create their own optimizable objects in two ways. One method
2727
is to create a standard python function, and apply the
28-
:obj:`simsopt.make_optimizable()` function to it, as explained
28+
:meth:`simsopt.make_optimizable()` function to it, as explained
2929
below. Or, you can directly subclass
3030
:obj:`simsopt._core.Optimizable`.
3131

@@ -533,7 +533,7 @@ Specifying least-squares objective functions
533533

534534
A common use case is to minimize a nonlinear least-squares objective
535535
function, which consists of a sum of several terms. In this case the
536-
:obj:`simsopt.objectives.least_squares.LeastSquaresProblem`
536+
:obj:`simsopt.objectives.LeastSquaresProblem`
537537
class can be used. Suppose we want to solve a least-squares
538538
optimization problem in which an
539539
:obj:`~simsopt._core.Optimizable` object ``obj`` has
@@ -562,18 +562,18 @@ The corresponding objective funtion is then ``weight1 *
562562
scalar functions and by 1D numpy array-valued functions. Note that
563563
the function handles that are specified should be members of an
564564
:obj:`~simsopt._core.Optimizable` object. As
565-
:obj:`~simsopt.objectives.least_squares.LeastSquaresProblem` is
565+
:obj:`~simsopt.objectives.LeastSquaresProblem` is
566566
a subclass of :obj:`~simsopt._core.Optimizable`, the
567567
free dofs of all the objects that go into the objective function are
568568
available in the global state vector ``prob.x``. The overall scalar
569569
objective function is available from
570-
:func:`simsopt.objectives.least_squares.LeastSquaresProblem.objective`.
570+
:func:`simsopt.objectives.LeastSquaresProblem.objective`.
571571
The vector of residuals before scaling by the ``weight`` factors
572572
``obj.func() - goal`` is available from
573-
:func:`simsopt.objectives.least_squares.LeastSquaresProblem.unweighted_residuals`.
573+
:func:`simsopt.objectives.LeastSquaresProblem.unweighted_residuals`.
574574
The vector of residuals after scaling by the ``weight`` factors,
575575
``sqrt(weight) * (obj.func() - goal)``, is available from
576-
:func:`simsopt.objectives.least_squares.LeastSquaresProblem.residuals`.
576+
:func:`simsopt.objectives.LeastSquaresProblem.residuals`.
577577

578578
Least-squares problems can also be defined in an alternative way::
579579

docs/source/overview.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ Simsopt does not use input data files to define optimization problems,
2525
in contrast to ``STELLOPT``. Rather, problems are specified using a
2626
python driver script, in which objects are defined and
2727
configured. However, objects related to specific physics codes may use
28-
their own input files. In particular, a :obj:`simsopt.mhd.vmec.Vmec` object
28+
their own input files. In particular, a :obj:`simsopt.mhd.Vmec` object
2929
can be initialized using a standard VMEC ``input.*`` input file, and a
30-
:obj:`simsopt.mhd.spec.Spec` object can be initialized using a standard
30+
:obj:`simsopt.mhd.Spec` object can be initialized using a standard
3131
SPEC ``*.sp`` input file.
3232

3333

@@ -72,18 +72,18 @@ Some typical objects are a MHD equilibrium represented by the VMEC or
7272
SPEC code, or some electromagnetic coils. To define objective
7373
functions, a variety of additional objects can be defined that depend
7474
on the MHD equilibrium or coils, such as a
75-
:obj:`simsopt.mhd.boozer.Boozer` object for Boozer-coordinate
76-
transformation, a :obj:`simsopt.mhd.spec.Residue` object to represent
75+
:obj:`simsopt.mhd.Boozer` object for Boozer-coordinate
76+
transformation, a :obj:`simsopt.mhd.Residue` object to represent
7777
Greene's residue of a magnetic island, or a
78-
:obj:`simsopt.geo.objectives.LpCurveCurvature` penalty on coil
78+
:obj:`simsopt.geo.LpCurveCurvature` penalty on coil
7979
curvature.
8080

8181
More details about setting degrees of freedom and defining
8282
objective functions can be found on the :doc:`optimizable` page.
8383

8484
For the solution step, two functions are provided presently,
85-
:meth:`simsopt.solve.serial.least_squares_serial_solve` and
86-
:meth:`simsopt.solve.mpi.least_squares_mpi_solve`. The first
85+
:meth:`simsopt.solve.least_squares_serial_solve` and
86+
:meth:`simsopt.solve.least_squares_mpi_solve`. The first
8787
is simpler, while the second allows MPI-parallelized finite differences
8888
to be used in the optimization.
8989

docs/source/tracing.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Particle motion in cylindrical coordinates
1818
------------------------------------------
1919

2020
The main function to use in this case is
21-
:obj:`simsopt.field.tracing.trace_particles` (click the link for more
21+
:obj:`simsopt.field.trace_particles` (click the link for more
2222
information on the input and output parameters) and it is able to use
2323
two different sets of equations depending on the input parameter
2424
``mode``:

0 commit comments

Comments
 (0)