-
Notifications
You must be signed in to change notification settings - Fork 618
/
viz.py
117 lines (99 loc) 路 3.13 KB
/
viz.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
from typing import Any, Dict, Tuple
from wandb.data_types import Table
from wandb.errors import Error
class Visualize:
def __init__(self, id: str, data: Table) -> None:
self._id = id
self._data = data
def get_config_value(self, key: str) -> Dict[str, Any]:
return {
"id": self._id,
"historyFieldSettings": {"x-axis": "_step", "key": key},
}
@staticmethod
def get_config_key(key: str) -> Tuple[str]:
return ("_wandb", "viz", key)
@property
def value(self) -> Table:
return self._data
class CustomChart:
def __init__(
self,
id: str,
data: Table,
fields: Dict[str, Any],
string_fields: Dict[str, Any],
) -> None:
self._id = id
self._data = data
self._fields = fields
self._string_fields = string_fields
def get_config_value(
self,
panel_type: str,
query: Dict[str, Any],
) -> Dict[str, Any]:
return {
"panel_type": panel_type,
"panel_config": {
"panelDefId": self._id,
"fieldSettings": self._fields,
"stringSettings": self._string_fields,
"transform": {"name": "tableWithLeafColNames"},
"userQuery": query,
},
}
@staticmethod
def get_config_key(key: str) -> Tuple[str]:
return ("_wandb", "visualize", key)
@staticmethod
def user_query(table_key: str) -> Dict[str, Any]:
return {
"queryFields": [
{
"name": "runSets",
"args": [{"name": "runSets", "value": "${runSets}"}],
"fields": [
{"name": "id", "fields": []},
{"name": "name", "fields": []},
{"name": "_defaultColorIndex", "fields": []},
{
"name": "summaryTable",
"args": [{"name": "tableKey", "value": table_key}],
"fields": [],
},
],
}
],
}
@property
def table(self) -> Table:
return self._data
@property
def fields(self) -> Dict[str, Any]:
return self._fields
@property
def string_fields(self) -> Dict[str, Any]:
return self._string_fields
def custom_chart(
vega_spec_name: str,
data_table: Table,
fields: Dict[str, Any],
string_fields: Dict[str, Any] = {},
) -> CustomChart:
if not isinstance(data_table, Table):
raise Error(
f"Expected `data_table` to be `wandb.Table` type, instead got {type(data_table).__name__}"
)
return CustomChart(
id=vega_spec_name,
data=data_table,
fields=fields,
string_fields=string_fields,
)
def visualize(id: str, value: Table) -> Visualize:
if not isinstance(value, Table):
raise Error(
f"Expected `value` to be `wandb.Table` type, instead got {type(value).__name__}"
)
return Visualize(id=id, data=value)