Commands that require the h5py package at runtime.
All commands that are part of this module require the h5py package a python API for hdf5. In addition, this module is an opt-in. As a consequence you’ll need to import it via import hoomd.hdf5 before you can use any command.
Thin wrapper of the h5py.File class.
This class ensures, that opening and close operations within a context manager are only executed on the root MPI rank.
This class can be used like the h5py.File class, but the user has to make sure that all operations are only executed on the root rank.
log(h5file, period, quantities=, matrix_quantities=, phase=0)¶
Log a number of calculated quantities or matrices to a hdf5 file.
- h5file (
hoomd.hdf5.File) – Instance describing the opened h5file.
- period (int) – Quantities are logged every period time steps
- quantities (list) – Quantities to log.
- matrix_quantities (list) – Matrix quantities to log.
- overwrite (bool) – When False (the default) the existing log will be append. When True the file will be overwritten.
- phase (int) – When -1, start on the current time step. When >= 0 execute on steps where (step +phase) % period == 0.
For details on the loggable quantities refer
The non-matrix quantities are combined in an array ‘quantities’ in the hdf5 file. The attributes list all the names of the logged quantities and their position in the file.
Matrix quantities are logged as a separate data set each in the file. The name of the data set corresponds to the name of the quantity. The first dimension of the data set is counting the logged time step. The other dimension correspond to the dimensions of the logged matrix.
The number and order of non-matrix quantities cannot change compared to data which is already stored in the hdf5 file. As a result, if you append to a file make sure you are logging the same values as before. In addition, also during a run with multiple hoomd.run() commands the logged values can not change.
The dimensions of logged matrix quantities cannot change compared to a matrix with same name stored in the file. This applies for appending files as well as during a single simulation run.
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 run(200)
Disable the logger.
Executing the disable command will remove the logger from the system. Any
hoomd.run()command executed after disabling the logger will not use that logger during the simulation. A disabled logger can be re-enabled with
- Get the last logged value of a quantity which has been written to the file. If quantity is registered as a non-matrix quantity, its value is returned. If it is not registered as a non-matrix quantity, it is assumed to be a matrix quantity. If a quantity exists as non-matrix and matrix quantity with the same name, force_matrix can be used to obtain the matrix value.
Matrix quantities are not efficiently cached by the class, so calling this function multiple time, may not be efficient.
register_callback(name, callback, matrix=False)¶
Register a callback to produce a logged quantity.
The callback method must take a single argument, the current timestep, and return a single floating point value to be logged. If the callback returns a matrix quantity the return value must be a numpy array constant dimensions of each call.
One callback can query the value of another, but logged quantities are evaluated in order from left to right.
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)
Change the parameters of the log.
Do not change the number or order of logged non-matrix quantities compared to values stored in the file.
- h5file (