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

Refactor hopper training loop and model loading #66

Merged
merged 1 commit into from
Nov 26, 2024
Merged

Conversation

leonvanbokhorst
Copy link
Owner

@leonvanbokhorst leonvanbokhorst commented Nov 26, 2024

Simplify the hopper training loop by removing commented out code and unnecessary print statements. Also, refactor the model loading process to handle cases where no saved model is found. This improves the readability and maintainability of the code.

Summary by Sourcery

Enhancements:

  • Refactor the model loading process to handle cases where no saved model is found, improving code readability and maintainability.

Simplify the hopper training loop by removing commented out code and unnecessary print statements. Also, refactor the model loading process to handle cases where no saved model is found. This improves the readability and maintainability of the code.
Copy link
Contributor

sourcery-ai bot commented Nov 26, 2024

Reviewer's Guide by Sourcery

The changes uncomment and restore the training loop functionality in the hopper.py file, which includes model loading and training phases. The code now properly handles model loading with error cases and implements the training phase loop that was previously commented out.

Sequence diagram for the hopper training loop

sequenceDiagram
    actor User
    participant Hopper as Hopper Training
    participant Model as Model Loader

    User->>Hopper: Start Training
    Hopper->>Model: Load Model
    alt Model Found
        Model-->>Hopper: Load Successful
        Hopper->>Hopper: Update global_best_reward
    else No Model Found
        Model-->>Hopper: Error
        Hopper->>Hopper: Start with Untrained Agent
    end
    Hopper->>Hopper: Train Agent
    alt Training Successful
        Hopper-->>User: Reached Solution Threshold
    else Training Unsuccessful
        Hopper->>Hopper: Continue Training
    end
Loading

File-Level Changes

Change Details Files
Restore and implement the training phase loop
  • Uncomment the phase iteration loop that runs 10 training phases
  • Restore the training progress print statement
  • Implement the training loop with success condition check
  • Re-enable the early exit when solution threshold is reached
gym/hopper.py
Implement robust model loading functionality
  • Uncomment and enable model checkpoint loading code
  • Add error handling for FileNotFoundError and RuntimeError cases
  • Implement proper loading of previous best reward from checkpoint
  • Add informative print statements for model loading status
gym/hopper.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@leonvanbokhorst leonvanbokhorst merged commit 119e85c into main Nov 26, 2024
1 check failed
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @leonvanbokhorst - I've reviewed your changes - here's some feedback:

Overall Comments:

  • The commit message doesn't accurately reflect the changes. Consider updating it to something like 'Enable hopper training loop' since the main change is uncommenting and activating the existing training code rather than refactoring it.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

# # Pass global best reward to train
# success = ai.train(num_episodes=100, previous_best=global_best_reward)
# Pass global best reward to train
success = ai.train(num_episodes=100, previous_best=global_best_reward)
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (code-quality): Use named expression to simplify assignment and conditional (use-named-expression)

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.

1 participant