diff --git a/psyneulink/core/components/functions/function.py b/psyneulink/core/components/functions/function.py index 9ec868e0f12..55b00825908 100644 --- a/psyneulink/core/components/functions/function.py +++ b/psyneulink/core/components/functions/function.py @@ -171,7 +171,7 @@ from psyneulink.core.globals.preferences.preferenceset import PreferenceEntry, PreferenceLevel from psyneulink.core.globals.registry import register_category from psyneulink.core.globals.utilities import ( - convert_all_elements_to_np_array, convert_to_np_array, get_global_seed, is_instance_or_subclass, object_has_single_value, parameter_spec, parse_valid_identifier, safe_len, + convert_all_elements_to_np_array, convert_to_np_array, _get_global_seed, is_instance_or_subclass, object_has_single_value, parameter_spec, parse_valid_identifier, safe_len, SeededRandomState, try_extract_0d_array_item, contains_type, is_numeric, NumericCollections, random_matrix, array_from_matrix_string ) @@ -357,7 +357,7 @@ def _seed_setter(value, owning_component, context, *, compilation_sync): value = try_extract_0d_array_item(value) if value is None or value == DEFAULT_SEED(): - value = get_global_seed() + value = _get_global_seed() # Remove any old PRNG state owning_component.parameters.random_state.set(None, context=context) diff --git a/psyneulink/core/components/functions/nonstateful/optimizationfunctions.py b/psyneulink/core/components/functions/nonstateful/optimizationfunctions.py index 649be335df9..7b6ec909475 100644 --- a/psyneulink/core/components/functions/nonstateful/optimizationfunctions.py +++ b/psyneulink/core/components/functions/nonstateful/optimizationfunctions.py @@ -641,7 +641,7 @@ def _evaluate(self, variable=None, context=None, params=None, fit_evaluate=False # Run compiled mode if requested by parameter and everything is initialized if self.owner and self.owner.parameters.comp_execution_mode._get(context) != 'Python' and \ ContextFlags.PROCESSING in context.flags: - all_samples = [s for s in itertools.product(*self.search_space)] + all_samples = list(itertools.product(*self.search_space)) all_values, num_evals = self._grid_evaluate(self.owner, context, fit_evaluate) assert len(all_values) == num_evals assert len(all_samples) == num_evals @@ -846,7 +846,7 @@ def reset_grid(self, context): """Reset iterators in `search_space `""" for s in self.search_space: s.reset() - self.parameters.grid._set(itertools.product(*[s for s in self.search_space]), context) + self.parameters.grid._set((s for s in itertools.product(*[s for s in self.search_space])), context) def _traverse_grid(self, variable, sample_num, context=None): """Get next sample from grid. diff --git a/psyneulink/core/globals/utilities.py b/psyneulink/core/globals/utilities.py index 9405b0c3f98..8c503310b2a 100644 --- a/psyneulink/core/globals/utilities.py +++ b/psyneulink/core/globals/utilities.py @@ -93,7 +93,6 @@ * `ContentAddressableList` * `make_readonly_property` * `get_class_attributes` -* `get_global_seed` * `set_global_seed` """ @@ -1718,7 +1717,7 @@ def seed(self, seed): _seed = np.uint32((time.time() * 1000) % 2**31) -def get_global_seed(offset=1): +def _get_global_seed(offset=1): global _seed old_seed = _seed _seed = (_seed + offset) % 2**31 diff --git a/psyneulink/library/components/mechanisms/processing/integrator/ddm.py b/psyneulink/library/components/mechanisms/processing/integrator/ddm.py index f61442192de..d4bd6b51a3f 100644 --- a/psyneulink/library/components/mechanisms/processing/integrator/ddm.py +++ b/psyneulink/library/components/mechanisms/processing/integrator/ddm.py @@ -386,7 +386,7 @@ from psyneulink.core.globals.parameters import Parameter, check_user_specified from psyneulink.core.globals.preferences.basepreferenceset import ValidPrefSet, REPORT_OUTPUT_PREF from psyneulink.core.globals.preferences.preferenceset import PreferenceEntry, PreferenceLevel -from psyneulink.core.globals.utilities import convert_all_elements_to_np_array, is_numeric, is_same_function_spec, object_has_single_value, get_global_seed +from psyneulink.core.globals.utilities import convert_all_elements_to_np_array, is_numeric, is_same_function_spec, object_has_single_value from psyneulink.core.scheduling.condition import AtTrialStart from psyneulink.core.components.functions.userdefinedfunction import UserDefinedFunction diff --git a/setup.cfg b/setup.cfg index 1fbd76b7c67..f448abca493 100644 --- a/setup.cfg +++ b/setup.cfg @@ -74,6 +74,7 @@ filterwarnings = error:the matrix subclass is not the recommended way to represent matrices or deal with linear algebra error:Passing (type, 1) or '1type' as a synonym of type is deprecated error:A builtin ctypes object gave a PEP3118:RuntimeWarning + error:Pickle, copy, and deepcopy support will be removed from itertools:DeprecationWarning [pycodestyle] # for code explanation see https://pep8.readthedocs.io/en/latest/intro.html#error-codes diff --git a/tests/functions/test_functions.py b/tests/functions/test_functions.py index fdab23d40bb..7d233953e86 100644 --- a/tests/functions/test_functions.py +++ b/tests/functions/test_functions.py @@ -60,7 +60,9 @@ def test_output_type_conversion_failure(output_type, variable): ) def test_seed_setting_results(obj): obj = obj() - new_seed = pnl.core.components.functions.function.get_global_seed() + + # A seed different from the one used by the instance + new_seed = obj.parameters.seed.get() + 1 obj.parameters.seed.set(new_seed, context='c1') @@ -81,20 +83,22 @@ def test_seed_setting_results(obj): # with different seeds, unlike those in test_seed_setting_results @pytest.mark.function @pytest.mark.parametrize( - "obj", + "config", [ - pnl.DDM, - pnl.DriftDiffusionIntegrator, - pnl.DriftOnASphereIntegrator(dimension=3), - pnl.OrnsteinUhlenbeckIntegrator, - pnl.DictionaryMemory, - pnl.ContentAddressableMemory, - ] + (pnl.DDM, {}), + (pnl.DriftDiffusionIntegrator, {}), + (pnl.DriftOnASphereIntegrator, {"dimension":3}), + (pnl.OrnsteinUhlenbeckIntegrator, {}), + (pnl.DictionaryMemory, {}), + (pnl.ContentAddressableMemory, {}), + ], + ids=lambda x: x[0] ) -def test_seed_setting_params(obj): - if not isinstance(obj, pnl.Component): - obj = obj() - new_seed = pnl.core.components.functions.function.get_global_seed() +def test_seed_setting_params(config): + obj_c, params = config + obj = obj_c(**params) + + new_seed = obj.parameters.seed.get() + 1 obj._initialize_from_context(pnl.Context(execution_id='c1')) obj._initialize_from_context(pnl.Context(execution_id='c2'), pnl.Context(execution_id='c1')) diff --git a/tests/misc/test_user_seed.py b/tests/misc/test_user_seed.py index 6ec31910c86..af5ff37b1e1 100644 --- a/tests/misc/test_user_seed.py +++ b/tests/misc/test_user_seed.py @@ -2,6 +2,6 @@ import sys def test_user_seed(): - seed1 = subprocess.check_output((sys.executable, "-c" ,"from psyneulink.core.globals.utilities import get_global_seed; print(get_global_seed())")) - seed2 = subprocess.check_output((sys.executable, "-c" ,"from psyneulink.core.globals.utilities import get_global_seed; print(get_global_seed())")) + seed1 = subprocess.check_output((sys.executable, "-c" ,"from psyneulink.core.globals.utilities import _get_global_seed; print(_get_global_seed())")) + seed2 = subprocess.check_output((sys.executable, "-c" ,"from psyneulink.core.globals.utilities import _get_global_seed; print(_get_global_seed())")) assert seed1 != seed2