diff --git a/chi_pet/chi_node.py b/chi_pet/chi_node.py index 45f91c6..f8cb057 100644 --- a/chi_pet/chi_node.py +++ b/chi_pet/chi_node.py @@ -160,7 +160,7 @@ def make_subnodes(self, overwrite: bool = False) -> None: for ind, grp_lst in zip(ind_list[:num_grps], matched_grps.values()): for mcp in grp_lst: - cp.set_values(ind) + mcp.set_value(ind) # Set scanned params values second for ind, scp in zip(ind_list[num_grps:], scanned_params): diff --git a/tests/test_chi_node.py b/tests/test_chi_node.py index 00c67cb..3a1e430 100644 --- a/tests/test_chi_node.py +++ b/tests/test_chi_node.py @@ -68,6 +68,8 @@ def test_chi_node_multilevel_subnode_creation(mock_yaml_dict, mock_create_opts): 'chi_param_2'] = "ChiParam(name='pB', format_str='pB{:.1f}', values=[.1,.2,.3], level=1)" chi_dict = ChiDict(param_dict=yaml_dict) cnode = ChiNode(root_path, chi_dict, opts=mock_create_opts) + assert len(cnode._chi_params) == 2 + cnode.make_node_dir(root_path) cnode.make_subnodes() for pa in [10, 20, 30]: @@ -114,5 +116,31 @@ def test_chi_node_combinatorics_subnode_creation(mock_yaml_dict, mock_create_opt def test_chi_node_matched_subnode_creation(mock_yaml_dict, mock_create_opts): - # TODO NEXT after create matched creation - pass + root_path = Path.cwd() / 'tests/mock_root' + yaml_dict = deepcopy(mock_yaml_dict) + # Change first chi-param to be a matched parameter + yaml_dict[MOCK_CHI_PARAM_DICT_PATH]['var_param'] = ( + MOCK_CHI_PARAM_STR[:-1] + ", alg='match', param_grp='alpha')") + # Add another ChiParam at a lower level + + yaml_dict[MOCK_PARAM_DICT_PATH][ + 'chi_param_2'] = "ChiParam(name='pB', format_str='pB{:.1f}', values=[.1,.2,.3], alg='match', param_grp='alpha')" + chi_dict = ChiDict(param_dict=yaml_dict) + cnode = ChiNode(root_path, chi_dict, opts=mock_create_opts) + + cnode.make_node_dir(root_path) + cnode.make_subnodes() + for pa, pb in zip([10, 20, 30], [.1, .2, .3]): + p_comb_dir = Path(f'tests/mock_root/subnodes/pA{pa}_pB{pb}') + assert p_comb_dir.exists() + assert (p_comb_dir / MOCK_PARAM_DICT_PATH).exists() + assert (p_comb_dir / MOCK_CHI_PARAM_DICT_PATH).exists() + assert (p_comb_dir / 'data').exists() + + assert (yaml.safe_load( + (p_comb_dir / MOCK_CHI_PARAM_DICT_PATH).open('r'))['var_param'] == pa) + assert (yaml.safe_load( + (p_comb_dir / MOCK_PARAM_DICT_PATH).open('r'))['chi_param_2'] == pb) + +# TODO NTEST do match at combinatorics creation +# TODO Make sure the system fails if two matched parameters do not have the same number of values