@@ -50,6 +50,11 @@ def load_scores(self):
50
50
- 1
51
51
)
52
52
53
+ self .solved_tasks = data .get (
54
+ f"solved_tasks" ,
55
+ np .zeros (self .neuron .metagraph .n , dtype = np .float32 ),
56
+ )
57
+
53
58
self .total_scores = data .get (
54
59
f"total_scores_{ __STATE_VERSION__ } " ,
55
60
np .zeros (self .neuron .metagraph .n , dtype = np .float32 ),
@@ -62,6 +67,7 @@ def load_scores(self):
62
67
bt .logging .error (f"Error loading state: { e } " )
63
68
self .hotkeys = copy .deepcopy (self .neuron .metagraph .hotkeys )
64
69
self .current_session = - 1
70
+ self .solved_tasks = np .zeros (self .neuron .metagraph .n , dtype = np .float32 )
65
71
self .total_scores = np .zeros (self .neuron .metagraph .n , dtype = np .float32 )
66
72
self .last_set_weights_session = - 1
67
73
self .number_of_tasks = 0
@@ -76,6 +82,7 @@ def save_scores(self):
76
82
** {f"current_session" : self .current_session },
77
83
last_set_weights_session = self .last_set_weights_session ,
78
84
number_of_tasks = self .number_of_tasks ,
85
+ solved_tasks = self .solved_tasks ,
79
86
** {f"total_scores_{ __STATE_VERSION__ } " : self .total_scores },
80
87
session_results = self .session_results ,
81
88
allow_pickle = True ,
@@ -91,6 +98,7 @@ def set_new_hotkeys(self, new_hotkeys: List[str]):
91
98
for uid , hotkey in enumerate (self .hotkeys ):
92
99
if hotkey != new_hotkeys [uid ]:
93
100
self .total_scores [uid ] = 0
101
+ self .solved_tasks [uid ] = 0
94
102
95
103
# Check to see if the metagraph has changed size.
96
104
# If so, we need to add new hotkeys and moving averages.
@@ -100,6 +108,11 @@ def set_new_hotkeys(self, new_hotkeys: List[str]):
100
108
new_total_scores [:min_len ] = self .total_scores [:min_len ]
101
109
self .total_scores = new_total_scores
102
110
111
+ new_solved_tasks = np .zeros ((len (new_hotkeys )))
112
+ min_len = min (len (self .hotkeys ), len (self .solved_tasks ))
113
+ new_solved_tasks [:min_len ] = self .solved_tasks [:min_len ]
114
+ self .solved_tasks = new_solved_tasks
115
+
103
116
# Update the hotkeys.
104
117
self .hotkeys = copy .deepcopy (new_hotkeys )
105
118
with self .lock :
@@ -113,16 +126,27 @@ def update_scores(self, rewards: np.ndarray, uids: List[int], challenge: Challen
113
126
# This is a new session, reset the scores and winners.
114
127
self .current_session = session
115
128
self .number_of_tasks = 0
129
+ self .solved_tasks = np .zeros (self .neuron .metagraph .n , dtype = np .float32 )
116
130
self .total_scores = np .zeros (self .neuron .metagraph .n , dtype = np .float32 )
117
131
# Update accumulated scores and track best performer
118
132
self .number_of_tasks += 1
119
133
self .total_scores [uids ] += rewards
134
+ self .solved_tasks [uids ] += 1
120
135
136
+ avg_scores = np .zeros (self .neuron .metagraph .n , dtype = np .float32 )
137
+ for uid in range (self .neuron .metagraph .n ):
138
+ if self .solved_tasks [uid ] >= max (1 , self .number_of_tasks / 2 ):
139
+ avg_scores [uid ] = self .total_scores [uid ] / self .solved_tasks [uid ]
140
+ else :
141
+ avg_scores [uid ] = 0
142
+ winner = np .argmax (avg_scores ) if max (avg_scores ) > 0 else - 1
143
+
121
144
current_session_results = {
122
145
"session" : session ,
123
146
"competition_type" : competition_type ,
124
147
"number_of_tasks" : self .number_of_tasks ,
125
- "winner" : np .argmax (self .total_scores ),
148
+ "winner" : winner ,
149
+ "solved_tasks" : self .solved_tasks ,
126
150
"scores" : self .total_scores ,
127
151
}
128
152
@@ -162,42 +186,51 @@ def get_scores(self, session_upto: int):
162
186
# return np.power(scores, 9)
163
187
164
188
def print_session_result (self , session_upto : int , console : Console ):
165
- session_result = self .session_results [session_upto ]
166
-
167
- number_of_tasks = session_result ["number_of_tasks" ]
168
- session = session_result ["session" ]
169
- competition_type = session_result ["competition_type" ]
170
- winner = session_result ["winner" ]
171
- scores = session_result ["scores" ]
172
-
173
- total_scores_table = Table (
174
- title = (
175
- f"📊 Total Scores Summary\n "
176
- f"🔄 Session: #{ session } \n "
177
- f"📝 Number of Tasks: #{ number_of_tasks } \n "
178
- f"🏆 Competition: { competition_type } \n "
179
- f"👑 Winner: #{ winner } \n "
180
- ),
181
- show_header = True ,
182
- header_style = "bold magenta" ,
183
- title_style = "bold blue" ,
184
- border_style = "blue"
185
- )
186
-
187
- total_scores_table .add_column ("Rank" , justify = "right" , style = "red" , header_style = "bold red" )
188
- total_scores_table .add_column ("UID" , justify = "right" , style = "cyan" , header_style = "bold cyan" )
189
- total_scores_table .add_column ("Total Score" , justify = "right" , style = "green" )
190
- total_scores_table .add_column ("Average Score" , justify = "right" , style = "yellow" )
191
- scored_uids = [(uid , score ) for uid , score in enumerate (scores ) if score > 0 ]
192
- scored_uids .sort (key = lambda x : x [1 ], reverse = True )
193
- for rank , (uid , score ) in enumerate (scored_uids ):
194
- total_scores_table .add_row (
195
- str (rank + 1 ),
196
- str (uid ),
197
- f"{ score :.4f} " ,
198
- f"{ score / number_of_tasks :.4f} " ,
189
+ try :
190
+ session_result = self .session_results [session_upto ]
191
+
192
+ number_of_tasks = session_result ["number_of_tasks" ]
193
+ session = session_result ["session" ]
194
+ competition_type = session_result ["competition_type" ]
195
+ winner = session_result ["winner" ]
196
+ scores = session_result ["scores" ]
197
+ solved_tasks = session_result ["solved_tasks" ]
198
+
199
+ avg_scores = np .zeros (self .neuron .metagraph .n , dtype = np .float32 )
200
+ for uid in range (self .neuron .metagraph .n ):
201
+ if solved_tasks [uid ] >= max (1 , number_of_tasks / 2 ):
202
+ avg_scores [uid ] = scores [uid ] / solved_tasks [uid ]
203
+ else :
204
+ avg_scores [uid ] = 0
205
+
206
+ total_scores_table = Table (
207
+ title = (
208
+ f"📊 Total Scores Summary\n "
209
+ f"🔄 Session: #{ session } \n "
210
+ f"📝 Number of Tasks: #{ number_of_tasks } \n "
211
+ f"🏆 Competition: { competition_type } \n "
212
+ f"👑 Winner: #{ winner } \n "
213
+ ),
214
+ show_header = True ,
215
+ header_style = "bold magenta" ,
216
+ title_style = "bold blue" ,
217
+ border_style = "blue"
199
218
)
200
- console .print (total_scores_table )
219
+
220
+ total_scores_table .add_column ("Rank" , justify = "right" , style = "red" , header_style = "bold red" )
221
+ total_scores_table .add_column ("UID" , justify = "right" , style = "cyan" , header_style = "bold cyan" )
222
+ total_scores_table .add_column ("Average Score" , justify = "right" , style = "yellow" )
223
+ scored_uids = [(uid , avg_scores [uid ]) for uid in range (self .neuron .metagraph .n ) if avg_scores [uid ] > 0 ]
224
+ scored_uids .sort (key = lambda x : x [1 ], reverse = True )
225
+ for rank , (uid , score ) in enumerate (scored_uids ):
226
+ total_scores_table .add_row (
227
+ str (rank + 1 ),
228
+ str (uid ),
229
+ f"{ score :.4f} " ,
230
+ )
231
+ console .print (total_scores_table )
232
+ except Exception as e :
233
+ bt .logging .warning (f"Error printing session result: { e } " )
201
234
202
235
def save_session_result_to_file (self , session_upto : int ):
203
236
try :
@@ -211,3 +244,4 @@ def save_session_result_to_file(self, session_upto: int):
211
244
except Exception as e :
212
245
bt .logging .error (f"Error saving session result to file: { e } " )
213
246
raise e
247
+
0 commit comments