diff --git a/README.md b/README.md index da0bec6..feab2bd 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ pip install -e . ``` ## Overview + Columbus.pdf contains a overview of columbus. ## Layout of the Repo @@ -27,6 +28,7 @@ There exist two ways to implement new envs: - Subclassing ColumbusEnv and expanding _init_ and overriding _setup_. - Using the ColumbusConfigDefined with a desired configuration. This makes configuring ColumbusEnvs via ClusterWorks2-configs possible. (See configs/example.yaml for an example of how the parameters are supposed to look like (uses yaml format) +- We now support using units (px, em, ct) in config files, examples can be found in configs/Example_Units.yaml - The environments used in my thesis can also be found in configs/ ##### Some caveats / infos diff --git a/columbus/env.py b/columbus/env.py index c76aea1..1814915 100644 --- a/columbus/env.py +++ b/columbus/env.py @@ -839,6 +839,45 @@ class ColumbusConfigDefined(ColumbusEnv): observable=observable, fps=fps, env_seed=env_seed, **kw) self.entities_definitions = entities + def is_unit(self, s): + if type(s) in [int, float]: + return True + if s.replace('.', '', 1).isdigit(): + return True + num, unit = s[:-2], s[-2:] + if unit in ['px', 'em', 'rx', 'ry', 'ct']: + if num.replace('.', '', 1).isdigit(): + return True + return False + + def conv_unit(self, s, target='px', axis='x'): + assert self.is_unit(s) + if type(s) in [int, float]: + return s + if s.replace('.', '', 1).isdigit(): + return float(s) + num, unit = s[:-2], s[-2:] + num = float(num) + if unit == 'rx': + unit = 'px' + axis = 'x' + elif unit == 'ry': + unit = 'px' + axis = 'y' + if unit == 'em': + em = num + elif unit == 'px': + em = num / ({'x': self.width, 'y': self.height}[axis]) + elif unit == 'ct': + em = num / 100 + else: + raise Exception('Conversion not implemented') + + if target == 'em': + return em + elif target == 'px': + return em * ({'x': self.width, 'y': self.height}[axis]) + def setup(self): self.agent.pos = self.start_pos for i, e in enumerate(self.entities_definitions): @@ -848,7 +887,15 @@ class ColumbusConfigDefined(ColumbusEnv): conf = {k: v for k, v in e.items() if str( k) not in ['num', 'num_rand', 'type']} - for k, v in conf.items(): + for k, v_raw in conf.items(): + if k == 'pos': + v = self.conv_unit(v_raw[0], target='em', axis='x'), self.conv_unit( + v_raw[1], target='em', axis='y') + elif k in ['width', 'height', 'radius']: + v = self.conv_unit( + v_raw, target='px', axis='y' if k == 'height' else 'x') + else: + v = v_raw if k.endswith('_rand'): n = k.replace('_rand', '') cur = getattr( diff --git a/configs/Example_Units.yaml b/configs/Example_Units.yaml new file mode 100644 index 0000000..14c005e --- /dev/null +++ b/configs/Example_Units.yaml @@ -0,0 +1,85 @@ +name: "DEFAULT" + +# Supported Units: +# px: Pixels +# em: 1em = Full Width / Height +# ct: 100ct = Full Width / Height +# rx: pixels relative to width +# ry: pixels relative to height +# +# When no unit is given, we use the folowing defaults +# (compatible with legacy behavior) +# pos: em +# all other: px +# +# ct is the recommendet unit... + +params: + task: + task: columbus + env_name: ColumbusConfigDefined-v0 + env_args: + observable: + - type: State + coordsAgent: True + speedAgent: True + coordsRelativeToAgent: False + coordsRewards: True + coordsEnemys: False + enemysNoBarriers: True + rewardsTimeouts: False + include_rand: True + - type: State + coordsAgent: False + speedAgent: False + coordsRelativeToAgent: True + coordsRewards: True + coordsEnemys: False + enemysNoBarriers: True + rewardsTimeouts: False + include_rand: True + - type: Compass + - type: RayCast + num_rays: 6 + chans: [Enemy] + entities: + - type: RectBarrier + num: 1 + width: 50ct + height: 50ct + pos: [0ct, 0ct] + - type: RectBarrier + num: 1 + width: 50ct + height: 50ct + pos: [50ct, 50ct] + - type: RectBarrier + num: 1 + width: 25rx + height: 25ry + pos: [0.75em, 30px] + - type: RectBarrier + num: 1 + width: 25ry + height: 25rx + pos: [0.75em, 60px] + - type: OnceReward + reward: 100 + radius: 3ct + pos: [0.3, 0.8] + start_pos: [0.1, 0.21] + default_collision_elasticity: 0.8 + start_score: 10 + speed_fac: 0.01 + acc_fac: 0.1 + die_on_zero: False #True + agent_drag: 0.1 # 0.05 + controll_type: ACC # SPEED + aux_reward_max: 1 + aux_penalty_max: 0.01 + void_damage: 5 #1 + terminate_on_reward: True + agent_draw_path: True + clear_path_on_reset: False + max_steps: 450 # 1800 +--- \ No newline at end of file