From 33b80a9e244922cd23b470dbaf7bfea4917a166e Mon Sep 17 00:00:00 2001 From: Jan Vesely Date: Sat, 18 Jul 2020 19:32:23 -0400 Subject: [PATCH 01/13] codestyle: Fix and check W293; Blank line contains whitespace find psyneulink/ tests/ -name '*.py' -exec sed -i 's/^ *$//' {} \; Signed-off-by: Jan Vesely --- .../components/functions/transferfunctions.py | 2 +- psyneulink/core/llvm/helpers.py | 8 ++-- .../library/compositions/compiledloss.py | 4 +- .../library/compositions/compiledoptimizer.py | 4 +- .../compositions/pytorchmodelcreator.py | 8 ++-- setup.cfg | 2 +- tests/composition/test_composition.py | 10 ++--- tests/composition/test_control.py | 4 +- tests/composition/test_learning.py | 40 +++++++++---------- tests/llvm/test_helpers.py | 2 +- tests/mechanisms/test_control_mechanism.py | 14 +++---- tests/scheduling/test_system_newsched.py | 14 +++---- 12 files changed, 56 insertions(+), 56 deletions(-) diff --git a/psyneulink/core/components/functions/transferfunctions.py b/psyneulink/core/components/functions/transferfunctions.py index 9db6e43d474..41041caa5c8 100644 --- a/psyneulink/core/components/functions/transferfunctions.py +++ b/psyneulink/core/components/functions/transferfunctions.py @@ -1265,7 +1265,7 @@ def _gen_llvm_transfer(self, builder, index, ctx, vi, vo, params, state, *, tags denominator = builder.fadd(exp_val.type(1), exp_val) denominator = builder.fmul(denominator, denominator) - + val = builder.fdiv(numerator, denominator) val = builder.fmul(val, mult) else: diff --git a/psyneulink/core/llvm/helpers.py b/psyneulink/core/llvm/helpers.py index d68fc4c1493..0fb9dd3eed6 100644 --- a/psyneulink/core/llvm/helpers.py +++ b/psyneulink/core/llvm/helpers.py @@ -265,7 +265,7 @@ def bump_ts(self, builder, cond_ptr, count=(0, 0, 1)): Count should be a tuple where there is a number in only one spot, and zeroes elsewhere. Indices greater than that of the one are zeroed. """ - + # Validate count tuple assert count.count(0) == len(count) - 1 @@ -400,7 +400,7 @@ def generate_sched_condition(self, builder, condition, cond_ptr, node, is_finish current_pass = builder.extract_value(ts, 1) return builder.icmp_unsigned("==", current_pass, current_pass.type(pass_num)) - + elif isinstance(condition, EveryNCalls): target, count = condition.args @@ -489,7 +489,7 @@ def generate_sched_condition(self, builder, condition, cond_ptr, node, is_finish assert len(condition.args) == 1 target_is_finished_ptr = is_finished_flag_locs[condition.args[0]] target_is_finished = builder.load(target_is_finished_ptr) - + return builder.fcmp_ordered("==", target_is_finished, target_is_finished.type(1)) @@ -506,7 +506,7 @@ def generate_sched_condition(self, builder, condition, cond_ptr, node, is_finish run_cond = builder.or_(run_cond, node_is_finished) return run_cond - + elif isinstance(condition, WhenFinishedAll): assert len(condition.args) > 0 diff --git a/psyneulink/library/compositions/compiledloss.py b/psyneulink/library/compositions/compiledloss.py index afb93a59a46..b82fd64cd49 100644 --- a/psyneulink/library/compositions/compiledloss.py +++ b/psyneulink/library/compositions/compiledloss.py @@ -24,7 +24,7 @@ class MSELoss(Loss): def __init__(self, reduction='sum'): if reduction not in ['sum']: raise Exception("Unsupported compiled reduction type " + reduction) - + super().__init__() self.reduction = reduction @@ -51,7 +51,7 @@ def _gen_loss_function(self, ctx): # Average the values in sum by dimensionality builder.store(builder.fdiv(builder.load(sum),builder.uitofp(dim, ctx.float_ty)), sum) - + builder.ret(builder.load(sum)) return builder.function diff --git a/psyneulink/library/compositions/compiledoptimizer.py b/psyneulink/library/compositions/compiledoptimizer.py index 5e585af59b0..eabf802a4b4 100644 --- a/psyneulink/library/compositions/compiledoptimizer.py +++ b/psyneulink/library/compositions/compiledoptimizer.py @@ -180,11 +180,11 @@ def step(self, ctx): delta_w, [zero, proj_idx_ir]) pnlvm.helpers.printf_float_matrix(builder, delta_w_ptr, prefix=f"grad val: {proj.sender._mechanism} -> {proj.receiver._mechanism}\n", override_debug=False) - + # this is messy - #TODO - cleanup this weights_llvmlite = proj._extract_llvm_matrix(ctx, builder, params) dim_x, dim_y = proj.matrix.shape - + weight_row = None pnlvm.helpers.printf(builder, "biascorr2 %.20f\n", one_minus_b2_pow, override_debug=False) with pnlvm.helpers.for_loop_zero_inc(builder, ctx.int32_ty(dim_x), "optimizer_w_upd_outer") as (b1, weight_row): diff --git a/psyneulink/library/compositions/pytorchmodelcreator.py b/psyneulink/library/compositions/pytorchmodelcreator.py index 8464addbdca..5f5a7fb872a 100644 --- a/psyneulink/library/compositions/pytorchmodelcreator.py +++ b/psyneulink/library/compositions/pytorchmodelcreator.py @@ -38,7 +38,7 @@ def __init__(self, composition, device, context=None): self.params = nn.ParameterList() self.device = device self._composition = composition - + # Instantiate pytorch mechanisms for node in set(composition.nodes) - set(composition.get_nodes_by_role(NodeRole.LEARNING)): pytorch_node = PytorchMechanismWrapper(node, self._composition._get_node_index(node), device, context=context) @@ -149,12 +149,12 @@ def _gen_llvm_training_backprop(self, ctx, optimizer, loss): # 2) call forward computation z_values = self._gen_llvm_forward_function_body( ctx, builder, state, params, model_input, data) - + # 3) compute errors loss_fn = ctx.import_llvm_function(loss) total_loss = builder.alloca(ctx.float_ty) builder.store(ctx.float_ty(0), total_loss) - + error_dict = {} for exec_set in reversed(self.execution_sets): for node in exec_set: @@ -168,7 +168,7 @@ def _gen_llvm_training_backprop(self, ctx, optimizer, loss): if NodeRole.OUTPUT in self._composition.get_roles_by_node(node._mechanism): # We handle output layer here # compute dC/da = a_l - y(x) (TODO: Allow other cost functions! This only applies to MSE) - + # 1) Lookup desired target value terminal_sequence = self._composition._terminal_backprop_sequences[node._mechanism] target_idx = self._composition.get_nodes_by_role( diff --git a/setup.cfg b/setup.cfg index 347cbb61b40..38c9accb89e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -66,7 +66,7 @@ filterwarnings = [pycodestyle] # for code explanation see https://pep8.readthedocs.io/en/latest/intro.html#error-codes -ignore = E111,E114,E115,E116,E117,E121,E122,E123,E124,E125,E126,E127,E128,E129,E131,E201,E202,E203,E211,E221,E225,E231,E241,E251,E252,E261,E262,E265,E266,E271,E301,E302,E303,E305,E306,E501,E711,E712,E713,E714,E721,E722,E731,E741,W293,W391,W503,W504,W605 +ignore = E111,E114,E115,E116,E117,E121,E122,E123,E124,E125,E126,E127,E128,E129,E131,E201,E202,E203,E211,E221,E225,E231,E241,E251,E252,E261,E262,E265,E266,E271,E301,E302,E303,E305,E306,E501,E711,E712,E713,E714,E721,E722,E731,E741,W391,W503,W504,W605 exclude = .git/*,Scripts/*,__pytest__/*,docs/*,bin/* [pydocstyle] diff --git a/tests/composition/test_composition.py b/tests/composition/test_composition.py index 7256f936223..7cfd8e7342e 100644 --- a/tests/composition/test_composition.py +++ b/tests/composition/test_composition.py @@ -1086,7 +1086,7 @@ def test_composition_pathways_arg_dict_with_non_list_or_node_value_error(self): c = Composition(pathways=[{'P1':'A'}]) assert ("The value in a dict specified in the \'pathways\' arg of the constructor" in str(error_text.value) and "must be a pathway specification (Node, list or tuple): A." in str(error_text.value)) - + def test_composition_pathways_Pathway_in_learning_tuples(self): pnl.clear_registry(pnl.PathwayRegistry) A = ProcessingMechanism(name='A') @@ -4472,7 +4472,7 @@ def test_nested_transfer_mechanism_composition_parallel(self, mode): sched = Scheduler(composition=outer_comp) ret = outer_comp.run(inputs={inner_comp1: [[1.0]], inner_comp2: [[1.0]]}, bin_execute=mode) assert np.allclose(ret, [[[0.52497918747894]],[[0.52497918747894]]]) - + @pytest.mark.nested @pytest.mark.composition @pytest.mark.parametrize("mode", ['Python', @@ -4497,7 +4497,7 @@ def test_nested_run_differing_num_trials(self, mode): inner_mech_B : [[[0,0]],[[0,0]]], } } - + outer.run(inputs=input, bin_execute=mode) def test_invalid_projection_deletion_when_nesting_comps(self): @@ -5666,13 +5666,13 @@ def test_function_as_learning_input(self): [0, 1], [1, 0], [1, 1]]) - + xor_targets = np.array( # the outputs we wish to see from the model [[0], [1], [1], [0]]) - + in_to_hidden_matrix = np.random.rand(2,10) hidden_to_out_matrix = np.random.rand(10,1) diff --git a/tests/composition/test_control.py b/tests/composition/test_control.py index aaaecc96933..eea730c027e 100644 --- a/tests/composition/test_control.py +++ b/tests/composition/test_control.py @@ -1014,11 +1014,11 @@ def test_recurrent_control(self, mode): initial_value=np.array([[0.0, 0.0]]), output_ports=[pnl.RESULT], name='rtm') - + controller = pnl.ControlMechanism( monitor_for_control=monitor, control_signals=[(pnl.NOISE, rtm)]) - + comp = pnl.Composition() roles = [pnl.NodeRole.INPUT, pnl.NodeRole.OUTPUT] comp.add_node(monitor, required_roles=roles) diff --git a/tests/composition/test_learning.py b/tests/composition/test_learning.py index 6ef8324a2cb..752b5f92ddd 100644 --- a/tests/composition/test_learning.py +++ b/tests/composition/test_learning.py @@ -1837,7 +1837,7 @@ def test_multilayer(self): comp.learn(inputs=input_dictionary, num_trials=10) - + objective_output_layer = comp.nodes[5] expected_output = [ @@ -1900,42 +1900,42 @@ def test_xor_training_identicalness_standard_composition_vs_autodiff(self, model [0, 1], [1, 0], [1, 1]]) - + xor_targets = np.array( # the outputs we wish to see from the model [[0], [1], [1], [0]]) - + in_to_hidden_matrix = np.random.rand(2,10) hidden_to_out_matrix = np.random.rand(10,1) - + # SET UP MODELS -------------------------------------------------------------------------------- # STANDARD Composition if pnl.COMPOSITION in models: - + input_comp = pnl.TransferMechanism(name='input_comp', default_variable=np.zeros(2)) - + hidden_comp = pnl.TransferMechanism(name='hidden_comp', default_variable=np.zeros(10), function=pnl.Logistic()) - + output_comp = pnl.TransferMechanism(name='output_comp', default_variable=np.zeros(1), function=pnl.Logistic()) - + in_to_hidden_comp = pnl.MappingProjection(name='in_to_hidden_comp', matrix=in_to_hidden_matrix.copy(), sender=input_comp, receiver=hidden_comp) - + hidden_to_out_comp = pnl.MappingProjection(name='hidden_to_out_comp', matrix=hidden_to_out_matrix.copy(), sender=hidden_comp, receiver=output_comp) - + xor_comp = pnl.Composition() backprop_pathway = xor_comp.add_backpropagation_learning_pathway([input_comp, @@ -1952,39 +1952,39 @@ def test_xor_training_identicalness_standard_composition_vs_autodiff(self, model # AutodiffComposition if 'AUTODIFF' in models: - + input_autodiff = pnl.TransferMechanism(name='input', default_variable=np.zeros(2)) - + hidden_autodiff = pnl.TransferMechanism(name='hidden', default_variable=np.zeros(10), function=pnl.Logistic()) - + output_autodiff = pnl.TransferMechanism(name='output', default_variable=np.zeros(1), function=pnl.Logistic()) - + in_to_hidden_autodiff = pnl.MappingProjection(name='in_to_hidden', matrix=in_to_hidden_matrix.copy(), sender=input_autodiff, receiver=hidden_autodiff) - + hidden_to_out_autodiff = pnl.MappingProjection(name='hidden_to_out', matrix=hidden_to_out_matrix.copy(), sender=hidden_autodiff, receiver=output_autodiff) - + xor_autodiff = pnl.AutodiffComposition(learning_rate=10, optimizer_type='sgd') - + xor_autodiff.add_node(input_autodiff) xor_autodiff.add_node(hidden_autodiff) xor_autodiff.add_node(output_autodiff) - + xor_autodiff.add_projection(sender=input_autodiff, projection=in_to_hidden_autodiff, receiver=hidden_autodiff) xor_autodiff.add_projection(sender=hidden_autodiff, projection=hidden_to_out_autodiff, receiver=output_autodiff) xor_autodiff.infer_backpropagation_learning_pathways() - + inputs_dict = {"inputs": {input_autodiff:xor_inputs}, "targets": {output_autodiff:xor_targets}, "epochs": num_epochs} @@ -2579,7 +2579,7 @@ def test_pytorch_equivalence_with_learning_enabled_composition(self): mnet.learn(inputs=inputs) mnet.run(inputs=inputs) - + comparator = np.array([0.02288846, 0.11646781, 0.03473711, 0.0348004, 0.01679579, 0.04851733, 0.05857743, 0.04819957, 0.03004438, 0.05113508, 0.06849843, 0.0442623, 0.00967315, 0.06998125, 0.03482444, diff --git a/tests/llvm/test_helpers.py b/tests/llvm/test_helpers.py index 9d6b6069968..34c9a592b6e 100644 --- a/tests/llvm/test_helpers.py +++ b/tests/llvm/test_helpers.py @@ -128,7 +128,7 @@ def test_helper_is_close(mode): b1.store(out_val, out_ptr) builder.ret_void() - + vec1 = copy.deepcopy(VECTOR) tmp = np.random.rand(DIM_X) tmp[0::2] = vec1[0::2] diff --git a/tests/mechanisms/test_control_mechanism.py b/tests/mechanisms/test_control_mechanism.py index fdf99160c36..860a33cac10 100644 --- a/tests/mechanisms/test_control_mechanism.py +++ b/tests/mechanisms/test_control_mechanism.py @@ -149,11 +149,11 @@ def test_identicalness_of_control_and_gating(self): Hidden_Layer_1 = pnl.TransferMechanism(name='Hidden Layer_1', function=pnl.Logistic, size=5) Hidden_Layer_2 = pnl.TransferMechanism(name='Hidden Layer_2', function=pnl.Logistic, size=4) Output_Layer = pnl.TransferMechanism(name='Output Layer', function=pnl.Logistic, size=3) - + Control_Mechanism = pnl.ControlMechanism(size=[1], control=[Hidden_Layer_1.input_port, Hidden_Layer_2.input_port, Output_Layer.input_port]) - + Input_Weights_matrix = (np.arange(2 * 5).reshape((2, 5)) + 1) / (2 * 5) Middle_Weights_matrix = (np.arange(5 * 4).reshape((5, 4)) + 1) / (5 * 4) Output_Weights_matrix = (np.arange(4 * 3).reshape((4, 3)) + 1) / (4 * 3) @@ -174,7 +174,7 @@ def test_identicalness_of_control_and_gating(self): Output_Weights = pnl.MappingProjection(sender=Hidden_Layer_2, receiver=Output_Layer, matrix=Output_Weights_matrix) - + pathway = [Input_Layer, Input_Weights, Hidden_Layer_1, Hidden_Layer_2, Output_Layer] comp = pnl.Composition() backprop_pathway = comp.add_backpropagation_learning_pathway( @@ -183,24 +183,24 @@ def test_identicalness_of_control_and_gating(self): ) # c.add_linear_processing_pathway(pathway=z) comp.add_node(Control_Mechanism) - + stim_list = { Input_Layer: [[-1, 30]], Control_Mechanism: [1.0], backprop_pathway.target: [[0, 0, 1]]} - + comp.learn(num_trials=3, inputs=stim_list) expected_results =[[[0.81493513, 0.85129046, 0.88154205]], [[0.81331773, 0.85008207, 0.88157851]], [[0.81168332, 0.84886047, 0.88161468]]] assert np.allclose(comp.results, expected_results) - + stim_list[Control_Mechanism]=[0.0] results = comp.learn(num_trials=1, inputs=stim_list) expected_results = [[[0.5, 0.5, 0.5]]] assert np.allclose(results, expected_results) - + stim_list[Control_Mechanism]=[2.0] results = comp.learn(num_trials=1, inputs=stim_list) expected_results = [[0.96941429, 0.9837254 , 0.99217549]] diff --git a/tests/scheduling/test_system_newsched.py b/tests/scheduling/test_system_newsched.py index 6e2ce9cfffb..88afa82ee17 100644 --- a/tests/scheduling/test_system_newsched.py +++ b/tests/scheduling/test_system_newsched.py @@ -145,7 +145,7 @@ def test_two_ABB(self): ) c = Composition(pathways=[A, B]) - + term_conds = {TimeScale.TRIAL: AfterNCalls(B, 2)} stim_list = {A: [[1]]} @@ -191,7 +191,7 @@ def test_three_ABAC(self): ) c = Composition(pathways=[[A,B],[A,C]]) - + term_conds = {TimeScale.TRIAL: AfterNCalls(C, 1)} stim_list = {A: [[1]]} @@ -240,7 +240,7 @@ def test_three_ABAC_convenience(self): ) c = Composition(pathways=[[A,B],[A,C]]) - + term_conds = {TimeScale.TRIAL: AfterNCalls(C, 1)} stim_list = {A: [[1]]} @@ -287,7 +287,7 @@ def test_three_ABACx2(self): ) c = Composition(pathways=[[A,B],[A,C]]) - + term_conds = {TimeScale.TRIAL: AfterNCalls(C, 2)} stim_list = {A: [[1]]} @@ -387,7 +387,7 @@ def test_three_2_ABCx2(self): ) c = Composition(pathways=[[A,C],[B,C]]) - + term_conds = {TimeScale.TRIAL: AfterNCalls(C, 2)} stim_list = {A: [[1]], B: [[2]]} @@ -496,7 +496,7 @@ def test_four_ABBCD(self): default_variable=[0], function=Linear(slope=1.0), ) - + c = Composition(pathways=[[A,B,D],[A,C,D]]) term_conds = {TimeScale.TRIAL: AfterNCalls(D, 1)} @@ -785,7 +785,7 @@ def test_termination_conditions_reset(self): ) c = Composition(pathways=[[A,B]]) - + term_conds = {TimeScale.TRIAL: AfterNCalls(B, 2)} stim_list = {A: [[1]]} From 345864465b39da3095b74e6b8b9d532d5f072129 Mon Sep 17 00:00:00 2001 From: Jan Vesely Date: Sat, 18 Jul 2020 21:03:06 -0400 Subject: [PATCH 02/13] codestyle: Fix and check W391; Blank line at end of file Signed-off-by: Jan Vesely --- .../functions/statefulfunctions/integratorfunctions.py | 3 --- .../components/functions/statefulfunctions/memoryfunctions.py | 2 -- psyneulink/core/components/functions/userdefinedfunction.py | 1 - psyneulink/core/components/mechanisms/mechanism.py | 1 - .../core/components/mechanisms/modulatory/control/__init__.py | 1 - .../core/components/ports/modulatorysignals/learningsignal.py | 1 - psyneulink/core/components/projections/projection.py | 3 --- psyneulink/core/globals/preferences/mechanismpreferenceset.py | 2 -- .../library/components/mechanisms/processing/integrator/ddm.py | 1 - setup.cfg | 2 +- tests/composition/test_control.py | 1 - tests/composition/test_models.py | 2 -- tests/composition/test_runtime_params.py | 1 - tests/functions/test_buffer.py | 1 - tests/mechanisms/test_input_output_labels.py | 1 - tests/mechanisms/test_modulatory_mechanism.py | 1 - tests/mechanisms/test_recurrent_transfer_mechanism.py | 2 -- tests/projections/test_projection_specifications.py | 1 - 18 files changed, 1 insertion(+), 26 deletions(-) diff --git a/psyneulink/core/components/functions/statefulfunctions/integratorfunctions.py b/psyneulink/core/components/functions/statefulfunctions/integratorfunctions.py index 5a45100af8a..17a2fcc7053 100644 --- a/psyneulink/core/components/functions/statefulfunctions/integratorfunctions.py +++ b/psyneulink/core/components/functions/statefulfunctions/integratorfunctions.py @@ -4425,6 +4425,3 @@ def __gen_llvm_dw_dt(self, builder, ctx, w, previous_v, param_vals): res = builder.fdiv(sum, param_vals["time_constant_w"]) return res - - - diff --git a/psyneulink/core/components/functions/statefulfunctions/memoryfunctions.py b/psyneulink/core/components/functions/statefulfunctions/memoryfunctions.py index 1ba2aa6a44f..6f96936e60c 100644 --- a/psyneulink/core/components/functions/statefulfunctions/memoryfunctions.py +++ b/psyneulink/core/components/functions/statefulfunctions/memoryfunctions.py @@ -1347,5 +1347,3 @@ def memory(self): return np.array(list(zip(self._memory[KEYS],self._memory[VALS]))) except: return np.array([]) - - diff --git a/psyneulink/core/components/functions/userdefinedfunction.py b/psyneulink/core/components/functions/userdefinedfunction.py index 44982ebdaf3..6b4295ade27 100644 --- a/psyneulink/core/components/functions/userdefinedfunction.py +++ b/psyneulink/core/components/functions/userdefinedfunction.py @@ -605,4 +605,3 @@ def _wrapper(params, state, arg_in, arg_out): builder.call(wrapper_ptr, [params, state, arg_in, arg_out]) return builder - diff --git a/psyneulink/core/components/mechanisms/mechanism.py b/psyneulink/core/components/mechanisms/mechanism.py index d14c7561efb..8068a4b7a40 100644 --- a/psyneulink/core/components/mechanisms/mechanism.py +++ b/psyneulink/core/components/mechanisms/mechanism.py @@ -4146,4 +4146,3 @@ def output_port_values(self): def output_values(self): """Return dict with output_values for all Mechanisms in MechanismList""" return self._get_attributes_dict('values', 'value') - diff --git a/psyneulink/core/components/mechanisms/modulatory/control/__init__.py b/psyneulink/core/components/mechanisms/modulatory/control/__init__.py index 6fd4626d172..70686823f53 100644 --- a/psyneulink/core/components/mechanisms/modulatory/control/__init__.py +++ b/psyneulink/core/components/mechanisms/modulatory/control/__init__.py @@ -6,4 +6,3 @@ __all__ = list(defaultcontrolmechanism.__all__) __all__.extend(optimizationcontrolmechanism.__all__) - diff --git a/psyneulink/core/components/ports/modulatorysignals/learningsignal.py b/psyneulink/core/components/ports/modulatorysignals/learningsignal.py index ff0699c6743..f06931f39f4 100644 --- a/psyneulink/core/components/ports/modulatorysignals/learningsignal.py +++ b/psyneulink/core/components/ports/modulatorysignals/learningsignal.py @@ -386,4 +386,3 @@ def _assign_default_port_Name(self, context=None): # Otherwise, allow ModulatorySignal to construct default name as usual else: super()._assign_default_port_Name(context=context) - diff --git a/psyneulink/core/components/projections/projection.py b/psyneulink/core/components/projections/projection.py index e959b016359..3e21a2ec01b 100644 --- a/psyneulink/core/components/projections/projection.py +++ b/psyneulink/core/components/projections/projection.py @@ -2165,6 +2165,3 @@ def _add_projection_from(sender, port, projection_spec, receiver, context=None): name=sender.name + '.output_ports') output_port._instantiate_projections_to_port(projections=projection_spec, context=context) - - - diff --git a/psyneulink/core/globals/preferences/mechanismpreferenceset.py b/psyneulink/core/globals/preferences/mechanismpreferenceset.py index 4584a6e56d0..739f744a09f 100644 --- a/psyneulink/core/globals/preferences/mechanismpreferenceset.py +++ b/psyneulink/core/globals/preferences/mechanismpreferenceset.py @@ -190,5 +190,3 @@ def runtimeParamModulationPrefEntry(self, entry): format(entry, self._runtime_param_modulation_pref)) return self._runtime_param_modulation_pref = entry - - diff --git a/psyneulink/library/components/mechanisms/processing/integrator/ddm.py b/psyneulink/library/components/mechanisms/processing/integrator/ddm.py index 5513efb05b5..3c4d6389113 100644 --- a/psyneulink/library/components/mechanisms/processing/integrator/ddm.py +++ b/psyneulink/library/components/mechanisms/processing/integrator/ddm.py @@ -1229,4 +1229,3 @@ def _gen_llvm_is_finished_cond(self, ctx, builder, params, state, current): is_prev_greater_or_equal = builder.fcmp_ordered('>=', prev_val, threshold) return is_prev_greater_or_equal - diff --git a/setup.cfg b/setup.cfg index 38c9accb89e..31da07ca71c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -66,7 +66,7 @@ filterwarnings = [pycodestyle] # for code explanation see https://pep8.readthedocs.io/en/latest/intro.html#error-codes -ignore = E111,E114,E115,E116,E117,E121,E122,E123,E124,E125,E126,E127,E128,E129,E131,E201,E202,E203,E211,E221,E225,E231,E241,E251,E252,E261,E262,E265,E266,E271,E301,E302,E303,E305,E306,E501,E711,E712,E713,E714,E721,E722,E731,E741,W391,W503,W504,W605 +ignore = E111,E114,E115,E116,E117,E121,E122,E123,E124,E125,E126,E127,E128,E129,E131,E201,E202,E203,E211,E221,E225,E231,E241,E251,E252,E261,E262,E265,E266,E271,E301,E302,E303,E305,E306,E501,E711,E712,E713,E714,E721,E722,E731,E741,W503,W504,W605 exclude = .git/*,Scripts/*,__pytest__/*,docs/*,bin/* [pydocstyle] diff --git a/tests/composition/test_control.py b/tests/composition/test_control.py index eea730c027e..780d180b09f 100644 --- a/tests/composition/test_control.py +++ b/tests/composition/test_control.py @@ -2207,4 +2207,3 @@ def test_list(self): assert sample_iterator.start == 1 assert sample_iterator.stop is None assert sample_iterator.num == len(sample_list) - diff --git a/tests/composition/test_models.py b/tests/composition/test_models.py index 2e7fe4ee645..ccffd71d057 100644 --- a/tests/composition/test_models.py +++ b/tests/composition/test_models.py @@ -570,5 +570,3 @@ def switch_trial_type(): # 0.66310932, 0.66378136, 0.6644706, 0.66517677, 0.66589961, 0.66663887, # 0.66739429, 0.66816564, 0.66895265, 0.66975511, 0.67057276, 0.67140537], # atol=1e-02) - - diff --git a/tests/composition/test_runtime_params.py b/tests/composition/test_runtime_params.py index db3f670ceb7..978b46f24ce 100644 --- a/tests/composition/test_runtime_params.py +++ b/tests/composition/test_runtime_params.py @@ -809,4 +809,3 @@ def test_composition_runtime_param_errors(self): ) assert ("Invalid specification in runtime_params arg for matrix of TARGET PROJECTION: 'amiby'." in str(error_text.value)) - diff --git a/tests/functions/test_buffer.py b/tests/functions/test_buffer.py index ea204bf7853..c3e9efe6b2b 100644 --- a/tests/functions/test_buffer.py +++ b/tests/functions/test_buffer.py @@ -180,4 +180,3 @@ def assemble_full_result(): for i in range(5): assert np.allclose(expected_full_result[i], np.asfarray(full_result[i])) - diff --git a/tests/mechanisms/test_input_output_labels.py b/tests/mechanisms/test_input_output_labels.py index 0071c8d35f1..7a3155075fb 100644 --- a/tests/mechanisms/test_input_output_labels.py +++ b/tests/mechanisms/test_input_output_labels.py @@ -319,4 +319,3 @@ # assert np.allclose(store_output_labels[1], [[2.0, 2.0]]) # assert store_output_labels[2] == ['green'] # assert np.allclose(store_output_labels[3], [[2.0, 2.0]]) - diff --git a/tests/mechanisms/test_modulatory_mechanism.py b/tests/mechanisms/test_modulatory_mechanism.py index c806068ecb3..bc1add43347 100644 --- a/tests/mechanisms/test_modulatory_mechanism.py +++ b/tests/mechanisms/test_modulatory_mechanism.py @@ -56,4 +56,3 @@ def test_control_modulation_in_composition(self): assert Tz.parameter_ports[SLOPE].mod_afferents[0].sender.owner == C assert np.allclose(comp.results,[[[1.], [4.]], [[4.], [4.]]]) - diff --git a/tests/mechanisms/test_recurrent_transfer_mechanism.py b/tests/mechanisms/test_recurrent_transfer_mechanism.py index 83a66b13ae0..c2c24dbc8e1 100644 --- a/tests/mechanisms/test_recurrent_transfer_mechanism.py +++ b/tests/mechanisms/test_recurrent_transfer_mechanism.py @@ -1394,5 +1394,3 @@ def test_matrix(self): print("\n\nMatrix Values ----------------------------------") print("R.matrix = ", R.matrix) print("R.parameters.matrix.get(eid) = ", R.parameters.matrix.get(eid)) - - diff --git a/tests/projections/test_projection_specifications.py b/tests/projections/test_projection_specifications.py index ddead9e6fc9..3d5985ce359 100644 --- a/tests/projections/test_projection_specifications.py +++ b/tests/projections/test_projection_specifications.py @@ -463,4 +463,3 @@ def test_duplicate_projection_creation_error(self): pnl.MappingProjection(sender=T1,receiver=T2,name='MP2') assert 'Attempt to assign Projection to InputPort-0 of T2 that already has an identical Projection.' \ in record.value.args[0] - From bb1ca78c70e2575e342232a6adad5975ec893bce Mon Sep 17 00:00:00 2001 From: Jan Vesely Date: Sat, 18 Jul 2020 19:43:15 -0400 Subject: [PATCH 03/13] codestyle: Fix and check E111; Indentation is not a multiple of 4 Signed-off-by: Jan Vesely --- .../components/functions/transferfunctions.py | 4 +-- .../core/components/projections/projection.py | 14 ++++---- psyneulink/core/globals/context.py | 4 +-- .../core/globals/preferences/preferenceset.py | 12 +++---- psyneulink/core/globals/registry.py | 10 +++--- setup.cfg | 2 +- .../test_projection_specifications.py | 34 +++++++++---------- 7 files changed, 40 insertions(+), 40 deletions(-) diff --git a/psyneulink/core/components/functions/transferfunctions.py b/psyneulink/core/components/functions/transferfunctions.py index 41041caa5c8..132bdfb999d 100644 --- a/psyneulink/core/components/functions/transferfunctions.py +++ b/psyneulink/core/components/functions/transferfunctions.py @@ -125,8 +125,8 @@ def _gen_llvm_function_body(self, ctx, builder, params, state, arg_in, arg_out, self._gen_llvm_transfer(ctx=ctx, vi=vi, vo=vo, params=params, state=state, *args, tags=tags) else: - self._gen_llvm_transfer(b, idx, ctx=ctx, vi=arg_in, vo=arg_out, - params=params, state=state, tags=tags) + self._gen_llvm_transfer(b, idx, ctx=ctx, vi=arg_in, vo=arg_out, + params=params, state=state, tags=tags) return builder diff --git a/psyneulink/core/components/projections/projection.py b/psyneulink/core/components/projections/projection.py index 3e21a2ec01b..1e39407ed88 100644 --- a/psyneulink/core/components/projections/projection.py +++ b/psyneulink/core/components/projections/projection.py @@ -1591,9 +1591,9 @@ def _parse_connection_specs(connectee_port_type, # Call _parse_connection_spec for each Port or Mechanism, to generate a conection spec for each for connect_with_spec in first_item: if not isinstance(connect_with_spec, (Port, Mechanism)): - raise PortError(f"Item in the list used to specify a {last_item.__name__} " - f"for {owner.name} ({connect_with_spec.__name__}) " - f"is not a {Port.__name__} or {Mechanism.__name__}") + raise PortError(f"Item in the list used to specify a {last_item.__name__} " + f"for {owner.name} ({connect_with_spec.__name__}) " + f"is not a {Port.__name__} or {Mechanism.__name__}") c = _parse_connection_specs(connectee_port_type=connectee_port_type, owner=owner, connections=ProjectionTuple(connect_with_spec, @@ -1620,10 +1620,10 @@ def _parse_connection_specs(connectee_port_type, # Call _parse_connection_spec for each Port name, to generate a conection spec for each for port_Name in port_item: if not isinstance(port_Name, str): - raise ProjectionError("Expected 1st item of the {} specification tuple for {} ({}) to be " - "the name of a {} of its 2nd item ({})". - format(connectee_port_type.__name__, owner.name, port_Name, - connects_with, mech_item.name)) + raise ProjectionError("Expected 1st item of the {} specification tuple for {} ({}) to be " + "the name of a {} of its 2nd item ({})". + format(connectee_port_type.__name__, owner.name, port_Name, + connects_with, mech_item.name)) c = _parse_connection_specs(connectee_port_type=connectee_port_type, owner=owner, connections=ProjectionTuple(port_Name, diff --git a/psyneulink/core/globals/context.py b/psyneulink/core/globals/context.py index 36ddf75b040..7eef92d344c 100644 --- a/psyneulink/core/globals/context.py +++ b/psyneulink/core/globals/context.py @@ -228,14 +228,14 @@ def _get_context_string(cls, condition_flags, flagged_items.append(ContextFlags.IDLE.name) break if c & condition_flags: - flagged_items.append(c.name) + flagged_items.append(c.name) if SOURCE in fields: for c in SOURCE_FLAGS: if not condition_flags & ContextFlags.SOURCE_MASK: flagged_items.append(ContextFlags.NONE.name) break if c & condition_flags: - flagged_items.append(c.name) + flagged_items.append(c.name) string += ", ".join(flagged_items) return string diff --git a/psyneulink/core/globals/preferences/preferenceset.py b/psyneulink/core/globals/preferences/preferenceset.py index a372cdde5d4..7b2c777e04e 100644 --- a/psyneulink/core/globals/preferences/preferenceset.py +++ b/psyneulink/core/globals/preferences/preferenceset.py @@ -40,11 +40,11 @@ class PreferenceLevel(IntEnum): class PreferenceSetError(Exception): - def __init__(self, error_value): - self.error_value = error_value + def __init__(self, error_value): + self.error_value = error_value - def __str__(self): - return repr(self.error_value) + def __str__(self): + return repr(self.error_value) @abc.abstractmethod @@ -228,10 +228,10 @@ def __init__(self, name = self.__class__.__name__ # If it belongs to a class, append name of owner's class to name if inspect.isclass(owner): - name = name + 'DefaultsFor' + owner.__name__ + name = name + 'DefaultsFor' + owner.__name__ # Otherwise, it belongs to an object, so append name of the owner object's class to name else: - name = name + 'Defaultsfor' + owner.__class__.__name__ + name = name + 'Defaultsfor' + owner.__class__.__name__ # REGISTER # FIX: MAKE SURE THIS MAKES SENSE diff --git a/psyneulink/core/globals/registry.py b/psyneulink/core/globals/registry.py index 103fb86d69a..17dd338bcda 100644 --- a/psyneulink/core/globals/registry.py +++ b/psyneulink/core/globals/registry.py @@ -125,25 +125,25 @@ def register_category(entry, from psyneulink.core.components.shellclasses import Port if inspect.isclass(entry) and issubclass(entry, Port): try: - entry.portAttributes + entry.portAttributes except AttributeError: raise RegistryError("PROGRAM ERROR: {} must implement a stateSpecificParams attribute". format(entry.__name__)) try: - entry.connectsWith + entry.connectsWith except AttributeError: raise RegistryError("PROGRAM ERROR: {} must implement a connectsWith attribute".format(entry.__name__)) try: - entry.connectsWithAttribute + entry.connectsWithAttribute except AttributeError: raise RegistryError("PROGRAM ERROR: {} must implement a connectsWithAttribute attribute". format(entry.__name__)) try: - entry.projectionSocket + entry.projectionSocket except AttributeError: raise RegistryError("PROGRAM ERROR: {} must implement a projectionSocket attribute".format(entry.__name__)) try: - entry.modulators + entry.modulators except AttributeError: raise RegistryError("PROGRAM ERROR: {} must implement a modulators attribute".format(entry.__name__)) diff --git a/setup.cfg b/setup.cfg index 31da07ca71c..fd7fc0393c9 100644 --- a/setup.cfg +++ b/setup.cfg @@ -66,7 +66,7 @@ filterwarnings = [pycodestyle] # for code explanation see https://pep8.readthedocs.io/en/latest/intro.html#error-codes -ignore = E111,E114,E115,E116,E117,E121,E122,E123,E124,E125,E126,E127,E128,E129,E131,E201,E202,E203,E211,E221,E225,E231,E241,E251,E252,E261,E262,E265,E266,E271,E301,E302,E303,E305,E306,E501,E711,E712,E713,E714,E721,E722,E731,E741,W503,W504,W605 +ignore = E114,E115,E116,E117,E121,E122,E123,E124,E125,E126,E127,E128,E129,E131,E201,E202,E203,E211,E221,E225,E231,E241,E251,E252,E261,E262,E265,E266,E271,E301,E302,E303,E305,E306,E501,E711,E712,E713,E714,E721,E722,E731,E741,W503,W504,W605 exclude = .git/*,Scripts/*,__pytest__/*,docs/*,bin/* [pydocstyle] diff --git a/tests/projections/test_projection_specifications.py b/tests/projections/test_projection_specifications.py index 3d5985ce359..f783354284b 100644 --- a/tests/projections/test_projection_specifications.py +++ b/tests/projections/test_projection_specifications.py @@ -116,23 +116,23 @@ def test_multiple_modulatory_projections_with_mech_and_port_Name_specs(self): assert M.output_ports[pnl.RESPONSE_TIME].mod_afferents[0]==G.gating_signals[0].efferents[1] def test_mapping_projection_with_mech_and_port_Name_specs(self): - R1 = pnl.TransferMechanism(output_ports=['OUTPUT_1', 'OUTPUT_2']) - R2 = pnl.TransferMechanism(default_variable=[[0],[0]], - input_ports=['INPUT_1', 'INPUT_2']) - T = pnl.TransferMechanism(input_ports=[{pnl.MECHANISM: R1, - pnl.OUTPUT_PORTS: ['OUTPUT_1', 'OUTPUT_2']}], - output_ports=[{pnl.MECHANISM:R2, - pnl.INPUT_PORTS: ['INPUT_1', 'INPUT_2']}]) - assert len(R1.output_ports)==2 - assert len(R2.input_ports)==2 - assert len(T.input_ports)==1 - for input_port in T.input_ports: - for projection in input_port.path_afferents: - assert projection.sender.owner is R1 - assert len(T.output_ports)==1 - for output_port in T.output_ports: - for projection in output_port.efferents: - assert projection.receiver.owner is R2 + R1 = pnl.TransferMechanism(output_ports=['OUTPUT_1', 'OUTPUT_2']) + R2 = pnl.TransferMechanism(default_variable=[[0],[0]], + input_ports=['INPUT_1', 'INPUT_2']) + T = pnl.TransferMechanism(input_ports=[{pnl.MECHANISM: R1, + pnl.OUTPUT_PORTS: ['OUTPUT_1', 'OUTPUT_2']}], + output_ports=[{pnl.MECHANISM:R2, + pnl.INPUT_PORTS: ['INPUT_1', 'INPUT_2']}]) + assert len(R1.output_ports)==2 + assert len(R2.input_ports)==2 + assert len(T.input_ports)==1 + for input_port in T.input_ports: + for projection in input_port.path_afferents: + assert projection.sender.owner is R1 + assert len(T.output_ports)==1 + for output_port in T.output_ports: + for projection in output_port.efferents: + assert projection.receiver.owner is R2 def test_mapping_projection_using_2_item_tuple_with_list_of_port_Names(self): From 3e21887f04758e981e628b16b7e523c537f0bd6d Mon Sep 17 00:00:00 2001 From: Jan Vesely Date: Sat, 18 Jul 2020 21:16:10 -0400 Subject: [PATCH 04/13] codestyle: Fix and check E211; Whitespace before '(' Mostly printf Signed-off-by: Jan Vesely --- .../core/components/mechanisms/mechanism.py | 13 +++++-------- .../modulatory/control/controlmechanism.py | 14 +++++++------- .../core/globals/preferences/preferenceset.py | 2 +- .../control/agt/agtcontrolmechanism.py | 16 ++++++++-------- .../modulatory/control/agt/lccontrolmechanism.py | 10 +++++----- setup.cfg | 2 +- tests/composition/test_learning.py | 4 ++-- 7 files changed, 29 insertions(+), 32 deletions(-) diff --git a/psyneulink/core/components/mechanisms/mechanism.py b/psyneulink/core/components/mechanisms/mechanism.py index 8068a4b7a40..47a2d9a2c3c 100644 --- a/psyneulink/core/components/mechanisms/mechanism.py +++ b/psyneulink/core/components/mechanisms/mechanism.py @@ -3095,10 +3095,7 @@ def _report_mechanism_execution(self, input_val=None, params=None, output=None, except TypeError: input_string = input_val - print ("\n\'{}\'{} executed:\n- input: {}". - format(self.name, - mechanism_string, - input_string)) + print("\n\'{}\'{} executed:\n- input: {}".format(self.name, mechanism_string, input_string)) if params: print("- params:") @@ -3123,14 +3120,14 @@ def _report_mechanism_execution(self, input_val=None, params=None, output=None, param_is_function = True else: param = param_value - print ("\t{}: {}".format(param_name, str(param).__str__().strip("[]"))) + print("\t{}: {}".format(param_name, str(param).__str__().strip("[]"))) if param_is_function: # Sort for consistency of output func_params_keys_sorted = sorted(self.function.parameters.names()) for fct_param_name in func_params_keys_sorted: - print ("\t\t{}: {}". - format(fct_param_name, - str(getattr(self.function.parameters, fct_param_name)).__str__().strip("[]"))) + print("\t\t{}: {}". + format(fct_param_name, + str(getattr(self.function.parameters, fct_param_name)).__str__().strip("[]"))) # FIX: kmantel: previous version would fail on anything but iterables of things that can be cast to floats # if you want more specific output, you can add conditional tests here diff --git a/psyneulink/core/components/mechanisms/modulatory/control/controlmechanism.py b/psyneulink/core/components/mechanisms/modulatory/control/controlmechanism.py index 2d16070cd18..845f98d1608 100644 --- a/psyneulink/core/components/mechanisms/modulatory/control/controlmechanism.py +++ b/psyneulink/core/components/mechanisms/modulatory/control/controlmechanism.py @@ -1595,32 +1595,32 @@ def show(self): weight = self.monitored_output_ports_weights_and_exponents[monitored_port_index][0] exponent = self.monitored_output_ports_weights_and_exponents[monitored_port_index][1] - print ("\t\t{0}: {1} (exp: {2}; wt: {3})". - format(monitored_port_Mech.name, monitored_port.name, weight, exponent)) + print("\t\t{0}: {1} (exp: {2}; wt: {3})". + format(monitored_port_Mech.name, monitored_port.name, weight, exponent)) try: if self.control_signals: - print ("\n\tControlling the following Mechanism parameters:".format(self.name)) + print("\n\tControlling the following Mechanism parameters:".format(self.name)) # Sort for consistency of output: port_Names_sorted = sorted(self.control_signals.names) for port_Name in port_Names_sorted: for projection in self.control_signals[port_Name].efferents: - print ("\t\t{0}: {1}".format(projection.receiver.owner.name, projection.receiver.name)) + print("\t\t{0}: {1}".format(projection.receiver.owner.name, projection.receiver.name)) except: pass try: if self.gating_signals: - print ("\n\tGating the following Ports:".format(self.name)) + print("\n\tGating the following Ports:".format(self.name)) # Sort for consistency of output: port_Names_sorted = sorted(self.gating_signals.names) for port_Name in port_Names_sorted: for projection in self.gating_signals[port_Name].efferents: - print ("\t\t{0}: {1}".format(projection.receiver.owner.name, projection.receiver.name)) + print("\t\t{0}: {1}".format(projection.receiver.owner.name, projection.receiver.name)) except: pass - print ("\n---------------------------------------------------------") + print("\n---------------------------------------------------------") def add_to_monitor(self, monitor_specs, context=None): """Instantiate OutputPorts to be monitored by ControlMechanism's `objective_mechanism diff --git a/psyneulink/core/globals/preferences/preferenceset.py b/psyneulink/core/globals/preferences/preferenceset.py index 7b2c777e04e..2a363386b95 100644 --- a/psyneulink/core/globals/preferences/preferenceset.py +++ b/psyneulink/core/globals/preferences/preferenceset.py @@ -384,7 +384,7 @@ def __init__(self, format(owner.name, owner.__class__.__name__)) if PreferenceSetVerbosity: - print ("Preference assignment condition {0}".format(condition)) + print("Preference assignment condition {0}".format(condition)) # FIX: ARE THESE NEEDED?? @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @property diff --git a/psyneulink/library/components/mechanisms/modulatory/control/agt/agtcontrolmechanism.py b/psyneulink/library/components/mechanisms/modulatory/control/agt/agtcontrolmechanism.py index f5e46de9981..cf00c39ec9b 100644 --- a/psyneulink/library/components/mechanisms/modulatory/control/agt/agtcontrolmechanism.py +++ b/psyneulink/library/components/mechanisms/modulatory/control/agt/agtcontrolmechanism.py @@ -387,12 +387,12 @@ def show(self): and the `multiplicative_params ` modulated by the AGTControlMechanism. """ - print ("\n---------------------------------------------------------") + print("\n---------------------------------------------------------") - print ("\n{0}".format(self.name)) + print("\n{0}".format(self.name)) print("\n\tMonitoring the following Mechanism OutputPorts:") if self.objective_mechanism is None: - print ("\t\tNone") + print("\t\tNone") else: for port in self.objective_mechanism.input_ports: for projection in port.path_afferents: @@ -403,14 +403,14 @@ def show(self): weight = self.monitored_output_ports_weights_and_exponents[monitored_port_index][0] exponent = self.monitored_output_ports_weights_and_exponents[monitored_port_index][1] - print ("\t\t{0}: {1} (exp: {2}; wt: {3})". - format(monitored_port_Mech.name, monitored_port.name, weight, exponent)) + print("\t\t{0}: {1} (exp: {2}; wt: {3})". + format(monitored_port_Mech.name, monitored_port.name, weight, exponent)) - print ("\n\tModulating the following parameters:".format(self.name)) + print("\n\tModulating the following parameters:".format(self.name)) # Sort for consistency of output: port_Names_sorted = sorted(self.output_ports.names) for port_Name in port_Names_sorted: for projection in self.output_ports[port_Name].efferents: - print ("\t\t{0}: {1}".format(projection.receiver.owner.name, projection.receiver.name)) + print("\t\t{0}: {1}".format(projection.receiver.owner.name, projection.receiver.name)) - print ("\n---------------------------------------------------------") + print("\n---------------------------------------------------------") diff --git a/psyneulink/library/components/mechanisms/modulatory/control/agt/lccontrolmechanism.py b/psyneulink/library/components/mechanisms/modulatory/control/agt/lccontrolmechanism.py index 6b2a0fa4eeb..3dee5710079 100644 --- a/psyneulink/library/components/mechanisms/modulatory/control/agt/lccontrolmechanism.py +++ b/psyneulink/library/components/mechanisms/modulatory/control/agt/lccontrolmechanism.py @@ -967,14 +967,14 @@ def show(self): weight = self.monitored_output_ports_weights_and_exponents[monitored_port_index][0] exponent = self.monitored_output_ports_weights_and_exponents[monitored_port_index][1] - print ("\t\t{0}: {1} (exp: {2}; wt: {3})". - format(monitored_port_Mech.name, monitored_port.name, weight, exponent)) + print("\t\t{0}: {1} (exp: {2}; wt: {3})". + format(monitored_port_Mech.name, monitored_port.name, weight, exponent)) - print ("\n\tModulating the following parameters:".format(self.name)) + print("\n\tModulating the following parameters:".format(self.name)) # Sort for consistency of output: port_Names_sorted = sorted(self.output_ports.names) for port_Name in port_Names_sorted: for projection in self.output_ports[port_Name].efferents: - print ("\t\t{0}: {1}".format(projection.receiver.owner.name, projection.receiver.name)) + print("\t\t{0}: {1}".format(projection.receiver.owner.name, projection.receiver.name)) - print ("\n---------------------------------------------------------") + print("\n---------------------------------------------------------") diff --git a/setup.cfg b/setup.cfg index fd7fc0393c9..daf20530eea 100644 --- a/setup.cfg +++ b/setup.cfg @@ -66,7 +66,7 @@ filterwarnings = [pycodestyle] # for code explanation see https://pep8.readthedocs.io/en/latest/intro.html#error-codes -ignore = E114,E115,E116,E117,E121,E122,E123,E124,E125,E126,E127,E128,E129,E131,E201,E202,E203,E211,E221,E225,E231,E241,E251,E252,E261,E262,E265,E266,E271,E301,E302,E303,E305,E306,E501,E711,E712,E713,E714,E721,E722,E731,E741,W503,W504,W605 +ignore = E114,E115,E116,E117,E121,E122,E123,E124,E125,E126,E127,E128,E129,E131,E201,E202,E203,E221,E225,E231,E241,E251,E252,E261,E262,E265,E266,E271,E301,E302,E303,E305,E306,E501,E711,E712,E713,E714,E721,E722,E731,E741,W503,W504,W605 exclude = .git/*,Scripts/*,__pytest__/*,docs/*,bin/* [pydocstyle] diff --git a/tests/composition/test_learning.py b/tests/composition/test_learning.py index 752b5f92ddd..8d41222b52e 100644 --- a/tests/composition/test_learning.py +++ b/tests/composition/test_learning.py @@ -179,7 +179,7 @@ def test_function_target_spec_converging_pathways(self): D: [2.0, 6.0], p1.target: [[3.0, 4.0], [7.0, 8.0]] } - def input_function (trial_num): + def input_function(trial_num): return { A: inputs[A][trial_num], D: inputs[D][trial_num], @@ -203,7 +203,7 @@ def test_dict_target_spec_diverging_pathways(self): p1.target: [2.0, 2.0], p2.target: [4.0, 4.0] } - def input_function (trial_num): + def input_function(trial_num): return { A: inputs[A][trial_num], p1.target: inputs[p1.target][trial_num], From ea5bc9d994aa08afdc17afdc6dbc29dc43d375f1 Mon Sep 17 00:00:00 2001 From: Jan Vesely Date: Sat, 4 Jul 2020 23:21:38 -0400 Subject: [PATCH 05/13] codestyle: Fix and check E266; Too many leading '#' for a comment Signed-off-by: Jan Vesely --- setup.cfg | 2 +- tests/composition/test_control.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.cfg b/setup.cfg index daf20530eea..825f9a8f220 100644 --- a/setup.cfg +++ b/setup.cfg @@ -66,7 +66,7 @@ filterwarnings = [pycodestyle] # for code explanation see https://pep8.readthedocs.io/en/latest/intro.html#error-codes -ignore = E114,E115,E116,E117,E121,E122,E123,E124,E125,E126,E127,E128,E129,E131,E201,E202,E203,E221,E225,E231,E241,E251,E252,E261,E262,E265,E266,E271,E301,E302,E303,E305,E306,E501,E711,E712,E713,E714,E721,E722,E731,E741,W503,W504,W605 +ignore = E114,E115,E116,E117,E121,E122,E123,E124,E125,E126,E127,E128,E129,E131,E201,E202,E203,E221,E225,E231,E241,E251,E252,E261,E262,E265,E271,E301,E302,E303,E305,E306,E501,E711,E712,E713,E714,E721,E722,E731,E741,W503,W504,W605 exclude = .git/*,Scripts/*,__pytest__/*,docs/*,bin/* [pydocstyle] diff --git a/tests/composition/test_control.py b/tests/composition/test_control.py index 780d180b09f..a32b8ac1b3d 100644 --- a/tests/composition/test_control.py +++ b/tests/composition/test_control.py @@ -143,7 +143,7 @@ def test_deferred_init(self): comp = pnl.Composition(name="evc", retain_old_simulation_data=True) - ### add the controller to the Composition before adding the relevant Mechanisms + # add the controller to the Composition before adding the relevant Mechanisms comp.add_controller(controller=pnl.OptimizationControlMechanism( agent_rep=comp, features=[Input.input_port, reward.input_port], From 69431a07fd8dba744bab75cbfad77fdd752a3536 Mon Sep 17 00:00:00 2001 From: Jan Vesely Date: Sat, 4 Jul 2020 23:47:59 -0400 Subject: [PATCH 06/13] codestyle: Fix and check E271; Multiple spaces after keyword Signed-off-by: Jan Vesely --- psyneulink/core/components/mechanisms/mechanism.py | 2 +- .../mechanisms/modulatory/learning/learningmechanism.py | 2 +- psyneulink/core/components/ports/inputport.py | 2 +- psyneulink/core/components/ports/outputport.py | 2 +- psyneulink/core/components/ports/parameterport.py | 2 +- psyneulink/core/components/projections/projection.py | 2 +- psyneulink/core/globals/preferences/preferenceset.py | 2 +- psyneulink/core/globals/utilities.py | 2 +- .../modulatory/control/agt/agtcontrolmechanism.py | 6 +++--- setup.cfg | 2 +- tests/composition/test_composition.py | 2 +- 11 files changed, 13 insertions(+), 13 deletions(-) diff --git a/psyneulink/core/components/mechanisms/mechanism.py b/psyneulink/core/components/mechanisms/mechanism.py index 47a2d9a2c3c..eee27d8b7c3 100644 --- a/psyneulink/core/components/mechanisms/mechanism.py +++ b/psyneulink/core/components/mechanisms/mechanism.py @@ -2512,7 +2512,7 @@ def execute(self, self.parameters.num_executions_before_finished._set(num_executions, override=True, context=context) - if num_executions >= max_executions: + if num_executions >= max_executions: self.parameters.is_finished_flag._set(True, context) warnings.warn(f"Maximum number of executions ({max_executions}) reached for {self.name}.") break diff --git a/psyneulink/core/components/mechanisms/modulatory/learning/learningmechanism.py b/psyneulink/core/components/mechanisms/modulatory/learning/learningmechanism.py index 020d07d5fb5..0fc87b83fad 100644 --- a/psyneulink/core/components/mechanisms/modulatory/learning/learningmechanism.py +++ b/psyneulink/core/components/mechanisms/modulatory/learning/learningmechanism.py @@ -1178,7 +1178,7 @@ def _validate_params(self, request_set, target_set=None, context=None): # Validate that the receiver of the LearningProjection (if specified) # is a MappingProjection and in the same System as self (if specified) if learning_signal[PARAMS] and PROJECTIONS in learning_signal[PARAMS]: - for learning_projection in learning_signal[PARAMS][PROJECTIONS]: + for learning_projection in learning_signal[PARAMS][PROJECTIONS]: _validate_receiver(sender_mech=self, projection=learning_projection, expected_owner_type=MappingProjection, diff --git a/psyneulink/core/components/ports/inputport.py b/psyneulink/core/components/ports/inputport.py index a6a41cc40fe..d2d6e54c555 100644 --- a/psyneulink/core/components/ports/inputport.py +++ b/psyneulink/core/components/ports/inputport.py @@ -1045,7 +1045,7 @@ def _parse_port_specific_specs(self, owner, port_dict, port_specific_spec): # (actual assignment is made in _parse_port_spec) if reference_value is None: port_dict[REFERENCE_VALUE]=port_spec - elif not iscompatible(port_spec, reference_value): + elif not iscompatible(port_spec, reference_value): raise PortError(f"Value in first item of 2-item tuple specification {InputPort.__name__} of " f"{owner.name} ({port_spec}) is not compatible with its {REFERENCE_VALUE} " f"({reference_value}).") diff --git a/psyneulink/core/components/ports/outputport.py b/psyneulink/core/components/ports/outputport.py index ccdabed3ea5..5fef880dad1 100644 --- a/psyneulink/core/components/ports/outputport.py +++ b/psyneulink/core/components/ports/outputport.py @@ -1115,7 +1115,7 @@ def _parse_port_specific_specs(self, owner, port_dict, port_specific_spec): # (actual assignment is made in _parse_port_spec) if reference_value is None: port_dict[REFERENCE_VALUE]=port_spec - elif not iscompatible(port_spec, reference_value): + elif not iscompatible(port_spec, reference_value): raise OutputPortError("Value in first item of 2-item tuple specification for {} of {} ({}) " "is not compatible with its {} ({})". format(OutputPort.__name__, owner.name, port_spec, diff --git a/psyneulink/core/components/ports/parameterport.py b/psyneulink/core/components/ports/parameterport.py index ce22b293e2b..74343a8bab1 100644 --- a/psyneulink/core/components/ports/parameterport.py +++ b/psyneulink/core/components/ports/parameterport.py @@ -625,7 +625,7 @@ def _parse_port_specific_specs(self, owner, port_dict, port_specific_spec): # (actual assignment is made in _parse_port_spec) if reference_value is None: port_dict[REFERENCE_VALUE]=port_spec - elif not iscompatible(port_spec, reference_value): + elif not iscompatible(port_spec, reference_value): raise PortError("Value in first item of 2-item tuple specification for {} of {} ({}) " "is not compatible with its {} ({})". format(ParameterPort.__name__, owner.name, port_spec, diff --git a/psyneulink/core/components/projections/projection.py b/psyneulink/core/components/projections/projection.py index 1e39407ed88..42f0741492c 100644 --- a/psyneulink/core/components/projections/projection.py +++ b/psyneulink/core/components/projections/projection.py @@ -1844,7 +1844,7 @@ def _validate_projection_type(projection_class): if connectee_port is OutputPort and isinstance(projection_spec, (GatingProjection, ControlProjection)): projection_socket = SENDER projection_socket_port = getattr(projection_spec, projection_socket) - if issubclass(projection_socket_port.__class__, connect_with_ports): + if issubclass(projection_socket_port.__class__, connect_with_ports): return True # None of the above worked, so must be incompatible diff --git a/psyneulink/core/globals/preferences/preferenceset.py b/psyneulink/core/globals/preferences/preferenceset.py index 2a363386b95..37b80e1a274 100644 --- a/psyneulink/core/globals/preferences/preferenceset.py +++ b/psyneulink/core/globals/preferences/preferenceset.py @@ -236,7 +236,7 @@ def __init__(self, # REGISTER # FIX: MAKE SURE THIS MAKES SENSE - from psyneulink.core.globals.registry import register_category + from psyneulink.core.globals.registry import register_category register_category(entry=self, base_class=PreferenceSet, name=name, diff --git a/psyneulink/core/globals/utilities.py b/psyneulink/core/globals/utilities.py index e14c08ffa05..e6b71b47259 100644 --- a/psyneulink/core/globals/utilities.py +++ b/psyneulink/core/globals/utilities.py @@ -601,7 +601,7 @@ def tensor_power(items, levels:tc.optional(range)=None, flat=False): levels = levels or range(1,max_levels) max_spec = max(list(levels)) min_spec = min(list(levels)) - if max_spec > max_levels: + if max_spec > max_levels: raise UtilitiesError("range ({},{}) specified for {} arg of tensor_power() " "exceeds max for items specified ({})". format(min_spec, max_spec + 1, repr('levels'), max_levels + 1)) diff --git a/psyneulink/library/components/mechanisms/modulatory/control/agt/agtcontrolmechanism.py b/psyneulink/library/components/mechanisms/modulatory/control/agt/agtcontrolmechanism.py index cf00c39ec9b..bc4123c431c 100644 --- a/psyneulink/library/components/mechanisms/modulatory/control/agt/agtcontrolmechanism.py +++ b/psyneulink/library/components/mechanisms/modulatory/control/agt/agtcontrolmechanism.py @@ -347,7 +347,7 @@ def short_term_bias(self, value): self.objective_mechanism.function.short_term_bias = value @property - def long_term_bias(self): + def long_term_bias(self): return self.objective_mechanism.function._long_term_bias @long_term_bias.setter @@ -355,7 +355,7 @@ def long_term_bias(self, value): self.objective_mechanism.function.long_term_bias = value @property - def short_term_rate(self): + def short_term_rate(self): return self.objective_mechanism.function._short_term_rate @short_term_rate.setter @@ -363,7 +363,7 @@ def short_term_rate(self, value): self.objective_mechanism.function.short_term_rate = value @property - def long_term_rate(self): + def long_term_rate(self): return self.objective_mechanism.function._long_term_rate @long_term_rate.setter diff --git a/setup.cfg b/setup.cfg index 825f9a8f220..b46fe443629 100644 --- a/setup.cfg +++ b/setup.cfg @@ -66,7 +66,7 @@ filterwarnings = [pycodestyle] # for code explanation see https://pep8.readthedocs.io/en/latest/intro.html#error-codes -ignore = E114,E115,E116,E117,E121,E122,E123,E124,E125,E126,E127,E128,E129,E131,E201,E202,E203,E221,E225,E231,E241,E251,E252,E261,E262,E265,E271,E301,E302,E303,E305,E306,E501,E711,E712,E713,E714,E721,E722,E731,E741,W503,W504,W605 +ignore = E114,E115,E116,E117,E121,E122,E123,E124,E125,E126,E127,E128,E129,E131,E201,E202,E203,E221,E225,E231,E241,E251,E252,E261,E262,E265,E301,E302,E303,E305,E306,E501,E711,E712,E713,E714,E721,E722,E731,E741,W503,W504,W605 exclude = .git/*,Scripts/*,__pytest__/*,docs/*,bin/* [pydocstyle] diff --git a/tests/composition/test_composition.py b/tests/composition/test_composition.py index 7cfd8e7342e..8eb24e76546 100644 --- a/tests/composition/test_composition.py +++ b/tests/composition/test_composition.py @@ -6456,7 +6456,7 @@ def test_three_node_cycle_with_FEEDBACK(self): assert set(comp.get_nodes_by_role(NodeRole.INTERNAL)) == {B} assert set(comp.get_nodes_by_role(NodeRole.FEEDBACK_RECEIVER)) == {A} - def test_branch(self): + def test_branch(self): a = TransferMechanism(default_variable=[0, 0]) b = TransferMechanism() c = TransferMechanism() From eadce9deb1d80e3a0bf793dfe685b353eb3508c7 Mon Sep 17 00:00:00 2001 From: Jan Vesely Date: Sat, 18 Jul 2020 20:08:45 -0400 Subject: [PATCH 07/13] codestyle: Fix and check E711; Comparison to None should be 'if cond is None:' Signed-off-by: Jan Vesely --- .../control/optimizationcontrolmechanism.py | 2 +- setup.cfg | 2 +- tests/composition/test_composition.py | 32 +++++++++---------- tests/composition/test_control.py | 2 +- tests/composition/test_runtime_params.py | 18 +++++------ 5 files changed, 28 insertions(+), 28 deletions(-) diff --git a/psyneulink/core/components/mechanisms/modulatory/control/optimizationcontrolmechanism.py b/psyneulink/core/components/mechanisms/modulatory/control/optimizationcontrolmechanism.py index 133dce6786e..e19e51b61aa 100644 --- a/psyneulink/core/components/mechanisms/modulatory/control/optimizationcontrolmechanism.py +++ b/psyneulink/core/components/mechanisms/modulatory/control/optimizationcontrolmechanism.py @@ -724,7 +724,7 @@ def __init__(self, """Implement OptimizationControlMechanism""" # If agent_rep hasn't been specified, put into deferred init - if agent_rep==None: + if agent_rep is None: if context.source==ContextFlags.COMMAND_LINE: # Temporarily name InputPort self._assign_deferred_init_name(self.__class__.__name__, context) diff --git a/setup.cfg b/setup.cfg index b46fe443629..fda34c8f352 100644 --- a/setup.cfg +++ b/setup.cfg @@ -66,7 +66,7 @@ filterwarnings = [pycodestyle] # for code explanation see https://pep8.readthedocs.io/en/latest/intro.html#error-codes -ignore = E114,E115,E116,E117,E121,E122,E123,E124,E125,E126,E127,E128,E129,E131,E201,E202,E203,E221,E225,E231,E241,E251,E252,E261,E262,E265,E301,E302,E303,E305,E306,E501,E711,E712,E713,E714,E721,E722,E731,E741,W503,W504,W605 +ignore = E114,E115,E116,E117,E121,E122,E123,E124,E125,E126,E127,E128,E129,E131,E201,E202,E203,E221,E225,E231,E241,E251,E252,E261,E262,E265,E301,E302,E303,E305,E306,E501,E712,E713,E714,E721,E722,E731,E741,W503,W504,W605 exclude = .git/*,Scripts/*,__pytest__/*,docs/*,bin/* [pydocstyle] diff --git a/tests/composition/test_composition.py b/tests/composition/test_composition.py index 8eb24e76546..129481848e7 100644 --- a/tests/composition/test_composition.py +++ b/tests/composition/test_composition.py @@ -90,7 +90,7 @@ def test_call_after_construction_with_no_arg_then_run_then_illegal_args_error(se B = ProcessingMechanism(function=Linear(slope=2)) C = ProcessingMechanism(function=Logistic) c = Composition(pathways=[[A],[B],[C]]) - assert c() == None + assert c() is None result = c(inputs={A:[[1],[100]],B:[[2],[200]],C:[[3],[1]]}) assert np.allclose(result, [[100],[400],[0.73105858]]) assert np.allclose(c(), [[100],[400],[0.73105858]]) @@ -103,7 +103,7 @@ def test_call_after_construction_with_learning_pathway(self): B = ProcessingMechanism(function=Linear(slope=0.5)) C = ProcessingMechanism(function=Logistic) c = Composition(pathways=[[A],{'LEARNING_PATHWAY':([B,C], BackPropagation)}]) - assert c() == None + assert c() is None # Run without learning result = c(inputs={A:[[1],[100]],B:[[2],[1]]}) @@ -505,13 +505,13 @@ def test_pathway_standalone_object(self): C = ProcessingMechanism(name='C') p = Pathway(pathway=[A,B,C], name='P') assert p.pathway == [A, B, C] - assert p.composition == None + assert p.composition is None assert p.name == 'P' - assert p.input == None - assert p.output == None - assert p.target == None - assert p.roles == None - assert p.learning_components == None + assert p.input is None + assert p.output is None + assert p.target is None + assert p.roles is None + assert p.learning_components is None def test_pathway_assign_composition_arg_error(self): c = Composition() @@ -530,7 +530,7 @@ def test_pathway_assign_roles_error(self): f"because it has not been assigned to a Composition" in str(error_text.value)) c.add_linear_processing_pathway(pathway=p) p_c = c.pathways[0] - assert p_c._assign_roles(composition=c) == None + assert p_c._assign_roles(composition=c) is None def test_pathway_illegal_arg_error(self): with pytest.raises(pnl.CompositionError) as error_text: @@ -556,13 +556,13 @@ def test_pathway_attributes(self): assert p1.name == 'P' assert p1.input == A assert p1.output == C - assert p1.target == None + assert p1.target is None assert p2.input == D - assert p2.output == None - assert p2.target == None - assert p3.input == None + assert p2.output is None + assert p2.target is None + assert p3.input is None assert p3.output == E - assert p3.target == None + assert p3.target is None assert l.name == 'L' assert l.input == F assert l.output == G @@ -6728,8 +6728,8 @@ def test_LEARNING_hebbian(self): A = RecurrentTransferMechanism(name='A', size=2, enable_learning=True) comp = Composition(pathways=A) pathway = comp.pathways[0] - assert pathway.target == None - assert pathway.learning_objective == None + assert pathway.target is None + assert pathway.learning_objective is None assert pathway.learning_components == {} roles = {NodeRole.INPUT, NodeRole.CYCLE, NodeRole.OUTPUT # , NodeRole.FEEDBACK_RECEIVER diff --git a/tests/composition/test_control.py b/tests/composition/test_control.py index a32b8ac1b3d..4fee4554a8d 100644 --- a/tests/composition/test_control.py +++ b/tests/composition/test_control.py @@ -365,7 +365,7 @@ def test_agent_rep_assignement_as_controller_and_replacement(self): comp.add_controller(new_ocm) assert comp.controller == new_ocm - assert old_ocm.composition == None + assert old_ocm.composition is None assert not any(pnl.SLOPE in p_name for p_name in comp.projections.names) assert any(pnl.INTERCEPT in p_name for p_name in comp.projections.names) diff --git a/tests/composition/test_runtime_params.py b/tests/composition/test_runtime_params.py index 978b46f24ce..56031412882 100644 --- a/tests/composition/test_runtime_params.py +++ b/tests/composition/test_runtime_params.py @@ -188,11 +188,11 @@ def test_input_port_param_no_condition(self): assert T2.parameter_ports['noise'].parameters.value.get(C) == 0.0 assert T2.function.intercept == 0.0 assert T2.function.parameters.intercept.get(C) == 0.0 - assert T2.input_port.weight == None + assert T2.input_port.weight is None assert T2.input_port.function.scale == 4.0 assert T2.input_port.function.parameters.scale.get(C) == 4.0 - assert T2.input_port.function.weights == None - assert T2.input_port.function.parameters.weights.get(C) == None + assert T2.input_port.function.weights is None + assert T2.input_port.function.parameters.weights.get(C) is None C.run(inputs={T1: 2.0}, ) assert C.results == [[[1201.5]], # (2*3*20*10)+1+0.5 @@ -372,11 +372,11 @@ def test_mechanism_params_with_combined_conditions_for_all_INPUT_PORT_PARAMS(sel assert T2.parameter_ports['noise'].parameters.value.get(C) == 0.0 assert T2.function.intercept == 0.0 assert T2.function.parameters.intercept.get(C) == 0.0 - assert T2.input_port.weight == None + assert T2.input_port.weight is None assert T2.input_port.function.scale == 4.0 assert T2.input_port.function.parameters.scale.get(C) == 4.0 - assert T2.input_port.function.weights == None - assert T2.input_port.function.parameters.weights.get(C) == None + assert T2.input_port.function.weights is None + assert T2.input_port.function.parameters.weights.get(C) is None # run again to insure restored default for noise after last run C.run(inputs={T1: 2.0}, ) @@ -466,11 +466,11 @@ def test_mechanism_params_with_combined_conditions_for_individual_INPUT_PORT_PAR assert T2.parameter_ports['noise'].parameters.value.get(C) == 0.0 assert T2.function.intercept == 0.0 assert T2.function.parameters.intercept.get(C) == 0.0 - assert T2.input_port.weight == None + assert T2.input_port.weight is None assert T2.input_port.function.scale == 4.0 assert T2.input_port.function.parameters.scale.get(C) == 4.0 - assert T2.input_port.function.weights == None - assert T2.input_port.function.parameters.weights.get(C) == None + assert T2.input_port.function.weights is None + assert T2.input_port.function.parameters.weights.get(C) is None # Final Run: insure restored default for noise after last run C.run(inputs={T1: 2.0}, ) From 1a7c60fc087871df0f4a76c5e3ba8b69dc5a5bb7 Mon Sep 17 00:00:00 2001 From: Jan Vesely Date: Sat, 18 Jul 2020 22:05:11 -0400 Subject: [PATCH 08/13] codestyle: Fix and check E713; Test for membership should be 'not in' Signed-off-by: Jan Vesely --- psyneulink/core/components/component.py | 6 ++--- .../functions/objectivefunctions.py | 2 +- .../components/functions/transferfunctions.py | 2 +- .../core/components/mechanisms/mechanism.py | 2 +- .../modulatory/learning/learningmechanism.py | 2 +- .../compositioninterfacemechanism.py | 4 ++-- .../processing/transfermechanism.py | 4 ++-- .../modulatorysignals/modulatorysignal.py | 2 +- .../core/components/ports/outputport.py | 2 +- .../core/components/ports/parameterport.py | 2 +- psyneulink/core/components/ports/port.py | 16 ++++++------- .../core/components/projections/projection.py | 8 +++---- psyneulink/core/compositions/composition.py | 24 +++++++++---------- psyneulink/core/compositions/showgraph.py | 10 ++++---- psyneulink/core/globals/log.py | 2 +- psyneulink/core/globals/utilities.py | 4 ++-- .../control/agt/lccontrolmechanism.py | 2 +- .../compositions/autodiffcomposition.py | 2 +- .../library/compositions/regressioncfa.py | 2 +- setup.cfg | 2 +- 20 files changed, 50 insertions(+), 50 deletions(-) diff --git a/psyneulink/core/components/component.py b/psyneulink/core/components/component.py index ef4eb719c5b..15574a034c2 100644 --- a/psyneulink/core/components/component.py +++ b/psyneulink/core/components/component.py @@ -1884,7 +1884,7 @@ def _initialize_parameters(self, context=None, **param_defaults): # assign defaults based on pass in params and class defaults defaults = { k: v for (k, v) in self.class_defaults.values(show_all=True).items() - if not k in alias_names + if k not in alias_names } if param_defaults is not None: @@ -2311,7 +2311,7 @@ def _validate_params(self, request_set, target_set=None, context=None): # setattr(self, "_"+param_name, param_value) # Check that param is in self.defaults (if not, it is assumed to be invalid for this object) - if not param_name in self.defaults.names(show_all=True): + if param_name not in self.defaults.names(show_all=True): continue # The default value of the param is None: suppress type checking @@ -2538,7 +2538,7 @@ def _get_param_value_for_modulatory_spec(self, param_name, param_value): else: raise ComponentError("PROGRAM ERROR: got {} instead of string, Component, or Class".format(param_value)) - if not param_spec in MODULATORY_SPEC_KEYWORDS: + if param_spec not in MODULATORY_SPEC_KEYWORDS: return(param_value) try: diff --git a/psyneulink/core/components/functions/objectivefunctions.py b/psyneulink/core/components/functions/objectivefunctions.py index 2cc9c80efe1..2767a9f7998 100644 --- a/psyneulink/core/components/functions/objectivefunctions.py +++ b/psyneulink/core/components/functions/objectivefunctions.py @@ -1194,7 +1194,7 @@ def _function(self, else: assert False, '{} not a recognized metric in {}'.format(self.metric, self.__class__.__name__) - if self.normalize and not self.metric in {MAX_ABS_DIFF, CORRELATION}: + if self.normalize and self.metric not in {MAX_ABS_DIFF, CORRELATION}: if self.metric == ENERGY: result /= len(v1) ** 2 else: diff --git a/psyneulink/core/components/functions/transferfunctions.py b/psyneulink/core/components/functions/transferfunctions.py index 132bdfb999d..2233d70da9e 100644 --- a/psyneulink/core/components/functions/transferfunctions.py +++ b/psyneulink/core/components/functions/transferfunctions.py @@ -4124,7 +4124,7 @@ def toggle_cost(self, cost_function_name:tc.any(str, CostFunctions), enabled_cost_functions = self.parameters.enabled_cost_functions.get(execution_context) if assignment: - if not cost_function_name in self.parameters.names(): + if cost_function_name not in self.parameters.names(): raise FunctionError("Unable to toggle {} ON as function assignment is \'None\'". format(cost_function_name)) if not enabled_cost_functions: diff --git a/psyneulink/core/components/mechanisms/mechanism.py b/psyneulink/core/components/mechanisms/mechanism.py index eee27d8b7c3..bc44609307d 100644 --- a/psyneulink/core/components/mechanisms/mechanism.py +++ b/psyneulink/core/components/mechanisms/mechanism.py @@ -3746,7 +3746,7 @@ def _get_standardized_label_dict(self, label_type): i = ports[k].position_in_mechanism _label_dict[i] = v else: - if not 0 in _label_dict: + if 0 not in _label_dict: _label_dict[0] = {} _label_dict[0].update({k:v}) return _label_dict diff --git a/psyneulink/core/components/mechanisms/modulatory/learning/learningmechanism.py b/psyneulink/core/components/mechanisms/modulatory/learning/learningmechanism.py index 0fc87b83fad..65aea8c3f03 100644 --- a/psyneulink/core/components/mechanisms/modulatory/learning/learningmechanism.py +++ b/psyneulink/core/components/mechanisms/modulatory/learning/learningmechanism.py @@ -1160,7 +1160,7 @@ def _validate_params(self, request_set, target_set=None, context=None): for error_source in error_sources: if (not isinstance(error_source, (ObjectiveMechanism, LearningMechanism, OutputPort)) or (isinstance(error_source, OutputPort) - and not error_source in error_source.owner.output_ports[ERROR_SIGNAL])): + and error_source not in error_source.owner.output_ports[ERROR_SIGNAL])): raise LearningMechanismError(f"{repr(ERROR_SOURCES)} arg for {self.name} ({error_source}) " f"must be an {ObjectiveMechanism.__name__}, " f"another {LearningMechanism.__name__}, an {repr(ERROR_SIGNAL)} " diff --git a/psyneulink/core/components/mechanisms/processing/compositioninterfacemechanism.py b/psyneulink/core/components/mechanisms/processing/compositioninterfacemechanism.py index ddd4ffb0dc9..f3ed4b029e5 100644 --- a/psyneulink/core/components/mechanisms/processing/compositioninterfacemechanism.py +++ b/psyneulink/core/components/mechanisms/processing/compositioninterfacemechanism.py @@ -167,11 +167,11 @@ def remove_ports(self, ports, context=None): super(CompositionInterfaceMechanism, self).remove_ports(ports, context) input_ports_marked_for_deletion = set() for port in self.user_added_ports[INPUT_PORTS]: - if not port in self.input_ports: + if port not in self.input_ports: input_ports_marked_for_deletion.add(port) self.user_added_ports[INPUT_PORTS] = self.user_added_ports[INPUT_PORTS] - input_ports_marked_for_deletion output_ports_marked_for_deletion = set() for port in self.user_added_ports[OUTPUT_PORTS]: - if not port in self.output_ports: + if port not in self.output_ports: output_ports_marked_for_deletion.add(port) self.user_added_ports[OUTPUT_PORTS] = self.user_added_ports[OUTPUT_PORTS] - output_ports_marked_for_deletion diff --git a/psyneulink/core/components/mechanisms/processing/transfermechanism.py b/psyneulink/core/components/mechanisms/processing/transfermechanism.py index f18359397ad..69f11ffb6f6 100644 --- a/psyneulink/core/components/mechanisms/processing/transfermechanism.py +++ b/psyneulink/core/components/mechanisms/processing/transfermechanism.py @@ -1102,8 +1102,8 @@ def _validate_termination_threshold(self, termination_threshold): return 'must be a float or int.' def _validate_termination_comparison_op(self, termination_comparison_op): - if (not termination_comparison_op in comparison_operators.keys() - and not termination_comparison_op in comparison_operators.values()): + if (termination_comparison_op not in comparison_operators.keys() + and termination_comparison_op not in comparison_operators.values()): return f"must be boolean comparison operator or one of the following strings:" \ f" {','.join(comparison_operators.keys())}." diff --git a/psyneulink/core/components/ports/modulatorysignals/modulatorysignal.py b/psyneulink/core/components/ports/modulatorysignals/modulatorysignal.py index 450fb677202..cab9788a25c 100644 --- a/psyneulink/core/components/ports/modulatorysignals/modulatorysignal.py +++ b/psyneulink/core/components/ports/modulatorysignals/modulatorysignal.py @@ -625,7 +625,7 @@ def _instantiate_attributes_after_function(self, context=None): if self.owner and self.modulation is None: self.modulation = self.owner.modulation if self.modulation is not None: - if not self.modulation in modulation_type_keywords: + if self.modulation not in modulation_type_keywords: try: getattr(self.function.parameters, self.modulation) except: diff --git a/psyneulink/core/components/ports/outputport.py b/psyneulink/core/components/ports/outputport.py index 5fef880dad1..2b2d7d299d1 100644 --- a/psyneulink/core/components/ports/outputport.py +++ b/psyneulink/core/components/ports/outputport.py @@ -1027,7 +1027,7 @@ def _instantiate_projections(self, projections, context=None): self._instantiate_projections_to_port(projections=modulatory_projections, context=context) # Treat all remaining specifications in projections as ones for outgoing MappingProjections - pathway_projections = [proj for proj in projections if not proj in modulatory_projections] + pathway_projections = [proj for proj in projections if proj not in modulatory_projections] for proj in pathway_projections: self._instantiate_projection_from_port(projection_spec=MappingProjection, receiver=proj, diff --git a/psyneulink/core/components/ports/parameterport.py b/psyneulink/core/components/ports/parameterport.py index 74343a8bab1..b593416dff0 100644 --- a/psyneulink/core/components/ports/parameterport.py +++ b/psyneulink/core/components/ports/parameterport.py @@ -1089,7 +1089,7 @@ def _get_parameter_port(sender_owner, sender_type, param_name, component): "of {} or its function" .format(param_name, sender_type, sender_owner.name, component)) # Check that the Mechanism has a ParameterPort for the param - if not param_name in component._parameter_ports.names: + if param_name not in component._parameter_ports.names: raise ParameterPortError("There is no ParameterPort for the parameter ({}) of {} " "specified in {} for {}". format(param_name, component.name, sender_type, sender_owner.name)) diff --git a/psyneulink/core/components/ports/port.py b/psyneulink/core/components/ports/port.py index d7432cc5a45..bd6094ca243 100644 --- a/psyneulink/core/components/ports/port.py +++ b/psyneulink/core/components/ports/port.py @@ -1477,7 +1477,7 @@ def _instantiate_projections_to_port(self, projections, context=None): continue # reassign default variable shape to this port and its function - if isinstance(projection, PathwayProjection_Base) and not projection in self.path_afferents: + if isinstance(projection, PathwayProjection_Base) and projection not in self.path_afferents: projs = self.path_afferents variable = self.defaults.variable projs.append(projection) @@ -1515,7 +1515,7 @@ def _instantiate_projections_to_port(self, projections, context=None): # f'unexpected results may occur when the {Mechanism.__name__} ' \ # f'or {Composition.__name__} to which it belongs is executed.') - elif isinstance(projection, ModulatoryProjection_Base) and not projection in self.mod_afferents: + elif isinstance(projection, ModulatoryProjection_Base) and projection not in self.mod_afferents: self.mod_afferents.append(projection) new_projections.append(projection) @@ -2567,7 +2567,7 @@ def _instantiate_port(port_type:_is_port_class, # Port's type if not port._init_args[OWNER]: port._init_args[OWNER] = owner # If variable was not specified by user or Port's constructor: - if not VARIABLE in port._init_args or port._init_args[VARIABLE] is None: + if VARIABLE not in port._init_args or port._init_args[VARIABLE] is None: # If call to _instantiate_port specified variable, use that if variable is not None: port._init_args[VARIABLE] = variable @@ -3077,7 +3077,7 @@ def _parse_port_spec(port_type=None, # MECHANISM: , :[, ...]} if MECHANISM in port_specific_args: - if not PROJECTIONS in params: + if PROJECTIONS not in params: if NAME in spec: # substitute into tuple spec params[PROJECTIONS] = (spec[NAME], params[MECHANISM]) @@ -3107,7 +3107,7 @@ def _parse_port_spec(port_type=None, port_attr = getattr(mech, PORTS) port = port_attr[port] except: - name = owner.name if not 'unnamed' in owner.name else 'a ' + owner.__class__.__name__ + name = owner.name if 'unnamed' not in owner.name else 'a ' + owner.__class__.__name__ raise PortError("Unrecognized name ({}) for {} " "of {} in specification of {} " "for {}".format(port, @@ -3131,7 +3131,7 @@ def _parse_port_spec(port_type=None, # FIX: REGARDING WHAT IS IN port_specific_args VS params (see REF_VAL_NAME BRANCH) # FIX: ALSO, ??DOES PROJECTIONS ENTRY BELONG IN param OR port_dict? # Check for single unrecognized key in params, used for {:[,...]} format - unrecognized_keys = [key for key in port_specific_args if not key in port_type.portAttributes] + unrecognized_keys = [key for key in port_specific_args if key not in port_type.portAttributes] if unrecognized_keys: if len(unrecognized_keys)==1: key = unrecognized_keys[0] @@ -3310,7 +3310,7 @@ def _get_port_for_socket(owner, if _is_projection_spec(port_spec): # These specifications require that a particular Port be specified to assign its default Projection type - if ((is_matrix(port_spec) or (isinstance(port_spec, dict) and not PROJECTION_TYPE in port_spec))): + if ((is_matrix(port_spec) or (isinstance(port_spec, dict) and PROJECTION_TYPE not in port_spec))): for st in port_types: try: proj_spec = _parse_projection_spec(port_spec, owner=owner, port_type=st) @@ -3390,7 +3390,7 @@ def _get_port_for_socket(owner, port = port_type._get_primary_port(port_type, port_spec) # Primary Port for Mechanism specified in port_spec is not compatible # with owner's Port for which a connection is being specified - if not port.__class__.__name__ in connectee_port_type.connectsWith: + if port.__class__.__name__ not in connectee_port_type.connectsWith: from psyneulink.core.components.projections.projection import ProjectionError raise ProjectionError(f"Primary {port_type.__name__} of {port_spec.name} ({port.name}) cannot be " f"used " diff --git a/psyneulink/core/components/projections/projection.py b/psyneulink/core/components/projections/projection.py index 42f0741492c..b20e6be668d 100644 --- a/psyneulink/core/components/projections/projection.py +++ b/psyneulink/core/components/projections/projection.py @@ -1192,7 +1192,7 @@ def _parse_projection_spec(projection_spec, Otherwise, return Projection specification dictionary using any arguments provided as defaults """ - bad_arg = next((key for key in kwargs if not key in PROJECTION_ARGS), None) + bad_arg = next((key for key in kwargs if key not in PROJECTION_ARGS), None) if bad_arg: raise ProjectionError("Illegal argument in call to _parse_port_spec: {}".format(bad_arg)) @@ -1464,11 +1464,11 @@ def _parse_connection_specs(connectee_port_type, # Add default WEIGHT, EXPONENT, and/or PROJECTION specification for any that are not aleady in the dict # (used as the default values for all the Ports of all Mechanisms specified for this dict; # can use different dicts to implement different sets of defaults for the Ports of diff Mechanisms) - if not WEIGHT in connection: + if WEIGHT not in connection: connection[WEIGHT] = DEFAULT_WEIGHT - if not EXPONENT in connection: + if EXPONENT not in connection: connection[EXPONENT] = DEFAULT_EXPONENT - if not PROJECTION in connection: + if PROJECTION not in connection: connection[PROJECTION] = DEFAULT_PROJECTION # Now process each entry that has *PORTS* or a Mechanism as its key diff --git a/psyneulink/core/compositions/composition.py b/psyneulink/core/compositions/composition.py index cdb5b0e6689..2ff464d9d68 100644 --- a/psyneulink/core/compositions/composition.py +++ b/psyneulink/core/compositions/composition.py @@ -4349,7 +4349,7 @@ def _get_external_modulatory_projections(self): sender = comp_projection.sender.owner receiver = comp_projection.receiver route_projection_through_pcim = False - if not sender in self.nodes \ + if sender not in self.nodes \ and not (hasattr(sender, 'composition') and sender.composition == self): connections = [v for k, v in receiver._afferents_info.items()] for i in connections: @@ -4578,7 +4578,7 @@ def _create_CIM_ports(self, context=None): receiver = comp_projection.receiver # the mechanism that owns the port for which the projection is an afferent owner = receiver.owner - if not receiver in self.parameter_CIM_ports: + if receiver not in self.parameter_CIM_ports: # control signal modulation should match the modulation type of the original control signal modulation = comp_projection.sender.modulation # input port of parameter CIM that will receive projection from the original control signal @@ -4788,7 +4788,7 @@ def _update_shadows_dict(self, node): if owner in nested_nodes: owner = nested_nodes[owner] if node is self.controller and self._controller_initialization_status == ContextFlags.DEFERRED_INIT: - if not owner in self.nodes: + if owner not in self.nodes: continue if node not in self.shadows[owner]: self.shadows[owner].append(node) @@ -7030,7 +7030,7 @@ def add_controller(self, controller:ControlMechanism): except DuplicateProjectionError: continue for proj in input_port.path_afferents: - if not proj.sender.owner in nested_cims: + if proj.sender.owner not in nested_cims: proj._activate_for_compositions(self) # Check whether controller has input, and if not then disable @@ -7110,14 +7110,14 @@ def _build_predicted_inputs_dict(self, predicted_input): if hasattr(input_port, SHADOW_INPUTS) and input_port.shadow_inputs is not None: owner = input_port.shadow_inputs.owner if self._controller_initialization_status == ContextFlags.DEFERRED_INIT \ - and not owner in nested_nodes\ - and not owner in self.nodes: + and owner not in nested_nodes \ + and owner not in self.nodes: continue - if not owner in nested_nodes: + if owner not in nested_nodes: inputs[input_port.shadow_inputs.owner] = predicted_input[j] else: comp = nested_nodes[owner] - if not comp in inputs: + if comp not in inputs: inputs[comp]=[[predicted_input[j]]] else: inputs[comp]=np.concatenate([[predicted_input[j]],inputs[comp][0]]) @@ -7704,8 +7704,8 @@ def _parse_labels(self, inputs, mech=None): target_to_output = {path.target: path.output for path in self.pathways if 'LEARNING' in [role.name for role in path.roles]} if mech: target_nodes_of_learning_pathways = [path.target for path in self.pathways] - label_type = INPUT if not mech in target_nodes_of_learning_pathways else OUTPUT - label_mech = mech if not mech in target_to_output else target_to_output[mech] + label_type = INPUT if mech not in target_nodes_of_learning_pathways else OUTPUT + label_mech = mech if mech not in target_to_output else target_to_output[mech] labels = label_mech._get_standardized_label_dict(label_type) if type(inputs) == dict: _inputs = {} @@ -7766,7 +7766,7 @@ def _validate_input_dict_node_roles(self, inputs): # STEP 1A: Check that all of the nodes listed in the inputs dict are INPUT nodes in the composition input_nodes = self.get_nodes_by_role(NodeRole.INPUT) for node in inputs.keys(): - if not node in input_nodes: + if node not in input_nodes: if not isinstance(node, (Mechanism, Composition)): raise CompositionError(f'{node} in "inputs" dict for {self.name} is not a ' f'{Mechanism.__name__} or {Composition.__name__}.') @@ -7775,7 +7775,7 @@ def _validate_input_dict_node_roles(self, inputs): # STEP 1B: Check that all of the INPUT nodes are represented - if not, use default_external_input_values for node in input_nodes: - if not node in inputs: + if node not in inputs: inputs[node] = node.default_external_input_values return inputs diff --git a/psyneulink/core/compositions/showgraph.py b/psyneulink/core/compositions/showgraph.py index c0479ce3dc9..f4d66ea3831 100644 --- a/psyneulink/core/compositions/showgraph.py +++ b/psyneulink/core/compositions/showgraph.py @@ -1201,9 +1201,9 @@ def _render_projection(_g, proj, sndr_label, rcvr_label, # Validate the Projection is to an INPUT node or a node that is shadowing one if ((rcvr_input_node_proj_owner in composition.nodes_to_roles and - not NodeRole.INPUT in composition.nodes_to_roles[rcvr_input_node_proj_owner]) + NodeRole.INPUT not in composition.nodes_to_roles[rcvr_input_node_proj_owner]) and (proj.receiver.shadow_inputs in composition.nodes_to_roles and - not NodeRole.INPUT in composition.nodes_to_roles[proj.receiver.shadow_inputs])): + NodeRole.INPUT not in composition.nodes_to_roles[proj.receiver.shadow_inputs])): raise ShowGraphError(f"Projection from input_CIM of {composition.name} to node " f"{rcvr_input_node_proj_owner} that is not an " f"{NodeRole.INPUT.name} node or shadowing its " @@ -1346,7 +1346,7 @@ def _render_projection(_g, proj, sndr_label, rcvr_label, sndr_output_node_proj_owner = sndr_output_node_proj.owner # Validate the Projection is from an OUTPUT node if ((sndr_output_node_proj_owner in composition.nodes_to_roles and - not NodeRole.OUTPUT in composition.nodes_to_roles[sndr_output_node_proj_owner])): + NodeRole.OUTPUT not in composition.nodes_to_roles[sndr_output_node_proj_owner])): raise ShowGraphError(f"Projection to output_CIM of {composition.name} " f"from node {sndr_output_node_proj_owner} that is not " f"an {NodeRole.OUTPUT} node.") @@ -2155,7 +2155,7 @@ def get_index_of_node_in_G_body(node, node_type:tc.enum(MECHANISM, PROJECTION, C if ((quoted_items and node.name == quoted_items[0]) or (node.name + ' [' in item)) and node_type in {MECHANISM, PROJECTION}: if node_type in {MECHANISM}: - if not '->' in item: + if '->' not in item: return i elif node_type in {PROJECTION}: if '->' in item: @@ -2328,7 +2328,7 @@ def _set_up_animation(self, context): composition._animation_directory = composition._animate.pop(MOVIE_DIR, default_dir) composition._save_images = composition._animate.pop(SAVE_IMAGES, False) composition._show_animation = composition._animate.pop(SHOW, False) - if not composition._animate_unit in {COMPONENT, EXECUTION_SET}: + if composition._animate_unit not in {COMPONENT, EXECUTION_SET}: raise ShowGraphError(f"{repr(UNIT)} entry of {repr('animate')} argument for {composition.name} method " f"of {repr('run')} ({composition._animate_unit}) " f"must be {repr(COMPONENT)} or {repr(EXECUTION_SET)}.") diff --git a/psyneulink/core/globals/log.py b/psyneulink/core/globals/log.py index 901d5c8aa3d..3552d02e8f0 100644 --- a/psyneulink/core/globals/log.py +++ b/psyneulink/core/globals/log.py @@ -805,7 +805,7 @@ def assign_log_condition(item, level): levels |= l level = levels - if not item in self.loggable_items: + if item not in self.loggable_items: # KDM 8/13/18: NOTE: add_entries is not defined anywhere raise LogError("\'{0}\' is not a loggable item for {1} (try using \'{1}.log.add_entries()\')". format(item, self.owner.name)) diff --git a/psyneulink/core/globals/utilities.py b/psyneulink/core/globals/utilities.py index e6b71b47259..9ff2729f9e6 100644 --- a/psyneulink/core/globals/utilities.py +++ b/psyneulink/core/globals/utilities.py @@ -609,7 +609,7 @@ def tensor_power(items, levels:tc.optional(range)=None, flat=False): pp = [] for s in ps: order = len(s) - if not order in list(levels): + if order not in list(levels): continue if order==1: pp.append(np.array(s[0])) @@ -1011,7 +1011,7 @@ def popitem(self): raise UtilitiesError("{} is read-only".format(self.name)) def __additem__(self, key, value): self.data[key] = value - if not key in self._ordered_keys: + if key not in self._ordered_keys: self._ordered_keys.append(key) def __deleteitem__(self, key): del self.data[key] diff --git a/psyneulink/library/components/mechanisms/modulatory/control/agt/lccontrolmechanism.py b/psyneulink/library/components/mechanisms/modulatory/control/agt/lccontrolmechanism.py index 3dee5710079..262e07b14c8 100644 --- a/psyneulink/library/components/mechanisms/modulatory/control/agt/lccontrolmechanism.py +++ b/psyneulink/library/components/mechanisms/modulatory/control/agt/lccontrolmechanism.py @@ -923,7 +923,7 @@ def remove_modulated_mechanisms(self, mechanisms:list): """ for mech in mechanisms: - if not mech in self.modulated_mechanisms: + if mech not in self.modulated_mechanisms: continue parameter_port = mech._parameter_ports[mech.multiplicative_param] diff --git a/psyneulink/library/compositions/autodiffcomposition.py b/psyneulink/library/compositions/autodiffcomposition.py index 6c3107b1937..f7b855ae5ce 100644 --- a/psyneulink/library/compositions/autodiffcomposition.py +++ b/psyneulink/library/compositions/autodiffcomposition.py @@ -447,7 +447,7 @@ def _infer_input_nodes(self, nodes: dict): """ ret = {} for node, values in nodes.items(): - if NodeRole.INPUT in self.get_roles_by_node(node) and not NodeRole.TARGET in self.get_roles_by_node(node): + if NodeRole.INPUT in self.get_roles_by_node(node) and NodeRole.TARGET not in self.get_roles_by_node(node): ret[node] = values return ret diff --git a/psyneulink/library/compositions/regressioncfa.py b/psyneulink/library/compositions/regressioncfa.py index b9d44bf07a3..5387069a634 100644 --- a/psyneulink/library/compositions/regressioncfa.py +++ b/psyneulink/library/compositions/regressioncfa.py @@ -273,7 +273,7 @@ def _instantiate_prediction_terms(self, prediction_terms): self.prediction_terms.append(PV[term.name]) # MODIFIED 11/9/18 END for term in self.prediction_terms: - if not term in PV: + if term not in PV: raise RegressionCFAError("{} specified in {} arg of {} is not a member of the {} enum". format(repr(term.name),repr(PREDICTION_TERMS), self.__class__.__name__, PV.__name__)) diff --git a/setup.cfg b/setup.cfg index fda34c8f352..e0980022cca 100644 --- a/setup.cfg +++ b/setup.cfg @@ -66,7 +66,7 @@ filterwarnings = [pycodestyle] # for code explanation see https://pep8.readthedocs.io/en/latest/intro.html#error-codes -ignore = E114,E115,E116,E117,E121,E122,E123,E124,E125,E126,E127,E128,E129,E131,E201,E202,E203,E221,E225,E231,E241,E251,E252,E261,E262,E265,E301,E302,E303,E305,E306,E501,E712,E713,E714,E721,E722,E731,E741,W503,W504,W605 +ignore = E114,E115,E116,E117,E121,E122,E123,E124,E125,E126,E127,E128,E129,E131,E201,E202,E203,E221,E225,E231,E241,E251,E252,E261,E262,E265,E301,E302,E303,E305,E306,E501,E712,E714,E721,E722,E731,E741,W503,W504,W605 exclude = .git/*,Scripts/*,__pytest__/*,docs/*,bin/* [pydocstyle] From 1d409bff14ec474350a861be39bdabbc9f52c213 Mon Sep 17 00:00:00 2001 From: Jan Vesely Date: Sun, 5 Jul 2020 00:00:17 -0400 Subject: [PATCH 09/13] codestyle: Fix and check E714; Test for object identity should be 'is not' Signed-off-by: Jan Vesely --- psyneulink/core/components/ports/port.py | 4 ++-- psyneulink/core/compositions/composition.py | 4 ++-- psyneulink/core/compositions/showgraph.py | 8 ++++---- psyneulink/core/globals/preferences/preferenceset.py | 2 +- setup.cfg | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/psyneulink/core/components/ports/port.py b/psyneulink/core/components/ports/port.py index bd6094ca243..b333db50e02 100644 --- a/psyneulink/core/components/ports/port.py +++ b/psyneulink/core/components/ports/port.py @@ -1701,7 +1701,7 @@ def _get_receiver_port(spec): # Validate that receiver and projection_spec receiver are now the same receiver = proj_recvr or receiver # If receiver was not specified, assign it receiver from projection_spec - if proj_recvr and receiver and not proj_recvr is receiver: + if proj_recvr and receiver and proj_recvr is not receiver: # Note: if proj_recvr is None, it will be assigned under handling of deferred_init below raise PortError("Receiver ({}) specified for Projection ({}) " "is not the same as the one specified in {} ({})". @@ -2606,7 +2606,7 @@ def _instantiate_port(port_type:_is_port_class, # Port's type format(port.name, port.value, REFERENCE_VALUE, reference_value, owner.name)) # Port has already been assigned to an owner - if port.owner is not None and not port.owner is owner: + if port.owner is not None and port.owner is not owner: raise PortError("Port {} does not belong to the owner for which it is specified ({})". format(port.name, owner.name)) return port diff --git a/psyneulink/core/compositions/composition.py b/psyneulink/core/compositions/composition.py index 2ff464d9d68..55b0de62cb7 100644 --- a/psyneulink/core/compositions/composition.py +++ b/psyneulink/core/compositions/composition.py @@ -4028,7 +4028,7 @@ def _determine_origin_and_terminal_nodes_from_consideration_queue(self): # consideration set. Identifying these assumes that graph_processing has been called/updated, # which identifies and "breaks" cycles, and assigns FEEDBACK_SENDER to the appropriate consideration set(s). for node in self.nodes: - if not any([efferent for efferent in node.efferents if not efferent.receiver.owner is self.output_CIM]): + if not any([efferent for efferent in node.efferents if efferent.receiver.owner is not self.output_CIM]): self._add_node_role(node, NodeRole.TERMINAL) def _determine_node_roles(self, context=None): @@ -7600,7 +7600,7 @@ def _validate_input_shapes(self, inputs): # see if the entire stimulus set provided is a valid input for the node (i.e. in the case of a call with a # single trial of provided input) node_input = self._validate_single_input(node, stimulus) - if not node_input is None: + if node_input is not None: node_input = [node_input] else: # if node_input is None, it means there are multiple trials of input in the stimulus set, so loop diff --git a/psyneulink/core/compositions/showgraph.py b/psyneulink/core/compositions/showgraph.py index f4d66ea3831..182e32fbb84 100644 --- a/psyneulink/core/compositions/showgraph.py +++ b/psyneulink/core/compositions/showgraph.py @@ -1190,7 +1190,7 @@ def _render_projection(_g, proj, sndr_label, rcvr_label, # Get label for Node that receives the input (rcvr_label) rcvr_input_node_proj = proj.receiver if (isinstance(rcvr_input_node_proj.owner, CompositionInterfaceMechanism) - and not show_nested is NESTED): + and show_nested is not NESTED): rcvr_input_node_proj_owner = rcvr_input_node_proj.owner.composition else: rcvr_input_node_proj_owner = rcvr_input_node_proj.owner @@ -1288,7 +1288,7 @@ def _render_projection(_g, proj, sndr_label, rcvr_label, # Get label for Node that receives modulation (modulated_mech_label) rcvr_modulated_mech_proj = proj.receiver if (isinstance(rcvr_modulated_mech_proj.owner, CompositionInterfaceMechanism) - and not show_nested is NESTED): + and show_nested is not NESTED): rcvr_modulated_mech_proj_owner = rcvr_modulated_mech_proj.owner.composition else: rcvr_modulated_mech_proj_owner = rcvr_modulated_mech_proj.owner @@ -1305,7 +1305,7 @@ def _render_projection(_g, proj, sndr_label, rcvr_label, # Get label for CIM's port as edge's sender sndr_param_cim_proj_label = f"{cim_label}:{OutputPort.__name__}-{proj.sender.name}" if (isinstance(rcvr_modulated_mech_proj_owner, Composition) - and not show_nested is not NESTED): + and show_nested is NESTED): rcvr_modulated_mec_proj_label = rcvr_label else: # Need to use direct reference to proj.receiver rather than rcvr_modulated_mech_proj @@ -1340,7 +1340,7 @@ def _render_projection(_g, proj, sndr_label, rcvr_label, sndr_output_node_proj = proj.sender if (isinstance(sndr_output_node_proj.owner, CompositionInterfaceMechanism) - and not show_nested is NESTED): + and show_nested is not NESTED): sndr_output_node_proj_owner = sndr_output_node_proj.owner.composition else: sndr_output_node_proj_owner = sndr_output_node_proj.owner diff --git a/psyneulink/core/globals/preferences/preferenceset.py b/psyneulink/core/globals/preferences/preferenceset.py index 37b80e1a274..f5606a9d066 100644 --- a/psyneulink/core/globals/preferences/preferenceset.py +++ b/psyneulink/core/globals/preferences/preferenceset.py @@ -610,7 +610,7 @@ def validate_log(self, candidate_log_item, pref_set): # * this prevents use of LogEntry attributes not recognized by, or having different values from # the LogEntry class in the owner object's module if (not pref_set.owner.name == DEFAULT_PREFERENCE_SET_OWNER and - not candidate_log_class.__module__ is pref_set.owner.__module__): + candidate_log_class.__module__ is not pref_set.owner.__module__): raise PreferenceSetError("Attempt to assign logPref setting for {0} using value ({1}) from LogEntry" " in {2} which is different than the one defined in Globals.Log" " or the module ({3}) in which the class of {0} ({4}) was declared". diff --git a/setup.cfg b/setup.cfg index e0980022cca..cfd05bd17ef 100644 --- a/setup.cfg +++ b/setup.cfg @@ -66,7 +66,7 @@ filterwarnings = [pycodestyle] # for code explanation see https://pep8.readthedocs.io/en/latest/intro.html#error-codes -ignore = E114,E115,E116,E117,E121,E122,E123,E124,E125,E126,E127,E128,E129,E131,E201,E202,E203,E221,E225,E231,E241,E251,E252,E261,E262,E265,E301,E302,E303,E305,E306,E501,E712,E714,E721,E722,E731,E741,W503,W504,W605 +ignore = E114,E115,E116,E117,E121,E122,E123,E124,E125,E126,E127,E128,E129,E131,E201,E202,E203,E221,E225,E231,E241,E251,E252,E261,E262,E265,E301,E302,E303,E305,E306,E501,E712,E721,E722,E731,E741,W503,W504,W605 exclude = .git/*,Scripts/*,__pytest__/*,docs/*,bin/* [pydocstyle] From a2be7e0b0cc7d6303857a7d3ce9d0dae7a668536 Mon Sep 17 00:00:00 2001 From: Jan Vesely Date: Mon, 20 Jul 2020 18:25:39 -0400 Subject: [PATCH 10/13] codestyle: Fixup new E713 violations; Test for membership should be 'not in' Signed-off-by: Jan Vesely --- psyneulink/core/compositions/composition.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/psyneulink/core/compositions/composition.py b/psyneulink/core/compositions/composition.py index a34a446d6f5..fefebb4d898 100644 --- a/psyneulink/core/compositions/composition.py +++ b/psyneulink/core/compositions/composition.py @@ -4866,7 +4866,7 @@ def _route_control_projection_through_intermediary_pcims(self, projection, sende modulates=receiver, name=PARAMETER_CIM_NAME + "_" + receiver.owner.name + "_" + receiver.name, ) - if not receiver.owner in graph_receiver.nodes.data + graph_receiver.cims: + if receiver.owner not in graph_receiver.nodes.data + graph_receiver.cims: receiver = interface_input_port graph_receiver.parameter_CIM.add_ports([control_signal], context=context) # add sender and receiver to self.parameter_CIM_ports dict @@ -5072,7 +5072,7 @@ def add_projection(self, self._parse_receiver_spec(projection, receiver, sender, learning_projection) if (isinstance(receiver_mechanism, (CompositionInterfaceMechanism)) - and not receiver_input_port.owner in self.nodes + and receiver_input_port.owner not in self.nodes and receiver.componentType == 'ParameterPort'): # unlike when projecting to nested InputPorts, we don't know for sure whether # intermediary pcims will have input ports that correspond to the ParameterPorts we are interested @@ -7039,7 +7039,7 @@ def _get_deeply_nested_aux_projections(self, node): aux_projections[i] = i nested_nodes = self._get_nested_nodes() for spec, proj in aux_projections.items(): - if not proj.receiver.owner in self.nodes and \ + if proj.receiver.owner not in self.nodes and \ proj.receiver.owner in [i[0] for i in nested_nodes if not i[1] in self.nodes]: deeply_nested_projections[spec] = proj return deeply_nested_projections @@ -7246,7 +7246,7 @@ def _build_predicted_inputs_dict(self, predicted_input): and owner not in nested_nodes \ and owner not in self.nodes: continue - if not owner in nested_nodes: + if owner not in nested_nodes: shadow_input_owner = input_port.shadow_inputs.owner if isinstance(shadow_input_owner, CompositionInterfaceMechanism): shadow_input_owner = shadow_input_owner.composition From 07af71504a31b57944a0fc743bc6e6bf17c3fef8 Mon Sep 17 00:00:00 2001 From: Katherine Mantel Date: Fri, 17 Jul 2020 21:51:14 -0400 Subject: [PATCH 11/13] Parameters: _user_specified: fix unspecified alias overriding specified source --- psyneulink/core/components/component.py | 33 +++++++++++-------------- tests/misc/test_parameters.py | 14 +++++++++++ 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/psyneulink/core/components/component.py b/psyneulink/core/components/component.py index 15574a034c2..fe6cbd8ae2b 100644 --- a/psyneulink/core/components/component.py +++ b/psyneulink/core/components/component.py @@ -1945,25 +1945,22 @@ def _is_user_specified(parameter): and param_defaults[parameter.name] is not None ) - for p in self.parameters: - p._user_specified = _is_user_specified(p) - - if isinstance(p, ParameterAlias): - if p._user_specified: - if _is_user_specified(p.source): - if param_defaults[p.name] is not param_defaults[p.source.name]: - raise ComponentError( - f"Multiple values ({p.name}: {param_defaults[p.name]}" - f"\t{p.source.name}: {param_defaults[p.source.name]} " - f"assigned to identical Parameters. {p.name} is an alias " - f"of {p.source.name}", - component=self, - ) - - else: - param_defaults[p.source.name] = param_defaults[p.name] + for p in filter(lambda x: isinstance(x, ParameterAlias), self.parameters): + if _is_user_specified(p): + if _is_user_specified(p.source): + if param_defaults[p.name] is not param_defaults[p.source.name]: + raise ComponentError( + f"Multiple values ({p.name}: {param_defaults[p.name]}" + f"\t{p.source.name}: {param_defaults[p.source.name]} " + f"assigned to identical Parameters. {p.name} is an alias " + f"of {p.source.name}", + component=self, + ) + else: + param_defaults[p.source.name] = param_defaults[p.name] - continue + for p in filter(lambda x: not isinstance(x, ParameterAlias), self.parameters): + p._user_specified = _is_user_specified(p) # copy spec so it is not overwritten later # TODO: check if this is necessary diff --git a/tests/misc/test_parameters.py b/tests/misc/test_parameters.py index 24e6f839767..00d44db6f01 100644 --- a/tests/misc/test_parameters.py +++ b/tests/misc/test_parameters.py @@ -226,3 +226,17 @@ def test_copy(): assert isinstance(g.parameters.additive_param, pnl.ParameterAlias) assert g.parameters.additive_param.source is g.parameters.intercept + + +@pytest.mark.parametrize( + 'cls_, kwargs, parameter, is_user_specified', + [ + (pnl.AdaptiveIntegrator, {'rate': None}, 'rate', False), + (pnl.AdaptiveIntegrator, {'rate': None}, 'multiplicative_param', False), + (pnl.AdaptiveIntegrator, {'rate': 0.5}, 'rate', True), + (pnl.AdaptiveIntegrator, {'rate': 0.5}, 'multiplicative_param', True), + ] +) +def test_user_specified(cls_, kwargs, parameter, is_user_specified): + c = cls_(**kwargs) + assert getattr(c.parameters, parameter)._user_specified == is_user_specified From 5e45265f133ad4fd58733b82a4d336b161df2bf0 Mon Sep 17 00:00:00 2001 From: Dillon Smith Date: Tue, 21 Jul 2020 17:23:29 -0400 Subject: [PATCH 12/13] Remove inactive link from docs -Remove link at top of `optimizationfunctions` module docstring for `ParamEstimationFunction`, which is currently hidden because it is still in development --- psyneulink/core/components/functions/optimizationfunctions.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/psyneulink/core/components/functions/optimizationfunctions.py b/psyneulink/core/components/functions/optimizationfunctions.py index ff4f200a322..86f9f2250f0 100644 --- a/psyneulink/core/components/functions/optimizationfunctions.py +++ b/psyneulink/core/components/functions/optimizationfunctions.py @@ -9,12 +9,13 @@ # # ****************************************** OPTIMIZATION FUNCTIONS ************************************************** """ +Contents +-------- * `OptimizationFunction` * `GradientOptimization` * `GridSearch` * `GaussianProcess` -* `ParamEstimationFunction` Overview -------- From b1f011bab5131b88d01bbfeea1add25deb63dceb Mon Sep 17 00:00:00 2001 From: Dillon Smith Date: Tue, 21 Jul 2020 17:55:59 -0400 Subject: [PATCH 13/13] comment out, instead of removing, link to ParamEstimationFunction --- psyneulink/core/components/functions/optimizationfunctions.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/psyneulink/core/components/functions/optimizationfunctions.py b/psyneulink/core/components/functions/optimizationfunctions.py index 86f9f2250f0..1b2ab53834c 100644 --- a/psyneulink/core/components/functions/optimizationfunctions.py +++ b/psyneulink/core/components/functions/optimizationfunctions.py @@ -16,6 +16,10 @@ * `GradientOptimization` * `GridSearch` * `GaussianProcess` +COMMENT: +uncomment this when ParamEstimationFunction is ready for users +* `ParamEstimationFunction` +COMMENT Overview --------