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

Feature/evaluate agents #139

Merged
merged 15 commits into from
Oct 31, 2023
Merged

Feature/evaluate agents #139

merged 15 commits into from
Oct 31, 2023

Conversation

belerico
Copy link
Member

@belerico belerico commented Oct 31, 2023

Summary

This PR fixes #123, letting users to run post-training evaluation of the agent. In particular:

  • It introduces the evaluation.py file, one for every algorithm, with a decorated evaluation (@register_evaluation(algorithms: str | List[str])) method for an algorithm placed in the same directory. The algorithm(s) associated to the evaluation method is (are) specified by the algorithms keyword argument: the name of the algorithm(s) must be equal to the name of the .py file where the algorithm(s) is (are) implemented
  • It introduces a new registry called evaluation_registry, where the evaluation methods are associated to a particular algorithm

For example, suppose that we want to create two separate evaluation methods, one for ppo and one for ppo_decoupled algorithms. The sheeprl/algos/ppo/evaluate.py file will look like:

@register_evaluation(algorithms=["ppo"])
def evaluate_ppo(fabric: Fabric, cfg: Dict[str, Any], state: Dict[str, Any]):
    # implementation here


@register_evaluation(algorithms=["ppo_decoupled"])
def evaluate_ppo_decoupled(fabric: Fabric, cfg: Dict[str, Any], state: Dict[str, Any]):
    # implementation here

Since the registration happens at runtime upon import in the sheeprl/__init__.py file, the evaluation registration MUST HAPPEN after the algorithms registration:

# fmt: off
from sheeprl.algos.ppo import ppo  # noqa: F401
from sheeprl.algos.ppo import ppo_decoupled  # noqa: F401
# Import all other algorithms
# The algorithms are registered upond import

# This must be imported after the import of the ppo algorithms
from sheeprl.algos.ppo import evaluate as ppo_evaluate  # noqa: F401, isort:skip
# Import all other evaluation algorithms
# fmt: on

Type of Change

Please select the one relevant option below:

  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist

Please confirm that the following tasks have been completed:

  • I have tested my changes locally and they work as expected. (Please describe the tests you performed.)
  • I have added unit tests for my changes, or updated existing tests if necessary.
  • I have updated the documentation, if applicable.
  • I have installed pre-commit and run locally for my code changes.

Thank you for your contribution! Once you have filled out this template, please ensure that you have assigned the appropriate reviewers and that all tests have passed.

@belerico belerico linked an issue Oct 31, 2023 that may be closed by this pull request
@belerico belerico merged commit b6091e3 into main Oct 31, 2023
7 checks passed
@belerico belerico deleted the feature/evaluate-agents branch November 2, 2023 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Evaluation of checkpoints after training
2 participants