Skip to content

Commit

Permalink
Merge aed5069 into 6e7ac34
Browse files Browse the repository at this point in the history
  • Loading branch information
maxscheurer committed Jan 17, 2021
2 parents 6e7ac34 + aed5069 commit 21210d1
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ jobs:
pip install coveralls
sudo gem install coveralls-lcov
coveralls-lcov -v -n coverage.info > coverage.json
coveralls --merge=coverage.json
coveralls --service=github --merge=coverage.json
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
#
Expand Down
7 changes: 6 additions & 1 deletion adcc/AmplitudeVector.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ def __getattr__(self, key):
return self.__getitem__(key)
raise AttributeError

def __setattr__(self, key, item):
if self.__contains__(key):
return self.__setitem__(key, item)
raise AttributeError

@property
def blocks(self):
warnings.warn("The blocks attribute will change behaviour in 0.16.0.")
Expand Down Expand Up @@ -94,7 +99,7 @@ def __setitem__(self, index, item):
else:
raise KeyError(index)
else:
super().__setitem__(index, item)
return super().__setitem__(index, item)

def copy(self):
"""Return a copy of the AmplitudeVector"""
Expand Down
47 changes: 47 additions & 0 deletions adcc/test_AmplitudeVector.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env python3
## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
## ---------------------------------------------------------------------
##
## Copyright (C) 2021 by the adcc authors
##
## This file is part of adcc.
##
## adcc is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published
## by the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## adcc is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with adcc. If not, see <http://www.gnu.org/licenses/>.
##
## ---------------------------------------------------------------------
import pytest
import unittest
import numpy as np

import adcc
from adcc.testdata.cache import cache


class TestAmplitudeVector(unittest.TestCase):
def test_functionality(self):
ground_state = adcc.LazyMp(cache.refstate["h2o_sto3g"])
matrix = adcc.AdcMatrix("adc2", ground_state)
vectors = [adcc.guess_zero(matrix) for i in range(2)]
for vec in vectors:
vec.set_random()
v, w = vectors
with pytest.raises(AttributeError):
v.pph
# setattr with expression
z = adcc.zeros_like(v)
z.ph = v.ph + w.ph
z -= w
np.testing.assert_allclose(
v.ph.to_ndarray(), z.ph.to_ndarray()
)

0 comments on commit 21210d1

Please sign in to comment.