Skip to content

Commit c28a6b5

Browse files
committed
Finish documentation for gradient testing (for now)
1 parent a4ee8ef commit c28a6b5

15 files changed

+78
-28
lines changed

Diff for: docs/Doxyfile.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ WARN_LOGFILE =
792792
# Note: If this tag is empty the current directory is searched.
793793

794794
## this is for read the docs, which builds in-place
795-
INPUT = @CMAKE_SOURCE_DIR@/src @CMAKE_SOURCE_DIR@/bindings @CMAKE_CURRENT_BINARY_DIR@
795+
INPUT = @CMAKE_SOURCE_DIR@/src @CMAKE_SOURCE_DIR@/tests @CMAKE_SOURCE_DIR@/bindings @CMAKE_CURRENT_BINARY_DIR@
796796

797797
# This tag can be used to specify the character encoding of the source files
798798
# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses

Diff for: docs/source/reference/cpp.rst

+36-3
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,14 @@ Math utilities (namespace :cpp:class:`rascal::math`)
5151
Gradient tests (developer)
5252
^^^^^^^^^^^^^^^^^^^^^^^^^^
5353

54+
.. cpp:namespace:: rascal
55+
5456
All representations in libRascal should implement, or plan to implement,
5557
gradients (derivatives w.r.t. the Cartesian positions of all the atoms) so that
5658
they can be used to run dynamics. This is often a complex and error-prone task,
5759
so a finite-difference gradient checker is provided to check the gradients of
58-
any representation calculator -- or any math function in general -- and ensure
59-
that the analytical and finite-difference gradients match up.
60+
any representation calculator -- or any mathematical function in general -- and
61+
ensure that the analytical and finite-difference gradients match up.
6062

