Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test to demonstrate issue mesalib #237

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ aliases:
name: create_conda_env
environment:
CHANNELS: "-c cdat/label/nightly -c conda-forge -c cdat"
PKGS: "cdms2 cdat_info udunits2 testsrunner mesalib matplotlib image-compare genutil dv3d cdutil cdtime nbformat 'proj4<5' 'numpy>1.14' "
PKGS: "cdms2 cdat_info udunits2 testsrunner mesalib matplotlib image-compare genutil dv3d cdutil cdtime nbformat 'proj4<5' 'numpy>1.14' vcsaddons"
command: |
export PATH=$WORKDIR/miniconda/bin:$PATH
conda config --set always_yes yes --set changeps1 no
Expand Down
1 change: 1 addition & 0 deletions Share/test_data_files.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ aa51aa896ead44019335cebec68e7955 clt.nc
6af2b2e8f8fe468c49d0324d69d83942 ta_ncep_87-6-88-4.nc
4e4648ad9855cb71259926c9d4a1d361 tas_ccsr-95a_1979.01-1979.12.nc
f05fd9a1a8026537d733dcea5b140f33 BlueMarble.ppm
814242dd4dbba4126b455160abd13d73 test_mesa_leak.nc
116 changes: 116 additions & 0 deletions tests/test_vcs_mesa_leak.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#!/bin/env python
import basevcstest
import EzTemplate
import gc
import time
import resource
import vcs
import cdms2
import numpy
import vcs
import os


def initVCS(x, levs1, levs2, split):
gtype = "isofill"
if gtype == "isofill":
crt = vcs.createisofill
else:
crt = vcs.createboxfill
x.setcolormap("bl_to_darkred")
gm1 = crt()
#iso = x.createboxfill()
if gtype == "boxfill": gm1.boxfill_type="custom"
gm1.levels = levs1
gm1.ext_1 = True
gm1.ext_2 = True
cols = vcs.getcolors(gm1.levels, split=split)
gm1.fillareacolors = cols

gm2 = crt()
if gtype == "boxfill": gm2.boxfill_type="custom"
levs = levs2
gm2.levels = levs
gm2.ext_1 = True
gm2.ext_2 = True
cols = vcs.getcolors(gm2.levels, split=1)
gm2.fillareacolors = cols

leg = x.createtextorientation()
leg.halign = "left"
leg.height = 8

tmpl = x.createtemplate()
tmpl.blank()
tmpl.scalefont(.9)

tmpl.legend.textorientation = leg
for a in ["data", "legend", "box1",
"xlabel1", "xtic1", "ylabel1", "ytic1"]:
setattr(getattr(tmpl, a), "priority", 1)

Ez = EzTemplate.Multi(rows=3, columns=1, x=x, template=tmpl)
Ez.legend.direction = 'vertical'
Ez.margins.left = .05
Ez.margins.right = .05
Ez.margins.top = .05
Ez.margins.bottom = .05

title = x.createtext()
title.height = 14
title.halign = "center"
title.x = [.5]
title.y = [.975]

t1 = Ez.get(legend="local")
t2 = Ez.get(legend="local")
t3 = Ez.get(legend="local")

del(Ez)

return gm1, gm2, title, t1, t2, t3, tmpl


class VCSTestMesaLeak(basevcstest.VCSBaseTest):
def testMesaLeak(self):
counter = 1
levs1 = list(numpy.arange(-5, 115, 10)) # SIC
levs2 = list(numpy.arange(-5, 5.5, .5))
split = 0

fout = cdms2.open(os.path.join(vcs.sample_data,"test_mesa_leak.nc"))
NITER = 10
mems = []
for i in range(NITER):
startTime = time.time()
printStr = 'processing: %i' % (i)
s1s = fout("sic")
s2 = fout("variable_4")
diff = s2 - s1s
iso1, iso2, title, t1, t2, t3, tmpl = initVCS(self.x, levs1, levs2, split)
title.string = '%i' % (i)
self.x.plot(title)
self.x.plot(s1s, t1, iso1)
self.x.plot(diff, t2, iso2)
self.x.plot(s2, t3, iso1)
self.x.clear()
vcs.removeobject(iso1)
vcs.removeobject(iso2)
vcs.removeobject(title)
vcs.removeobject(t1)
vcs.removeobject(t2)
vcs.removeobject(t3)
vcs.removeobject(tmpl)
endTime = time.time()
timeStr = 'Time: %06.3f secs;' % (endTime - startTime)
mem = float(resource.getrusage(resource.RUSAGE_SELF).ru_maxrss) / 1.e6
mems.append(mem)
memStr = 'Max mem: %05.3f GB' % ( mem )
counterStr = '%05d' % counter
pyObj = 'PyObj#: %07d;' % (len(gc.get_objects()))
print(counterStr, printStr, timeStr, memStr, pyObj)
counter = counter + 1
gc.collect() # Attempt to force a memory flush
a, b = numpy.polyfit(numpy.arange(NITER),numpy.array(mems),1)
print(a,b)
self.assertTrue(abs(a)<1.e-3)