HuggingFace community-driven open-source library of simulation environments
Project description
Simulate
Simulate is a library for easily creating and sharing simulation environments for intelligent agents (e.g. reinforcement learning) or synthetic data generation.
Install
Install Simulate (preferentially in a virtual environment) with a simple pip install simulate
Install for contribution (from CONTRIBUTING.md)
Create a virtual env and then install the code style/quality tools as well as the code base locally
pip install --upgrade simulate
Before you merge a PR, fix the style (we use isort
+ black
)
make style
Quick tour
Simulate's API is inspired by the great Kubric's API.
The user create a Scene
and add Assets
in it (objects, cameras, lights etc).
Once the scene is created, you can save and share it as a file. This is a gIFT file, aka a JSON file with associated resources.
You can also render the scene or do simulations using one of the backend rendering/simulation engines (at the moment Unity, Blender and Godot).
The saving/sharing format is engine agnostic and using a graphic industry standard.
Let's do a quick exploration together.
import simulate as sm
scene = sm.Scene()
Project Structure
The Python API is located in src/simulate. It allows creation and loading of scenes, and sending commands to the backend.
We provide several backends to render and/or run the scene.
The default backend requires no specific installation and is based on pyvista. It allows one to quick render/explored scene but doesn't handle physics simulation.
To allow physic simulations, the Unity backend can for instance be used by setting engine="unity"
(and soon the Godot and Blender Engines backend as well). A Unity build will be automatically downloaded (if not already) and spawed to run simulations. Alternatively, one can download and use the Unity editor themself, which must then be opened with Unity version 2021.3.2f1.
Loading a scene from the Hub or a local file
Loading a scene from a local file or the Hub is done with Scene.create_from()
, saving locally or pushing to the Hub with scene.save()
or scene.push_to_hub()
:
from simulate import Scene
scene = Scene.create_from('tests/test_assets/fixtures/Box.gltf') # either local (priority) or on the Hub with full path to file
scene = Scene.create_from('simulate-tests/Box/glTF/Box.gltf', is_local=False) # Set priority to the Hub file
scene.save('local_dir/file.gltf') # Save to a local file
scene.push_to_hub('simulate-tests/Debug/glTF/Box.gltf') # Save to the Hub - use a token if necessary
scene.show()
Creating a Scene and adding/managing Objects in the scene
Basic example of creating a scene with a plane and a sphere above it:
import simulate as sm
scene = sm.Scene()
scene += sm.Plane() + sm.Sphere(position=[0, 1, 0], radius=0.2)
>>> scene
>>> Scene(dimensionality=3, engine='PyVistaEngine')
>>> └── plane_01 (Plane - Mesh: 121 points, 100 cells)
>>> └── sphere_02 (Sphere - Mesh: 842 points, 870 cells)
scene.show()
An object (as well as the Scene) is just a node in a tree provided with optional mesh (under the hood created/stored/edited as a pyvista.PolyData
or pyvista.MultiBlock
objects) and material and/or light, camera, agents special objects.
The following objects creation helpers are currently provided:
Object3D
any object with a mesh and/or materialPlane
Sphere
Capsule
Cylinder
Box
Cone
Line
MultipleLines
Tube
Polygon
Ring
Text3D
Triangle
Rectangle
Circle
StructuredGrid
- ... (see the doc)
Many of these objects can be visualized by running the following example:
python examples/basic/objects.py
Objects are organized in a tree structure
Adding/removing objects:
- Using the addition (
+
) operator (or alternatively the method.add(object)
) will add an object as a child of a previous object. - Objects can be removed with the subtraction (
-
) operator or the.remove(object)
command. - Several objects can be added at once by adding a list/tuple to the scene.
- The whole scene can be cleared with
.clear()
. - To add a nested object, just add it to the object under which it should be nested, e.g.
scene.sphere += sphere_child
.
Accessing objects:
- Objects can be directly accessed as attributes of their parents using their names (given with
name
attribute at creation or automatically generated from the class name + creation counter). - Objects can also be accessed from their names with
.get_node(name)
. - The names of the object are enforced to be unique (on save/show).
- Various
tree_*
attributes are available on any node to quickly navegate or list part of the tree of nodes.
Here are a couple of examples of manipulations:
# Add two copy of the sphere to the scene as children of the root node (using list will add all objects on the same level)
# Using `.copy()` will create a copy of an object (the copy doesn't have any parent or children)
scene += [scene.plane_01.sphere_02.copy(), scene.plane_01.sphere_02.copy()]
>>> scene
>>> Scene(dimensionality=3, engine='pyvista')
>>> ├── plane_01 (Plane - Mesh: 121 points, 100 cells)
>>> │ └── sphere_02 (Sphere - Mesh: 842 points, 870 cells)
>>> ├── sphere_03 (Sphere - Mesh: 842 points, 870 cells)
>>> └── sphere_04 (Sphere - Mesh: 842 points, 870 cells)
# Remove the last added sphere
>>> scene.remove(scene.sphere_04)
>>> Scene(dimensionality=3, engine='pyvista')
>>> ├── plane_01 (Plane - Mesh: 121 points, 100 cells)
>>> │ └── sphere_02 (Sphere - Mesh: 842 points, 870 cells)
>>> └── sphere_03 (Sphere - Mesh: 842 points, 870 cells)
Editing and moving objects
Objects can be easily translated, rotated, scaled
Here are a couple of examples:
# Let's translate our floor (with the first sphere, it's child)
scene.plane_01.translate_x(1)
# Let's scale the second sphere uniformly
scene.sphere_03.scale(0.1)
# Inspect the current position and scaling values
print(scene.plane_01.position)
>>> array([1., 0., 0.])
print(scene.sphere_03.scaling)
>>> array([0.1, 0.1, 0.1])
# We can also translate from a vector and rotate from a quaternion or along the various axis
Editing objects:
- mesh of the object can be edited with all the manipulation operator provided by pyvista
Visualization engine
A default visualization engine is provided with the vtk backend of pyvista
.
Starting the visualization engine can be done simply with .show()
.
scene.show()
You can find bridges to other rendering/simulation engines in the integrations
directory.
Tips
If you are running on GCP, remember not to install pyvistaqt
, and if you did so, uninstall it in your environment, since QT doesn't work well on GCP.
Citation
@misc{simulate,
author = {Thomas Wolf, Edward Beeching, Carl Cochet, Dylan Ebert, Alicia Machado, Nathan Lambert, Clément Romac},
title = {Simulate},
year = {2022},
publisher = {GitHub},
journal = {GitHub repository},
howpublished = {\url{https://github.com/huggingface/simulate}}
}
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 Distribution
Built Distributions
File details
Details for the file simulate-0.0.3.dev0.tar.gz
.
File metadata
- Download URL: simulate-0.0.3.dev0.tar.gz
- Upload date:
- Size: 137.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5b4717a58ecf94957dde9fc5c9293ccfff4b3d2e3c459aa9925d7ac56438026d |
|
MD5 | 20fed11074a6a04e56e847476a82940a |
|
BLAKE2b-256 | 8ac4203a622350e43a315e53ebe4d1f03575950973de5ab8dd7ff85c5ee48cfa |
File details
Details for the file simulate-0.0.3.dev0-cp310-cp310-win_amd64.whl
.
File metadata
- Download URL: simulate-0.0.3.dev0-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 801.9 kB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | da5ba388c898084ca76c7886794d1ebdf783e02fadf0383b7abad7587123302d |
|
MD5 | bfac412955c29c0c94aebf2a49b0923e |
|
BLAKE2b-256 | 4e15d2c1809ea20b1669620ccd98aa804ba600c4687e6a447d3595cad39a4cdd |
File details
Details for the file simulate-0.0.3.dev0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: simulate-0.0.3.dev0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 641.5 kB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 446aa224248d1e30190f6c1e243df1a69303ddd829a5f66a1107c805458ba566 |
|
MD5 | f1d02f271600ce3c91319baed88b8725 |
|
BLAKE2b-256 | 13e53c753707dfeadea62c266f1cc4ae921b3d57d98a5420f971edc61750bd03 |
File details
Details for the file simulate-0.0.3.dev0-cp310-cp310-macosx_10_13_x86_64.whl
.
File metadata
- Download URL: simulate-0.0.3.dev0-cp310-cp310-macosx_10_13_x86_64.whl
- Upload date:
- Size: 571.4 kB
- Tags: CPython 3.10, macOS 10.13+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7fb07b9875af7bdad475e9e65a5d94c67df1c451cbe0237ded5b73735b59fa64 |
|
MD5 | acbea076ef660302834c207eefcd5ab9 |
|
BLAKE2b-256 | e9a3930c72e1fcc807edd2db37f27970151956d560e95ce3594711cf5da15a35 |
File details
Details for the file simulate-0.0.3.dev0-cp310-cp310-macosx_10_13_universal2.whl
.
File metadata
- Download URL: simulate-0.0.3.dev0-cp310-cp310-macosx_10_13_universal2.whl
- Upload date:
- Size: 811.1 kB
- Tags: CPython 3.10, macOS 10.13+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 27d761778a660654242144fa03cdf9ebad4ba840d96262d01b53f531e207d7b1 |
|
MD5 | db4d4af09f921e1ba91a401410530797 |
|
BLAKE2b-256 | 6d141f5835a06c6425b17c16673fc330cee3733e7942ce33a205d4153b0dff96 |
File details
Details for the file simulate-0.0.3.dev0-cp39-cp39-win_amd64.whl
.
File metadata
- Download URL: simulate-0.0.3.dev0-cp39-cp39-win_amd64.whl
- Upload date:
- Size: 801.0 kB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8986b8f998e70998a6193a6d32860be733b1e141b119691299612111a8c46279 |
|
MD5 | 9951b6cb7e1dbbefb3587e85ece530b5 |
|
BLAKE2b-256 | 9f90fb849a66431f61c23329ac8781f74a5f3b685b2f080111b8cab09649a49f |
File details
Details for the file simulate-0.0.3.dev0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: simulate-0.0.3.dev0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 642.0 kB
- Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b62c219a8eb963a1d657ea371036b81cceb1b4c88133a3377c5439424d8ab474 |
|
MD5 | 690eb7b725b0e76bdeb8af3893e03f9d |
|
BLAKE2b-256 | 616181e8871d6066ff2c9cce09dcde0898177ee35021af07fb9265540cf546bf |
File details
Details for the file simulate-0.0.3.dev0-cp39-cp39-macosx_10_13_x86_64.whl
.
File metadata
- Download URL: simulate-0.0.3.dev0-cp39-cp39-macosx_10_13_x86_64.whl
- Upload date:
- Size: 571.6 kB
- Tags: CPython 3.9, macOS 10.13+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f57e1b8b060b76fc68edb36aacfa250b06a8c70ffd7fba82b5382866f4a1a0c |
|
MD5 | 0c9ac0bc8b37509a21a8642c8c297a74 |
|
BLAKE2b-256 | 7f660c055a74f5302edc6685204fff6e8117b7b22e7df7aaf87436006b2838d3 |
File details
Details for the file simulate-0.0.3.dev0-cp39-cp39-macosx_10_13_universal2.whl
.
File metadata
- Download URL: simulate-0.0.3.dev0-cp39-cp39-macosx_10_13_universal2.whl
- Upload date:
- Size: 811.4 kB
- Tags: CPython 3.9, macOS 10.13+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b946530e5bbfe4480ada5b0dfd145afd5b34349ac3197d4a855903c833354c7c |
|
MD5 | 2cf24110e28362bad3372ec5c9553901 |
|
BLAKE2b-256 | 9ec739b881dbccb8a2d6e9f272e9b9ce0ef898a5eaed0f73a461aab76fafab32 |
File details
Details for the file simulate-0.0.3.dev0-cp38-cp38-win_amd64.whl
.
File metadata
- Download URL: simulate-0.0.3.dev0-cp38-cp38-win_amd64.whl
- Upload date:
- Size: 801.1 kB
- Tags: CPython 3.8, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e8c4f57c0290742dfb748a7e1bbf14b43c49b062dd6d44fcc329e4e311248a63 |
|
MD5 | 8179d22cf10f850b44483605c7d26c5f |
|
BLAKE2b-256 | a6d778e863ffeed492c9e4f2cdfd02a4def2b2ff1761e540c92cc4dc07826119 |
File details
Details for the file simulate-0.0.3.dev0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: simulate-0.0.3.dev0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 641.6 kB
- Tags: CPython 3.8, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 190ded207710e30f042c10c2427e79ce8ffc5d4eb3ee683f1c6f149541e65645 |
|
MD5 | 7d1a3b225f578b8f1db9f1f38dbb4b0a |
|
BLAKE2b-256 | 3bb621186038d8d102a516b528b53e8ffc7730050a9b3854e5617a82b8b72f30 |
File details
Details for the file simulate-0.0.3.dev0-cp38-cp38-macosx_10_13_x86_64.whl
.
File metadata
- Download URL: simulate-0.0.3.dev0-cp38-cp38-macosx_10_13_x86_64.whl
- Upload date:
- Size: 571.4 kB
- Tags: CPython 3.8, macOS 10.13+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa0d34504847fe324ced5eb7f2d446e6469433c3cb728f60a8d1b26543682204 |
|
MD5 | e98adf96a8992cb58057414c57c0c4b8 |
|
BLAKE2b-256 | 456ecdd0e68b320d8ef06211e9b887b42ec34ac272e33113013dc2cfb19c7a43 |
File details
Details for the file simulate-0.0.3.dev0-cp38-cp38-macosx_10_13_universal2.whl
.
File metadata
- Download URL: simulate-0.0.3.dev0-cp38-cp38-macosx_10_13_universal2.whl
- Upload date:
- Size: 811.2 kB
- Tags: CPython 3.8, macOS 10.13+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 19b517eda0f2b31f0f63b59eb2fb703cfee6b7c21e5971df73cee2e52f633a49 |
|
MD5 | 519f700722e5379c41ad846d6358679e |
|
BLAKE2b-256 | 5995e508a6efbde725ad587d9ec41c7eeae412d63d3cbbfed97c3ade6fdf6e19 |