temporary_level

Inheritance Diagram

Inheritance diagram of tenpy.tools.optimization.temporary_level

Methods

temporary_level.__init__(temporary_level)

class tenpy.tools.optimization.temporary_level(temporary_level)[source]

Bases: object

Context manager to temporarily set the optimization level to a different value.

Parameters:

temporary_level (int | OptimizationFlag | str | None) – The optimization level to be set during the context. None defaults to the current value of the optimization level.

temporary_level

The optimization level to be set during the context.

Type:

None | OptimizationFlag

_old_level

Optimization level to be restored at the end of the context manager.

Type:

OptimizationFlag

Examples

It is recommended to use this context manager in a with statement:

# optimization level default
with temporary_level(OptimizationFlag.safe):
    do_some_stuff()  # temporarily have Optimization level `safe`
    # you can even change the optimization level to something else:
    set_level(OptimizationFlag.skip_args_check)
    do_some_really_heavy_stuff()
# here we are back to the optimization level as before the ``with ...`` statement