Rename spec to sig in state-related API functions.

(to avoid confusion with mjSpec)

PiperOrigin-RevId: 795848898
Change-Id: I0b64eb85f5c7a3ee889a746c751d9f5561650277
This commit is contained in:
Yuval Tassa
2025-08-16 08:37:41 -07:00
committed by Copybara-Service
parent 5a24eb2d34
commit 1447711037
11 changed files with 77 additions and 77 deletions
+13 -13
View File
@@ -768,36 +768,36 @@ class MuJoCoBindingsTest(parameterized.TestCase):
def test_getsetstate(self): # pylint: disable=invalid-name
mujoco.mj_step(self.model, self.data)
# Test for invalid state spec
invalid_spec = 2**mujoco.mjtState.mjNSTATE.value
# Test for invalid state signature
invalid_sig = 2**mujoco.mjtState.mjNSTATE.value
expected_message = (
f'mj_stateSize: invalid state spec {invalid_spec} >= 2^mjNSTATE'
f'mj_stateSize: invalid state signature {invalid_sig} >= 2^mjNSTATE'
)
with self.assertRaisesWithLiteralMatch(mujoco.FatalError, expected_message):
mujoco.mj_stateSize(self.model, invalid_spec)
mujoco.mj_stateSize(self.model, invalid_sig)
spec = mujoco.mjtState.mjSTATE_INTEGRATION
size = mujoco.mj_stateSize(self.model, spec)
sig = mujoco.mjtState.mjSTATE_INTEGRATION
size = mujoco.mj_stateSize(self.model, sig)
state_bad_size = np.empty(size + 1, np.float64)
expected_message = 'state size should equal mj_stateSize(m, spec)'
expected_message = 'state size should equal mj_stateSize(m, sig)'
with self.assertRaisesWithLiteralMatch(TypeError, expected_message):
mujoco.mj_getState(self.model, self.data, state_bad_size, spec)
mujoco.mj_getState(self.model, self.data, state_bad_size, sig)
# Get initial state.
state0 = np.empty(size, np.float64)
mujoco.mj_getState(self.model, self.data, state0, spec)
mujoco.mj_getState(self.model, self.data, state0, sig)
# Step, get next state.
mujoco.mj_step(self.model, self.data)
state1a = np.empty(size, np.float64)
mujoco.mj_getState(self.model, self.data, state1a, spec)
mujoco.mj_getState(self.model, self.data, state1a, sig)
# Reset to initial state, step again, get state again.
mujoco.mj_setState(self.model, self.data, state0, spec)
mujoco.mj_setState(self.model, self.data, state0, sig)
mujoco.mj_step(self.model, self.data)
state1b = np.empty(size, np.float64)
mujoco.mj_getState(self.model, self.data, state1b, spec)
mujoco.mj_getState(self.model, self.data, state1b, sig)
# Expect next states to be equal.
np.testing.assert_array_equal(state1a, state1b)
@@ -805,7 +805,7 @@ class MuJoCoBindingsTest(parameterized.TestCase):
def test_mj_setKeyframe(self): # pylint: disable=invalid-name
mujoco.mj_step(self.model, self.data)
# Test for invalid state spec
# Test for invalid keyframe
invalid_key = 2
expected_message = (
f'mj_setKeyframe: index must be smaller than {invalid_key} (keyframes'
+8 -8
View File
@@ -292,20 +292,20 @@ PYBIND11_MODULE(_functions, pymodule) {
Def<traits::mj_getState>(
pymodule,
[](const raw::MjModel* m, const raw::MjData* d,
Eigen::Ref<EigenVectorX> state, unsigned int spec) {
if (state.size() != mj_stateSize(m, spec)) {
throw py::type_error("state size should equal mj_stateSize(m, spec)");
Eigen::Ref<EigenVectorX> state, unsigned int sig) {
if (state.size() != mj_stateSize(m, sig)) {
throw py::type_error("state size should equal mj_stateSize(m, sig)");
}
return InterceptMjErrors(::mj_getState)(m, d, state.data(), spec);
return InterceptMjErrors(::mj_getState)(m, d, state.data(), sig);
});
Def<traits::mj_setState>(
pymodule,
[](const raw::MjModel* m, raw::MjData* d,
const Eigen::Ref<EigenVectorX> state, unsigned int spec) {
if (state.size() != mj_stateSize(m, spec)) {
throw py::type_error("state size should equal mj_stateSize(m, spec)");
const Eigen::Ref<EigenVectorX> state, unsigned int sig) {
if (state.size() != mj_stateSize(m, sig)) {
throw py::type_error("state size should equal mj_stateSize(m, sig)");
}
return InterceptMjErrors(::mj_setState)(m, d, state.data(), spec);
return InterceptMjErrors(::mj_setState)(m, d, state.data(), sig);
});
Def<traits::mj_setKeyframe>(pymodule);
Def<traits::mj_addContact>(pymodule);
+4 -4
View File
@@ -2226,11 +2226,11 @@ FUNCTIONS: Mapping[str, FunctionDecl] = dict([
),
),
FunctionParameterDecl(
name='spec',
name='sig',
type=ValueType(name='unsigned int'),
),
),
doc='Return size of state specification.',
doc='Return size of state signature.',
)),
('mj_getState',
FunctionDecl(
@@ -2256,7 +2256,7 @@ FUNCTIONS: Mapping[str, FunctionDecl] = dict([
),
),
FunctionParameterDecl(
name='spec',
name='sig',
type=ValueType(name='unsigned int'),
),
),
@@ -2286,7 +2286,7 @@ FUNCTIONS: Mapping[str, FunctionDecl] = dict([
),
),
FunctionParameterDecl(
name='spec',
name='sig',
type=ValueType(name='unsigned int'),
),
),