shenfun icon indicating copy to clipboard operation
shenfun copied to clipboard

issues with demo/KleinGordon.py out of the box

Open apatlpo opened this issue 7 years ago • 3 comments

These are really minor issues but may be of some help.

I installed shenfun with:

conda create --name shenfun -c conda-forge -c spectralDNS python=3.6 shenfun
  • h5py was not installed and lead to a first crash while launching mpirun -np 4 python KleinGordon.py

  • after installing h5py (with conda), a second crash occured:

  File "KleinGordon.py", line 25, in <module>
    from spectralDNS.utilities import Timer
ModuleNotFoundError: No module named 'spectralDNS'
  • after commenting out the import statement and the call to Timer(), I got another crash:
Traceback (most recent call last):
  File "KleinGordon.py", line 59, in <module>
    file0 = HDF5Writer("KleinGordon{}.h5".format(N[0]), ['u', 'f'], TT)
  File "/Users/aponte/.miniconda3/envs/shenfun/lib/python3.6/site-packages/shenfun/utilities/h5py_writer.py", line 25, in __init__
    self.f = h5py.File(h5name, "w", driver="mpio", comm=T.comm)
  File "/Users/aponte/.miniconda3/envs/shenfun/lib/python3.6/site-packages/h5py/_hl/files.py", line 268, in __init__
    fapl = make_fapl(driver, libver, **kwds)
  File "/Users/aponte/.miniconda3/envs/shenfun/lib/python3.6/site-packages/h5py/_hl/files.py", line 71, in make_fapl
    kwds.setdefault('info', mpi4py.MPI.Info())
NameError: name 'mpi4py' is not defined

This one looks strange to me, mpi4run was installed with shenfun. A quick search online seems to indicate h5py install with conda may be faulty. Any suggestions?

apatlpo avatar Dec 14 '17 10:12 apatlpo

Thanks a lot for creating this issue, and sorry that you have to be a guinea pig. The Klein Gordon demo requires matplotlib and h5py-parallel to work. The latter is in my channel on anaconda cloud and I should really make it a dependency. Will do that. For now, try to uninstall h5py and install h5py-parallel. Or restart by doing conda create --name shenfun -c conda-forge -c spectralDNS python=3.6 shenfun h5py-parallel matplotlib

mikaem avatar Dec 14 '17 10:12 mikaem

Ok, thanks, the code ran successfully.

I ran into a second issue which has more to do with my inexperience with hdf5 data. As an oceanographer I am used to deal with netcdf and reading an hdf5 file is not straitghforward for me. My guess is that you have somewhere code that does just that but I did not find it easily but it would be nice if it was more visible.

Anyway I came up with a simple script in order to explore the output files:

import h5py
import matplotlib.pyplot as plt
import sys, time

def print_attrs(name, obj):
    print(name)
    for key, val in obj.attrs.items():
        print('    %s: %s'.format(key, val))

if len(sys.argv) > 1:

    # open file and print variables
    fname = sys.argv[1]
    f = h5py.File(fname, 'r')

    if len(sys.argv) == 2:

        f.visititems(print_attrs)

    else:

        # go within data tree
        g=f
        for i in range(2,len(sys.argv)):
            g=g[sys.argv[i]]
            print(g)
            if i==len(sys.argv)-1:
                flag=True
                for key, val in g.items():
                    if isinstance(val, h5py.Dataset):
                        flag=False
                        if len(val.shape)==2:
                            gname=g.name[1:].replace('/','_')+'_'
                            plt.figure()
                            plt.imshow(val)
                            #print(val[:,:])
                            plt.title(gname+' '+key)
                            plt.savefig(gname+key+'.png')
                            plt.close()
                        elif len(val.shape)==3:
                            print('Data is 3D')
                        elif len(val.shape) == 1:
                            print('Data is 1D')
                if flag:
                    g.visititems(print_attrs)
f.close()

apatlpo avatar Dec 14 '17 13:12 apatlpo

I only use hdf5 to visualise in parallel. In the end of KleinGordon.py there is a script that generates an xdmf file. This file (which uses pointers into the hdf5 file) can be opened by paraview for visualisation. For plotting in python it is really not necessary to go through the hdf5 format. Just plot the numpy arrays. Of course, in parallel this becomes a bit problematic:-)

mikaem avatar Dec 14 '17 13:12 mikaem