示例#1
0
文件: hpc.py 项目: argju/cgptoolbox
def hdfcaching():
    """Auto-cache/save results to HDF."""
    import os
    import tables as pt    
    from cgp.utils.hdfcache import Hdfcache
    
    filename = "/home/jonvi/hdfcache.h5"
    hdfcache = Hdfcache(filename)
    pipeline = [hdfcache.cache(i) for i in gt2par, par2ph, ph2agg]
    with hdfcache:
        for i in genotypes:
            for func in pipeline:
                i = func(i)
    with pt.openFile(filename) as f:
        gt = f.root.gt2par.input[:]
        agg = f.root.ph2agg.output[:]
    summarize(gt, agg)
    os.system("h5ls -r " + filename)
示例#2
0
"""
Cache computations to HDF file for simple genotype-phenotype example.

Here, the line "ph = hdfcache.cache(ph)" is equivalent to the decorator syntax:

.. code-block:: none
   
   @hdfcache.cache
   def ph(...):
       ...

However, cgp.examples.simple.ph is left undecorated so we can illustrate 
different tools for caching and parallelization. 
"""

import os
from tempfile import gettempdir

from cgp.utils.hdfcache import Hdfcache
from cgp.examples.simple import *  # @UnusedWildImport pylint: disable=W0614

if __name__ == "__main__":
    
    hdfcache = Hdfcache(os.path.join(gettempdir(), "cgpdemo.h5"))
    ph = hdfcache.cache(ph)
    
    result = np.concatenate([ph(gt) for gt in gts]).view(np.recarray)
    
    visualize(result)