recording
Record kinematic trajectories on the GPU and render them with MJWarp batch rendering.
See flygym.recording for an overview. Trajectories recorded here are ordinary
flygym.recording.RecordedTrajectory objects and can be rendered on either backend.
WarpTrajectoryRecorder
¶
Records the kinematic state of selected worlds of a GPU simulation.
The GPU counterpart of flygym.recording.TrajectoryRecorder. Usually created via
GPUSimulation.set_trajectory_recorder. At each frame, the state of all worlds is
copied to host memory, and the selected worlds are kept.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mj_model
|
MjModel
|
Compiled MuJoCo model. |
required |
n_worlds
|
int
|
Total number of parallel worlds in the simulation. |
required |
worlds
|
list[int] | None
|
Indices of the worlds to record. Defaults to all worlds. |
None
|
playback_speed
|
float
|
Video playback speed relative to real time. |
0.2
|
output_fps
|
int
|
Output video frame rate. |
25
|
Source code in src/flygym/warp/recording.py
trajectories
property
¶
The trajectories recorded so far, one per selected world.
record_as_needed(mjw_data)
¶
Record the current state of the selected worlds if a frame is due.
Returns:
| Type | Description |
|---|---|
bool
|
True if a frame was recorded, False otherwise. |
Source code in src/flygym/warp/recording.py
reset()
¶
Discard recorded frames and reset the frame clock.
Source code in src/flygym/warp/recording.py
render_trajectories_gpu(mj_model, trajectories, cameras, output_path=None, *, camera_res=(240, 320), worlds_per_batch=32)
¶
Render recorded trajectories using MJWarp's GPU batch rendering.
The GPU counterpart of flygym.recording.render_trajectories. All frames of all
trajectories are rendered in batches of worlds_per_batch parallel worlds, so the
batch size is independent of how many worlds were simulated.
mj_model must be compatible with GPU batch rendering, i.e., compiled from a world
modified by flygym.warp.rendering.modify_world_for_batch_rendering. The model of
a GPUSimulation with a renderer set up with use_gpu_batch_rendering=True already
satisfies this.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mj_model
|
MjModel
|
Compiled, batch-rendering-compatible model with the same |
required |
trajectories
|
RecordedTrajectory | list[RecordedTrajectory]
|
One trajectory or a list of them. |
required |
cameras
|
str | MjsCamera | list[str | MjsCamera]
|
Camera(s) to render. |
required |
output_path
|
PathLike | None
|
If given, also save the frames as videos (see
|
None
|
camera_res
|
tuple[int, int]
|
|
(240, 320)
|
worlds_per_batch
|
int
|
Number of frames rendered in parallel. Larger values are faster but use more GPU memory. |
32
|
Returns:
| Type | Description |
|---|---|
list[dict[str, ndarray]]
|
A list, parallel to |
list[dict[str, ndarray]]
|
|
Source code in src/flygym/warp/recording.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | |