Add to_file function to save the Spec to a file.
Fixes #2415. PiperOrigin-RevId: 725161617 Change-Id: I6c374cc7f7cb3f1da1cc0da531dd7e5be5d62b6a
This commit is contained in:
committed by
Copybara-Service
parent
0e01b51590
commit
4156350708
@@ -518,6 +518,12 @@ PYBIND11_MODULE(_specs, m) {
|
|||||||
}
|
}
|
||||||
return std::string(buf.get());
|
return std::string(buf.get());
|
||||||
});
|
});
|
||||||
|
mjSpec.def("to_file", [](MjSpec& self, std::string& file) {
|
||||||
|
std::array<char, 1024> err;
|
||||||
|
if (mj_saveXML(self.ptr, file.c_str(), err.data(), err.size()) < 0) {
|
||||||
|
throw FatalError(std::string(err.data()));
|
||||||
|
}
|
||||||
|
});
|
||||||
mjSpec.def(
|
mjSpec.def(
|
||||||
"add_default",
|
"add_default",
|
||||||
[](MjSpec* spec, std::string& classname,
|
[](MjSpec* spec, std::string& classname,
|
||||||
|
|||||||
@@ -113,9 +113,7 @@ class SpecsTest(absltest.TestCase):
|
|||||||
self.assertEqual(model.nuser_site, 6)
|
self.assertEqual(model.nuser_site, 6)
|
||||||
np.testing.assert_array_equal(model.site_user[0], [1, 2, 3, 4, 5, 6])
|
np.testing.assert_array_equal(model.site_user[0], [1, 2, 3, 4, 5, 6])
|
||||||
|
|
||||||
self.assertEqual(
|
xml = textwrap.dedent("""\
|
||||||
spec.to_xml(),
|
|
||||||
textwrap.dedent("""\
|
|
||||||
<mujoco model="MuJoCo Model">
|
<mujoco model="MuJoCo Model">
|
||||||
<compiler angle="radian"/>
|
<compiler angle="radian"/>
|
||||||
|
|
||||||
@@ -127,8 +125,8 @@ class SpecsTest(absltest.TestCase):
|
|||||||
</body>
|
</body>
|
||||||
</worldbody>
|
</worldbody>
|
||||||
</mujoco>
|
</mujoco>
|
||||||
"""),
|
""")
|
||||||
)
|
self.assertEqual(spec.to_xml(), xml)
|
||||||
|
|
||||||
def test_kwarg(self):
|
def test_kwarg(self):
|
||||||
# Create a spec.
|
# Create a spec.
|
||||||
|
|||||||
Reference in New Issue
Block a user