Skip to content

Commit 2830e1e

Browse files
authored
📝 Document "✨ Set constant random seed via config or command line" (FCP-INDI/C-PAC#1646) (#271)
2 parents ed67ffa + d4fff9c commit 2830e1e

File tree

7 files changed

+92
-21
lines changed

7 files changed

+92
-21
lines changed

docs/_sources/developer/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Contents:
1616
installation
1717
pipeline
1818
nodes
19+
random_state
1920
workflow_documentation
2021
workflows/index
2122
testing

docs/_sources/developer/nodes.rst

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
*****
22
Nodes
33
*****
4-
54
.. _mem_gb:
65

76
.. _n_procs:
@@ -23,8 +22,10 @@ When a developer creates or modifies a Node in C-PAC, a ``mem_gb`` and ``n_procs
2322

2423
For nodes that will use a varying amount of memory depending on the node's input data, the optional parameter ``mem_x`` takes a tuple of ``(memory multiplier, input file, multiplier mode)`` where ``memory multiplier`` is a number and ``input file`` is the string name of the Node input to multiply such that the memory estimate returned by the ``mem_gb`` attribute is the ``mem_gb`` argument plus ``memory multiplier`` times the dimensions of the ``input file`` as specified in the ``multiplier mode`` (``xyzt`` (spatial × temporal; default), ``xyz`` (spatial), or just ``t`` (temporal)).
2524

26-
.. note::
27-
``mem_x`` is a new parameter in C-PAC v1.8.1 and subject to change in future releases as we continue to `develop methods for setting data- and operation-dependent memory estimates <https://github.com/FCP-INDI/C-PAC/issues/1509>`_.
25+
26+
.. note::
27+
``mem_x`` is a new parameter in C-PAC v1.8.1 and subject to change in future releases as we continue to `develop methods for setting data- and operation-dependent memory estimates <https://github.com/FCP-INDI/C-PAC/issues/1509>`_.
28+
2829

2930
.. autoclass:: CPAC.pipeline.nipype_pipeline_engine.Node
3031
:special-members: __init__
@@ -36,17 +37,33 @@ For nodes that will use a varying amount of memory depending on the node's input
3637
:members:
3738
:inherited-members:
3839

40+
.. autoclass:: nipype.interfaces.base.core.Interface
41+
:special-members: __init__
42+
:members:
43+
:inherited-members:
44+
45+
46+
.. seealso::
47+
`Nipype: Interface Specifications <https://nipype.readthedocs.io/en/1.5.1/devel/interface_specs.html>`_
48+
49+
50+
.. autoclass:: CPAC.utils.interfaces.function.Function
51+
:special-members: __init__
52+
:members:
53+
:inherited-members:
54+
3955
.. autoclass:: CPAC.pipeline.nipype_pipeline_engine.Workflow
4056
:special-members: __init__
4157
:members:
4258
:inherited-members:
4359

60+
4461
The Nipype utility function :py:func:`~nipype.utils.draw_gantt_chart.log_to_dict` reads a log file generated by ``log_nodes_cb`` to a Python dictionary.
4562

63+
4664
.. autofunction:: CPAC.utils.monitoring.log_nodes_cb
4765

48-
draw_gantt_chart
49-
================
66+
5067

5168
.. automodule:: CPAC.utils.monitoring.draw_gantt_chart
5269
:members: resource_report, log_to_dict, generate_gantt_chart, resource_overusage_report
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Random State
2+
============
3+
4+
When performing reproducibility/variability experiments, it is important to isolate sources of variability. One such source is random state.
5+
6+
Users can fix the random state of C-PAC's execution by specifying a random seed. When adding a Node that should accept a user-specified random seed, add
7+
8+
* the :py:class:`nipype.interfaces.base.core.Interface` and the corresponding flags to add/remove to set the random seed, or
9+
* in the case of a :py:class:`CPAC.utils.interfaces.function.Function` Node, the Function node's function and a function to apply to that function definition to set the random seed
10+
11+
to :py:func:`CPAC.pipeline.random_state.seed.random_seed_flags`.
12+
13+
.. autofunction:: CPAC.pipeline.random_state.seed.random_seed_flags

docs/_sources/user/pipelines/design_a_pipeline.rst

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,21 @@ Design A Pipeline
1313

1414
C-PAC offers a graphical interface you can use to quickly and easily modify the default pipeline or create your own from scratch: `https://fcp-indi.github.io/C-PAC_GUI/ <https://fcp-indi.github.io/C-PAC_GUI/>`_
1515

16-
.. note::
16+
.. note::
17+
18+
Currently the GUI creates a C-PAC v1.6.0 pipeline configuration file. This syntax persisted through v1.7.2 but is deprecated with the release of v1.8.0.
1719

18-
Currently the GUI creates a C-PAC v1.6.0 pipeline configuration file. This syntax persisted through v1.7.2 but is deprecated with the release of v1.8.0.
20+
If given a pipeline file in the older syntax, C-PAC v1.8 will attempt to convert the pipeline configuration file to the new syntax, saving the converted file in your output directory.
1921

20-
If given a pipeline file in the older syntax, C-PAC v1.8 will attempt to convert the pipeline configuration file to the new syntax, saving the converted file in your output directory.
22+
An update to the GUI to create v1.8.0 syntax configuration files is underway.
2123

22-
An update to the GUI to create v1.8.0 syntax configuration files is underway.
24+
The newer (v1.8) syntax will not work with older versions of C-PAC.
2325

24-
The newer (v1.8) syntax will not work with older versions of C-PAC.
26+
See :ref:`using_a_text_editor` for configuring a custom pipeline without the GUI.
27+
28+
.. seealso::
2529

26-
See :ref:`using_a_text_editor` for configuring a custom pipeline without the GUI.
27-
28-
.. seealso::
29-
30-
:doc:`Details about mapping the older syntax to the new. </user/pipelines/1.7-1.8-nesting-mappings>`
30+
:doc:`Details about mapping the older syntax to the new. </user/pipelines/1.7-1.8-nesting-mappings>`
3131

3232
.. figure:: /_images/gui_home1.png
3333

docs/_sources/user/pipelines/pipeline_config.rst

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,10 @@ Definitions
3737
.. include:: /glossary/template.rst
3838
:start-line: 3
3939

40-
.. rubric:: Reference
41-
42-
.. bibliography:: /references/glossary.bib
43-
:style: cpac_docs_style
44-
:cited:
45-
:keyprefix: glossary-
4640

4741
.. include:: design_a_pipeline.rst
4842

43+
4944
.. _using_a_text_editor:
5045

5146
Using a Text Editor
@@ -109,6 +104,7 @@ Data Management and Environment Settings
109104

110105
* :doc:`Computer Settings </user/compute_config>`
111106
* :doc:`Output Settings </user/output_config>`
107+
* :doc:`Random State </user/pipelines/random_state>`
112108

113109
Pre- and post-processing
114110
'''''''''''''''''''''''''
@@ -127,3 +123,12 @@ Derivatives
127123
* :doc:`Amplitude of Low Frequency Fluctuations (ALFF) and fractional ALFF (fALFF) </user/alff>` - Measure the power of slow fluctuations in brain activity.
128124
* :doc:`Regional Homogeneity (ReHo) </user/reho>` - Measure the similarity of activity patterns across neighboring voxels.
129125
* :doc:`Network Centrality </user/centrality>` - Analyze the structure of functional networks.
126+
127+
128+
.. rubric:: Reference
129+
130+
131+
.. bibliography:: /references/glossary.bib
132+
:style: cpac_docs_style
133+
:cited:
134+
:keyprefix: glossary-
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
Random State
2+
============
3+
4+
When performing reproducibility/variability experiments, it is important to isolate sources of variability. One such source is random state.
5+
6+
Random seed can be set in pipeline config
7+
8+
.. literalinclude:: /references/default_pipeline.yml
9+
:language: YAML
10+
:start-at: pipeline_setup:
11+
:lines: 1
12+
13+
.. literalinclude:: /references/default_pipeline.yml
14+
:language: YAML
15+
:start-at: system_config:
16+
:end-before: # Select Off if you intend to run CPAC on a single machine.
17+
18+
or on the command line with ``--random_seed $SEED``.
19+
20+
Valid options are positive integers up to 2,147,483,647 or the word 'random' (which will set an integer in that range). If not specified, a seed will not be set, and each relevant process will run with an undocumented random seed.
21+
22+
When a seed is set, a ``random.log`` file, including the constant seed and each node the seed was applied to, will be generated in the logging directory.
23+
24+
The following processes currently support this feature:
25+
26+
.. exec::
27+
from CPAC.pipeline.random_state.seed import random_seed_flags, \
28+
set_up_random_state
29+
set_up_random_state('random')
30+
processes = random_seed_flags()
31+
for interface in processes['interfaces'].keys():
32+
print(interface._cmd)
33+
for fxn in processes['functions'].keys():
34+
print('.'.join([fxn.__module__, fxn.__name__]))

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
m2r
2+
mistune==0.8.4
23
numpydoc
34
PyGithub
45
sphinx

0 commit comments

Comments
 (0)