musculoskeletal
Experimental
Support for the FlyMimic musculoskeletal body model is
experimental. The API may change in future releases, and only
the left-front leg is muscle-driven in the current model. Not all
features available for the default NeuroMechFly model are
currently supported (e.g. per-leg ground-contact sensors).
Musculoskeletal (FlyMimic) body model as a FlyGym composition element.
Unlike NeuroMechFly and FlyBody, which compose a body from meshes and YAML
rigging configs via BaseFly, the musculoskeletal model is a pre-authored
self-contained MJCF: FlyMimic's muscle-driven fly ships its own floor, lighting,
15 left-front-leg Hill-type muscles, 15 spatial tendons, and passive joint
properties. Rather than overlaying muscles onto FlyGym's composed body, the
musculoskeletal path switches the body model: it loads that MJCF into a
mujoco.MjSpec (FlyGym's model-editing backend since the v2.1.0 PyMJCF ->
MjSpec migration) and wraps it so that flygym.Simulation and its sensor suite
work unchanged.
MusculoskeletalFly therefore subclasses BaseCompositionElement directly
(not BaseFly) but exposes the same dicts/accessors Simulation reads, keyed
by the model's own MJCF element-name strings (e.g. "LFFemur",
"joint_LFCoxa_yaw", "LFTibia_flex_93434"), since FlyMimic's body
topology does not line up 1:1 with FlyGym's BodySegment names:
bodyseg_to_mjcfbody,bodyseg_to_mjcfgeomjointdof_to_mjcfjoint,jointdof_to_mjcfactuator_by_typeleg_to_adhesionactuator,anatomicaljoint_to_mjcfsiteseyecameraname_to_mjcfcameraplus theget_*_orderaccessors.
Pair it with MusculoskeletalWorld (see flygym.compose.world), or use
build_musculoskeletal_simulation (defined below) for the common case.
build_musculoskeletal_simulation returns a plain flygym.Simulation (CPU,
single world) — not flygym.warp.GPUSimulation. Guarded GPU/MuJoCo-Warp
helpers (check_mjwarp_compatibility, build_musculoskeletal_gpu_simulation)
live here too — they lazily import mujoco_warp so they are safe to import
on machines without a GPU, and require the [warp] extra to actually run.
DEFAULT_MUSCULOSKELETAL_XML = MUSCULOSKELETAL_MODEL_DIR / 'best_combined_arm_damping_stiff_cvt3.xml'
module-attribute
¶
FlyMimic's muscle-driven fly with passive joint stiffness + spring refs.
This is the arm_damping_stiff variant: 15 left-front-leg muscles and body
geometry, plus biologically-motivated passive joint stiffness (0.4) and
per-joint spring reference angles.
DEFAULT_SCENE_CAMERA = 'scene'
module-attribute
¶
Name assigned to FlyMimic's (otherwise unnamed) world camera so it can be
selected for rendering via Simulation.set_renderer — e.g. when recording a
rollout video of a trained policy.
MUSCULOSKELETAL_MODEL_DIR = assets_dir / 'model/musculoskeletal'
module-attribute
¶
Directory holding FlyMimic's musculoskeletal MJCF. The body meshes it
references are not bundled here (see MUSCULOSKELETAL_MESH_DIR), and the
imitation-learning mocap clips live with the demo, in
flygym_demo.muscle_imitation.
MjWarpCompatibilityReport
dataclass
¶
Outcome of probing whether MuJoCo-Warp accepts the muscle model.
Attributes:
| Name | Type | Description |
|---|---|---|
mjwarp_available |
bool
|
Whether |
put_model_ok |
bool | None
|
Whether |
error |
str | None
|
The exception text if |
message |
str
|
A human-readable summary. |
Source code in src/flygym/compose/fly/musculoskeletal.py
MusculoskeletalFly
¶
Bases: BaseCompositionElement
FlyGym-compatible wrapper around FlyMimic's musculoskeletal MJCF.
The musculoskeletal body model is published in:
Ozdil, P. G., et al. (2026). Musculoskeletal simulation of limb
movement biomechanics in *Drosophila melanogaster*. *ICLR 2026*.
https://arxiv.org/abs/2509.06426
Source code for the original model: https://github.com/gizemozd/FlyMimic
Plain flygym — not GPU-accelerated
MusculoskeletalFly works with plain flygym.Simulation (CPU,
single world). It does not require flygym.warp.
Unlike NeuroMechFly and FlyBody, which compose a body from meshes
and YAML rigging configs via BaseFly, this class loads FlyMimic's
pre-authored self-contained MJCF and wraps it so that Simulation and
its sensor suite work unchanged. Dict keys on all tracking attributes
are the model's own MJCF element-name strings (e.g. "LFFemur",
"joint_LFCoxa_yaw").
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xml_path
|
PathLike
|
Path to the FlyMimic MJCF. Defaults to the bundled
|
DEFAULT_MUSCULOSKELETAL_XML
|
name
|
str
|
Logical fly name used by |
'nmf'
|
Attributes:
| Name | Type | Description |
|---|---|---|
bodyseg_to_mjcfbody |
dict[str, MjsBody]
|
Maps body-segment name → MJCF body element. |
bodyseg_to_mjcfgeom |
dict[str, list[MjsGeom]]
|
Maps body-segment name → list of MJCF geom elements (one entry per geom on that body). |
jointdof_to_mjcfjoint |
dict[str, MjsJoint]
|
Maps joint-DoF name → MJCF joint element. |
jointdof_to_mjcfactuator_by_type |
Maps |
|
leg_to_adhesionactuator |
dict[str, MjsActuator]
|
Always empty (FlyMimic has no adhesion). |
anatomicaljoint_to_mjcfsites |
dict[str, MjsSite]
|
Always empty. |
eyecameraname_to_mjcfcamera |
dict[str, MjsCamera]
|
Camera elements added via |
cameraname_to_mjcfcamera |
dict[str, MjsCamera]
|
All scene cameras, including the world
camera named |
muscle_names |
list[str]
|
Names of the 15 Hill-type muscle actuators, in MJCF order (read-only property). |
Source code in src/flygym/compose/fly/musculoskeletal.py
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 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 | |
muscle_names
property
¶
Names of the muscle actuators, in MJCF order.
add_vision(*, fovy=145.0, draw_sensor_markers=False)
¶
Attach left/right eye cameras to the model's eye bodies.
Enables Simulation.get_raw_vision / get_ommatidia_readouts. Note
that FlyGym's fisheye Retina is calibrated for FlyGym's own eye
placement, so ommatidia readouts on this body are approximate.
Source code in src/flygym/compose/fly/musculoskeletal.py
get_actuated_jointdofs_order(actuator_type)
¶
Return actuator names of the given type, in MJCF order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
actuator_type
|
ActuatorType | str
|
An |
required |
Source code in src/flygym/compose/fly/musculoskeletal.py
get_bodysegs_order()
¶
get_jointdofs_order()
¶
get_legs_order()
¶
get_sites_order()
¶
build_musculoskeletal_gpu_simulation(n_worlds, *, xml_path=DEFAULT_MUSCULOSKELETAL_XML, name='nmf', add_vision=False, **gpu_kwargs)
¶
Build a GPUSimulation of the muscle model with n_worlds parallel
copies for vectorized RL on a CUDA machine.
Call check_mjwarp_compatibility first to verify that the installed
mujoco_warp version supports the muscle model's Hill-type actuators,
spatial tendons, and joint-equality constraints.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_worlds
|
int
|
Number of parallel simulation worlds. |
required |
xml_path
|
PathLike
|
Path to the FlyMimic MJCF. Defaults to
|
DEFAULT_MUSCULOSKELETAL_XML
|
name
|
str
|
Logical fly name. Defaults to |
'nmf'
|
add_vision
|
bool
|
Attach eye cameras (approximate; see
|
False
|
**gpu_kwargs
|
Any
|
Forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
GPUSimulation
|
|
MusculoskeletalFly
|
|
Raises:
| Type | Description |
|---|---|
ImportError
|
If the |
Source code in src/flygym/compose/fly/musculoskeletal.py
build_musculoskeletal_simulation(*, xml_path=DEFAULT_MUSCULOSKELETAL_XML, name='nmf', add_vision=False)
¶
Build a MusculoskeletalFly + MusculoskeletalWorld + Simulation.
Equivalent to the standard composition flow::
fly = MusculoskeletalFly(xml_path, name=name)
world = MusculoskeletalWorld(fly)
sim = Simulation(world)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xml_path
|
PathLike
|
Path to the FlyMimic MJCF. Defaults to
|
DEFAULT_MUSCULOSKELETAL_XML
|
name
|
str
|
Logical fly name. Defaults to |
'nmf'
|
add_vision
|
bool
|
If True, attach left/right eye cameras so
|
False
|
Plain flygym — not GPU-accelerated
Returns a plain flygym.Simulation (CPU, single world). For the
GPU path use build_musculoskeletal_gpu_simulation with the
[warp] extra.
Returns:
| Type | Description |
|---|---|
Simulation
|
|
MusculoskeletalFly
|
and fly is the |
tuple[Simulation, MusculoskeletalFly]
|
inspecting |
Source code in src/flygym/compose/fly/musculoskeletal.py
check_mjwarp_compatibility(fly=None, *, xml_path=DEFAULT_MUSCULOSKELETAL_XML)
¶
Probe whether MuJoCo-Warp can ingest the muscle model.
Safe to call anywhere: if mujoco_warp is not installed (the usual case
off a CUDA machine), it returns a report with mjwarp_available=False
rather than raising.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fly
|
MusculoskeletalFly | None
|
A |
None
|
xml_path
|
PathLike
|
XML to use when |
DEFAULT_MUSCULOSKELETAL_XML
|
Returns:
| Type | Description |
|---|---|
MjWarpCompatibilityReport
|
A |