output_filename_from_dict

tenpy.simulations.simulation.output_filename_from_dict(options, parts={}, prefix='result', suffix='.h5', joint='_', parts_order=None, separator='.')[source]

Format a output_filename from parts with values from nested options.

The results of a simulation are ideally fixed by the simulation class and the options. Unique filenames could be obtained by including all options into the filename, but this would be a huge overkill: it suffices if we include the options that we actually change. This function helps to keep the length of the output filename at a sane level while ensuring (hopefully) sufficient uniqueness.

Parameters:
  • options ((nested) dict) – Typically the simulation parameters, i.e., options passed to Simulation.

  • : (parts) – dict: Entries map a recursive_key for options to a format_str used to format the value, i.e. we extend the filename with format_str.format(get_recursive(options, recursive_key, separator)). If format_str is empty, no part is added to the filename.

  • prefix (str) – First and last part of the filename.

  • suffix (str) – First and last part of the filename.

  • joint (str) – Individual filename parts (except the suffix) are joined by this string.

  • parts_order (None | list of keys) – Optionally, an explicit order for the keys of parts. By default (None), just the keys of parts, i.e. the order in which they appear in the dictionary; before python 3.7 (where the order is not defined) alphabetically sorted.

  • separator (str) – Separator for get_recursive().

Returns:

output_filename – (Hopefully) sufficiently unique filename.

Return type:

str

Examples

>>> from tenpy.simulations.simulation import output_filename_from_dict
>>> options = {  # some simulation parameters
...    'algorithm_params': {
...         'dt': 0.01,  # ...
...    },
...    'model_params':  {
...         'Lx': 3,
...         'Ly': 4, # ...
...    }, # ... and many more options ...
... }
>>> output_filename_from_dict(options)
'result.h5'
>>> output_filename_from_dict(options, suffix='.pkl')
'result.pkl'
>>> output_filename_from_dict(options, parts={'model_params.Ly': 'Ly_{0:d}'}, prefix='check')
'check_Ly_4.h5'
>>> output_filename_from_dict(options, parts={
...         'algorithm_params.dt': 'dt_{0:.3f}',
...         'model_params.Ly': 'Ly_{0:d}'})
'result_dt_0.010_Ly_4.h5'
>>> output_filename_from_dict(options, parts={
...         'algorithm_params.dt': 'dt_{0:.3f}',
...         ('model_params.Lx', 'model_params.Ly'): '{0:d}x{1:d}'})
'result_dt_0.010_3x4.h5'
>>> output_filename_from_dict(options, parts={
...         'algorithm_params.dt': '_dt_{0:.3f}',
...         'model_params.Lx': '_{0:d}',
...         'model_params.Ly': 'x{0:d}'}, joint='')
'result_dt_0.010_3x4.h5'