def _test_logdetM(self, kappa): "Test log(det(M))." nx = kappa.rows() self.assertRaises(RuntimeError, lambda msg: isle.logdetM(isle.HubbardFermiMatrixDia(kappa, 1, 1), isle.CDVector(nx), isle.Species.PARTICLE), msg="logdetM must throw a RuntimeError when called with mu != 0. If this bug has been fixed, update the unit test!") for nt, mu, sigmaKappa, species, rep in itertools.product((4, 8, 32), [0], (-1, 1), (isle.Species.PARTICLE, isle.Species.HOLE), range(N_REP)): hfm = isle.HubbardFermiMatrixDia(kappa/nt, mu/nt, sigmaKappa) phi = _randomPhi(nx*nt) plain = isle.logdet(isle.Matrix(hfm.M(phi, species))) viaLU = isle.logdetM(hfm, phi, species) self.assertAlmostEqual(plain, viaLU, places=10, msg="Failed check log(det(M)) in repetition {}".format(rep)\ + "for nt={}, mu={}, sigmaKappa={}, species={}:".format(nt, mu, sigmaKappa, species)\ + "\nplain = {}".format(plain) \ + "\nviaLU = {}".format(viaLU))
def __call__(self, stage, itr): """!Record logdet.""" if self.alpha == 1: self.nextItem("particles")[...] = isle.logdetM( self.hfm, stage.phi, isle.Species.PARTICLE) self.nextItem("holes")[...] = isle.logdetM(self.hfm, stage.phi, isle.Species.HOLE) else: # use dense, slow numpy routine to get stable result ld = np.linalg.slogdet( isle.Matrix(self.hfm.M(-1j * stage.phi, isle.Species.PARTICLE))) self.nextItem("particles")[...] = np.log(ld[0]) + ld[1] ld = np.linalg.slogdet( isle.Matrix(self.hfm.M(-1j * stage.phi, isle.Species.HOLE))) self.nextItem("holes")[...] = np.log(ld[0]) + ld[1]
def __call__(self, stage, itr): """!Record logdet.""" if self.alpha == 1: for species, logdet in self.logdet.items(): logdet.append(isle.logdetM(self.hfm, stage.phi, species)) else: for species, logdet in self.logdet.items(): # use dense, slow numpy routine to get stable result ld = np.linalg.slogdet( isle.Matrix(self.hfm.M(-1j * stage.phi, species))) logdet.append(np.log(ld[0]) + ld[1])
def _test_logdetM(self, HFM, kappa): "Test log(det(M))." nx = kappa.rows() for nt, beta, mu, sigmaKappa in product((2, 4, 8, 32), (3, 6), [0, 0.1, 0.5, 1.0, 2.0], (-1, 1)): hfm = HFM(kappa * beta / nt, mu * beta / nt, sigmaKappa) for species, (real, imag), rep in product((isle.Species.PARTICLE, isle.Species.HOLE), ((True, False), (False, True), (True, True)), range(N_REP)): phi = _randomPhi(nx * nt, real=real, imag=imag) plain = isle.logdet(isle.Matrix(hfm.M(phi, species))) viaLU = isle.logdetM(hfm, phi, species) self.assertAlmostEqual(plain, viaLU, places=5, msg="Failed check log(det(M)) in repetition {}".format(rep) + "\nfor nt={}, beta={}, mu={}, sigmaKappa={}, species={}, real={}, imag={}" .format(nt, beta, mu, sigmaKappa, species, real, imag) + "\n plain = {}".format(plain) + "\n viaLU = {}".format(viaLU))