6
6
import os
7
7
from collections import defaultdict
8
8
from concurrent .futures import ThreadPoolExecutor
9
- from copy import deepcopy
10
9
from functools import partial
11
10
from urllib .parse import quote
12
11
@@ -119,7 +118,11 @@ async def experiment(
119
118
len_test_cases = len (data ) if isinstance (data , list ) else 0
120
119
121
120
if n_trials > 1 :
122
- data = duplicate_dicts (data , n_trials )
121
+ try :
122
+ data = duplicate_dicts (data , n_trials )
123
+ except TypeError as e :
124
+ logger .error (f"Error duplicating input data. You need to manually duplicate input data and set n_trials=1. \n " , exc_info = e )
125
+ raise e
123
126
len_test_cases = len (data ) if isinstance (data , list ) else 0
124
127
print (f"Running { n_trials } trials of the experiment \n " )
125
128
@@ -129,14 +132,12 @@ async def experiment(
129
132
130
133
async def limit_concurrency (sample ):
131
134
async with sem :
132
- sample_copy = deepcopy (sample )
133
- target = sample_copy .pop ("target" , None )
134
- return await func (_parea_target_field = target , ** sample_copy )
135
+ kwargs = {"_parea_target_field" : sample .get ("target" , None ), ** {k : v for k , v in sample .items () if k != "target" }}
136
+ return await func (** kwargs )
135
137
136
138
def limit_concurrency_sync (sample ):
137
- sample_copy = deepcopy (sample )
138
- target = sample_copy .pop ("target" , None )
139
- return func (_parea_target_field = target , ** sample_copy )
139
+ kwargs = {"_parea_target_field" : sample .get ("target" , None ), ** {k : v for k , v in sample .items () if k != "target" }}
140
+ return func (** kwargs )
140
141
141
142
if inspect .iscoroutinefunction (func ):
142
143
tasks = [asyncio .ensure_future (limit_concurrency (sample )) for sample in data ]
@@ -158,7 +159,7 @@ def limit_concurrency_sync(sample):
158
159
import traceback
159
160
160
161
traceback .print_exc ()
161
- print (f"\n Experiment stopped due to an error (note you can deactivate this behavior by setting stop_on_error=False): { str (e )} \n " )
162
+ logger . error (f"\n Experiment stopped due to an error (note you can deactivate this behavior by setting stop_on_error=False): { str (e )} \n " , exc_info = e )
162
163
for task in tasks :
163
164
task .cancel ()
164
165
else :
0 commit comments