yt.geometry_tests / chunking.py

from yt.mods import *

pf = load("DD0039/output_0039")
sp = pf.h.sphere('c', (1.0, 'kpc'))
print "Density"
all = {}
t1 = time.time()
for field in ['Density', 'Entropy', 'Ones']:
    f = sp[field]
    all[field] = (f.size, f.sum(dtype='float64'))
all["time"] = time.time() - t1

sp = pf.h.sphere('c', (1.0, 'kpc'))
grid = {}
t1 = time.time()
for field in ['Density', 'Entropy', 'Ones']:
    grid[field] = (0, 0.0)
    for rv in sp.chunks(field, "grid"):
        s, v = grid[field]
        grid[field] = (rv[field].size + s,
                        rv[field].sum(dtype="float64") + v)
grid["time"] = time.time() - t1

sp = pf.h.sphere('c', (1.0, 'kpc'))
grids = {}
t1 = time.time()
for field in ['Density', 'Entropy', 'Ones']:
    grids[field] = (0, 0.0)
    for rv in sp.chunks(field, "grids"):
        s, v = grids[field]
        grids[field] = (rv[field].size + s,
                        rv[field].sum(dtype="float64") + v)
grids["time"] = time.time() - t1

sp = pf.h.sphere('c', (1.0, 'kpc'))
inner = {}
t1 = time.time()
for field in ['Density', 'Entropy', 'Ones']:
    inner[field] = (0, 0.0)
for rv in sp.chunks(field, "grids"):
    for field in ['Density', 'Entropy', 'Ones']:
        s, v = inner[field]
        inner[field] = (rv[field].size + s,
                        rv[field].sum(dtype="float64") + v)
inner["time"] = time.time() - t1
print "All-at-once took %0.3e" % (all["time"])

print "Grid-by-grid chunking:"
for field in ['Density', 'Entropy', 'Ones']:
    print grid[field][0] - all[field][0],
    print grid[field][1] / all[field][1]
print "Took %0.3es" % (grid["time"])

print "Grids-by-grids chunking:"
for field in ['Density', 'Entropy', 'Ones']:
    print grids[field][0] - all[field][0],
    print grids[field][1] / all[field][1]
print "Took %0.3es" % (grids["time"])

print "Inner-field-read chunking:"
for field in ['Density', 'Entropy', 'Ones']:
    print inner[field][0] - all[field][0],
    print inner[field][1] / all[field][1]
print "Took %0.3es" % (inner["time"])
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.