Support scalar-like analytics values#4683
Conversation
7efa912 to
b2f76b7
Compare
There was a problem hiding this comment.
Pull request overview
This PR updates the AnalyticsData validation layer to accept and normalize “scalar-like” numeric values (e.g., objects with .item() such as NumPy scalars / 0-D arrays), and extends unit tests to cover the new behavior and improved error messaging.
Changes:
- Normalize scalar-like values for
SCALAR/METRICanalytics values duringAnalyticsDataconstruction. - Normalize numeric entries inside
SCALARS/METRICSdict payloads and reject non-numeric-scalar dict values. - Add unit tests for scalar-like normalization (including NumPy), dict normalization/rejection, and the
pathvalidation error message.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
nvflare/apis/analytix.py |
Adds numeric-scalar normalization logic and applies it to scalar and dict-based analytics value validation; fixes path error message type reporting. |
tests/unit_test/apis/analytix_test.py |
Adds unit coverage for scalar-like and NumPy scalar normalization, dict normalization/rejection, and path error message validation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
b4c9ce8 to
d66bbbe
Compare
058b94a to
59f1e2b
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4683 +/- ##
==========================================
+ Coverage 56.40% 56.42% +0.01%
==========================================
Files 969 969
Lines 92192 92226 +34
==========================================
+ Hits 52001 52036 +35
+ Misses 40191 40190 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
What changed
AnalyticsData.int/floatvalues as before, plus scalar-like objects with.item()such asnumpy.float32and 0-D numpy arrays.SCALARSandMETRICSdictionaries, and fail fast if a dict entry is not numeric-scalar-like.pathvalidation message to reporttype(path).METRICSdict normalization, non-scalar dict rejection, and thepatherror message.Why
Client tracking writers currently reject values such as
numpy.float32for single scalar metrics because analytics validation only accepts built-in Pythonfloat/int. This can happen with code like:Centralizing the normalization in
AnalyticsDatakeepsSummaryWriter,MLflowWriter,WandBWriter, and lower-level analytics logging paths consistent without adding a numpy dependency to core API code.This is a replacement PR for the previous glitched PR #4659, rebased onto the latest
NVIDIA/NVFlare:mainbefore branch creation.