[Yt-svn] yt: 2 new changesets

hg at spacepope.org hg at spacepope.org
Fri Jul 2 14:17:55 PDT 2010


hg Repository: yt
details:   yt/rev/14633162e2ac
changeset: 1857:14633162e2ac
user:      Matthew Turk <matthewturk at gmail.com>
date:
Fri Jul 02 14:17:41 2010 -0700
description:
Adding enzo testing mechanism to yt

hg Repository: yt
details:   yt/rev/9a04cc4046d5
changeset: 1858:9a04cc4046d5
user:      Matthew Turk <matthewturk at gmail.com>
date:
Fri Jul 02 14:17:52 2010 -0700
description:
Merging

diffstat:

 yt/extensions/enzo_test/DataProviders.py       |   69 -------
 yt/extensions/enzo_test/ProblemSetup.py        |   92 ----------
 yt/extensions/enzo_test/ProblemVerification.py |   78 --------
 yt/extensions/enzo_test/README                 |  275 ++++++++++++++++++++++++++++++
 yt/extensions/enzo_test/SimulationTests.py     |   70 -------
 yt/extensions/enzo_test/__init__.py            |   29 ---
 yt/extensions/enzo_test/halo_tests.py          |   48 +++++
 yt/extensions/enzo_test/hydro_tests.py         |   77 ++++++++
 yt/extensions/enzo_test/output_tests.py        |  117 +++++++++++++
 yt/extensions/enzo_test/particle_tests.py      |   59 ++++++
 yt/extensions/enzo_test/run_tests.py           |   13 +
 yt/extensions/enzo_test/runner.py              |  112 ++++++++++++
 yt/extensions/merger_tree.py                   |    2 +-
 yt/lagos/HaloFinding.py                        |    2 +
 14 files changed, 704 insertions(+), 339 deletions(-)

diffs (truncated from 1111 to 300 lines):

