Skip to content

Commit cf5cc0f

Browse files
author
Yuwei Yan
committed
update
1 parent 188608c commit cf5cc0f

File tree

5 files changed

+44
-8
lines changed

5 files changed

+44
-8
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ evaluation_results = simulator.evaluate()
178178
- [Recommendation Track](https://tsinghua-fib-lab.github.io/AgentSocietyChallenge/pages/recommendation-track.html)
179179
- Please register your team first.
180180
- When you submit your agent, please carefully **SELECT the TRACK you want to submit to.**
181-
- **The content of your submission should be a zip file containing your agent (Only one `{your_agent}.py` file without evaluation code).**
181+
- **The content of your submission should be a .py file containing your agent (Only one `{your_team}.py` file without evaluation code).**
182182
- Example submissions:
183183
- For Track 1: [submission_1](example/trackOneSubmission_example.zip)
184184
- For Track 2: [submission_2](example/trackTwoSubmission_example.zip)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
Team name,Submission Time,Preference Estimation,Review Generation,Overall Quality
22
baseline,2024-12-31, 0.6879, 0.8098, 0.7489
33
RankMe, 2025-01-03, 0.6823, 0.8087, 0.7455
4+
伸腿瞪眼丸, 2025-01-06, 0.7966, 0.8700, 0.8333
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
Team name,Submission Time,Top-1 hr,Top-3 hr,Top-5 hr,Overall hr
22
baseline, 2024-12-31, 0.0766, 0.2033, 0.3116, 0.1972
33
RankMe, 2025-01-04, 0.0683, 0.2050, 0.2833, 0.1855
4+
谭湘文, 2025-01-06, 0.4316, 0.6516, 0.7516, 0.6116
5+
KON, 2025-01-06, 0.3383, 0.5900, 0.6850, 0.5377

docs/pages/submission-guidelines.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ <h2>Submit Your Agent</h2>
288288
<ul>
289289
<li>Please register your team first. <a href="https://forms.gle/wisLykLK8eGB2X1PA" target="_blank">Registration</a></li>
290290
<li>Please carefully <strong>SELECT the TRACK</strong> you want to submit to.</li>
291-
<li><strong>The content of your submission should be a zip file containing your agent (Only one <code>{your_agent}.py</code> file without evaluation code).</strong></li>
291+
<li><strong>The content of your submission should be a .py file containing your agent (Only one <code>{your_team}.py</code> file without evaluation code).</strong></li>
292292
<li>Example submissions:
293293
<ul>
294294
<li>For Track 1: <a href="https://github.com/tsinghua-fib-lab/AgentSocietyChallenge/blob/main/example/trackOneSubmission_example.zip" target="_blank">submission_1</a></li>

websocietysimulator/simulator.py

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,17 +121,24 @@ def set_llm(self, llm: Union[LLMBase, list[LLMBase]]):
121121
self.llm = llm
122122
logger.info("LLM set")
123123

124-
def run_simulation(self, number_of_tasks: int = None, enable_threading: bool = False, max_workers: int = None) -> List[Any]:
124+
def run_simulation(self, number_of_tasks: int = None, enable_threading: bool = False, max_workers: int = None, time_limitation: float = None) -> List[Any]:
125125
"""
126-
Run the simulation with optional multi-threading support.
126+
Run the simulation with optional multi-threading support and time limitation.
127127
128128
Args:
129129
number_of_tasks: Number of tasks to run. If None, run all tasks.
130130
enable_threading: Whether to enable multi-threading. Default is False.
131131
max_workers: Maximum number of threads to use. If None, will use min(32, number_of_tasks).
132+
time_limitation: Time limit in minutes. If None, no time limit is applied.
132133
Returns:
133134
List of outputs from agents for each scenario.
134135
"""
136+
import time
137+
from concurrent.futures import ThreadPoolExecutor, as_completed, TimeoutError
138+
139+
start_time = time.time()
140+
timeout_seconds = time_limitation * 60 if time_limitation else None
141+
135142
logger.info("Running simulation")
136143
if not self.agent_class:
137144
raise RuntimeError("Agent class is not set. Use set_agent() to set it.")
@@ -145,6 +152,11 @@ def run_simulation(self, number_of_tasks: int = None, enable_threading: bool = F
145152
if not enable_threading:
146153
self.simulation_outputs = []
147154
for index, task in enumerate(task_to_run):
155+
# 检查是否超时
156+
if timeout_seconds and (time.time() - start_time) > timeout_seconds:
157+
logger.warning(f"Time limit ({time_limitation} minutes) reached. Stopping simulation.")
158+
break
159+
148160
if isinstance(self.llm, list):
149161
agent = self.agent_class(llm=self.llm[index%len(self.llm)])
150162
else:
@@ -167,15 +179,17 @@ def run_simulation(self, number_of_tasks: int = None, enable_threading: bool = F
167179
logger.info(f"Simulation finished for task {index}")
168180
else:
169181
# 多线程处理
170-
from concurrent.futures import ThreadPoolExecutor
171182
from threading import Lock
172183

173184
log_lock = Lock()
174185
self.simulation_outputs = [None] * len(task_to_run)
175186

176187
def process_task(task_index_tuple):
177188
index, task = task_index_tuple
178-
agent = self.agent_class(llm=self.llm)
189+
if isinstance(self.llm, list):
190+
agent = self.agent_class(llm=self.llm[index%len(self.llm)])
191+
else:
192+
agent = self.agent_class(llm=self.llm)
179193
agent.set_interaction_tool(self.interaction_tool)
180194
agent.insert_task(task)
181195

@@ -195,7 +209,7 @@ def process_task(task_index_tuple):
195209
logger.info(f"Simulation finished for task {index}")
196210

197211
self.simulation_outputs[index] = result
198-
return result
212+
return index, result
199213

200214
# 确定线程数
201215
if max_workers is None:
@@ -204,10 +218,29 @@ def process_task(task_index_tuple):
204218
max_workers = min(max_workers, len(task_to_run))
205219

206220
logger.info(f"Running with {max_workers} threads")
221+
207222
with ThreadPoolExecutor(max_workers=max_workers) as executor:
208-
list(executor.map(process_task, enumerate(task_to_run)))
223+
# 提交所有任务
224+
future_to_index = {
225+
executor.submit(process_task, (i, task)): i
226+
for i, task in enumerate(task_to_run)
227+
}
228+
229+
try:
230+
# 等待所有任务完成或达到时间限制
231+
for future in as_completed(future_to_index, timeout=timeout_seconds):
232+
try:
233+
index, result = future.result()
234+
self.simulation_outputs[index] = result
235+
except Exception as e:
236+
logger.error(f"Task failed with error: {str(e)}")
237+
except TimeoutError:
238+
logger.error(f"Time limit ({time_limitation} minutes) reached.")
239+
raise TimeoutError
209240

210241
logger.info("Simulation finished")
242+
# 过滤掉None值(未完成的任务)
243+
self.simulation_outputs = [output for output in self.simulation_outputs if output is not None]
211244
return self.simulation_outputs
212245

213246
def evaluate(self) -> Dict[str, Any]:

0 commit comments

Comments
 (0)