Hello community, here is the log from the commit of package python-qsymm for openSUSE:Factory checked in at 2020-11-15 15:26:35 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/python-qsymm (Old) and /work/SRC/openSUSE:Factory/.python-qsymm.new.24930 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "python-qsymm" Sun Nov 15 15:26:35 2020 rev:2 rq:848502 version:1.3.0 Changes: -------- --- /work/SRC/openSUSE:Factory/python-qsymm/python-qsymm.changes 2020-07-08 19:15:06.191555644 +0200 +++ /work/SRC/openSUSE:Factory/.python-qsymm.new.24930/python-qsymm.changes 2020-11-15 15:27:42.203535700 +0100 @@ -1,0 +2,12 @@ +Sun Nov 1 23:45:46 UTC 2020 - Atri Bhattacharya <badshah...@gmail.com> + +- Update to version 1.3.0: + + Integration test: run the tests for Kwant's qsymm module + against the current version of qsymm. + + Avoided using deprecated functionality in latest scipy, numpy, + and sympy. + + Fix syntax for python 3.9. + + Support of python < 3.7, numpy < 1.16, scipy < 1.1, sympy < + 1.3. + +------------------------------------------------------------------- Old: ---- qsymm-1.2.7.tar.gz New: ---- qsymm-1.3.0.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ python-qsymm.spec ++++++ --- /var/tmp/diff_new_pack.qncYjP/_old 2020-11-15 15:27:42.747536282 +0100 +++ /var/tmp/diff_new_pack.qncYjP/_new 2020-11-15 15:27:42.751536286 +0100 @@ -19,7 +19,7 @@ %define skip_python2 1 %define modname qsymm Name: python-qsymm -Version: 1.2.7 +Version: 1.3.0 Release: 0 Summary: Symmetry finder and symmetric Hamiltonian generator License: BSD-2-Clause ++++++ qsymm-1.2.7.tar.gz -> qsymm-1.3.0.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qsymm-1.2.7/CHANGELOG.md new/qsymm-1.3.0/CHANGELOG.md --- old/qsymm-1.2.7/CHANGELOG.md 2019-12-04 14:17:10.000000000 +0100 +++ new/qsymm-1.3.0/CHANGELOG.md 2020-11-01 15:06:42.000000000 +0100 @@ -6,19 +6,22 @@ ## [unreleased] -## [1.2.7] - 2019-12-04 +## [1.3.0] - 2020-11-01 ### Added -- Added integration test: run the tests for Kwant's qsymm module against the - current version of qsymm. -- Added tests for fail cases in symmetry finder and Model with locals. + ++ integration test: run the tests for Kwant's qsymm module against the current version + of qsymm. ### Fixed -- Bug when Model is initialized with numpy arrays in `locals`. -- Bug in symmetry finding when transformed Hamiltonian has very small coefficients, - this could lead to not finding symmetries in continuum models. -- Bug in Model.copy with sparse arrays did not return a copy of the stored arrays. -- Move docstrings to class level from __init__ functions and extend docstrings. + ++ Avoided using deprecated functionality in latest scipy, numpy, and sympy ++ Fix syntax for python 3.9 + +### Removed + ++ Support of python < 3.7, numpy < 1.16, scipy < 1.1, sympy < 1.3 + (similar to the upcoming Kwant release) ## [1.2.6] - 2019-11-12 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qsymm-1.2.7/PKG-INFO new/qsymm-1.3.0/PKG-INFO --- old/qsymm-1.2.7/PKG-INFO 2019-12-04 14:18:56.000000000 +0100 +++ new/qsymm-1.3.0/PKG-INFO 2020-11-01 15:07:21.372530500 +0100 @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: qsymm -Version: 1.2.7 +Version: 1.3.0 Summary: Symmetry finder and symmetric Hamiltonian generator Home-page: https://gitlab.kwant-project.org/qt/qsymm Author: Qsymm authors @@ -78,5 +78,6 @@ Classifier: License :: OSI Approved :: BSD License Classifier: Intended Audience :: Science/Research Classifier: Programming Language :: Python :: 3.5 +Requires-Python: >=3.7 Description-Content-Type: text/markdown Provides-Extra: kwant diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qsymm-1.2.7/qsymm/__init__.py new/qsymm-1.3.0/qsymm/__init__.py --- old/qsymm-1.2.7/qsymm/__init__.py 2019-08-30 14:15:14.000000000 +0200 +++ new/qsymm-1.3.0/qsymm/__init__.py 2020-08-30 16:47:10.000000000 +0200 @@ -1,3 +1,4 @@ +from ._version import __version__ from . import groups from . import linalg from . import hamiltonian_generator @@ -13,4 +14,4 @@ continuous_symmetries, bravais_point_group from .kwant_continuum import sympify -from ._version import __version__ +del _version diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qsymm-1.2.7/qsymm/_static_version.py new/qsymm-1.3.0/qsymm/_static_version.py --- old/qsymm-1.2.7/qsymm/_static_version.py 2019-12-04 14:18:56.000000000 +0100 +++ new/qsymm-1.3.0/qsymm/_static_version.py 2020-11-01 15:07:21.372530500 +0100 @@ -1,2 +1,2 @@ # This file has been created by setup.py. -version = '1.2.7' +version = '1.3.0' diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qsymm-1.2.7/qsymm/_version.py new/qsymm-1.3.0/qsymm/_version.py --- old/qsymm-1.2.7/qsymm/_version.py 2018-06-13 15:48:14.000000000 +0200 +++ new/qsymm-1.3.0/qsymm/_version.py 2020-11-01 14:38:44.000000000 +0100 @@ -4,9 +4,8 @@ from collections import namedtuple import os import subprocess -import sys -from distutils.command.build_py import build_py as build_py_orig +from setuptools.command.build_py import build_py as build_py_orig from setuptools.command.sdist import sdist as sdist_orig Version = namedtuple('Version', ('release', 'dev', 'labels')) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qsymm-1.2.7/qsymm/groups.py new/qsymm-1.3.0/qsymm/groups.py --- old/qsymm-1.2.7/qsymm/groups.py 2019-11-26 03:24:49.000000000 +0100 +++ new/qsymm-1.3.0/qsymm/groups.py 2020-11-01 15:06:42.000000000 +0100 @@ -1,15 +1,16 @@ # -*- coding: utf-8 -*- -import numpy as np -import tinyarray as ta -import scipy.linalg as la from itertools import product from functools import lru_cache from fractions import Fraction from numbers import Number from collections import OrderedDict + +import numpy as np +import tinyarray as ta +import scipy.linalg as la import sympy -from copy import deepcopy +from sympy.matrices.matrices import MatrixBase from .linalg import prop_to_id, _inv_int, allclose from .model import Model @@ -88,7 +89,7 @@ def is_sympy_matrix(R): # Returns True if the input is a sympy.Matrix or sympy.ImmutableMatrix. - return isinstance(R, (sympy.ImmutableMatrix, sympy.matrices.MatrixBase)) + return isinstance(R, (sympy.ImmutableMatrix, MatrixBase)) class PointGroupElement: @@ -139,7 +140,7 @@ pass elif isinstance(R, ta.ndarray_float): R = _make_int(R) - elif isinstance(R, sympy.matrices.MatrixBase): + elif isinstance(R, MatrixBase): R = sympy.ImmutableMatrix(R) R = _make_int(R) elif isinstance(R, np.ndarray): @@ -986,7 +987,7 @@ else: az_name = "" name = (az_name if (rot_name == '1' and az_name != "") - else rot_name + (" " if az_name is not "" else "") + az_name) + else rot_name + (" " if az_name != "" else "") + az_name) return '$' + name + '$' if latex else name diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qsymm-1.2.7/qsymm/kwant_continuum.py new/qsymm-1.3.0/qsymm/kwant_continuum.py --- old/qsymm-1.2.7/qsymm/kwant_continuum.py 2019-12-04 14:02:26.000000000 +0100 +++ new/qsymm-1.3.0/qsymm/kwant_continuum.py 2019-02-22 18:02:05.000000000 +0100 @@ -206,10 +206,7 @@ "identifiers and may not be keywords".format(repr(k))) # sympify values of locals before updating it with extra_ns - # Cast numpy array values in locals to sympy matrices to make sure they have - # correct format - locals = {k: (sympy.Matrix(v) if isinstance(v, np.ndarray) else sympify(v)) - for k, v in locals.items()} + locals = {k: sympify(v) for k, v in locals.items()} for k, v in extra_ns.items(): locals.setdefault(k, v) try: diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qsymm-1.2.7/qsymm/linalg.py new/qsymm-1.3.0/qsymm/linalg.py --- old/qsymm-1.2.7/qsymm/linalg.py 2019-11-28 15:38:22.000000000 +0100 +++ new/qsymm-1.3.0/qsymm/linalg.py 2020-10-27 09:40:52.000000000 +0100 @@ -258,7 +258,7 @@ if isinstance(A, scipy.sparse.spmatrix): A = A.A # Do dense SVD - u, s, vh = la.svd(A, full_matrices = True) + _, s, vh = la.svd(A, full_matrices = True) nnz = np.isclose(s, 0, atol=atol) # Make sure it works for arbitrary rectangular matrices if len(s) < len(vh): @@ -456,7 +456,6 @@ null_mat = [] for hL, hR, conj in zip(HL, HR, conjugate): if conj: - print(next(basis)) row = [flatten(mat @ hL - hR @ mat.conj()) for mat in basis()] else: row = [flatten(mat @ hL - hR @ mat) for mat in basis()] diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qsymm-1.2.7/qsymm/model.py new/qsymm-1.3.0/qsymm/model.py --- old/qsymm-1.2.7/qsymm/model.py 2019-12-04 14:11:29.000000000 +0100 +++ new/qsymm-1.3.0/qsymm/model.py 2020-10-27 09:40:52.000000000 +0100 @@ -1,18 +1,21 @@ -import numpy as np -import scipy -import tinyarray as ta -import scipy.linalg as la from itertools import product -import copy as copy_module +from copy import copy from numbers import Number from warnings import warn from functools import lru_cache +from collections import defaultdict, abc, UserDict + +import numpy as np +import scipy +import tinyarray as ta +import scipy.linalg as la import sympy +from sympy.core.numbers import One +from sympy.matrices.matrices import MatrixBase from sympy.core.basic import Basic from sympy.core.function import AppliedUndef -from collections import defaultdict, abc, UserDict -from .linalg import prop_to_id, allclose +from .linalg import prop_to_id, allclose from . import kwant_continuum, _scipy_patch _commutative_momenta = [kwant_continuum.make_commutative(k, k) @@ -22,17 +25,6 @@ I = kwant_continuum.sympify('I') -# Scipy sparse matrices defined a 'copy' method (which does -# a deep-copy of their data) but no '__copy__' method, to work -# correctly with the 'copy' module. We therefore make our own -# wrapper here that does the right thing -def copy(a): - if callable(getattr(a, 'copy', None)): - return a.copy() - else: - return copy_module.copy(a) - - def substitute_exponents(expr): """Substitute trignometric functions with exp. @@ -63,15 +55,15 @@ class BlochCoeff(tuple): - """ - Container for Bloch coefficient in ``BlochModel``, in the form of - ``(hop, coeff)``, equivalent to ``coeff * exp(I * hop.dot(k))``. - """ def __new__(cls, hop, coeff): + """ + Container for Bloch coefficient in ``BlochModel``, in the form of + ``(hop, coeff)``, equivalent to ``coeff * exp(I * hop.dot(k))``. + """ if not (isinstance(hop, np.ndarray) and isinstance(coeff, sympy.Expr)): raise ValueError('`hop` must be a 1D numpy array and `coeff` a sympy expression.') - if isinstance(coeff, sympy.add.Add): + if isinstance(coeff, sympy.Add): raise ValueError('`coeff` must be a single term with no sum.') return super(BlochCoeff, cls).__new__(cls, [hop, coeff]) @@ -123,72 +115,6 @@ class Model(UserDict): - """ - Symbolic matrix-valued function that depends on momenta and other parameters. - - Implements the algebra of matrix valued functions. - Implements many sympy and numpy methods and overrides arithmetic operators. - Internally it represents ``sum(symbol * value)``, where ``symbol`` is a symbolic - expression, and ``value`` can be scalar, array (both dense and sparse) - or LinearOperator. This is accessible as a dict ``{symbol: value}``. - - Parameters - ---------- - hamiltonian : str, SymPy expression, dict or None (default) - Symbolic representation of a Hamiltonian. If a string, it is - first converted to a SymPy expression using `kwant_continuum.sympify`. - If a dict is provided, it should have the form - ``{symbol: array}`` with all arrays the same size (dense or sparse). - ``symbol`` by default is passed through sympy.sympify, and should - consist purely of a product of symbolic coefficients, no constant - factors other than 1, except if ``normalize=True``. ``None`` initializes - a zero ``Model``. - locals : dict or ``None`` (default) - Additional namespace entries for `~kwant_continuum.sympify`. May be - used to simplify input of matrices or modify input before proceeding - further. For example: - ``locals={'k': 'k_x + I * k_y'}`` or - ``locals={'sigma_plus': [[0, 2], [0, 0]]}``. - keep : iterable of expressions (optional) - Set of symbolic coefficients that are kept, anything that does not - appear here is discarded. Useful for perturbative calculations where - only terms to a given order are needed. By default all keys are kept. - momenta : iterable of strings or Sympy symbols - Names of momentum variables, default ``('k_x', 'k_y', 'k_z')`` or - corresponding sympy symbols. Momenta are treated the same as other - keys for the purpose of `keep`. - symbol_normalizer : callable (optional) - Function applied to symbols when initializing the internal dict. By default the - keys are passed through ``sympy.sympify`` and ``sympy.expand_power_exp``. - Keys when accessing a term and keys in ``keep`` are also passed through - ``symbol_normalizer``. - normalize : bool, default False - Whether to clean input dict by splitting summands in symbols, - moving numerical factors in the symbols to values, removing entries - with values allclose to zero. Ignored if hamiltonian is not a dict. - shape : tuple or None (default) - Shape of the Model, must match the shape of all the values. If not - provided, it is automatically found based on the shape of the input. - Must be provided if ``hamiltonian`` is ``None`` or ``{}``. Empty tuple - corresponds to scalar values. - format : class or None (default) - Type of the values in the model. Supported types are - ``np.complex128``, ``scipy.sparse.linalg.LinearOperator``, ``np.ndarray``, - and subclasses of ``scipy.sparse.spmatrix`` . If ``hamiltonian`` is - provided as a dict, all values must be of this type, except for - scalar values, which are recast to ``np.complex128``. If ``format`` is - not provided, it is inferred from the type of the values. Must be - provided if ``hamiltonian`` is `None` or ``{}``. If ``hamiltonian`` is - not a dictionary, ``format`` is ignored an set to ``np.ndarray``. - - Notes - ----- - Sympy symbols are immutable and references to the same symbols is - stored in different Models. Be warned that setting any assumptions - for symbols (such as ``real``) will result in an identically named, - but different symbol, and these are not handled properly. Model assumes - that all sympy symbols are real without any assumptions explicitly set. - """ # Make it work with numpy arrays __array_ufunc__ = None @@ -201,6 +127,64 @@ keep=None, symbol_normalizer=None, normalize=False, shape=None, format=None ): + """ + Symbolic matrix-valued function that depends on momenta and other parameters. + + Implements the algebra of matrix valued functions. + Implements many sympy and numpy methods and overrides arithmetic operators. + Internally it represents ``sum(symbol * value)``, where ``symbol`` is a symbolic + expression, and ``value`` can be scalar, array (both dense and sparse) + or LinearOperator. This is accessible as a dict ``{symbol: value}``. + + Parameters + ---------- + hamiltonian : str, SymPy expression, dict or None (default) + Symbolic representation of a Hamiltonian. If a string, it is + first converted to a SymPy expression using `kwant_continuum.sympify`. + If a dict is provided, it should have the form + ``{symbol: array}`` with all arrays the same size (dense or sparse). + ``symbol`` by default is passed through sympy.sympify, and should + consist purely of a product of symbolic coefficients, no constant + factors other than 1, except if ``normalize=True``. ``None`` initializes + a zero ``Model``. + locals : dict or ``None`` (default) + Additional namespace entries for `~kwant_continuum.sympify`. May be + used to simplify input of matrices or modify input before proceeding + further. For example: + ``locals={'k': 'k_x + I * k_y'}`` or + ``locals={'sigma_plus': [[0, 2], [0, 0]]}``. + keep : iterable of expressions (optional) + Set of symbolic coefficients that are kept, anything that does not + appear here is discarded. Useful for perturbative calculations where + only terms to a given order are needed. By default all keys are kept. + momenta : iterable of strings or Sympy symbols + Names of momentum variables, default ``['k_x', 'k_y', 'k_z']`` or + corresponding sympy symbols. Momenta are treated the same as other + keys for the purpose of `keep`. + symbol_normalizer : callable (optional) + Function applied to symbols when initializing the internal dict. By default the + keys are passed through ``sympy.sympify`` and ``sympy.expand_power_exp``. + Keys when accessing a term and keys in ``keep`` are also passed through + ``symbol_normalizer``. + normalize : bool, default False + Whether to clean input dict by splitting summands in symbols, + moving numerical factors in the symbols to values, removing entries + with values allclose to zero. Ignored if hamiltonian is not a dict. + shape : tuple or None (default) + Shape of the Model, must match the shape of all the values. If not + provided, it is automatically found based on the shape of the input. + Must be provided if ``hamiltonian`` is ``None`` or ``{}``. Empty tuple + corresponds to scalar values. + format : class or None (default) + Type of the values in the model. Supported types are + ``np.complex128``, ``scipy.sparse.linalg.LinearOperator``, ``np.ndarray``, + and subclasses of ``scipy.sparse.spmatrix`` . If ``hamiltonian`` is + provided as a dict, all values must be of this type, except for + scalar values, which are recast to ``np.complex128``. If ``format`` is + not provided, it is inferred from the type of the values. Must be + provided if ``hamiltonian`` is `None` or ``{}``. If ``hamiltonian`` is + not a dictionary, ``format`` is ignored an set to ``np.ndarray``. + """ if hamiltonian is None: hamiltonian = {} if symbol_normalizer is None: @@ -221,7 +205,7 @@ else: # Try to parse the input with kwant_continuum.sympify hamiltonian = kwant_continuum.sympify(hamiltonian, locals=locals) - if not isinstance(hamiltonian, sympy.matrices.MatrixBase): + if not isinstance(hamiltonian, MatrixBase): hamiltonian = sympy.Matrix([[hamiltonian]]) hamiltonian = substitute_exponents(hamiltonian) free_parameters = list(hamiltonian.atoms(sympy.Symbol)) @@ -723,73 +707,58 @@ return all(allclose(self[key], other[key], rtol, atol, equal_nan) for key in self.keys() | other.keys()) - def eliminate_zeros(self, rtol=1e-05, atol=1e-08): - """Return a model with small terms removed. Tolerances are - in Frobenius matrix norm, relative tolerance compares to the - value with largest norm.""" - if not issubclass(self.format, (np.ndarray, scipy.sparse.spmatrix)): - raise ValueError('Operation only supported for Models with ' - '`np.ndarray` or `scipy.sparse.spmatrix` data type.') - # Write it explicitely so it works with sparse arrays - norm = lambda mat: np.sqrt(np.sum(np.abs(mat)**2)) - max_norm = np.max([norm(val) for val in self.values()]) - tol = max(atol, max_norm * rtol) - result = self.zeros_like() - result.data = {key: copy(val) for key, val in self.items() if not norm(val) < tol} - return result - class BlochModel(Model): - """ - A ``Model`` where coefficients are periodic functions of momenta. - - Internally it is a ``sum(BlochCoeff * value)``, where ``BlochCoeff`` is - a symbolic representation of coefficients and a periodic function of ``k``. - ``value`` can be scalar, array (both dense and sparse) or LinearOperator. - This is accessible as a dict ``{BlochCoeff: value}``. - - Parameters - ---------- - hamiltonian : Model, str, SymPy expression, dict or None (default) - Symbolic representation of a Hamiltonian. If a string, it is - converted to a SymPy expression using ``kwant_continuum.sympify``. - If a dict is provided, it should have the form - ``{symbol: array}`` with all arrays the same size (dense or sparse). - If symbol is not a BlochCoeff, it is passed through sympy.sympify, - and should consist purely of a product of symbolic coefficients, - no constant factors other than 1. `symbol` is then converted to BlochCoeff. - `None` initializes a zero ``BlochModel``. - locals : dict or ``None`` (default) - Additional namespace entries for `~kwant_continuum.sympify`. May be - used to simplify input of matrices or modify input before proceeding - further. For example: - ``locals={'k': 'k_x + I * k_y'}`` or - ``locals={'sigma_plus': [[0, 2], [0, 0]]}``. - momenta : iterable of strings or Sympy symbols - Names of momentum variables, default ``('k_x', 'k_y', 'k_z')`` or - corresponding sympy symbols. Momenta are treated the same as other - keys for the purpose of `keep`. Ignored when initialized with Model. - keep : iterable of BlochCoeff (optional) - Set of symbolic coefficients that are kept, anything that does not - appear here is discarded. Useful for perturbative calculations where - only terms to a given order are needed. By default all keys are kept. - Ignored when initialized with Model. - shape : tuple or None (default) - Shape of the Model, must match the shape of all the values. If not - provided, it is automatically found based on the shape of the input. - Must be provided is ``hamiltonian`` is `None` or ``{}``. Empty tuple - corresponds to scalar values. Ignored when initialized with Model. - format : class or None (default) - Type of the values in the model. Supported types are `np.complex128`, - ``np.ndarray``, ``scipy.sparse.spmatrix`` and ``scipy.sparse.linalg.LinearOperator``. - If ``hamiltonian`` is provided as a dict, all values must be of this type, - except for scalar values, which are recast to ``np.complex128``. - If ``format`` is not provided, it is inferred from the type of the values. - If ``hamiltonian`` is not a dictionary, ``format`` is ignored and set to - ``np.ndarray`` or ``hamiltonian.format`` if it is a ``Model``. - """ def __init__(self, hamiltonian=None, locals=None, momenta=('k_x', 'k_y', 'k_z'), keep=None, shape=None, format=None): + """ + A ``Model`` where coefficients are periodic functions of momenta. + + Internally it is a ``sum(BlochCoeff * value)``, where ``BlochCoeff`` is + a symbolic representation of coefficients and a periodic function of ``k``. + ``value`` can be scalar, array (both dense and sparse) or LinearOperator. + This is accessible as a dict ``{BlochCoeff: value}``. + + Parameters + ---------- + hamiltonian : Model, str, SymPy expression, dict or None (default) + Symbolic representation of a Hamiltonian. If a string, it is + converted to a SymPy expression using ``kwant_continuum.sympify``. + If a dict is provided, it should have the form + ``{symbol: array}`` with all arrays the same size (dense or sparse). + If symbol is not a BlochCoeff, it is passed through sympy.sympify, + and should consist purely of a product of symbolic coefficients, + no constant factors other than 1. `symbol` is then converted to BlochCoeff. + `None` initializes a zero ``BlochModel``. + locals : dict or ``None`` (default) + Additional namespace entries for `~kwant_continuum.sympify`. May be + used to simplify input of matrices or modify input before proceeding + further. For example: + ``locals={'k': 'k_x + I * k_y'}`` or + ``locals={'sigma_plus': [[0, 2], [0, 0]]}``. + momenta : iterable of strings or Sympy symbols + Names of momentum variables, default ``['k_x', 'k_y', 'k_z']`` or + corresponding sympy symbols. Momenta are treated the same as other + keys for the purpose of `keep`. Ignored when initialized with Model. + keep : iterable of BlochCoeff (optional) + Set of symbolic coefficients that are kept, anything that does not + appear here is discarded. Useful for perturbative calculations where + only terms to a given order are needed. By default all keys are kept. + Ignored when initialized with Model. + shape : tuple or None (default) + Shape of the Model, must match the shape of all the values. If not + provided, it is automatically found based on the shape of the input. + Must be provided is ``hamiltonian`` is `None` or ``{}``. Empty tuple + corresponds to scalar values. Ignored when initialized with Model. + format : class or None (default) + Type of the values in the model. Supported types are `np.complex128`, + ``np.ndarray``, ``scipy.sparse.spmatrix`` and ``scipy.sparse.linalg.LinearOperator``. + If ``hamiltonian`` is provided as a dict, all values must be of this type, + except for scalar values, which are recast to ``np.complex128``. + If ``format`` is not provided, it is inferred from the type of the values. + If ``hamiltonian`` is not a dictionary, ``format`` is ignored and set to + ``np.ndarray`` or ``hamiltonian.format`` if it is a ``Model``. + """ momenta = tuple(momenta) if hamiltonian is None: hamiltonian = {} @@ -908,21 +877,21 @@ # Expand multiplication of brackets into sums. key = sympy.expand(key, power_base=False, power_exp=False, mul=True, log=False, multinomial=False) - if isinstance(key, sympy.add.Add): + if isinstance(key, sympy.Add): raise ValueError("Key cannot be a sum of terms.") # Key is a single exponential. - if isinstance(key, sympy.power.Pow): + if isinstance(key, sympy.Pow): base, exp = key.as_base_exp() # If the exponential is a hopping, store it # with coefficient 1. if is_hopping_expo(key): hop_expo = key - coeff = sympy.numbers.One() + coeff = One() # If it is not a hopping, it belongs to the coeff. else: hop, coeff, hop_expo = np.zeros((len(momenta,))), key, None # Key is the product of an exponential and some extra stuff. - elif sympy.power.Pow in [type(arg) for arg in key.args]: + elif sympy.Pow in [type(arg) for arg in key.args]: # Check that a natural exponential is present, which also # includes momenta in its arguments. # First find all exponentials. @@ -971,7 +940,7 @@ for momentum in momenta] # We do not allow sympy symbols in the hopping, should # be numerical values only. - if any([isinstance(item, sympy.symbol.Symbol) + if any([isinstance(item, sympy.Symbol) for ele in hop for item in ele.atoms() if isinstance(ele, sympy.Expr)]): raise ValueError( diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qsymm-1.2.7/qsymm/symmetry_finder.py new/qsymm-1.3.0/qsymm/symmetry_finder.py --- old/qsymm-1.2.7/qsymm/symmetry_finder.py 2019-12-04 14:02:26.000000000 +0100 +++ new/qsymm-1.3.0/qsymm/symmetry_finder.py 2020-10-27 09:40:52.000000000 +0100 @@ -1,8 +1,10 @@ +from collections import defaultdict +from copy import deepcopy +import itertools as it + import numpy as np import scipy.linalg as la import scipy.sparse -import itertools as it -from copy import deepcopy from .linalg import matrix_basis, nullspace, split_list, simult_diag, commutator, \ prop_to_id, sparse_basis, mtm, family_to_vectors, solve_mat_eqn, \ @@ -426,7 +428,7 @@ gr = _find_unitary(model, Ps, g, sparse=sparse_linalg) if gr.U is not None: # Check that it's indeed a symmetry - assert gr.apply(model).allclose(model, atol=1e-6), (n, gr) + assert gr.apply(model) == model, (n, gr) genset.add(gr) # Needless to test anything in the group generated by the # symmetries found already, they are symmetries for sure. @@ -484,11 +486,9 @@ if not issubclass(model.format, (np.ndarray, scipy.sparse.spmatrix)): raise ValueError('Symmetry finding is only supported for Models with ' '`np.ndarray` or `scipy.sparse.spmatrix` data type.') - # Remove potential small terms - model = model.eliminate_zeros() if g.U is not None: raise ValueError('g.U must be None.') - Rmodel = g.apply(model).eliminate_zeros() + Rmodel = g.apply(model) if set(model) != set(Rmodel): return g HR, HL = [], [] @@ -700,9 +700,7 @@ blockdim = rham.shape[0] L = None # Generate all reduced hamiltonians transformed by spatial part - # ignoring small terms - trf_hams = [ContinuousGroupGenerator(1j * R, L).apply(rham).eliminate_zeros() - for R in Rs()] + trf_hams = [ContinuousGroupGenerator(1j * R, L).apply(rham) for R in Rs()] # Generate all keys that appear as transformed reduced hamiltonians keys = rham.keys() for th in trf_hams: @@ -714,11 +712,9 @@ Rblocks.append(Rblock) # Iterate over all reduced hamiltonians transformed by only hilbert space part - # ignoring small terms R = None Ls = matrix_basis(blockdim, traceless=True) - trf_hams = [ContinuousGroupGenerator(R, L).apply(rham).eliminate_zeros() - for L in Ls] + trf_hams = [ContinuousGroupGenerator(R, L).apply(rham) for L in Ls] Lblock = family_to_vectors(trf_hams, all_keys=keys).T Lblocks.append(Lblock) @@ -779,7 +775,7 @@ Ps = _reduce_hamiltonian(np.array([H for H in model.values()])) reduced_hamiltonians = [] for P in Ps: - Hr = (P[0].T.conj() @ model @ P[0]).eliminate_zeros() + Hr = P[0].T.conj() @ model @ P[0] reduced_hamiltonians.append(Hr) return reduced_hamiltonians @@ -848,7 +844,6 @@ def bravais_group_2d(neighbors, num_eq, sets_eq, verbose=False): - s3 = np.sqrt(3) gens = set() assert len(neighbors) <= 3 @@ -997,7 +992,7 @@ def equals(vectors): # group equivalent vectors based on length and angles one = kwant_continuum.sympify('1') - sets = dict() + vector_sets = defaultdict(list) # Take abs because every vector has opposite pair overlaps = np.abs(vectors @ vectors.T) angles = np.outer(np.diag(overlaps), np.diag(overlaps))**(-1/2) * overlaps @@ -1006,25 +1001,23 @@ # Symmetry equivalent vectors must have the same signature signature = np.concatenate([length, sorted(overlaps[i]), sorted(angles[i])]) key = BlochCoeff(signature, one) - if key in sets: - sets[key].append(vector) - else: - sets[key] = [vector] - numbers, sets = zip(*((len(set), np.array(set)) for set in sets.values())) - order = np.argsort(numbers) - numbers = np.array(numbers) - sets = np.array(sets) - return list(numbers[order]), list(sets[order]) + vector_sets[key].append(vector) + + vector_sets = sorted( + (np.array(vector_set) for vector_set in vector_sets.values()), + key=(lambda x: len(x)) + ) + + return [len(vector_set) for vector_set in vector_sets], vector_sets def pick_perp(vectors, n, other_vectors=None): # Pick vectors that are orthogonal to at least n other vectors other_vectors = np.array(vectors if other_vectors is None else other_vectors) - perp = [] - non_perp = [] - for v in vectors: - if np.sum(np.isclose(v @ other_vectors.T, 0)) >= n: - perp.append(v) + perp = [ + v for v in vectors + if np.sum(np.isclose(v @ other_vectors.T, 0)) >= n + ] return perp diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qsymm-1.2.7/qsymm/tests/test_hamiltonian_generator.py new/qsymm-1.3.0/qsymm/tests/test_hamiltonian_generator.py --- old/qsymm-1.2.7/qsymm/tests/test_hamiltonian_generator.py 2019-11-26 03:24:49.000000000 +0100 +++ new/qsymm-1.3.0/qsymm/tests/test_hamiltonian_generator.py 2020-10-27 09:40:52.000000000 +0100 @@ -64,7 +64,7 @@ """Square lattice with time reversal and rotation symmetry, such that all hoppings are real. """ # Time reversal trU = np.eye(2) - trR = sympy.Matrix(np.eye(2, dtype=int)) + trR = sympy.Matrix([[1, 0], [0, 1]]) trS = PointGroupElement(trR, True, False, trU) # 2-fold rotation rotU = np.eye(2) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qsymm-1.2.7/qsymm/tests/test_model.py new/qsymm-1.3.0/qsymm/tests/test_model.py --- old/qsymm-1.2.7/qsymm/tests/test_model.py 2019-12-04 14:02:26.000000000 +0100 +++ new/qsymm-1.3.0/qsymm/tests/test_model.py 2020-10-27 09:40:52.000000000 +0100 @@ -1,6 +1,7 @@ import pytest import warnings import sympy +from sympy.core.numbers import One from scipy.sparse import csr_matrix from scipy.sparse.linalg import LinearOperator import numpy as np @@ -293,15 +294,6 @@ assert m2[k_x] == m1[k_x].conj() assert m2[e**(-I*k_y)] == m1[e**(I*k_y)].conj() -def test_Model_locals(): - # Test that locals are treated properly - ham1 = Model('alpha * sigma_z') - ham2 = Model('alpha * sz', locals=dict(sz=np.diag([1, -1]))) - assert ham1 == ham2 - ham3 = Model('alpha * sz', locals=dict(sz='[[1, 0], [0, -1]]')) - assert ham2 == ham3 - ham4 = Model('Hz', locals=dict(Hz='[[alpha, 0], [0, -alpha]]')) - assert ham3 == ham4 def test_BlochModel(): @@ -311,7 +303,7 @@ m = Model({c1*e**(I*k_y): 3*np.eye(2), np.sqrt(3)*e**(I*k_x) : np.eye(2)}, momenta=['k_x', 'k_y'], normalize=True) bm = BlochModel(m) - keys = [BlochCoeff(np.array([0, 1]), c1), BlochCoeff(np.array([1, 0]), sympy.numbers.One())] + keys = [BlochCoeff(np.array([0, 1]), c1), BlochCoeff(np.array([1, 0]), One())] assert all([key in keys for key in bm.keys()]) assert allclose(bm[keys[0]], m[c1*e**(I*k_y)]) assert allclose(bm[keys[1]], m[e**(I*k_x)]) @@ -351,7 +343,7 @@ Ham = BlochModel({c0 * e**(-I*(k_x/2 + k_y )) : T, c1 * e**(I*(4*k_x + 3*k_y)) : 2*T}, momenta=['k_x', 'k_y']) nHam = Ham.subs([(c0, 3), (c1, 2*u_1)]) - right_Ham = BlochModel({BlochCoeff(np.array([-0.5, -1]), sympy.numbers.One()): T * 3, + right_Ham = BlochModel({BlochCoeff(np.array([-0.5, -1]), One()): T * 3, BlochCoeff(np.array([4, 3]), u_1): 2 * T * 2}, momenta=[k_x, k_y]) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qsymm-1.2.7/qsymm/tests/test_symmetry_finder.py new/qsymm-1.3.0/qsymm/tests/test_symmetry_finder.py --- old/qsymm-1.2.7/qsymm/tests/test_symmetry_finder.py 2019-12-04 14:02:26.000000000 +0100 +++ new/qsymm-1.3.0/qsymm/tests/test_symmetry_finder.py 2020-11-01 15:06:42.000000000 +0100 @@ -5,7 +5,6 @@ from .. import kwant_rmt from ..symmetry_finder import * from ..symmetry_finder import _reduced_model, _reduce_hamiltonian, bravais_point_group -from ..groups import hexagonal from ..linalg import * from .. import kwant_continuum @@ -30,7 +29,7 @@ def test_cont_finder(): # Test symmetry adapted basis - gens = sumrep((*2*[0.5*sigma[[3, 1, 2]]])) + gens = sumrep(*2*[0.5*sigma[[3, 1, 2]]]) U2 = kwant_rmt.circular(len(gens[0])) gens2 = np.einsum('ij,ajk,kl->ail',(U2.T).conjugate(),gens,U2) U = symmetry_adapted_sun(gens, check=True) @@ -635,26 +634,3 @@ assert len(group) == n, (name, periods, group, n) group = bravais_point_group(periods @ R, tr=False, ph=False) assert len(group) == n, (name, periods, group, n) - - -def test_3d_dirac(): - # Define 3D Dirac Hamiltonian - ham = """ - (C + D1*k_z**2 + D2*(k_x**2+k_y**2))*eye(4) - + kron(sigma_x,sigma_x)*A2*k_y - + kron(sigma_x,sigma_y)*(-A2*k_x) - + kron(sigma_y,eye(2))*A1*k_z - + kron(sigma_z, eye(2))*(M+B1*k_z**2+B2*(k_x**2+k_y**2)) - + m5*kron(sigma_x,sigma_z) - """ - - H = Model(ham, momenta=['k_x', 'k_y','k_z']) - candidates = hexagonal(dim=3) - sg, cg = symmetries(H, candidates, continuous_rotations=True, prettify=True) - assert len(sg) == 24 - assert len(cg) == 1 - - # Find symmetries with m5 set to 0 - sg, cg = symmetries(H.subs('m5', 0), candidates, continuous_rotations=True, prettify=True) - assert len(sg) == 48 - assert len(cg) == 1 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qsymm-1.2.7/qsymm/tests/test_util.py new/qsymm-1.3.0/qsymm/tests/test_util.py --- old/qsymm-1.2.7/qsymm/tests/test_util.py 2019-08-30 14:15:14.000000000 +0200 +++ new/qsymm-1.3.0/qsymm/tests/test_util.py 2020-10-27 09:40:52.000000000 +0100 @@ -21,10 +21,10 @@ assert sparse_U.shape == U.shape # Make one row linearly dependent on the others U[-1, :] = sum([np.random.rand()*row for row in U[:-1, :]]) - with warnings.catch_warnings(record=True) as w: + with pytest.warns(UserWarning): sparse_U = sparse_basis(U, num_digits=4, reals=real) - assert sparse_U.shape[0] == dim-1 - assert len(w) == 1 # A warning should be raised + + assert sparse_U.shape[0] == dim-1 def test_spatial_types(): diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qsymm-1.2.7/qsymm.egg-info/PKG-INFO new/qsymm-1.3.0/qsymm.egg-info/PKG-INFO --- old/qsymm-1.2.7/qsymm.egg-info/PKG-INFO 2019-12-04 14:18:56.000000000 +0100 +++ new/qsymm-1.3.0/qsymm.egg-info/PKG-INFO 2020-11-01 15:07:21.000000000 +0100 @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: qsymm -Version: 1.2.7 +Version: 1.3.0 Summary: Symmetry finder and symmetric Hamiltonian generator Home-page: https://gitlab.kwant-project.org/qt/qsymm Author: Qsymm authors @@ -78,5 +78,6 @@ Classifier: License :: OSI Approved :: BSD License Classifier: Intended Audience :: Science/Research Classifier: Programming Language :: Python :: 3.5 +Requires-Python: >=3.7 Description-Content-Type: text/markdown Provides-Extra: kwant diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qsymm-1.2.7/qsymm.egg-info/requires.txt new/qsymm-1.3.0/qsymm.egg-info/requires.txt --- old/qsymm-1.2.7/qsymm.egg-info/requires.txt 2019-12-04 14:18:56.000000000 +0100 +++ new/qsymm-1.3.0/qsymm.egg-info/requires.txt 2020-11-01 15:07:21.000000000 +0100 @@ -1,7 +1,7 @@ -numpy>=1.13 -scipy>=0.19 -sympy>=1.1 -tinyarray +numpy>=1.16.2 +scipy>=1.1 +sympy>=1.3.0 +tinyarray>=1.2.2 [kwant] kwant diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qsymm-1.2.7/setup.py new/qsymm-1.3.0/setup.py --- old/qsymm-1.2.7/setup.py 2019-11-28 15:38:22.000000000 +0100 +++ new/qsymm-1.3.0/setup.py 2020-10-27 09:40:52.000000000 +0100 @@ -2,23 +2,16 @@ # -*- coding: utf-8 -*- from setuptools import setup, find_packages -import sys - - -if sys.version_info < (3, 5): - print('Qsymm requires Python 3.5 or above.') - sys.exit(1) - # These requirements should not be updated to versions more # recent than required by Kwant: # https://gitlab.kwant-project.org/kwant/kwant/blob/master/setup.py#L584 # because we want to remain interoperable install_requires = [ - 'numpy>=1.13', # because we use __array_ufunc__ - 'scipy>=0.19', - 'sympy>=1.1', - 'tinyarray', + 'numpy>=1.16.2', + 'scipy>=1.1', + 'sympy>=1.3.0', + 'tinyarray>=1.2.2', ] extras_require = { @@ -71,6 +64,7 @@ extras_require=extras_require, tests_require=tests_require, setup_requires=setup_requires, + python_requires='>=3.7', version=version, cmdclass=cmdclass, ) _______________________________________________ openSUSE Commits mailing list -- commit@lists.opensuse.org To unsubscribe, email commit-le...@lists.opensuse.org List Netiquette: https://en.opensuse.org/openSUSE:Mailing_list_netiquette List Archives: https://lists.opensuse.org/archives/list/commit@lists.opensuse.org