Skip to content

Commit

Permalink
Add better formatting for Experimenter metadata.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 564269088
  • Loading branch information
qiuyiz authored and copybara-github committed Sep 11, 2023
1 parent dbb0896 commit 0ee1737
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion vizier/_src/benchmarks/analyzers/plot_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@
"""Tools for visualization with PlotElements."""


import json
from typing import Optional, Sequence, Tuple
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from vizier import pyvizier as vz
from vizier._src.benchmarks.analyzers import state_analyzer
from vizier.utils import json_utils


def plot_median_convergence(
Expand Down Expand Up @@ -147,8 +150,21 @@ def plot_from_records(
Raises:
ValueError: When plot type is not supported.
"""

def _metadata_to_str(metadata: vz.Metadata) -> str:
visual_dict = {}
for _, key, value in metadata.all_items():
try:
loaded = json.loads(value, cls=json_utils.NumpyDecoder)
assert isinstance(loaded, dict)
visual_dict = visual_dict | {k: v for k, v in loaded.items() if v}
except Exception as e: # pylint: disable=broad-except
del e
visual_dict[key] = value
return str(visual_dict)

records_list = [
(rec.algorithm, str(dict(rec.experimenter_metadata)), rec)
(rec.algorithm, _metadata_to_str(rec.experimenter_metadata), rec)
for rec in records
]
df = pd.DataFrame(
Expand Down

0 comments on commit 0ee1737

Please sign in to comment.