Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overload '+' operator to concatenate ConfigSet objects #338

Merged
merged 3 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pytests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ jobs:
mpirun -n 2 pytest --cov=wfl --cov-report term --cov-config=tests/.coveragerc --cov-report term-missing --cov-report term:skip-covered --with-mpi -k mpi --cov-append

- name: 'Upload Coverage Data'
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
if: env.coverage-on-version == matrix.python-version
with:
name: coverage-html-${{ matrix.python-version }}
Expand Down
3 changes: 3 additions & 0 deletions tests/test_configset.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,9 @@ def test_from_mult_ConfigSets(tmp_path, ats):
locs = [f" / {i0} / {i1}" for i0 in range(3) for i1 in range(3)]
check_ConfigSet(ConfigSet([cs_01, cs_2]), locs, gather_numbers([ats_i_0, ats_i_1, ats_i_2]))

# same check for overloaded + operator
check_ConfigSet(cs_01 + cs_2, locs, gather_numbers([ats_i_0, ats_i_1, ats_i_2]))

def test_from_ConfigSets_mixed_0(tmp_path, ats):
ats_i_0 = ats[0:3]
ats_i_1 = ats[3:6]
Expand Down
6 changes: 6 additions & 0 deletions wfl/configset.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,12 @@ def _flat_iter(items):
yield at


def __add__(self, other):
if not isinstance(other, ConfigSet):
raise TypeError(f"unsupported operand type(s) for +: 'ConfigSet' and '{type(other)}'")
return ConfigSet([self, other])


class OutputSpec:
"""Abstraction for writing to a ConfigSet, preserving tree structure.

Expand Down