pycityagent 2.0.0a80__cp311-cp311-macosx_11_0_arm64.whl → 2.0.0a81__cp311-cp311-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.
@@ -2,6 +2,7 @@ import asyncio
2
2
  import logging
3
3
  import re
4
4
  import time
5
+ from collections.abc import Sequence
5
6
  from typing import Any, Literal, Union
6
7
 
7
8
  import grpc
@@ -27,11 +28,17 @@ def _snake_to_pascal(snake_str):
27
28
  _res = _res.replace(_word, _word.upper())
28
29
  return _res
29
30
 
31
+
30
32
  def camel_to_snake(d):
31
33
  if not isinstance(d, dict):
32
34
  return d
33
- return {re.sub('([a-z0-9])([A-Z])', r'\1_\2', k).lower(): camel_to_snake(v) if isinstance(v, dict) else v
34
- for k, v in d.items()}
35
+ return {
36
+ re.sub("([a-z0-9])([A-Z])", r"\1_\2", k).lower(): (
37
+ camel_to_snake(v) if isinstance(v, dict) else v
38
+ )
39
+ for k, v in d.items()
40
+ }
41
+
35
42
 
36
43
  def _create_aio_channel(server_address: str, secure: bool = False) -> grpc.aio.Channel:
37
44
  """
@@ -104,7 +111,7 @@ class EconomyClient:
104
111
 
105
112
  def get_log_list(self):
106
113
  return self._log_list
107
-
114
+
108
115
  def clear_log_list(self):
109
116
  self._log_list = []
110
117
 
@@ -120,7 +127,7 @@ class EconomyClient:
120
127
  return state
121
128
 
122
129
  def __setstate__(self, state):
123
- """
130
+ """
124
131
  Restore instance attributes (i.e., filename and mode) from the
125
132
  unpickled state dictionary.
126
133
  """
@@ -134,7 +141,7 @@ class EconomyClient:
134
141
  Get the ids of agents and orgs
135
142
  """
136
143
  return self._agent_ids, self._org_ids
137
-
144
+
138
145
  async def set_ids(self, agent_ids: set[int], org_ids: set[int]):
139
146
  """
140
147
  Set the ids of agents and orgs
@@ -142,7 +149,7 @@ class EconomyClient:
142
149
  self._agent_ids = agent_ids
143
150
  self._org_ids = org_ids
144
151
 
145
- async def get_agent(self, id: int) -> economyv2.Agent:
152
+ async def get_agent(self, id: int) -> dict[str, Any]:
146
153
  """
147
154
  Get agent by id
148
155
 
@@ -153,22 +160,14 @@ class EconomyClient:
153
160
  - `economyv2.Agent`: The agent object.
154
161
  """
155
162
  start_time = time.time()
156
- log = {
157
- "req": "get_agent",
158
- "start_time": start_time,
159
- "consumption": 0
160
- }
161
- agent = await self._aio_stub.GetAgent(
162
- org_service.GetAgentRequest(
163
- agent_id=id
164
- )
165
- )
163
+ log = {"req": "get_agent", "start_time": start_time, "consumption": 0}
164
+ agent = await self._aio_stub.GetAgent(org_service.GetAgentRequest(agent_id=id))
166
165
  agent_dict = MessageToDict(agent)["agent"]
167
166
  log["consumption"] = time.time() - start_time
168
167
  self._log_list.append(log)
169
168
  return camel_to_snake(agent_dict)
170
169
 
171
- async def get_org(self, id: int) -> economyv2.Org:
170
+ async def get_org(self, id: int) -> dict[str, Any]:
172
171
  """
173
172
  Get org by id
174
173
 
@@ -179,16 +178,8 @@ class EconomyClient:
179
178
  - `economyv2.Org`: The org object.
180
179
  """
181
180
  start_time = time.time()
182
- log = {
183
- "req": "get_org",
184
- "start_time": start_time,
185
- "consumption": 0
186
- }
187
- org = await self._aio_stub.GetOrg(
188
- org_service.GetOrgRequest(
189
- org_id=id
190
- )
191
- )
181
+ log = {"req": "get_org", "start_time": start_time, "consumption": 0}
182
+ org = await self._aio_stub.GetOrg(org_service.GetOrgRequest(org_id=id))
192
183
  org_dict = MessageToDict(org)["org"]
193
184
  log["consumption"] = time.time() - start_time
194
185
  self._log_list.append(log)
@@ -210,11 +201,7 @@ class EconomyClient:
210
201
  - Any
