consistency_check

  • full name: tenpy.tools.misc.consistency_check

  • parent module: tenpy.tools.misc

  • type: function

tenpy.tools.misc.consistency_check(value, options, threshold_key, threshold_default, msg, compare='<=')[source]

Perform a consistency check, raising an error if it is violated.

At several points in the library we perform checks that detect if:

a) Parameters do not permit the simulation to complete on typical cluster hardware,
   e.g. because it would need to much memory or runtime.

b) Parameters do not permit useable results, e.g. if the time step is too large to trust
   a Suzuki-Trotter approximation.

c) Results are unreliable, e.g. if the truncation errors are too large

This necessarily requires heuristic threshold values for each of those conditions. We hard code default values, informed by our experience, typically as magic numbers for the threshold_default argument of this function. If the threshold is exceeded, a TenpyInconsistencyError is raised. To manually adjust the threshold, we provide a config option for each check, such as e.g. Algorithm.max_N_sites_per_ring. It can be set to None, which causes a TenpyInconsistencyWarning to be emitted instead of the error.

Warning

Obviously, the fact that we do consistency checks like dt < 1. does not mean that that your results are converged for any dt < 1.! You will likely have to choose a value much smaller than the threshold, and it is your responsibility as a user to ensure that you are in fact converged in each of the parameters.

Parameters:
  • value – The value to check. Must support the compare operation.

  • options (Config | dict-like) – The options that may contain the manually overriding threshold value.

  • threshold_key (str) – The key of the threshold value in options. If present, the value is used as the threshold and takes precedence over threshold_default. If the value is None, the threshold_default is used for comparison, and if violated, we only issue a warning (warnings.warn) instead of raising an error.

  • threshold_default (float) – The default value for the threshold

  • msg (str) – The error message, in case the check fails.

  • compare ('<=' | '<' | '>' | '>=' | '!=' | '==' | callable) – By default, we check if value <= threshold and raise otherwise. This allows other comparison operations. A callable means we check compare(value, threshold).