phyelds-vmas 7.1.0__tar.gz
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.
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: phyelds-vmas
|
|
3
|
+
Version: 7.1.0
|
|
4
|
+
Summary: VMAS integration for phyelds
|
|
5
|
+
Home-page: https://github.com/phyelds/phyelds
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Author: Davide Domini
|
|
8
|
+
Author-email: davide.domini@unibo.it
|
|
9
|
+
Requires-Python: >=3.12,<3.14
|
|
10
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
15
|
+
Requires-Dist: numpy (>=1.26)
|
|
16
|
+
Requires-Dist: phyelds (>=7.0.0,<8.0.0)
|
|
17
|
+
Requires-Dist: torch (>=2.0)
|
|
18
|
+
Requires-Dist: vmas (==1.5.2)
|
|
19
|
+
Project-URL: Repository, https://github.com/phyelds/phyelds
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
|
|
22
|
+
# phyelds-vmas
|
|
23
|
+
|
|
24
|
+
VMAS integration for [phyelds](https://pypi.org/project/phyelds/).
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
pip install phyelds-vmas
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
`phyelds-vmas` installs a compatible `phyelds` release and VMAS.
|
|
33
|
+
|
|
34
|
+
## Usage
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
from phyelds.simulator import Simulator
|
|
38
|
+
from phyelds.simulator.runner import schedule_program_for_all
|
|
39
|
+
from phyelds.vmas import VmasEnvironment, vmas_runner
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
The extension requires `phyelds >=7.0.0,<8.0.0`.
|
|
43
|
+
|
|
44
|
+
## Release
|
|
45
|
+
|
|
46
|
+
`phyelds-vmas` follows the same version as `phyelds`. The root semantic-release
|
|
47
|
+
workflow calculates the release version, writes it to both package manifests,
|
|
48
|
+
and publishes both distributions together.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# phyelds-vmas
|
|
2
|
+
|
|
3
|
+
VMAS integration for [phyelds](https://pypi.org/project/phyelds/).
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install phyelds-vmas
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
`phyelds-vmas` installs a compatible `phyelds` release and VMAS.
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```python
|
|
16
|
+
from phyelds.simulator import Simulator
|
|
17
|
+
from phyelds.simulator.runner import schedule_program_for_all
|
|
18
|
+
from phyelds.vmas import VmasEnvironment, vmas_runner
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
The extension requires `phyelds >=7.0.0,<8.0.0`.
|
|
22
|
+
|
|
23
|
+
## Release
|
|
24
|
+
|
|
25
|
+
`phyelds-vmas` follows the same version as `phyelds`. The root semantic-release
|
|
26
|
+
workflow calculates the release version, writes it to both package manifests,
|
|
27
|
+
and publishes both distributions together.
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
[tool.poetry]
|
|
2
|
+
name = "phyelds-vmas"
|
|
3
|
+
version = "7.1.0"
|
|
4
|
+
description = "VMAS integration for phyelds"
|
|
5
|
+
license = "Apache-2.0"
|
|
6
|
+
authors = [
|
|
7
|
+
"Davide Domini <davide.domini@unibo.it>",
|
|
8
|
+
"Gianluca Aguzzi <gianluca.aguzzi@unibo.it>"
|
|
9
|
+
]
|
|
10
|
+
homepage = "https://github.com/phyelds/phyelds"
|
|
11
|
+
repository = "https://github.com/phyelds/phyelds"
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
|
|
14
|
+
packages = [
|
|
15
|
+
{ include = "phyelds/vmas", from = "src" },
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
classifiers = [
|
|
19
|
+
"Operating System :: OS Independent",
|
|
20
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
[tool.poetry.dependencies]
|
|
24
|
+
python = ">=3.12,<3.14"
|
|
25
|
+
phyelds = ">=7.0.0,<8.0.0"
|
|
26
|
+
vmas = "1.5.2"
|
|
27
|
+
numpy = ">=1.26"
|
|
28
|
+
torch = ">=2.0"
|
|
29
|
+
|
|
30
|
+
[tool.poetry.group.dev.dependencies]
|
|
31
|
+
pytest = "^8.0.0"
|
|
32
|
+
pylint = "^3.0.0"
|
|
33
|
+
flake8 = "^7.0.0"
|
|
34
|
+
|
|
35
|
+
[tool.pytest.ini_options]
|
|
36
|
+
testpaths = ["tests"]
|
|
37
|
+
|
|
38
|
+
[build-system]
|
|
39
|
+
requires = ["poetry-core>=2.0.0,<3.0.0"]
|
|
40
|
+
build-backend = "poetry.core.masonry.api"
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"""Adapter between VMAS environments and the phyelds simulator."""
|
|
2
|
+
|
|
3
|
+
from typing import Any, Callable, List
|
|
4
|
+
|
|
5
|
+
import vmas.simulator.environment
|
|
6
|
+
|
|
7
|
+
from phyelds.simulator import Environment, Node
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class VmasEnvironment(Environment):
|
|
11
|
+
"""Wrap a VMAS environment as a phyelds simulator environment."""
|
|
12
|
+
|
|
13
|
+
def __init__(
|
|
14
|
+
self,
|
|
15
|
+
vmas_environment: vmas.simulator.environment.Environment,
|
|
16
|
+
neighborhood_function: Callable[[Node, Environment], List[Node]] = None,
|
|
17
|
+
):
|
|
18
|
+
super().__init__(neighborhood_function)
|
|
19
|
+
self.vmas_environment = vmas_environment
|
|
20
|
+
self.initialize_nodes()
|
|
21
|
+
|
|
22
|
+
def initialize_nodes(self) -> None:
|
|
23
|
+
"""Create phyelds nodes from the agents in the VMAS environment."""
|
|
24
|
+
observations = self.vmas_environment.reset()
|
|
25
|
+
for index, agent in enumerate(self.vmas_environment.agents):
|
|
26
|
+
data: dict[str, Any] = {
|
|
27
|
+
"observations": observations[index][0],
|
|
28
|
+
"rewards": 0.0,
|
|
29
|
+
"dones": False,
|
|
30
|
+
"infos": {},
|
|
31
|
+
"agent": agent,
|
|
32
|
+
}
|
|
33
|
+
node = Node(
|
|
34
|
+
position=(agent.state.pos[0][0].item(), agent.state.pos[0][1].item()),
|
|
35
|
+
data=data,
|
|
36
|
+
node_id=index,
|
|
37
|
+
)
|
|
38
|
+
self.add_node(node)
|
|
39
|
+
|
|
40
|
+
def update_nodes(self, observations, rewards, dones, infos) -> None:
|
|
41
|
+
"""Synchronize phyelds nodes with the latest VMAS step result."""
|
|
42
|
+
for index, agent in enumerate(self.vmas_environment.agents):
|
|
43
|
+
node = self.nodes[index]
|
|
44
|
+
node.data["observations"] = observations[index][0]
|
|
45
|
+
node.position = (agent.state.pos[0][0].item(), agent.state.pos[0][1].item())
|
|
46
|
+
node.data["rewards"] = rewards[index][0]
|
|
47
|
+
node.data["dones"] = dones
|
|
48
|
+
node.data["infos"] = infos[index]
|
|
49
|
+
node.data["agent"] = agent
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"""VMAS-specific simulation runner."""
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
import torch
|
|
5
|
+
|
|
6
|
+
from phyelds.simulator import Simulator
|
|
7
|
+
from phyelds.vmas.environment import VmasEnvironment
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def vmas_runner(simulator: Simulator, time_delta: float) -> None:
|
|
11
|
+
"""Step VMAS from aggregate-program actions and schedule the next step."""
|
|
12
|
+
if not isinstance(simulator.environment, VmasEnvironment):
|
|
13
|
+
raise TypeError("vmas_runner requires a simulator with a VmasEnvironment")
|
|
14
|
+
|
|
15
|
+
environment = simulator.environment
|
|
16
|
+
actions = [
|
|
17
|
+
np.array(node.data["outputs"]["action"], dtype=np.float32)
|
|
18
|
+
for node in environment.node_list()
|
|
19
|
+
]
|
|
20
|
+
actions_single_env = torch.tensor(
|
|
21
|
+
np.stack(actions), device=environment.vmas_environment.device
|
|
22
|
+
)
|
|
23
|
+
actions_batch = actions_single_env.expand(
|
|
24
|
+
environment.vmas_environment.num_envs, -1, -1
|
|
25
|
+
)
|
|
26
|
+
actions_per_agent = list(actions_batch.unbind(dim=1))
|
|
27
|
+
observations, rewards, dones, infos = environment.vmas_environment.step(actions_per_agent)
|
|
28
|
+
environment.update_nodes(observations, rewards, dones, infos)
|
|
29
|
+
simulator.schedule_event(time_delta, vmas_runner, simulator, time_delta)
|