当前位置: 首页>>代码示例>>Python>>正文


Python testing.assert_allclose方法代码示例

本文整理汇总了Python中numpy.testing.assert_allclose方法的典型用法代码示例。如果您正苦于以下问题:Python testing.assert_allclose方法的具体用法?Python testing.assert_allclose怎么用?Python testing.assert_allclose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在numpy.testing的用法示例。


在下文中一共展示了testing.assert_allclose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_eri_gamma

# 需要导入模块: from numpy import testing [as 别名]
# 或者: from numpy.testing import assert_allclose [as 别名]
def test_eri_gamma(self):
        """Tests all ERI implementations: with and without symmetries (gamma-point only)."""
        for eri in (ktd.PhysERI, ktd.PhysERI4, ktd.PhysERI8):
            if eri is not ktd.PhysERI8 or self.test8:
                try:
                    e = eri(self.model_krhf)
                    m = e.tdhf_full_form(0)

                    # Test matrix vs ref
                    testing.assert_allclose(m, retrieve_m_khf(e, 0), atol=1e-11)

                    # Test matrix vs pyscf
                    testing.assert_allclose(self.ref_m_gamma, m, atol=1e-12)
                except Exception:
                    print("When testing {} the following exception occurred:".format(eri))
                    raise 
开发者ID:pyscf,项目名称:pyscf,代码行数:18,代码来源:test_krhf_slow.py

示例2: test_eri

# 需要导入模块: from numpy import testing [as 别名]
# 或者: from numpy.testing import assert_allclose [as 别名]
def test_eri(self):
        """Tests all ERI implementations: with and without symmetries."""
        for eri in (PhysERI, PhysERI4, PhysERI8):
            try:
                e = eri(self.model_rhf)
                m = e.tdhf_full_form()

                # Test matrix vs ref
                testing.assert_allclose(m, retrieve_m_hf(e), atol=1e-14)

                # Test matrix vs pyscf
                testing.assert_allclose(self.ref_m_rhf, m, atol=1e-14)
                vals, vecs = eig(m, nroots=self.td_model_rhf.nroots)
                testing.assert_allclose(vals, self.td_model_rhf.e, atol=1e-5)
            except Exception:
                print("When testing {} the following exception occurred:".format(eri))
                raise 
开发者ID:pyscf,项目名称:pyscf,代码行数:19,代码来源:test_rhf_slow.py

示例3: test_class

# 需要导入模块: from numpy import testing [as 别名]
# 或者: from numpy.testing import assert_allclose [as 别名]
def test_class(self):
        """Tests container behavior."""
        model = TDRHF(self.model_rhf)
        model.nroots = self.td_model_rhf.nroots
        assert model.fast
        e, xy = model.kernel()
        model.fast = False
        model.kernel()
        # Slow vs fast
        testing.assert_allclose(model.e, e)
        assert_vectors_close(model.xy, xy)
        # ... vs ref
        testing.assert_allclose(model.e, self.td_model_rhf.e, atol=1e-12)
        assert_vectors_close(model.xy, self.td_model_rhf.xy, atol=1e-12)
        # Test real
        testing.assert_allclose(model.e.imag, 0, atol=1e-8) 
开发者ID:pyscf,项目名称:pyscf,代码行数:18,代码来源:test_rhf_slow.py

示例4: test_cplx

# 需要导入模块: from numpy import testing [as 别名]
# 或者: from numpy.testing import assert_allclose [as 别名]
def test_cplx(self):
        """Tests whether complex conjugation is handled correctly."""
        # Perform mf calculation
        model_rhf = RHF(self.cell)
        model_rhf.kernel()

        # Add random phases
        import numpy
        numpy.random.seed(0)
        p = numpy.exp(2.j * numpy.pi * numpy.random.rand(model_rhf.mo_coeff.shape[1]))
        model_rhf.mo_coeff = model_rhf.mo_coeff * p[numpy.newaxis, :]

        m_ref = PhysERI(model_rhf).tdhf_full_form()

        td_model_rhf = TDRHF(model_rhf)
        assert not td_model_rhf.fast
        td_model_rhf.kernel()
        with self.assertRaises(ValueError):
            td_model_rhf.fast = True
            td_model_rhf.kernel()

        self.assertIsInstance(td_model_rhf.eri, PhysERI4)
        m = td_model_rhf.eri.tdhf_full_form()

        testing.assert_allclose(m, m_ref, atol=1e-14) 
