ITensor / ITensors.jl

A Julia library for efficient tensor computations and tensor network calculations
https://itensor.org
Apache License 2.0
540 stars 124 forks source link

[ITensors] [ENCHANCEMENT] Remove TimerOutputs.jl as a dependency #1526

Open MazenAli opened 1 month ago

MazenAli commented 1 month ago

Description of bug

The @timeit_debug decorator from TimerOutputs does not to seem to function properly as timeit_debug_enabled is not defined in ITensors. See also screenshot of README from TimerOutputs.

Screenshot 2024-09-09 at 16 08 05

Minimal runnable code

```julia using Pkg Pkg.add("TimerOutputs") using ITensors, ITensorMPS, TimerOutputs TimerOutputs.enable_debug_timings(ITensors) const timer = TimerOutput() # Build MPO J = 4.0 h = 1.0 L = 15 ampo = AutoMPO() for j in 1:(L - 1) add!(ampo, -J, "Sz", j, "Sz", j + 1) add!(ampo, -h, "Sx", j) end add!(ampo, -h, "Sx", L) sites = siteinds("S=1/2", L) ham = MPO(ampo, sites) # Do DMRG psi0 = MPS(sites, "Up") nsweeps = 20 maxdim = 15 cutoff = 0 @timeit_debug timer "dmrg" energy, _ = dmrg(ham, psi0; nsweeps=nsweeps, maxdim=maxdim, mindim=maxdim, cutoff=cutoff, outputlevel=0) println("Run $i: $energy") println(timer) ```

Output of minimal runnable code

```julia root@8506b93efb68:/opt/project/examples# julia tmp.jl Resolving package versions... No Changes to `~/.julia/environments/v1.10/Project.toml` No Changes to `~/.julia/environments/v1.10/Manifest.toml` ERROR: LoadError: UndefVarError: `timeit_debug_enabled` not defined Stacktrace: [1] enable_debug_timings(m::Module) @ TimerOutputs ~/.julia/packages/TimerOutputs/Lw5SP/src/TimerOutput.jl:187 [2] top-level scope @ /opt/project/examples/tmp.jl:5 in expression starting at /opt/project/examples/tmp.jl:5 root@8506b93efb68:/opt/project/examples# ```

Version information

mtfishman commented 1 month ago

I don't think we have many timers inside the codebase right now anyway, what were you hoping to time?

As an alternative, I would recommend using a profiler.

MazenAli commented 1 month ago

I wanted to time dmrg, i.e., how much time dmrg spends in the subroutines, e.g., truncating, eigenvalue solve, etc. You do use the timeit_debug decorators, but I couldn't find tests for it. Did you test it?

mtfishman commented 1 month ago

I don't remember testing it, I haven't used TimerOutputs in a long time, we were mostly using it in the codebase for debugging some performance issues early on when developing the package. Probably we should remove it at this point, it isn't really meant for external users.

mtfishman commented 1 month ago

I'll keep this issue open as a reminder to remove TimerOutputs from the codebase.

@MazenAli to summarize, I would recommend using a profiler instead, or dev'ing the package and adding your own timers with TimerOutputs if you prefer to use TimerOutputs.