1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511
|
.. _siconos_doc:
=======================================================
Writing and building documention for Siconos Software
=======================================================
.. contents::
:local:
.. _about_doc:
Documentation overview
======================
The whole Siconos documentation is gathered on Siconos webpage, https://siconos.gforge.inria.fr.
It consists in
* Different **"textbooks"** : details on algorithms, how to install, use the platform, ... everything user and developers should know concerning Siconos software.
* Getting and installing Siconos software
* Users' guide
* Developers' guide
All these guides are generated with sphinx (http://www.sphinx-doc.org/en/master/index.html) from files written in reStructuredText (http://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html)
Source files and sphinx configuration file are all in docs/sphinx directory.
* **Siconos APIs** (Python and C++) documentation, automatically generated from inline comments in source files ( .h and .hpp).
Rules and best practices to write comments leading to a proper html documentation are detailed in :ref:`documenting_source_code`.
* In addition to these pages, "inline" documentation for the python API, as usual for python packages, based on docstrings, e.g. :
.. code-block:: python
>>> import siconos.kernel as sk
>>> help(sk.SimpleMatrix)
Help on class SimpleMatrix in module siconos.kernel:
class SimpleMatrix(SiconosMatrix)
| Matrix (embedded various types of Boost matrices of double)
|
| SimpleMatrix is used in the platform to store matrices (mathematical object) of
| double.
...
The complete documentation can be generated in one shot using doc target
.. code-block:: bash
cd build-dir
cmake -DWITH_DOCUMENTATION=ON path_to_siconos_sources
make doc
It results in html pages, generated in build-dir/docs/build/html.
Siconos web site (https://siconos.gforge.inria.fr) is the online version of those pages.
The building process for documentation is described in :ref:`build_doc`.
.. _doc_rules:
How to write Siconos documentation
==================================
Writing textbooks
-----------------
* Textbooks are generated from rst files from source-dir/docs/sphinx directory.
* Everything you need to know to write siconos docs in reStructuredTextPrimer is available here : http://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html.
* All rst files are copied from source dir to binary dir by cmake, so edit only
files in source dir.
* All figures and images must be in sphinx/figures directory.
.. _documenting_source_code:
Document source code
--------------------
Since source code comments (in c/c++ header files) are used to generate doxygen, sphinx and docstrings documentation,
one has to be very careful when writing those comments and follow the rules below.
.. rubric:: General rules
* Document all header files using doxygen comments, as defined in http://www.stack.nl/~dimitri/doxygen/manual/index.html
* Do not comment doxygen comments --> breaks doxy2swig outputs.
e.g. commenting a function and its doc will append the doc to the next function in the file
and so break doxy2swig outputs
* Try to follow numpydoc (https://numpydoc.readthedocs.io/en/latest/) requirements.
.. rubric:: files description
Each header file must contain something like
.. code-block:: c++
/*! \file SimpleMatrix.hpp
Brief (no more than one line) description of the content of the file
*/
The name and description will be used in the API contents listings.
If this block is not present, the file (and all the objects or functions it contents) won't appear in the documentation.
.. rubric:: Classes and structs
Document each class like this
.. code-block:: c++
/** Short description of the class
*
* Detailed description
* equations (see details about latex below), reference to textbooks chapter and so on
*/
class SiconosVector
...
.. rubric:: Class methods or functions
.. code-block:: c++
/** brief description
* \param name_of_param1 description of the param
* \param name_of_param2 description of the param
* \return description of what is returned
*/
double some_function(int p, int v)
No need to repeat parameters types in comments (param or return)! They will be extracted from function prototype.
Something like
.. code-block:: c++
/** get size of A
* \param A double A
* \return unsigned int
*/
unsigned int size(double * A) const;
is totally useless ...
.. rubric:: rst inside doxygen commments
Use "\\rst" / "\\endrst" tags to write reStructuredText (reST) specific (i.e. that doxygen can not tackle) comments.
See details below for references and math formula.
In the case of comments with leading asterisk, use "\\rststar" / "\\endrststar" tags
.. rubric:: Enums, union ...
Since they will probably appear as global variables in python API,
it's important that each component of the enum has an explicit comment, e.g:
.. code-block:: cpp
/** Global description of the enum */
enum UBLAS_TYPE
{
/** id for dense matrix or vector */
DENSE = 1,
/** id for triangular matrix */
TRIANGULAR,
}
References to sphinx documents
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To refer to any other sphinx document (reminder about sphinx cross-ref : http://www.sphinx-doc.org/en/stable/markup/inline.html)
use "\\rst" / "\\endrst" tags :
.. code :: rst
/** Class used to defined friction-contact problems
This class deals with blabla
\rst
See :ref:`global_fc_problem`
\endrst
*/
or with leading asterisk
.. code :: rst
/** Class used to defined friction-contact problems
*
* This class deals with blabla
*
* \rststar
*
* See :ref:`global_fc_problem`
*
* \endrststar
*
*
*/
Math and latex
~~~~~~~~~~~~~~
* inline math
.. code:: rst
use this \f$\alpha\f$ to write inline math
* displayed math
- Wrap your formula between "\rst" and "\endrst" tags and write math as you would with sphinx (see http://www.sphinx-doc.org/en/master/ext/math.html).
- Between rst tags, replace all occurences of :math:'\'dot (one backlash) with :math:'\\'dot (two backlashes), else doxygen will fail to produce documentation.
A simple example :
.. code:: rst
\rst
.. math::
y &=& h(X,t,\lambda,Z)\\
R &=& g(X,t,\lambda,Z)
\endrst
* New line after math keyword is required.
* Indentation for formula (related to math keyword) is required.
For more complicated maths, use nowrap keyword :
.. code:: rst
\rst
.. math::
:nowrap:
\left\{\begin{array}{l}
y \geq 0, \lambda \geq 0, y^{T} \lambda=0\\
if y \leq 0 \quad \mbox{then} \quad \\dot y(t^{+}) - e \\dot y(t^{-}) \geq 0, \quad \lambda \geq 0, (\\dot y(t^{+}) - e \\dot y(t^{-}))^{T} \lambda=0
\end{array}\right.
\endrst
If you need comments with leading asterisk, use "\rststar" / "\endrststar" tags :
.. code:: rst
* \rststar
*
* .. math::
* :nowrap:
*
* \begin{eqnarray}
* \begin{cases}
* M v = q + H r \\
* u = H^\top v + b \\
* \hat u = u +\left[
* \left[\begin{array}{c}
* \mu^\alpha \|u^\alpha_{T}\|\\
* 0 \\
* 0
* \end{array}\right]^T, \alpha = 1 \ldots n_c
* \right]^T \\ \\
* C^\star_{\mu} \ni {\hat u} \perp r \in C_{\mu}
* \end{cases}
* \end{eqnarray}
*
* \endrststar
.. _build_doc:
Building process
================
One target to generate the whole documentation :
.. code-block:: bash
cmake -DWITH_DOCUMENTATION=ON ...
make doc # The whole doc
Resulting files will be in docs/build/html of the current building path.
Below are some details about the documentation generation process, useful only if you want to generate a subpart of the doc or change the configuration and the process.
Tools, config and description
-----------------------------
**Tools:**
* `Doxygen`_ : tool able to generate documentation from annotated C++ sources, in html, xml ...
* `Sphinx`_ : powerful generator of documentation (mostly for Python)
* `Breathe`_ : an extension to reStructuredText and Sphinx to be able to read and render the Doxygen xml outputs.
* `Doxy2swig`_ : converter from doxygen XML to SWIG docstring.
Images are sometimes better than words : the different operations are detailed on figures below
.. rubric:: Generation of rst files for C++ API
How does it work?
`Doxygen`_ is used to generate xml files from comments in headers of each Siconos component. Python scripts are used to postprocess those xml files and produce rst files fitting with `Breathe`_ requirements and ready for `Sphinx_`.
*Config and sources:*
* cmake/doc_tools.cmake : cmake macros and functions calling doxygen, sphinx or other tool related to documentation.
* docs/gendoctools/* : python tools used to generate docs. This python package will be installed in <CMAKE_BINARY_DIR>/share
at build time.
* docs/config/doxyxml2sphinx.config.in : doxygen (xml output) for breathe/sphinx
.. figure:: /figures/doc_process/build_breathe.*
:figclass: align-center
Generation of rst files for C++ API
.. rubric:: Generation of rst files for Python API
How does it work?
Doxygen generates xml from comments in headers. Some python scripts are
used to postprocess those xml files and produce .i files (swig), ending in
docstrings in generated swig python modules.
We have written a wrapper to doxy2swig (https://github.com/m7thon/doxy2swig) to fit with our needs.
Finally, rst files are generated, based on those docstrings, in autodoc format, for sphinx.
*Config and sources:*
* cmake/swig_python_tools.cmake : python functions used to drive docstrings
generation
* docs/gendoctools/* : python tools used to generate docs. This python package will be installed in <CMAKE_BINARY_DIR>/share
at build time.
* docs/config/doxy2swig.config.in : doxygen (xml output) config, for swig and docstrings
.. figure:: /figures/doc_process/build_doxy2swig.*
:figclass: align-center
Generation of rst files for Python API
Remark : during generation process, siconos python packages are imported and only
objects with non-empty docstrings are documented.
.. rubric:: html pages generation
How does it work?
All rst files (from source dir and generated for Python and C++ API) and processed by `Sphinx`_ to produce html documentation.
*Config and sources:*
* docs/CMakeLists.txt : main driver
* cmake/doc_tools.cmake : cmake macros and functions calling doxygen, sphinx or other tool related to documentation.
* cmake/doxygen_warning.cmake : included in LibraryProjectSetup, rules to build "\*.warnings" files.
* docs/sphinx/conf.py.in : main sphinx configuration file
* docs/sphinx/index.rst.in : source for documentation main page
* docs/sphinx/\*/\*.rst : inputs for sphinx doc (textbooks)
* docs/sphinx/figures/\* : all figures used in sphinx doc
* docs/gendoctools/* : python tools used to generate docs.
* docs/config/doxy.config.in : doxygen (html output) config
* docs/config/doxy_warnings.config.in : doxygen (log output) config
.. figure:: /figures/doc_process/build_html_process.*
:figclass: align-center
make doc toolchain
.. figure:: /figures/doc_process/targets_dep.*
:figclass: align-center
make targets (related to doc) dependencies
.. rubric:: Other (exotic) configuration options
* Full doxygen (i.e. extract all from sources!) html documentation.
Target : developpers only. Indeed, everything is included in sphinx doc except things like callgraph or collaboration graphs.
Use this when those graphs are needed.
Same as above, with a new cmake option :
.. code-block:: bash
cmake -DWITH_DOCUMENTATION=ON -DUSE_DEVEL_DOXYGEN=ON
make doc # The whole doc
Doxygen ouput is set to be "quiet" and without warnings.
But, if required (devel), use:
* Generate doxygen warnings
Use WITH_DOXYGEN_WARNINGS option (in USER_OPTIONS_FILE or in command line), e.g. :
.. code-block:: bash
cmake -DWITH_DOCUMENTATION=ON -DWITH_DOXYGEN_WARNINGS=ON
make filter_warnings
It will generate (during compilation process) and print doxygen warnings in files
saved in CMAKE_BINARY_DIR/doxygen_warnings. A warnings file is generated for
each input source file. The final call to 'make filter_warnings' will concatenate all interesting
warnings into one file, doxygen_warnings/SUMMARY.warnings
doxygen warnings conf is defined in docs/config/doxy_warnings.config.in and setup in
cmake/doxygen_warnings.cmake.
* Generate docstrings
.. code-block:: bash
cmake -DWITH_DOCUMENTATION=ON -DWITH_DOXY2SWIG=ON
make numerics_docstrings
This option is set to ON by default.
To produce documentation in python interface, xml outputs from doxygen are used to create swig files containing 'docstrings' for python.
Comments written in C++ (doxygen) will be available in python interface, e.g. :
.. code-block:: python
import siconos.kernel as sk
help(sk.DynamicalSystem)
Help on class LCP in module siconos.kernel:
class LCP(LinearOSNS)
| Non Smooth Problem Formalization and Simulation.
|
| author: SICONOS Development Team - copyright INRIA
|
| This is an abstract class, that provides an interface to define a non smooth
| problem:
|
| * a formulation (ie the way the problem is written)
| * a solver (algorithm and solving formulation, that can be different from
| problem formulation)
| * routines to compute the problem solution.
Dependencies
------------
* `Doxygen`_
* `Sphinx`_, sphinxcontrib.bibtex, sphinxcontrib-youtube, sphinxcontrib-napoleon
* sphinx-bootstrap-theme
* `Breathe`_
See docs/requirements.txt for a list of required python packages, and try for example
.. code-block:: bash
pip install -r ./docs/requirements.txt
pip install git+https://github.com/sphinx-contrib/youtube.git
See also the file CI/make_siconos_doc.sh that may be helpful to install siconos docs, since it is used by continuous integration on gitlab to provide all dependencies required to build doc on ubuntu.
More about Doxygen to sphinx rst
--------------------------------
Some other tools to generate rst from doxygen have been tested : Exhale and doxyrest. We choose breathe, that seems more appropriate to our case. Exhale and doxyrest configs are kept for the records in siconos-junk/sandbox project.
Existing tools (as far as we know ...):
* Sphinx/Exhale(breathe) : https://github.com/svenevs/exhale`Sphinx/Exhale
* doxyrest https://github.com/vovkos/doxyrest
* https://bitbucket.org/trlandet/doxygen_to_sphinx_and_swig
.. _Doxygen : http://www.stack.nl/~dimitri/doxygen/
.. _Sphinx : http://www.sphinx-doc.org/en/master/
.. _Breathe : https://github.com/michaeljones/breathe
.. _Doxy2swig : https://github.com/m7thon/doxy2swig
|