How to use the gym.spaces.Box function in gym

To help you get started, we’ve selected a few gym examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github learnables / cherry / tests / dummy_env.py View on Github external
def __init__(self):
        low = np.array([-5, -5, -5, -5, -5])
        high = -np.array([-5, -5, -5, -5, -5])
        self.observation_space = gym.spaces.Box(low, high, dtype=np.float32)
        self.action_space = gym.spaces.Box(low, high, dtype=np.float32)
        self.rng = random.Random()
github chainer / chainerrl / tests / wrappers_tests / test_atari_wrappers.py View on Github external
def dtyped_rand():
                    return np_random.rand(1, 84, 84).astype(self.dtype)
                low, high = -1.0, 3.14
            else:
                assert False
            env.reset.side_effect = [dtyped_rand() for _ in range(steps)]
            env.step.side_effect = [
                (
                    dtyped_rand(),
                    np_random.rand(),
                    bool(np_random.randint(2)),
                    {},
                )
                for _ in range(steps)]
            env.action_space = gym.spaces.Discrete(2)
            env.observation_space = gym.spaces.Box(
                low=low, high=high, shape=(1, 84, 84), dtype=self.dtype)
            return env
github adderbyte / GYM_XPLANE_ML / gym_xplane_final_version / gym_xplane / space_definition.py View on Github external
def _action_space(self):
        
        '''
        return  spaces.Dict({"Latitudinal_Stick":  spaces.Box(low=-1, high=1, shape=()),
            "Longitudinal_Stick":  spaces.Box(low=-1, high=1, shape=()),
            "Rudder_Pedals":  spaces.Box(low=-1, high=1, shape=()),"Throttle":  spaces.Box(low=-1, high=1, shape=()),
            "Gear":  spaces.Discrete(2),"Flaps":  spaces.Box(low=0, high=1, shape=()),
            "Speedbrakes": spaces.Box(low=-0.5, high=1.5, shape=())})
        '''
        return spaces.Box(np.array([ -1, -1, -1,-1/4]),np.array([1,1,1,1]))
github arnomoonens / yarll / yarll / misc / utils.py View on Github external
def hard_update(source_vars: Sequence[tf.Variable], target_vars: Sequence[tf.Variable]) -> None:
    """Copy source variables to target variables.

    Arguments:
        source_vars {Sequence[tf.Variable]} -- Source variables to copy from
        target_vars {Sequence[tf.Variable]} -- Variables to copy data to
    """
    soft_update(source_vars, target_vars, 1.0) # Tau of 1, so get everything from source and keep nothing from target

def flatten_list(l: List[List]):
    return list(itertools.chain.from_iterable(l))

spaces_mapping = {
    Discrete: "discrete",
    MultiDiscrete: "multidiscrete",
    Box: "continuous",
    MultiBinary: "multibinary"
}
github deephyper / deephyper / deephyper / search / nas / env / math_env.py View on Github external
def __init__(self, evaluator):

        self.evaluator = evaluator
        self.observation_space = spaces.Box(low=-0, high=DIST_SIZE-1, shape=(1,), dtype=np.float32)
        self.action_space = spaces.Discrete(DIST_SIZE)

        self._state = np.array([1.])
        self.action_buffer = []
        self.num_timesteps = NUM_DIM
github AcutronicRobotics / gym-gazebo2 / gym_gazebo2 / envs / MARA / gazebo_mara_orient_vision_collision.py View on Github external
# # print(observation, _reward)

        # # Here idially we should find the control range of the robot. Unfortunatelly in ROS/KDL there is nothing like this.
        # # I have tested this with the mujoco enviroment and the output is always same low[-1.,-1.], high[1.,1.]
        # #bounds = self.model.actuator_ctrlrange.copy()
        low = -np.pi/2.0 * np.ones(self.scara_chain.getNrOfJoints())
        high = np.pi/2.0 * np.ones(self.scara_chain.getNrOfJoints())
        # low = -np.pi * np.ones(self.scara_chain.getNrOfJoints())
        # high = np.pi * np.ones(self.scara_chain.getNrOfJoints())
        # low = -np.inf * np.ones(self.scara_chain.getNrOfJoints())
        # high = np.inf * np.ones(self.scara_chain.getNrOfJoints())
        # print("Action spaces: ", low, high)
        self.action_space = spaces.Box(low, high)
        high = np.inf*np.ones(self.obs_dim)
        low = -high
        self.observation_space = spaces.Box(low, high)


        # Migration to ROS2

        #self.add_model_urdf = rospy.ServiceProxy('/gazebo/spawn_urdf_model', SpawnModel)
        #self.add_model_sdf = rospy.ServiceProxy('/gazebo/spawn_sdf_model', SpawnModel)
        self.add_entity = self.node.create_client(SpawnEntity, '/spawn_entity')
        #self.remove_model = rospy.ServiceProxy('/gazebo/delete_model', DeleteModel)
        self.remove_entity = self.node.create_client(DeleteEntity, '/delete_entity')
        #self.set_model_pose = rospy.ServiceProxy('/gazebo/set_model_state', SetModelState)
        self.set_entity_state = self.node.create_client(SetEntityState, '/set_entity_state')
        #self.get_model_state = rospy.ServiceProxy('/gazebo/get_entity_state', GetModelState)
        self.get_entity_state = self.node.create_client(GetEntityState, '/get_entity_state')
        #self.reset_sim = rospy.ServiceProxy('/gazebo/reset_simulation', Empty)
        self.reset_sim = self.node.create_client(Empty, '/reset_simulation')
