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

mturk at wrangler.dreamhost.com mturk at wrangler.dreamhost.com
Tue Jun 9 08:33:03 PDT 2009


Author: mturk
Date: Tue Jun  9 08:33:02 2009
New Revision: 1327
URL: http://yt.spacepope.org/changeset/1327

Log:
Rewrote a *little* bit the embedded yt script.  Moving toward 'refresh' method
on a single client-interface, but right now it doesn't work as hoped for -- the
client needs to be fully reinstantiated, because it needs to have a blocking
wait.  The correct way will be to have the engines instantiated at startup, and
then move forward on the task nodes through each cycle.



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

Modified: trunk/scripts/eyt
==============================================================================
--- trunk/scripts/eyt	(original)
+++ trunk/scripts/eyt	Tue Jun  9 08:33:02 2009
@@ -41,48 +41,58 @@
 ip = ip_shell.IP.getapi()
 ip.ex("from yt.mods import *")
 from IPython.kernel import client
-mec = client.MultiEngineClient()
-mec.activate()
 
-# there are some blocks in hierarchy instantiation, so
-# we pre-instantiate
-mec.execute("pf.h") 
-
-def mec_eval(varname, targets = None):
-    """
-    This function pulls anything from the remote host, but it will overwrite
-    any variable named __tmp.  This is to get around nested variables and
-    properties on the remote host.
-    """
-    mec.execute("__tmp = %s" % varname, targets=targets)
-    result = mec.pull("__tmp", targets=targets)
-    return result
+class YTClient(object):
+    mec = None
 
-class enzo_module_proxy(object):
-    pass
+    def __init__(self):
+        self.refresh()
+
+    def eval(self, varname, targets = None):
+        """
+        This function pulls anything from the remote host, but it will overwrite
+        any variable named __tmp.  This is to get around nested variables and
+        properties on the remote host.
+        """
+        self.mec.execute("__tmp = %s" % varname, targets=targets)
+        result = self.mec.pull("__tmp", targets=targets)
+        return result
+
+    def get_grid_field(self, grid_index, field_name, raw=False):
+        """
+        Return the numpy array representing a piece of field information.
+        Note that *grid_index* is the actual index into the array, which is ID-1.
+
+        If *raw* is set to True, then only raw original fields from the hierarchy
+        are returned.  This will include ghost zones, and derived fields are
+        inaccessible.
+        """
+        proc = int(self.enzo.hierarchy_information["GridProcs"][grid_index])
+        if not raw: # go through yt
+            result = self.eval("pf.h.grids[%s]['%s']" % (
+                        grid_index, field_name), [proc])[0]
+        else: # go through enzo module
+            result = self.eval("enzo.grid_data[%s + 1]['%s']" % (
+                        grid_index, field_name), [proc])[0].swapaxes(0,2)
+        return result
+
+    def refresh(self):
+        if self.mec is not None: self.mec.kill()
+        self.mec = client.MultiEngineClient()
+        self.mec.activate()
+        # there are some blocks in hierarchy instantiation, so
+        # we pre-instantiate
+        self.mec.execute("pf.h") 
+        self.enzo = enzo_module_proxy(self)
+        self.pf = EnzoStaticOutputProxy(ytc=self)
+        ip.to_user_ns(dict(
+            mec=self.mec, ytc=self, pf = self.pf))
 
-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):
-    """
-    Return the numpy array representing a piece of field information.
-    Note that *grid_index* is the actual index into the array, which is ID-1.
-
-    If *raw* is set to True, then only raw original fields from the hierarchy
-    are returned.  This will include ghost zones, and derived fields are
-    inaccessible.
-    """
-    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].swapaxes(0,2)
-    return result
+class enzo_module_proxy(object):
+    def __init__(self, ytc):
+        self.hierarchy_information = ytc.eval("enzo.hierarchy_information", [0])[0]
+        self.conversion_factors = ytc.eval("enzo.conversion_factors", [0])[0]
+        self.yt_parameter_file = ytc.eval("enzo.yt_parameter_file", [0])[0]
 
 from yt.lagos import EnzoStaticOutputInMemory, EnzoHierarchyInMemory
 from yt.lagos.HierarchyType import _data_style_funcs
@@ -91,19 +101,24 @@
 class EnzoHierarchyProxy(EnzoHierarchyInMemory):
     _data_style = 'proxy'
     def _setup_field_lists(self):
-        self.field_list = mec_eval("pf.h.field_list", [0])[0]
+        self.field_list = self.parameter_file.ytc.eval("pf.h.field_list", [0])[0]
 
     def _obtain_enzo(self):
-        return enzo
+        return self.parameter_file.ytc.enzo
 
 class EnzoStaticOutputProxy(EnzoStaticOutputInMemory):
     _data_style = 'proxy'
     _hierarchy_class = EnzoHierarchyProxy
+
+    def __init__(self, *args, **kwargs):
+        self.ytc = kwargs.pop("ytc")
+        EnzoStaticOutputInMemory.__init__(self, *args, **kwargs)
+
     def _obtain_enzo(self):
-        return enzo
+        return self.ytc.enzo
 
 def _read_proxy_slice(self, grid, field, axis, coord):
-    data = get_grid_field(grid.id - 1, field, raw=True)
+    data = ytc.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))
@@ -117,7 +132,7 @@
         BaseDataQueue.__init__(self)
 
     def _read_set(self, grid, field):
-        data = get_grid_field(grid.id - 1, field, raw=True)
+        data = ytc.get_grid_field(grid.id - 1, field, raw=True)
         return data[self.my_slice]
 
     def modify(self, field):
@@ -126,12 +141,12 @@
 def proxy_exception(*args, **kwargs):
     return KeyError
 
+# things like compare buffers over time
+
 _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,
-                   pf = EnzoStaticOutputProxy(),
-                    ))
+ytc = YTClient()
+mec = ytc.mec
+
 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	Tue Jun  9 08:33:02 2009
@@ -968,6 +968,7 @@
         import enzo; return enzo
 
     def __init__(self, pf, data_style = None):
+        self.parameter_file = weakref.proxy(pf) # for _obtain_enzo
         if data_style is None: data_style = self._data_style
         enzo = self._obtain_enzo()
         self.float_type = 'float64'



More information about the yt-svn mailing list