Add KL bar plots and sample_frac to load_predicted_local; ignore root parquet scratch files
Adds plot_kl_bars/plot_kl_bars_pl (numpy/polars variants) for ranking which target dimension or pdg/material stratum drives KL regressions, with the same kl*n group capping as plot_marginals. Switches existing histogram plots to step-type/log-scale. Adds sample_frac to load_predicted_local for subsampling large predict parquets. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -20,6 +20,8 @@ from giant.analysis import (
|
||||
plot_constraint_violations,
|
||||
plot_correlation_matrices,
|
||||
plot_direction_alignment,
|
||||
plot_kl_bars,
|
||||
plot_kl_bars_pl,
|
||||
plot_marginals,
|
||||
plot_pairwise,
|
||||
)
|
||||
@@ -155,6 +157,24 @@ def test_plot_constraint_violations_runs_without_error():
|
||||
assert fig is not None
|
||||
|
||||
|
||||
def test_plot_kl_bars_runs_without_error():
|
||||
fig = plot_kl_bars(_make_collection())
|
||||
assert fig is not None
|
||||
|
||||
|
||||
def test_plot_kl_bars_grouped_runs_without_error():
|
||||
fig = plot_kl_bars(_make_collection(), group_by="material")
|
||||
assert fig is not None
|
||||
|
||||
|
||||
def test_plot_kl_bars_caps_groups_by_pdg():
|
||||
collection = _make_collection(n=600)
|
||||
collection.pdg = np.arange(600) % 8 # 8 distinct pdg values, > max_groups
|
||||
fig = plot_kl_bars(collection, group_by="pdg", max_groups=3)
|
||||
ax = fig.axes[0]
|
||||
assert len({line.get_label() for line in ax.containers}) <= 3
|
||||
|
||||
|
||||
def _write_predicted_local_parquet(path, n=50, metadata=None, rng=None):
|
||||
"""Mimic `giant predict --coord local`'s output schema for the loader tests."""
|
||||
rng = rng or np.random.default_rng(0)
|
||||
@@ -300,6 +320,13 @@ def test_marginal_table_pl_matches_numpy_version(tmp_path, group_by):
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("group_by", [None, "pdg", "material", "energy"])
|
||||
def test_plot_kl_bars_pl_runs_without_error(tmp_path, group_by):
|
||||
path = _predicted_local_path(tmp_path)
|
||||
fig = plot_kl_bars_pl(path, group_by=group_by)
|
||||
assert fig is not None
|
||||
|
||||
|
||||
def test_marginal_table_pl_rejects_missing_metadata(tmp_path):
|
||||
path = tmp_path / "no_metadata.parquet"
|
||||
_write_predicted_local_parquet(path, metadata=None)
|
||||
|
||||
Reference in New Issue
Block a user