Config¶
full name: tenpy.tools.params.Config
parent module:
tenpy.tools.params
type: class
Inheritance Diagram

Methods
|
|
|
Check for any non-zero or non-equal entries in some parameters. |
Return a copy of the options as a dictionary. |
|
|
Make a shallow copy, as for a dictionary. |
|
|
|
Load instance from a HDF5 file. |
|
Load a Config instance from a YAML file containing the |
|
Find the value of key; really more like setdefault of a |
|
Check whether self contains key, and if self[key] is nontrivial. |
|
Print out option if verbosity and other conditions are met. |
|
If key is not found, d is returned if given, otherwise KeyError is raised. |
as a 2-tuple; but raise KeyError if D is empty. |
|
|
Export self into a HDF5 file. |
|
Save the parameters to filename as a YAML file. |
|
Set a default value without reading it out. |
|
Find the value of key, but don't set as default value and don't print. |
|
Get |
|
Mark keys as read out to supress warnings about those keys being unused. |
|
If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v |
|
Warn about (so far) unused options. |
Class Attributes and Properties
|
- class tenpy.tools.params.Config(config, name)[source]¶
Bases:
MutableMapping
Dict-like wrapper class for parameter/configuration dictionaries.
This class behaves mostly like a dictionary of option keys/values (together making the whole “config”) with some additional features:
Logging of the options the first time they get used.
get()
acts more likedict.setdefault()
such that after the algorithm, all the used default values are known and can be saved for future reference.Keeping track of unused options to detect typos in the keys.
Nicer formatting with
print(config)
Import/export to yaml and hdf5 files.
- config Config¶
- [No options defined for this config]
- Parameters
- name¶
Name of the dictionary, for output statements. For example, when using a Config class for DMRG,
name='DMRG'
.- Type
- as_dict()[source]¶
Return a copy of the options as a dictionary.
Subconfigs are recursivley converted to dict.
- save_yaml(filename)[source]¶
Save the parameters to filename as a YAML file.
- Parameters
filename (str) – Name of the resulting YAML file.
- classmethod from_yaml(filename, name=None)[source]¶
Load a Config instance from a YAML file containing the
options
.Warning
Like pickle, it is not safe to load a yaml file from an untrusted source! A malicious file can call any Python function and should thus be treated with extreme caution.
- save_hdf5(hdf5_saver, h5gr, subpath)[source]¶
Export self into a HDF5 file.
This method saves all the data it needs to reconstruct self with
from_hdf5()
.This implementation saves the content of
__dict__
withsave_dict_content()
, storing the format under the attribute'format'
.
- classmethod from_hdf5(hdf5_loader, h5gr, subpath)[source]¶
Load instance from a HDF5 file.
This method reconstructs a class instance from the data saved with
save_hdf5()
.- Parameters
hdf5_loader (
Hdf5Loader
) – Instance of the loading engine.h5gr (
Group
) – HDF5 group which is represent the object to be constructed.subpath (str) – The name of h5gr with a
'/'
in the end.
- Returns
obj – Newly generated class instance containing the required data.
- Return type
cls
- warn_unused(recursive=False)[source]¶
Warn about (so far) unused options.
This can help to detect typos in the option keys. It is automatically called upon deletion of self, but this might be a bit later than you intended.
- get(key, default)[source]¶
Find the value of key; really more like setdefault of a
dict
.If no value is set, return default and set the value of key to default internally.
- Parameters
option (str) – Key for the option being read out.
default – Default value for the parameter.
- Returns
The value for option if it existed, default otherwise.
- Return type
val
- silent_get(key, default)[source]¶
Find the value of key, but don’t set as default value and don’t print.
Same as
dict.get
, i.e. just return self[key] if existent, else default, without memorizing/logging the access. Does not count as read-out for theunused
parameters.
- setdefault(key, default)[source]¶
Set a default value without reading it out.
- Parameters
key (str) – Key name for the option being set.
default – The value to be set by default if the option is not yet set.
- touch(*keys)[source]¶
Mark keys as read out to supress warnings about those keys being unused.
- Parameters
*keys (str) – Each key is marked as read out.
- log(option, action='Option', use_default=False)[source]¶
Print out option if verbosity and other conditions are met.
- any_nonzero(keys, log_msg=None)[source]¶
Check for any non-zero or non-equal entries in some parameters.
- Parameters
keys (list of {key | tuple of keys}) – For a single key, check
self[key]
for non-zero entries. For a tuple of keys, all theself[key]
have to be equal (as numpy arrays). It is assumed that the default values for the keys are 0!log_msg (None | str) – If not None, logger.debug this message with the reason if True is returned.
- Returns
match – False, if all
self[key]
are zero or None and True, if any of theself[key]
for single key in keys, or if any of the entries for a tuple of keys- Return type
- clear() None. Remove all items from D. ¶
- items() a set-like object providing a view on D's items ¶
- pop(k[, d]) v, remove specified key and return the corresponding value. ¶
If key is not found, d is returned if given, otherwise KeyError is raised.
- popitem() (k, v), remove and return some (key, value) pair ¶
as a 2-tuple; but raise KeyError if D is empty.
- update([E, ]**F) None. Update D from mapping/iterable E and F. ¶
If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v
- values() an object providing a view on D's values ¶