Use logging and tqdm; fix numpy where-without-out warning #4
Loading…
Reference in a new issue
No description provided.
Delete branch "modernize-logging-and-progress"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Three commits: the numpy fix, the logging/tqdm work, and the version bump to 1.2.0.
Logging
Output went through bare
print()— stage banners prefixed with#, a dot per completed energy, and a\rpercentage counter in the Penn ELF loop. None of it could be silenced, redirected, or levelled.Stage messages are now
logger.infoon per-module loggers, configured inmain()with a--log-levelflag (DEBUG…CRITICAL, default INFO). The checksum-failure message becamelogger.warning, since it reports a corrupted download rather than routine progress. The commented-out debug print inendf_reader._print_debugis now a livelogger.debug, reachable via--log-level DEBUG— parsing Si takes 14 ms, so the per-record level check is irrelevant.Progress bars
tqdm on the four long loops. Two details that matter:
logging_redirect_tqdm(), which routes log records throughtqdm.write(). Without it, a message arriving mid-loop interleaves with the bar's\rredraws and tears the line.disable=None, so tqdm suppresses itself when stderr is not a tty. Redirected and CI runs produce clean log lines with no bar frames — which is what thecompilejob wants.Confirmed in a real terminal:
numpy warning
np.log(y, where=y>0)withoutout=leaves masked entries uninitialized, which numpy warns about twice per compile. The next line overwrote every masked entry with-inf, so nothing was actually reading garbage — the code just relied on that. Nowout=np.full(shape, -inf)makes the intent explicit and the fill replaces the separate assignment.Verified equivalent: old and new expressions give bit-identical arrays over 200 random inputs containing zeros and negatives.
Verification
silicon.yamlcompile,exit=0, twicealuminium.yaml: all four bars render and complete cleanlyuv run basedpyright: 0 errors, 0 warnings, 0 notesBehaviour change
The version banner is logged rather than printed, so it no longer precedes
--helpoutput and is silenced by--log-level WARNING.np.log(y, where=y>0) without out= leaves the masked entries uninitialized, which numpy warns about: UserWarning: 'where' used without 'out', expect uninitialized memory in output. If this is intentional, use out=None. The following line overwrote every masked entry with -inf, so nothing was actually reading garbage, but the code relied on that and the warning fired twice per compile. Passing out=np.full(shape, -inf) makes the intent explicit and lets the fill replace the separate assignment. Verified equivalent: the old and new expressions produce bit-identical arrays over 200 random inputs containing zeros and negative values. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>