pycityagent 2.0.0a42__cp310-cp310-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/__init__.py +23 -0
- pycityagent/agent.py +833 -0
- pycityagent/cli/wrapper.py +44 -0
- pycityagent/economy/__init__.py +5 -0
- pycityagent/economy/econ_client.py +355 -0
- pycityagent/environment/__init__.py +7 -0
- pycityagent/environment/interact/__init__.py +0 -0
- pycityagent/environment/interact/interact.py +198 -0
- pycityagent/environment/message/__init__.py +0 -0
- pycityagent/environment/sence/__init__.py +0 -0
- pycityagent/environment/sence/static.py +416 -0
- pycityagent/environment/sidecar/__init__.py +8 -0
- pycityagent/environment/sidecar/sidecarv2.py +109 -0
- pycityagent/environment/sim/__init__.py +29 -0
- pycityagent/environment/sim/aoi_service.py +39 -0
- pycityagent/environment/sim/client.py +126 -0
- pycityagent/environment/sim/clock_service.py +44 -0
- pycityagent/environment/sim/economy_services.py +192 -0
- pycityagent/environment/sim/lane_service.py +111 -0
- pycityagent/environment/sim/light_service.py +122 -0
- pycityagent/environment/sim/person_service.py +295 -0
- pycityagent/environment/sim/road_service.py +39 -0
- pycityagent/environment/sim/sim_env.py +145 -0
- pycityagent/environment/sim/social_service.py +59 -0
- pycityagent/environment/simulator.py +331 -0
- pycityagent/environment/utils/__init__.py +14 -0
- pycityagent/environment/utils/base64.py +16 -0
- pycityagent/environment/utils/const.py +244 -0
- pycityagent/environment/utils/geojson.py +24 -0
- pycityagent/environment/utils/grpc.py +57 -0
- pycityagent/environment/utils/map_utils.py +157 -0
- pycityagent/environment/utils/port.py +11 -0
- pycityagent/environment/utils/protobuf.py +41 -0
- pycityagent/llm/__init__.py +11 -0
- pycityagent/llm/embeddings.py +231 -0
- pycityagent/llm/llm.py +377 -0
- pycityagent/llm/llmconfig.py +13 -0
- pycityagent/llm/utils.py +6 -0
- pycityagent/memory/__init__.py +13 -0
- pycityagent/memory/const.py +43 -0
- pycityagent/memory/faiss_query.py +302 -0
- pycityagent/memory/memory.py +448 -0
- pycityagent/memory/memory_base.py +170 -0
- pycityagent/memory/profile.py +165 -0
- pycityagent/memory/self_define.py +165 -0
- pycityagent/memory/state.py +173 -0
- pycityagent/memory/utils.py +28 -0
- pycityagent/message/__init__.py +3 -0
- pycityagent/message/messager.py +88 -0
- pycityagent/metrics/__init__.py +6 -0
- pycityagent/metrics/mlflow_client.py +147 -0
- pycityagent/metrics/utils/const.py +0 -0
- pycityagent/pycityagent-sim +0 -0
- pycityagent/pycityagent-ui +0 -0
- pycityagent/simulation/__init__.py +8 -0
- pycityagent/simulation/agentgroup.py +580 -0
- pycityagent/simulation/simulation.py +634 -0
- pycityagent/simulation/storage/pg.py +184 -0
- pycityagent/survey/__init__.py +4 -0
- pycityagent/survey/manager.py +54 -0
- pycityagent/survey/models.py +120 -0
- pycityagent/utils/__init__.py +11 -0
- pycityagent/utils/avro_schema.py +109 -0
- pycityagent/utils/decorators.py +99 -0
- pycityagent/utils/parsers/__init__.py +13 -0
- pycityagent/utils/parsers/code_block_parser.py +37 -0
- pycityagent/utils/parsers/json_parser.py +86 -0
- pycityagent/utils/parsers/parser_base.py +60 -0
- pycityagent/utils/pg_query.py +92 -0
- pycityagent/utils/survey_util.py +53 -0
- pycityagent/workflow/__init__.py +26 -0
- pycityagent/workflow/block.py +211 -0
- pycityagent/workflow/prompt.py +79 -0
- pycityagent/workflow/tool.py +240 -0
- pycityagent/workflow/trigger.py +163 -0
- pycityagent-2.0.0a42.dist-info/LICENSE +21 -0
- pycityagent-2.0.0a42.dist-info/METADATA +235 -0
- pycityagent-2.0.0a42.dist-info/RECORD +81 -0
- pycityagent-2.0.0a42.dist-info/WHEEL +5 -0
- pycityagent-2.0.0a42.dist-info/entry_points.txt +3 -0
- pycityagent-2.0.0a42.dist-info/top_level.txt +3 -0
@@ -0,0 +1,147 @@
|
|
1
|
+
import asyncio
|
2
|
+
import logging
|
3
|
+
import os
|
4
|
+
import uuid
|
5
|
+
from collections.abc import Sequence
|
6
|
+
from typing import Any, Optional, Union
|
7
|
+
|
8
|
+
import mlflow
|
9
|
+
from mlflow.entities import (Dataset, DatasetInput, Document, Experiment,
|
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)
|
15
|
+
|
16
|
+
from ..utils.decorators import lock_decorator
|
17
|
+
|
18
|
+
logger = logging.getLogger("mlflow")
|
19
|
+
|
20
|
+
|
21
|
+
def init_mlflow_connection(
|
22
|
+
config: dict,
|
23
|
+
mlflow_run_name: Optional[str] = None,
|
24
|
+
experiment_name: Optional[str] = None,
|
25
|
+
experiment_description: Optional[str] = None,
|
26
|
+
experiment_tags: Optional[dict[str, Any]] = None,
|
27
|
+
) -> tuple[str, tuple[str, mlflow.MlflowClient, Run, str]]:
|
28
|
+
|
29
|
+
os.environ["MLFLOW_TRACKING_USERNAME"] = config.get("username", None)
|
30
|
+
os.environ["MLFLOW_TRACKING_PASSWORD"] = config.get("password", None)
|
31
|
+
|
32
|
+
run_uuid = str(uuid.uuid4())
|
33
|
+
# run name
|
34
|
+
if mlflow_run_name is None:
|
35
|
+
mlflow_run_name = f"exp_{run_uuid}"
|
36
|
+
|
37
|
+
# exp name
|
38
|
+
if experiment_name is None:
|
39
|
+
experiment_name = f"run_{run_uuid}"
|
40
|
+
|
41
|
+
# tags
|
42
|
+
if experiment_tags is None:
|
43
|
+
experiment_tags = {}
|
44
|
+
if experiment_description is not None:
|
45
|
+
experiment_tags["mlflow.note.content"] = experiment_description
|
46
|
+
|
47
|
+
uri = config["mlflow_uri"]
|
48
|
+
client = mlflow.MlflowClient(tracking_uri=uri)
|
49
|
+
|
50
|
+
# experiment
|
51
|
+
try:
|
52
|
+
experiment_id = client.create_experiment(
|
53
|
+
name=experiment_name,
|
54
|
+
tags=experiment_tags,
|
55
|
+
)
|
56
|
+
except Exception as e:
|
57
|
+
experiment = client.get_experiment_by_name(experiment_name)
|
58
|
+
if experiment is None:
|
59
|
+
raise e
|
60
|
+
experiment_id = experiment.experiment_id
|
61
|
+
|
62
|
+
# run
|
63
|
+
run = client.create_run(experiment_id=experiment_id, run_name=mlflow_run_name)
|
64
|
+
|
65
|
+
run_id = run.info.run_id
|
66
|
+
|
67
|
+
return run_id, (uri, client, run, run_uuid)
|
68
|
+
|
69
|
+
|
70
|
+
class MlflowClient:
|
71
|
+
"""
|
72
|
+
- Mlflow client
|
73
|
+
"""
|
74
|
+
|
75
|
+
def __init__(
|
76
|
+
self,
|
77
|
+
config: dict,
|
78
|
+
mlflow_run_name: Optional[str] = None,
|
79
|
+
experiment_name: Optional[str] = None,
|
80
|
+
experiment_description: Optional[str] = None,
|
81
|
+
experiment_tags: Optional[dict[str, Any]] = None,
|
82
|
+
run_id: Optional[str] = None,
|
83
|
+
) -> None:
|
84
|
+
if run_id is None:
|
85
|
+
self._run_id, (
|
86
|
+
self._mlflow_uri,
|
87
|
+
self._client,
|
88
|
+
self._run,
|
89
|
+
self._run_uuid,
|
90
|
+
) = init_mlflow_connection(
|
91
|
+
config=config,
|
92
|
+
mlflow_run_name=mlflow_run_name,
|
93
|
+
experiment_name=experiment_name,
|
94
|
+
experiment_description=experiment_description,
|
95
|
+
experiment_tags=experiment_tags,
|
96
|
+
)
|
97
|
+
else:
|
98
|
+
self._mlflow_uri = uri = config["mlflow_uri"]
|
99
|
+
os.environ["MLFLOW_TRACKING_USERNAME"] = config.get("username", None)
|
100
|
+
os.environ["MLFLOW_TRACKING_PASSWORD"] = config.get("password", None)
|
101
|
+
self._client = client = mlflow.MlflowClient(tracking_uri=uri)
|
102
|
+
self._run = client.get_run(run_id=run_id)
|
103
|
+
self._run_id = run_id
|
104
|
+
self._run_uuid = run_uuid = str(uuid.uuid4())
|
105
|
+
self._lock = asyncio.Lock()
|
106
|
+
|
107
|
+
@property
|
108
|
+
def client(
|
109
|
+
self,
|
110
|
+
) -> mlflow.MlflowClient:
|
111
|
+
return self._client
|
112
|
+
|
113
|
+
@property
|
114
|
+
def run_id(
|
115
|
+
self,
|
116
|
+
) -> str:
|
117
|
+
assert self._run_id is not None
|
118
|
+
return self._run_id
|
119
|
+
|
120
|
+
@lock_decorator
|
121
|
+
async def log_batch(
|
122
|
+
self,
|
123
|
+
metrics: Sequence[Metric] = (),
|
124
|
+
params: Sequence[Param] = (),
|
125
|
+
tags: Sequence[RunTag] = (),
|
126
|
+
):
|
127
|
+
self.client.log_batch(
|
128
|
+
run_id=self.run_id, metrics=metrics, params=params, tags=tags
|
129
|
+
)
|
130
|
+
|
131
|
+
@lock_decorator
|
132
|
+
async def log_metric(
|
133
|
+
self,
|
134
|
+
key: str,
|
135
|
+
value: float,
|
136
|
+
step: Optional[int] = None,
|
137
|
+
timestamp: Optional[int] = None,
|
138
|
+
):
|
139
|
+
if timestamp is not None:
|
140
|
+
timestamp = int(timestamp)
|
141
|
+
self.client.log_metric(
|
142
|
+
run_id=self.run_id,
|
143
|
+
key=key,
|
144
|
+
value=value,
|
145
|
+
timestamp=timestamp,
|
146
|
+
step=step,
|
147
|
+
)
|
File without changes
|
Binary file
|
Binary file
|