composabl-cli-dev 0.19.1.dev1__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.
Potentially problematic release.
This version of composabl-cli-dev might be problematic. Click here for more details.
- composabl_cli/__init__.py +9 -0
- composabl_cli/cli/__init__.cpython-310-darwin.so +0 -0
- composabl_cli/cli/cli.cpython-310-darwin.so +0 -0
- composabl_cli/cli/cli_agent.cpython-310-darwin.so +0 -0
- composabl_cli/cli/cli_benchmark.cpython-310-darwin.so +0 -0
- composabl_cli/cli/cli_debug.cpython-310-darwin.so +0 -0
- composabl_cli/cli/cli_historian.cpython-310-darwin.so +0 -0
- composabl_cli/cli/cli_job.cpython-310-darwin.so +0 -0
- composabl_cli/cli/cli_main.cpython-310-darwin.so +0 -0
- composabl_cli/cli/cli_perceptor.cpython-310-darwin.so +0 -0
- composabl_cli/cli/cli_selector.cpython-310-darwin.so +0 -0
- composabl_cli/cli/cli_sim.cpython-310-darwin.so +0 -0
- composabl_cli/cli/cli_skill.cpython-310-darwin.so +0 -0
- composabl_cli/cli/cli_version.cpython-310-darwin.so +0 -0
- composabl_cli/k8s/k8s_train.cpython-310-darwin.so +0 -0
- composabl_cli/k8s/util.cpython-310-darwin.so +0 -0
- composabl_cli/main/agent.cpython-310-darwin.so +0 -0
- composabl_cli/main/perceptor.cpython-310-darwin.so +0 -0
- composabl_cli/main/selector.cpython-310-darwin.so +0 -0
- composabl_cli/main/sim.cpython-310-darwin.so +0 -0
- composabl_cli/main/skill.cpython-310-darwin.so +0 -0
- composabl_cli/template/agent_composabl/agent.py +90 -0
- composabl_cli/template/agent_docker/agent.py +99 -0
- composabl_cli/template/agent_local/agent.py +96 -0
- composabl_cli/template/perceptor/README.md +67 -0
- composabl_cli/template/perceptor/pyproject.toml +15 -0
- composabl_cli/template/perceptor/{{NAME_MODULE}}/__init__.py +3 -0
- composabl_cli/template/perceptor/{{NAME_MODULE}}/perceptor.py +34 -0
- composabl_cli/template/selector_controller/README.md +67 -0
- composabl_cli/template/selector_controller/pyproject.toml +12 -0
- composabl_cli/template/selector_controller/{{NAME_MODULE}}/__init__.py +3 -0
- composabl_cli/template/selector_controller/{{NAME_MODULE}}/controller.py +52 -0
- composabl_cli/template/selector_teacher/README.md +67 -0
- composabl_cli/template/selector_teacher/pyproject.toml +12 -0
- composabl_cli/template/selector_teacher/{{NAME_MODULE}}/__init__.py +3 -0
- composabl_cli/template/selector_teacher/{{NAME_MODULE}}/teacher.py +70 -0
- composabl_cli/template/sim/README.md +39 -0
- composabl_cli/template/sim/pyproject.toml +20 -0
- composabl_cli/template/sim/{{NAME_MODULE}}/__init__.py +3 -0
- composabl_cli/template/sim/{{NAME_MODULE}}/sim.py +253 -0
- composabl_cli/template/sim/{{NAME_MODULE}}/sim_impl.py +115 -0
- composabl_cli/template/sim_docker/Dockerfile +45 -0
- composabl_cli/template/sim_docker/README.md +17 -0
- composabl_cli/template/sim_docker/docker/sim-start.sh +14 -0
- composabl_cli/template/sim_docker/main.py +55 -0
- composabl_cli/template/sim_docker/module/README.md +39 -0
- composabl_cli/template/sim_docker/module/pyproject.toml +20 -0
- composabl_cli/template/sim_docker/module/{{NAME_MODULE}}/__init__.py +3 -0
- composabl_cli/template/sim_docker/module/{{NAME_MODULE}}/sim.py +253 -0
- composabl_cli/template/sim_docker/module/{{NAME_MODULE}}/sim_impl.py +115 -0
- composabl_cli/template/skill_controller/README.md +67 -0
- composabl_cli/template/skill_controller/pyproject.toml +12 -0
- composabl_cli/template/skill_controller/{{NAME_MODULE}}/__init__.py +3 -0
- composabl_cli/template/skill_controller/{{NAME_MODULE}}/controller.py +40 -0
- composabl_cli/template/skill_coordinated_population/README.md +67 -0
- composabl_cli/template/skill_coordinated_population/pyproject.toml +12 -0
- composabl_cli/template/skill_coordinated_population/{{NAME_MODULE}}/__init__.py +3 -0
- composabl_cli/template/skill_coordinated_population/{{NAME_MODULE}}/coach.py +70 -0
- composabl_cli/template/skill_coordinated_set/README.md +67 -0
- composabl_cli/template/skill_coordinated_set/pyproject.toml +12 -0
- composabl_cli/template/skill_coordinated_set/{{NAME_MODULE}}/__init__.py +3 -0
- composabl_cli/template/skill_coordinated_set/{{NAME_MODULE}}/coach.py +70 -0
- composabl_cli/template/skill_teacher/README.md +67 -0
- composabl_cli/template/skill_teacher/pyproject.toml +12 -0
- composabl_cli/template/skill_teacher/{{NAME_MODULE}}/__init__.py +3 -0
- composabl_cli/template/skill_teacher/{{NAME_MODULE}}/teacher.py +70 -0
- composabl_cli_dev-0.19.1.dev1.dist-info/METADATA +49 -0
- composabl_cli_dev-0.19.1.dev1.dist-info/RECORD +71 -0
- composabl_cli_dev-0.19.1.dev1.dist-info/WHEEL +5 -0
- composabl_cli_dev-0.19.1.dev1.dist-info/entry_points.txt +2 -0
- composabl_cli_dev-0.19.1.dev1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Copyright (C) Composabl, Inc - All Rights Reserved
|
|
2
|
+
# Unauthorized copying of this file, via any medium is strictly prohibited
|
|
3
|
+
# Proprietary and confidential
|
|
4
|
+
|
|
5
|
+
# We want to expose these classes to the user at the base of core
|
|
6
|
+
# ex: `from composabl.core import Agent``
|
|
7
|
+
|
|
8
|
+
# Continue with the imports
|
|
9
|
+
from .cli import *
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# Copyright (C) Composabl, Inc - All Rights Reserved
|
|
2
|
+
# Unauthorized copying of this file, via any medium is strictly prohibited
|
|
3
|
+
# Proprietary and confidential
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
from typing import Dict
|
|
7
|
+
|
|
8
|
+
from composabl import Agent, MaintainGoal, Sensor, Skill, Trainer
|
|
9
|
+
|
|
10
|
+
# Accept the EULA
|
|
11
|
+
os.environ["COMPOSABL_EULA_AGREED"] = "1"
|
|
12
|
+
|
|
13
|
+
# Set the license
|
|
14
|
+
# os.environ["COMPOSABL_LICENSE"] = "YOUR_LICENSE_KEY"
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class BalanceTeacher(MaintainGoal):
|
|
18
|
+
def __init__(self, *args, **kwargs):
|
|
19
|
+
super().__init__(
|
|
20
|
+
"pole_theta", "Maintain pole to upright", target=0, stop_distance=0.418
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
# defaults the BL and BR
|
|
24
|
+
|
|
25
|
+
async def compute_action_mask(self, transformed_sensors: Dict, action):
|
|
26
|
+
# Cartpole might not use an action mask, so this can return None
|
|
27
|
+
return None
|
|
28
|
+
|
|
29
|
+
async def transform_sensors(self, sensors, action):
|
|
30
|
+
# For Cartpole, might just return sensors directly
|
|
31
|
+
return sensors
|
|
32
|
+
|
|
33
|
+
async def transform_action(self, transformed_sensors: Dict, action):
|
|
34
|
+
# No transformation needed for discrete action space
|
|
35
|
+
return action
|
|
36
|
+
|
|
37
|
+
async def filtered_sensor_space(self):
|
|
38
|
+
# Return relevant sensors
|
|
39
|
+
return ["cart_pos", "cart_vel", "pole_theta", "pole_alpha"]
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def main():
|
|
43
|
+
# Create the agent
|
|
44
|
+
a = Agent()
|
|
45
|
+
|
|
46
|
+
# https://gymnasium.farama.org/environments/classic_control/cart_pole/#observation-space
|
|
47
|
+
a.add_sensors(
|
|
48
|
+
[
|
|
49
|
+
Sensor(
|
|
50
|
+
"cart_pos",
|
|
51
|
+
"The Cart Position between [-4.8, 4.8]",
|
|
52
|
+
lambda sensors: sensors[0],
|
|
53
|
+
),
|
|
54
|
+
Sensor(
|
|
55
|
+
"cart_vel",
|
|
56
|
+
"The Cart Position between [-inf, inf]",
|
|
57
|
+
lambda sensors: sensors[1],
|
|
58
|
+
),
|
|
59
|
+
Sensor(
|
|
60
|
+
"pole_theta",
|
|
61
|
+
"The Pole Angle [-0.418 rad, 0.418 rad]",
|
|
62
|
+
lambda sensors: sensors[2],
|
|
63
|
+
),
|
|
64
|
+
Sensor(
|
|
65
|
+
"pole_alpha",
|
|
66
|
+
"The Pole Angular Velocity [-inf, inf]",
|
|
67
|
+
lambda sensors: sensors[3],
|
|
68
|
+
),
|
|
69
|
+
]
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
skill = Skill("pole-balance", BalanceTeacher)
|
|
73
|
+
a.add_skill(skill)
|
|
74
|
+
|
|
75
|
+
# Create trainer and train the agent
|
|
76
|
+
r = Trainer(
|
|
77
|
+
{
|
|
78
|
+
"target": {"composabl"},
|
|
79
|
+
"resources": {
|
|
80
|
+
"sim_count": 2,
|
|
81
|
+
},
|
|
82
|
+
}
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
r.train(a, train_cycles=5)
|
|
86
|
+
r.close()
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
if __name__ == "__main__":
|
|
90
|
+
main()
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# Copyright (C) Composabl, Inc - All Rights Reserved
|
|
2
|
+
# Unauthorized copying of this file, via any medium is strictly prohibited
|
|
3
|
+
# Proprietary and confidential
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
from typing import Dict
|
|
7
|
+
|
|
8
|
+
from composabl import Agent, MaintainGoal, Sensor, Skill, Trainer
|
|
9
|
+
|
|
10
|
+
# Accept the EULA
|
|
11
|
+
os.environ["COMPOSABL_EULA_AGREED"] = "1"
|
|
12
|
+
|
|
13
|
+
# Set the license
|
|
14
|
+
# os.environ["COMPOSABL_LICENSE"] = "YOUR_LICENSE_KEY"
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class BalanceTeacher(MaintainGoal):
|
|
18
|
+
def __init__(self, *args, **kwargs):
|
|
19
|
+
super().__init__(
|
|
20
|
+
"pole_theta", "Maintain pole to upright", target=0, stop_distance=0.418
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
# defaults the BL and BR
|
|
24
|
+
|
|
25
|
+
async def compute_action_mask(self, transformed_sensors: Dict, action):
|
|
26
|
+
# Cartpole might not use an action mask, so this can return None
|
|
27
|
+
return None
|
|
28
|
+
|
|
29
|
+
async def transform_sensors(self, sensors, action):
|
|
30
|
+
# For Cartpole, might just return sensors directly
|
|
31
|
+
return sensors
|
|
32
|
+
|
|
33
|
+
async def transform_action(self, transformed_sensors: Dict, action):
|
|
34
|
+
# No transformation needed for discrete action space
|
|
35
|
+
return action
|
|
36
|
+
|
|
37
|
+
async def filtered_sensor_space(self):
|
|
38
|
+
# Return relevant sensors
|
|
39
|
+
return ["cart_pos", "cart_vel", "pole_theta", "pole_alpha"]
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def main():
|
|
43
|
+
# Create the agent
|
|
44
|
+
a = Agent()
|
|
45
|
+
|
|
46
|
+
# https://gymnasium.farama.org/environments/classic_control/cart_pole/#observation-space
|
|
47
|
+
a.add_sensors(
|
|
48
|
+
[
|
|
49
|
+
Sensor(
|
|
50
|
+
"cart_pos",
|
|
51
|
+
"The Cart Position between [-4.8, 4.8]",
|
|
52
|
+
lambda sensors: sensors[0],
|
|
53
|
+
),
|
|
54
|
+
Sensor(
|
|
55
|
+
"cart_vel",
|
|
56
|
+
"The Cart Position between [-inf, inf]",
|
|
57
|
+
lambda sensors: sensors[1],
|
|
58
|
+
),
|
|
59
|
+
Sensor(
|
|
60
|
+
"pole_theta",
|
|
61
|
+
"The Pole Angle [-0.418 rad, 0.418 rad]",
|
|
62
|
+
lambda sensors: sensors[2],
|
|
63
|
+
),
|
|
64
|
+
Sensor(
|
|
65
|
+
"pole_alpha",
|
|
66
|
+
"The Pole Angular Velocity [-inf, inf]",
|
|
67
|
+
lambda sensors: sensors[3],
|
|
68
|
+
),
|
|
69
|
+
]
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
skill = Skill("pole-balance", BalanceTeacher)
|
|
73
|
+
a.add_skill(skill)
|
|
74
|
+
|
|
75
|
+
# Create trainer and train the agent
|
|
76
|
+
r = Trainer(
|
|
77
|
+
{
|
|
78
|
+
"target": {"docker": {"image": "composabl/sim-cartpole-dev:latest"}},
|
|
79
|
+
"resources": {
|
|
80
|
+
"sim_count": 2,
|
|
81
|
+
},
|
|
82
|
+
"post_processing": {
|
|
83
|
+
"record": {
|
|
84
|
+
"is_enabled": True,
|
|
85
|
+
"file_path": "/tmp/composabl/recordings",
|
|
86
|
+
"avi_file_name": "output.avi",
|
|
87
|
+
"gif_file_name": "output.gif",
|
|
88
|
+
"max_frames": 24 * 5,
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
}
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
r.train(a, train_cycles=5)
|
|
95
|
+
r.close()
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
if __name__ == "__main__":
|
|
99
|
+
main()
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# Copyright (C) Composabl, Inc - All Rights Reserved
|
|
2
|
+
# Unauthorized copying of this file, via any medium is strictly prohibited
|
|
3
|
+
# Proprietary and confidential
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
from typing import Dict
|
|
7
|
+
|
|
8
|
+
from composabl import Agent, MaintainGoal, Sensor, Skill, Trainer
|
|
9
|
+
|
|
10
|
+
# Accept the EULA
|
|
11
|
+
os.environ["COMPOSABL_EULA_AGREED"] = "1"
|
|
12
|
+
|
|
13
|
+
# Set the license
|
|
14
|
+
# os.environ["COMPOSABL_LICENSE"] = "YOUR_LICENSE_KEY"
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class BalanceTeacher(MaintainGoal):
|
|
18
|
+
def __init__(self, *args, **kwargs):
|
|
19
|
+
super().__init__(
|
|
20
|
+
"pole_theta", "Maintain pole to upright", target=0, stop_distance=0.418
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
# defaults the BL and BR
|
|
24
|
+
|
|
25
|
+
async def compute_action_mask(self, transformed_sensors: Dict, action):
|
|
26
|
+
# Cartpole might not use an action mask, so this can return None
|
|
27
|
+
return None
|
|
28
|
+
|
|
29
|
+
async def transform_sensors(self, sensors, action):
|
|
30
|
+
# For Cartpole, might just return sensors directly
|
|
31
|
+
return sensors
|
|
32
|
+
|
|
33
|
+
async def transform_action(self, transformed_sensors: Dict, action):
|
|
34
|
+
# No transformation needed for discrete action space
|
|
35
|
+
return action
|
|
36
|
+
|
|
37
|
+
async def filtered_sensor_space(self):
|
|
38
|
+
# Return relevant sensors
|
|
39
|
+
return ["cart_pos", "cart_vel", "pole_theta", "pole_alpha"]
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def main():
|
|
43
|
+
# Create the agent
|
|
44
|
+
a = Agent()
|
|
45
|
+
|
|
46
|
+
# https://gymnasium.farama.org/environments/classic_control/cart_pole/#observation-space
|
|
47
|
+
a.add_sensors(
|
|
48
|
+
[
|
|
49
|
+
Sensor(
|
|
50
|
+
"cart_pos",
|
|
51
|
+
"The Cart Position between [-4.8, 4.8]",
|
|
52
|
+
lambda sensors: sensors[0],
|
|
53
|
+
),
|
|
54
|
+
Sensor(
|
|
55
|
+
"cart_vel",
|
|
56
|
+
"The Cart Position between [-inf, inf]",
|
|
57
|
+
lambda sensors: sensors[1],
|
|
58
|
+
),
|
|
59
|
+
Sensor(
|
|
60
|
+
"pole_theta",
|
|
61
|
+
"The Pole Angle [-0.418 rad, 0.418 rad]",
|
|
62
|
+
lambda sensors: sensors[2],
|
|
63
|
+
),
|
|
64
|
+
Sensor(
|
|
65
|
+
"pole_alpha",
|
|
66
|
+
"The Pole Angular Velocity [-inf, inf]",
|
|
67
|
+
lambda sensors: sensors[3],
|
|
68
|
+
),
|
|
69
|
+
]
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
skill = Skill("pole-balance", BalanceTeacher)
|
|
73
|
+
a.add_skill(skill)
|
|
74
|
+
|
|
75
|
+
# Create trainer and train the agent
|
|
76
|
+
r = Trainer(
|
|
77
|
+
{
|
|
78
|
+
"target": {"local": {"address": "localhost:1337"}},
|
|
79
|
+
"post_processing": {
|
|
80
|
+
"record": {
|
|
81
|
+
"is_enabled": True,
|
|
82
|
+
"file_path": "/tmp/composabl/recordings",
|
|
83
|
+
"avi_file_name": "output.avi",
|
|
84
|
+
"gif_file_name": "output.gif",
|
|
85
|
+
"max_frames": 24 * 5,
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
}
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
r.train(a, train_cycles=5)
|
|
92
|
+
r.close()
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
if __name__ == "__main__":
|
|
96
|
+
main()
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# README
|
|
2
|
+
|
|
3
|
+
This is a template for creating a new Perceptor. A Perceptor is a component that is responsible for processing data and returning a result. This can be used for example in a Machine Learning model, where the Perceptor is responsible for processing the data and returning the prediction.
|
|
4
|
+
|
|
5
|
+
## Tree Structure
|
|
6
|
+
|
|
7
|
+
The template is structured as follows:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
my-perceptor/ # Root folder
|
|
11
|
+
├── my_perceptor/ # Main package folder
|
|
12
|
+
│ ├── __init__.py # Package init file
|
|
13
|
+
│ └── perceptor.py # Main perceptor file
|
|
14
|
+
├── pyproject.toml # Project configuration, containing [composabl]
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## PyProject [composabl] Section
|
|
18
|
+
|
|
19
|
+
We add the `[composabl]` section to the `pyproject.toml` file to specify the type of component we are creating as well as its entrypoint. This is used by the Composabl CLI to determine the type of
|
|
20
|
+
component and how to handle it.
|
|
21
|
+
|
|
22
|
+
Example:
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
[composabl]
|
|
26
|
+
type = "teacher"
|
|
27
|
+
entrypoint = "my_perceptor.perceptor:MyPerceptor"
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Development
|
|
31
|
+
|
|
32
|
+
To work on the Perceptor, you can simply create a temporary file or main file that starts up and executes the `compute` method of the portable Perceptor. Example, we can create a `test.py` file with:
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
from composabl_perceptor_my_perceptor.perceptor import MyPerceptor
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
async def start():
|
|
39
|
+
p = MyPerceptor()
|
|
40
|
+
res = await t.compute(None, [1.0])
|
|
41
|
+
print(res)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
if __name__ == "__main__":
|
|
45
|
+
import asyncio
|
|
46
|
+
|
|
47
|
+
asyncio.run(start())
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Which we can then run with
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
# Install the module
|
|
54
|
+
pip install -e my-perceptor
|
|
55
|
+
|
|
56
|
+
# Run the test file
|
|
57
|
+
python my-perceptor/test.py
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Preparing for Upload
|
|
61
|
+
|
|
62
|
+
Once we are ready for uploading, we can create a `.tar.gz` file that contains the version. This can be done with the following command:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
# Tar GZ the plugin
|
|
66
|
+
tar -czvf my-perceptor-0.0.1.tar.gz my-perceptor
|
|
67
|
+
```
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "{{NAME}}"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "{{DESCRIPTION}}"
|
|
5
|
+
authors = [{ name = "John Doe", email = "john.doe@composabl.com" }]
|
|
6
|
+
dependencies = [
|
|
7
|
+
"composabl-core{{COMPOSABL_DEV}}{{COMPOSABL_CORE_VERSION}}",
|
|
8
|
+
]
|
|
9
|
+
|
|
10
|
+
[composabl]
|
|
11
|
+
type = "perceptor"
|
|
12
|
+
variables = [
|
|
13
|
+
"counter_derived"
|
|
14
|
+
]
|
|
15
|
+
entrypoint = "{{NAME_MODULE}}.perceptor:DemoPerceptor"
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Copyright (C) Composabl, Inc - All Rights Reserved
|
|
2
|
+
# Unauthorized copying of this file, via any medium is strictly prohibited
|
|
3
|
+
# Proprietary and confidential
|
|
4
|
+
|
|
5
|
+
import time
|
|
6
|
+
|
|
7
|
+
from composabl_core import PerceptorImpl
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class DemoPerceptor(PerceptorImpl):
|
|
11
|
+
def __init__(self, *args, **kwargs):
|
|
12
|
+
self.previous_value = None
|
|
13
|
+
self.previous_time = None
|
|
14
|
+
|
|
15
|
+
async def compute(self, obs_spec, obs):
|
|
16
|
+
current_value = obs["counter"]
|
|
17
|
+
current_time = time.time() # Get current time
|
|
18
|
+
value_derived = 0
|
|
19
|
+
|
|
20
|
+
# Only calculate derivative if we have a previous sensors values
|
|
21
|
+
if self.previous_value is not None and self.previous_time is not None:
|
|
22
|
+
time_delta = current_time - self.previous_time
|
|
23
|
+
|
|
24
|
+
if time_delta > 0: # Check to ensure time has passed
|
|
25
|
+
value_derived = (current_value - self.previous_value) / time_delta
|
|
26
|
+
|
|
27
|
+
# Update previous value and time for the next sensor values
|
|
28
|
+
self.previous_value = current_value
|
|
29
|
+
self.previous_time = current_time
|
|
30
|
+
|
|
31
|
+
return {"counter_derived": value_derived}
|
|
32
|
+
|
|
33
|
+
def filtered_sensor_space(self, obs):
|
|
34
|
+
return ["counter"]
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# README
|
|
2
|
+
|
|
3
|
+
This is a template for creating a new Perceptor. A Perceptor is a component that is responsible for processing data and returning a result. This can be used for example in a Machine Learning model, where the Perceptor is responsible for processing the data and returning the prediction.
|
|
4
|
+
|
|
5
|
+
## Tree Structure
|
|
6
|
+
|
|
7
|
+
The template is structured as follows:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
my-perceptor/ # Root folder
|
|
11
|
+
├── my_perceptor/ # Main package folder
|
|
12
|
+
│ ├── __init__.py # Package init file
|
|
13
|
+
│ └── perceptor.py # Main perceptor file
|
|
14
|
+
├── pyproject.toml # Project configuration, containing [composabl]
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## PyProject [composabl] Section
|
|
18
|
+
|
|
19
|
+
We add the `[composabl]` section to the `pyproject.toml` file to specify the type of component we are creating as well as its entrypoint. This is used by the Composabl CLI to determine the type of
|
|
20
|
+
component and how to handle it.
|
|
21
|
+
|
|
22
|
+
Example:
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
[composabl]
|
|
26
|
+
type = "teacher"
|
|
27
|
+
entrypoint = "my_perceptor.perceptor:MyPerceptor"
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Development
|
|
31
|
+
|
|
32
|
+
To work on the Perceptor, you can simply create a temporary file or main file that starts up and executes the `compute` method of the portable Perceptor. Example, we can create a `test.py` file with:
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
from composabl_perceptor_my_perceptor.perceptor import MyPerceptor
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
async def start():
|
|
39
|
+
p = MyPerceptor()
|
|
40
|
+
res = await t.compute(None, [1.0])
|
|
41
|
+
print(res)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
if __name__ == "__main__":
|
|
45
|
+
import asyncio
|
|
46
|
+
|
|
47
|
+
asyncio.run(start())
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Which we can then run with
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
# Install the module
|
|
54
|
+
pip install -e my-perceptor
|
|
55
|
+
|
|
56
|
+
# Run the test file
|
|
57
|
+
python my-perceptor/test.py
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Preparing for Upload
|
|
61
|
+
|
|
62
|
+
Once we are ready for uploading, we can create a `.tar.gz` file that contains the version. This can be done with the following command:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
# Tar GZ the plugin
|
|
66
|
+
tar -czvf my-perceptor-0.0.1.tar.gz my-perceptor
|
|
67
|
+
```
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "{{NAME}}"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "{{DESCRIPTION}}"
|
|
5
|
+
authors = [{ name = "John Doe", email = "john.doe@composabl.com" }]
|
|
6
|
+
dependencies = [
|
|
7
|
+
"composabl-core{{COMPOSABL_DEV}}{{COMPOSABL_CORE_VERSION}}",
|
|
8
|
+
]
|
|
9
|
+
|
|
10
|
+
[composabl]
|
|
11
|
+
type = "selector-controller"
|
|
12
|
+
entrypoint = "{{NAME_MODULE}}.controller:Controller"
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# Copyright (C) Composabl, Inc - All Rights Reserved
|
|
2
|
+
# Unauthorized copying of this file, via any medium is strictly prohibited
|
|
3
|
+
# Proprietary and confidential
|
|
4
|
+
|
|
5
|
+
from typing import Dict, List
|
|
6
|
+
|
|
7
|
+
from composabl_core import SkillController
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class Controller(SkillController):
|
|
11
|
+
"""
|
|
12
|
+
We start at 10 reward and count down to 0 the goal is that the agent stays
|
|
13
|
+
above or equal to 0 this means it learned to cound +1 each time
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
def __init__(self, *args, **kwargs):
|
|
17
|
+
self.past_obs = None
|
|
18
|
+
self.counter = 10
|
|
19
|
+
self.sensor_name = "counter"
|
|
20
|
+
|
|
21
|
+
async def compute_action(self, transformed_sensors: Dict, action) -> List[float]:
|
|
22
|
+
"""
|
|
23
|
+
Compute action in a programme selector is to select the best skill based in a rule or an optimization.
|
|
24
|
+
Let's supose that we have three skills:
|
|
25
|
+
1 - Decrease counter
|
|
26
|
+
2 - Increase counter
|
|
27
|
+
3 - Stop
|
|
28
|
+
"""
|
|
29
|
+
# return Skill 1 = decrease
|
|
30
|
+
if self.counter > 10:
|
|
31
|
+
return [0]
|
|
32
|
+
# return Skill 2 = increase
|
|
33
|
+
elif self.counter < 10:
|
|
34
|
+
return [1]
|
|
35
|
+
# return Skill 3 = stop
|
|
36
|
+
else:
|
|
37
|
+
return [3]
|
|
38
|
+
|
|
39
|
+
async def compute_success_criteria(self, transformed_sensors: Dict, action) -> bool:
|
|
40
|
+
return bool(transformed_sensors[self.sensor_name] >= 10)
|
|
41
|
+
|
|
42
|
+
async def compute_termination(self, transformed_sensors: Dict, action) -> bool:
|
|
43
|
+
return bool(transformed_sensors[self.sensor_name] <= -10)
|
|
44
|
+
|
|
45
|
+
async def transform_sensors(self, sensors, action) -> str:
|
|
46
|
+
return sensors
|
|
47
|
+
|
|
48
|
+
async def transform_action(self, transformed_sensors: Dict, action) -> float:
|
|
49
|
+
return action
|
|
50
|
+
|
|
51
|
+
async def filtered_sensor_space(self) -> List[str]:
|
|
52
|
+
return ["counter"]
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# README
|
|
2
|
+
|
|
3
|
+
This is a template for creating a new Perceptor. A Perceptor is a component that is responsible for processing data and returning a result. This can be used for example in a Machine Learning model, where the Perceptor is responsible for processing the data and returning the prediction.
|
|
4
|
+
|
|
5
|
+
## Tree Structure
|
|
6
|
+
|
|
7
|
+
The template is structured as follows:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
my-perceptor/ # Root folder
|
|
11
|
+
├── my_perceptor/ # Main package folder
|
|
12
|
+
│ ├── __init__.py # Package init file
|
|
13
|
+
│ └── perceptor.py # Main perceptor file
|
|
14
|
+
├── pyproject.toml # Project configuration, containing [composabl]
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## PyProject [composabl] Section
|
|
18
|
+
|
|
19
|
+
We add the `[composabl]` section to the `pyproject.toml` file to specify the type of component we are creating as well as its entrypoint. This is used by the Composabl CLI to determine the type of
|
|
20
|
+
component and how to handle it.
|
|
21
|
+
|
|
22
|
+
Example:
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
[composabl]
|
|
26
|
+
type = "teacher"
|
|
27
|
+
entrypoint = "my_perceptor.perceptor:MyPerceptor"
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Development
|
|
31
|
+
|
|
32
|
+
To work on the Perceptor, you can simply create a temporary file or main file that starts up and executes the `compute` method of the portable Perceptor. Example, we can create a `test.py` file with:
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
from composabl_perceptor_my_perceptor.perceptor import MyPerceptor
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
async def start():
|
|
39
|
+
p = MyPerceptor()
|
|
40
|
+
res = await t.compute(None, [1.0])
|
|
41
|
+
print(res)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
if __name__ == "__main__":
|
|
45
|
+
import asyncio
|
|
46
|
+
|
|
47
|
+
asyncio.run(start())
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Which we can then run with
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
# Install the module
|
|
54
|
+
pip install -e my-perceptor
|
|
55
|
+
|
|
56
|
+
# Run the test file
|
|
57
|
+
python my-perceptor/test.py
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Preparing for Upload
|
|
61
|
+
|
|
62
|
+
Once we are ready for uploading, we can create a `.tar.gz` file that contains the version. This can be done with the following command:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
# Tar GZ the plugin
|
|
66
|
+
tar -czvf my-perceptor-0.0.1.tar.gz my-perceptor
|
|
67
|
+
```
|