Robotics Simulator written in Rust
Project description
PyKesko
PyKesko is the python package for the Kesko simulator. It contains python bindings to the Rust code and provides an API to interact with simulator.
Note: PyKesko is currently pre-release, unstable and very limited.
Getting Started
Prerequisites
Make sure you have one of the supported python versions installed (3.7-3.11). It is also recommended to use a virtual environment.
Installation
pip install pykesko
Usage
Run the simulator
Run and step the simulator
from pykesko import Kesko
if __name__ == "__main__":
kesko = Kesko()
kesko.initialize()
for _ in range(1000):
kesko.step()
kesko.close()
Spawn bodies
Kesko has som built in models that can be spawned.
from pykesko import Kesko, KeskoModel
from pykesko.protocol.commands import Spawn
from pykesko.color import Color
if __name__ == "__main__":
kesko = Kesko()
kesko.initialize()
kesko.send(
[
Spawn(model=KeskoModel.Plane, position=[0.0, 0.0, 0.0], color=Color.WHITE),
Spawn(model=KeskoModel.Humanoid, position=[0.0, 2.0, 0.0], color=Color.DEEP_ORANGE),
]
)
for _ in range(1000):
kesko.step()
kesko.close()
Use a Gym environment
In the future PyKesko will contain a bunch of gym environments. Currently there is only one prototype environment consisting of a four legged agent which is tasked with learning to walk.
import gym
env = gym.make("pykesko:Spider-v0", render_mode="human")
env.reset()
for _ in range(1000):
env.step(env.action_space.sample())
env.close()
Use Stable Baselines3 to train an agent to walk
Since PyKesko has Gym integration it is really easy to train with a library like Stable Baselines3. Make sure to use the bleeding edge version of Stable Baselines3 that has support for the latest Gym version
Install Stable Baselines3 bleeding edge version
pip install git+https://github.com/carlosluis/stable-baselines3@fix_tests
Train agent using PPO
import gym
from stable_baselines3 import PPO
env = gym.make("pykesko:Spider-v0", render_mode="human")
model = PPO("MlpPolicy", env)
model.learn(total_timesteps=100_000, progress_bar=True)
env.close()
Running PPO for about 5 million steps yield the result below. Note that in order to train in reasonable amount of time you should use parallel non-render environments.
Train parallel environments in headless mode
Below is an example how to use multiple parallel environments without rendering (headless mode). It also includes saving checkpoints as well as logging to tensorboard
from datetime import datetime
import gym
from stable_baselines3 import PPO
from stable_baselines3.common.callbacks import CheckpointCallback
from stable_baselines3.common.vec_env import SubprocVecEnv
from stable_baselines3.common.utils import set_random_seed
ENV = "Spider-v0"
FULL_ENV = f"pykesko:Spider-v0"
MODEL_NAME = f"{ENV}_PPO"
# Number of environments, should be close to the number of cpu's available
NUM_ENVS = 16
# PPO parameters
N_STEPS = 2048 // NUM_ENVS # Number of steps to take for each PPO iteration
N_EPOCHS = 10 # Number of epochs to use when optimizing the surrogate loss
BATCH_SIZE = 64
TOTAL_TIME_STEPS = 8_000_000 # Total number of time steps to train for
SAVE_EVERY = 200_000 # How often to save a checkpoint of the model
SAVE_FOLDER = f"./runs/{MODEL_NAME}_{datetime.now()}"
def make_env(env_id: str, rank: int, seed: int = 0):
"""
Utility function for multiprocessed env.
:param env_id: the environment ID
:param seed: the initial seed for RNG
:param rank: index of the subprocess
"""
def _init():
env = gym.make(env_id)
env.seed(seed + rank)
return env
set_random_seed(seed)
return _init
if __name__ == "__main__":
# Create NUM_ENVS environments
env = SubprocVecEnv([make_env(env_id=FULL_ENV, rank=i) for i in range(NUM_ENVS)])
checkpoint_callback = CheckpointCallback(
save_freq=max(SAVE_EVERY // NUM_ENVS, 1),
save_path=f"{SAVE_FOLDER}/model_checkpoints",
name_prefix=MODEL_NAME,
)
model = PPO(
"MlpPolicy",
env,
tensorboard_log=f"{SAVE_FOLDER}/tb_logs",
n_steps=N_STEPS,
n_epochs=N_EPOCHS,
batch_size=BATCH_SIZE,
)
model.learn(
total_timesteps=TOTAL_TIME_STEPS,
callback=checkpoint_callback,
progress_bar=True,
)
env.close()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
File details
Details for the file pykesko-0.0.4-cp311-none-win_amd64.whl
.
File metadata
- Download URL: pykesko-0.0.4-cp311-none-win_amd64.whl
- Upload date:
- Size: 8.9 MB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee87ec7775f4a4e39ef0cb94dfe671adba4c8bda21225cfe81496c1427e45222 |
|
MD5 | c5b1c2e9d450393ae080804e5dc937bb |
|
BLAKE2b-256 | 9b7b6831b0a0a9eb1d481439865c476fa7846d063c41d442aef228607f976889 |
File details
Details for the file pykesko-0.0.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: pykesko-0.0.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 13.8 MB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1cdc80ff217b11cad2e5da9d66e310f9e3953bc14559f964305b14301626f095 |
|
MD5 | bcd22e153ec4a8a589b91cb1c9d0c4d8 |
|
BLAKE2b-256 | 618d8d53f338e5b68e6ad6e7f2b41e4b08f4fa2165152129c80b50d20c5ba7c2 |
File details
Details for the file pykesko-0.0.4-cp311-cp311-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
.
File metadata
- Download URL: pykesko-0.0.4-cp311-cp311-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
- Upload date:
- Size: 19.2 MB
- Tags: CPython 3.11, macOS 10.9+ universal2 (ARM64, x86-64), macOS 10.9+ x86-64, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 591a7eb241285ea2fb62a027646a199f5b7dc813b10c0ecfc77a6f4bbd7907d0 |
|
MD5 | 3be7912cbb0e2f323fceb683d0f45b1c |
|
BLAKE2b-256 | a2e3309b1e49e29a0bb412c2eaf3e5621a5c2043b84317e4119d88cb27228787 |
File details
Details for the file pykesko-0.0.4-cp310-none-win_amd64.whl
.
File metadata
- Download URL: pykesko-0.0.4-cp310-none-win_amd64.whl
- Upload date:
- Size: 8.9 MB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f4a0475186b51359b84c225d2749438fee0fdc441bfab7e5cd24a3b117ce67a7 |
|
MD5 | 5c4ce01017e562fbad7c7b773366aed9 |
|
BLAKE2b-256 | 3fa8a8824adfce7657fb89becd7c424f6f466d7f34038fefdf7b98bcdeeccd46 |
File details
Details for the file pykesko-0.0.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: pykesko-0.0.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 13.8 MB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b60474be1a9043a6f8eace8831b476f43ecff8fbcdccfd5047a5d05d81430d17 |
|
MD5 | 271e466bbdfd67d4c8ab90356a3c8b48 |
|
BLAKE2b-256 | 626680682964296f6815b64c770084388efd4ce1927f5943813a78a876a5038d |
File details
Details for the file pykesko-0.0.4-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
.
File metadata
- Download URL: pykesko-0.0.4-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
- Upload date:
- Size: 19.2 MB
- Tags: CPython 3.10, macOS 10.9+ universal2 (ARM64, x86-64), macOS 10.9+ x86-64, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b80235078a89de2602b6e281cb604122bb6c40c0996a15f7e5aef499cc03aa73 |
|
MD5 | fcdef95518449bdf3e74790da4ad0e7d |
|
BLAKE2b-256 | 346d866c83667cb2656194c146219d6f026aa92397e924458b26bc87ed4b53b0 |
File details
Details for the file pykesko-0.0.4-cp39-none-win_amd64.whl
.
File metadata
- Download URL: pykesko-0.0.4-cp39-none-win_amd64.whl
- Upload date:
- Size: 8.9 MB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 269971c728901619ad36f4915d4fee74e6bbc8be28c6816188909541cbbcc4bd |
|
MD5 | b41c671d8746c69f0b55439b9f09509b |
|
BLAKE2b-256 | ba1838985d93ac23aad666a7526ad0042da4408638b01de38e8064128d40d364 |
File details
Details for the file pykesko-0.0.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: pykesko-0.0.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 13.8 MB
- Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab1e67cf366a381d07d4ad6724128e05efdd46aa35f71d2aec6c9a09a0ea6824 |
|
MD5 | 12b1fc012497edee156cd0d7e50b9ad5 |
|
BLAKE2b-256 | 48ad2fecefce4b7c2954ac850eef3ffb6e0d8bf608e57a9c1067c6fb3f22c375 |
File details
Details for the file pykesko-0.0.4-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
.
File metadata
- Download URL: pykesko-0.0.4-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
- Upload date:
- Size: 19.2 MB
- Tags: CPython 3.9, macOS 10.9+ universal2 (ARM64, x86-64), macOS 10.9+ x86-64, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c16b798acf21a48269afbb75d5c5825eac0324738e0e9a9d3666a608e9e54197 |
|
MD5 | 48c3fbd336c2fc37863957fe86588d13 |
|
BLAKE2b-256 | dbb33d84ec4735edb4c870e4d3e6218793a08fc0dd958fa8a8c2da762e2d1677 |
File details
Details for the file pykesko-0.0.4-cp38-none-win_amd64.whl
.
File metadata
- Download URL: pykesko-0.0.4-cp38-none-win_amd64.whl
- Upload date:
- Size: 8.9 MB
- Tags: CPython 3.8, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ce253c0293aae3385d8bff37988d4bb31b6112b0ac0c148a22d79a6a18f7517 |
|
MD5 | 6b28b1421f6bee66516af9b8787f83aa |
|
BLAKE2b-256 | f76f81ccd75788d7d7b24d63ffb05c1fe70ed1b6d5047239823afee4b05809b4 |
File details
Details for the file pykesko-0.0.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: pykesko-0.0.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 13.8 MB
- Tags: CPython 3.8, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 35fb5d1905de17d119c35265b6b94bd11da9ff4e8049f2af73eb344ab722bcc7 |
|
MD5 | 1f2b5a07b6ee78f4fddcd10cc4dbaff9 |
|
BLAKE2b-256 | b4217ee4d9005083366d05d3b6bfde93402ec9c3fbf82eb68980e04ab08755d0 |
File details
Details for the file pykesko-0.0.4-cp38-cp38-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
.
File metadata
- Download URL: pykesko-0.0.4-cp38-cp38-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
- Upload date:
- Size: 19.2 MB
- Tags: CPython 3.8, macOS 10.9+ universal2 (ARM64, x86-64), macOS 10.9+ x86-64, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 90c90376ec4b3842113c25b2c1686ac9d6d077dcf639a4079231e2d8e90abf73 |
|
MD5 | e811f4bf7dbd86e988e1da4c83db5cd0 |
|
BLAKE2b-256 | 45dea79fd347ba6c53820ade07d94106fcc71cc8f417a47ad94c0e09ba495d68 |
File details
Details for the file pykesko-0.0.4-cp37-none-win_amd64.whl
.
File metadata
- Download URL: pykesko-0.0.4-cp37-none-win_amd64.whl
- Upload date:
- Size: 8.9 MB
- Tags: CPython 3.7, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 904979d82b6eca7216fb061adcf1da06634b8ff33994d663cb2102cf05d6d536 |
|
MD5 | ba8bc18f252f31c8d16ec1db02e1822a |
|
BLAKE2b-256 | 55f0083abc2cbbf938f3f1914ab571a6a3f1b64f341f41c375acf2a5a9d87160 |
File details
Details for the file pykesko-0.0.4-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: pykesko-0.0.4-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 13.8 MB
- Tags: CPython 3.7m, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ffb3a65d5ddf1c45bb1621b7d289cf86cdcd641cfbf353d556614893a9172764 |
|
MD5 | bcf040e4ff171c74591f17586e1fa339 |
|
BLAKE2b-256 | c16294d39e30559f2e169aa7967da7164053dbf2289a7079378c88ecaf5feac1 |
File details
Details for the file pykesko-0.0.4-cp37-cp37m-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
.
File metadata
- Download URL: pykesko-0.0.4-cp37-cp37m-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
- Upload date:
- Size: 19.2 MB
- Tags: CPython 3.7m, macOS 10.9+ universal2 (ARM64, x86-64), macOS 10.9+ x86-64, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3d88d34cacd3fe12d9c628b3fe8c80657e3bdfb0fd468b3e836f6f82a383d22c |
|
MD5 | 657a90c48e091740aed56b1b2686432c |
|
BLAKE2b-256 | 7181ef29f1883c4ac696655e963376b128101488feb479302eb688535f5bbaf9 |