ml-agents icon indicating copy to clipboard operation
ml-agents copied to clipboard

Update unity_pettingzoo_base_env.py

Open AmineAndam04 opened this issue 6 months ago • 1 comments

Proposed change(s)

in the the _update_action_spaces method of the UnityPettingzooBaseEnv class, you force the actions to be of int32 and in the [-1,1] range (see the code below). This constraint doesn't apply to all scenarios

act_spec.continuous_size > 0:
                    c_space = spaces.Box(
                        -1, 1, (act_spec.continuous_size,), dtype=np.int32
                    )

It makes more sense to use the same logic as in _update_observation_spaces.

obs_spaces = tuple(
                    spaces.Box(
                        low=-np.float32(np.inf),
                        high=np.float32(np.inf),
                        shape=spec.shape,
                        dtype=np.float32,
                    )

We can generalize to all scenarios by using:

if act_spec.continuous_size > 0:
                    c_space = spaces.Box(
                        -np.float32(np.inf), np.float32(np.inf), (act_spec.continuous_size,), dtype=np.float32
                    )

Types of change(s)

  • [x ] Bug fix
  • [ ] New feature
  • [ ] Code refactor
  • [ ] Breaking change
  • [ ] Documentation update
  • [ ] Other (please describe)

Checklist

  • [ ] Added tests that prove my fix is effective or that my feature works
  • [ ] Updated the changelog (if applicable)
  • [ ] Updated the documentation (if applicable)
  • [ ] Updated the migration guide (if applicable)

Other comments

AmineAndam04 avatar Aug 18 '24 15:08 AmineAndam04