def create_inner_product(self, description): # try: ip_type = description["type"] except: # Default setting print( "Warning: Using fall-back inner product of type 'InhomogeneousInnerProduct'!" ) # TODO: Maybe change to homogeneous one? ip_type = "InhomogeneousInnerProduct" if ip_type == "HomogeneousInnerProduct": from WaveBlocksND.HomogeneousInnerProduct import HomogeneousInnerProduct QE = self.create_quadrature(description["delegate"]) IP = HomogeneousInnerProduct(QE) elif ip_type == "InhomogeneousInnerProduct": from WaveBlocksND.InhomogeneousInnerProduct import InhomogeneousInnerProduct QE = self.create_quadrature(description["delegate"]) IP = InhomogeneousInnerProduct(QE) else: raise ValueError("Unknown inner product type {}".format(ip_type)) return IP
def __init__(self, threshold=1e-8): r"""Initialize an oracle for estimating if a specific overlap integral :math:`\langle \Psi_k | O | \Psi_l \rangle` is approximately zero. The oracle works by approximating :math:`\langle \Psi_k | \Psi_l \rangle` with a Gaussian integral. If .. math:: \langle \Psi_k | \Psi_l \rangle \approx \langle \Psi_k^G | \Psi_l^G \rangle \leq \tau the value :math:`\langle \Psi_k | O | \Psi_l \rangle` is considered to be zero. Of course this may fail depending on the form of the operator :math:`O` or the basis shape :math:`\mathfrak{K}`. .. warning:: This code is highly experimental. :param threshold: The threshold :math:`\tau` in the Gaussian integral criterion. The default value of :math:`10^{-8}` should be reasonable in most cases. """ self._threshold = threshold self._ip = InhomogeneousInnerProduct(GaussianIntegral())
class SparsityOracleGIHAWP(SparsityOracle): r"""This class implements an oracle by looking at Gaussian integrals. """ def __init__(self, threshold=1e-8): r"""Initialize an oracle for estimating if a specific overlap integral :math:`\langle \Psi_k | O | \Psi_l \rangle` is approximately zero. The oracle works by approximating :math:`\langle \Psi_k | \Psi_l \rangle` with a Gaussian integral. If .. math:: \langle \Psi_k | \Psi_l \rangle \approx \langle \Psi_k^G | \Psi_l^G \rangle \leq \tau the value :math:`\langle \Psi_k | O | \Psi_l \rangle` is considered to be zero. Of course this may fail depending on the form of the operator :math:`O` or the basis shape :math:`\mathfrak{K}`. .. warning:: This code is highly experimental. :param threshold: The threshold :math:`\tau` in the Gaussian integral criterion. The default value of :math:`10^{-8}` should be reasonable in most cases. """ self._threshold = threshold self._ip = InhomogeneousInnerProduct(GaussianIntegral()) def is_not_zero(self, pacbra, packet, component=None): r"""Try to estimate if the overlap integral :math:`\langle \Psi_k | \Psi_l \rangle` is zero or at least negligible. :param pacbra: The packet :math:`\Psi_k` that is used for the 'bra' part. :param packet: The packet :math:`\Psi_l` that is used for the 'ket' part. :param component: The component of the packet that is considered. :return: ``True`` or ``False`` whether the inner product is negligible. """ Q = self._ip.quadrature(pacbra, packet, diag_component=component, summed=True) return abs(abs(Q) > self._threshold)