6163
To check the gradient of a new representation calculator, it should suffice to
6264
use the classes RepresentationManagerGradientCalculator (to provide the function
@@ -67,13 +69,44 @@ below, excerpted from :file:`tests/test_calculator.cc`:
6769
.. literalinclude:: ../../../tests/test_calculator.cc
6870
:language: cpp
6971
:lines: 430-436, 441-444
70-
:dedent: 2
72+
:dedent: 4
73+
74+
where :cpp:var:`representations.back()` is a
75+
:cpp:class:`RepresentationCalculator`,
76+
:cpp:var:`manager` is a :cpp:class:`StructureManager`, and
77+
:cpp:var:`structures.back()` is the :cpp:class:`AtomicStructure` associated with
78+
that manager.
79+
80+
A more detailed documentation of these two classes follows:
81+
82+
.. doxygenclass:: rascal::RepresentationManagerGradientCalculator
83+
:project: rascal
84+
:members:
85+
86+
.. doxygenclass:: rascal::RepresentationManagerGradientFixture
87+
:project: rascal
88+
:members:
89+
90+
For testing the gradient of arbitrary functions :math:`f: \mathbb{R}^m
91+
\rightarrow \mathbb{R}^n`, the function :cpp:func:`test_gradients` is
92+
provided:
93+
94+
.. doxygenfunction:: test_gradients
95+
:project: rascal
96+
97+
An example generalized gradient test fixture is provided by
98+
:cpp:class:`GradientTestFixture`:
7199

100+
.. doxygenclass:: rascal::GradientTestFixture
101+
:project: rascal
102+
:members:
72103

73104
Index
74105
~~~~~
75106

76107
.. doxygennamespace:: rascal
77108
:project: rascal
78109
:members:
110+
:outline:
111+
:no-link:
79112

Diff for: tests/test_adaptor_center_contribution.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* file test_adaptor_center_contribution.cc
2+
* @file test_adaptor_center_contribution.cc
33
*
44
* @author Felix Musil <[email protected]>
55
*

Diff for: tests/test_calculator.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* file test_calculator.cc
2+
* @file test_calculator.cc
33
*
44
* @author Musil Felix <[email protected]>
55
*

Diff for: tests/test_calculator.hh

+12-2
Original file line numberDiff line numberDiff line change
@@ -820,8 +820,8 @@ namespace rascal {
820820
/**
821821
* Test fixture holding the gradient calculator and structure manager
822822
*
823-
* Holds data (i.e. function values, gradient directions) and iterates through
824-
* the list of centers
823+
* Holds data (function values, gradient directions, verbosity) and iterates
824+
* through the list of centers
825825
*/
826826
template <typename RepCalculator_t, class StructureManager_t>
827827
class RepresentationManagerGradientFixture : public GradientTestFixture {
@@ -833,6 +833,16 @@ namespace rascal {
833833

834834
static const size_t n_arguments = 3;
835835

836+
/**
837+
* Initialize a gradient test fixture
838+
*
839+
* @param filename JSON file holding gradient test parameters, format
840+
* documented in GradientTestFixture
841+
*
842+
* @param structure StructureManager on which to test
843+
*
844+
* @param calc RepresentationCalculator whose gradient is being tested
845+
*/
836846
RepresentationManagerGradientFixture(
837847
std::string filename, std::shared_ptr<StructureManager_t> structure,
838848
Calculator_t & calc)

Diff for: tests/test_kernels.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* file test_kernels.cc
2+
* @file test_kernels.cc
33
*
44
* @author Felix Musil <[email protected]>
55
*

Diff for: tests/test_kernels.hh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* file test_kernels.hh
2+
* @file test_kernels.hh
33
*
44
* @author Felix Musil <[email protected]>
55
*

Diff for: tests/test_manager_collection.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* file test_manager_collection.cc
2+
* @file test_manager_collection.cc
33
*
44
* @author Felix Musil <[email protected]>
55
*

Diff for: tests/test_manager_collection.hh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* file test_manager_collection.hh
2+
* @file test_manager_collection.hh
33
*
44
* @author Felix Musil <[email protected]>
55
*

Diff for: tests/test_math.hh

+18-11
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ namespace rascal {
148148
};
149149

150150
/**
151-
* Fixture for testing a the gradient of a real function of N real arguments
151+
* Fixture for testing the gradient of a real function of N real arguments
152152
*
153153
* (Verifies that the gradient is the same as the converged value of the
154154
* finite-difference approximation along the given directions)
@@ -166,6 +166,9 @@ namespace rascal {
166166
* @param displacement_directions List of vectors along which to displace the
167167
* inputs, in case "direction_mode" is
168168
* "Provided".
169+
*
170+
* @param verbosity Level of verbosity to use when printing test info, as
171+
* string ("NORMAL", "INFO", or "DEBUG")
169172
*/
170173
class GradientTestFixture {
171174
public:
@@ -222,10 +225,14 @@ namespace rascal {
222225
return directions;
223226
}
224227

228+
/** Levels of verbosity for the gradient test */
225229
enum struct VerbosityValue {
226-
NORMAL = 0, // Print nothing
227-
INFO = 10, // Print one line of info for each gradient step
228-
DEBUG = 20 // Print as much as possible
230+
/** Print nothing */
231+
NORMAL = 0,
232+
/** Print one line of info for each gradient step */
233+
INFO = 10,
234+
/** Print as much as possible */
235+
DEBUG = 20
229236
};
230237

231238
static VerbosityValue get_verbosity(json & input_data) {
@@ -304,18 +311,18 @@ namespace rascal {
304311
* The function_calculator object may be of any type, as long as it provides
305312
* two functions, f() and grad_f(), to calculate the function and its gradient
306313
* (derivative for functions with one input, Jacobian for functions with
307-
* multiple outputs -- the output dimension is expected to correspond to
314+
* multiple outputs - the output dimension is expected to correspond to
308315
* columns). Both functions must accept an Eigen::Vector, corresponding to
309316
* the function input, of dimension determined in the data file (read by
310317
* GradientTestFixture). This function additionally guarantees that f() will
311318
* be called before grad_f() with the same input.
312319
*
313-
* If the functions f() and grad_f() are designed to accept fixed-size vectors
314-
* (i.e. if the size of the argument is known at compile time), be sure to
315-
* define, in the FunctionProvider class, a
316-
* `constexpr static size_t n_arguments` member with the size of the argument
317-
* vector. This will ensure that the gradient tester uses the corresponding
318-
* fixed-size Eigen vectors/matrices as inputs.
320+
* @note If the functions f() and grad_f() are designed to accept fixed-size
321+
* vectors (i.e. if the size of the argument is known at compile time), be
322+
* sure to define, in the FunctionProvider class, a `constexpr static size_t
323+
* n_arguments` member with the size of the argument vector. This will ensure
324+
* that the gradient tester uses the corresponding fixed-size Eigen
325+
* vectors/matrices as inputs.
319326
*/
320327
template <typename FunctionProvider_t, typename TestFixture_t>
321328
void test_gradients(FunctionProvider_t function_calculator,

Diff for: tests/test_math_gauss_legendre.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* file test_math_gauss_legendre.cc
2+
* @file test_math_gauss_legendre.cc
33
*
44
* @author Felix Musil <[email protected]>
55
*

Diff for: tests/test_math_modified_bessel_first_kind.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* file test_math_modified_bessel_first_kind.cc
2+
* @file test_math_modified_bessel_first_kind.cc
33
*
44
* @author Felix Musil <[email protected]>
55
*

Diff for: tests/test_math_spherical_harmonics.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* file test_math_spherical_harmonics.cc
2+
* @file test_math_spherical_harmonics.cc
33
*
44
* @section LICENSE
55
*

Diff for: tests/test_properties.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* file test_properties.cc
2+
* @file test_properties.cc
33
*
44
* @author Till Junge <[email protected]>
55
*

Diff for: tests/test_species_manager.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* file test_species_manager.cc
2+
* @file test_species_manager.cc
33
*
44
* @author Markus Stricker <[email protected]>
55
* @author Till Junge <[email protected]>

0 commit comments

Comments
 (0)