@@ -146,13 +146,14 @@ def _run_configs(self, xs, check_restrictions=True):
146146 batch_keys = [] # The keys of the configs to run
147147 pending_indices_by_key = dict () # Maps key => where to store result in `final_results`
148148 final_results = [] # List returned to the user
149+ legal_indices = [] # Indices in `final_results` that are legal
149150
150151 # Loop over all configurations. For each configurations there are four cases:
151152 # 1. The configuration is invalid, we can skip it
152153 # 2. The configuration is in `unique_results`, we can get it from there
153154 # 3. The configuration is in `pending_indices_by_key`, it is duplicate in `xs`
154155 # 4. The configuration must be evaluated by the runner.
155- for x in xs :
156+ for index , x in enumerate ( xs ) :
156157 config , is_legal = self ._normalize_and_validate_config (x , check_restrictions = check_restrictions )
157158 logging .debug ("normalize config: %s -> %s (legal: %s)" , str (x ), str (config ), is_legal )
158159 key = "," .join ([str (i ) for i in config ])
@@ -166,18 +167,19 @@ def _run_configs(self, xs, check_restrictions=True):
166167 # 2. Attempt to retrieve from `unique_results`
167168 elif key in self .unique_results :
168169 result = dict (self .unique_results [key ])
170+ legal_indices .append (index )
169171 final_results .append (result )
170172
171173 # 3. We have already seen this config in the current batch
172174 elif key in pending_indices_by_key :
173- pending_indices_by_key [key ].append (len ( final_results ) )
175+ pending_indices_by_key [key ].append (index )
174176 final_results .append (None )
175177
176178 # 4. A new config, we must evaluate this
177179 else :
178180 batch_keys .append (key )
179181 batch_configs .append (config )
180- pending_indices_by_key [key ] = [len ( final_results ) ]
182+ pending_indices_by_key [key ] = [index ]
181183 final_results .append (None )
182184
183185 # compile and benchmark the batch
@@ -190,6 +192,7 @@ def _run_configs(self, xs, check_restrictions=True):
190192
191193 # set in the results array
192194 for index in pending_indices_by_key [key ]:
195+ legal_indices .append (index )
193196 final_results [index ] = dict (result )
194197
195198 # Disable the timings. Only the first result must get these.
@@ -200,10 +203,9 @@ def _run_configs(self, xs, check_restrictions=True):
200203 # Put result in `unique_results`
201204 self .unique_results [key ] = result
202205
203- for result in final_results :
204- # Skip if None. Result is missing if runner exhausted the budget
205- if result is not None :
206- self .results .append (result )
206+ # Only things in `legal_indices` are valid results
207+ for index in sorted (legal_indices ):
208+ self .results .append (final_results [index ])
207209
208210 # upon returning from this function control will be given back to the strategy, so reset the start time
209211 self .runner .last_strategy_start_time = perf_counter ()
0 commit comments