Commit c6dadf73 authored by whooie's avatar whooie
Browse files

adjust terminal output from ndscan

parent 75dfc105
...@@ -4,6 +4,7 @@ import inspect ...@@ -4,6 +4,7 @@ import inspect
import ctypes import ctypes
import sys import sys
import time import time
import timeit
from math import prod, log10 from math import prod, log10
from itertools import product from itertools import product
from typing import Callable, Iterable, Sequence, TypeVar from typing import Callable, Iterable, Sequence, TypeVar
...@@ -243,12 +244,12 @@ def _nested_loop_over( ...@@ -243,12 +244,12 @@ def _nested_loop_over(
raise Exception("_nested_loop_over: must have values to loop over") raise Exception("_nested_loop_over: must have values to loop over")
elif len(vals) == 1: elif len(vals) == 1:
_fmt = fmt + f" {{:{int(log10(len(vals[0]))) + 1}}}/{len(vals[0])}" _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]): for k, x in enumerate(vals[0]):
if printflag: if printflag:
print( print(
_fmt.format( _fmt.format(
*(Q + [k]), *([q + 1 for q in Q] + [k + 1]),
100.0 * ( 100.0 * (
sum(q * nnq for q, nnq in zip(Q, NN[1:])) + k sum(q * nnq for q, nnq in zip(Q, NN[1:])) + k
) / NN[0] ) / NN[0]
...@@ -261,7 +262,7 @@ def _nested_loop_over( ...@@ -261,7 +262,7 @@ def _nested_loop_over(
if printflag: if printflag:
print( print(
_fmt.format( _fmt.format(
*([q + 1 for q in Q] + [k]), *([q + 1 for q in Q] + [k + 1]),
100.0 * ( 100.0 * (
sum(q * nnq for q, nnq in zip(Q, NN[1:])) + k + 1 sum(q * nnq for q, nnq in zip(Q, NN[1:])) + k + 1
) / NN[0] ) / NN[0]
...@@ -269,7 +270,6 @@ def _nested_loop_over( ...@@ -269,7 +270,6 @@ def _nested_loop_over(
end="", flush=True end="", flush=True
) )
elif len(vals) == 2 and not reps_first: elif len(vals) == 2 and not reps_first:
print(loop_args, loop_kwargs)
for k, x in enumerate(vals[0]): for k, x in enumerate(vals[0]):
vals[0].pre_loop(x, *loop_args, **loop_kwargs) vals[0].pre_loop(x, *loop_args, **loop_kwargs)
_nested_loop_over( _nested_loop_over(
...@@ -313,19 +313,25 @@ def ndscan( ...@@ -313,19 +313,25 @@ def ndscan(
_vals = [ScanVals(list(range(reps)))] + vals _vals = [ScanVals(list(range(reps)))] + vals
else: else:
_vals = vals + [ScanVals(list(range(reps)))] _vals = vals + [ScanVals(list(range(reps)))]
TOT = prod(len(X) for X in _vals)
t0 = timeit.default_timer()
_nested_loop_over( _nested_loop_over(
_vals, _vals,
loop_func, loop_func,
list(), list(),
[prod(len(X) for X in _vals)], [TOT],
f"\r ", "",
list() if loop_args is None else loop_args, list() if loop_args is None else loop_args,
dict() if loop_kwargs is None else loop_kwargs, dict() if loop_kwargs is None else loop_kwargs,
reps_first, reps_first,
printflag, printflag,
) )
T = timeit.default_timer() - t0
if printflag: 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( def map_scanvars(
scan_maps: Sequence[tuple[Callable[[T, ...], ...], dict[str, Sequence[T]]]], 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