开发者ID:pyscf,项目名称:pyscf,代码行数:27,代码来源:test_rhf_slow.py

示例5: test_eri

# 需要导入模块: from numpy import testing [as 别名]
# 或者: from numpy.testing import assert_allclose [as 别名]
def test_eri(self):
        """Tests all ERI implementations: with and without symmetries."""
        for eri in (ktd.PhysERI, ktd.PhysERI4, ktd.PhysERI8):
            # Note that specific combintation of k-points results in real orbitals and allows testing PhysERI8
            try:
                e = eri(self.model_krhf)
                m = e.tdhf_full_form()

                # Test matrix vs ref
                testing.assert_allclose(m, retrieve_m_hf(e), atol=1e-11)

                # Test matrix vs pyscf
                testing.assert_allclose(self.ref_m, m, atol=1e-5)
            except Exception:
                print("When testing {} the following exception occurred:".format(eri))
                raise 
开发者ID:pyscf,项目名称:pyscf,代码行数:18,代码来源:test_krhf_slow_gamma.py

示例6: test_class

# 需要导入模块: from numpy import testing [as 别名]
# 或者: from numpy.testing import assert_allclose [as 别名]
def test_class(self):
        """Tests container behavior."""
        model = kproxy_supercell.TDProxy(self.model_krhf, "hf", [self.k, 1, 1], density_fitting_hf)
        model.nroots = self.td_model_krhf.nroots
        assert not model.fast
        model.kernel()
        testing.assert_allclose(model.e, self.td_model_krhf.e, atol=1e-5)
        # Test real
        testing.assert_allclose(model.e.imag, 0, atol=1e-8)

        nocc = nvirt = 4
        testing.assert_equal(model.xy.shape, (len(model.e), 2, self.k, self.k, nocc, nvirt))

        # Test only non-degenerate roots
        d = abs(model.e[1:] - model.e[:-1]) < 1e-8
        d = numpy.logical_or(numpy.concatenate(([False], d)), numpy.concatenate((d, [False])))
        d = numpy.logical_not(d)
        assert_vectors_close(self.td_model_krhf.xy[d], model.xy[d], atol=1e-5) 
开发者ID:pyscf,项目名称:pyscf,代码行数:20,代码来源:test_kproxy_supercell_hf.py

示例7: test_eri

# 需要导入模块: from numpy import testing [as 别名]
# 或者: from numpy.testing import assert_allclose [as 别名]
def test_eri(self):
        """Tests ERI."""
        for frozen in (1, [0, 1], [0, -1]):
            try:
                e = kproxy_supercell.PhysERI(self.model_krhf, "hf", [self.k, 1, 1], density_fitting_hf, frozen=frozen)
                m = e.tdhf_full_form()

                ref_e = krhf_slow_supercell.PhysERI4(self.model_krhf, frozen=frozen)
                ref_m = ref_e.tdhf_full_form()

                # Test matrix vs ref
                testing.assert_allclose(m, ref_m, atol=1e-11)

            except Exception:
                print("When testing class with frozen={} the following exception occurred:".format(repr(frozen)))
                raise 
开发者ID:pyscf,项目名称:pyscf,代码行数:18,代码来源:test_kproxy_supercell_hf.py

示例8: test_class

# 需要导入模块: from numpy import testing [as 别名]
# 或者: from numpy.testing import assert_allclose [as 别名]
def test_class(self):
        """Tests container behavior."""
        model = kproxy.TDProxy(self.model_krhf, "hf", [self.k, 1, 1], density_fitting_hf)
        model.nroots = self.td_model_krhf.nroots
        assert not model.fast
        model.kernel()
        for i in range(self.k):
            try:
                testing.assert_allclose(model.e[i], self.td_model_krhf.e[i], atol=1e-5)
                # Test real
                testing.assert_allclose(model.e[i].imag, 0, atol=1e-8)

                nocc = nvirt = 4
                testing.assert_equal(model.xy[i].shape, (len(model.e[i]), 2, self.k, nocc, nvirt))

                assert_vectors_close(self.td_model_krhf.xy[i], model.xy[i], atol=1e-5)

            except Exception:
                print("When testing model @k={:d} the following exception occurred:".format(i))
                raise 
