Skip to content

Commit

Permalink
Fixed bug in matched parameter node generation
Browse files Browse the repository at this point in the history
  • Loading branch information
lamsoa729 committed Dec 14, 2023
1 parent 6be476c commit d0f7478
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion chi_pet/chi_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
32 changes: 30 additions & 2 deletions tests/test_chi_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down Expand Up @@ -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

0 comments on commit d0f7478

Please sign in to comment.