diffneusim 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- diffneusim/__init__.py +1 -0
- diffneusim/_cache.py +42 -0
- diffneusim/_paths.py +5 -0
- diffneusim/bindings/rew14_ext.cu +115 -0
- diffneusim/bindings/soft14_capi.cpp +443 -0
- diffneusim/bindings/soft14_engine_ext.cu +596 -0
- diffneusim/bindings/soft_capi.cpp +782 -0
- diffneusim/bindings/soft_engine_ext.cu +495 -0
- diffneusim/core/cpu_engine/build.sh +40 -0
- diffneusim/core/cpu_engine/fiber/cuda_runtime.h +445 -0
- diffneusim/core/cpu_engine/x14_cpu.cpp +283 -0
- diffneusim/core/diff/dual.h +126 -0
- diffneusim/core/include/diffneusim/macros.h +35 -0
- diffneusim/core/kin/kinematic_tree.h +273 -0
- diffneusim/core/math/so3.h +182 -0
- diffneusim/core/soft/adj/out_adj.h +102 -0
- diffneusim/core/soft/adj/rnea_adj.h +425 -0
- diffneusim/core/soft/adj/rows_adj.h +439 -0
- diffneusim/core/soft/adj/rows_functor.h +89 -0
- diffneusim/core/soft/adj/rows_lanes.h +443 -0
- diffneusim/core/soft/adj/shell_adj.h +243 -0
- diffneusim/core/soft/adj/tree_adj.h +356 -0
- diffneusim/core/soft/collide.h +183 -0
- diffneusim/core/soft/gpu/adj14.cuh +233 -0
- diffneusim/core/soft/gpu/adj14_mus.cuh +98 -0
- diffneusim/core/soft/gpu/adj_shell.cuh +50 -0
- diffneusim/core/soft/gpu/adj_tab.cuh +49 -0
- diffneusim/core/soft/gpu/body14.cuh +47 -0
- diffneusim/core/soft/gpu/chol_rn.cuh +458 -0
- diffneusim/core/soft/gpu/chol_small.cuh +123 -0
- diffneusim/core/soft/gpu/chol_split.cuh +193 -0
- diffneusim/core/soft/gpu/engine_launch.cuh +263 -0
- diffneusim/core/soft/gpu/fk_rn.cuh +109 -0
- diffneusim/core/soft/gpu/generated/body_019e20820f86_mmfloor.cuh +28 -0
- diffneusim/core/soft/gpu/generated/body_62f77a4bb16b_mmfloor.cuh +52 -0
- diffneusim/core/soft/gpu/generated/body_77dbb7213f26_mmfloor_rampsb3l_n6t12.cuh +28 -0
- diffneusim/core/soft/gpu/generated/body_8989b60e4486_mmfloor_rampsb3l_n6t12.cuh +28 -0
- diffneusim/core/soft/gpu/generated/body_8989b60e4486_mmfloor_rhlsd05_n6t12.cuh +28 -0
- diffneusim/core/soft/gpu/generated/body_8989b60e4486_mmfloor_rhlsdef_n6t12.cuh +28 -0
- diffneusim/core/soft/gpu/generated/body_8989b60e4486_mmfloor_rhlsmjd_n6t12.cuh +28 -0
- diffneusim/core/soft/gpu/generated/body_a1e8b196b2cd_mmfloor_rampsb3l_n6t12.cuh +52 -0
- diffneusim/core/soft/gpu/generated/body_a944653edd64_mmfloor.cuh +25 -0
- diffneusim/core/soft/gpu/generated/body_a944653edd64_mmfloor_rampsb3l_n6t12.cuh +25 -0
- diffneusim/core/soft/gpu/generated/g1_soft_5db44fd45286.cuh +74 -0
- diffneusim/core/soft/gpu/generated/split_62f77a4bb16b_mmfloor.cuh +18 -0
- diffneusim/core/soft/gpu/generated/split_a1e8b196b2cd_mmfloor_rampsb3l_n6t12.cuh +18 -0
- diffneusim/core/soft/gpu/generated/x14_soft_019e20820f86_mmfloor.cuh +123 -0
- diffneusim/core/soft/gpu/generated/x14_soft_62f77a4bb16b_mmfloor.cuh +129 -0
- diffneusim/core/soft/gpu/generated/x14_soft_77dbb7213f26_mmfloor_rampsb3l_n6t12.cuh +123 -0
- diffneusim/core/soft/gpu/generated/x14_soft_8989b60e4486_mmfloor_rampsb3l_n6t12.cuh +123 -0
- diffneusim/core/soft/gpu/generated/x14_soft_8989b60e4486_mmfloor_rhlsd05_n6t12.cuh +123 -0
- diffneusim/core/soft/gpu/generated/x14_soft_8989b60e4486_mmfloor_rhlsdef_n6t12.cuh +123 -0
- diffneusim/core/soft/gpu/generated/x14_soft_8989b60e4486_mmfloor_rhlsmjd_n6t12.cuh +123 -0
- diffneusim/core/soft/gpu/generated/x14_soft_a1e8b196b2cd_mmfloor_rampsb3l_n6t12.cuh +129 -0
- diffneusim/core/soft/gpu/generated/x14_soft_a944653edd64_mmfloor.cuh +123 -0
- diffneusim/core/soft/gpu/generated/x14_soft_a944653edd64_mmfloor_rampsb3l_n6t12.cuh +123 -0
- diffneusim/core/soft/gpu/k_mus.cuh +1038 -0
- diffneusim/core/soft/gpu/k_mus_host.cuh +377 -0
- diffneusim/core/soft/gpu/k_pre.cuh +52 -0
- diffneusim/core/soft/gpu/kernel_p.cuh +490 -0
- diffneusim/core/soft/gpu/kp14.cuh +465 -0
- diffneusim/core/soft/gpu/l2v2.cuh +367 -0
- diffneusim/core/soft/gpu/l2x14.cuh +319 -0
- diffneusim/core/soft/gpu/l3.cuh +1483 -0
- diffneusim/core/soft/gpu/model_view.cuh +48 -0
- diffneusim/core/soft/gpu/mus_case_fits.h +15 -0
- diffneusim/core/soft/gpu/mus_classes.h +182 -0
- diffneusim/core/soft/gpu/mus_row_cf.h +44 -0
- diffneusim/core/soft/gpu/rew14.cuh +177 -0
- diffneusim/core/soft/gpu/rows_ctab.cuh +44 -0
- diffneusim/core/soft/gpu/tree_m.cuh +247 -0
- diffneusim/core/soft/gpu/x14_engine_kernels.cuh +260 -0
- diffneusim/core/soft/gpu/x14_rowcf.h +14 -0
- diffneusim/core/soft/hand.h +124 -0
- diffneusim/core/soft/impedance.h +115 -0
- diffneusim/core/soft/jvp.h +202 -0
- diffneusim/core/soft/kin.h +250 -0
- diffneusim/core/soft/muscle.h +1208 -0
- diffneusim/core/soft/newton.h +371 -0
- diffneusim/core/soft/rows.h +176 -0
- diffneusim/core/soft/step.h +188 -0
- diffneusim/core/soft/tape.h +313 -0
- diffneusim/core/soft/x14/collide14.h +69 -0
- diffneusim/core/soft/x14/jvp14.h +182 -0
- diffneusim/core/soft/x14/law14.h +453 -0
- diffneusim/core/soft/x14adj/collide14_adj.h +134 -0
- diffneusim/core/soft/x14adj/passive14_adj.h +162 -0
- diffneusim/core/soft/x14adj/reward14.h +484 -0
- diffneusim/core/soft/x14adj/rows14_adj.h +400 -0
- diffneusim/core/soft/x14adj/scan14.h +349 -0
- diffneusim/core/soft/x14adj/shell14_adj.h +122 -0
- diffneusim/core/soft/x14adj/sweep14.h +255 -0
- diffneusim/core/soft/x14adj/tree14_adj.h +500 -0
- diffneusim/core/soft/x14adj/x14adj_common.h +96 -0
- diffneusim/data/mirror/H1622v2k_geyer_hfdeq.npz +0 -0
- diffneusim/data/mirror/H1622v2k_hfd.npz +0 -0
- diffneusim/data/mirror/H1622v2k_millard_hfdeq.npz +0 -0
- diffneusim/data/mirror/fullbody_contact.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_millard.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_p2str.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_p2str_rigid.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src_rigid.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_calf2_pe.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_axfix.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_axfixlegs01.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_jd01.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_jd01legs.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_jd01lumbar.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_lumbfix.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_lumbfixlegs01.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1a.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n2.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_rom23.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_hinge.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1a.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n2.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_rom23.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_fusedhand_lspine_girdle_osimeq.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_lspine_girdle_millard.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_lspine_girdle_osimeq.npz +0 -0
- diffneusim/data/mirror/myoleg26_3d_compound_g14eq.npz +0 -0
- diffneusim/data/mirror/myoleg26_3d_kneeexp_g14eq.npz +0 -0
- diffneusim/data/mirror/myoleg26_3d_kneeexp_g14eq_trunkpose.npz +0 -0
- diffneusim/data/mirror/myoleg26_3d_kneeexp_g14eq_trunkpose_spin.npz +0 -0
- diffneusim/data/mirror/myoleg26_3d_kneeexp_g14eq_trunkpose_spin_ank30.npz +0 -0
- diffneusim/data/mirror/myoleg26_3d_kneeexp_g14eq_trunkpose_spin_ank30_hip30.npz +0 -0
- diffneusim/data/mirror/myoleg26_3d_kneeexp_g14eq_trunkpose_spin_ank30_hip30_luispe.npz +0 -0
- diffneusim/data/mirror/myoleg26_3d_kneeexp_g14eq_trunkpose_spin_ank30_hip30_trunk0701.npz +0 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_axfix.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_axfixlegs01.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_jd01.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_jd01legs.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_jd01lumbar.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_lumbfix.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_lumbfixlegs01.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_n1.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_n1a.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_n2.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_rom23.json +91 -0
- diffneusim/data/reference/musclemimic/myofullbody_mimic_sites.json +261 -0
- diffneusim/data/reference/pose3/pose3_scone.json +305 -0
- diffneusim/data/reference/pose3/pose3_scone.txt +3 -0
- diffneusim/data/reference/pose3/pose3_scone_gait.npz +0 -0
- diffneusim/data/reference/pose3/pose3_scone_mirror.npz +0 -0
- diffneusim/data/reference/pose3/pose3_scone_stand.npz +0 -0
- diffneusim/data/reference/x016run/MD5SUMS +241 -0
- diffneusim/data/reference/x016run/x016run_states.txt +240 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s0_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s0_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s0_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s0_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s0_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s0_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s0_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s0_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s1_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s1_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s1_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s1_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s1_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s1_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s1_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s1_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s2_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s2_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s2_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s2_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s2_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s2_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s2_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s2_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s3_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s3_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s3_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s3_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s3_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s3_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s3_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s3_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s4_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s4_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s4_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s4_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s4_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s4_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s4_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s4_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s5_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s5_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s5_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s5_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s5_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s5_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s5_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s5_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s6_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s6_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s6_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s6_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s6_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s6_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s6_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s6_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s7_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s7_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s7_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s7_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s7_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s7_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s7_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s7_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s0_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s0_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s0_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s0_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s0_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s0_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s0_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s0_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s1_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s1_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s1_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s1_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s1_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s1_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s1_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s1_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s2_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s2_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s2_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s2_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s2_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s2_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s2_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s2_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s3_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s3_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s3_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s3_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s3_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s3_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s3_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s3_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s4_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s4_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s4_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s4_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s4_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s4_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s4_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s4_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s5_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s5_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s5_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s5_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s5_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s5_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s5_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s5_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s6_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s6_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s6_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s6_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s6_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s6_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s6_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s6_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s7_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s7_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s7_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s7_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s7_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s7_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s7_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s7_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s0_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s0_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s0_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s0_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s0_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s0_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s0_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s0_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s1_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s1_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s1_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s1_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s1_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s1_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s1_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s1_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s2_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s2_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s2_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s2_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s2_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s2_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s2_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s2_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s3_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s3_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s3_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s3_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s3_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s3_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s3_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s3_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s5_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s5_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s5_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s5_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s5_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s5_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s5_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s5_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s6_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s6_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s6_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s6_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s6_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s6_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s6_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s6_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s7_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s7_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s7_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s7_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s7_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s7_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s7_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s7_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s0_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s0_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s0_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s0_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s0_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s0_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s0_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s0_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s1_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s1_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s1_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s1_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s1_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s1_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s1_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s1_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s2_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s2_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s2_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s2_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s2_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s2_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s2_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s2_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s3_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s3_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s3_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s3_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s3_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s3_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s3_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s3_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s5_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s5_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s5_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s5_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s5_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s5_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s5_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s5_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s6_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s6_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s6_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s6_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s6_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s6_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s6_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s6_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s7_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s7_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s7_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s7_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s7_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s7_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s7_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s7_r3.npz +0 -0
- diffneusim/data/state_prior/lumbar_poly_fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc.npz +0 -0
- diffneusim/engine/__init__.py +0 -0
- diffneusim/engine/build_tag.py +52 -0
- diffneusim/engine/case_tables.py +46 -0
- diffneusim/engine/d16_body.py +80 -0
- diffneusim/engine/engine14.py +367 -0
- diffneusim/engine/gen_split.py +159 -0
- diffneusim/engine/hand_format.py +69 -0
- diffneusim/engine/live14.py +149 -0
- diffneusim/engine/phase_b_tree.py +137 -0
- diffneusim/engine/soft14.py +130 -0
- diffneusim/engine/soft_capi.py +373 -0
- diffneusim/engine/soft_engine.py +165 -0
- diffneusim/engine/step14.py +132 -0
- diffneusim/engine/tape_format.py +89 -0
- diffneusim/engine/x14cpu.py +163 -0
- diffneusim/env/__init__.py +0 -0
- diffneusim/env/absent.py +20 -0
- diffneusim/env/cpu14.py +105 -0
- diffneusim/env/e0loop14.py +224 -0
- diffneusim/env/env14.py +568 -0
- diffneusim/env/kin_contact14.py +193 -0
- diffneusim/env/mimic_sites_x14.json +366 -0
- diffneusim/env/old_count.py +78 -0
- diffneusim/env/rew14.py +114 -0
- diffneusim/env/rew14_hook.py +105 -0
- diffneusim/g1/__init__.py +1 -0
- diffneusim/g1/arm_a2.py +165 -0
- diffneusim/g1/arm_a3.py +576 -0
- diffneusim/g1/read_a3.py +79 -0
- diffneusim/g1/rg1_read.py +89 -0
- diffneusim/model/__init__.py +66 -0
- diffneusim/model/case.py +17 -0
- diffneusim/model/dnmodel.py +79 -0
- diffneusim/model/fuse_fixed.py +281 -0
- diffneusim/model/monitor.py +834 -0
- diffneusim/models/BODIES.toml +48 -0
- diffneusim/models/MANIFEST.toml +979 -0
- diffneusim/models/cases/G290/case.bin +0 -0
- diffneusim/models/cases/G290/case.json +1 -0
- diffneusim/models/cases/G356-SRC/case.bin +0 -0
- diffneusim/models/cases/G356-SRC/case.json +1 -0
- diffneusim/models/cases/G416/case.bin +0 -0
- diffneusim/models/cases/G416/case.json +1 -0
- diffneusim/models/cases/M290C-SRC/case.bin +0 -0
- diffneusim/models/cases/M290C-SRC/case.json +1 -0
- diffneusim/models/cases/M290R-SRC/case.bin +0 -0
- diffneusim/models/cases/M290R-SRC/case.json +1 -0
- diffneusim/models/cases/M356C-SRC/case.bin +0 -0
- diffneusim/models/cases/M356C-SRC/case.json +1 -0
- diffneusim/models/cases/M356R-SRC/case.bin +0 -0
- diffneusim/models/cases/M356R-SRC/case.json +1 -0
- diffneusim/models/cases/M416C-SRC/case.bin +0 -0
- diffneusim/models/cases/M416C-SRC/case.json +1 -0
- diffneusim/models/derived/d16_expanded_62f77a4bb16b1e67_mmfloor.xml +673 -0
- diffneusim/models/derived/d16_expanded_a1e8b196b2cd7b3c_mmfloor.xml +673 -0
- diffneusim/models/derived/d16_soft_law_019e20820f8633b9_mmfloor.json +7844 -0
- diffneusim/models/derived/d16_soft_law_62f77a4bb16b1e67_mmfloor.json +16855 -0
- diffneusim/models/derived/d16_soft_law_77dbb7213f26e821_mmfloor_rampsb3l_n6t12.json +7883 -0
- diffneusim/models/derived/d16_soft_law_8989b60e44860c5b_mmfloor_rampsb3l_n6t12.json +7883 -0
- diffneusim/models/derived/d16_soft_law_8989b60e44860c5b_mmfloor_rhlsd05_n6t12.json +7868 -0
- diffneusim/models/derived/d16_soft_law_8989b60e44860c5b_mmfloor_rhlsdef_n6t12.json +7868 -0
- diffneusim/models/derived/d16_soft_law_8989b60e44860c5b_mmfloor_rhlsmjd_n6t12.json +7868 -0
- diffneusim/models/derived/d16_soft_law_a1e8b196b2cd7b3c_mmfloor_rampsb3l_n6t12.json +16894 -0
- diffneusim/models/derived/d16_soft_law_a944653edd642082_mmfloor.json +12655 -0
- diffneusim/models/derived/d16_soft_law_a944653edd642082_mmfloor_rampsb3l_n6t12.json +12700 -0
- diffneusim/models/derived/unitree_g1_soft_law.json +15580 -0
- diffneusim/models/fullbody_contact_spinecoupled_armless_ball_lspine_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src.dnmodel +28913 -0
- diffneusim/models/fullbody_contact_spinecoupled_armless_ball_lspine_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src_qk.txt +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_armless_ball_lspine_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src_rigid.dnmodel +29202 -0
- diffneusim/models/fullbody_contact_spinecoupled_armless_ball_lspine_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src_rigid_qk.txt +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_axfixlegs01.dnmodel +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1.dnmodel +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1_qk.txt +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_ball_lspine_girdle_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src.dnmodel +46970 -0
- diffneusim/models/fullbody_contact_spinecoupled_ball_lspine_girdle_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src_qk.txt +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1.dnmodel +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1_qk.txt +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src.dnmodel +38570 -0
- diffneusim/models/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src_qk.txt +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src_rigid.dnmodel +38923 -0
- diffneusim/models/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src_rigid_qk.txt +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1.dnmodel +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1_qk.txt +1 -0
- diffneusim/models/fullbody_meshes/1mc.stl +0 -0
- diffneusim/models/fullbody_meshes/2distph.stl +0 -0
- diffneusim/models/fullbody_meshes/2mc.stl +0 -0
- diffneusim/models/fullbody_meshes/2midph.stl +0 -0
- diffneusim/models/fullbody_meshes/2proxph.stl +0 -0
- diffneusim/models/fullbody_meshes/3distph.stl +0 -0
- diffneusim/models/fullbody_meshes/3mc.stl +0 -0
- diffneusim/models/fullbody_meshes/3midph.stl +0 -0
- diffneusim/models/fullbody_meshes/3proxph.stl +0 -0
- diffneusim/models/fullbody_meshes/4distph.stl +0 -0
- diffneusim/models/fullbody_meshes/4mc.stl +0 -0
- diffneusim/models/fullbody_meshes/4midph.stl +0 -0
- diffneusim/models/fullbody_meshes/4proxph.stl +0 -0
- diffneusim/models/fullbody_meshes/5distph.stl +0 -0
- diffneusim/models/fullbody_meshes/5mc.stl +0 -0
- diffneusim/models/fullbody_meshes/5midph.stl +0 -0
- diffneusim/models/fullbody_meshes/5proxph.stl +0 -0
- diffneusim/models/fullbody_meshes/NOTICE +2 -0
- diffneusim/models/fullbody_meshes/capitate.stl +0 -0
- diffneusim/models/fullbody_meshes/clavicle.stl +0 -0
- diffneusim/models/fullbody_meshes/hamate.stl +0 -0
- diffneusim/models/fullbody_meshes/hat_cervical.stl +0 -0
- diffneusim/models/fullbody_meshes/hat_jaw.stl +0 -0
- diffneusim/models/fullbody_meshes/hat_skull.stl +0 -0
- diffneusim/models/fullbody_meshes/humerus.stl +0 -0
- diffneusim/models/fullbody_meshes/l_bofoot.stl +0 -0
- diffneusim/models/fullbody_meshes/l_femur.stl +0 -0
- diffneusim/models/fullbody_meshes/l_fibula.stl +0 -0
- diffneusim/models/fullbody_meshes/l_foot.stl +0 -0
- diffneusim/models/fullbody_meshes/l_patella.stl +0 -0
- diffneusim/models/fullbody_meshes/l_pelvis.stl +0 -0
- diffneusim/models/fullbody_meshes/l_talus.stl +0 -0
- diffneusim/models/fullbody_meshes/l_tibia.stl +0 -0
- diffneusim/models/fullbody_meshes/lumbar1.stl +0 -0
- diffneusim/models/fullbody_meshes/lumbar2.stl +0 -0
- diffneusim/models/fullbody_meshes/lumbar3.stl +0 -0
- diffneusim/models/fullbody_meshes/lumbar4.stl +0 -0
- diffneusim/models/fullbody_meshes/lumbar5.stl +0 -0
- diffneusim/models/fullbody_meshes/lunate.stl +0 -0
- diffneusim/models/fullbody_meshes/pisiform.stl +0 -0
- diffneusim/models/fullbody_meshes/r_bofoot.stl +0 -0
- diffneusim/models/fullbody_meshes/r_femur.stl +0 -0
- diffneusim/models/fullbody_meshes/r_fibula.stl +0 -0
- diffneusim/models/fullbody_meshes/r_foot.stl +0 -0
- diffneusim/models/fullbody_meshes/r_patella.stl +0 -0
- diffneusim/models/fullbody_meshes/r_pelvis.stl +0 -0
- diffneusim/models/fullbody_meshes/r_talus.stl +0 -0
- diffneusim/models/fullbody_meshes/r_tibia.stl +0 -0
- diffneusim/models/fullbody_meshes/radius.stl +0 -0
- diffneusim/models/fullbody_meshes/sacrum.stl +0 -0
- diffneusim/models/fullbody_meshes/scaphoid.stl +0 -0
- diffneusim/models/fullbody_meshes/scapula.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic10_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic11_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic12_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic1_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic2_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic3_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic4_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic5_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic6_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic7_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic8_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic9_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thorax.stl +0 -0
- diffneusim/models/fullbody_meshes/thumbdist.stl +0 -0
- diffneusim/models/fullbody_meshes/thumbprox.stl +0 -0
- diffneusim/models/fullbody_meshes/trapezium.stl +0 -0
- diffneusim/models/fullbody_meshes/trapezoid.stl +0 -0
- diffneusim/models/fullbody_meshes/triquetrum.stl +0 -0
- diffneusim/models/fullbody_meshes/ulna.stl +0 -0
- diffneusim/models/source/myo_fullbody/UPSTREAM.md +91 -0
- diffneusim/models/source/myoleg/UPSTREAM.md +52 -0
- diffneusim/models/source/unitree_g1/LICENSE.mjlab +202 -0
- diffneusim/models/source/unitree_g1/UPSTREAM.md +38 -0
- diffneusim/models/source/unitree_g1/assets/head_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_ankle_pitch_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_ankle_roll_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_elbow_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_hip_pitch_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_hip_roll_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_hip_yaw_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_knee_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_rubber_hand.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_shoulder_pitch_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_shoulder_roll_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_shoulder_yaw_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_wrist_pitch_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_wrist_roll_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_wrist_yaw_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/logo_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/pelvis.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/pelvis_contour_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_ankle_pitch_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_ankle_roll_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_elbow_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_hip_pitch_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_hip_roll_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_hip_yaw_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_knee_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_rubber_hand.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_shoulder_pitch_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_shoulder_roll_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_shoulder_yaw_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_wrist_pitch_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_wrist_roll_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_wrist_yaw_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/torso_link_rev_1_0.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/waist_roll_link_rev_1_0.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/waist_yaw_link_rev_1_0.STL +0 -0
- diffneusim/models/source/unitree_g1/dump_mjlab_reference.py +30 -0
- diffneusim/models/source/unitree_g1/g1.xml +308 -0
- diffneusim/models/source/unitree_g1/g1_constants.py +298 -0
- diffneusim/models/source/unitree_g1/mjlab_compiled_reference.json +857 -0
- diffneusim/models/unitree_g1.dnmodel +4393 -0
- diffneusim/models/unitree_g1_selfcol.dnmodel +20824 -0
- diffneusim/rl/__init__.py +2 -0
- diffneusim/rl/dynsyn_layer.py +146 -0
- diffneusim/rl/footstep_plan.py +337 -0
- diffneusim/rl/g1_bm_env.py +572 -0
- diffneusim/rl/g1_bm_eval.py +168 -0
- diffneusim/rl/g1_bm_fused.py +275 -0
- diffneusim/rl/g1_bm_ppo.py +622 -0
- diffneusim/rl/g1_bm_sapo.py +551 -0
- diffneusim/rl/g1_ppo.py +395 -0
- diffneusim/rl/g1_sapo_soft.py +240 -0
- diffneusim/rl/g1_soft_env.py +452 -0
- diffneusim/rl/g1_soft_grad.py +145 -0
- diffneusim/rl/geyer_curves_torch.py +108 -0
- diffneusim/rl/gpu_fullbody_vec_env.py +1241 -0
- diffneusim/rl/imitation.py +2027 -0
- diffneusim/rl/imitation_reward_v2.py +248 -0
- diffneusim/rl/imitation_reward_v3.py +349 -0
- diffneusim/rl/latent_task.py +175 -0
- diffneusim/rl/llc_reward.py +316 -0
- diffneusim/rl/millard_curves_torch.py +154 -0
- diffneusim/rl/mirror_symmetry.py +212 -0
- diffneusim/rl/model_path.py +35 -0
- diffneusim/rl/mvae_recon.py +123 -0
- diffneusim/rl/nets_shac.py +599 -0
- diffneusim/rl/reset_pool.py +154 -0
- diffneusim/rl/sapo_capture.py +873 -0
- diffneusim/rl/sapo_vec.py +1051 -0
- diffneusim/rl/shac_vec.py +346 -0
- diffneusim/rl/state_prior.py +151 -0
- diffneusim/rl/step_library.py +105 -0
- diffneusim/rl/task_walk_env.py +1793 -0
- diffneusim/rl/task_walk_reward.py +3300 -0
- diffneusim/run.py +23 -0
- diffneusim/run_env.py +46 -0
- diffneusim/tasks/__init__.py +147 -0
- diffneusim/tasks/legacy_names.py +63 -0
- diffneusim/tasks/paths.py +79 -0
- diffneusim/tasks/settings.py +202 -0
- diffneusim/third_party/instantmimic_947430ee/LICENSE +202 -0
- diffneusim/third_party/instantmimic_947430ee/NOTICE +19 -0
- diffneusim/third_party/instantmimic_947430ee/README.md +31 -0
- diffneusim/third_party/instantmimic_947430ee/instantmimic/envs/unitree_g1/tasks/beyondmimic_tracking/benchmark_protocol.py +106 -0
- diffneusim/third_party/instantmimic_947430ee/instantmimic/envs/unitree_g1/tasks/beyondmimic_tracking/metrics.py +214 -0
- diffneusim/third_party/instantmimic_947430ee/instantmimic/envs/unitree_g1/tasks/beyondmimic_tracking/reference.py +513 -0
- diffneusim/third_party/instantmimic_947430ee/instantmimic/motion/quaternion.py +193 -0
- diffneusim/train/__init__.py +0 -0
- diffneusim/train/eval_ckpt.py +239 -0
- diffneusim/train/eval_mimic.py +133 -0
- diffneusim/train/gait_report.py +203 -0
- diffneusim/train/gcot_chain.py +51 -0
- diffneusim/train/levers.py +135 -0
- diffneusim/train/masked_reset.py +314 -0
- diffneusim/train/rl_algorithm_suite.py +917 -0
- diffneusim/train/train14.py +240 -0
- diffneusim/train/train_tw14.py +674 -0
- diffneusim/viz/__init__.py +5 -0
- diffneusim/viz/__main__.py +41 -0
- diffneusim/viz/camera.py +115 -0
- diffneusim/viz/dnrec.py +118 -0
- diffneusim/viz/dnrec_io.py +686 -0
- diffneusim/viz/hud.py +565 -0
- diffneusim/viz/meshes.py +458 -0
- diffneusim/viz/play.py +237 -0
- diffneusim/viz/record.py +74 -0
- diffneusim/viz/render.py +1402 -0
- diffneusim/viz/renderer.py +268 -0
- diffneusim/viz/rl_env_render.py +635 -0
- diffneusim/viz/snapshot.py +54 -0
- diffneusim/viz/strobe.py +124 -0
- diffneusim/viz/to_mp4.py +58 -0
- diffneusim/viz/ui.py +481 -0
- diffneusim/viz/viewer.py +2086 -0
- diffneusim-1.0.0.dist-info/METADATA +226 -0
- diffneusim-1.0.0.dist-info/RECORD +682 -0
- diffneusim-1.0.0.dist-info/WHEEL +5 -0
- diffneusim-1.0.0.dist-info/licenses/LICENSE +201 -0
- diffneusim-1.0.0.dist-info/licenses/LICENSES/BSD-3-Clause-NC-ARMS-hand-wrist-4.3.txt +20 -0
- diffneusim-1.0.0.dist-info/licenses/LICENSES/BSD-3-Clause-NC-MoBL-ARMS.txt +25 -0
- diffneusim-1.0.0.dist-info/licenses/LICENSES/CC-BY-3.0-OpenSim-geometry.txt +25 -0
- diffneusim-1.0.0.dist-info/licenses/LICENSES/MIT-Christophy2012-lumbarspine.txt +10 -0
- diffneusim-1.0.0.dist-info/licenses/LICENSES/MIT-Lai2017-model-high-flex.txt +10 -0
- diffneusim-1.0.0.dist-info/licenses/LICENSES/MIT-Lee2015-hand_muscle.txt +11 -0
- diffneusim-1.0.0.dist-info/licenses/LICENSES/MIT-Rajagopal2016-full_body.txt +11 -0
- diffneusim-1.0.0.dist-info/licenses/LICENSES/MIT-Uhlrich2022-fbmodpassivecal.txt +10 -0
- diffneusim-1.0.0.dist-info/licenses/NOTICE +274 -0
- diffneusim-1.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,834 @@
|
|
|
1
|
+
"""Runtime monitors for `.dnmodel` rollouts.
|
|
2
|
+
|
|
3
|
+
The helpers here are intentionally model-data driven. They do not pick a
|
|
4
|
+
model-specific extension and they do not affect gradients; training code can use
|
|
5
|
+
them to log contact penetration and joint-limit penetration from the same
|
|
6
|
+
`.dnmodel` that drives the engine.
|
|
7
|
+
"""
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import json
|
|
11
|
+
import os
|
|
12
|
+
import pathlib
|
|
13
|
+
import re
|
|
14
|
+
|
|
15
|
+
import torch
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _load_jsonc(path: str | pathlib.Path) -> dict:
|
|
19
|
+
text = re.sub(r"^\s*//.*$", "", pathlib.Path(path).read_text(), flags=re.MULTILINE)
|
|
20
|
+
return json.loads(text)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _quat_mul(a: torch.Tensor, b: torch.Tensor) -> torch.Tensor:
|
|
24
|
+
aw, ax, ay, az = a[0], a[1], a[2], a[3]
|
|
25
|
+
bw, bx, by, bz = b[0], b[1], b[2], b[3]
|
|
26
|
+
return torch.stack(
|
|
27
|
+
(
|
|
28
|
+
aw * bw - ax * bx - ay * by - az * bz,
|
|
29
|
+
aw * bx + ax * bw + ay * bz - az * by,
|
|
30
|
+
aw * by - ax * bz + ay * bw + az * bx,
|
|
31
|
+
aw * bz + ax * by - ay * bx + az * bw,
|
|
32
|
+
),
|
|
33
|
+
dim=0,
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _quat_normalize(q: torch.Tensor) -> torch.Tensor:
|
|
38
|
+
return q / q.norm(dim=0, keepdim=True).clamp_min(1e-12)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _quat_axis_angle(axis: torch.Tensor, theta: torch.Tensor) -> torch.Tensor:
|
|
42
|
+
axis = axis[:, None]
|
|
43
|
+
half = 0.5 * theta[None, :]
|
|
44
|
+
return torch.cat((torch.cos(half), axis * torch.sin(half)), dim=0)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _quat_rotate(q: torch.Tensor, v: torch.Tensor) -> torch.Tensor:
|
|
48
|
+
w, x, y, z = q[0], q[1], q[2], q[3]
|
|
49
|
+
vx, vy, vz = v[0], v[1], v[2]
|
|
50
|
+
return torch.stack(
|
|
51
|
+
(
|
|
52
|
+
(1 - 2 * (y * y + z * z)) * vx + 2 * (x * y - z * w) * vy + 2 * (x * z + y * w) * vz,
|
|
53
|
+
2 * (x * y + z * w) * vx + (1 - 2 * (x * x + z * z)) * vy + 2 * (y * z - x * w) * vz,
|
|
54
|
+
2 * (x * z - y * w) * vx + 2 * (y * z + x * w) * vy + (1 - 2 * (x * x + y * y)) * vz,
|
|
55
|
+
),
|
|
56
|
+
dim=0,
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
# --- contracted quaternion algebra (same results, ~10x fewer dispatches) -------------------------------
|
|
61
|
+
# _quat_mul / _quat_rotate spell the products out elementwise: ~33 and ~28 aten dispatches each. Both are
|
|
62
|
+
# BILINEAR, so they can be written as one contraction against a constant tensor. In the reduced FK almost
|
|
63
|
+
# every product has a CONSTANT operand (a pre-composed welded chain, or a joint axis), which folds the
|
|
64
|
+
# contraction down to a single (4,4) @ (4,n) matmul. See body_poses_subset; the elementwise forms above
|
|
65
|
+
# stay as the reference oracle that python/tests/test_reduced_fk_parity.py checks the fast path against.
|
|
66
|
+
|
|
67
|
+
# T[i,j,k] = coefficient of a_j*b_k in (a (x) b)_i
|
|
68
|
+
_QMUL_T = torch.zeros(4, 4, 4, dtype=torch.float64)
|
|
69
|
+
for _i, _terms in enumerate((
|
|
70
|
+
((1, 0, 0), (-1, 1, 1), (-1, 2, 2), (-1, 3, 3)),
|
|
71
|
+
((1, 0, 1), (1, 1, 0), (1, 2, 3), (-1, 3, 2)),
|
|
72
|
+
((1, 0, 2), (-1, 1, 3), (1, 2, 0), (1, 3, 1)),
|
|
73
|
+
((1, 0, 3), (1, 1, 2), (-1, 2, 1), (1, 3, 0)))):
|
|
74
|
+
for _c, _j, _k in _terms:
|
|
75
|
+
_QMUL_T[_i, _j, _k] = _c
|
|
76
|
+
|
|
77
|
+
# R(q)[i][j] as quadratic monomials in q=(w,x,y,z): list of (coef, a, b) meaning coef*q_a*q_b (unit q)
|
|
78
|
+
_ROT_MONOMIALS = (
|
|
79
|
+
(((1, 0, 0), (1, 1, 1), (-1, 2, 2), (-1, 3, 3)), ((2, 1, 2), (-2, 0, 3)), ((2, 1, 3), (2, 0, 2))),
|
|
80
|
+
(((2, 1, 2), (2, 0, 3)), ((1, 0, 0), (-1, 1, 1), (1, 2, 2), (-1, 3, 3)), ((2, 2, 3), (-2, 0, 1))),
|
|
81
|
+
(((2, 1, 3), (-2, 0, 2)), ((2, 2, 3), (2, 0, 1)), ((1, 0, 0), (-1, 1, 1), (-1, 2, 2), (1, 3, 3))),
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def _qmul_right_matrix(b: torch.Tensor) -> torch.Tensor:
|
|
86
|
+
"""(4,4) matrix M with M @ a == a (x) b, for a CONSTANT right operand b."""
|
|
87
|
+
return torch.einsum("ijk,k->ij", _QMUL_T.to(device=b.device, dtype=b.dtype), b)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def _qrot_form(c: torch.Tensor) -> torch.Tensor:
|
|
91
|
+
"""(3,4,4) symmetric forms A with (A q) . q == R(q) @ c, for a CONSTANT vector c and UNIT q."""
|
|
92
|
+
A = torch.zeros(3, 4, 4, dtype=c.dtype, device=c.device)
|
|
93
|
+
for i in range(3):
|
|
94
|
+
for j in range(3):
|
|
95
|
+
for coef, a, b in _ROT_MONOMIALS[i][j]:
|
|
96
|
+
if a == b:
|
|
97
|
+
A[i, a, a] += coef * c[j]
|
|
98
|
+
else:
|
|
99
|
+
A[i, a, b] += 0.5 * coef * c[j]
|
|
100
|
+
A[i, b, a] += 0.5 * coef * c[j]
|
|
101
|
+
return A
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
# DN_FK_POINTWISE=1 (opt-in): inside a torch.compile trace the FK's constant contractions below (and the hinge spin)
|
|
105
|
+
# are spelled as broadcast products summed over the contracted 4-axis, which Inductor unrolls into the surrounding fused
|
|
106
|
+
# kernels; as matmuls each is a cuBLAS call of its own (~180 forward and ~180 backward per E0 control step). Eager calls
|
|
107
|
+
# keep the matmul, one dispatch. Equal to roundoff against the compiled matmul form.
|
|
108
|
+
_FK_POINTWISE = os.environ.get("DN_FK_POINTWISE", "0")
|
|
109
|
+
assert _FK_POINTWISE in ("0", "1"), f"DN_FK_POINTWISE={_FK_POINTWISE!r} must be exactly '0' or '1'"
|
|
110
|
+
_FK_POINTWISE = _FK_POINTWISE == "1"
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def _cmm(M: torch.Tensor, a: torch.Tensor) -> torch.Tensor:
|
|
114
|
+
"""M @ a for a small constant M over the leading 4-axis of a (see _FK_POINTWISE)."""
|
|
115
|
+
if _FK_POINTWISE and torch.compiler.is_compiling():
|
|
116
|
+
return (M.unsqueeze(-1) * a.unsqueeze(-3)).sum(-2)
|
|
117
|
+
return torch.matmul(M, a)
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def _qmul_const(M: torch.Tensor, a: torch.Tensor) -> torch.Tensor:
|
|
121
|
+
"""a (x) b for a constant b, via its precomputed right-multiply matrix M. One dispatch."""
|
|
122
|
+
return _cmm(M, a)
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def _qmul_fast(a: torch.Tensor, b: torch.Tensor, T: torch.Tensor) -> torch.Tensor:
|
|
126
|
+
"""General a (x) b as one contraction against _QMUL_T (3 dispatches instead of ~33)."""
|
|
127
|
+
return (_cmm(T, b) * a.unsqueeze(0)).sum(1)
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def _qrot_const(A: torch.Tensor, q: torch.Tensor) -> torch.Tensor:
|
|
131
|
+
"""R(q) @ c for a constant c via its precomputed form A (3 dispatches instead of ~28)."""
|
|
132
|
+
return (_cmm(A, q) * q.unsqueeze(0)).sum(1)
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def _quat_rotate_batched(q: torch.Tensor, v: torch.Tensor) -> torch.Tensor:
|
|
136
|
+
"""_quat_rotate over a leading BODY axis: q `(F,4,n)`, v `(F,3,1|n)` -> `(F,3,n)`. Same algebra as
|
|
137
|
+
_quat_rotate but one dispatch per term instead of F of them -- used by the composite-COM sum."""
|
|
138
|
+
w, x, y, z = q.unbind(1)
|
|
139
|
+
vx, vy, vz = v.unbind(1)
|
|
140
|
+
return torch.stack(
|
|
141
|
+
(
|
|
142
|
+
(1 - 2 * (y * y + z * z)) * vx + 2 * (x * y - z * w) * vy + 2 * (x * z + y * w) * vz,
|
|
143
|
+
2 * (x * y + z * w) * vx + (1 - 2 * (x * x + z * z)) * vy + 2 * (y * z - x * w) * vz,
|
|
144
|
+
2 * (x * z - y * w) * vx + 2 * (y * z + x * w) * vy + (1 - 2 * (x * x + y * y)) * vz,
|
|
145
|
+
),
|
|
146
|
+
dim=1,
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def _zero_vec(n_env: int, dtype: torch.dtype, device: torch.device) -> torch.Tensor:
|
|
151
|
+
return torch.zeros(3, n_env, dtype=dtype, device=device)
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def _identity_quat(n_env: int, dtype: torch.dtype, device: torch.device) -> torch.Tensor:
|
|
155
|
+
q = torch.zeros(4, n_env, dtype=dtype, device=device)
|
|
156
|
+
q[0] = 1.0
|
|
157
|
+
return q
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
class DnModelMonitor:
|
|
161
|
+
"""Batch FK + scalar rollout diagnostics for a `.dnmodel`."""
|
|
162
|
+
|
|
163
|
+
def __init__(self, model_path: str | pathlib.Path, device: str | torch.device = "cuda"):
|
|
164
|
+
self.model_path = str(model_path)
|
|
165
|
+
self.jm = _load_jsonc(model_path)
|
|
166
|
+
self.device = torch.device(device)
|
|
167
|
+
self.bodies = self.jm["bodies"]
|
|
168
|
+
self.contact_geoms = self.jm.get("contact", {}).get("geoms", [])
|
|
169
|
+
# Ground-plane normal (optional "contact.normal"; default flat +z). Kept in sync with the
|
|
170
|
+
# engine: core/io/dnmodel.h reads the same field into ContactParams.gnrm, so a sloped model
|
|
171
|
+
# measures the same gap here as the kernel does.
|
|
172
|
+
_gn = self.jm.get("contact", {}).get("normal", [0.0, 0.0, 1.0])
|
|
173
|
+
_gn = [float(x) for x in _gn]
|
|
174
|
+
_ln = sum(x * x for x in _gn) ** 0.5
|
|
175
|
+
assert _ln > 1e-9 and _gn[2] > 0.0, f"contact.normal must point up out of the ground: {_gn}"
|
|
176
|
+
self.ground_normal = [x / _ln for x in _gn]
|
|
177
|
+
|
|
178
|
+
self.parents = [int(b["parent"]) for b in self.bodies]
|
|
179
|
+
self.body_pos = [
|
|
180
|
+
torch.tensor(b.get("pos", [0.0, 0.0, 0.0]), dtype=torch.float32, device=self.device)
|
|
181
|
+
for b in self.bodies
|
|
182
|
+
]
|
|
183
|
+
self.body_quat = [
|
|
184
|
+
torch.tensor(b.get("quat", [1.0, 0.0, 0.0, 0.0]), dtype=torch.float32, device=self.device)
|
|
185
|
+
for b in self.bodies
|
|
186
|
+
]
|
|
187
|
+
self.contact_body = [int(g["body"]) for g in self.contact_geoms]
|
|
188
|
+
self.contact_center = [
|
|
189
|
+
torch.tensor(g["center"], dtype=torch.float32, device=self.device)
|
|
190
|
+
for g in self.contact_geoms
|
|
191
|
+
]
|
|
192
|
+
self.contact_radius = [float(g["radius"]) for g in self.contact_geoms]
|
|
193
|
+
# Cache joint axes as GPU tensors ONCE. body_poses() previously rebuilt them every call via
|
|
194
|
+
# torch.tensor(axis, device=) -- a per-step host->device copy (hundreds/step at full body) that
|
|
195
|
+
# both costs throughput AND makes the step un-capturable by CUDA graphs (HtoD is illegal mid-capture).
|
|
196
|
+
self.body_axis = [] # per body: hinge/slide axis tensor, else None
|
|
197
|
+
self.joint_axes = [] # per body: list of composite-prim axis tensors, else None
|
|
198
|
+
for _b in self.bodies:
|
|
199
|
+
if "joints" in _b:
|
|
200
|
+
self.joint_axes.append([torch.tensor(_p["axis"], dtype=torch.float32, device=self.device)
|
|
201
|
+
for _p in _b["joints"]])
|
|
202
|
+
self.body_axis.append(None)
|
|
203
|
+
elif _b.get("joint") in ("hinge", "revolute", "slide", "prismatic"):
|
|
204
|
+
self.body_axis.append(torch.tensor(_b["axis"], dtype=torch.float32, device=self.device))
|
|
205
|
+
self.joint_axes.append(None)
|
|
206
|
+
else:
|
|
207
|
+
self.body_axis.append(None)
|
|
208
|
+
self.joint_axes.append(None)
|
|
209
|
+
self.limit_specs = []
|
|
210
|
+
for body_i, body in enumerate(self.bodies):
|
|
211
|
+
qa = int(body["qadr"])
|
|
212
|
+
body_name = body.get("name") or f"body{body_i}"
|
|
213
|
+
if "joints" in body:
|
|
214
|
+
for k, prim in enumerate(body["joints"]):
|
|
215
|
+
if not prim.get("limited", False):
|
|
216
|
+
continue
|
|
217
|
+
lo, hi = prim["range"]
|
|
218
|
+
name = prim.get("name") or f"{body_name}.joint{k}"
|
|
219
|
+
self.limit_specs.append(
|
|
220
|
+
{"qadr": qa + k, "lo": float(lo), "hi": float(hi), "label": name}
|
|
221
|
+
)
|
|
222
|
+
continue
|
|
223
|
+
if body.get("joint") not in ("hinge", "revolute", "slide", "prismatic"):
|
|
224
|
+
continue
|
|
225
|
+
if not body.get("limited", False):
|
|
226
|
+
continue
|
|
227
|
+
lo, hi = body["range"]
|
|
228
|
+
name = body.get("name") or f"{body_name}.{body.get('joint')}"
|
|
229
|
+
self.limit_specs.append({"qadr": qa, "lo": float(lo), "hi": float(hi), "label": name})
|
|
230
|
+
self._build_reduced_fk()
|
|
231
|
+
# FUSED reduced FK (opt-in, DN_FK_COMPILE=1): body_poses_subset traced once per call signature by
|
|
232
|
+
# torch.compile, so its forward AND its backward run as a handful of generated kernels instead of ~900
|
|
233
|
+
# autograd nodes. Measured 2026-10-01 (RTX 3080 Ti laptop GPU, taskwalk SAPO): one FK+COM call = 909 nodes, ~90% of the
|
|
234
|
+
# backward nodes the taskwalk reward adds over the SHAC reward -- and on the 4090 the step is bound by
|
|
235
|
+
# dispatching them. Same maths, reassociated by the compiler: equal to roundoff, not bit-identical, so
|
|
236
|
+
# it is a flag and every cell that turns it on reads against a same-flag control.
|
|
237
|
+
_fc = os.environ.get("DN_FK_COMPILE", "0")
|
|
238
|
+
assert _fc in ("0", "1"), f"DN_FK_COMPILE={_fc!r} must be exactly '0' or '1'"
|
|
239
|
+
self._fk_compile = _fc == "1"
|
|
240
|
+
self._fk_compiled = {} # (bodies, need_com, dtype, n_env, device) -> compiled fn
|
|
241
|
+
# FUSED twist recursion (opt-in, DN_TWIST_COMPILE=1): body_twists_from_poses traced once per call signature,
|
|
242
|
+
# the same contract as the reduced FK above. On the MuscleMimic reward the twists of the 17 sites' chains were the
|
|
243
|
+
# largest source of kernel launches left (tools/dispatch_attribution.py, 2026-10-27: the generic _quat_rotate
|
|
244
|
+
# alone ~7k of ~21k launches per control step, backward included). Equal to roundoff (tools/twist_compile_gate.py).
|
|
245
|
+
_tc = os.environ.get("DN_TWIST_COMPILE", "0")
|
|
246
|
+
assert _tc in ("0", "1"), f"DN_TWIST_COMPILE={_tc!r} must be exactly '0' or '1'"
|
|
247
|
+
self._tw_compile = _tc == "1"
|
|
248
|
+
self._tw_compiled = {} # (bodies, frames, dtype, n_env, device) -> compiled fn
|
|
249
|
+
|
|
250
|
+
def body_poses(self, q: torch.Tensor) -> tuple[list[torch.Tensor], list[torch.Tensor]]:
|
|
251
|
+
"""Return world body positions/quaternions for batched q `[nq, n_env]`."""
|
|
252
|
+
assert q.dim() == 2, q.shape
|
|
253
|
+
n_env = q.shape[1]
|
|
254
|
+
dtype, device = q.dtype, q.device
|
|
255
|
+
positions: list[torch.Tensor] = []
|
|
256
|
+
quats: list[torch.Tensor] = []
|
|
257
|
+
for i, body in enumerate(self.bodies):
|
|
258
|
+
parent = self.parents[i]
|
|
259
|
+
if parent < 0:
|
|
260
|
+
parent_p = _zero_vec(n_env, dtype, device)
|
|
261
|
+
parent_q = _identity_quat(n_env, dtype, device)
|
|
262
|
+
else:
|
|
263
|
+
parent_p = positions[parent]
|
|
264
|
+
parent_q = quats[parent]
|
|
265
|
+
rel_pos = self.body_pos[i].to(dtype=dtype, device=device)[:, None].expand(3, n_env)
|
|
266
|
+
rel_quat = self.body_quat[i].to(dtype=dtype, device=device)[:, None].expand(4, n_env)
|
|
267
|
+
base_p = parent_p + _quat_rotate(parent_q, rel_pos)
|
|
268
|
+
base_q = _quat_normalize(_quat_mul(parent_q, rel_quat))
|
|
269
|
+
p_i, q_i = self._apply_joint(i, body, base_p, base_q, q, n_env, dtype, device)
|
|
270
|
+
positions.append(p_i)
|
|
271
|
+
quats.append(q_i)
|
|
272
|
+
return positions, quats
|
|
273
|
+
|
|
274
|
+
def _apply_joint(self, i, body, base_p, base_q, q, n_env, dtype, device):
|
|
275
|
+
"""Compose body i's own joint transform onto its attach frame (base_p, base_q).
|
|
276
|
+
|
|
277
|
+
Extracted verbatim from body_poses so the reduced FK (body_poses_subset) shares ONE
|
|
278
|
+
implementation of the joint semantics -- same expressions, same op order, so the full and the
|
|
279
|
+
reduced path agree to float roundoff on every joint type."""
|
|
280
|
+
qa = int(body["qadr"])
|
|
281
|
+
if "joints" in body:
|
|
282
|
+
rel_p = _zero_vec(n_env, dtype, device)
|
|
283
|
+
rel_q = _identity_quat(n_env, dtype, device)
|
|
284
|
+
for k, prim in enumerate(body["joints"]):
|
|
285
|
+
axis = self.joint_axes[i][k].to(dtype=dtype, device=device)
|
|
286
|
+
typ = prim["type"]
|
|
287
|
+
if typ in ("hinge", "revolute"):
|
|
288
|
+
rel_q = _quat_normalize(_quat_mul(rel_q, _quat_axis_angle(axis, q[qa + k])))
|
|
289
|
+
elif typ in ("slide", "prismatic"):
|
|
290
|
+
rel_p = rel_p + _quat_rotate(rel_q, axis[:, None] * q[qa + k][None, :])
|
|
291
|
+
else:
|
|
292
|
+
raise AssertionError(typ)
|
|
293
|
+
return base_p + _quat_rotate(base_q, rel_p), _quat_normalize(_quat_mul(base_q, rel_q))
|
|
294
|
+
joint = body["joint"]
|
|
295
|
+
coupled = body.get("coupled")
|
|
296
|
+
if coupled is not None: # driven ("mimic") joint: angle = poly(q[master_qadr]); mirrors the engine FK
|
|
297
|
+
mq = int(coupled["master_qadr"]); c = coupled["coef"]
|
|
298
|
+
qm = q[mq] # (n_env,) master coord
|
|
299
|
+
theta = c[0] + qm * (c[1] + qm * (c[2] + qm * (c[3] + qm * c[4]))) # Horner: Σ c_k q_m^k
|
|
300
|
+
axis = self.body_axis[i].to(dtype=dtype, device=device)
|
|
301
|
+
if joint in ("hinge", "revolute"):
|
|
302
|
+
return base_p, _quat_normalize(_quat_mul(base_q, _quat_axis_angle(axis, theta)))
|
|
303
|
+
assert joint in ("slide", "prismatic"), joint
|
|
304
|
+
return base_p + _quat_rotate(base_q, axis[:, None] * theta[None, :]), base_q
|
|
305
|
+
if joint == "free":
|
|
306
|
+
# compose the free joint (pos, quat) with the body attach frame (base_p/base_q =
|
|
307
|
+
# parent o pos_tree/quat_tree), matching the engine chain-FK. Using the raw free
|
|
308
|
+
# pos/quat drops quat_tree -> a non-identity root (e.g. myoLeg26's +90deg-about-x
|
|
309
|
+
# y-up->z-up map) is placed wrong. Mirrors viz.dnrec_io.fk_poses.
|
|
310
|
+
return (base_p + _quat_rotate(base_q, q[qa : qa + 3]),
|
|
311
|
+
_quat_normalize(_quat_mul(base_q, q[qa + 3 : qa + 7])))
|
|
312
|
+
if joint == "ball":
|
|
313
|
+
return base_p, _quat_normalize(_quat_mul(base_q, q[qa : qa + 4]))
|
|
314
|
+
if joint in ("hinge", "revolute"):
|
|
315
|
+
axis = self.body_axis[i].to(dtype=dtype, device=device)
|
|
316
|
+
return base_p, _quat_normalize(_quat_mul(base_q, _quat_axis_angle(axis, q[qa])))
|
|
317
|
+
if joint in ("slide", "prismatic"):
|
|
318
|
+
axis = self.body_axis[i].to(dtype=dtype, device=device)
|
|
319
|
+
return base_p + _quat_rotate(base_q, axis[:, None] * q[qa][None, :]), base_q
|
|
320
|
+
assert joint == "fixed", joint
|
|
321
|
+
return base_p, base_q
|
|
322
|
+
|
|
323
|
+
# ---------------------------------------------------------------------------------------------
|
|
324
|
+
# Reduced FK: only the frames that actually move, + welded subtrees folded into composite bodies.
|
|
325
|
+
#
|
|
326
|
+
# body_poses() walks EVERY body in a Python loop; on the full-body models most bodies are WELDED
|
|
327
|
+
# (`fixed`, 0 dof) so their pose is a CONSTANT transform of the nearest moving ancestor and their
|
|
328
|
+
# mass is a CONSTANT contribution to that ancestor's composite inertia. Recomputing them per control
|
|
329
|
+
# step is pure launch overhead: measured (2026-07-27, live SAPO fullbody run) body_poses = 18.3k
|
|
330
|
+
# aten dispatches fwd / 28.7k bwd and the imitation _com another 10.5k -- together ~90% of training
|
|
331
|
+
# wall-clock, with the GPU idle 64% of the time. armless_ball has 27 moving frames out of 156 bodies.
|
|
332
|
+
#
|
|
333
|
+
# The reduced path pre-composes the welded chains ONCE (in f64, at build time) and then evaluates
|
|
334
|
+
# only the moving frames plus whatever fixed bodies a caller explicitly asks for. The COM is the
|
|
335
|
+
# exact same sum, regrouped by composite body -- not an approximation (verified <1e-7 in f32).
|
|
336
|
+
# ---------------------------------------------------------------------------------------------
|
|
337
|
+
@staticmethod
|
|
338
|
+
def _body_is_moving(body) -> bool:
|
|
339
|
+
return ("coupled" in body) or ("joints" in body) or body.get("joint") not in ("fixed", None)
|
|
340
|
+
|
|
341
|
+
def _build_reduced_fk(self):
|
|
342
|
+
nb = len(self.bodies)
|
|
343
|
+
moving = [i for i, b in enumerate(self.bodies) if self._body_is_moving(b)]
|
|
344
|
+
# nearest MOVING ancestor of every body (-1 = welded straight to the world)
|
|
345
|
+
anc = [-1] * nb
|
|
346
|
+
for i in range(nb):
|
|
347
|
+
j = self.parents[i]
|
|
348
|
+
while j >= 0 and not self._body_is_moving(self.bodies[j]):
|
|
349
|
+
j = self.parents[j]
|
|
350
|
+
anc[i] = j
|
|
351
|
+
# constant transform anc(i)-frame -> body i ATTACH frame: compose (pos, quat) of every body on
|
|
352
|
+
# the path (anc(i), i], f64 for accuracy, cast at use.
|
|
353
|
+
const_p, const_q = [None] * nb, [None] * nb
|
|
354
|
+
for i in range(nb):
|
|
355
|
+
chain = []
|
|
356
|
+
j = i
|
|
357
|
+
while j != anc[i]:
|
|
358
|
+
chain.append(j)
|
|
359
|
+
j = self.parents[j]
|
|
360
|
+
p = torch.zeros(3, dtype=torch.float64, device=self.device)
|
|
361
|
+
qq = torch.tensor([1.0, 0.0, 0.0, 0.0], dtype=torch.float64, device=self.device)
|
|
362
|
+
for j in reversed(chain):
|
|
363
|
+
bp = self.body_pos[j].to(torch.float64)
|
|
364
|
+
bq = self.body_quat[j].to(torch.float64)
|
|
365
|
+
p = p + _quat_rotate(qq[:, None], bp[:, None]).squeeze(1)
|
|
366
|
+
qq = _quat_normalize(_quat_mul(qq[:, None], bq[:, None]).squeeze(1))
|
|
367
|
+
const_p[i], const_q[i] = p, qq
|
|
368
|
+
self._fk_moving = moving # topological (dnmodel body order is parent-first)
|
|
369
|
+
self._fk_anc = anc
|
|
370
|
+
self._fk_const_p, self._fk_const_q = const_p, const_q
|
|
371
|
+
# composite mass + COM offset per moving frame (welded descendants folded in). Bodies welded to
|
|
372
|
+
# the world (anc == -1) contribute a CONSTANT world moment.
|
|
373
|
+
mass = [float(b.get("mass", 0.0)) for b in self.bodies]
|
|
374
|
+
com = [torch.tensor(b.get("com", [0.0, 0.0, 0.0]), dtype=torch.float64, device=self.device)
|
|
375
|
+
for b in self.bodies]
|
|
376
|
+
acc_m = {f: 0.0 for f in moving}
|
|
377
|
+
acc_c = {f: torch.zeros(3, dtype=torch.float64, device=self.device) for f in moving}
|
|
378
|
+
world_moment = torch.zeros(3, dtype=torch.float64, device=self.device)
|
|
379
|
+
for i in range(nb):
|
|
380
|
+
if mass[i] <= 0.0:
|
|
381
|
+
continue
|
|
382
|
+
# HOST frame = the frame body i is rigidly fixed to = itself when it moves, else its nearest
|
|
383
|
+
# moving ancestor. const_p/const_q map anc(i)'s POSE frame to i's ATTACH frame, which for a
|
|
384
|
+
# WELDED body IS its pose frame; a MOVING body sits at its own frame (its joint transform is
|
|
385
|
+
# applied at FK time), so its offset is the identity.
|
|
386
|
+
if self._body_is_moving(self.bodies[i]):
|
|
387
|
+
host, c_in_f = i, com[i]
|
|
388
|
+
else:
|
|
389
|
+
host = anc[i]
|
|
390
|
+
c_in_f = const_p[i] + _quat_rotate(const_q[i][:, None], com[i][:, None]).squeeze(1)
|
|
391
|
+
if host < 0:
|
|
392
|
+
world_moment = world_moment + mass[i] * c_in_f
|
|
393
|
+
continue
|
|
394
|
+
acc_m[host] += mass[i]
|
|
395
|
+
acc_c[host] = acc_c[host] + mass[i] * c_in_f
|
|
396
|
+
self._com_terms = [(f, acc_m[f], acc_c[f] / acc_m[f]) for f in moving if acc_m[f] > 0.0]
|
|
397
|
+
self._com_world_moment = world_moment
|
|
398
|
+
# Decided ONCE here: testing the tensor per call was a host sync, and it would break a compiled trace.
|
|
399
|
+
self._com_has_world = bool(float(world_moment.abs().sum()) > 0.0)
|
|
400
|
+
self._mass_tot = sum(mass)
|
|
401
|
+
self._fk_cache = {} # (dtype, n_env) -> broadcast constants, see _fk_consts
|
|
402
|
+
|
|
403
|
+
def _fk_consts(self, dtype, n_env):
|
|
404
|
+
"""Per-(dtype, n_env) broadcast views of the FK constants. Built once: casting + unsqueeze +
|
|
405
|
+
expand on every call is ~4 extra dispatches per frame, which is exactly the overhead this path
|
|
406
|
+
exists to remove (n_env is fixed for the lifetime of a training run, so the cache always hits)."""
|
|
407
|
+
key = (dtype, n_env)
|
|
408
|
+
c = self._fk_cache.get(key)
|
|
409
|
+
if c is None:
|
|
410
|
+
cp = [p.to(dtype=dtype)[:, None].expand(3, n_env) for p in self._fk_const_p]
|
|
411
|
+
cq = [p.to(dtype=dtype)[:, None].expand(4, n_env) for p in self._fk_const_q]
|
|
412
|
+
com_m = torch.tensor([t[1] for t in self._com_terms], dtype=dtype, device=self.device)
|
|
413
|
+
com_c = (torch.stack([t[2] for t in self._com_terms]).to(dtype=dtype)[:, :, None]
|
|
414
|
+
if self._com_terms else None) # (F,3,1), broadcasts over n_env
|
|
415
|
+
com_w = self._com_world_moment.to(dtype=dtype)[:, None]
|
|
416
|
+
# contracted forms of the per-body CONSTANTS (welded-chain quat/offset + joint axes)
|
|
417
|
+
qm = [_qmul_right_matrix(p.to(dtype=dtype)) for p in self._fk_const_q]
|
|
418
|
+
qa = [_qrot_form(p.to(dtype=dtype)) for p in self._fk_const_p]
|
|
419
|
+
ax = []
|
|
420
|
+
for i, b in enumerate(self.bodies):
|
|
421
|
+
if self.joint_axes[i] is not None:
|
|
422
|
+
ax.append([(_qmul_right_matrix(torch.cat([torch.zeros(1, dtype=dtype, device=self.device),
|
|
423
|
+
a.to(dtype=dtype)])),
|
|
424
|
+
_qrot_form(a.to(dtype=dtype))) for a in self.joint_axes[i]])
|
|
425
|
+
elif self.body_axis[i] is not None:
|
|
426
|
+
a = self.body_axis[i].to(dtype=dtype)
|
|
427
|
+
ax.append((_qmul_right_matrix(torch.cat([torch.zeros(1, dtype=dtype, device=self.device), a])),
|
|
428
|
+
_qrot_form(a)))
|
|
429
|
+
else:
|
|
430
|
+
ax.append(None)
|
|
431
|
+
c = (cp, cq, com_m[:, None, None], com_c, com_w, qm, qa, ax,
|
|
432
|
+
_QMUL_T.to(device=self.device, dtype=dtype))
|
|
433
|
+
# _QMUL_T is a module-level CPU constant: every contraction helper must place it on the
|
|
434
|
+
# model's device or the first CUDA call dies inside einsum (a CPU-only test cannot see this).
|
|
435
|
+
assert all(t.device.type == self.device.type for t in qm), (qm[0].device, self.device)
|
|
436
|
+
self._fk_cache[key] = c
|
|
437
|
+
return c
|
|
438
|
+
|
|
439
|
+
def _apply_joint_fast(self, i, body, base_p, base_q, q, K):
|
|
440
|
+
"""_apply_joint with the constant-folded quaternion contractions (see the module header). Same
|
|
441
|
+
function, ~4x fewer dispatches; test_reduced_fk_parity checks it against _apply_joint."""
|
|
442
|
+
_, _, _, _, _, _, _, ax, T = K
|
|
443
|
+
qa_i = int(body["qadr"])
|
|
444
|
+
|
|
445
|
+
def _spin(qq, axM, theta): # qq (x) (cos(th/2), sin(th/2)*axis), axis folded into axM
|
|
446
|
+
half = 0.5 * theta
|
|
447
|
+
return torch.cos(half).unsqueeze(0) * qq + torch.sin(half).unsqueeze(0) * _cmm(axM, qq)
|
|
448
|
+
|
|
449
|
+
if "joints" in body:
|
|
450
|
+
rel_p = None
|
|
451
|
+
rel_q = None
|
|
452
|
+
for k, prim in enumerate(body["joints"]):
|
|
453
|
+
axM, axA = ax[i][k]
|
|
454
|
+
typ = prim["type"]
|
|
455
|
+
if typ in ("hinge", "revolute"):
|
|
456
|
+
if rel_q is None: # identity (x) spin == spin about the axis alone
|
|
457
|
+
half = 0.5 * q[qa_i + k]
|
|
458
|
+
rel_q = torch.cat([torch.cos(half).unsqueeze(0),
|
|
459
|
+
self.joint_axes[i][k].to(dtype=q.dtype)[:, None]
|
|
460
|
+
* torch.sin(half).unsqueeze(0)], 0)
|
|
461
|
+
else:
|
|
462
|
+
rel_q = _quat_normalize(_spin(rel_q, axM, q[qa_i + k]))
|
|
463
|
+
elif typ in ("slide", "prismatic"):
|
|
464
|
+
step = (self.joint_axes[i][k].to(dtype=q.dtype)[:, None] * q[qa_i + k].unsqueeze(0)
|
|
465
|
+
if rel_q is None else _qrot_const(axA, rel_q) * q[qa_i + k].unsqueeze(0))
|
|
466
|
+
rel_p = step if rel_p is None else rel_p + step
|
|
467
|
+
else:
|
|
468
|
+
raise AssertionError(typ)
|
|
469
|
+
p = base_p if rel_p is None else base_p + _quat_rotate(base_q, rel_p)
|
|
470
|
+
qq = base_q if rel_q is None else _quat_normalize(_qmul_fast(base_q, rel_q, T))
|
|
471
|
+
return p, qq
|
|
472
|
+
joint = body["joint"]
|
|
473
|
+
coupled = body.get("coupled")
|
|
474
|
+
if coupled is not None:
|
|
475
|
+
mq = int(coupled["master_qadr"]); c = coupled["coef"]
|
|
476
|
+
qm_ = q[mq]
|
|
477
|
+
theta = c[0] + qm_ * (c[1] + qm_ * (c[2] + qm_ * (c[3] + qm_ * c[4])))
|
|
478
|
+
axM, axA = ax[i]
|
|
479
|
+
if joint in ("hinge", "revolute"):
|
|
480
|
+
return base_p, _quat_normalize(_spin(base_q, axM, theta))
|
|
481
|
+
assert joint in ("slide", "prismatic"), joint
|
|
482
|
+
return base_p + _qrot_const(axA, base_q) * theta.unsqueeze(0), base_q
|
|
483
|
+
if joint == "free":
|
|
484
|
+
return (base_p + _quat_rotate(base_q, q[qa_i:qa_i + 3]),
|
|
485
|
+
_quat_normalize(_qmul_fast(base_q, q[qa_i + 3:qa_i + 7], T)))
|
|
486
|
+
if joint == "ball":
|
|
487
|
+
return base_p, _quat_normalize(_qmul_fast(base_q, q[qa_i:qa_i + 4], T))
|
|
488
|
+
if joint in ("hinge", "revolute"):
|
|
489
|
+
return base_p, _quat_normalize(_spin(base_q, ax[i][0], q[qa_i]))
|
|
490
|
+
if joint in ("slide", "prismatic"):
|
|
491
|
+
return base_p + _qrot_const(ax[i][1], base_q) * q[qa_i].unsqueeze(0), base_q
|
|
492
|
+
assert joint == "fixed", joint
|
|
493
|
+
return base_p, base_q
|
|
494
|
+
|
|
495
|
+
def body_poses_subset(self, q: torch.Tensor, bodies=(), need_com: bool = False):
|
|
496
|
+
"""Reduced FK. Returns `(pos, quat, com)` where pos/quat are DICTS keyed by body index -- the
|
|
497
|
+
requested `bodies` are always present (plus every moving frame that had to be evaluated) -- and
|
|
498
|
+
`com` is the whole-body centre of mass `(3, n_env)` or None when `need_com` is False.
|
|
499
|
+
|
|
500
|
+
Mathematically identical to body_poses()/the per-body COM sum; only the grouping differs, so
|
|
501
|
+
results match to float roundoff (gated by python/tests/test_reduced_fk_parity.py). With
|
|
502
|
+
DN_FK_COMPILE=1 the same function runs compiled (see __init__; gated by
|
|
503
|
+
tools/fk_compile_gate.py)."""
|
|
504
|
+
# Compiled ONLY where it pays: a call whose output enters the backward. The op exists to cut autograd
|
|
505
|
+
# nodes; a no-grad call (reset grounding, calibration, eval) has none, and the reset path calls with a
|
|
506
|
+
# different batch size every time, which recompiled until dynamo's recompile limit killed the run
|
|
507
|
+
# (2026-10-01, fb_..._e2000_fk_s1 at ep1). One training signature -> one compile.
|
|
508
|
+
if not (self._fk_compile and torch.is_grad_enabled() and q.requires_grad):
|
|
509
|
+
return self._body_poses_subset_eager(q, bodies, need_com)
|
|
510
|
+
assert q.dim() == 2, q.shape
|
|
511
|
+
want = tuple(sorted({int(b) for b in bodies}))
|
|
512
|
+
key = (want, bool(need_com), q.dtype, int(q.shape[1]), q.device.type)
|
|
513
|
+
fn = self._fk_compiled.get(key)
|
|
514
|
+
if fn is None:
|
|
515
|
+
self._fk_consts(q.dtype, int(q.shape[1])) # build the constant cache EAGERLY: the trace reads it
|
|
516
|
+
fn = torch.compile(lambda qq: self._body_poses_subset_eager(qq, want, key[1]),
|
|
517
|
+
fullgraph=True, dynamic=False)
|
|
518
|
+
self._fk_compiled[key] = fn
|
|
519
|
+
return fn(q)
|
|
520
|
+
|
|
521
|
+
def _body_poses_subset_eager(self, q: torch.Tensor, bodies=(), need_com: bool = False):
|
|
522
|
+
assert q.dim() == 2, q.shape
|
|
523
|
+
n_env = q.shape[1]
|
|
524
|
+
dtype, device = q.dtype, q.device
|
|
525
|
+
want = {int(b) for b in bodies}
|
|
526
|
+
# which moving frames must be evaluated: every moving ancestor chain of a requested body, plus
|
|
527
|
+
# ALL of them when the COM is needed (the composite sum spans the whole body).
|
|
528
|
+
need_moving = set(self._fk_moving) if need_com else set()
|
|
529
|
+
for b in want:
|
|
530
|
+
j = b if self._body_is_moving(self.bodies[b]) else self._fk_anc[b]
|
|
531
|
+
while j >= 0:
|
|
532
|
+
if j in need_moving:
|
|
533
|
+
break
|
|
534
|
+
need_moving.add(j)
|
|
535
|
+
j = self._fk_anc[j]
|
|
536
|
+
K = self._fk_consts(dtype, n_env)
|
|
537
|
+
cp_all, cq_all, com_m, com_c, com_w, qm_all, qa_all = K[0], K[1], K[2], K[3], K[4], K[5], K[6]
|
|
538
|
+
pos: dict[int, torch.Tensor] = {}
|
|
539
|
+
quat: dict[int, torch.Tensor] = {}
|
|
540
|
+
for f in self._fk_moving: # parent-first order
|
|
541
|
+
if f not in need_moving:
|
|
542
|
+
continue
|
|
543
|
+
a = self._fk_anc[f]
|
|
544
|
+
if a < 0: # welded straight to the world: the constant IS the frame
|
|
545
|
+
base_p, base_q = cp_all[f], cq_all[f]
|
|
546
|
+
else:
|
|
547
|
+
base_p = pos[a] + _qrot_const(qa_all[f], quat[a])
|
|
548
|
+
base_q = _quat_normalize(_qmul_const(qm_all[f], quat[a]))
|
|
549
|
+
pos[f], quat[f] = self._apply_joint_fast(f, self.bodies[f], base_p, base_q, q, K)
|
|
550
|
+
for b in want: # requested WELDED bodies: one constant compose
|
|
551
|
+
if b in pos:
|
|
552
|
+
continue
|
|
553
|
+
a = self._fk_anc[b]
|
|
554
|
+
if a < 0:
|
|
555
|
+
pos[b], quat[b] = cp_all[b], cq_all[b]
|
|
556
|
+
else:
|
|
557
|
+
pos[b] = pos[a] + _qrot_const(qa_all[b], quat[a])
|
|
558
|
+
quat[b] = _quat_normalize(_qmul_const(qm_all[b], quat[a]))
|
|
559
|
+
com = None
|
|
560
|
+
if need_com:
|
|
561
|
+
frames = [t[0] for t in self._com_terms]
|
|
562
|
+
P = torch.stack([pos[f] for f in frames], 0) # (F,3,n)
|
|
563
|
+
Q = torch.stack([quat[f] for f in frames], 0) # (F,4,n)
|
|
564
|
+
com = ((P + _quat_rotate_batched(Q, com_c)) * com_m).sum(0) # mass-weighted, batched over F
|
|
565
|
+
if self._com_has_world:
|
|
566
|
+
com = com + com_w
|
|
567
|
+
com = com / self._mass_tot
|
|
568
|
+
return pos, quat, com
|
|
569
|
+
|
|
570
|
+
# ------------------------------------------------------------------ heading (yaw) frame
|
|
571
|
+
# A locomotion policy should not care WHICH COMPASS DIRECTION it walks in. Measured on the v3 reward,
|
|
572
|
+
# 51% of the error signal was expressed in WORLD axes -- the end-effector offsets, the COM offset, the
|
|
573
|
+
# end-effector velocities and every FK quaternion -- so the reward demanded the clip's absolute heading,
|
|
574
|
+
# and the observation carried the absolute root quaternion on top of that. Both are removed by working
|
|
575
|
+
# in the root's own HEADING frame: the rotation about world z that the body currently faces.
|
|
576
|
+
#
|
|
577
|
+
# Yaw is taken as the ZYX-euler heading, atan2(2(wz+xy), 1-2(y^2+z^2)). That is singular at pitch = +-90
|
|
578
|
+
# deg; a walking pelvis stays far from it (measured |lean_FWD| <= 23 deg even on the falls), and the
|
|
579
|
+
# alternative -- projecting the body x-axis onto the ground plane -- has the same singularity in the same
|
|
580
|
+
# place. Not guarded, but named.
|
|
581
|
+
|
|
582
|
+
@staticmethod
|
|
583
|
+
def yaw_quat(q: torch.Tensor) -> torch.Tensor:
|
|
584
|
+
"""The yaw-only quaternion of q (4,n): the heading, with roll and pitch removed."""
|
|
585
|
+
w, x, y, z = q[0], q[1], q[2], q[3]
|
|
586
|
+
half = 0.5 * torch.atan2(2.0 * (w * z + x * y), 1.0 - 2.0 * (y * y + z * z))
|
|
587
|
+
zero = torch.zeros_like(half)
|
|
588
|
+
return torch.stack((torch.cos(half), zero, zero, torch.sin(half)), 0)
|
|
589
|
+
|
|
590
|
+
@classmethod
|
|
591
|
+
def yaw_free_quat(cls, q: torch.Tensor) -> torch.Tensor:
|
|
592
|
+
"""conj(yaw(q)) (x) q -- the orientation with the heading divided out, so only roll and pitch remain.
|
|
593
|
+
Two bodies facing different compass directions but tilted identically give the SAME value."""
|
|
594
|
+
yq = cls.yaw_quat(q)
|
|
595
|
+
conj = torch.stack((yq[0], -yq[1], -yq[2], -yq[3]), 0)
|
|
596
|
+
return _quat_mul(conj, q)
|
|
597
|
+
|
|
598
|
+
@classmethod
|
|
599
|
+
def yaw_conj(cls, q_root: torch.Tensor) -> torch.Tensor:
|
|
600
|
+
"""conj(yaw(q_root)) -- the rotation taking a world vector INTO q_root's heading frame.
|
|
601
|
+
|
|
602
|
+
Exposed separately so a caller mapping SEVERAL vectors into ONE body's heading frame pays the
|
|
603
|
+
atan2/cos/sin once instead of once per vector. The v3 reward maps five (two feet, the COM, two foot
|
|
604
|
+
velocities) into the root's frame, so four of the five were redundant.
|
|
605
|
+
"""
|
|
606
|
+
yq = cls.yaw_quat(q_root)
|
|
607
|
+
return torch.stack((yq[0], -yq[1], -yq[2], -yq[3]), 0)
|
|
608
|
+
|
|
609
|
+
@staticmethod
|
|
610
|
+
def rotate_by_yaw_conj(conj: torch.Tensor, v: torch.Tensor) -> torch.Tensor:
|
|
611
|
+
"""Apply a `yaw_conj` result to v (3,n). Split from to_yaw_frame so `conj` can be hoisted."""
|
|
612
|
+
return _quat_rotate(conj, v)
|
|
613
|
+
|
|
614
|
+
@classmethod
|
|
615
|
+
def to_yaw_frame(cls, q_root: torch.Tensor, v: torch.Tensor) -> torch.Tensor:
|
|
616
|
+
"""Express the world vector v (3,n) in the heading frame of q_root (4,n)."""
|
|
617
|
+
return cls.rotate_by_yaw_conj(cls.yaw_conj(q_root), v)
|
|
618
|
+
|
|
619
|
+
def body_velocities_from_poses(self, pos, quat, qd: torch.Tensor, bodies):
|
|
620
|
+
"""World LINEAR velocity of `bodies`, assembled from the frames body_poses_subset ALREADY evaluated.
|
|
621
|
+
|
|
622
|
+
`v_b = sum_f [ l_f + w_f x (p_b - p_f) ]` over the moving ancestor chain of b -- the jacobian columns
|
|
623
|
+
of the chain, contracted against qd on the spot. Every quantity it needs is in the primal FK output:
|
|
624
|
+
|
|
625
|
+
hinge the world axis is `R_f * axis`, and `R_f` is safe to use even though it already contains this
|
|
626
|
+
joint's own rotation, because rotating an axis about ITSELF is the identity. `pos[f]` is the
|
|
627
|
+
joint origin (a hinge does not translate its frame).
|
|
628
|
+
ball `w_f = R_f * qd[vadr:vadr+3]` -- the rate is in the CHILD frame, which is what R_f maps out
|
|
629
|
+
of; `pos[f]` is again the origin.
|
|
630
|
+
slide pure translation, `R_f * axis * qd` -- no origin needed.
|
|
631
|
+
free `[w_body; v_body]` with S = I6 (core/dyn/articulated.h), both in the child frame, so
|
|
632
|
+
`w_f = R_f * qd[v:v+3]` and `l_f = R_f * qd[v+3:v+6]` about the frame origin `pos[f]`.
|
|
633
|
+
|
|
634
|
+
WHY NOT torch.func.jvp THROUGH THE FK. That is the obvious one-liner and it works (it was implemented
|
|
635
|
+
and gated first), but measured on armless_ball / 64 env / CPU it cost **+320%** on reward()+backward:
|
|
636
|
+
forward-mode doubles the dual arithmetic AND adds a functorch dispatch layer over every op in the FK.
|
|
637
|
+
This path instead reuses the primal and adds ~6 ops per frame in TWO chains, so it is a rounding error
|
|
638
|
+
against the FK it borrows from. Same value: gated against a central difference of the FK along the
|
|
639
|
+
same tangent.
|
|
640
|
+
|
|
641
|
+
`qd` is the engine's velocity vector, NOT a q-space tangent -- no chart map is involved here, which is
|
|
642
|
+
the other reason this is cheaper.
|
|
643
|
+
"""
|
|
644
|
+
n_env = qd.shape[1]
|
|
645
|
+
out = {}
|
|
646
|
+
for b in bodies:
|
|
647
|
+
b = int(b)
|
|
648
|
+
p_b = pos[b]
|
|
649
|
+
v = torch.zeros_like(p_b)
|
|
650
|
+
f = b if self._body_is_moving(self.bodies[b]) else self._fk_anc[b]
|
|
651
|
+
while f >= 0:
|
|
652
|
+
body = self.bodies[f]
|
|
653
|
+
assert "coupled" not in body, (
|
|
654
|
+
f"body {f} on the chain of {b} is a COUPLED mimic joint: its rate is c'(q_master)*qd_master, "
|
|
655
|
+
"not a dof of its own, and this assembly would silently drop it")
|
|
656
|
+
assert self.joint_axes[f] is None, (
|
|
657
|
+
f"body {f} on the chain of {b} is a composite joint STACK: its sub-joints have "
|
|
658
|
+
"intermediate frames that the reduced FK does not materialise, so their origins are "
|
|
659
|
+
"unavailable here")
|
|
660
|
+
jt = body["joint"]
|
|
661
|
+
va = int(body["vadr"])
|
|
662
|
+
R = quat[f]
|
|
663
|
+
if jt in ("free", "freejoint"):
|
|
664
|
+
w = _quat_rotate(R, qd[va:va + 3])
|
|
665
|
+
v = v + _quat_rotate(R, qd[va + 3:va + 6]) + torch.cross(w, p_b - pos[f], dim=0)
|
|
666
|
+
elif jt == "ball":
|
|
667
|
+
w = _quat_rotate(R, qd[va:va + 3])
|
|
668
|
+
v = v + torch.cross(w, p_b - pos[f], dim=0)
|
|
669
|
+
elif jt in ("hinge", "revolute"):
|
|
670
|
+
ax = self.body_axis[f].to(dtype=p_b.dtype)[:, None].expand(3, n_env)
|
|
671
|
+
v = v + torch.cross(_quat_rotate(R, ax) * qd[va], p_b - pos[f], dim=0)
|
|
672
|
+
elif jt in ("slide", "prismatic"):
|
|
673
|
+
ax = self.body_axis[f].to(dtype=p_b.dtype)[:, None].expand(3, n_env)
|
|
674
|
+
v = v + _quat_rotate(R, ax) * qd[va]
|
|
675
|
+
else:
|
|
676
|
+
raise AssertionError((f, jt))
|
|
677
|
+
f = self._fk_anc[f]
|
|
678
|
+
out[b] = v
|
|
679
|
+
return out
|
|
680
|
+
|
|
681
|
+
def body_twists_from_poses(self, pos, quat, q: torch.Tensor, qd: torch.Tensor, bodies):
|
|
682
|
+
"""World LINEAR and ANGULAR velocity `(v_b, w_b)` of `bodies` (see _body_twists_from_poses_eager). With
|
|
683
|
+
DN_TWIST_COMPILE=1 a call whose outputs enter the backward runs compiled, once per call signature; any
|
|
684
|
+
other call (no grad, eval, reset) stays eager, as body_poses_subset does."""
|
|
685
|
+
if not (self._tw_compile and torch.is_grad_enabled() and (q.requires_grad or qd.requires_grad)):
|
|
686
|
+
return self._body_twists_from_poses_eager(pos, quat, q, qd, bodies)
|
|
687
|
+
want = tuple(int(b) for b in bodies)
|
|
688
|
+
frames = tuple(sorted(int(k) for k in (pos.keys() if isinstance(pos, dict) else range(len(pos)))))
|
|
689
|
+
key = (want, frames, q.dtype, int(q.shape[1]), q.device.type)
|
|
690
|
+
fn = self._tw_compiled.get(key)
|
|
691
|
+
if fn is None:
|
|
692
|
+
fn = torch.compile(lambda P, Q, qq, qqd: self._body_twists_from_poses_eager(P, Q, qq, qqd, want),
|
|
693
|
+
fullgraph=True, dynamic=False)
|
|
694
|
+
self._tw_compiled[key] = fn
|
|
695
|
+
return fn(pos, quat, q, qd)
|
|
696
|
+
|
|
697
|
+
def _body_twists_from_poses_eager(self, pos, quat, q: torch.Tensor, qd: torch.Tensor, bodies):
|
|
698
|
+
"""World LINEAR and ANGULAR velocity `(v_b, w_b)` of `bodies`, from the frames body_poses_subset evaluated.
|
|
699
|
+
|
|
700
|
+
body_velocities_from_poses plus two things it refuses: the angular velocity, and COUPLED ("mimic")
|
|
701
|
+
joints on the chain. A coupled joint's angle is `theta = sum_k c_k q_m^k` of its master (see the FK), so
|
|
702
|
+
its rate is `theta' = (c_1 + 2 c_2 q_m + 3 c_3 q_m^2 + 4 c_4 q_m^3) * qd[master_vadr]`, and it then
|
|
703
|
+
contributes exactly like an independent hinge / slide with that rate. MuscleMimic's site velocities need
|
|
704
|
+
this on the full body, whose spine levels and shoulder girdle are coupled to their masters.
|
|
705
|
+
|
|
706
|
+
`w_b` is the sum of the chain's joint angular velocities (world frame); hinge / ball / free conventions are
|
|
707
|
+
body_velocities_from_poses'. Composite joint stacks are still refused for the same reason.
|
|
708
|
+
|
|
709
|
+
SHARED, not per body: each moving frame's twist at its own origin is built ONCE from its moving ancestor's,
|
|
710
|
+
`v_f = v_a + w_a x (p_f - p_a) + l_f`, `w_f = w_a + w_f(joint)`, in topological order, and a requested body reads
|
|
711
|
+
its frame's twist (shifted to its own origin when it is welded to that frame). The same sum as walking every
|
|
712
|
+
body's chain separately (which re-walked the shared spine and pelvis for each of 17 sites: ~10x the reward's
|
|
713
|
+
dispatches), only regrouped.
|
|
714
|
+
"""
|
|
715
|
+
n_env = qd.shape[1]
|
|
716
|
+
want = [int(b) for b in bodies]
|
|
717
|
+
frame_of = {b: (b if self._body_is_moving(self.bodies[b]) else self._fk_anc[b]) for b in want}
|
|
718
|
+
frames = set()
|
|
719
|
+
for f in frame_of.values():
|
|
720
|
+
while f >= 0:
|
|
721
|
+
frames.add(f)
|
|
722
|
+
f = self._fk_anc[f]
|
|
723
|
+
tw = {}
|
|
724
|
+
for f in sorted(frames): # topological: a moving ancestor always has the lower index
|
|
725
|
+
body = self.bodies[f]
|
|
726
|
+
assert self.joint_axes[f] is None, (
|
|
727
|
+
f"body {f} is a composite joint STACK: its sub-joints have intermediate frames that the reduced FK "
|
|
728
|
+
"does not materialise, so their origins are unavailable here")
|
|
729
|
+
a = self._fk_anc[f]
|
|
730
|
+
if a >= 0:
|
|
731
|
+
v_a, w_a = tw[a]
|
|
732
|
+
v = v_a + torch.cross(w_a, pos[f] - pos[a], dim=0)
|
|
733
|
+
w = w_a
|
|
734
|
+
else:
|
|
735
|
+
v = torch.zeros_like(pos[f])
|
|
736
|
+
w = torch.zeros_like(pos[f])
|
|
737
|
+
jt = body["joint"]
|
|
738
|
+
R = quat[f]
|
|
739
|
+
coupled = body.get("coupled")
|
|
740
|
+
if coupled is not None:
|
|
741
|
+
c = coupled["coef"]
|
|
742
|
+
qm = q[int(coupled["master_qadr"])]
|
|
743
|
+
rate = (c[1] + qm * (2.0 * c[2] + qm * (3.0 * c[3] + qm * 4.0 * c[4]))) * qd[int(coupled["master_vadr"])]
|
|
744
|
+
else:
|
|
745
|
+
rate = None
|
|
746
|
+
if jt in ("free", "freejoint"):
|
|
747
|
+
va = int(body["vadr"])
|
|
748
|
+
w = w + _quat_rotate(R, qd[va:va + 3])
|
|
749
|
+
v = v + _quat_rotate(R, qd[va + 3:va + 6])
|
|
750
|
+
elif jt == "ball":
|
|
751
|
+
va = int(body["vadr"])
|
|
752
|
+
w = w + _quat_rotate(R, qd[va:va + 3])
|
|
753
|
+
elif jt in ("hinge", "revolute"):
|
|
754
|
+
ax = self.body_axis[f].to(dtype=pos[f].dtype)[:, None].expand(3, n_env)
|
|
755
|
+
w = w + _quat_rotate(R, ax) * (qd[int(body["vadr"])] if rate is None else rate)
|
|
756
|
+
elif jt in ("slide", "prismatic"):
|
|
757
|
+
ax = self.body_axis[f].to(dtype=pos[f].dtype)[:, None].expand(3, n_env)
|
|
758
|
+
v = v + _quat_rotate(R, ax) * (qd[int(body["vadr"])] if rate is None else rate)
|
|
759
|
+
else:
|
|
760
|
+
raise AssertionError((f, jt))
|
|
761
|
+
tw[f] = (v, w)
|
|
762
|
+
out = {}
|
|
763
|
+
for b in want:
|
|
764
|
+
f = frame_of[b]
|
|
765
|
+
if f < 0: # welded straight to the world
|
|
766
|
+
out[b] = (torch.zeros_like(pos[b]), torch.zeros_like(pos[b]))
|
|
767
|
+
continue
|
|
768
|
+
v, w = tw[f]
|
|
769
|
+
out[b] = (v if f == b else v + torch.cross(w, pos[b] - pos[f], dim=0), w)
|
|
770
|
+
return out
|
|
771
|
+
|
|
772
|
+
def contact_penetration(self, q: torch.Tensor) -> torch.Tensor:
|
|
773
|
+
"""Per-env maximum ground penetration over contact spheres."""
|
|
774
|
+
if not self.contact_geoms:
|
|
775
|
+
return torch.zeros(q.shape[1], dtype=q.dtype, device=q.device)
|
|
776
|
+
positions, quats = self.body_poses(q)
|
|
777
|
+
pen = torch.zeros(q.shape[1], dtype=q.dtype, device=q.device)
|
|
778
|
+
for body, center, radius in zip(self.contact_body, self.contact_center, self.contact_radius):
|
|
779
|
+
c = center.to(dtype=q.dtype, device=q.device)[:, None].expand(3, q.shape[1])
|
|
780
|
+
world_center = positions[body] + _quat_rotate(quats[body], c)
|
|
781
|
+
n = self.ground_normal
|
|
782
|
+
gap = (n[0] * world_center[0] + n[1] * world_center[1] + n[2] * world_center[2]
|
|
783
|
+
- float(radius)) # == world_center[2] on flat ground
|
|
784
|
+
pen = torch.maximum(pen, (-gap).clamp_min(0.0))
|
|
785
|
+
return pen
|
|
786
|
+
|
|
787
|
+
def joint_limit_penetration(self, q: torch.Tensor) -> torch.Tensor:
|
|
788
|
+
"""Per-env maximum violation of passive joint ranges, in q units."""
|
|
789
|
+
pen, _idx, _side, _value = self.joint_limit_detail(q)
|
|
790
|
+
return pen
|
|
791
|
+
|
|
792
|
+
def joint_limit_detail(
|
|
793
|
+
self, q: torch.Tensor
|
|
794
|
+
) -> tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]:
|
|
795
|
+
"""Per-env maximum joint-limit violation plus the responsible limit spec.
|
|
796
|
+
|
|
797
|
+
Returns `(pen, spec_idx, side, q_value)`, where side is -1 for lower-limit
|
|
798
|
+
violation, +1 for upper-limit violation, and 0 when no limit is violated.
|
|
799
|
+
"""
|
|
800
|
+
n_env = q.shape[1]
|
|
801
|
+
if not self.limit_specs:
|
|
802
|
+
z = torch.zeros(n_env, dtype=q.dtype, device=q.device)
|
|
803
|
+
zi = torch.full((n_env,), -1, dtype=torch.long, device=q.device)
|
|
804
|
+
return z, zi, z, z
|
|
805
|
+
per_limit = []
|
|
806
|
+
per_side = []
|
|
807
|
+
per_value = []
|
|
808
|
+
for spec in self.limit_specs:
|
|
809
|
+
v = q[int(spec["qadr"])]
|
|
810
|
+
lo_pen = (float(spec["lo"]) - v).clamp_min(0.0)
|
|
811
|
+
hi_pen = (v - float(spec["hi"])).clamp_min(0.0)
|
|
812
|
+
use_hi = hi_pen >= lo_pen
|
|
813
|
+
per_limit.append(torch.maximum(lo_pen, hi_pen))
|
|
814
|
+
per_side.append(torch.where(use_hi, torch.ones_like(v), -torch.ones_like(v)))
|
|
815
|
+
per_value.append(v)
|
|
816
|
+
pens = torch.stack(per_limit, dim=0)
|
|
817
|
+
sides = torch.stack(per_side, dim=0)
|
|
818
|
+
values = torch.stack(per_value, dim=0)
|
|
819
|
+
pen, idx = pens.max(dim=0)
|
|
820
|
+
env_ids = torch.arange(n_env, device=q.device)
|
|
821
|
+
side = torch.where(pen > 0.0, sides[idx, env_ids], torch.zeros_like(pen))
|
|
822
|
+
value = values[idx, env_ids]
|
|
823
|
+
return pen, idx, side, value
|
|
824
|
+
|
|
825
|
+
@torch.no_grad()
|
|
826
|
+
def metrics(self, q: torch.Tensor) -> dict[str, float]:
|
|
827
|
+
contact_pen = self.contact_penetration(q)
|
|
828
|
+
joint_pen = self.joint_limit_penetration(q)
|
|
829
|
+
return {
|
|
830
|
+
"contact_pen_max": float(contact_pen.max().detach()),
|
|
831
|
+
"contact_pen_mean": float(contact_pen.mean().detach()),
|
|
832
|
+
"joint_limit_pen_max": float(joint_pen.max().detach()),
|
|
833
|
+
"joint_limit_pen_mean": float(joint_pen.mean().detach()),
|
|
834
|
+
}
|