diff -r e1429ccfbce9 -r 9a04cc4046d5 yt/extensions/enzo_test/DataProviders.py
--- a/yt/extensions/enzo_test/DataProviders.py	Wed Jun 30 08:44:29 2010 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,69 +0,0 @@
-"""
-This is a definition of a class for providing data to a simulation
-verification method
-
-Author: Matthew Turk <matthewturk at gmail.com>
-Affiliation: KIPAC/SLAC/Stanford
-Homepage: http://yt.enzotools.org/
-License:
-  Copyright (C) 2007-2009 Matthew Turk.  All Rights Reserved.
-
-  This file is part of yt.
-
-  yt is free software; you can redistribute it and/or modify
-  it under the terms of the GNU General Public License as published by
-  the Free Software Foundation; either version 3 of the License, or
-  (at your option) any later version.
-
-  This program is distributed in the hope that it will be useful,
-  but WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-  GNU General Public License for more details.
-
-  You should have received a copy of the GNU General Public License
-  along with this program.  If not, see <http://www.gnu.org/licenses/>.
-"""
-
-from yt.mods import *
-
-class TestDataSource(object):
-    def provide(self, pf):
-        pass
-
-    def __call__(self, pf):
-        return self.provide(pf)
-
-class MaximumDensitySphere(TestDataSource):
-    def __init__(self, radius, unit):
-        self.radius = radius
-        self.unit = unit
-
-    def provide(self, pf):
-        v, c = pf.h.find_max("Density")
-        yield pf.h.sphere(c, self.radius/pf[self.unit])
-
-class HaloSpheres(TestDataSource):
-    def __init__(self, n_part):
-        self.n_part = n_part
-
-    def provide(self, pf):
-       halo_list = HaloFinder(pf)
-       for halo in halo_list:
-            if halo.get_size() < self.n_part: continue
-            yield halo.get_sphere()
-
-class Halos(TestDataSource):
-    def __init__(self):
-        pass
-
-    def provide(self, pf):
-       halo_list = HaloFinder(pf)
-       for halo in halo_list:
-            yield halo
-
-class EntireDataset(TestDataSource):
-    def __init__(self):
-        pass
-
-    def provide(self, pf):
-        yield pf.h.all_data()
diff -r e1429ccfbce9 -r 9a04cc4046d5 yt/extensions/enzo_test/ProblemSetup.py
--- a/yt/extensions/enzo_test/ProblemSetup.py	Wed Jun 30 08:44:29 2010 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,92 +0,0 @@
-"""
-This is a definition of a class for defining problem verification.
-
-Author: Matthew Turk <matthewturk at gmail.com>
-Affiliation: KIPAC/SLAC/Stanford
-Homepage: http://yt.enzotools.org/
-License:
-  Copyright (C) 2007-2009 Matthew Turk.  All Rights Reserved.
-
-  This file is part of yt.
-
-  yt is free software; you can redistribute it and/or modify
-  it under the terms of the GNU General Public License as published by
-  the Free Software Foundation; either version 3 of the License, or
-  (at your option) any later version.
-
-  This program is distributed in the hope that it will be useful,
-  but WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-  GNU General Public License for more details.
-
-  You should have received a copy of the GNU General Public License
-  along with this program.  If not, see <http://www.gnu.org/licenses/>.
-"""
-
-from yt.mods import *
-from yt.funcs import *
-from yt.extensions.EnzoSimulation import *
-from SimulationTests import test_registry
-
-from mercurial import commands, hg, ui
-import cPickle
-
-class Problem(object):
-    def __init__(self, name, pfname, repo_path="."):
-        self.name = name
-        self.pfname = pfname
-        self.simulation = EnzoSimulation(pfname)
-        self.tests, self.test_types = [], {}
-        self.init_repo(repo_path)
-        self._initialize_tests()
-
-    def _add_existing_test(self, test_type):
-        @wraps(test_type.__init__)
-        def test_wrapper(name, *args, **kwargs):
-            new_test = test_type(name, *args, **kwargs)
-            self.tests.append(new_test)
-        return test_wrapper
-
-    def _initialize_tests(self):
-        for name, test in test_registry.iteritems():
-            setattr(self, 'add_%s' % name, self._add_existing_test(test))
-            self.test_types[name] = self._add_existing_test(test)
-
-    def init_repo(self, path):
-        self.ui = ui.ui()
-        try:
-            self.repo = hg.repository(self.ui, path)
-        except:
-            print "CREATING:", path
-            self.repo = hg.repository(self.ui, path, create=True)
-
-    def load_repo_file(self, fn, identifier='tip'):
-        return self.repo[identifier][fn].data()
-
-    def run_tests(self):
-        all_results = {}
-        try:
-            for pf in self.simulation:
-                results = {}
-                for test in self.tests:
-                    results[test.name] = test(pf)
-                all_results[str(pf)] = results
-        except IOError:
-            pass
-        return all_results
-
-    def store_results(self, results):
-        base_fn = "results_%s.cpkl" % self.name
-        fn = self.repo.pathto(base_fn)
-        cPickle.dump(results, open(fn, "w"))
-        if base_fn not in self.repo['tip'].manifest():
-            commands.add(self.ui, self.repo, fn)
-        message = "Committing results from current run"
-        commands.commit(self.ui, self.repo, fn, message=message)
-        print "Committed"
-
-    def __call__(self):
-        results = self.run_tests()
-        self.store_results((self.tests, results))
-
-# repo['tip']['yt/lagos/__init__.py'].data()
diff -r e1429ccfbce9 -r 9a04cc4046d5 yt/extensions/enzo_test/ProblemVerification.py
--- a/yt/extensions/enzo_test/ProblemVerification.py	Wed Jun 30 08:44:29 2010 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,78 +0,0 @@
-"""
-This is a definition of a set of classes for defining problem verification
-methods, along with storage mechanisms.
-
-Author: Matthew Turk <matthewturk at gmail.com>
-Affiliation: KIPAC/SLAC/Stanford
-Homepage: http://yt.enzotools.org/
-License:
-  Copyright (C) 2007-2009 Matthew Turk.  All Rights Reserved.
-
-  This file is part of yt.
-
-  yt is free software; you can redistribute it and/or modify
-  it under the terms of the GNU General Public License as published by
-  the Free Software Foundation; either version 3 of the License, or
-  (at your option) any later version.
-
-  This program is distributed in the hope that it will be useful,
-  but WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-  GNU General Public License for more details.
-
-  You should have received a copy of the GNU General Public License
-  along with this program.  If not, see <http://www.gnu.org/licenses/>.
-"""
-
-from yt.mods import *
-
-class VerificationMechanism(object):
-    def __init__(self):
-        pass
-
-    def __call__(self, pf, plot):
-        return self.run(pf)
-
-class ProfileVerification(VerificationMechanism):
-    def __init__(self, q1, q2,
-                 q1_limits = None, q1_nbins = 64):
-        VerificationMechanism.__init__(self)
-        self.q1 = q1
-        self.q2 = q2
-        self.q1_limits = q1_limits
-        self.q1_nbins = q1_nbins
-
-    def _setup_profile(self):
-        pass
-
-    def run(self, data):
-        limits = self.q1_limits
-        if limits is None:
-            limits = data.quantities["Extrema"](
-                self.q1, lazy_reader=True)[0]
-        prof = BinnedProfile1D(
-            data, self.q1_nbins, self.q1,
-            limits[0], limits[1], lazy_reader=True)
-        prof.add_fields(self.q2)
-        return na.array([prof[self.q1], prof[self.q2]])
-
-class RadialProfileVerification(VerificationMechanism):
-    def __init__(self, radius, unit, q2,
-                 r_limits = None, q2_limits = None,
-                 r_nbins = 64, q2_nbins = 64):
-        VerificationMechanism.__init__(self)
-        self.radius = radius
-        self.unit = unit
-        self.q2 = q2
-        self.q1_limits = q1_limits
-        self.q2_limits = q2_limits
-        self.q1_nbins = q1_nbins
-        self.q2_nbins = q2_nbins
-
-class TotalMassVerification(VerificationMechanism):
-    def __init__(self):
-        pass
-
-    def run(self, data):
-        return data.quantities["TotalQuantity"](
-                "CellMassMsun", lazy_reader=True)
diff -r e1429ccfbce9 -r 9a04cc4046d5 yt/extensions/enzo_test/README
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/yt/extensions/enzo_test/README	Fri Jul 02 14:17:52 2010 -0700
@@ -0,0 +1,275 @@
+Enzo Regression Test Runner
+===========================
+
+This is an evolving sketch of how Enzo regression tests might work.  They will
+be based on a python test runner, called from LCA test, that will output images
+as well as success/failure for a set of tests.
+
+The interface is still evolving, but we're working on both creating something
+fun, easy to write tests for, and clear.
+
+This is still a work in progress!  Things might change without notice!
+
+What Is A Test And How To Write One
+-----------------------------------
+
+A test at its most fundamental level makes some value from one or multiple
+outputs from a simulation and then compares those outputs to the outputs from
+some previous simulation.
+
+Each test follows a fixed interface, but we're trying to provide a couple
+mechanisms to make test writing easier.  To implement a test, you have to
+define a python class that subclasses from a particular type of test case.
+
+Your new test must implement the following interface, or it will fail:
+
+    name
+        All tests have to have the variable "name" defined in the class
+        definition.  This is a unique key that identifies the test, and it is
+        used to self-register every test in a global registry.  This will play
+        into filenames, so it's for the best if it doesn't contain spaces or
+        other unacceptable filename characters.
+
+    setup(self)
+        If you subclass from the YT test case or another test case base
+        class that implements setup, this may not be necessary.  This is
+        where all the pre-testing operation occurs, and is useful if you
+        want to write a bunch of tests that have the same setup.  Not return
+        value is needed.
+
+    run(self)
+        This is where the testing occurs and some value generated -- this value
+        can be an array, a number, a string, any Python or NumPy base type.
+        (For various reasons, YT objects can't be considered results, only
+        their base components.)  When this value is prepared, it needs to be
+        stored as the property "result" on the object -- for example, you might



More information about the yt-svn mailing list