66
77
88class AbstractSelector (ABC ):
9- def __init__ (self , name : str ) -> None :
9+ def __init__ (self , name : str , label : str | None = None ) -> None :
1010 """Abstract class for selecting runs based on a specific attribute.
1111
1212 Args:
1313 name: Name of the attribute to select on.
14+ label: Optional label for displaying purposes. If None, defaults to `name`.
15+ Defaults to None.
1416 """
1517 self .name = name
18+ self .label = label or name
1619
1720 @abstractmethod
1821 def __call__ (self , run : Run ) -> Any : ...
@@ -43,9 +46,14 @@ class AbstractParam(AbstractSelector, ABC): ...
4346
4447
4548class Id (AbstractParam ):
46- def __init__ (self ) -> None :
47- """Selector for the ID of the run."""
48- super ().__init__ ("id" )
49+ def __init__ (self , label : str | None = None ) -> None :
50+ """Selector for the ID of the run.
51+
52+ Args:
53+ label: Optional label for displaying purposes. If None, defaults to `name`.
54+ Defaults to None.
55+ """
56+ super ().__init__ ("id" , label )
4957
5058 def __call__ (self , run : Run ) -> str :
5159 return run .id
@@ -63,8 +71,9 @@ def __init__(
6371 self ,
6472 name : str ,
6573 direction : Literal ["min" , "max" ],
74+ label : str | None = None ,
6675 ) -> None :
67- super ().__init__ (name )
76+ super ().__init__ (name , label )
6877 if direction not in ("min" , "max" ):
6978 raise ValueError (
7079 f"Invalid direction: '{ direction } '. Must be 'min' or 'max'."
@@ -79,6 +88,8 @@ class Metric(AbstractMetric):
7988 name: Name of the metric to select on.
8089 direction: Direction of the metric. "min" for minimization, "max" for
8190 maximization.
91+ label: Optional label for displaying purposes. If None, defaults to `name`.
92+ Defaults to None.
8293 """
8394
8495 def __call__ (self , run : Run ) -> float :
@@ -94,6 +105,7 @@ def __init__(
94105 name : str ,
95106 direction : Literal ["min" , "max" ],
96107 reduction : Literal ["min" , "max" , "first" , "last" ] | None = None ,
108+ label : str | None = None ,
97109 ) -> None :
98110 """Selector for a specific temporal metric of the run.
99111
@@ -105,8 +117,10 @@ def __init__(
105117 minimum, "max" for maximum, "first" for the first value, and "last"
106118 for the last value. If None, the direction is used as the reduction.
107119 Defaults to None.
120+ label: Optional label for displaying purposes. If None, defaults to `name`.
121+ Defaults to None.
108122 """
109- super ().__init__ (name , direction )
123+ super ().__init__ (name , direction , label )
110124 if reduction is not None and reduction not in ("min" , "max" , "first" , "last" ):
111125 raise ValueError (
112126 f"Invalid reduction method: '{ reduction } '. Must be 'min', 'max', "
0 commit comments