class netket.utils.timing.Timer[source]#

Bases: Pytree

Measures how much time was spent in a timer, with possible sub-timers.

Can be used as a context manager to time a scope, and will show up timers used inside of the scope if present.

If you directly construct a timer, you cannot nest it inside another timer. If you are building a library function you should instead use netket.utils.timing.timed_scope().


Time a scope

>>> import netket as nk
>>> import time
>>> with nk.utils.timing.Timer() as t:
...    time.sleep(1)  # This line and the ones below are indented
...    with nk.utils.timing.timed_scope("subfunction 1"):
...       time.sleep(0.5)
...    with nk.utils.timing.timed_scope("subfunction 2"):
...       time.sleep(0.25)
>>> t  
╭──────────────────────── Timing Information ─────────────────────────╮
│ Total: 1.763                                                        │
│ ├── (28.7%) | subfunction 1 : 0.505 s                               │
│ └── (14.3%) | subfunction 2 : 0.252 s                               │
Inheritance diagram of netket.utils.timing.Timer

Constructs a new timer object.

Does not accept any argument.

total: float#
sub_timers: dict#

name (str)


Replace the values of the fields of the object with the values of the keyword arguments. If the object is a dataclass, dataclasses.replace will be used. Otherwise, a new object will be created with the same type as the original object.

Return type:

TypeVar(P, bound= Pytree)

  • self (P)

  • kwargs (Any)