1+ # Copyright 2025 The Physics-Next Project Developers
2+ #
3+ # Licensed under the Apache License, Version 2.0 (the "License");
4+ # you may not use this file except in compliance with the License.
5+ # You may obtain a copy of the License at
6+ #
7+ # http://www.apache.org/licenses/LICENSE-2.0
8+ #
9+ # Unless required by applicable law or agreed to in writing, software
10+ # distributed under the License is distributed on an "AS IS" BASIS,
11+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ # See the License for the specific language governing permissions and
13+ # limitations under the License.
14+ # ==============================================================================
15+
116"""Tests for forward dynamics functions."""
217
318from absl .testing import absltest
1429
1530def _assert_eq (a , b , name ):
1631 tol = _TOLERANCE * 10 # avoid test noise
17- err_msg = f' mismatch: { name } '
32+ err_msg = f" mismatch: { name } "
1833 np .testing .assert_allclose (a , b , err_msg = err_msg , atol = tol , rtol = tol )
1934
2035
2136class ForwardTest (absltest .TestCase ):
22-
2337 def _load (self , fname : str , is_sparse : bool = True ):
24- path = epath .resource_path (' mujoco.mjx' ) / ' test_data' / fname
38+ path = epath .resource_path (" mujoco.mjx" ) / " test_data" / fname
2539 mjm = mujoco .MjModel .from_xml_path (path .as_posix ())
2640 mjm .opt .jacobian = is_sparse
2741 mjd = mujoco .MjData (mjm )
@@ -34,28 +48,30 @@ def _load(self, fname: str, is_sparse: bool = True):
3448
3549 def test_fwd_velocity (self ):
3650 """Tests MJX fwd_velocity."""
37- _ , mjd , m , d = self ._load (' humanoid/humanoid.xml' )
38-
51+ _ , mjd , m , d = self ._load (" humanoid/humanoid.xml" )
52+
3953 d .actuator_velocity .zero_ ()
4054 mjx .fwd_velocity (m , d )
4155
42- _assert_eq (d .actuator_velocity .numpy ()[0 ], mjd .actuator_velocity , 'actuator_velocity' )
43- _assert_eq (d .qfrc_bias .numpy ()[0 ], mjd .qfrc_bias , 'qfrc_bias' )
56+ _assert_eq (
57+ d .actuator_velocity .numpy ()[0 ], mjd .actuator_velocity , "actuator_velocity"
58+ )
59+ _assert_eq (d .qfrc_bias .numpy ()[0 ], mjd .qfrc_bias , "qfrc_bias" )
4460
4561 def test_fwd_acceleration (self ):
4662 """Tests MJX fwd_acceleration."""
47- _ , mjd , m , d = self ._load (' humanoid/humanoid.xml' , is_sparse = False )
63+ _ , mjd , m , d = self ._load (" humanoid/humanoid.xml" , is_sparse = False )
4864
4965 for arr in (d .qfrc_smooth , d .qacc_smooth ):
5066 arr .zero_ ()
5167
52- mjx .factor_m (m , d ) # for dense, get tile cholesky factorization
68+ mjx .factor_m (m , d ) # for dense, get tile cholesky factorization
5369 mjx .fwd_acceleration (m , d )
5470
55- _assert_eq (d .qfrc_smooth .numpy ()[0 ], mjd .qfrc_smooth , ' qfrc_smooth' )
56- _assert_eq (d .qacc_smooth .numpy ()[0 ], mjd .qacc_smooth , ' qacc_smooth' )
71+ _assert_eq (d .qfrc_smooth .numpy ()[0 ], mjd .qfrc_smooth , " qfrc_smooth" )
72+ _assert_eq (d .qacc_smooth .numpy ()[0 ], mjd .qacc_smooth , " qacc_smooth" )
5773
5874
59- if __name__ == ' __main__' :
75+ if __name__ == " __main__" :
6076 wp .init ()
6177 absltest .main ()
0 commit comments