pycityagent 2.0.0a94__cp311-cp311-macosx_11_0_arm64.whl → 2.0.0a95__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.
- pycityagent/agent/agent.py +5 -5
- pycityagent/agent/agent_base.py +1 -2
- pycityagent/cityagent/__init__.py +6 -5
- pycityagent/cityagent/bankagent.py +2 -2
- pycityagent/cityagent/blocks/__init__.py +4 -4
- pycityagent/cityagent/blocks/cognition_block.py +7 -4
- pycityagent/cityagent/blocks/economy_block.py +227 -135
- pycityagent/cityagent/blocks/mobility_block.py +70 -27
- pycityagent/cityagent/blocks/needs_block.py +11 -12
- pycityagent/cityagent/blocks/other_block.py +2 -2
- pycityagent/cityagent/blocks/plan_block.py +22 -24
- pycityagent/cityagent/blocks/social_block.py +15 -17
- pycityagent/cityagent/blocks/utils.py +3 -2
- pycityagent/cityagent/firmagent.py +1 -1
- pycityagent/cityagent/governmentagent.py +1 -1
- pycityagent/cityagent/initial.py +1 -1
- pycityagent/cityagent/memory_config.py +0 -1
- pycityagent/cityagent/message_intercept.py +7 -8
- pycityagent/cityagent/nbsagent.py +1 -1
- pycityagent/cityagent/societyagent.py +1 -2
- pycityagent/configs/__init__.py +18 -0
- pycityagent/configs/exp_config.py +202 -0
- pycityagent/configs/sim_config.py +251 -0
- pycityagent/configs/utils.py +17 -0
- pycityagent/environment/__init__.py +2 -0
- pycityagent/{economy → environment/economy}/econ_client.py +14 -32
- pycityagent/environment/sim/sim_env.py +17 -24
- pycityagent/environment/simulator.py +36 -113
- pycityagent/llm/__init__.py +1 -2
- pycityagent/llm/llm.py +54 -167
- pycityagent/memory/memory.py +13 -12
- pycityagent/message/message_interceptor.py +5 -4
- pycityagent/message/messager.py +3 -5
- pycityagent/metrics/__init__.py +1 -1
- pycityagent/metrics/mlflow_client.py +20 -17
- pycityagent/pycityagent-sim +0 -0
- pycityagent/simulation/agentgroup.py +17 -19
- pycityagent/simulation/simulation.py +157 -210
- pycityagent/survey/manager.py +0 -2
- pycityagent/utils/__init__.py +3 -0
- pycityagent/utils/config_const.py +20 -0
- pycityagent/workflow/__init__.py +1 -2
- pycityagent/workflow/block.py +0 -3
- {pycityagent-2.0.0a94.dist-info → pycityagent-2.0.0a95.dist-info}/METADATA +7 -24
- {pycityagent-2.0.0a94.dist-info → pycityagent-2.0.0a95.dist-info}/RECORD +50 -46
- pycityagent/llm/llmconfig.py +0 -18
- /pycityagent/{economy → environment/economy}/__init__.py +0 -0
- {pycityagent-2.0.0a94.dist-info → pycityagent-2.0.0a95.dist-info}/LICENSE +0 -0
- {pycityagent-2.0.0a94.dist-info → pycityagent-2.0.0a95.dist-info}/WHEEL +0 -0
- {pycityagent-2.0.0a94.dist-info → pycityagent-2.0.0a95.dist-info}/entry_points.txt +0 -0
- {pycityagent-2.0.0a94.dist-info → pycityagent-2.0.0a95.dist-info}/top_level.txt +0 -0
pycityagent/message/messager.py
CHANGED
@@ -7,8 +7,6 @@ from typing import Any, Optional, Union
|
|
7
7
|
import ray
|
8
8
|
from aiomqtt import Client
|
9
9
|
|
10
|
-
from .message_interceptor import MessageInterceptor
|
11
|
-
|
12
10
|
__all__ = [
|
13
11
|
"Messager",
|
14
12
|
]
|
@@ -69,10 +67,10 @@ class Messager:
|
|
69
67
|
- `Union[None, ray.ObjectRef]`: The message interceptor reference.
|
70
68
|
"""
|
71
69
|
return self._message_interceptor
|
72
|
-
|
70
|
+
|
73
71
|
def get_log_list(self):
|
74
72
|
return self._log_list
|
75
|
-
|
73
|
+
|
76
74
|
def clear_log_list(self):
|
77
75
|
self._log_list = []
|
78
76
|
|
@@ -213,7 +211,7 @@ class Messager:
|
|
213
211
|
"from_uuid": from_uuid,
|
214
212
|
"to_uuid": to_uuid,
|
215
213
|
"start_time": start_time,
|
216
|
-
"consumption": 0
|
214
|
+
"consumption": 0,
|
217
215
|
}
|
218
216
|
message = json.dumps(payload, default=str)
|
219
217
|
interceptor = self.message_interceptor
|
pycityagent/metrics/__init__.py
CHANGED
@@ -6,22 +6,21 @@ from collections.abc import Sequence
|
|
6
6
|
from typing import Any, Optional, Union
|
7
7
|
|
8
8
|
import mlflow
|
9
|
-
from mlflow.entities import
|
10
|
-
ExperimentTag, FileInfo, InputTag, LifecycleStage,
|
11
|
-
LiveSpan, Metric, NoOpSpan, Param, Run, RunData,
|
12
|
-
RunInfo, RunInputs, RunStatus, RunTag, SourceType,
|
13
|
-
Span, SpanEvent, SpanStatus, SpanStatusCode,
|
14
|
-
SpanType, Trace, TraceData, TraceInfo, ViewType)
|
9
|
+
from mlflow.entities import Metric, Param, Run, RunTag
|
15
10
|
|
11
|
+
from ..configs import MlflowConfig
|
16
12
|
from ..utils.decorators import lock_decorator
|
17
13
|
|
18
|
-
__all__ = [
|
14
|
+
__all__ = [
|
15
|
+
"init_mlflow_connection",
|
16
|
+
"MlflowClient",
|
17
|
+
]
|
19
18
|
|
20
19
|
logger = logging.getLogger("mlflow")
|
21
20
|
|
22
21
|
|
23
22
|
def init_mlflow_connection(
|
24
|
-
config:
|
23
|
+
config: MlflowConfig,
|
25
24
|
experiment_uuid: str,
|
26
25
|
mlflow_run_name: Optional[str] = None,
|
27
26
|
experiment_name: Optional[str] = None,
|
@@ -32,7 +31,7 @@ def init_mlflow_connection(
|
|
32
31
|
Initialize an MLflow connection with a new or existing experiment and run.
|
33
32
|
|
34
33
|
- **Args**:
|
35
|
-
config (
|
34
|
+
config (MlflowConfig): Configuration containing MLflow credentials and URI.
|
36
35
|
experiment_uuid (str): A unique identifier for the experiment.
|
37
36
|
mlflow_run_name (str, optional): Name of the MLflow run. Defaults to a generated name.
|
38
37
|
experiment_name (str, optional): Name of the experiment. Defaults to a generated name.
|
@@ -42,8 +41,10 @@ def init_mlflow_connection(
|
|
42
41
|
- **Returns**:
|
43
42
|
tuple: A tuple containing the run_id and another tuple with the MLflow URI, client, run object, and run UUID.
|
44
43
|
"""
|
45
|
-
|
46
|
-
|
44
|
+
if config.username is not None:
|
45
|
+
os.environ["MLFLOW_TRACKING_USERNAME"] = config.username
|
46
|
+
if config.password is not None:
|
47
|
+
os.environ["MLFLOW_TRACKING_PASSWORD"] = config.password
|
47
48
|
|
48
49
|
run_uuid = str(uuid.uuid4())
|
49
50
|
# run name
|
@@ -61,7 +62,7 @@ def init_mlflow_connection(
|
|
61
62
|
experiment_tags["mlflow.note.content"] = experiment_description
|
62
63
|
experiment_tags["experiment_id"] = experiment_uuid
|
63
64
|
|
64
|
-
uri = config
|
65
|
+
uri = config.mlflow_uri
|
65
66
|
client = mlflow.MlflowClient(tracking_uri=uri)
|
66
67
|
|
67
68
|
# experiment
|
@@ -89,7 +90,7 @@ class MlflowClient:
|
|
89
90
|
|
90
91
|
def __init__(
|
91
92
|
self,
|
92
|
-
config:
|
93
|
+
config: MlflowConfig,
|
93
94
|
experiment_uuid: str,
|
94
95
|
mlflow_run_name: Optional[str] = None,
|
95
96
|
experiment_name: Optional[str] = None,
|
@@ -101,7 +102,7 @@ class MlflowClient:
|
|
101
102
|
Initialize the MlflowClient.
|
102
103
|
|
103
104
|
- **Args**:
|
104
|
-
config (dict): Configuration
|
105
|
+
config (dict): Configuration containing MLflow credentials and URI.
|
105
106
|
experiment_uuid (str): A unique identifier for the experiment.
|
106
107
|
mlflow_run_name (str, optional): Name of the MLflow run. Defaults to a generated name.
|
107
108
|
experiment_name (str, optional): Name of the experiment. Defaults to a generated name.
|
@@ -124,9 +125,11 @@ class MlflowClient:
|
|
124
125
|
experiment_tags=experiment_tags,
|
125
126
|
)
|
126
127
|
else:
|
127
|
-
self._mlflow_uri = uri = config
|
128
|
-
|
129
|
-
|
128
|
+
self._mlflow_uri = uri = config.mlflow_uri
|
129
|
+
if config.username is not None:
|
130
|
+
os.environ["MLFLOW_TRACKING_USERNAME"] = config.username
|
131
|
+
if config.password is not None:
|
132
|
+
os.environ["MLFLOW_TRACKING_PASSWORD"] = config.password
|
130
133
|
self._client = client = mlflow.MlflowClient(tracking_uri=uri)
|
131
134
|
self._run = client.get_run(run_id=run_id)
|
132
135
|
self._run_id = run_id
|
pycityagent/pycityagent-sim
CHANGED
Binary file
|
@@ -15,10 +15,9 @@ import ray
|
|
15
15
|
from langchain_core.embeddings import Embeddings
|
16
16
|
|
17
17
|
from ..agent import Agent, InstitutionAgent
|
18
|
-
from ..
|
19
|
-
from ..environment import Simulator
|
18
|
+
from ..configs import SimConfig
|
19
|
+
from ..environment import EconomyClient, Simulator
|
20
20
|
from ..llm.llm import LLM
|
21
|
-
from ..llm.llmconfig import LLMConfig
|
22
21
|
from ..memory import FaissQuery, Memory
|
23
22
|
from ..message import Messager
|
24
23
|
from ..metrics import MlflowClient
|
@@ -36,7 +35,7 @@ class AgentGroup:
|
|
36
35
|
agent_class: Union[type[Agent], list[type[Agent]]],
|
37
36
|
number_of_agents: Union[int, list[int]],
|
38
37
|
memory_config_function_group: dict[type[Agent], Callable],
|
39
|
-
config:
|
38
|
+
config: SimConfig,
|
40
39
|
map_ref: ray.ObjectRef,
|
41
40
|
exp_name: str,
|
42
41
|
exp_id: Union[str, UUID],
|
@@ -65,7 +64,7 @@ class AgentGroup:
|
|
65
64
|
- `agent_class` (Union[Type[Agent], List[Type[Agent]]]): A single or list of agent classes to instantiate.
|
66
65
|
- `number_of_agents` (Union[int, List[int]]): Number of instances to create for each agent class.
|
67
66
|
- `memory_config_function_group` (Dict[Type[Agent], Callable]): Functions to configure memory for each agent type.
|
68
|
-
- `config` (
|
67
|
+
- `config` (SimConfig): Configuration settings for the agent group.
|
69
68
|
- `map_ref` (ray.ObjectRef): Reference to the map object.
|
70
69
|
- `exp_name` (str): Name of the experiment.
|
71
70
|
- `exp_id` (str | UUID): Identifier for the experiment.
|
@@ -109,11 +108,11 @@ class AgentGroup:
|
|
109
108
|
if self.enable_pgsql:
|
110
109
|
pass
|
111
110
|
# Mlflow
|
112
|
-
|
113
|
-
if
|
111
|
+
metric_config = config.prop_metric_request
|
112
|
+
if metric_config is not None and metric_config.mlflow is not None:
|
114
113
|
logger.info(f"-----Creating Mlflow client in AgentGroup {self._uuid} ...")
|
115
114
|
self.mlflow_client = MlflowClient(
|
116
|
-
config=
|
115
|
+
config=metric_config.mlflow,
|
117
116
|
experiment_uuid=self.exp_id, # type:ignore
|
118
117
|
mlflow_run_name=f"{exp_name}_{1000*int(time.time())}",
|
119
118
|
experiment_name=exp_name,
|
@@ -123,12 +122,13 @@ class AgentGroup:
|
|
123
122
|
self.mlflow_client = None
|
124
123
|
|
125
124
|
# prepare Messager
|
126
|
-
|
125
|
+
mqtt_config = config.prop_mqtt
|
126
|
+
if mqtt_config is not None:
|
127
127
|
self.messager = Messager.remote(
|
128
|
-
hostname=
|
129
|
-
port=
|
130
|
-
username=
|
131
|
-
password=
|
128
|
+
hostname=mqtt_config.server, # type:ignore
|
129
|
+
port=mqtt_config.port,
|
130
|
+
username=mqtt_config.username,
|
131
|
+
password=mqtt_config.password,
|
132
132
|
)
|
133
133
|
else:
|
134
134
|
self.messager = None
|
@@ -140,23 +140,21 @@ class AgentGroup:
|
|
140
140
|
self.initialized = False
|
141
141
|
self.id2agent = {}
|
142
142
|
# prepare LLM client
|
143
|
-
llmConfig = LLMConfig(config["llm_request"])
|
144
143
|
logger.info(f"-----Creating LLM client in AgentGroup {self._uuid} ...")
|
145
|
-
self.llm = LLM(
|
144
|
+
self.llm = LLM(config.prop_llm_request)
|
146
145
|
self.llm.set_semaphore(llm_semaphore)
|
147
146
|
|
148
147
|
# prepare Simulator
|
149
148
|
logger.info(f"-----Initializing Simulator in AgentGroup {self._uuid} ...")
|
150
|
-
self.simulator = Simulator(config
|
149
|
+
self.simulator = Simulator(config)
|
150
|
+
self.simulator.set_environment(environment)
|
151
151
|
self.simulator.set_map(map_ref)
|
152
152
|
self.projector = pyproj.Proj(
|
153
153
|
ray.get(self.simulator.map.get_projector.remote()) # type:ignore
|
154
154
|
)
|
155
155
|
# prepare Economy client
|
156
156
|
logger.info(f"-----Creating Economy client in AgentGroup {self._uuid} ...")
|
157
|
-
self.economy_client = EconomyClient(
|
158
|
-
config["simulator_request"]["simulator"]["server"]
|
159
|
-
)
|
157
|
+
self.economy_client = EconomyClient(config.prop_simulator_server_address)
|
160
158
|
|
161
159
|
# set FaissQuery
|
162
160
|
if self.embedding_model is not None:
|