[Yt-svn] yt-commit r1326 - in trunk: scripts yt/lagos

mturk at wrangler.dreamhost.com mturk at wrangler.dreamhost.com
Mon Jun 8 13:20:57 PDT 2009


Author: mturk
Date: Mon Jun  8 13:20:56 2009
New Revision: 1326
URL: http://yt.spacepope.org/changeset/1326

Log:
Added new stuff to the embedded yt code -- now a separate node can
interactively do ANYthing to the data via a proxy class.

So when you start up eyt, you can now either run things through %px or you can
manually manipulate the pf object, which will grab data as necessary (and
operate on it in SERIAL) on the local node.



Modified:
   trunk/scripts/eyt
   trunk/yt/lagos/HierarchyType.py
   trunk/yt/lagos/OutputTypes.py

Modified: trunk/scripts/eyt
==============================================================================
--- trunk/scripts/eyt	(original)
+++ trunk/scripts/eyt	Mon Jun  8 13:20:56 2009
@@ -58,7 +58,13 @@
     result = mec.pull("__tmp", targets=targets)
     return result
 
-hierarchy_information = mec_eval("enzo.hierarchy_information", [0])[0]
+class enzo_module_proxy(object):
+    pass
+
+enzo = enzo_module_proxy()
+enzo.hierarchy_information = mec_eval("enzo.hierarchy_information", [0])[0]
+enzo.conversion_factors = mec_eval("enzo.conversion_factors", [0])[0]
+enzo.yt_parameter_file = mec_eval("enzo.yt_parameter_file", [0])[0]
 
 def get_grid_field(grid_index, field_name, raw=False):
     """
@@ -69,16 +75,63 @@
     are returned.  This will include ghost zones, and derived fields are
     inaccessible.
     """
-    proc = int(hierarchy_information["GridProcs"][grid_index])
+    proc = int(enzo.hierarchy_information["GridProcs"][grid_index])
     if not raw: # go through yt
         result = mec_eval("pf.h.grids[%s]['%s']" % (
                     grid_index, field_name), [proc])[0]
     else: # go through enzo module
         result = mec_eval("enzo.grid_data[%s + 1]['%s']" % (
-                    grid_index, field_name), [proc])[0]
+                    grid_index, field_name), [proc])[0].swapaxes(0,2)
     return result
 
+from yt.lagos import EnzoStaticOutputInMemory, EnzoHierarchyInMemory
+from yt.lagos.HierarchyType import _data_style_funcs
+from yt.lagos.DataReadingFuncs import BaseDataQueue
+
+class EnzoHierarchyProxy(EnzoHierarchyInMemory):
+    _data_style = 'proxy'
+    def _setup_field_lists(self):
+        self.field_list = mec_eval("pf.h.field_list", [0])[0]
+
+    def _obtain_enzo(self):
+        return enzo
+
+class EnzoStaticOutputProxy(EnzoStaticOutputInMemory):
+    _data_style = 'proxy'
+    _hierarchy_class = EnzoHierarchyProxy
+    def _obtain_enzo(self):
+        return enzo
+
+def _read_proxy_slice(self, grid, field, axis, coord):
+    data = get_grid_field(grid.id - 1, field, raw=True)
+    sl = [slice(3,-3), slice(3,-3), slice(3,-3)]
+    sl[axis] = slice(coord + 3, coord + 4)
+    sl = tuple(reversed(sl))
+    return data[sl].swapaxes(0,2)
+
+class DataQueueProxy(BaseDataQueue):
+    def __init__(self, ghost_zones = 3):
+        self.my_slice = (slice(ghost_zones, -ghost_zones),
+                         slice(ghost_zones, -ghost_zones),
+                         slice(ghost_zones, -ghost_zones))
+        BaseDataQueue.__init__(self)
+
+    def _read_set(self, grid, field):
+        data = get_grid_field(grid.id - 1, field, raw=True)
+        return data[self.my_slice]
+
+    def modify(self, field):
+        return field.swapaxes(0,2)
+
+def proxy_exception(*args, **kwargs):
+    return KeyError
+
+_data_style_funcs['proxy'] = \
+    (None, None, None, _read_proxy_slice, proxy_exception, DataQueueProxy)
+
 ip.to_user_ns(dict(mec=mec,
                    get_grid_field = get_grid_field,
-                   mec_eval=mec_eval))
+                   mec_eval=mec_eval,
+                   pf = EnzoStaticOutputProxy(),
+                    ))
 ip_shell.mainloop(sys_exit=1,banner=doc)