211
202
  """
212
203
  start_time = time.time()
213
- log = {
214
- "req": "get",
215
- "start_time": start_time,
216
- "consumption": 0
217
- }
204
+ log = {"req": "get", "start_time": start_time, "consumption": 0}
218
205
  if id not in self._agent_ids and id not in self._org_ids:
219
206
  raise ValueError(f"Invalid id {id}, this id does not exist!")
220
207
  request_type = "Org" if id in self._org_ids else "Agent"
@@ -245,11 +232,7 @@ class EconomyClient:
245
232
  - Any
246
233
  """
247
234
  start_time = time.time()
248
- log = {
249
- "req": "update",
250
- "start_time": start_time,
251
- "consumption": 0
252
- }
235
+ log = {"req": "update", "start_time": start_time, "consumption": 0}
253
236
  if id not in self._agent_ids and id not in self._org_ids:
254
237
  raise ValueError(f"Invalid id {id}, this id does not exist!")
255
238
  request_type = "Org" if id in self._org_ids else "Agent"
@@ -283,17 +266,13 @@ class EconomyClient:
283
266
  original_value[key] = value
284
267
  if request_type == "Org":
285
268
  await self._aio_stub.UpdateOrg(
286
- org_service.UpdateOrgRequest(
287
- org=original_value
288
- )
269
+ org_service.UpdateOrgRequest(org=original_value)
289
270
  )
290
271
  log["consumption"] = time.time() - start_time
291
272
  self._log_list.append(log)
292
273
  else:
293
274
  await self._aio_stub.UpdateAgent(
294
- org_service.UpdateAgentRequest(
295
- agent=original_value
296
- )
275
+ org_service.UpdateAgentRequest(agent=original_value)
297
276
  )
298
277
  log["consumption"] = time.time() - start_time
299
278
  self._log_list.append(log)
@@ -315,11 +294,7 @@ class EconomyClient:
315
294
  - All tasks are executed concurrently, and their results are gathered and returned.
316
295
  """
317
296
  start_time = time.time()
318
- log = {
319
- "req": "add_agents",
320
- "start_time": start_time,
321
- "consumption": 0
322
- }
297
+ log = {"req": "add_agents", "start_time": start_time, "consumption": 0}
323
298
  if isinstance(configs, dict):
324
299
  configs = [configs]
325
300
  for config in configs:
@@ -362,11 +337,7 @@ class EconomyClient:
362
337
  - Executes all tasks concurrently and gathers their results.
363
338
  """
364
339
  start_time = time.time()
365
- log = {
366
- "req": "add_orgs",
367
- "start_time": start_time,
368
- "consumption": 0
369
- }
340
+ log = {"req": "add_orgs", "start_time": start_time, "consumption": 0}
370
341
  if isinstance(configs, dict):
371
342
  configs = [configs]
372
343
  for config in configs:
@@ -425,11 +396,8 @@ class EconomyClient:
425
396
  - `Tuple[float, List[float]]`: A tuple containing the total taxes due and updated incomes after tax calculation.
426
397
  """
427
398
  start_time = time.time()
428
- log = {
429
- "req": "calculate_taxes_due",
430
- "start_time": start_time,
431
- "consumption": 0
432
- }
399
+ log = {"req": "calculate_taxes_due", "start_time": start_time, "consumption": 0}
400
+ # TODO: support multiple org
433
401
  request = org_service.CalculateTaxesDueRequest(
434
402
  government_id=org_id,
435
403
  agent_ids=agent_ids,
@@ -461,8 +429,10 @@ class EconomyClient:
461
429
  log = {
462
430
  "req": "calculate_consumption",
463
431
  "start_time": start_time,
464
- "consumption": 0
432
+ "consumption": 0,
465
433
  }
434
+ if not isinstance(org_ids, Sequence):
435
+ org_ids = [org_ids]
466
436
  request = org_service.CalculateConsumptionRequest(
467
437
  firm_ids=org_ids,
468
438
  agent_id=agent_id,
@@ -487,11 +457,7 @@ class EconomyClient:
487
457
  - `Tuple[float, List[float]]`: A tuple containing the total interest and updated currencies for each agent.
488
458
  """
489
459
  start_time = time.time()
