Better memory setting and reporting, updated example models.

- Memory heuristic rounds up to the nearest MB.
- `simulate` reports total memory currently allocated in the info box.
- All example models use `<size memory/>` rather than legacy attributes.
- Regenerated `example_saved.xml` and reformatted original model in [overview chapter](https://mujoco.readthedocs.io/en/latest/overview.html?#examples).
- `<size>` top-level section does not get written if empty.

PiperOrigin-RevId: 486702670
Change-Id: I0306e335f32344c59562ba606664ec9d2101f8a8
This commit is contained in:
Yuval Tassa
2022-11-07 10:35:50 -08:00
committed by Copybara-Service
parent 9370039015
commit 5004a4c8c5
18 changed files with 107 additions and 101 deletions
+35 -41
View File
@@ -1,44 +1,38 @@
<mujoco model="example"> <mujoco model="example">
<compiler angle="radian" /> <compiler angle="radian" autolimits="true"/>
<size njmax="500" nconmax="100" /> <default class="main">
<default class="main"> <geom rgba="0.8 0.6 0.4 1"/>
<geom size="0" rgba="0.8 0.6 0.4 1" /> </default>
<site size="0" /> <asset>
</default> <texture type="skybox" builtin="gradient" rgb1="1 1 1" rgb2="0.6 0.8 1" width="256" height="1536"/>
<asset> </asset>
<texture type="skybox" builtin="gradient" rgb1="1 1 1" rgb2="0.6 0.8 1" width="256" height="1536" /> <worldbody>
</asset> <light pos="0 1 1" dir="0 -0.707107 -0.707107" diffuse="1 1 1"/>
<worldbody> <body pos="0 0 0.8" gravcomp="0">
<light pos="0 1 1" dir="0 -0.707107 -0.707107" diffuse="1 1 1" /> <joint pos="0 0 0.2" type="ball"/>
<body pos="0 0 0.8"> <geom size="0.06 0.2" type="capsule"/>
<inertial pos="0 0 0" mass="5.20248" diaginertia="0.0964192 0.0964192 0.00936446" /> <body pos="0.15 0 -0.2" quat="0.707107 0 -0.707107 0" gravcomp="0">
<joint pos="0 0 0.2" type="ball" /> <joint pos="0 0 0.15" axis="0 1 0"/>
<geom type="capsule" size="0.06 0.2" /> <joint pos="0 0 0.15" axis="0 0 -1"/>
<body pos="0.15 0 -0.2" quat="0.707107 0 -0.707107 0"> <geom size="0.04 0.15" type="capsule"/>
<inertial pos="0 0 0" mass="1.70903" diaginertia="0.0171472 0.0171472 0.00136722" /> <body pos="0 0 -0.25" quat="0.707107 0 0.707107 0" gravcomp="0">
<joint pos="0 0 0.15" axis="0 1 0" /> <joint pos="-0.1 0 0" axis="0 1 0"/>
<joint pos="0 0 0.15" axis="0 0 -1" /> <joint pos="-0.1 0 0" axis="0 0 1"/>
<geom type="capsule" size="0.04 0.15" /> <geom size="0.1 0.08 0.02" type="ellipsoid"/>
<body pos="0 0 -0.25" quat="0.707107 0 0.707107 0"> <site name="end1" pos="0.1 0 0" size="0.01"/>
<inertial pos="0 0 0" mass="0.670206" diaginertia="0.000911481 0.00139403 0.00219828" />
<joint pos="-0.1 0 0" axis="0 1 0" />
<joint pos="-0.1 0 0" axis="0 0 1" />
<geom type="ellipsoid" size="0.1 0.08 0.02" />
<site name="end1" pos="0.1 0 0" size="0.01" />
</body>
</body>
</body> </body>
<body pos="0.5 0 0.1"> </body>
<inertial pos="0 0 0" mass="3.07876" diaginertia="0.014034 0.014034 0.00754296" /> </body>
<joint type="free" /> <body pos="0.5 0 0.1" gravcomp="0">
<geom type="cylinder" size="0.07 0.1" /> <joint type="free"/>
<site name="end2" pos="0 0 0.1" size="0.01" /> <geom size="0.07 0.1" type="cylinder"/>
</body> <site name="end2" pos="0 0 0.1" size="0.01"/>
</worldbody> </body>
<tendon> </worldbody>
<spatial limited="true" width="0.005" range="0 0.6"> <tendon>
<site site="end1" /> <spatial range="0 0.6" width="0.005">
<site site="end2" /> <site site="end1"/>
</spatial> <site site="end2"/>
</tendon> </spatial>
</tendon>
</mujoco> </mujoco>
+46 -43
View File
@@ -177,14 +177,14 @@ objects and cast shadows, and a floating box with 6 DOFs (this is what the "free
.. code:: xml .. code:: xml
<mujoco> <mujoco>
<worldbody> <worldbody>
<light diffuse=".5 .5 .5" pos="0 0 3" dir="0 0 -1"/> <light diffuse=".5 .5 .5" pos="0 0 3" dir="0 0 -1"/>
<geom type="plane" size="1 1 0.1" rgba=".9 0 0 1"/> <geom type="plane" size="1 1 0.1" rgba=".9 0 0 1"/>
<body pos="0 0 1"> <body pos="0 0 1">
<joint type="free"/> <joint type="free"/>
<geom type="box" size=".1 .2 .3" rgba="0 .9 0 1"/> <geom type="box" size=".1 .2 .3" rgba="0 .9 0 1"/>
</body> </body>
</worldbody> </worldbody>
</mujoco> </mujoco>
The built-in OpenGL visualizer renders this model as: The built-in OpenGL visualizer renders this model as:
@@ -244,43 +244,46 @@ Next we provide a more elaborate example illustrating several features of MJCF.
.. code:: xml .. code:: xml
<mujoco model="example"> <mujoco model="example">
<compiler coordinate="global"/> <compiler coordinate="global"/>
<default>
<geom rgba=".8 .6 .4 1"/> <default>
</default> <geom rgba=".8 .6 .4 1"/>
<asset> </default>
<texture type="skybox" builtin="gradient" rgb1="1 1 1" rgb2=".6 .8 1"
width="256" height="256"/> <asset>
</asset> <texture type="skybox" builtin="gradient" rgb1="1 1 1" rgb2=".6 .8 1" width="256" height="256"/>
<worldbody> </asset>
<light pos="0 1 1" dir="0 -1 -1" diffuse="1 1 1"/>
<worldbody>
<light pos="0 1 1" dir="0 -1 -1" diffuse="1 1 1"/>
<body>
<geom type="capsule" fromto="0 0 1 0 0 0.6" size="0.06"/>
<joint type="ball" pos="0 0 1"/>
<body>
<geom type="capsule" fromto="0 0 0.6 0.3 0 0.6" size="0.04"/>
<joint type="hinge" pos="0 0 0.6" axis="0 1 0"/>
<joint type="hinge" pos="0 0 0.6" axis="1 0 0"/>
<body> <body>
<geom type="capsule" fromto="0 0 1 0 0 0.6" size="0.06"/> <geom type="ellipsoid" pos="0.4 0 0.6" size="0.1 0.08 0.02"/>
<joint type="ball" pos="0 0 1"/> <site name="end1" pos="0.5 0 0.6" type="sphere" size="0.01"/>
<body> <joint type="hinge" pos="0.3 0 0.6" axis="0 1 0"/>
<geom type="capsule" fromto="0 0 0.6 0.3 0 0.6" size="0.04"/> <joint type="hinge" pos="0.3 0 0.6" axis="0 0 1"/>
<joint type="hinge" pos="0 0 0.6" axis="0 1 0"/>
<joint type="hinge" pos="0 0 0.6" axis="1 0 0"/>
<body>
<geom type="ellipsoid" pos="0.4 0 0.6" size="0.1 0.08 0.02"/>
<site name="end1" pos="0.5 0 0.6" type="sphere" size="0.01"/>
<joint type="hinge" pos="0.3 0 0.6" axis="0 1 0"/>
<joint type="hinge" pos="0.3 0 0.6" axis="0 0 1"/>
</body>
</body>
</body> </body>
<body> </body>
<geom type="cylinder" fromto="0.5 0 0.2 0.5 0 0" size="0.07"/> </body>
<site name="end2" pos="0.5 0 0.2" type="sphere" size="0.01"/> <body>
<joint type="free"/> <geom type="cylinder" fromto="0.5 0 0.2 0.5 0 0" size="0.07"/>
</body> <site name="end2" pos="0.5 0 0.2" type="sphere" size="0.01"/>
</worldbody> <joint type="free"/>
<tendon> </body>
<spatial limited="true" range="0 0.6" width="0.005"> </worldbody>
<site site="end1"/>
<site site="end2"/> <tendon>
</spatial> <spatial limited="true" range="0 0.6" width="0.005">
</tendon> <site site="end1"/>
<site site="end2"/>
</spatial>
</tendon>
</mujoco> </mujoco>
.. raw:: html .. raw:: html
+1 -1
View File
@@ -4,7 +4,7 @@
--> -->
<option viscosity="1"/> <option viscosity="1"/>
<size nconmax="500" njmax="1000"/> <size memory="10M"/>
<visual> <visual>
<headlight diffuse=".2 .2 .2"/> <headlight diffuse=".2 .2 .2"/>
+1 -1
View File
@@ -18,7 +18,7 @@
<option timestep="0.002" solver="CG" tolerance="1e-6"/> <option timestep="0.002" solver="CG" tolerance="1e-6"/>
<size nconmax="300" njmax="1000" nstack="1000000"/> <size memory="10M"/>
<worldbody> <worldbody>
+1 -1
View File
@@ -16,7 +16,7 @@
<mujoco model="2D grid with pins"> <mujoco model="2D grid with pins">
<include file="scene.xml"/> <include file="scene.xml"/>
<size nconmax="200" njmax="1000" nstack="1000000"/> <size memory="10M"/>
<worldbody> <worldbody>
<composite type="grid" count="9 9 1" spacing="0.05" offset="0 0 1"> <composite type="grid" count="9 9 1" spacing="0.05" offset="0 0 1">
+1 -1
View File
@@ -18,7 +18,7 @@
<option timestep="0.002" jacobian="dense"/> <option timestep="0.002" jacobian="dense"/>
<size nconmax="100" njmax="300" nstack="50000"/> <size memory="2M"/>
<worldbody> <worldbody>
<body name="B0" pos="0 0 1"> <body name="B0" pos="0 0 1">
+1 -1
View File
@@ -21,7 +21,7 @@
<option solver="CG" tolerance="1e-6" timestep=".01"/> <option solver="CG" tolerance="1e-6" timestep=".01"/>
<size nconmax="6000" njmax="6000" nstack="50000000"/> <size memory="1G"/>
<visual> <visual>
<map stiffness="100"/> <map stiffness="100"/>
+1 -1
View File
@@ -18,7 +18,7 @@
<option timestep="0.002" jacobian="dense"/> <option timestep="0.002" jacobian="dense"/>
<size nconmax="100" njmax="300" nstack="50000"/> <size memory="2M"/>
<worldbody> <worldbody>
<body name="B10" pos="0 0 1"> <body name="B10" pos="0 0 1">
+1 -1
View File
@@ -22,7 +22,7 @@
<option solver="CG" tolerance="1e-6"/> <option solver="CG" tolerance="1e-6"/>
<size nconmax="500" njmax="5000" nstack="5000000"/> <size memory="30M"/>
<worldbody> <worldbody>
<body pos="0 0 1"> <body pos="0 0 1">
+1 -1
View File
@@ -24,7 +24,7 @@
<option timestep="0.005" solver="CG" iterations="30" tolerance="1e-6"/> <option timestep="0.005" solver="CG" iterations="30" tolerance="1e-6"/>
<size njmax="1000" nconmax="100" nstack="1000000"/> <size memory="20M"/>
<visual> <visual>
<map force="0.1" zfar="30"/> <map force="0.1" zfar="30"/>
+1 -1
View File
@@ -16,7 +16,7 @@
<mujoco model="22 Humanoids"> <mujoco model="22 Humanoids">
<option timestep="0.005"/> <option timestep="0.005"/>
<size nconmax="1000" njmax="3000"/> <size memory="100M"/>
<asset> <asset>
<texture type="skybox" builtin="gradient" rgb1=".3 .5 .7" rgb2="0 0 0" width="512" height="512"/> <texture type="skybox" builtin="gradient" rgb1=".3 .5 .7" rgb2="0 0 0" width="512" height="512"/>
+1 -1
View File
@@ -23,7 +23,7 @@
<option timestep="0.005"/> <option timestep="0.005"/>
<size nconmax="500" njmax="1500" nstack="5000000"/> <size memory="100M"/>
<default> <default>
<geom solimp=".9 .9 .01"/> <geom solimp=".9 .9 .01"/>
+2 -2
View File
@@ -27,7 +27,7 @@
<compiler autolimits="true"/> <compiler autolimits="true"/>
<size nconmax="100" njmax="300" nstack="500000"/> <size memory="2M"/>
<worldbody> <worldbody>
<composite type="cable" curve="s" count="41 1 1" size="1" offset="-.3 0 .6" initial="none"> <composite type="cable" curve="s" count="41 1 1" size="1" offset="-.3 0 .6" initial="none">
@@ -53,4 +53,4 @@
<actuator> <actuator>
<motor site="S_last" gear="0 0 0 1 0 0" ctrlrange="-.03 .03"/> <motor site="S_last" gear="0 0 0 1 0 0" ctrlrange="-.03 .03"/>
</actuator> </actuator>
</mujoco> </mujoco>
-2
View File
@@ -16,8 +16,6 @@
<mujoco model="2-link 6-muscle arm"> <mujoco model="2-link 6-muscle arm">
<option timestep="0.005" iterations="50" solver="Newton" tolerance="1e-10"/> <option timestep="0.005" iterations="50" solver="Newton" tolerance="1e-10"/>
<size njmax="50" nconmax="10" nstack="200"/>
<visual> <visual>
<rgba haze=".3 .3 .3 1"/> <rgba haze=".3 .3 .3 1"/>
</visual> </visual>
+4 -2
View File
@@ -29,6 +29,7 @@
#include <mujoco/mjtnum.h> #include <mujoco/mjtnum.h>
#include <mujoco/mjvisualize.h> #include <mujoco/mjvisualize.h>
#include <mujoco/mjxmacro.h> #include <mujoco/mjxmacro.h>
#include <mujoco/mujoco.h>
#include "glfw_dispatch.h" #include "glfw_dispatch.h"
#include "uitools.h" #include "uitools.h"
#include "array_safety.h" #include "array_safety.h"
@@ -478,7 +479,7 @@ void infotext(mj::Simulate* sim,
// prepare info text // prepare info text
mju::strcpy_arr(title, "Time\nSize\nCPU\nSolver \nFPS\nMemory"); mju::strcpy_arr(title, "Time\nSize\nCPU\nSolver \nFPS\nMemory");
mju::sprintf_arr(content, mju::sprintf_arr(content,
"%-9.3f\n%d (%d con)\n%.3f\n%.1f (%d it)\n%.0f\n%.3f", "%-9.3f\n%d (%d con)\n%.3f\n%.1f (%d it)\n%.0f\n%.2g of %s",
d->time, d->time,
d->nefc, d->ncon, d->nefc, d->ncon,
sim->run ? sim->run ?
@@ -486,7 +487,8 @@ void infotext(mj::Simulate* sim,
d->timer[mjTIMER_FORWARD].duration / mjMAX(1, d->timer[mjTIMER_FORWARD].number), d->timer[mjTIMER_FORWARD].duration / mjMAX(1, d->timer[mjTIMER_FORWARD].number),
solerr, d->solver_iter, solerr, d->solver_iter,
1/interval, 1/interval,
d->maxuse_arena/(double)(d->nstack * sizeof(mjtNum))); d->maxuse_arena/(double)(d->nstack * sizeof(mjtNum)),
mju_writeNumBytes(d->nstack * sizeof(mjtNum)));
// add Energy if enabled // add Energy if enabled
{ {
+6
View File
@@ -2689,6 +2689,12 @@ void mjCModel::TryCompile(mjModel*& m, mjData*& d, const mjVFS* vfs) {
njmax * m->nv * (2 * sizeof(int) + 2 * sizeof(mjtNum)) + njmax * m->nv * (2 * sizeof(int) + 2 * sizeof(mjtNum)) +
njmax * njmax * (sizeof(int) + sizeof(mjtNum))); njmax * njmax * (sizeof(int) + sizeof(mjtNum)));
m->nstack += (arena_bytes / sizeof(mjtNum)) + (arena_bytes % sizeof(mjtNum) ? 1 : 0); m->nstack += (arena_bytes / sizeof(mjtNum)) + (arena_bytes % sizeof(mjtNum) ? 1 : 0);
// round up to the nearest megabyte
constexpr int kMegabyte = (1 << 20) / sizeof(mjtNum); // number of mjtNum's in 1 Mb
int nstack_mb = m->nstack / kMegabyte;
int residual_mb = m->nstack % kMegabyte ? 1 : 0;
m->nstack = kMegabyte * (nstack_mb + residual_mb);
} }
// create data // create data
+3
View File
@@ -847,6 +847,9 @@ void mjXWriter::Size(XMLElement* root) {
WriteAttrInt(section, "nuser_tendon", model->nuser_tendon, 0); WriteAttrInt(section, "nuser_tendon", model->nuser_tendon, 0);
WriteAttrInt(section, "nuser_actuator", model->nuser_actuator, 0); WriteAttrInt(section, "nuser_actuator", model->nuser_actuator, 0);
WriteAttrInt(section, "nuser_sensor", model->nuser_sensor, 0); WriteAttrInt(section, "nuser_sensor", model->nuser_sensor, 0);
// remove entire section if no attributes
if (!section->FirstAttribute()) root->DeleteChild(section);
} }
+1 -1
View File
@@ -9,7 +9,7 @@
<map force="0.1"/> <map force="0.1"/>
</visual> </visual>
<size njmax="3000" nconmax="1000"/> <size memory="100M"/>
<asset> <asset>
<mesh name="box" vertex="-1 -1 -1 1 -1 -1 1 1 -1 1 1 1 1 -1 1 -1 1 -1 -1 1 1 -1 -1 1" <mesh name="box" vertex="-1 -1 -1 1 -1 -1 1 1 -1 1 1 1 1 -1 1 -1 1 -1 -1 1 1 -1 -1 1"