Modified: trunk/yt/lagos/HierarchyType.py
==============================================================================
--- trunk/yt/lagos/HierarchyType.py	(original)
+++ trunk/yt/lagos/HierarchyType.py	Mon Jun  8 13:20:56 2009
@@ -175,6 +175,7 @@
         self._data_file.flush()
 
     def _reload_data_file(self, *args, **kwargs):
+        if self._data_file is None: return
         self._data_file.close()
         del self._data_file
         self._data_file = h5py.File(self.__data_filename, self._data_mode)
@@ -962,8 +963,13 @@
         return self.grids[(random_sample,)]
 
 class EnzoHierarchyInMemory(EnzoHierarchy):
-    def __init__(self, pf, data_style = 8):
-        import enzo
+    _data_style = 8
+    def _obtain_enzo(self):
+        import enzo; return enzo
+
+    def __init__(self, pf, data_style = None):
+        if data_style is None: data_style = self._data_style
+        enzo = self._obtain_enzo()
         self.float_type = 'float64'
         self.data_style = data_style # Mandated
         self.directory = os.getcwd()
@@ -989,7 +995,7 @@
 
     def _populate_hierarchy(self):
         self._copy_hierarchy_structure()
-        import enzo
+        enzo = self._obtain_enzo()
         mylog.debug("Copying reverse tree")
         self.gridReverseTree = enzo.hierarchy_information["GridParentIDs"].ravel().tolist()
         # Initial setup:
@@ -1024,7 +1030,7 @@
         mylog.debug("Hierarchy fully populated.")
 
     def _copy_hierarchy_structure(self):
-        import enzo
+        enzo = self._obtain_enzo()
         self.gridDimensions[:] = enzo.hierarchy_information["GridDimensions"][:]
         self.gridStartIndices[:] = enzo.hierarchy_information["GridStartIndices"][:]
         self.gridEndIndices[:] = enzo.hierarchy_information["GridEndIndices"][:]

Modified: trunk/yt/lagos/OutputTypes.py
==============================================================================
--- trunk/yt/lagos/OutputTypes.py	(original)
+++ trunk/yt/lagos/OutputTypes.py	Mon Jun  8 13:20:56 2009
@@ -393,6 +393,7 @@
 
 class EnzoStaticOutputInMemory(EnzoStaticOutput):
     _hierarchy_class = EnzoHierarchyInMemory
+    _data_style = 8
 
     def __new__(cls, *args, **kwargs):
         obj = object.__new__(cls)
@@ -405,12 +406,12 @@
         if conversion_override is None: conversion_override = {}
         self.__conversion_override = conversion_override
 
-        StaticOutput.__init__(self, "InMemoryParameterFile", 8)
+        StaticOutput.__init__(self, "InMemoryParameterFile", self._data_style)
 
         self.field_info = self._fieldinfo_class()
 
     def _parse_parameter_file(self):
-        import enzo
+        enzo = self._obtain_enzo()
         self.basename = "cycle%08i" % (
             enzo.yt_parameter_file["NumberOfPythonCalls"])
         self.parameters['CurrentTimeIdentifier'] = time.time()
@@ -427,6 +428,9 @@
         for p, v in self.__conversion_override.items():
             self.conversion_factors[p] = v
 
+    def _obtain_enzo(self):
+        import enzo; return enzo
+
     @classmethod
     def _is_valid(cls, *args, **kwargs):
         return False



More information about the yt-svn mailing list