github CPJKU / score_following_game / score_following_game / environment / env_wrappers.py View on Github external
"""
        Returns original and delta observation if keep_raw=True else only the delta observation
        """
        gym.ObservationWrapper.__init__(self, env)
        self.prev = None
        self.keep_raw = keep_raw
        self.key = key

        space = self.observation_space.spaces[self.key]
        shape = list(space.shape)

        # adapt the observation space
        if self.keep_raw:
            shape[0] = shape[0]*2

        self.observation_space.spaces[self.key] = gym.spaces.Box(0, 255, shape, dtype=np.float32)
github rlworkgroup / metaworld / metaworld / envs / mujoco / sawyer_xyz / sawyer_faucet_open.py View on Github external
self.random_init = random_init
        self.max_path_length = 150
        self.rotMode = rotMode
        if rotMode == 'fixed':
            self.action_space = Box(
                np.array([-1, -1, -1, -1]),
                np.array([1, 1, 1, 1]),
            )
        elif rotMode == 'rotz':
            self.action_rot_scale = 1./50
            self.action_space = Box(
                np.array([-1, -1, -1, -np.pi, -1]),
                np.array([1, 1, 1, np.pi, 1]),
            )
        elif rotMode == 'quat':
            self.action_space = Box(
                np.array([-1, -1, -1, 0, -1, -1, -1, -1]),
                np.array([1, 1, 1, 2*np.pi, 1, 1, 1, 1]),
            )
        else:
            self.action_space = Box(
                np.array([-1, -1, -1, -np.pi/2, -np.pi/2, 0, -1]),
                np.array([1, 1, 1, np.pi/2, np.pi/2, np.pi*2, 1]),
            )
        self.obj_and_goal_space = Box(
            np.array(obj_low),
            np.array(obj_high),
        )
        self.goal_space = Box(np.array(goal_low), np.array(goal_high))
        if self.obs_type == 'plain':
            self.observation_space = Box(
                np.hstack((self.hand_low, obj_low,)),
github PSVL / DoorGym / doorenv2 / doorenv2 / envs / doorenv.py View on Github external
self.b = bytearray(3*self.imgsize_h*self.imgsize_w)
                self.no_viewer = False
            else:
                self.no_viewer = True
        else:
            self.no_viewer = False
        frame_skip = 20
        # utils.EzPickle.__init__(self)
        mujoco_env.MujocoEnv.__init__(self, self.xml_path, frame_skip)
        gripper_space = self.gripper_action.shape[0]
        # print("gripper space", gripper_space)
        if self.xml_path.find("gripper")>-1:
            bounds = self.model.actuator_ctrlrange.copy()
            low, high = bounds.T
            low, high = low[:-gripper_space], high[:-gripper_space] # four joints for finger is a dependant of finger inertial joint
            self.action_space = spaces.Box(low=low, high=high, dtype=np.float32)
            self.gripper_action = self.sim.data.qpos[-gripper_space:]
        self.init_done = True
        self.model_origin = self.model
github EmbersArc / PPO / agents / environment.py View on Github external
self.env = gym.wrappers.Monitor(self.env, "./video", lambda x: x % 1 == 0)

        ob_space = self.env.observation_space
        ac_space = self.env.action_space
        if isinstance(ac_space, gym.spaces.Box):
            assert len(ac_space.shape) == 1
            self.ac_space_type = "continuous"
            self.ac_space_size = ac_space.shape[0]
        elif isinstance(ac_space, gym.spaces.Discrete):
            self.ac_space_type = "discrete"
            self.ac_space_size = ac_space.n

        else:
            raise NotImplementedError

        if isinstance(ob_space, gym.spaces.Box):
            assert len(ob_space.shape) == 1
            self.ob_space_type = "continuous"
            self.ob_space_size = ob_space.shape[0]

        elif isinstance(ob_space, gym.spaces.Discrete):
            self.ob_space_type = "discrete"
            self.ob_space_size = ob_space.n
        else:
            raise NotImplementedError

        self._data = {}
        self._log_path = log_path
        self._global_done = False
        self._brains = {}
        self._brain_names = ["FirstBrain"]
        self._external_brain_names = self._brain_names