Skip to content

Commit e3f89a3

Browse files
committed
Implement runtime counting for optimizer steps
1 parent 4daea03 commit e3f89a3

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

varipeps/optimization/optimizer.py

+16
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from collections import deque
33
from functools import partial
44
from os import PathLike
5+
import time
56

67
from scipy.optimize import OptimizeResult
78

@@ -210,6 +211,7 @@ def _autosave_wrapper(
210211
step_energies,
211212
step_chi,
212213
step_conv,
214+
step_runtime,
213215
spiral_indices,
214216
additional_input,
215217
):
@@ -223,6 +225,7 @@ def _autosave_wrapper(
223225
auxiliary_data[f"step_energies_{k:d}"] = step_energies[k]
224226
auxiliary_data[f"step_chi_{k:d}"] = step_chi[k]
225227
auxiliary_data[f"step_conv_{k:d}"] = step_conv[k]
228+
auxiliary_data[f"step_runtime_{k:d}"] = step_runtime[k]
226229

227230
spiral_vectors = None
228231
if spiral_indices is not None:
@@ -390,6 +393,7 @@ def random_noise(a):
390393
step_energies = {random_noise_retries: []}
391394
step_chi = {random_noise_retries: []}
392395
step_conv = {random_noise_retries: []}
396+
step_runtime = {random_noise_retries: []}
393397

394398
if (
395399
varipeps_config.optimizer_preconverge_with_half_projectors
@@ -401,6 +405,8 @@ def random_noise(a):
401405

402406
with tqdm(desc="Optimizing PEPS state") as pbar:
403407
while count < varipeps_config.optimizer_max_steps:
408+
runtime_start = time.perf_counter()
409+
404410
try:
405411
if varipeps_config.ad_use_custom_vjp:
406412
(
@@ -579,6 +585,9 @@ def random_noise(a):
579585
conv > varipeps_config.optimizer_reuse_env_eps,
580586
)
581587
except NoSuitableStepSizeError:
588+
runtime = time.perf_counter() - runtime_start
589+
step_runtime[random_noise_retries].append(runtime)
590+
582591
if varipeps_config.optimizer_fail_if_no_step_size_found:
583592
raise
584593
else:
@@ -612,6 +621,7 @@ def random_noise(a):
612621
step_energies,
613622
step_chi,
614623
step_conv,
624+
step_runtime,
615625
spiral_indices,
616626
additional_input,
617627
)
@@ -659,6 +669,7 @@ def random_noise(a):
659669
step_chi[random_noise_retries] = []
660670
step_conv[random_noise_retries] = []
661671
max_trunc_error_list[random_noise_retries] = []
672+
step_runtime[random_noise_retries] = []
662673

663674
pbar.reset()
664675
pbar.refresh()
@@ -667,6 +678,8 @@ def random_noise(a):
667678
else:
668679
conv = 0
669680
else:
681+
runtime = time.perf_counter() - runtime_start
682+
step_runtime[random_noise_retries].append(runtime)
670683
max_trunc_error_list[random_noise_retries].append(max_trunc_error)
671684
step_energies[random_noise_retries].append(working_value)
672685
step_chi[random_noise_retries].append(
@@ -751,6 +764,7 @@ def random_noise(a):
751764
step_energies,
752765
step_chi,
753766
step_conv,
767+
step_runtime,
754768
spiral_indices,
755769
additional_input,
756770
)
@@ -797,6 +811,7 @@ def random_noise(a):
797811
step_energies,
798812
step_chi,
799813
step_conv,
814+
step_runtime,
800815
spiral_indices,
801816
additional_input,
802817
)
@@ -813,5 +828,6 @@ def random_noise(a):
813828
step_energies=step_energies,
814829
step_chi=step_chi,
815830
step_conv=step_conv,
831+
step_runtime=step_runtime,
816832
best_run=best_run,
817833
)

0 commit comments

Comments
 (0)