Commit c6dadf73 authored by whooie's avatar whooie
Browse files

adjust terminal output from ndscan

parent 75dfc105
......@@ -4,6 +4,7 @@ import inspect
import ctypes
import sys
import time
import timeit
from math import prod, log10
from itertools import product
from typing import Callable, Iterable, Sequence, TypeVar
......@@ -243,12 +244,12 @@ def _nested_loop_over(
raise Exception("_nested_loop_over: must have values to loop over")
elif len(vals) == 1:
_fmt = fmt + f" {{:{int(log10(len(vals[0]))) + 1}}}/{len(vals[0])}"
_fmt += " ({:6.2f}%) "
_fmt += " ({:6.2f}%) \r"
for k, x in enumerate(vals[0]):
if printflag:
print(
_fmt.format(
*(Q + [k]),
*([q + 1 for q in Q] + [k + 1]),
100.0 * (
sum(q * nnq for q, nnq in zip(Q, NN[1:])) + k
) / NN[0]
......@@ -261,7 +262,7 @@ def _nested_loop_over(
if printflag:
print(
_fmt.format(
*([q + 1 for q in Q] + [k]),
*([q + 1 for q in Q] + [k + 1]),
100.0 * (
sum(q * nnq for q, nnq in zip(Q, NN[1:])) + k + 1
) / NN[0]
......@@ -269,7 +270,6 @@ def _nested_loop_over(
end="", flush=True
)
elif len(vals) == 2 and not reps_first:
print(loop_args, loop_kwargs)
for k, x in enumerate(vals[0]):
vals[0].pre_loop(x, *loop_args, **loop_kwargs)
_nested_loop_over(
......@@ -313,19 +313,25 @@ def ndscan(
_vals = [ScanVals(list(range(reps)))] + vals
else:
_vals = vals + [ScanVals(list(range(reps)))]
TOT = prod(len(X) for X in _vals)
t0 = timeit.default_timer()
_nested_loop_over(
_vals,
loop_func,
list(),
[prod(len(X) for X in _vals)],
f"\r ",
[TOT],
"",
list() if loop_args is None else loop_args,
dict() if loop_kwargs is None else loop_kwargs,
reps_first,
printflag,
)
T = timeit.default_timer() - t0
if printflag:
print("")
print(
f"\n total time elapsed: {T:.2f} s"
f"\n average time per shot: {T / TOT:.2f} s"
)
def map_scanvars(
scan_maps: Sequence[tuple[Callable[[T, ...], ...], dict[str, Sequence[T]]]],
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment