def test_rotation_with_randomization(): """ Validate that the rotation of the agent is not the same between resets Args: Returns: """ bin_path = pm.get_binary_path_for_package("DefaultWorlds") conf = copy.deepcopy(base_conf) with HolodeckEnvironment(scenario=conf, binary_path=bin_path, show_viewport=False, uuid=str(uuid.uuid4())) as env: prev_start_rotation = conf["agents"][0]["rotation"] num_resets = 5 for _ in range(num_resets): cur_rotation = env.tick()["RotationSensor"] assert is_different_3d_vector(cur_rotation, prev_start_rotation) prev_start_rotation = cur_rotation env.reset()
def env_with_config(config): binary_path = pm.get_binary_path_for_package("DefaultWorlds") return HolodeckEnvironment( scenario=config, binary_path=binary_path, show_viewport=False, uuid=str(uuid.uuid4()), )
def mean_square_error_before_after_reset(env: HolodeckEnvironment): """ Args: env: Environment to reset and test on Returns: mean squared error between RGB sensor data capture before and after and environment reset """ env.tick(10) before_data = env.tick()["TestCamera"] env.reset() env.tick(10) after_data = env.tick()["TestCamera"] return compare_rgb_sensor_data(before_data, after_data)
def test_min_max_action_space_constraints(): binary_path = pm.get_binary_path_for_package("DefaultWorlds") with HolodeckEnvironment(scenario=config, binary_path=binary_path, show_viewport=False, uuid=str(uuid.uuid4())) as env: for x in test_data: agent = x["name"] control_scheme = x["control_scheme"] min_result = env.agents[agent].control_schemes[control_scheme][ 1].get_low() exp_min = x["min"] check_constraints(min_result, exp_min) max_result = env.agents[agent].control_schemes[control_scheme][ 1].get_high() exp_max = x["max"] check_constraints(max_result, exp_max)
def make(world_name, gl_version=GL_VERSION.OPENGL4, window_res=None, cam_res=None, verbose=False): """Creates a holodeck environment using the supplied world name. Args: world_name (str): The name of the world to load as an environment. Must match the name of a world in an installed package. gl_version (int, optional): The OpenGL version to use (Linux only). Defaults to GL_VERSION.OPENGL4. window_res ((int, int), optional): The resolution to load the game window at. Defaults to (512, 512). cam_res ((int, int), optional): The resolution to load the pixel camera sensors at. Defaults to (256, 256). verbose (bool): Whether to run in verbose mode. Defaults to False. Returns: HolodeckEnvironment: A holodeck environment instantiated with all the settings necessary for the specified world, and other supplied arguments. """ holodeck_worlds = _get_worlds_map() if world_name not in holodeck_worlds: raise HolodeckException("Invalid World Name") param_dict = copy(holodeck_worlds[world_name]) param_dict["start_world"] = True param_dict["uuid"] = str(uuid.uuid4()) param_dict["gl_version"] = gl_version param_dict["verbose"] = verbose if window_res is not None: param_dict["window_width"] = window_res[0] param_dict["window_height"] = window_res[1] if cam_res is not None: param_dict["camera_width"] = cam_res[0] param_dict["camera_height"] = cam_res[1] return HolodeckEnvironment(**param_dict)
def make(scenario_name="", scenario_cfg=None, gl_version=GL_VERSION.OPENGL4, window_res=None, verbose=False, show_viewport=True, ticks_per_sec=30, copy_state=True): """Creates a Holodeck environment Args: world_name (:obj:`str`): The name of the world to load as an environment. Must match the name of a world in an installed package. scenario_cfg (:obj:`dict`): Dictionary containing scenario configuration, instead of loading a scenario from the installed packages. Dictionary should match the format of the JSON configuration files gl_version (:obj:`int`, optional): The OpenGL version to use (Linux only). Defaults to GL_VERSION.OPENGL4. window_res ((:obj:`int`, :obj:`int`), optional): The (height, width) to load the engine window at. Overrides the (optional) resolution in the scenario config file verbose (:obj:`bool`, optional): Whether to run in verbose mode. Defaults to False. show_viewport (:obj:`bool`, optional): If the viewport window should be shown on-screen (Linux only). Defaults to True ticks_per_sec (:obj:`int`, optional): The number of frame ticks per unreal seconds. Defaults to 30. copy_state (:obj:`bool`, optional): If the state should be copied or passed as a reference when returned. Defaults to True Returns: :class:`~holodeck.environments.HolodeckEnvironment`: A holodeck environment instantiated with all the settings necessary for the specified world, and other supplied arguments. """ param_dict = dict() binary_path = None if scenario_name != "": scenario = get_scenario(scenario_name) binary_path = get_binary_path_for_scenario(scenario_name) elif scenario_cfg is not None: scenario = scenario_cfg binary_path = get_binary_path_for_package(scenario["package_name"]) else: raise HolodeckException( "You must specify scenario_name or scenario_config") # Get pre-start steps package_config = get_package_config_for_scenario(scenario) world = [ world for world in package_config["worlds"] if world["name"] == scenario["world"] ][0] param_dict["pre_start_steps"] = world["pre_start_steps"] param_dict["scenario"] = scenario param_dict["binary_path"] = binary_path param_dict["start_world"] = True param_dict["uuid"] = str(uuid.uuid4()) param_dict["gl_version"] = gl_version param_dict["verbose"] = verbose param_dict["show_viewport"] = show_viewport param_dict["copy_state"] = copy_state param_dict["ticks_per_sec"] = ticks_per_sec if window_res is not None: param_dict["window_size"] = window_res return HolodeckEnvironment(**param_dict)