Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed 'passMark' Bug due to incorrect and inconsistent handling #40

Merged

Conversation

alhasacademy96
Copy link
Contributor

@alhasacademy96 alhasacademy96 commented Aug 20, 2024

PR Description

The bug was apparent when multiple arenas were defined in the yaml configuration but some of them had incorrect/inconsistent passMark values assigned to them. For example, there are 3 arenas defined, with each 20, 50, 100 passMark values assigned to them. Upon play, the first arena had passMark value of 0, and second arena had a passMark of 20, the third 50.

Proposed change(s)

This PR refactors the handling of the passMark property across several classes to remove redundancy and simplify the codebase. Specifically, I removed unnecessary static properties and methods related to passMark and ensured that the value is correctly parsed from the YAML configuration and applied directly in the ArenaConfiguration class.

In the code, a redundant variable and getter method related to passMark parameter was removed to simply and improve code.

Changes:

Removed Redundant Static Logic:

  • The CurrentPassMark static property and associated SetCurrentPassMark method were removed from the Arena class, as they were unnecessary and caused duplication of logic.

Direct Property Access:

  • The passMark property in the ArenaConfiguration class is now directly set from the YAML configuration and used without additional getter/setter methods.

Updated Class Implementations:

  • YAMLDefs.cs: Simplified passMark handling by removing the static logic and using direct property assignment.
  • ArenasParameters.cs: Removed duplicate logic and ensured that passMark is correctly stored and accessed within ArenaConfiguration.
  • TrainingArena.cs: Cleaned up pass mark application logic, ensuring it is directly pulled from ArenaConfiguration.
  • TrainingAgent.cs: Updated references to passMark to ensure it is used correctly during training.

Useful links (Github issues, ML-Agents forum threads etc.)

Types of change(s)

  • 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
    • Verified tests using existing tests and via Debug logs.
  • Updated the changelog (if applicable)
  • Updated the documentation (if applicable)
  • Updated the migration guide (if applicable)

Other comments

Key tests carried out:

  • Verified that the passMark is correctly parsed and applied from the YAML files in various test cases.
  • Ensured that the agent behaves as expected when the passMark is set, including transitioning between arenas.
  • Manually tested scenarios with different passMark values to ensure consistency and correctness.

This PR also significantly simplifies the handling of the passMark property, reducing the potential for bugs and making the code easier to maintain.

Screenshots (if any)

Modifications:
- Removed the static CurrentPassMark and the associated SetCurrentPassMark method in the Arena class, as they were not necessary (redundant)
- The passMark property in the Arena class remains and is used directly, avoiding duplication and ensuring that the pass mark value is set correctly from the YAML configuration.
Mods:
- Removed duplicate pass mark management logic. The passMark property in the ArenaConfiguration class now directly reflects the value parsed from the YAML configuration.
- Ensured that the passMark is correctly passed and applied when an arena configuration is loaded.
Modifications:
- Removed redundant logic related to passMark setting and retrieval.
- Updated the ApplyNewArenaConfiguration method to directly use the passMark value from the ArenaConfiguration instance without any additional methods (reduced LoC)
- added debug statements strategically to confirm the correct application of the passMark.
Modifications are:
- Updated to use the passMark directly from the ArenaConfiguration without relying on any static properties or methods (this was likely causing half the the bug logic)
- Added debug logging in OnEpisodeBegin and other relevant methods to ensure the correct passMark is being used and applied throughout the training process.
- Removed EpisodeDebugLogs() method as redundancy.
@alhasacademy96 alhasacademy96 linked an issue Aug 20, 2024 that may be closed by this pull request
@alhasacademy96 alhasacademy96 marked this pull request as ready for review August 20, 2024 17:34
@alhasacademy96 alhasacademy96 added the bug fix A fix to a known bug label Aug 20, 2024
@benaslater benaslater self-assigned this Aug 22, 2024
@benaslater
Copy link
Contributor

nit: In the PR description this is highlighted as a bug fix, but the title of the PR calls it a refactor. I would expect a refactor not to change any functionality - the title should make it clear that this change is fixing a bug and how. Additionally the comment explaining the PR should be explicit about what the behaviour of the bug was, what was causing it and how the change fixes it.

It's good to do some tidying up in the course of fixing a bug, and to describe what those changes are, but if you've set out to fix a bug and succeeded that's the main thing!

@alhasacademy96 alhasacademy96 changed the title Refactor 'passMark' Handling: Remove Redundant Logic and Simplify Property Access Fixed 'passMark' Bug due to incorrect and inconsistent logic handling Aug 23, 2024
@alhasacademy96 alhasacademy96 changed the title Fixed 'passMark' Bug due to incorrect and inconsistent logic handling Fixed 'passMark' Bug due to incorrect and inconsistent handling Aug 23, 2024
@benaslater
Copy link
Contributor

nit: It's good to have detailed descriptions in the commit messages, but commits also need titles otherwise people are faced with this view when they look at the history

image

@alhasacademy96 alhasacademy96 merged commit 6458eee into main Sep 2, 2024
@alhasacademy96 alhasacademy96 deleted the fix-passMark-value-discrepancy-per-configuration branch September 2, 2024 12:22
Copy link
Contributor

@benaslater benaslater left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a good addition to this PR would be a test that previously did not pass but now does, just so it's really clear what was previously broken, that it's fixed now, and that we have something that will stop it from breaking in the future

Assets/Scripts/TrainingAgent.cs Show resolved Hide resolved
Assets/Scripts/TrainingArena.cs Show resolved Hide resolved
Assets/Scripts/TrainingArena.cs Show resolved Hide resolved
Assets/Scripts/TrainingArena.cs Show resolved Hide resolved
Assets/Scripts/TrainingAgent.cs Show resolved Hide resolved
Assets/Scripts/ArenasParameters.cs Show resolved Hide resolved
Assets/Scripts/TrainingArena.cs Show resolved Hide resolved
@alhasacademy96
Copy link
Contributor Author

Yeah so in order to see this bug simply put (as an example) two or three arena configs - set their passMark values individually and check the debug logs on unity. You will see the inconsistencies.

I'm surprised how this bug was left unnoticed until now. There will be more comprehensive tests added

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug fix A fix to a known bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PassMark for Arena 0 (index 0) is skipped/not being set
2 participants