490
- log = {
491
- "req": "calculate_interest",
492
- "start_time": start_time,
493
- "consumption": 0
494
- }
460
+ log = {"req": "calculate_interest", "start_time": start_time, "consumption": 0}
495
461
  request = org_service.CalculateInterestRequest(
496
462
  bank_id=org_id,
497
463
  agent_ids=agent_ids,
@@ -511,11 +477,7 @@ class EconomyClient:
511
477
  - `org_ids` (`Union[int, List[int]]`): A single ID or a list of IDs for the agents to be removed.
512
478
  """
513
479
  start_time = time.time()
514
- log = {
515
- "req": "remove_agents",
516
- "start_time": start_time,
517
- "consumption": 0
518
- }
480
+ log = {"req": "remove_agents", "start_time": start_time, "consumption": 0}
519
481
  if isinstance(agent_ids, int):
520
482
  agent_ids = [agent_ids]
521
483
  tasks = [
@@ -536,11 +498,7 @@ class EconomyClient:
536
498
  - `org_ids` (`Union[int, List[int]]`): A single ID or a list of IDs for the organizations to be removed.
537
499
  """
538
500
  start_time = time.time()
539
- log = {
540
- "req": "remove_orgs",
541
- "start_time": start_time,
542
- "consumption": 0
543
- }
501
+ log = {"req": "remove_orgs", "start_time": start_time, "consumption": 0}
544
502
  if isinstance(org_ids, int):
545
503
  org_ids = [org_ids]
546
504
  tasks = [
@@ -562,11 +520,7 @@ class EconomyClient:
562
520
  - `Tuple[List[int], List[int]]`: A tuple containing lists of agent IDs and organization IDs that were saved.
563
521
  """
564
522
  start_time = time.time()
565
- log = {
566
- "req": "save",
567
- "start_time": start_time,
568
- "consumption": 0
569
- }
523
+ log = {"req": "save", "start_time": start_time, "consumption": 0}
570
524
  request = org_service.SaveEconomyEntitiesRequest(
571
525
  file_path=file_path,
572
526
  )
@@ -589,11 +543,7 @@ class EconomyClient:
589
543
  - `Tuple[List[int], List[int]]`: A tuple containing lists of agent IDs and organization IDs that were loaded.
590
544
  """
591
545
  start_time = time.time()
592
- log = {
593
- "req": "load",
594
- "start_time": start_time,
595
- "consumption": 0
596
- }
546
+ log = {"req": "load", "start_time": start_time, "consumption": 0}
597
547
  request = org_service.LoadEconomyEntitiesRequest(
598
548
  file_path=file_path,
599
549
  )
@@ -616,11 +566,7 @@ class EconomyClient:
616
566
  - `List[int]`: A list of organization IDs matching the specified type.
617
567
  """
618
568
  start_time = time.time()
619
- log = {
620
- "req": "get_org_entity_ids",
621
- "start_time": start_time,
622
- "consumption": 0
623
- }
569
+ log = {"req": "get_org_entity_ids", "start_time": start_time, "consumption": 0}
624
570
  request = org_service.GetOrgEntityIdsRequest(
625
571
  type=org_type,
626
572
  )
@@ -648,22 +594,12 @@ class EconomyClient:
648
594
  - Any
649
595
  """
650
596
  start_time = time.time()
651
- log = {
652
- "req": "add_delta_value",
653
- "start_time": start_time,
654
- "consumption": 0
655
- }
597
+ log = {"req": "add_delta_value", "start_time": start_time, "consumption": 0}
656
598
  pascal_key = _snake_to_pascal(key)
657
599
  _request_type = getattr(org_service, f"Add{pascal_key}Request")
658
600
  _request_func = getattr(self._aio_stub, f"Add{pascal_key}")
659
601
 
660
- _available_keys = {
661
- "inventory",
662
- "price",
663
- "interest_rate",
664
- "currency",
665
- "income"
666
- }
602
+ _available_keys = {"inventory", "price", "interest_rate", "currency", "income"}
667
603
  if key not in _available_keys:
668
604
  raise ValueError(f"Invalid key `{key}`, can only be {_available_keys}!")
669
605
  response = await _request_func(
@@ -676,4 +612,4 @@ class EconomyClient:
676
612
  )
677
613
  log["consumption"] = time.time() - start_time
678
614
  self._log_list.append(log)
679
- return response
615
+ return response
Binary file
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: pycityagent
3
- Version: 2.0.0a80
3
+ Version: 2.0.0a81
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,10 @@
1
- pycityagent/pycityagent-sim,sha256=Bz7hBBEltPOOFAWuRFy7i_O6etwlABDxq0pHberDCU0,35884466
1
+ pycityagent/pycityagent-sim,sha256=SnMFg3S1TaWHPJUqX_vluprsF5dkzJrsc3PdAvimStM,36957042
2
2
  pycityagent/__init__.py,sha256=PUKWTXc-xdMG7px8oTNclodsILUgypANj2Z647sY63k,808
3
3
  pycityagent/pycityagent-ui,sha256=Ur95yZygIaZ5l_CDqP9394M5GQ66iV5PkcNPYFWqzvk,41225346
4
4
  pycityagent/metrics/mlflow_client.py,sha256=-iyh4BPVnBkluhmfucUzibCUnBX2iftkz4tVJJVxwHw,6958
5
5
  pycityagent/metrics/__init__.py,sha256=X08PaBbGVAd7_PRGLREXWxaqm7nS82WBQpD1zvQzcqc,128
6
6
  pycityagent/economy/__init__.py,sha256=aonY4WHnx-6EGJ4WKrx4S-2jAkYNLtqUA04jp6q8B7w,75
7
- pycityagent/economy/econ_client.py,sha256=FUE-7Kxpa3u41eH_4Xye7IYquk1i25Hfv8Smq0nR1-o,24757
7
+ pycityagent/economy/econ_client.py,sha256=sdGTxiIaAxrKXaM3ZyBZxKDVZ1BKx_NOG6PTM4_fOq4,24043
8
8
  pycityagent/tools/__init__.py,sha256=y7sMVMHf0AbivlczM2h-kr7mkgXK-WAx3S9BXLXkWvw,235
9
9
  pycityagent/tools/tool.py,sha256=4ZJSHbNM8dfAVwZEw8T0a2_9OuPsPQpKSVL4WxZVBUc,9022
10
10
  pycityagent/llm/llmconfig.py,sha256=6AqCMV4B_JqBD2mb98bLGzpUdlOCnziQKae-Hhxxp-E,469
@@ -89,9 +89,9 @@ pycityagent/cityagent/blocks/mobility_block.py,sha256=qkRiV0nkGOUUoo9lGIjAFE_Hl0
89
89
  pycityagent/survey/models.py,sha256=g3xni4GcA1Py3vlGt6z4ltutjgQ4G0uINYAM8vKRJAw,5225
90
90
  pycityagent/survey/__init__.py,sha256=rxwou8U9KeFSP7rMzXtmtp2fVFZxK4Trzi-psx9LPIs,153
91
91
  pycityagent/survey/manager.py,sha256=tHkdeq4lTfAHwvgf4-udsXri0z2l6E00rEbvwl7SqRs,3439
92
- pycityagent-2.0.0a80.dist-info/RECORD,,
93
- pycityagent-2.0.0a80.dist-info/LICENSE,sha256=n2HPXiupinpyHMnIkbCf3OTYd3KMqbmldu1e7av0CAU,1084
94
- pycityagent-2.0.0a80.dist-info/WHEEL,sha256=NW1RskY9zow1Y68W-gXg0oZyBRAugI1JHywIzAIai5o,109
95
- pycityagent-2.0.0a80.dist-info/entry_points.txt,sha256=BZcne49AAIFv-hawxGnPbblea7X3MtAtoPyDX8L4OC4,132
96
- pycityagent-2.0.0a80.dist-info/top_level.txt,sha256=yOmeu6cSXmiUtScu53a3s0p7BGtLMaV0aff83EHCTic,43
97
- pycityagent-2.0.0a80.dist-info/METADATA,sha256=IUJKnqJ9ln8u6OypJKDFHt1BiR3ylWZoTVxBz3j3JHE,9110
92
+ pycityagent-2.0.0a81.dist-info/RECORD,,
93
+ pycityagent-2.0.0a81.dist-info/LICENSE,sha256=n2HPXiupinpyHMnIkbCf3OTYd3KMqbmldu1e7av0CAU,1084
94
+ pycityagent-2.0.0a81.dist-info/WHEEL,sha256=NW1RskY9zow1Y68W-gXg0oZyBRAugI1JHywIzAIai5o,109
95
+ pycityagent-2.0.0a81.dist-info/entry_points.txt,sha256=BZcne49AAIFv-hawxGnPbblea7X3MtAtoPyDX8L4OC4,132
96
+ pycityagent-2.0.0a81.dist-info/top_level.txt,sha256=yOmeu6cSXmiUtScu53a3s0p7BGtLMaV0aff83EHCTic,43
97
+ pycityagent-2.0.0a81.dist-info/METADATA,sha256=k3eeBerreeFML0eSXLd87rtFa25if0Sv1D8GhHmywvk,9110