Coverage for kwant/_common.py : 81%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# Copyright 2011-2015 Kwant authors. # # This file is part of Kwant. It is subject to the license terms in the file # LICENSE.rst found in the top-level directory of this distribution and at # http://kwant-project.org/license. A list of Kwant authors can be found in # the file AUTHORS.rst at the top-level directory of this distribution and at # http://kwant-project.org/authors.
"""Class of warnings about a deprecated feature of Kwant.
DeprecationWarning has been made invisible by default in Python 2.7 in order to not confuse non-developer users with warnings that are not relevant to them. In the case of Kwant, by far most users are developers, so we feel that a KwantDeprecationWarning that is visible by default is useful. """
"""Class for errors that occur in user-provided code.
Usually users will define value functions that Kwant calls in order to evaluate the Hamiltonian. If one of these function raises an exception then it is caught and this error is raised in its place. This makes it clear that the error is from the user's code (and not a bug in Kwant) and also makes it possible for any libraries that wrap Kwant to detect when a user's function causes an error. """
"""Class that replaces unavailable extension modules in the Kwant namespace.
Some extensions for Kwant (e.g. 'kwant.continuum') require additional dependencies that are not required for core functionality. When the additional dependencies are not installed an instance of this class will be inserted into Kwant's root namespace to simulate the presence of the extension and inform users that they need to install additional dependencies.
See https://mail.python.org/pipermail/python-ideas/2012-May/014969.html for more details. """
self.name = name self.dependencies = ', '.join(dependencies)
msg = ("'{}' is not available because one or more of the following " "dependencies are not installed: {}") raise RuntimeError(msg.format(self.name, self.dependencies))
if msg is None: msg = "Expecting an instance of {}.".format(typ.__name__) raise TypeError(msg)
"""Turn rng into a random number generator instance
If rng is None, return the RandomState instance used by np.random. If rng is an integer, return a new RandomState instance seeded with rng. If rng is already a RandomState instance, return it. Otherwise raise ValueError. """ 'randint', 'choice')): raise ValueError("Expecting a seed or an object that offers the " "numpy.random.RandomState interface.")
"""Get the names of the parameters to 'func' and whether it takes kwargs.
Returns ------- required_params : list Names of positional, and keyword only parameters that do not have a default value and that appear in the signature of 'func'. default_params : list Names of parameters that have a default value. takes_kwargs : bool True if 'func' takes '**kwargs'. """
# Signature.parameters is an *ordered mapping* if v.kind in (inspect.Parameter.POSITIONAL_OR_KEYWORD, inspect.Parameter.KEYWORD_ONLY) and v.default is inspect._empty] if v.default is not inspect._empty] for i in pars.values()) |