Skip to content

Commit

Permalink
Merge pull request #338 from libAtoms/configset_add_op
Browse files Browse the repository at this point in the history
Overload '+' operator to concatenate ConfigSet objects
  • Loading branch information
bernstei authored Oct 3, 2024
2 parents 6655d94 + 17226f1 commit 2d600ae
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
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

0 comments on commit 2d600ae

Please sign in to comment.