def _list_rearrange_envs(include_holdout=True, **kwargs): rearrange_path = abspath(join(dirname(__file__), "..")) # Load envs defined as python file. for env_path in glob(join(rearrange_path, "*.py")): if basename(env_path).startswith("__"): continue if basename(env_path) == "holdout.py": # Don't load holdout env directly. continue if "shapenet" in env_path: # We need to use small default mesh_scale for shapenet because objects are too big # and this causes collision among objects and a robot. shapenet_args = recursive_dict_update( deepcopy(kwargs), {"parameters": { "simulation_params": { "mesh_scale": 0.1 } }}, ) yield load_env(env_path, **shapenet_args) else: yield load_env(env_path, **kwargs) # Load holdout envs defined as jsonnet. if include_holdout: for env_path in glob( join(rearrange_path, "holdouts/configs", "*.jsonnet")): yield load_env(f"{env_path}::make_env", **kwargs)
def main(argv, teleoperate): """ examine.py is used to display environments. \b Example uses: ./examine.py dactyl/full_perpendicular.py : displays environment full_perpendicular from envs/dactyl/full_perpendicular.py ./examine.py rearrange/blocks.py --teleoperate : loads BlocksRearrangeEnv in teleoperate mode such that the robot can be teleoperated via the keyboard. """ names, kwargs = parse_arguments(argv) assert len(names) == 1, "Expected a single argument for the environment." env_name = names[0] env, args_remaining = load_env(env_name, return_args_remaining=True, **kwargs) assert env is not None, print( '"{}" doesn\'t seem to be a valid environment'.format(env_name) ) if teleoperate: teleop_compatible = ( isinstance(env.unwrapped, RearrangeEnv) and env.parameters.robot_control_params.is_tcp_controlled() ) assert ( teleop_compatible ), "Teleoperation is only supported for rearrange environments with TCP control modes." viewer = RobotControlViewer if teleoperate else EnvViewer viewer(env).run()
def test_initial_states(): for holdout_env, max_speed, _ in HOLDOUT_ENVS: path = os.path.join(ROOT_PATH, holdout_env) env = load_env(path, starting_seed=0) _test_static_stability( env, f"initial state for {holdout_env}", max_object_speed_allowed=max_speed, max_angular_speed_allowed=6.0, )
def _test_materials( test_cases: List, max_object_speed_allowed: float = 0.1, max_angular_speed: float = 0.05, materials: List = None, render: bool = False, verbose: bool = False, ): """ Evaluates the stability of all test cases on all given materials (defaults to all available materials). """ if not materials: materials = ALL_MATERIALS overall_max_speed = 0.0 overall_max_ang_speed = 0.0 for material, color in materials: for test in test_cases: path = os.path.join(ROOT_PATH, "physics_tests", "tmp_" + test) if material: parsed_material = f'(import "../../../materials/{material}")' else: parsed_material = "{}" jsonnet = MATERIALS_JSONNET_TEMPLATE.format( config_file=test, material=parsed_material, color=color ) with open(path, "w") as f: f.write(jsonnet) env = load_env(path, starting_seed=0) os.remove(path) desc = f"material = {material} on test = {test}" env_max_speed, env_max_ang_speed = _test_static_stability( env, desc, max_object_speed_allowed, max_angular_speed, render=render, verbose=verbose, ) overall_max_speed = max(overall_max_speed, env_max_speed) overall_max_ang_speed = max(overall_max_ang_speed, env_max_ang_speed) if verbose: print(f"\nMax object speed across all test cases = {overall_max_speed:.3f}") print( f"\nMax angular speed across all test cases = {overall_max_ang_speed:.3f}" )
def test_goal_states(): for holdout_env, _, max_speed in HOLDOUT_ENVS: fname = "tmp_" + holdout_env.split("/")[-1] path = os.path.join(ROOT_PATH, fname) jsonnet = GOAL_STATE_JSONNET_TEMPLATE.format(config_file=holdout_env) with open(path, "w") as f: f.write(jsonnet) env = load_env(path, starting_seed=0) os.remove(path) _test_static_stability( env, f"goal state for {holdout_env}", max_object_speed_allowed=max_speed, max_angular_speed_allowed=6.0, )