Random State¶
When performing reproducibility/variability experiments, it is important to isolate sources of variability. One such source is random state.
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
the
nipype.interfaces.base.core.Interface
and the corresponding flags to add/remove to set the random seed, orin the case of a
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
to CPAC.pipeline.random_state.seed.random_seed_flags
.
- CPAC.pipeline.random_state.seed.random_seed_flags()[source]¶
Function to return dictionary of flags with current random seed.
- Parameters:
- None
- Returns:
- dict of {‘functions’: {function: function}, ‘interfaces’: {list or tuple}}
Developer note: sequence matters here! Only the first match will be applied!
In the ‘functions’ sub-dictionary, each key should be a function used in a
CPAC.utils.interfaces.function.Function
, and each value should be a function that takes a single parameter (a function) to apply to the key-function such that, once the value-function is applied, the random seed is applied when the key-function is run.In the ‘interfaces’ sub-dictionary, each key should be an
nipype.interfaces.base.core.Interface
, and each value should be either a list of strings to add to the interface’s flags/args or a tuple of (list of strings to add to, list of strings to remove from) the interface’s flags/args.
Examples
>>> list(random_seed_flags().keys()) ['functions', 'interfaces'] >>> all([isinstance(random_seed_flags()[key], dict) for key in [ ... 'functions', 'interfaces']]) True >>> rs = set_up_random_state('random') >>> list(random_seed_flags().keys()) ['functions', 'interfaces'] >>> all([isinstance(random_seed_flags()[key], dict) for key in [ ... 'functions', 'interfaces']]) True