38f0ff3caa
Support named CLI flags, physics overrides, and refactor global state. - **Named CLI Flags**: Replaced standard positional arguments with named flags (`--nstep`, `--nthread`, `--noisestd`, `--noiserate`, `--npoolthread`) and preserved Google-wide flags compatibility (via custom argv compacting and InitGoogle). - **Physics Option Overrides**: Added support for configuring loaded model settings directly from the command line (`--solver`, `--cone`, `--jacobian`, `--integrator`, `--iterations`, `--tolerance`, `--sleep_tolerance`, `--noslip_iterations`). - **Encapsulated Thread State**: Consolidated loose global variables and per-thread rollout statistics arrays into a single data structure, `RolloutRunner runner`, simplifying mutli-threaded data boundaries. - **Readable Physics Options Printing**: Logged configured non-default options dynamically prior to rollout. Enums and active bitmask flags (e.g. disableflags/enableflags) are decoded into friendly strings (e.g., `Sleep : Enabled`). - **Tests & Docs**: Added testspeed_test.sh running testspeed over dominos.xml to check all overrides, registered shell test target in BUILD and CMakeLists.txt, and updated samples.rst documentation. PiperOrigin-RevId: 942285912 Change-Id: Idb966fadfa0ccba0f1862f9d62bf83458b61939a
73 lines
3.3 KiB
Bash
Executable File
73 lines
3.3 KiB
Bash
Executable File
#!/bin/bash
|
|
# Copyright 2026 DeepMind Technologies Limited
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
MODEL="${CMAKE_SOURCE_DIR}/model/sleep/dominos.xml"
|
|
|
|
die() { echo "$*" 1>&2 ; exit 1; }
|
|
|
|
if [ -z "$TARGET_BINARY" ]; then
|
|
die "Expecting environment variable TARGET_BINARY."
|
|
fi
|
|
|
|
if [ -z "$MUJOCO_DLL_DIR" ]; then
|
|
# Extend PATH to include the directory containing the mujoco DLL.
|
|
# This is needed on Windows.
|
|
PATH=$PATH:$MUJOCO_DLL_DIR
|
|
fi
|
|
|
|
# Run testspeed with override flags and verify they get applied
|
|
echo "Running testspeed with command-line overrides on dominos.xml..."
|
|
echo "Command: $TARGET_BINARY --nstep=10 --nthread=1 --noisestd=0.02 --noiserate=0.2 --solver=PGS --jacobian=sparse --integrator=rk4 --iterations=12 --tolerance=1e-7 --sleep_tolerance=2e-4 --noslip_iterations=5 $MODEL"
|
|
|
|
OUTPUT=$("$TARGET_BINARY" --nstep=10 --nthread=1 --noisestd=0.02 --noiserate=0.2 --solver=PGS --jacobian=sparse --integrator=rk4 --iterations=12 --tolerance=1e-7 --sleep_tolerance=2e-4 --noslip_iterations=5 "$MODEL") || die "testspeed failed"
|
|
|
|
# Verify option printing works.
|
|
# Dominos.xml has:
|
|
# cone="elliptic" -> cone: Elliptic
|
|
# impratio="10" -> impratio: 10
|
|
# <flag sleep="enable"/> -> Sleep: Enabled
|
|
#
|
|
# Overridden via command line options:
|
|
# solver=PGS
|
|
# jacobian=sparse -> jacobian: Sparse
|
|
# integrator=rk4 -> integrator: RK4
|
|
# iterations=12
|
|
# tolerance=1e-7 -> tolerance: 1e-07
|
|
# sleep_tolerance=2e-4 (overwrites XML's 3e-4) -> sleep_tolerance: 0.0002
|
|
# noslip_iterations=5
|
|
|
|
echo "Full testspeed Output:"
|
|
echo "--------------------------------------------------------"
|
|
echo "$OUTPUT"
|
|
echo "--------------------------------------------------------"
|
|
|
|
echo "Verifying printed non-default option block:"
|
|
echo "$OUTPUT" | grep -A 10 "Physics options (non-default):" || die "Missing physics options block!"
|
|
echo "--------------------------------------------------------"
|
|
|
|
echo "$OUTPUT" | grep -F "Physics options (non-default):" || die "Missing non-default header"
|
|
echo "$OUTPUT" | grep -F " cone : Elliptic" || die "Missing cone print"
|
|
echo "$OUTPUT" | grep -F " impratio : 10" || die "Missing impratio print"
|
|
echo "$OUTPUT" | grep -E " sleep_tolerance : (0.0002|2e-0?4)" || die "Missing sleep_tolerance print"
|
|
echo "$OUTPUT" | grep -F " Sleep : Enabled" || die "Missing Sleep print"
|
|
echo "$OUTPUT" | grep -F " solver : PGS" || die "Missing solver print"
|
|
echo "$OUTPUT" | grep -F " jacobian : Sparse" || die "Missing jacobian print"
|
|
echo "$OUTPUT" | grep -F " integrator : RK4" || die "Missing integrator print"
|
|
echo "$OUTPUT" | grep -F " iterations : 12" || die "Missing iterations print"
|
|
echo "$OUTPUT" | grep -E " tolerance : (1e-0?7|0.0000001|1e-7)" || die "Missing tolerance print"
|
|
echo "$OUTPUT" | grep -F " noslip_iterations : 5" || die "Missing noslip_iterations print"
|
|
|
|
echo "PASS"
|