Python API Reference¶
joltsim.World¶
Construction & Stepping¶
World(config: SolverConfig = SolverConfig(), num_threads: int = 1)— Create a single Jolt physics world.step(dt: float, substeps: int = 1) -> int— Advance simulation bydtseconds acrosssubstepssubsteps (GIL released). Returns Jolt step error bitmask (0on success).reset() -> None— Restore initial snapshot/poses, zero velocities/controls, and reset contact count.optimize_broadphase() -> None— Rebuild Jolt broadphase tree after adding bodies.set_gravity(x: float, y: float, z: float) -> None— Set gravity vector (\(\text{m/s}^2\)).set_solver_config(config: SolverConfig) -> None/get_solver_config() -> SolverConfig— Update or inspect solver settings.
Scene Building & Lookups¶
add_ground_plane(z: float = 0.0, friction: float = 0.8, restitution: float = 0.0) -> Noneadd_body(desc: BodyDesc) -> int— Add rigid/static/kinematic body; returnsbody_idx. RaisesRuntimeErrorif shape construction fails.add_articulation(desc: ArticulationDesc) -> int— Add articulated multibody; returnsart_idx.add_soft_body(desc: SoftBodyDesc) -> int— Add deformable soft body; returnssb_idx.add_site(desc: SiteDesc) -> int— Attach a named frame (SiteDesc) to a body; returnssite_idx.body_id(name: str) -> int/joint_id(name: str) -> int/site_id(name: str) -> int— Look up index by name (returns-1if not found).get_site_pose(site_idx: int) -> tuple[np.ndarray, np.ndarray]— Return(pos, quat_xyzw)in world frame. RaisesIndexError/out_of_rangeif invalid.get_scene_metadata() -> dict— Return{"bodies": [...], "joints": [...], "soft_bodies": [...], "sites": [...]}.
State, Keyframes & Mocap¶
save_state() -> bytes/load_state(data: bytes) -> None— Binary snapshot serialization (GIL released).save_keyframe(name: str) -> None/load_keyframe(name: str) -> None/list_keyframes() -> list[str]— Named in-memory reset snapshots (load_keyframeraisesKeyError/out_of_rangeif unknown).set_body_pose(body_idx: int, pos: Sequence[float], quat: Sequence[float]) -> None— Teleport a body to(pos, quat_xyzw).set_mocap_pose(body_idx: int, pos: Sequence[float], quat: Sequence[float], dt: float = 0.0) -> None— Move a kinematic body (BodyDesc.is_kinematic=True) to target pose overdt.
Properties & Zero-Copy Buffers¶
nq: int,nv: int,nu: int,num_joints: int,num_bodies: int,num_articulations: int,num_soft_bodies: int,contact_count: intqpos,qvel,ctrl,qfrc_motor,joint_error(float321D views)body_pos(nb, 3),body_quat(nb, 4),body_linvel(nb, 3),body_angvel(nb, 3)(float322D views)contacts(CONTACT_DTYPEstructured view of active contacts)
Control, Dynamics & Kinematics¶
set_articulation_motor_config(art_idx: int, joint_idx: int, motor: MotorConfig) -> Noneapply_external_force(body_idx: int, force: Sequence[float], pos: Sequence[float] | None = None) -> Noneapply_external_torque(body_idx: int, torque: Sequence[float]) -> Nonecalculate_ik(art_idx: int, link_idx: int, target_pos: Sequence[float], target_quat: Sequence[float] | None = None, max_iters: int = 64, tol: float = 1e-4, damping: float = 0.05) -> np.ndarraycalculate_jacobian(art_idx: int, link_idx: int, local_point: Sequence[float] | None = None) -> np.ndarray((6, nv))calculate_mass_matrix(art_idx: int) -> np.ndarray((nv, nv))calculate_inverse_dynamics(art_idx: int, qpos: np.ndarray, qvel: np.ndarray, qacc: np.ndarray) -> np.ndarray((nv,), full RNEA)
Soft Bodies, Materials, Constraints & Queries¶
soft_body_vertices(sb_idx: int) -> np.ndarray((V, 3)float32),soft_body_faces(sb_idx: int) -> np.ndarray((F, 3)uint32)set_soft_body_vertex_inv_mass(sb_idx: int, vert_idx: int, inv_mass: float) -> None,set_soft_body_pressure(sb_idx: int, pressure: float) -> Nonechange_dynamics(body_idx: int, mass=-1.0, friction=-1.0, restitution=-1.0, linear_damping=-1.0, angular_damping=-1.0) -> Noneset_contact_pair_properties(body1: int, body2: int, friction=-1.0, restitution=-1.0) -> None,clear_contact_pair_properties(body1: int, body2: int) -> Noneset_collision_filter_pair(body1: int, body2: int, enable: bool) -> None,set_collision_filter_group_mask(body_idx: int, group: int, mask: int) -> Noneadd_constraint(desc: RuntimeConstraintDesc) -> int,remove_constraint(constraint_id: int) -> Noneget_aabb(body_idx: int) -> tuple[np.ndarray, np.ndarray]get_closest_points(body1: int, body2: int, max_dist: float = 0.5) -> list[ClosestPointResult]get_overlapping_objects(aabb_min: Sequence[float], aabb_max: Sequence[float]) -> list[int]get_joint_ft_sensor(art_idx: int) -> np.ndarray((num_joints, 6)),get_imu(body_idx: int, include_gravity: bool = True) -> np.ndarray((6,))raycast_batch(starts: np.ndarray, directions: np.ndarray, max_dist: float = 10.0) -> np.ndarray(RAY_HIT_DTYPE,(M,))
joltsim.VecWorld¶
VecWorld(num_envs: int, num_threads: int = 0, config: SolverConfig = SolverConfig()) mirrors World with batched (N, ...) arrays and env_idx-scoped methods:
Counters:
num_envs,num_threads,nq,nv,nu,num_joints,num_bodies,total_contact_count,contact_counts((N,)uint32).Stepping & Resets (GIL released):
step(dt, substeps=1),reset_all(),reset_envs(env_ids),save_state(env_idx),load_state(env_idx, data).Keyframes, Mocap & Scene:
save_keyframe(name),load_keyframe(name),list_keyframes(),set_mocap_pose(env_idx, body_idx, pos, quat, dt=0.0),set_body_poses(env_ids, body_idx, pos, quat),get_site_pose(env_idx, site_idx),get_aabb(env_idx, body_idx),get_scene_metadata().Config, Materials & Filters:
set_gravity,set_solver_config,optimize_broadphase,set_articulation_motor_config,change_dynamics(env_idx, body_idx, ...),set_contact_pair_properties,clear_contact_pair_properties,set_collision_filter_pair,set_collision_filter_group_mask,apply_external_force(env_ids, body_idx, forces),apply_external_torque(env_ids, body_idx, torques).Queries:
calculate_ik(env_idx, art_idx, link_idx, ...),raycast_batch(starts, directions, max_dist=10.0)((M, 3)or(N, M, 3)->(N, M)).
Python Modules (autodoc)¶
- joltsim.load_urdf(urdf_path, base_pos=(0.0, 0.0, 0.0), base_quat=(0.0, 0.0, 0.0, 1.0), fixed_base=False, default_kp=200.0, default_kd=20.0, default_effort=100.0, inertia_scale=1.0, min_inertia_diag=0.0, link_friction=0.5, merge_fixed_links=True)[source]¶
- Return type:
- Parameters:
urdf_path (str | Path)
base_pos (Tuple[float, float, float])
base_quat (Tuple[float, float, float, float])
fixed_base (bool)
default_kp (float)
default_kd (float)
default_effort (float)
inertia_scale (float)
min_inertia_diag (float)
link_friction (float)
merge_fixed_links (bool)
- joltsim.load_mjcf(mjcf_path, base_pos=None, fixed_base=None, default_kp=120.0, default_kd=12.0, default_effort=150.0, inertia_scale=1.0, min_inertia_diag=0.001, motor_mode=MotorMode.Position)[source]¶
Parse a MuJoCo MJCF XML into a JoltSim ArticulationDesc.
- Return type:
- Parameters:
mjcf_path (str | Path)
base_pos (Tuple[float, float, float] | None)
fixed_base (bool | None)
default_kp (float)
default_kd (float)
default_effort (float)
inertia_scale (float)
min_inertia_diag (float)
motor_mode (MotorMode)
- joltsim.load_sdf(path, default_kp=100.0, default_kd=10.0)[source]¶
Parse an SDF (<sdf><model>…) file into JoltSim ArticulationDesc and BodyDesc objects.
- Return type:
- Parameters:
path (str | Path)
default_kp (float)
default_kd (float)
- joltsim.get_asset_path(rel_path)[source]¶
Resolve a bundled asset path inside joltsim/assets/.
- Return type:
Path- Parameters:
rel_path (str)
- joltsim.to_torch(array, device='cuda', non_blocking=True)[source]¶
Convert a NumPy array to a PyTorch tensor, using pinned host memory for async CUDA transfer.
PyTorch is imported lazily so import joltsim never fails when torch is not installed.
- Parameters:
array (ndarray)
device (str)
non_blocking (bool)
- class joltsim.UrdfModel(desc, link_names, joint_names, actuated_joint_names, mimic_map)[source]¶
- Parameters:
desc (ArticulationDesc)
link_names (List[str])
joint_names (List[str])
actuated_joint_names (List[str])
mimic_map (Dict[str, Tuple[str, float, float]])
- class joltsim.MjcfModel(desc, link_names, joint_names, actuated_joint_names, motor_joint_names, has_ground_plane, ground_z, sites=list())[source]¶
- Parameters:
desc (ArticulationDesc)
link_names (List[str])
joint_names (List[str])
actuated_joint_names (List[str])
motor_joint_names (List[str])
has_ground_plane (bool)
ground_z (float)
sites (List[SiteDesc])
- class joltsim.SdfModel(name, articulations=list(), bodies=list())[source]¶
- Parameters:
name (str)
articulations (List[ArticulationDesc])
bodies (List[BodyDesc])
- joltsim.camera.compute_view_matrix(eye, target, up=(0.0, 0.0, 1.0))[source]¶
Compute a 4x4 column-major look-at view matrix (float32).
- Return type:
ndarray- Parameters:
eye (Tuple[float, float, float])
target (Tuple[float, float, float])
up (Tuple[float, float, float])
- joltsim.camera.compute_projection_matrix(fov_deg, aspect, near=0.05, far=50.0)[source]¶
Compute a 4x4 perspective projection matrix (float32).
- Return type:
ndarray- Parameters:
fov_deg (float)
aspect (float)
near (float)
far (float)
- joltsim.camera.get_camera_image(world, width, height, view_matrix=None, projection_matrix=None, far=50.0, as_torch=False, device='cpu', body_idx=None, site_idx=None, local_pos=(0.0, 0.0, 0.0), local_quat=(0.0, 0.0, 0.0, 1.0), return_flow=False)[source]¶
Render offscreen (rgb uint8, depth float32, seg int32[, flow float32]) for World or VecWorld.
Supports either an explicit
view_matrixor mounting to abody_idx/site_idxwith optionallocal_posandlocal_quat(xyzw). Whenreturn_flow=True, also returns instantaneous 2D optical flow(du/dt, dv/dt)in pixels/second of shape(H, W, 2)or(N, H, W, 2). Whenas_torch=True, converts outputs viajoltsim.to_torch(..., device=device).- Return type:
Tuple[Any,...]- Parameters:
world (Any)
width (int)
height (int)
view_matrix (ndarray | None)
projection_matrix (ndarray | None)
far (float)
as_torch (bool)
device (str)
body_idx (int | None)
site_idx (int | None)
local_pos (Tuple[float, float, float])
local_quat (Tuple[float, float, float, float])
return_flow (bool)
- class joltsim.viewer.ViewerServer(world, host='127.0.0.1', port=8765, dt=0.016666666666666666, substeps=4, title='JoltSim Studio', ray_provider=None)[source]¶
Single-port HTTP + WebSocket server streaming World/VecWorld state at 60 FPS.
- Parameters:
world (Any)
host (str)
port (int)
dt (float)
substeps (int)
title (str)
ray_provider (Optional[Callable[[], tuple[np.ndarray, np.ndarray]]])
- add_debug_line(line_from, line_to, color=(1.0, 0.0, 0.0), width=1.0, life_time=0.0, replace_item_unique_id=-1)[source]¶
Add or replace a 3D debug line segment rendered in JoltSim Studio.
- Return type:
int- Parameters:
line_from (tuple[float, float, float] | list[float] | ndarray)
line_to (tuple[float, float, float] | list[float] | ndarray)
color (tuple[float, float, float])
width (float)
life_time (float)
replace_item_unique_id (int)
- remove_debug_line(line_id)[source]¶
Remove a debug line by ID.
- Return type:
None- Parameters:
line_id (int)
- property url: str¶
- joltsim.viewer.launch(world, host='127.0.0.1', port=8765, dt=0.016666666666666666, substeps=4, open_browser=True, block=True, title='JoltSim Studio', ray_provider=None)[source]¶
Launch JoltSim Studio in the browser for a World or VecWorld.
- Return type:
- Parameters:
world (Any)
host (str)
port (int)
dt (float)
substeps (int)
open_browser (bool)
block (bool)
title (str)
ray_provider (Callable[[], tuple[ndarray, ndarray]] | None)
- class joltsim.gym.JoltVectorEnv(vec_world, single_observation_space, single_action_space, dt=0.016666666666666666, substeps=4, max_episode_steps=200)[source]¶
Base Gymnasium VectorEnv wrapping a JoltSim VecWorld with zero-copy stepping and auto-reset.
- Parameters:
vec_world (VecWorld)
single_observation_space (gym.Space)
single_action_space (gym.Space)
dt (float)
substeps (int)
max_episode_steps (int)
- reset(*, seed=None, options=None)[source]¶
Reset all parallel environments and return a batch of initial observations and info.
- Parameters:
seed (
Optional[int]) – The environment reset seedoptions (
Optional[Dict[str,Any]]) – If to return the options
- Return type:
Tuple[ndarray,Dict[str,Any]]- Returns:
A batch of observations and info from the vectorized environment.
Example
>>> import gymnasium as gym >>> envs = gym.make_vec("CartPole-v1", num_envs=3, vectorization_mode="sync") >>> observations, infos = envs.reset(seed=42) >>> observations array([[ 0.0273956 , -0.00611216, 0.03585979, 0.0197368 ], [ 0.01522993, -0.04562247, -0.04799704, 0.03392126], [-0.03774345, -0.02418869, -0.00942293, 0.0469184 ]], dtype=float32) >>> infos {}
- step(actions)[source]¶
Take an action for each parallel environment.
- Parameters:
actions (
ndarray) – Batch of actions with theaction_spaceshape.- Return type:
Tuple[ndarray,ndarray,ndarray,ndarray,Dict[str,Any]]- Returns:
Batch of (observations, rewards, terminations, truncations, infos)
Note
As the vector environments autoreset for a terminating and truncating sub-environments, this will occur on the next step after terminated or truncated is True.
Example
>>> import gymnasium as gym >>> import numpy as np >>> envs = gym.make_vec("CartPole-v1", num_envs=3, vectorization_mode="sync") >>> _ = envs.reset(seed=42) >>> actions = np.array([1, 0, 1], dtype=np.int32) >>> observations, rewards, terminations, truncations, infos = envs.step(actions) >>> observations array([[ 0.02727336, 0.18847767, 0.03625453, -0.26141977], [ 0.01431748, -0.24002443, -0.04731862, 0.3110827 ], [-0.03822722, 0.1710671 , -0.00848456, -0.2487226 ]], dtype=float32) >>> rewards array([1., 1., 1.]) >>> terminations array([False, False, False]) >>> terminations array([False, False, False]) >>> infos {}
- class joltsim.envs.A1WalkEnv(num_envs=16, num_threads=0, urdf_path=None, max_episode_steps=300)[source]¶
Floating-base 12-DoF Unitree A1 quadruped locomotion environment.
- Parameters:
num_envs (int)
num_threads (int)
urdf_path (str | Path | None)
max_episode_steps (int)
- class joltsim.envs.ClutteredGraspEnv(num_envs=16, num_threads=0, num_clutter=30, urdf_path=None, max_episode_steps=150)[source]¶
Franka Panda + 30 dynamic tabletop clutter objects + target cube.
- Parameters:
num_envs (int)
num_threads (int)
num_clutter (int)
urdf_path (str | Path | None)
max_episode_steps (int)