| | |
| | |
| | |
| | |
| |
|
| | """Launch Isaac Sim Simulator first.""" |
| |
|
| | from isaaclab.app import AppLauncher |
| |
|
| | |
| | |
| | simulation_app = AppLauncher(headless=True, enable_cameras=True).app |
| |
|
| | """Rest everything follows.""" |
| |
|
| | import math |
| |
|
| | import numpy as np |
| | import pytest |
| | import torch |
| |
|
| | from pxr import Gf, Sdf, Usd, UsdGeom |
| |
|
| | import isaaclab.sim as sim_utils |
| | from isaaclab.sim.utils.prims import _to_tuple |
| | from isaaclab.utils.assets import ISAAC_NUCLEUS_DIR, ISAACLAB_NUCLEUS_DIR |
| |
|
| |
|
| | @pytest.fixture(autouse=True) |
| | def test_setup_teardown(): |
| | """Create a blank new stage for each test.""" |
| | |
| | sim_utils.create_new_stage() |
| | sim_utils.update_stage() |
| |
|
| | |
| | yield |
| |
|
| | |
| | sim_utils.clear_stage() |
| |
|
| |
|
| | def assert_quat_close(q1: Gf.Quatf | Gf.Quatd, q2: Gf.Quatf | Gf.Quatd, eps: float = 1e-6): |
| | """Assert two quaternions are close.""" |
| | assert math.isclose(q1.GetReal(), q2.GetReal(), abs_tol=eps) |
| | for i in range(3): |
| | assert math.isclose(q1.GetImaginary()[i], q2.GetImaginary()[i], abs_tol=eps) |
| |
|
| |
|
| | """ |
| | General Utils |
| | """ |
| |
|
| |
|
| | def test_create_prim(): |
| | """Test create_prim() function.""" |
| | |
| | stage = sim_utils.get_current_stage() |
| | |
| | prim = sim_utils.create_prim(prim_path="/World/Test", prim_type="Xform", stage=stage) |
| | |
| | assert prim.IsValid() |
| | assert prim.GetPrimPath() == "/World/Test" |
| | assert prim.GetTypeName() == "Xform" |
| |
|
| | |
| | with pytest.raises(ValueError, match="already exists"): |
| | sim_utils.create_prim(prim_path="/World/Test", prim_type="Xform", stage=stage) |
| |
|
| | |
| | prim = sim_utils.create_prim(prim_path="/World/Test/Cube", prim_type="Cube", stage=stage, attributes={"size": 100}) |
| | |
| | assert prim.IsValid() |
| | assert prim.GetPrimPath() == "/World/Test/Cube" |
| | assert prim.GetTypeName() == "Cube" |
| | assert prim.GetAttribute("size").Get() == 100 |
| |
|
| | |
| | franka_usd = f"{ISAACLAB_NUCLEUS_DIR}/Robots/FrankaEmika/panda_instanceable.usd" |
| | prim = sim_utils.create_prim("/World/Test/USDReference", usd_path=franka_usd, stage=stage) |
| | |
| | assert prim.IsValid() |
| | assert prim.GetPrimPath() == "/World/Test/USDReference" |
| | assert prim.GetTypeName() == "Xform" |
| | |
| | references = [] |
| | for prim_spec in prim.GetPrimStack(): |
| | references.extend(prim_spec.referenceList.prependedItems) |
| | assert len(references) == 1 |
| | assert str(references[0].assetPath) == franka_usd |
| |
|
| | |
| | prim = sim_utils.create_prim( |
| | "/World/Test/Sphere", "Sphere", stage=stage, semantic_label="sphere", attributes={"radius": 10.0} |
| | ) |
| | |
| | assert prim.IsValid() |
| | assert prim.GetPrimPath() == "/World/Test/Sphere" |
| | assert prim.GetTypeName() == "Sphere" |
| | assert prim.GetAttribute("radius").Get() == 10.0 |
| | assert sim_utils.get_labels(prim)["class"] == ["sphere"] |
| |
|
| | |
| | pos = (1.0, 2.0, 3.0) |
| | quat = (0.0, 0.0, 0.0, 1.0) |
| | scale = (1.0, 0.5, 0.5) |
| | prim = sim_utils.create_prim( |
| | "/World/Test/Xform", "Xform", stage=stage, translation=pos, orientation=quat, scale=scale |
| | ) |
| | |
| | assert prim.IsValid() |
| | assert prim.GetPrimPath() == "/World/Test/Xform" |
| | assert prim.GetTypeName() == "Xform" |
| | assert prim.GetAttribute("xformOp:translate").Get() == Gf.Vec3d(pos) |
| | assert_quat_close(prim.GetAttribute("xformOp:orient").Get(), Gf.Quatd(*quat)) |
| | assert prim.GetAttribute("xformOp:scale").Get() == Gf.Vec3d(scale) |
| | |
| | op_names = [op.GetOpName() for op in UsdGeom.Xformable(prim).GetOrderedXformOps()] |
| | assert op_names == ["xformOp:translate", "xformOp:orient", "xformOp:scale"] |
| |
|
| |
|
| | @pytest.mark.parametrize( |
| | "input_type", |
| | ["list", "tuple", "numpy", "torch_cpu", "torch_cuda"], |
| | ids=["list", "tuple", "numpy", "torch_cpu", "torch_cuda"], |
| | ) |
| | def test_create_prim_with_different_input_types(input_type: str): |
| | """Test create_prim() with different input types (list, tuple, numpy array, torch tensor).""" |
| | |
| | stage = sim_utils.get_current_stage() |
| |
|
| | |
| | translation_vals = [1.0, 2.0, 3.0] |
| | orientation_vals = [1.0, 0.0, 0.0, 0.0] |
| | scale_vals = [2.0, 3.0, 4.0] |
| |
|
| | |
| | if input_type == "list": |
| | translation = translation_vals |
| | orientation = orientation_vals |
| | scale = scale_vals |
| | elif input_type == "tuple": |
| | translation = tuple(translation_vals) |
| | orientation = tuple(orientation_vals) |
| | scale = tuple(scale_vals) |
| | elif input_type == "numpy": |
| | translation = np.array(translation_vals) |
| | orientation = np.array(orientation_vals) |
| | scale = np.array(scale_vals) |
| | elif input_type == "torch_cpu": |
| | translation = torch.tensor(translation_vals) |
| | orientation = torch.tensor(orientation_vals) |
| | scale = torch.tensor(scale_vals) |
| | elif input_type == "torch_cuda": |
| | if not torch.cuda.is_available(): |
| | pytest.skip("CUDA not available") |
| | translation = torch.tensor(translation_vals, device="cuda") |
| | orientation = torch.tensor(orientation_vals, device="cuda") |
| | scale = torch.tensor(scale_vals, device="cuda") |
| |
|
| | |
| | prim = sim_utils.create_prim( |
| | f"/World/Test/Xform_{input_type}", |
| | "Xform", |
| | stage=stage, |
| | translation=translation, |
| | orientation=orientation, |
| | scale=scale, |
| | ) |
| |
|
| | |
| | assert prim.IsValid() |
| | assert prim.GetPrimPath() == f"/World/Test/Xform_{input_type}" |
| |
|
| | |
| | assert prim.GetAttribute("xformOp:translate").Get() == Gf.Vec3d(*translation_vals) |
| | assert_quat_close(prim.GetAttribute("xformOp:orient").Get(), Gf.Quatd(*orientation_vals)) |
| | assert prim.GetAttribute("xformOp:scale").Get() == Gf.Vec3d(*scale_vals) |
| |
|
| | |
| | op_names = [op.GetOpName() for op in UsdGeom.Xformable(prim).GetOrderedXformOps()] |
| | assert op_names == ["xformOp:translate", "xformOp:orient", "xformOp:scale"] |
| |
|
| |
|
| | @pytest.mark.parametrize( |
| | "input_type", |
| | ["list", "tuple", "numpy", "torch_cpu", "torch_cuda"], |
| | ids=["list", "tuple", "numpy", "torch_cpu", "torch_cuda"], |
| | ) |
| | def test_create_prim_with_world_position_different_types(input_type: str): |
| | """Test create_prim() with world position using different input types.""" |
| | |
| | stage = sim_utils.get_current_stage() |
| |
|
| | |
| | _ = sim_utils.create_prim( |
| | "/World/Parent", |
| | "Xform", |
| | stage=stage, |
| | translation=(5.0, 10.0, 15.0), |
| | orientation=(1.0, 0.0, 0.0, 0.0), |
| | ) |
| |
|
| | |
| | world_pos_vals = [10.0, 20.0, 30.0] |
| | world_orient_vals = [0.7071068, 0.0, 0.7071068, 0.0] |
| |
|
| | |
| | if input_type == "list": |
| | world_pos = world_pos_vals |
| | world_orient = world_orient_vals |
| | elif input_type == "tuple": |
| | world_pos = tuple(world_pos_vals) |
| | world_orient = tuple(world_orient_vals) |
| | elif input_type == "numpy": |
| | world_pos = np.array(world_pos_vals) |
| | world_orient = np.array(world_orient_vals) |
| | elif input_type == "torch_cpu": |
| | world_pos = torch.tensor(world_pos_vals) |
| | world_orient = torch.tensor(world_orient_vals) |
| | elif input_type == "torch_cuda": |
| | if not torch.cuda.is_available(): |
| | pytest.skip("CUDA not available") |
| | world_pos = torch.tensor(world_pos_vals, device="cuda") |
| | world_orient = torch.tensor(world_orient_vals, device="cuda") |
| |
|
| | |
| | child = sim_utils.create_prim( |
| | f"/World/Parent/Child_{input_type}", |
| | "Xform", |
| | stage=stage, |
| | position=world_pos, |
| | orientation=world_orient, |
| | ) |
| |
|
| | |
| | assert child.IsValid() |
| |
|
| | |
| | world_pose = sim_utils.resolve_prim_pose(child) |
| | pos_result, quat_result = world_pose |
| |
|
| | |
| | for i in range(3): |
| | assert math.isclose(pos_result[i], world_pos_vals[i], abs_tol=1e-4) |
| |
|
| | |
| | quat_match = all(math.isclose(quat_result[i], world_orient_vals[i], abs_tol=1e-4) for i in range(4)) |
| | quat_match_neg = all(math.isclose(quat_result[i], -world_orient_vals[i], abs_tol=1e-4) for i in range(4)) |
| | assert quat_match or quat_match_neg |
| |
|
| |
|
| | def test_create_prim_non_xformable(): |
| | """Test create_prim() with non-Xformable prim types (Material, Shader, Scope). |
| | |
| | This test verifies that prims which are not Xformable (like Material, Shader, Scope) |
| | are created successfully but transform operations are not applied to them. |
| | This is expected behavior as documented in the create_prim function. |
| | """ |
| | |
| | stage = sim_utils.get_current_stage() |
| |
|
| | |
| | material_prim = sim_utils.create_prim( |
| | "/World/TestMaterial", |
| | "Material", |
| | stage=stage, |
| | translation=(1.0, 2.0, 3.0), |
| | orientation=(1.0, 0.0, 0.0, 0.0), |
| | scale=(2.0, 2.0, 2.0), |
| | ) |
| |
|
| | |
| | assert material_prim.IsValid() |
| | assert material_prim.GetPrimPath() == "/World/TestMaterial" |
| | assert material_prim.GetTypeName() == "Material" |
| |
|
| | |
| | assert not material_prim.IsA(UsdGeom.Xformable) |
| |
|
| | |
| | assert not material_prim.HasAttribute("xformOp:translate") |
| | assert not material_prim.HasAttribute("xformOp:orient") |
| | assert not material_prim.HasAttribute("xformOp:scale") |
| |
|
| | |
| | scope_prim = sim_utils.create_prim( |
| | "/World/TestScope", |
| | "Scope", |
| | stage=stage, |
| | translation=(5.0, 6.0, 7.0), |
| | ) |
| |
|
| | |
| | assert scope_prim.IsValid() |
| | assert scope_prim.GetPrimPath() == "/World/TestScope" |
| | assert scope_prim.GetTypeName() == "Scope" |
| |
|
| | |
| | assert not scope_prim.IsA(UsdGeom.Xformable) |
| |
|
| | |
| | assert not scope_prim.HasAttribute("xformOp:translate") |
| | assert not scope_prim.HasAttribute("xformOp:orient") |
| | assert not scope_prim.HasAttribute("xformOp:scale") |
| |
|
| |
|
| | def test_delete_prim(): |
| | """Test delete_prim() function.""" |
| | |
| | stage = sim_utils.get_current_stage() |
| | |
| | prim = sim_utils.create_prim("/World/Test/Xform", "Xform", stage=stage) |
| | |
| | sim_utils.delete_prim("/World/Test/Xform") |
| | |
| | assert not prim.IsValid() |
| |
|
| | |
| | prim = sim_utils.create_prim( |
| | "/World/Test/USDReference", |
| | usd_path=f"{ISAACLAB_NUCLEUS_DIR}/Robots/FrankaEmika/panda_instanceable.usd", |
| | stage=stage, |
| | ) |
| | |
| | sim_utils.delete_prim("/World/Test/USDReference", stage=stage) |
| | |
| | assert not prim.IsValid() |
| |
|
| | |
| | prim1 = sim_utils.create_prim("/World/Test/Xform1", "Xform", stage=stage) |
| | prim2 = sim_utils.create_prim("/World/Test/Xform2", "Xform", stage=stage) |
| | sim_utils.delete_prim(("/World/Test/Xform1", "/World/Test/Xform2"), stage=stage) |
| | |
| | assert not prim1.IsValid() |
| | assert not prim2.IsValid() |
| |
|
| |
|
| | def test_move_prim(): |
| | """Test move_prim() function.""" |
| | |
| | stage = sim_utils.get_current_stage() |
| | |
| | sim_utils.create_prim("/World/Test", "Xform", stage=stage) |
| | prim = sim_utils.create_prim( |
| | "/World/Test/Xform", |
| | "Xform", |
| | usd_path=f"{ISAACLAB_NUCLEUS_DIR}/Robots/FrankaEmika/panda_instanceable.usd", |
| | translation=(1.0, 2.0, 3.0), |
| | orientation=(0.0, 0.0, 0.0, 1.0), |
| | stage=stage, |
| | ) |
| |
|
| | |
| | sim_utils.create_prim("/World/TestMove", "Xform", stage=stage, translation=(1.0, 1.0, 1.0)) |
| | sim_utils.move_prim("/World/Test/Xform", "/World/TestMove/Xform", stage=stage) |
| | |
| | prim = stage.GetPrimAtPath("/World/TestMove/Xform") |
| | assert prim.IsValid() |
| | assert prim.GetPrimPath() == "/World/TestMove/Xform" |
| | assert prim.GetAttribute("xformOp:translate").Get() == Gf.Vec3d((0.0, 1.0, 2.0)) |
| | assert_quat_close(prim.GetAttribute("xformOp:orient").Get(), Gf.Quatd(0.0, 0.0, 0.0, 1.0)) |
| |
|
| | |
| | |
| | sim_utils.create_prim( |
| | "/World/TestMove2", "Xform", stage=stage, translation=(2.0, 2.0, 2.0), orientation=(0.0, 0.7071, 0.0, 0.7071) |
| | ) |
| | sim_utils.move_prim("/World/TestMove/Xform", "/World/TestMove2/Xform", keep_world_transform=False, stage=stage) |
| | |
| | prim = stage.GetPrimAtPath("/World/TestMove2/Xform") |
| | assert prim.IsValid() |
| | assert prim.GetPrimPath() == "/World/TestMove2/Xform" |
| | assert prim.GetAttribute("xformOp:translate").Get() == Gf.Vec3d((0.0, 1.0, 2.0)) |
| | assert_quat_close(prim.GetAttribute("xformOp:orient").Get(), Gf.Quatd(0.0, 0.0, 0.0, 1.0)) |
| |
|
| |
|
| | """ |
| | USD references and variants. |
| | """ |
| |
|
| |
|
| | def test_get_usd_references(): |
| | """Test get_usd_references() function.""" |
| | |
| | stage = sim_utils.get_current_stage() |
| |
|
| | |
| | sim_utils.create_prim("/World/NoReference", "Xform", stage=stage) |
| | |
| | refs = sim_utils.get_usd_references("/World/NoReference", stage=stage) |
| | assert len(refs) == 0 |
| |
|
| | |
| | franka_usd = f"{ISAACLAB_NUCLEUS_DIR}/Robots/FrankaEmika/panda_instanceable.usd" |
| | sim_utils.create_prim("/World/WithReference", usd_path=franka_usd, stage=stage) |
| | |
| | refs = sim_utils.get_usd_references("/World/WithReference", stage=stage) |
| | assert len(refs) == 1 |
| | assert refs == [franka_usd] |
| |
|
| | |
| | with pytest.raises(ValueError, match="not valid"): |
| | sim_utils.get_usd_references("/World/NonExistent", stage=stage) |
| |
|
| |
|
| | def test_select_usd_variants(): |
| | """Test select_usd_variants() function.""" |
| | stage = sim_utils.get_current_stage() |
| |
|
| | |
| | prim: Usd.Prim = UsdGeom.Xform.Define(stage, Sdf.Path("/World")).GetPrim() |
| | stage.SetDefaultPrim(prim) |
| |
|
| | |
| | variants = ["red", "blue", "green"] |
| | variant_set = prim.GetVariantSets().AddVariantSet("colors") |
| | for variant in variants: |
| | variant_set.AddVariant(variant) |
| |
|
| | |
| | sim_utils.utils.select_usd_variants("/World", {"colors": "red"}, stage) |
| |
|
| | |
| | assert variant_set.GetVariantSelection() == "red" |
| |
|
| |
|
| | def test_select_usd_variants_in_usd_file(): |
| | """Test select_usd_variants() function in USD file.""" |
| | stage = sim_utils.get_current_stage() |
| |
|
| | prim = sim_utils.create_prim( |
| | "/World/Test", "Xform", usd_path=f"{ISAAC_NUCLEUS_DIR}/Robots/UniversalRobots/ur10e/ur10e.usd", stage=stage |
| | ) |
| |
|
| | variant_sets = prim.GetVariantSets() |
| |
|
| | |
| | for name in variant_sets.GetNames(): |
| | vs = variant_sets.GetVariantSet(name) |
| | options = vs.GetVariantNames() |
| | selected = vs.GetVariantSelection() |
| |
|
| | print(f"{name}: {selected} / {options}") |
| |
|
| | print("Setting variant 'Gripper' to 'Robotiq_2f_140'.") |
| | |
| | |
| | target_vs = variant_sets.GetVariantSet("Gripper") |
| | target_vs.SetVariantSelection("Robotiq_2f_140") |
| |
|
| | |
| | variant_sets = prim.GetVariantSets() |
| |
|
| | for name in variant_sets.GetNames(): |
| | vs = variant_sets.GetVariantSet(name) |
| | options = vs.GetVariantNames() |
| | selected = vs.GetVariantSelection() |
| |
|
| | print(f"{name}: {selected} / {options}") |
| |
|
| | |
| |
|
| | |
| | |
| |
|
| | |
| | |
| | |
| | |
| |
|
| |
|
| | """ |
| | Property Management. |
| | """ |
| |
|
| |
|
| | def test_change_prim_property_basic(): |
| | """Test change_prim_property() with existing property.""" |
| | |
| | stage = sim_utils.get_current_stage() |
| | |
| | prim = sim_utils.create_prim("/World/Cube", "Cube", stage=stage, attributes={"size": 1.0}) |
| |
|
| | |
| | assert prim.GetAttribute("size").Get() == 1.0 |
| |
|
| | |
| | result = sim_utils.change_prim_property( |
| | prop_path="/World/Cube.size", |
| | value=2.0, |
| | stage=stage, |
| | ) |
| |
|
| | |
| | assert result is True |
| | assert prim.GetAttribute("size").Get() == 2.0 |
| |
|
| |
|
| | def test_change_prim_property_create_new(): |
| | """Test change_prim_property() creates new property when it doesn't exist.""" |
| | |
| | stage = sim_utils.get_current_stage() |
| | |
| | prim = sim_utils.create_prim("/World/Test", "Xform", stage=stage) |
| |
|
| | |
| | assert prim.GetAttribute("customValue").Get() is None |
| |
|
| | |
| | result = sim_utils.change_prim_property( |
| | prop_path="/World/Test.customValue", |
| | value=42, |
| | stage=stage, |
| | type_to_create_if_not_exist=Sdf.ValueTypeNames.Int, |
| | is_custom=True, |
| | ) |
| |
|
| | |
| | assert result is True |
| | assert prim.GetAttribute("customValue").Get() == 42 |
| |
|
| |
|
| | def test_change_prim_property_clear_value(): |
| | """Test change_prim_property() clears property value when value is None.""" |
| | |
| | stage = sim_utils.get_current_stage() |
| | |
| | prim = sim_utils.create_prim("/World/Cube", "Cube", stage=stage, attributes={"size": 1.0}) |
| |
|
| | |
| | assert prim.GetAttribute("size").Get() == 1.0 |
| |
|
| | |
| | result = sim_utils.change_prim_property( |
| | prop_path="/World/Cube.size", |
| | value=None, |
| | stage=stage, |
| | ) |
| |
|
| | |
| | assert result is True |
| | |
| | assert prim.GetAttribute("size").Get() == 2.0 |
| |
|
| |
|
| | @pytest.mark.parametrize( |
| | "attr_name,value,value_type,expected", |
| | [ |
| | ("floatValue", 3.14, Sdf.ValueTypeNames.Float, 3.14), |
| | ("boolValue", True, Sdf.ValueTypeNames.Bool, True), |
| | ("intValue", 42, Sdf.ValueTypeNames.Int, 42), |
| | ("stringValue", "test", Sdf.ValueTypeNames.String, "test"), |
| | ("vec3Value", Gf.Vec3f(1.0, 2.0, 3.0), Sdf.ValueTypeNames.Float3, Gf.Vec3f(1.0, 2.0, 3.0)), |
| | ("colorValue", Gf.Vec3f(1.0, 0.0, 0.5), Sdf.ValueTypeNames.Color3f, Gf.Vec3f(1.0, 0.0, 0.5)), |
| | ], |
| | ids=["float", "bool", "int", "string", "vec3", "color"], |
| | ) |
| | def test_change_prim_property_different_types(attr_name: str, value, value_type, expected): |
| | """Test change_prim_property() with different value types.""" |
| | |
| | stage = sim_utils.get_current_stage() |
| | |
| | prim = sim_utils.create_prim("/World/Test", "Xform", stage=stage) |
| |
|
| | |
| | result = sim_utils.change_prim_property( |
| | prop_path=f"/World/Test.{attr_name}", |
| | value=value, |
| | stage=stage, |
| | type_to_create_if_not_exist=value_type, |
| | is_custom=True, |
| | ) |
| |
|
| | |
| | assert result is True |
| | actual_value = prim.GetAttribute(attr_name).Get() |
| |
|
| | |
| | if isinstance(expected, float): |
| | assert math.isclose(actual_value, expected, abs_tol=1e-6) |
| | else: |
| | assert actual_value == expected |
| |
|
| |
|
| | @pytest.mark.parametrize( |
| | "prop_path_input", |
| | ["/World/Cube.size", Sdf.Path("/World/Cube.size")], |
| | ids=["str_path", "sdf_path"], |
| | ) |
| | def test_change_prim_property_path_types(prop_path_input): |
| | """Test change_prim_property() with different path input types.""" |
| | |
| | stage = sim_utils.get_current_stage() |
| | |
| | prim = sim_utils.create_prim("/World/Cube", "Cube", stage=stage, attributes={"size": 1.0}) |
| |
|
| | |
| | result = sim_utils.change_prim_property( |
| | prop_path=prop_path_input, |
| | value=3.0, |
| | stage=stage, |
| | ) |
| |
|
| | |
| | assert result is True |
| | assert prim.GetAttribute("size").Get() == 3.0 |
| |
|
| |
|
| | def test_change_prim_property_error_invalid_prim(): |
| | """Test change_prim_property() raises error for invalid prim path.""" |
| | |
| | stage = sim_utils.get_current_stage() |
| |
|
| | |
| | with pytest.raises(ValueError, match="Prim does not exist"): |
| | sim_utils.change_prim_property( |
| | prop_path="/World/NonExistent.property", |
| | value=1.0, |
| | stage=stage, |
| | ) |
| |
|
| |
|
| | def test_change_prim_property_error_missing_type(): |
| | """Test change_prim_property() returns False when property doesn't exist and type not provided.""" |
| | |
| | stage = sim_utils.get_current_stage() |
| | |
| | prim = sim_utils.create_prim("/World/Test", "Xform", stage=stage) |
| |
|
| | |
| | result = sim_utils.change_prim_property( |
| | prop_path="/World/Test.nonExistentProperty", |
| | value=42, |
| | stage=stage, |
| | ) |
| |
|
| | |
| | assert result is False |
| | |
| | assert prim.GetAttribute("nonExistentProperty").Get() is None |
| |
|
| |
|
| | """ |
| | Internal Helpers. |
| | """ |
| |
|
| |
|
| | def test_to_tuple_basic(): |
| | """Test _to_tuple() with basic input types.""" |
| | |
| | result = _to_tuple([1.0, 2.0, 3.0]) |
| | assert result == (1.0, 2.0, 3.0) |
| | assert isinstance(result, tuple) |
| |
|
| | |
| | result = _to_tuple((1.0, 2.0, 3.0)) |
| | assert result == (1.0, 2.0, 3.0) |
| |
|
| | |
| | result = _to_tuple(np.array([1.0, 2.0, 3.0])) |
| | assert result == (1.0, 2.0, 3.0) |
| |
|
| | |
| | result = _to_tuple(torch.tensor([1.0, 2.0, 3.0])) |
| | assert result == (1.0, 2.0, 3.0) |
| |
|
| | |
| | result = _to_tuple(torch.tensor([[1.0, 2.0]])) |
| | assert result == (1.0, 2.0) |
| |
|
| | result = _to_tuple(np.array([[1.0, 2.0, 3.0]])) |
| | assert result == (1.0, 2.0, 3.0) |
| |
|
| |
|
| | def test_to_tuple_raises_error(): |
| | """Test _to_tuple() raises an error for N-dimensional arrays.""" |
| |
|
| | with pytest.raises(ValueError, match="not one dimensional"): |
| | _to_tuple(np.array([[1.0, 2.0], [3.0, 4.0]])) |
| |
|
| | with pytest.raises(ValueError, match="not one dimensional"): |
| | _to_tuple(torch.tensor([[[1.0, 2.0]], [[3.0, 4.0]]])) |
| |
|
| | with pytest.raises(ValueError, match="only one element tensors can be converted"): |
| | _to_tuple((torch.tensor([1.0, 2.0]), 3.0)) |
| |
|
| |
|
| | def test_to_tuple_mixed_sequences(): |
| | """Test _to_tuple() with mixed type sequences.""" |
| |
|
| | |
| | result = _to_tuple([np.float32(1.0), 2.0, 3.0]) |
| | assert len(result) == 3 |
| | assert all(isinstance(x, float) for x in result) |
| |
|
| | |
| | result = _to_tuple([torch.tensor(1.0), 2.0, 3.0]) |
| | assert result == (1.0, 2.0, 3.0) |
| |
|
| | |
| | result = _to_tuple((np.float32(1.0), 2.0, torch.tensor(3.0))) |
| | assert result == (1.0, 2.0, 3.0) |
| |
|
| |
|
| | def test_to_tuple_precision(): |
| | """Test _to_tuple() maintains numerical precision.""" |
| | from isaaclab.sim.utils.prims import _to_tuple |
| |
|
| | |
| | high_precision = [1.123456789, 2.987654321, 3.141592653] |
| | result = _to_tuple(torch.tensor(high_precision, dtype=torch.float64)) |
| |
|
| | |
| | for i, val in enumerate(high_precision): |
| | assert math.isclose(result[i], val, abs_tol=1e-6) |
| |
|