Profiling gives very different predictions of best algorithm

Rick rpmuller at gmail.com
Fri May 1 18:21:11 EDT 2009


Sorry, I'm running the function:

def debugsuite():
    import profile,pstats
    profile.run('runsuite()','prof')
    prof = pstats.Stats('prof')
    prof.strip_dirs().sort_stats('time').print_stats(15)

where runsuite() runs the Hartree-Fock energy of a water molecule, and
is given by:


import unittest,logging
from PyQuante.CI import CIS
from PyQuante.Molecule import Molecule
from PyQuante.MP import MP2
from PyQuante.OEP import oep_hf,oep_hf_an
from PyQuante.PyQuante2 import SCF,SubspaceSolver,DmatSolver

class UnitTests(unittest.TestCase):
    def setUp(self):
        from PyQuante.Molecule import Molecule
        self.h2o = Molecule('h2o',[(8,(0,0,0)),(1,(1.,0,0)),(1,
(0,1.,0))],
                            units="Angstrom")

    def testH2OHF(self):
        h2o_hf = SCF(self.h2o,method='HF')
        h2o_hf.iterate()
        self.assertAlmostEqual(h2o_hf.energy,-76.011755864850628,4)

def runsuite(verbose=True):
    # To use psyco, uncomment this line:
    #import psyco; psyco.full()
    if verbose: verbosity=2
    else: verbosity=1
    # If you want more output, uncomment this line:
    #logging.basicConfig(format="%(message)s",level=logging.DEBUG)
    suite = unittest.TestLoader().loadTestsFromTestCase(UnitTests)
    unittest.TextTestRunner(verbosity=verbosity).run(suite)
    # Running without verbosity is equivalent to replacing the above
    # two lines with the following:
    #unittest.main()
    return


On May 1, 3:50 pm, Terry Reedy <tjre... at udel.edu> wrote:
> Rick Muller wrote:
> > I'm the main programmer for the PyQuante package, a quantum chemistry
> > package in Python. I'm trying to speed up one of my rate determining
> > steps. Essentially, I have to decide between two algorithms:
>
> > 1. Packed means that I compute N**4/8 integrals, and then do a bunch
> > of indexing operations to unpack;
> > 2. Unpacked means that I compute all N**4 integrals, but don't have to
> > do any indexing.
>
> > Raw timing the two options show that packed is clearly faster (12.5
> > sec vs 20.6 sec). However, the profilings show very different results.
> > I have the results below. Clearly I'm going to use the packed scheme.
> > My question to the mailing list is what am I doing wrong with my
> > profiling that it shows such poor predictions?
>
> That *might* be easier to answer if you were to show exactly what you
> did to get the odd-looking results ;-)




More information about the Python-list mailing list