开发者ID:pyscf,项目名称:pyscf,代码行数:22,代码来源:test_kproxy_hf.py

示例9: test_eri

# 需要导入模块: from numpy import testing [as 别名]
# 或者: from numpy.testing import assert_allclose [as 别名]
def test_eri(self):
        """Tests all ERI implementations: with and without symmetries."""
        for eri in (ktd.PhysERI, ktd.PhysERI4, ktd.PhysERI8):
            if not eri == ktd.PhysERI8 or self.test8:
                try:
                    e = eri(self.model_krhf)
                    m = e.tdhf_full_form()

                    # Test matrix vs ref
                    testing.assert_allclose(m, retrieve_m_hf(e), atol=1e-11)

                    # Test matrix vs pyscf
                    testing.assert_allclose(self.ref_m, m[numpy.ix_(self.ov_order, self.ov_order)], atol=1e-5)
                except Exception:
                    print("When testing {} the following exception occurred:".format(eri))
                    raise 
开发者ID:pyscf,项目名称:pyscf,代码行数:18,代码来源:test_krhf_slow_supercell.py

示例10: test_iter_s

# 需要导入模块: from numpy import testing [as 别名]
# 或者: from numpy.testing import assert_allclose [as 别名]
def test_iter_s(self):
        """CCS iterations."""
        e1, t1 = cc.kernel_ground_state_s(self.ccsd)
        # # TODO: MRCC energy is way off expected
        # testing.assert_allclose(self.mf.e_tot + e1, -74.841686696943, atol=1e-4)

        import pyscf.cc
        mf = scf.RHF(self.mol).set(conv_tol = 1e-11).run()
        cc1 = pyscf.cc.UCCSD(mf, frozen=1)
        old_update_amps = cc1.update_amps
        def update_amps(t1, t2, eris):
            t1, t2 = old_update_amps(t1, t2, eris)
            return t1, (t2[0]*0, t2[1]*0, t2[2]*0)
        cc1.update_amps = update_amps
        cc1.kernel()
        testing.assert_allclose(self.mf.e_tot + e1, cc1.e_tot, atol=1e-4) 
开发者ID:pyscf,项目名称:pyscf,代码行数:18,代码来源:test.py

示例11: test_iter_d

# 需要导入模块: from numpy import testing [as 别名]
# 或者: from numpy.testing import assert_allclose [as 别名]
def test_iter_d(self):
        """CCD iterations."""
        e2, t2 = cc.kernel_ground_state_d(self.ccsd)
        # # TODO: MRCC energy is way off expected
        # testing.assert_allclose(self.mf.e_tot + e2, -76.177931897355, atol=1e-4)

        import pyscf.cc
        cc1 = scf.RHF(self.mol).run(conv_tol = 1e-11).apply(pyscf.cc.CCSD)
        cc1.frozen = 1
        old_update_amps = cc1.update_amps
        def update_amps(t1, t2, eris):
            t1, t2 = old_update_amps(t1, t2, eris)
            return t1*0, t2
        cc1.update_amps = update_amps
        cc1.kernel()
        testing.assert_allclose(self.mf.e_tot + e2, cc1.e_tot, atol=1e-4) 
开发者ID:pyscf,项目名称:pyscf,代码行数:18,代码来源:test.py

示例12: test_conversion

# 需要导入模块: from numpy import testing [as 别名]
# 或者: from numpy.testing import assert_allclose [as 别名]
def test_conversion(self):
        """Tests common conversions."""
        e = PhysERI(self.model_rhf)

        full = e.tdhf_full_form()
        a, b = e.tdhf_ab_form()
        mk, k = e.tdhf_mk_form()

        testing.assert_allclose(full, ab2full(a, b))
        testing.assert_allclose(full, mkk2full(mk, k), atol=1e-13)

        _a, _b = full2ab(full)
        testing.assert_allclose(a, _a)
        testing.assert_allclose(b, _b)
        _a, _b = mkk2ab(mk, k)
        testing.assert_allclose(a, _a)
        testing.assert_allclose(b, _b)

        _mk, _k = full2mkk(full)
        testing.assert_allclose(mk, _mk)
        testing.assert_allclose(k, _k)
        _mk, _k = ab2mkk(a, b)
        testing.assert_allclose(mk, _mk)
        testing.assert_allclose(k, _k) 
