Error with HDF5 file

1,277 views
Skip to first unread message

jude vishnu

unread,
Feb 5, 2021, 8:08:25 AM2/5/21
to hoomd...@googlegroups.com
Hello everyone,

I was trying to write matrix data into a hdf5 file as described in the documentation 2.9.3.
I imported hoomd.hdf5 and to tried to do the same example in given in the documentation to understand how it works:
with hoomd.hdf5.File("log.h5", "w") as h5file:
   #general setup

   log = hoomd.hdf5.log(filename='log.h5', quantities=['my_quantity', 'cosm'], matrix_quantities = ['random_matrix'], period=100)
   log.register_callback('my_quantity', lambda timestep: timestep**2)
   log.register_callback('cosm', lambda timestep: math.cos(logger.query('my_quantity')))
   def random_matrix(timestep):
      return numpy.random.rand(23, 56)
   log.register_callback('random_matrix', random_matrix, True)
   #more setup

But I end up getting an error as follows:

**ERROR**: HDF5 file descriptor is no instance of h5py.File, which is the hoomd thin wrapper for hdf5 file descriptors.Traceback (most recent call last):
  File "./psd.py", line 344, in <module>
    log = hoomd.hdf5.log('log.h5', quantities=['my_quantity', 'cosm'], matrix_quantities = ['random_matrix'], period=100)
  File "/usr/local/lib/python3.7/dist-packages/hoomd/hdf5.py", line 96, in __init__
    raise RuntimeError("Error creating hoomd.hdf5.log")
RuntimeError: Error creating hoomd.hdf5.log

Would anyone know what I am doing wrong to create this problem. I would really appreciate your help.

Regards,
Jude  Ann Vishnu

Michael Howard

unread,
Feb 5, 2021, 9:53:03 AM2/5/21
to hoomd-users
That looks like an error in the example given if you compare to the other documentation:


Note that you are opening the hdf5 file as h5file, but then doing nothing with it. The documentation says that hoomd.hd5.log should accept a hoomd.hdf5.File as the first argument called h5file (not a string called filename). Try changing that line this instead:

log = hoomd.hdf5.log(h5file, quantities=['my_quantity', 'cosm'], matrix_quantities = ['random_matrix'], period=100)

Regards,
Mike

jude vishnu

unread,
Feb 5, 2021, 7:21:37 PM2/5/21
to hoomd...@googlegroups.com
Hi Mike,
Your suggestion helped a lot. But I still end up having errors. To be honest I am not able to understand what this error means:
This is the snippet of code
with hoomd.hdf5.File("log.h5", "w") as h5file:
   #general setup

   log = hoomd.hdf5.log(h5file, matrix_quantities = ['random_matrix'], period=100)
   
   def random_matrix(timestep):
      return numpy.random.rand(23, 56)
   log.register_callback('random_matrix', random_matrix, True)
   #more setup
   hoomd.run(1e7)
Traceback (most recent call last):
  File "./psd.py", line 369, in <module>
    hoomd.run(1e7 )
  File "/usr/local/lib/python3.7/dist-packages/hoomd/__init__.py", line 201, in run
    context.current.system.run(int(tsteps), callback_period, callback, limit_hours, int(limit_multiple));
  File "/usr/local/lib/python3.7/dist-packages/hoomd/hdf5.py", line 255, in _write_hdf5
    self._write_quantities(f, timestep)
  File "/usr/local/lib/python3.7/dist-packages/hoomd/hdf5.py", line 269, in _write_quantities
    self._write_header(f)
  File "/usr/local/lib/python3.7/dist-packages/hoomd/hdf5.py", line 354, in _write_header
    data_set = f.create_dataset("quantities", shape=(0, len(quantities)), maxshape=(None, len(quantities)))
  File "/usr/local/lib/python3.7/dist-packages/h5py/_hl/group.py", line 148, in create_dataset
    dsid = dataset.make_new_dset(group, shape, dtype, data, name, **kwds)
  File "/usr/local/lib/python3.7/dist-packages/h5py/_hl/dataset.py", line 137, in make_new_dset
    dset_id = h5d.create(parent.id, name, tid, sid, dcpl=dcpl)
  File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
  File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
  File "h5py/h5d.pyx", line 87, in h5py.h5d.create
ValueError: Invalid location identifier (invalid location identifier)

It could greatly help me, if some one has an example code which can be shared with me.

Regards,
Jude Ann Vishnu

--
You received this message because you are subscribed to the Google Groups "hoomd-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hoomd-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/hoomd-users/9768fcd3-f9a1-4ffa-afa7-6c8c44067dbfn%40googlegroups.com.


--
Yours truly,
Jude Ann Vishnu
Reply all
Reply to author
Forward
0 new messages