torchref.utils.stats module
Statistics Utilities for torchref.
Provides verbosity-aware statistics reporting across all refinement components.
Verbosity Levels
VERBOSITY_ESSENTIAL (0): Major weights (ADP, GEOM, Xray targets), R-factors
VERBOSITY_STANDARD (1): Component weights and component losses
VERBOSITY_DETAILED (2): Detailed stats (RMSDs, per-restraint statistics)
VERBOSITY_DEBUG (3): All internal parameters for debugging
Usage
from torchref.utils.stats import stat, filter_stats, VERBOSITY_STANDARD
stats = {
'rwork': stat(0.20, VERBOSITY_ESSENTIAL),
'bond_rmsd': stat(0.015, VERBOSITY_DETAILED),
}
filter_stats(stats, VERBOSITY_ESSENTIAL)
# {'rwork': 0.20}
# StatEntry is JSON serializable - just use json.dumps directly:
import json
json.dumps(stats, cls=StatEntryEncoder)
# '{"rwork": 0.2, "bond_rmsd": 0.015}'
- class torchref.utils.stats.StatEntry(value, verbosity=1)[source]
Bases:
objectA statistics entry with value and verbosity level.
JSON serializable - when serialized, only the value is written.
- value
The statistic value.
- Type:
Any
- __init__(value, verbosity=1)
- torchref.utils.stats.stat(value, verbosity=1)[source]
Create a StatEntry with given value and verbosity.
- torchref.utils.stats.filter_stats(stats, max_verbosity)[source]
Filter stats dictionary to only include entries at or below max_verbosity.
- torchref.utils.stats.flatten_stats(stats, prefix='')[source]
Flatten nested stats dict into flat dict with dotted keys.