开发者ID:pyscf,项目名称:pyscf,代码行数:26,代码来源:test_rhf_slow.py

示例13: test_class

# 需要导入模块: from numpy import testing [as 别名]
# 或者: from numpy.testing import assert_allclose [as 别名]
def test_class(self):
        """Tests container behavior."""
        model = TDRHF(self.model_rhf)
        model.nroots = self.td_model_rhf.nroots
        assert model.fast
        e, xy = model.kernel()
        model.fast = False
        model.kernel()
        # Slow vs fast
        testing.assert_allclose(model.e, e)
        assert_vectors_close(model.xy, xy)
        # ... vs ref
        testing.assert_allclose(model.e, self.td_model_rhf.e, atol=1e-5)
        assert_vectors_close(model.xy, self.td_model_rhf.xy, atol=1e-2)
        # Test real-valued
        testing.assert_allclose(model.e.imag, 0, atol=1e-8) 
开发者ID:pyscf,项目名称:pyscf,代码行数:18,代码来源:test_rhf_slow.py

示例14: test_dft_1d

# 需要导入模块: from numpy import testing [as 别名]
# 或者: from numpy.testing import assert_allclose [as 别名]
def test_dft_1d(self, test_data_1d):
        """Test the discrete Fourier transform function on one-dimensional data."""

        da = test_data_1d
        Nx = len(da)
        dx = float(da.x[1] - da.x[0]) if 'x' in da.dims else 1

        # defaults with no keyword args
        ft = xrft.dft(da, detrend='constant')
        # check that the frequency dimension was created properly
        assert ft.dims == ('freq_x',)
        # check that the coords are correct
        freq_x_expected = np.fft.fftshift(np.fft.fftfreq(Nx, dx))
        npt.assert_allclose(ft['freq_x'], freq_x_expected)
        # check that a spacing variable was created
        assert ft['freq_x_spacing'] == freq_x_expected[1] - freq_x_expected[0]
        # make sure the function is lazy
        assert isinstance(ft.data, type(da.data))
        # check that the Fourier transform itself is correct
        data = (da - da.mean()).values
        ft_data_expected = np.fft.fftshift(np.fft.fft(data))
        # because the zero frequency component is zero, there is a numerical
        # precision issue. Fixed by setting atol
        npt.assert_allclose(ft_data_expected, ft.values, atol=1e-14)


        # redo without removing mean
        ft = xrft.dft(da)
        ft_data_expected = np.fft.fftshift(np.fft.fft(da))
        npt.assert_allclose(ft_data_expected, ft.values)

        # redo with detrending linear least-square fit
        ft = xrft.dft(da, detrend='linear')
        da_prime = sps.detrend(da.values)
        ft_data_expected = np.fft.fftshift(np.fft.fft(da_prime))
        npt.assert_allclose(ft_data_expected, ft.values, atol=1e-14)

        if 'x' in da and not da.chunks:
            da['x'].values[-1] *= 2
            with pytest.raises(ValueError):
                ft = xrft.dft(da) 
开发者ID:xgcm,项目名称:xrft,代码行数:43,代码来源:test_xrft.py

示例15: test_dft_1d_time

# 需要导入模块: from numpy import testing [as 别名]
# 或者: from numpy.testing import assert_allclose [as 别名]
def test_dft_1d_time(self):
        """Test the discrete Fourier transform function on timeseries data."""
        time = pd.date_range('2000-01-01', '2001-01-01', closed='left')
        Nt = len(time)
        da = xr.DataArray(np.random.rand(Nt), coords=[time], dims=['time'])

        ft = xrft.dft(da)

        # check that frequencies are correct
        dt = (time[1] - time[0]).total_seconds()
        freq_time_expected = np.fft.fftshift(np.fft.fftfreq(Nt, dt))
        npt.assert_allclose(ft['freq_time'], freq_time_expected) 
开发者ID:xgcm,项目名称:xrft,代码行数:14,代码来源:test_xrft.py


注:本文中的numpy.testing.assert_allclose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。