Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision

Target

Select target project
  • qt/qsymm
1 result
Select Git revision
Show changes
Commits on Source (2)
......@@ -10,6 +10,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added citation instructions in CITING.md
- Added a tutorial with downloadable Python files and Jupyter notebooks
### Fixed
- Bug when multiplying a model by a sympy expression (undefined variable)
- Bug when multiplying BlochCoeff with sympy expression (sympy multiplication was
being used, when BlochCoeff multiplication should have been used)
### Removed
- Removed the notebooks from the source repository
......
......@@ -288,7 +288,9 @@ def hamiltonian_from_family(family, coeffs=None, nsimplify=True, tosympy=True):
coeffs = list(sympy.symbols('c0:%d'%len(family), real=True))
else:
assert len(coeffs) == len(family), 'Length of family and coeffs do not match.'
ham = sum(c * term for c, term in zip(coeffs, family))
# The order of multiplication is important here, so that __mul__ of 'term'
# gets used. 'c' is a sympy symbol, which multiplies 'term' incorrectly.
ham = sum(term * c for c, term in zip(coeffs, family))
if tosympy:
return ham.tosympy(nsimplify=nsimplify)
else:
......
......@@ -360,6 +360,7 @@ class Model(UserDict):
result = self.zeros_like()
result.data = {key: val * other for key, val in self.items()}
elif isinstance(other, Basic):
keep = self.keep
result = sum((type(self)({key * other: copy(val)},
keep=keep,
momenta=self.momenta)
......@@ -396,11 +397,15 @@ class Model(UserDict):
if isinstance(other, Number):
result = self.__mul__(other)
elif isinstance(other, Basic):
result = sum((type(self)({other * key: copy(val)},
keep=self.keep,
keep = self.keep
# The order 'key * other' is important: we want to force
# the implementation of __mul__ of 'key' to be used. This
# is correct as long as the symbols in 'key' and 'other' commute.
result = sum((type(self)({key * other: copy(val)},
keep=keep,
momenta=self.momenta)
for key, val in self.items()
if (key * other in self.keep or not self.keep)),
if (key * other in keep or not keep)),
self.zeros_like())
else:
# Otherwise try to multiply every value with other
......