netket.utils.timing.Timer#

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().

Example

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
Inheritance diagram of netket.utils.timing.Timer
__init__()[source]#

Constructs a new timer object.

Does not accept any argument.

Attributes
total: float#
sub_timers: dict#
Methods
get_subtimer(name)[source]#
Parameters:

name (str)

replace(**kwargs)#

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)

Parameters:
  • self (P)

  • kwargs (Any)