pycityagent 2.0.0a74__cp312-cp312-macosx_11_0_arm64.whl → 2.0.0a76__cp312-cp312-macosx_11_0_arm64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pycityagent/environment/simulator.py +63 -86
- pycityagent/pycityagent-sim +0 -0
- pycityagent/simulation/agentgroup.py +19 -9
- pycityagent/simulation/simulation.py +55 -33
- {pycityagent-2.0.0a74.dist-info → pycityagent-2.0.0a76.dist-info}/METADATA +1 -1
- {pycityagent-2.0.0a74.dist-info → pycityagent-2.0.0a76.dist-info}/RECORD +10 -10
- {pycityagent-2.0.0a74.dist-info → pycityagent-2.0.0a76.dist-info}/LICENSE +0 -0
- {pycityagent-2.0.0a74.dist-info → pycityagent-2.0.0a76.dist-info}/WHEEL +0 -0
- {pycityagent-2.0.0a74.dist-info → pycityagent-2.0.0a76.dist-info}/entry_points.txt +0 -0
- {pycityagent-2.0.0a74.dist-info → pycityagent-2.0.0a76.dist-info}/top_level.txt +0 -0
@@ -3,19 +3,19 @@
|
|
3
3
|
import asyncio
|
4
4
|
import logging
|
5
5
|
import os
|
6
|
-
from datetime import datetime, timedelta
|
7
6
|
import time
|
7
|
+
from datetime import datetime, timedelta
|
8
8
|
from typing import Optional, Union, cast
|
9
9
|
|
10
|
+
import ray
|
11
|
+
from mosstool.type import TripMode
|
10
12
|
from mosstool.util.format_converter import coll2pb, dict2pb
|
11
13
|
from pycitydata.map import Map as SimMap
|
12
14
|
from pycityproto.city.map.v2 import map_pb2 as map_pb2
|
13
15
|
from pycityproto.city.person.v2 import person_pb2 as person_pb2
|
14
16
|
from pycityproto.city.person.v2 import person_service_pb2 as person_service
|
15
17
|
from pymongo import MongoClient
|
16
|
-
import ray
|
17
18
|
from shapely.geometry import Point
|
18
|
-
from mosstool.type import TripMode
|
19
19
|
|
20
20
|
from .sim import CityClient, ControlSimEnv
|
21
21
|
from .utils.const import *
|
@@ -26,22 +26,30 @@ __all__ = [
|
|
26
26
|
"Simulator",
|
27
27
|
]
|
28
28
|
|
29
|
+
|
29
30
|
@ray.remote
|
30
31
|
class CityMap:
|
31
|
-
def __init__(self,
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
32
|
+
def __init__(self, mongo_input: tuple[str, str, str, str], map_cache_path: str):
|
33
|
+
if map_cache_path:
|
34
|
+
self.map = SimMap(
|
35
|
+
pb_path=map_cache_path,
|
36
|
+
)
|
37
|
+
else:
|
38
|
+
mongo_uri, mongo_db, mongo_coll, cache_dir = mongo_input
|
39
|
+
self.map = SimMap(
|
40
|
+
mongo_uri=mongo_uri,
|
41
|
+
mongo_db=mongo_db,
|
42
|
+
mongo_coll=mongo_coll,
|
43
|
+
cache_dir=cache_dir,
|
44
|
+
)
|
45
|
+
self.poi_cate = POI_CATG_DICT
|
38
46
|
|
39
47
|
def get_aoi(self, aoi_id: Optional[int] = None):
|
40
48
|
if aoi_id is None:
|
41
49
|
return list(self.map.aois.values())
|
42
50
|
else:
|
43
51
|
return self.map.aois[aoi_id]
|
44
|
-
|
52
|
+
|
45
53
|
def get_poi(self, poi_id: Optional[int] = None):
|
46
54
|
if poi_id is None:
|
47
55
|
return list(self.map.pois.values())
|
@@ -50,19 +58,20 @@ class CityMap:
|
|
50
58
|
|
51
59
|
def query_pois(self, **kwargs):
|
52
60
|
return self.map.query_pois(**kwargs)
|
53
|
-
|
61
|
+
|
54
62
|
def get_poi_cate(self):
|
55
63
|
return self.poi_cate
|
56
|
-
|
64
|
+
|
57
65
|
def get_map(self):
|
58
66
|
return self.map
|
59
|
-
|
67
|
+
|
60
68
|
def get_map_header(self):
|
61
69
|
return self.map.header
|
62
70
|
|
63
71
|
def get_projector(self):
|
64
72
|
return self.map.header["projection"]
|
65
73
|
|
74
|
+
|
66
75
|
class Simulator:
|
67
76
|
"""
|
68
77
|
Main class of the simulator.
|
@@ -132,7 +141,11 @@ class Simulator:
|
|
132
141
|
- Simulator map object
|
133
142
|
"""
|
134
143
|
if create_map:
|
135
|
-
|
144
|
+
_map_cache_path = "" # 地图pb文件路径
|
145
|
+
self._map = CityMap.remote(
|
146
|
+
(_mongo_uri, _mongo_db, _mongo_coll, _map_cache_dir),
|
147
|
+
_map_cache_path,
|
148
|
+
)
|
136
149
|
self._create_poi_id_2_aoi_id()
|
137
150
|
|
138
151
|
self.time: int = 0
|
@@ -145,15 +158,15 @@ class Simulator:
|
|
145
158
|
self.map_y_gap = None
|
146
159
|
self._bbox: tuple[float, float, float, float] = (-1, -1, -1, -1)
|
147
160
|
self._lock = asyncio.Lock()
|
148
|
-
self._environment_prompt:dict[str, str] = {}
|
161
|
+
self._environment_prompt: dict[str, str] = {}
|
149
162
|
self._log_list = []
|
150
163
|
|
151
|
-
def set_map(self, map:
|
164
|
+
def set_map(self, map: ray.ObjectRef):
|
152
165
|
self._map = map
|
153
166
|
self._create_poi_id_2_aoi_id()
|
154
167
|
|
155
168
|
def _create_poi_id_2_aoi_id(self):
|
156
|
-
pois = ray.get(self._map.get_poi.remote())
|
169
|
+
pois = ray.get(self._map.get_poi.remote()) # type:ignore
|
157
170
|
self.poi_id_2_aoi_id: dict[int, int] = {
|
158
171
|
poi["id"]: poi["aoi_id"] for poi in pois
|
159
172
|
}
|
@@ -164,7 +177,7 @@ class Simulator:
|
|
164
177
|
|
165
178
|
def get_log_list(self):
|
166
179
|
return self._log_list
|
167
|
-
|
180
|
+
|
168
181
|
def clear_log_list(self):
|
169
182
|
self._log_list = []
|
170
183
|
|
@@ -177,7 +190,7 @@ class Simulator:
|
|
177
190
|
Get the current state of environment variables.
|
178
191
|
"""
|
179
192
|
return self._environment_prompt
|
180
|
-
|
193
|
+
|
181
194
|
def get_server_addr(self):
|
182
195
|
return self.server_addr
|
183
196
|
|
@@ -229,11 +242,7 @@ class Simulator:
|
|
229
242
|
Refer to https://cityproto.sim.fiblab.net/#city.person.1.GetPersonByLongLatBBoxResponse.
|
230
243
|
"""
|
231
244
|
start_time = time.time()
|
232
|
-
log = {
|
233
|
-
"req": "find_agents_by_area",
|
234
|
-
"start_time": start_time,
|
235
|
-
"consumption": 0
|
236
|
-
}
|
245
|
+
log = {"req": "find_agents_by_area", "start_time": start_time, "consumption": 0}
|
237
246
|
loop = asyncio.get_event_loop()
|
238
247
|
resp = loop.run_until_complete(
|
239
248
|
self._client.person_service.GetPersonByLongLatBBox(req=req)
|
@@ -268,19 +277,17 @@ class Simulator:
|
|
268
277
|
- `List[str]`: A list of unique POI category names.
|
269
278
|
"""
|
270
279
|
start_time = time.time()
|
271
|
-
log = {
|
272
|
-
"req": "get_poi_categories",
|
273
|
-
"start_time": start_time,
|
274
|
-
"consumption": 0
|
275
|
-
}
|
280
|
+
log = {"req": "get_poi_categories", "start_time": start_time, "consumption": 0}
|
276
281
|
categories: list[str] = []
|
277
282
|
if center is None:
|
278
283
|
center = (0, 0)
|
279
|
-
_pois: list[dict] = ray.get(
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
+
_pois: list[dict] = ray.get(
|
285
|
+
self.map.query_pois.remote( # type:ignore
|
286
|
+
center=center,
|
287
|
+
radius=radius,
|
288
|
+
return_distance=False,
|
289
|
+
)
|
290
|
+
)
|
284
291
|
for poi in _pois:
|
285
292
|
catg = poi["category"]
|
286
293
|
categories.append(catg.split("|")[-1])
|
@@ -304,11 +311,7 @@ class Simulator:
|
|
304
311
|
- `Union[int, str]`: The current simulation time either as an integer representing seconds since midnight or as a formatted string.
|
305
312
|
"""
|
306
313
|
start_time = time.time()
|
307
|
-
log = {
|
308
|
-
"req": "get_time",
|
309
|
-
"start_time": start_time,
|
310
|
-
"consumption": 0
|
311
|
-
}
|
314
|
+
log = {"req": "get_time", "start_time": start_time, "consumption": 0}
|
312
315
|
now = await self._client.clock_service.Now({})
|
313
316
|
now = cast(dict[str, int], now)
|
314
317
|
self.time = now["t"]
|
@@ -332,11 +335,7 @@ class Simulator:
|
|
332
335
|
This method sends a request to the simulator's pause service to pause the simulation.
|
333
336
|
"""
|
334
337
|
start_time = time.time()
|
335
|
-
log = {
|
336
|
-
"req": "pause",
|
337
|
-
"start_time": start_time,
|
338
|
-
"consumption": 0
|
339
|
-
}
|
338
|
+
log = {"req": "pause", "start_time": start_time, "consumption": 0}
|
340
339
|
await self._client.pause_service.pause()
|
341
340
|
log["consumption"] = time.time() - start_time
|
342
341
|
self._log_list.append(log)
|
@@ -348,11 +347,7 @@ class Simulator:
|
|
348
347
|
This method sends a request to the simulator's pause service to resume the simulation.
|
349
348
|
"""
|
350
349
|
start_time = time.time()
|
351
|
-
log = {
|
352
|
-
"req": "resume",
|
353
|
-
"start_time": start_time,
|
354
|
-
"consumption": 0
|
355
|
-
}
|
350
|
+
log = {"req": "resume", "start_time": start_time, "consumption": 0}
|
356
351
|
await self._client.pause_service.resume()
|
357
352
|
log["consumption"] = time.time() - start_time
|
358
353
|
self._log_list.append(log)
|
@@ -365,11 +360,7 @@ class Simulator:
|
|
365
360
|
- `int`: The day number since the start of the simulation.
|
366
361
|
"""
|
367
362
|
start_time = time.time()
|
368
|
-
log = {
|
369
|
-
"req": "get_simulator_day",
|
370
|
-
"start_time": start_time,
|
371
|
-
"consumption": 0
|
372
|
-
}
|
363
|
+
log = {"req": "get_simulator_day", "start_time": start_time, "consumption": 0}
|
373
364
|
now = await self._client.clock_service.Now({})
|
374
365
|
now = cast(dict[str, int], now)
|
375
366
|
day = now["day"]
|
@@ -388,7 +379,7 @@ class Simulator:
|
|
388
379
|
log = {
|
389
380
|
"req": "get_simulator_second_from_start_of_day",
|
390
381
|
"start_time": start_time,
|
391
|
-
"consumption": 0
|
382
|
+
"consumption": 0,
|
392
383
|
}
|
393
384
|
now = await self._client.clock_service.Now({})
|
394
385
|
now = cast(dict[str, int], now)
|
@@ -407,12 +398,8 @@ class Simulator:
|
|
407
398
|
- `Dict`: Information about the specified person.
|
408
399
|
"""
|
409
400
|
start_time = time.time()
|
410
|
-
log = {
|
411
|
-
|
412
|
-
"start_time": start_time,
|
413
|
-
"consumption": 0
|
414
|
-
}
|
415
|
-
person = await self._client.person_service.GetPerson(
|
401
|
+
log = {"req": "get_person", "start_time": start_time, "consumption": 0}
|
402
|
+
person: dict = await self._client.person_service.GetPerson(
|
416
403
|
req={"person_id": person_id}
|
417
404
|
) # type:ignore
|
418
405
|
log["consumption"] = time.time() - start_time
|
@@ -430,20 +417,16 @@ class Simulator:
|
|
430
417
|
- `Dict`: Response from adding the person.
|
431
418
|
"""
|
432
419
|
start_time = time.time()
|
433
|
-
log = {
|
434
|
-
"req": "add_person",
|
435
|
-
"start_time": start_time,
|
436
|
-
"consumption": 0
|
437
|
-
}
|
420
|
+
log = {"req": "add_person", "start_time": start_time, "consumption": 0}
|
438
421
|
person = dict2pb(dict_person, person_pb2.Person())
|
439
422
|
if isinstance(person, person_pb2.Person):
|
440
423
|
req = person_service.AddPersonRequest(person=person)
|
441
424
|
else:
|
442
425
|
req = person
|
443
|
-
|
426
|
+
resp: dict = await self._client.person_service.AddPerson(req) # type:ignore
|
444
427
|
log["consumption"] = time.time() - start_time
|
445
428
|
self._log_list.append(log)
|
446
|
-
return
|
429
|
+
return resp
|
447
430
|
|
448
431
|
async def set_aoi_schedules(
|
449
432
|
self,
|
@@ -467,11 +450,7 @@ class Simulator:
|
|
467
450
|
Defaults to `TRIP_MODE_DRIVE_ONLY` if not specified.
|
468
451
|
"""
|
469
452
|
start_time = time.time()
|
470
|
-
log = {
|
471
|
-
"req": "set_aoi_schedules",
|
472
|
-
"start_time": start_time,
|
473
|
-
"consumption": 0
|
474
|
-
}
|
453
|
+
log = {"req": "set_aoi_schedules", "start_time": start_time, "consumption": 0}
|
475
454
|
cur_time = float(await self.get_time())
|
476
455
|
if not isinstance(target_positions, list):
|
477
456
|
target_positions = [target_positions]
|
@@ -546,7 +525,7 @@ class Simulator:
|
|
546
525
|
log = {
|
547
526
|
"req": "reset_person_position",
|
548
527
|
"start_time": start_time,
|
549
|
-
"consumption": 0
|
528
|
+
"consumption": 0,
|
550
529
|
}
|
551
530
|
reset_position = {}
|
552
531
|
if aoi_id is not None:
|
@@ -597,11 +576,7 @@ class Simulator:
|
|
597
576
|
- `List[Dict]`: A list of dictionaries containing information about the POIs found.
|
598
577
|
"""
|
599
578
|
start_time = time.time()
|
600
|
-
log = {
|
601
|
-
"req": "get_around_poi",
|
602
|
-
"start_time": start_time,
|
603
|
-
"consumption": 0
|
604
|
-
}
|
579
|
+
log = {"req": "get_around_poi", "start_time": start_time, "consumption": 0}
|
605
580
|
if isinstance(poi_type, str):
|
606
581
|
poi_type = [poi_type]
|
607
582
|
transformed_poi_type: list[str] = []
|
@@ -612,11 +587,13 @@ class Simulator:
|
|
612
587
|
transformed_poi_type += self.poi_cate[t]
|
613
588
|
poi_type_set = set(transformed_poi_type)
|
614
589
|
# 获取半径内的poi
|
615
|
-
_pois: list[dict] = ray.get(
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
590
|
+
_pois: list[dict] = ray.get(
|
591
|
+
self.map.query_pois.remote( # type:ignore
|
592
|
+
center=center,
|
593
|
+
radius=radius,
|
594
|
+
return_distance=False,
|
595
|
+
)
|
596
|
+
)
|
620
597
|
# 过滤掉不满足类别前缀的poi
|
621
598
|
pois = []
|
622
599
|
for poi in _pois:
|
@@ -626,4 +603,4 @@ class Simulator:
|
|
626
603
|
pois.append(poi)
|
627
604
|
log["consumption"] = time.time() - start_time
|
628
605
|
self._log_list.append(log)
|
629
|
-
return pois
|
606
|
+
return pois
|
pycityagent/pycityagent-sim
CHANGED
Binary file
|
@@ -22,12 +22,18 @@ from ..llm.llmconfig import LLMConfig
|
|
22
22
|
from ..memory import FaissQuery, Memory
|
23
23
|
from ..message import Messager
|
24
24
|
from ..metrics import MlflowClient
|
25
|
-
from ..utils import (
|
26
|
-
|
25
|
+
from ..utils import (
|
26
|
+
DIALOG_SCHEMA,
|
27
|
+
INSTITUTION_STATUS_SCHEMA,
|
28
|
+
PROFILE_SCHEMA,
|
29
|
+
STATUS_SCHEMA,
|
30
|
+
SURVEY_SCHEMA,
|
31
|
+
)
|
27
32
|
|
28
33
|
logger = logging.getLogger("pycityagent")
|
29
34
|
__all__ = ["AgentGroup"]
|
30
35
|
|
36
|
+
|
31
37
|
@ray.remote
|
32
38
|
class AgentGroup:
|
33
39
|
def __init__(
|
@@ -148,7 +154,9 @@ class AgentGroup:
|
|
148
154
|
logger.info(f"-----Initializing Simulator in AgentGroup {self._uuid} ...")
|
149
155
|
self.simulator = Simulator(config["simulator_request"])
|
150
156
|
self.simulator.set_map(map_ref)
|
151
|
-
self.projector = pyproj.Proj(
|
157
|
+
self.projector = pyproj.Proj(
|
158
|
+
ray.get(self.simulator.map.get_projector.remote()) # type:ignore
|
159
|
+
)
|
152
160
|
# prepare Economy client
|
153
161
|
logger.info(f"-----Creating Economy client in AgentGroup {self._uuid} ...")
|
154
162
|
self.economy_client = EconomyClient(
|
@@ -208,7 +216,7 @@ class AgentGroup:
|
|
208
216
|
@property
|
209
217
|
def agent_type(self):
|
210
218
|
return self.agent_class
|
211
|
-
|
219
|
+
|
212
220
|
async def get_economy_ids(self):
|
213
221
|
return await self.economy_client.get_ids()
|
214
222
|
|
@@ -780,16 +788,18 @@ class AgentGroup:
|
|
780
788
|
"""
|
781
789
|
try:
|
782
790
|
tasks = [agent.run() for agent in self.agents]
|
783
|
-
agent_time_log =await asyncio.gather(*tasks)
|
784
|
-
simulator_log =
|
791
|
+
agent_time_log = await asyncio.gather(*tasks)
|
792
|
+
simulator_log = (
|
793
|
+
self.simulator.get_log_list() + self.economy_client.get_log_list()
|
794
|
+
)
|
785
795
|
group_logs = {
|
786
796
|
"llm_log": self.llm.get_log_list(),
|
787
|
-
"mqtt_log": ray.get(self.messager.get_log_list.remote()),
|
797
|
+
"mqtt_log": ray.get(self.messager.get_log_list.remote()), # type:ignore
|
788
798
|
"simulator_log": simulator_log,
|
789
|
-
"agent_time_log": agent_time_log
|
799
|
+
"agent_time_log": agent_time_log,
|
790
800
|
}
|
791
801
|
self.llm.clear_log_list()
|
792
|
-
self.messager.clear_log_list.remote()
|
802
|
+
self.messager.clear_log_list.remote() # type:ignore
|
793
803
|
self.simulator.clear_log_list()
|
794
804
|
self.economy_client.clear_log_list()
|
795
805
|
return group_logs
|
@@ -13,30 +13,21 @@ import yaml
|
|
13
13
|
from langchain_core.embeddings import Embeddings
|
14
14
|
|
15
15
|
from ..agent import Agent, InstitutionAgent
|
16
|
-
from ..cityagent import BankAgent, FirmAgent, GovernmentAgent, NBSAgent,
|
17
|
-
|
18
|
-
memory_config_bank,
|
19
|
-
memory_config_firm,
|
20
|
-
memory_config_government,
|
21
|
-
memory_config_nbs,
|
22
|
-
memory_config_societyagent,
|
23
|
-
memory_config_init,
|
24
|
-
)
|
16
|
+
from ..cityagent import (BankAgent, FirmAgent, GovernmentAgent, NBSAgent,
|
17
|
+
SocietyAgent)
|
25
18
|
from ..cityagent.initial import bind_agent_info, initialize_social_network
|
26
|
-
from ..cityagent.
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
19
|
+
from ..cityagent.memory_config import (memory_config_bank, memory_config_firm,
|
20
|
+
memory_config_government,
|
21
|
+
memory_config_init, memory_config_nbs,
|
22
|
+
memory_config_societyagent)
|
23
|
+
from ..cityagent.message_intercept import (EdgeMessageBlock,
|
24
|
+
MessageBlockListener,
|
25
|
+
PointMessageBlock)
|
31
26
|
from ..economy.econ_client import EconomyClient
|
32
27
|
from ..environment import Simulator
|
33
28
|
from ..llm import SimpleEmbedding
|
34
|
-
from ..message import (
|
35
|
-
|
36
|
-
MessageBlockListenerBase,
|
37
|
-
MessageInterceptor,
|
38
|
-
Messager,
|
39
|
-
)
|
29
|
+
from ..message import (MessageBlockBase, MessageBlockListenerBase,
|
30
|
+
MessageInterceptor, Messager)
|
40
31
|
from ..metrics import init_mlflow_connection
|
41
32
|
from ..metrics.mlflow_client import MlflowClient
|
42
33
|
from ..survey import Survey
|
@@ -49,6 +40,7 @@ logger = logging.getLogger("pycityagent")
|
|
49
40
|
|
50
41
|
__all__ = ["AgentSimulation"]
|
51
42
|
|
43
|
+
|
52
44
|
class AgentSimulation:
|
53
45
|
"""
|
54
46
|
A class to simulate a multi-agent system.
|
@@ -316,7 +308,7 @@ class AgentSimulation:
|
|
316
308
|
"crime": "The crime rate is low",
|
317
309
|
"pollution": "The pollution level is low",
|
318
310
|
"temperature": "The temperature is normal",
|
319
|
-
"day": "Workday"
|
311
|
+
"day": "Workday",
|
320
312
|
},
|
321
313
|
)
|
322
314
|
simulation._simulator.set_environment(environment)
|
@@ -391,10 +383,21 @@ class AgentSimulation:
|
|
391
383
|
logger.info(
|
392
384
|
f"Running step: type: {step['type']} - description: {step.get('description', 'no description')}"
|
393
385
|
)
|
394
|
-
if step["type"] not in [
|
386
|
+
if step["type"] not in [
|
387
|
+
"run",
|
388
|
+
"step",
|
389
|
+
"interview",
|
390
|
+
"survey",
|
391
|
+
"intervene",
|
392
|
+
"pause",
|
393
|
+
"resume",
|
394
|
+
"function",
|
395
|
+
]:
|
395
396
|
raise ValueError(f"Invalid step type: {step['type']}")
|
396
397
|
if step["type"] == "run":
|
397
|
-
llm_log_list, mqtt_log_list, simulator_log_list, agent_time_log_list =
|
398
|
+
llm_log_list, mqtt_log_list, simulator_log_list, agent_time_log_list = (
|
399
|
+
await simulation.run(step.get("days", 1))
|
400
|
+
)
|
398
401
|
llm_log_lists.extend(llm_log_list)
|
399
402
|
mqtt_log_lists.extend(mqtt_log_list)
|
400
403
|
simulator_log_lists.extend(simulator_log_list)
|
@@ -402,7 +405,12 @@ class AgentSimulation:
|
|
402
405
|
elif step["type"] == "step":
|
403
406
|
times = step.get("times", 1)
|
404
407
|
for _ in range(times):
|
405
|
-
|
408
|
+
(
|
409
|
+
llm_log_list,
|
410
|
+
mqtt_log_list,
|
411
|
+
simulator_log_list,
|
412
|
+
agent_time_log_list,
|
413
|
+
) = await simulation.step()
|
406
414
|
llm_log_lists.extend(llm_log_list)
|
407
415
|
mqtt_log_lists.extend(mqtt_log_list)
|
408
416
|
simulator_log_lists.extend(simulator_log_list)
|
@@ -415,7 +423,7 @@ class AgentSimulation:
|
|
415
423
|
await step["func"](simulation)
|
416
424
|
logger.info("Simulation finished")
|
417
425
|
return llm_log_lists, mqtt_log_lists, simulator_log_lists, agent_time_log_lists
|
418
|
-
|
426
|
+
|
419
427
|
@property
|
420
428
|
def enable_avro(
|
421
429
|
self,
|
@@ -1026,7 +1034,9 @@ class AgentSimulation:
|
|
1026
1034
|
|
1027
1035
|
# step
|
1028
1036
|
simulator_day = await self._simulator.get_simulator_day()
|
1029
|
-
simulator_time = int(
|
1037
|
+
simulator_time = int(
|
1038
|
+
await self._simulator.get_simulator_second_from_start_of_day()
|
1039
|
+
)
|
1030
1040
|
logger.info(
|
1031
1041
|
f"Start simulation day {simulator_day} at {simulator_time}, step {self._total_steps}"
|
1032
1042
|
)
|
@@ -1039,13 +1049,15 @@ class AgentSimulation:
|
|
1039
1049
|
simulator_log_list = []
|
1040
1050
|
agent_time_log_list = []
|
1041
1051
|
for log_messages_group in log_messages_groups:
|
1042
|
-
llm_log_list.extend(log_messages_group[
|
1043
|
-
mqtt_log_list.extend(log_messages_group[
|
1044
|
-
simulator_log_list.extend(log_messages_group[
|
1045
|
-
agent_time_log_list.extend(log_messages_group[
|
1052
|
+
llm_log_list.extend(log_messages_group["llm_log"])
|
1053
|
+
mqtt_log_list.extend(log_messages_group["mqtt_log"])
|
1054
|
+
simulator_log_list.extend(log_messages_group["simulator_log"])
|
1055
|
+
agent_time_log_list.extend(log_messages_group["agent_time_log"])
|
1046
1056
|
# save
|
1047
1057
|
simulator_day = await self._simulator.get_simulator_day()
|
1048
|
-
simulator_time = int(
|
1058
|
+
simulator_time = int(
|
1059
|
+
await self._simulator.get_simulator_second_from_start_of_day()
|
1060
|
+
)
|
1049
1061
|
save_tasks = []
|
1050
1062
|
for group in self._groups.values():
|
1051
1063
|
save_tasks.append(group.save.remote(simulator_day, simulator_time))
|
@@ -1108,7 +1120,12 @@ class AgentSimulation:
|
|
1108
1120
|
current_time = await self._simulator.get_time()
|
1109
1121
|
if current_time >= end_time: # type:ignore
|
1110
1122
|
break
|
1111
|
-
|
1123
|
+
(
|
1124
|
+
llm_log_list,
|
1125
|
+
mqtt_log_list,
|
1126
|
+
simulator_log_list,
|
1127
|
+
agent_time_log_list,
|
1128
|
+
) = await self.step()
|
1112
1129
|
llm_log_lists.extend(llm_log_list)
|
1113
1130
|
mqtt_log_lists.extend(mqtt_log_list)
|
1114
1131
|
simulator_log_lists.extend(simulator_log_list)
|
@@ -1121,7 +1138,12 @@ class AgentSimulation:
|
|
1121
1138
|
|
1122
1139
|
# 运行成功后更新状态
|
1123
1140
|
await self._update_exp_status(2)
|
1124
|
-
return
|
1141
|
+
return (
|
1142
|
+
llm_log_lists,
|
1143
|
+
mqtt_log_lists,
|
1144
|
+
simulator_log_lists,
|
1145
|
+
agent_time_log_lists,
|
1146
|
+
)
|
1125
1147
|
except Exception as e:
|
1126
1148
|
error_msg = f"模拟器运行错误: {str(e)}"
|
1127
1149
|
logger.error(error_msg)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.2
|
2
2
|
Name: pycityagent
|
3
|
-
Version: 2.0.
|
3
|
+
Version: 2.0.0a76
|
4
4
|
Summary: LLM-based city environment agent building library
|
5
5
|
Author-email: Yuwei Yan <pinkgranite86@gmail.com>, Junbo Yan <yanjb20thu@gmali.com>, Jun Zhang <zhangjun990222@gmali.com>
|
6
6
|
License: MIT License
|
@@ -1,10 +1,4 @@
|
|
1
|
-
pycityagent-
|
2
|
-
pycityagent-2.0.0a74.dist-info/LICENSE,sha256=n2HPXiupinpyHMnIkbCf3OTYd3KMqbmldu1e7av0CAU,1084
|
3
|
-
pycityagent-2.0.0a74.dist-info/WHEEL,sha256=VujM3ypTCyUW6hcTDdK2ej0ARVMxlU1Djlh_zWnDgqk,109
|
4
|
-
pycityagent-2.0.0a74.dist-info/entry_points.txt,sha256=BZcne49AAIFv-hawxGnPbblea7X3MtAtoPyDX8L4OC4,132
|
5
|
-
pycityagent-2.0.0a74.dist-info/top_level.txt,sha256=yOmeu6cSXmiUtScu53a3s0p7BGtLMaV0aff83EHCTic,43
|
6
|
-
pycityagent-2.0.0a74.dist-info/METADATA,sha256=q-uOMuI2GY8bvyqqMpXk4W9ItaKMUxP9HrnaOc8RVtQ,9110
|
7
|
-
pycityagent/pycityagent-sim,sha256=MYlRyvlpybVbiqKehzfV3GUbhatuQHNrxNWRBOs3nsU,35884466
|
1
|
+
pycityagent/pycityagent-sim,sha256=27tTBz9KKr9fkggzX3EmzvmHwj1l4Xw1ofUhkbSioh8,35884466
|
8
2
|
pycityagent/__init__.py,sha256=PUKWTXc-xdMG7px8oTNclodsILUgypANj2Z647sY63k,808
|
9
3
|
pycityagent/pycityagent-ui,sha256=Ur95yZygIaZ5l_CDqP9394M5GQ66iV5PkcNPYFWqzvk,41225346
|
10
4
|
pycityagent/metrics/mlflow_client.py,sha256=-iyh4BPVnBkluhmfucUzibCUnBX2iftkz4tVJJVxwHw,6958
|
@@ -27,9 +21,9 @@ pycityagent/memory/utils.py,sha256=oJWLdPeJy_jcdKcDTo9JAH9kDZhqjoQhhv_zT9qWC0w,8
|
|
27
21
|
pycityagent/memory/const.py,sha256=nFmjvt-8FEB0hc0glOH3lliqJhkhf3D_NKxWI0pf6TY,936
|
28
22
|
pycityagent/memory/faiss_query.py,sha256=KPeyzIjD0dzkxr-TlOeCiIlkdh1WAyyipCAXUEt97Lk,17350
|
29
23
|
pycityagent/memory/state.py,sha256=JFCBuK1AS-HqscvdGS9ATF9AUU8t29_2leDY_6iO2_4,5158
|
30
|
-
pycityagent/simulation/simulation.py,sha256=
|
24
|
+
pycityagent/simulation/simulation.py,sha256=b4sFPVAMdCi1aiG6GX2cSE3vYa2Q14XfyRkxHp1GRCc,49526
|
31
25
|
pycityagent/simulation/__init__.py,sha256=u1WpgwVxPboXWMxrUQKMXJNmTKQYAeCaqZv9HmSxESY,118
|
32
|
-
pycityagent/simulation/agentgroup.py,sha256=
|
26
|
+
pycityagent/simulation/agentgroup.py,sha256=oXo2iRUThh_96JhXHMufT8_BPx0PrlwqbMpiVqK_viA,36957
|
33
27
|
pycityagent/simulation/storage/pg.py,sha256=xRshSOGttW-p0re0fNBOjOpb-nQ5msIE2LsdT79_E_Y,8425
|
34
28
|
pycityagent/message/message_interceptor.py,sha256=QWuTUqi1Cu214fhFs0f78tD2zflMnb6zEAGB4RutXxs,17736
|
35
29
|
pycityagent/message/__init__.py,sha256=f5QH7DKPqEAMyfSlBMnl3uouOKlsoel909STlIe7nUk,276
|
@@ -52,7 +46,7 @@ pycityagent/workflow/prompt.py,sha256=rzenP4EFGxbWE1aq-x2036b6umKvi5cQx2xtWULwgI
|
|
52
46
|
pycityagent/workflow/block.py,sha256=WJfCeL8e117GzkVPJCRNsQZZinccMnVyEubkwrf-17U,12295
|
53
47
|
pycityagent/workflow/trigger.py,sha256=4nzAwywGQsFabgo6gzp-vD2EV4wII7Z0LHGEAsflSEY,7608
|
54
48
|
pycityagent/environment/__init__.py,sha256=fFIth2jxxgZ92cXm-aoM2igHgaSqsYGwtBhyb7opjzk,166
|
55
|
-
pycityagent/environment/simulator.py,sha256=
|
49
|
+
pycityagent/environment/simulator.py,sha256=PpO4XyIbn5fSqycBlRYdGWuRumDzeXXM8ZQr8U5Mgcs,22608
|
56
50
|
pycityagent/environment/utils/port.py,sha256=3OM6kSUt3PxvDUOlgyiendBtETaWU8Mzk_8H0TzTmYg,295
|
57
51
|
pycityagent/environment/utils/grpc.py,sha256=_lB4-k4dTKuNvApaDiYgFxiLTPtYG42DVQtG9yOj9pQ,2022
|
58
52
|
pycityagent/environment/utils/base64.py,sha256=hoREzQo3FXMN79pqQLO2jgsDEvudciomyKii7MWljAM,374
|
@@ -95,3 +89,9 @@ pycityagent/cityagent/blocks/mobility_block.py,sha256=qkRiV0nkGOUUoo9lGIjAFE_Hl0
|
|
95
89
|
pycityagent/survey/models.py,sha256=g3xni4GcA1Py3vlGt6z4ltutjgQ4G0uINYAM8vKRJAw,5225
|
96
90
|
pycityagent/survey/__init__.py,sha256=rxwou8U9KeFSP7rMzXtmtp2fVFZxK4Trzi-psx9LPIs,153
|
97
91
|
pycityagent/survey/manager.py,sha256=tHkdeq4lTfAHwvgf4-udsXri0z2l6E00rEbvwl7SqRs,3439
|
92
|
+
pycityagent-2.0.0a76.dist-info/RECORD,,
|
93
|
+
pycityagent-2.0.0a76.dist-info/LICENSE,sha256=n2HPXiupinpyHMnIkbCf3OTYd3KMqbmldu1e7av0CAU,1084
|
94
|
+
pycityagent-2.0.0a76.dist-info/WHEEL,sha256=VujM3ypTCyUW6hcTDdK2ej0ARVMxlU1Djlh_zWnDgqk,109
|
95
|
+
pycityagent-2.0.0a76.dist-info/entry_points.txt,sha256=BZcne49AAIFv-hawxGnPbblea7X3MtAtoPyDX8L4OC4,132
|
96
|
+
pycityagent-2.0.0a76.dist-info/top_level.txt,sha256=yOmeu6cSXmiUtScu53a3s0p7BGtLMaV0aff83EHCTic,43
|
97
|
+
pycityagent-2.0.0a76.dist-info/METADATA,sha256=GzZHP_O0fhXXBDRQiQluHGmVNilpnUNdabA9nxRa0r4,9110
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|