Skip to content

Refactor: Simplify TrajectoryGroup and remove monkey-patching #307

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Mirza-Samad-Ahmed-Baig
Copy link

This pull request refactors the TrajectoryGroup class to simplify its initialization and remove the need for monkey-patching in the ART CLI. Previously, the TrajectoryGroup class had a complex new method to handle both synchronous and asynchronous creation, which required monkey-patching in the server environment to function correctly. This approach made the code harder to understand and maintain. This refactoring addresses the issue by: - Moving the asynchronous instantiation logic to a new from_awaitables class method. This separates the asynchronous and synchronous creation paths, making the code more explicit and easier to follow. - Simplifying the new and init methods to handle only the standard, synchronous case. - Removing the monkey-patching code from src/art/cli.py, as it is no longer necessary. These changes improve code clarity, maintainability, and eliminate the potential side effects of modifying a class at runtime. The TrajectoryGroup class is now more robust and easier to use in different contexts without workarounds.

@corbt corbt requested a review from bradhilton August 7, 2025 02:13
@corbt
Copy link
Contributor

corbt commented Aug 7, 2025

@bradhilton you're probably the best person to review here!

@corbt
Copy link
Contributor

corbt commented Aug 7, 2025

@Mirza-Samad-Ahmed-Baig could you review the failing code quality checks and fix if necessary?

Copy link
Collaborator

@bradhilton bradhilton left a comment

Choose a reason for hiding this comment

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

There appear to be syntax errors in trajectories.py

@Mirza-Samad-Ahmed-Baig
Copy link
Author

Thank you for reviewing, oh man how can I leave that like that. I will correct that soon.

The __new__ method in TrajectoryGroup had syntax errors due to incorrect overloading. This commit refactors the method to correctly handle both synchronous and asynchronous instantiation.
@Mirza-Samad-Ahmed-Baig
Copy link
Author

Done, further lowered the required uv version to 0.6.13 to align with the available development environment.

Copy link
Collaborator

@bradhilton bradhilton left a comment

Choose a reason for hiding this comment

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

There are at least a couple type errors:

/home/ubuntu/sky_workdir/src/art/trajectories.py
  /home/ubuntu/sky_workdir/src/art/trajectories.py:175:9 - error: Overloaded implementation is not consistent with signature of overload 1
    Function return type "TrajectoryGroup" is incompatible with type "Self@TrajectoryGroup | CoroutineWithMetadata"
      Type "TrajectoryGroup" is not assignable to type "Self@TrajectoryGroup | CoroutineWithMetadata"
        Type "TrajectoryGroup" is not assignable to type "Self@TrajectoryGroup"
        "TrajectoryGroup" is not assignable to "CoroutineWithMetadata" (reportInconsistentOverload)
  /home/ubuntu/sky_workdir/src/art/trajectories.py:175:9 - error: Overloaded implementation is not consistent with signature of overload 2
    Function return type "Awaitable[TrajectoryGroup]" is incompatible with type "Self@TrajectoryGroup | CoroutineWithMetadata"
      Type "Awaitable[TrajectoryGroup]" is not assignable to type "Self@TrajectoryGroup | CoroutineWithMetadata"
        Type "Awaitable[TrajectoryGroup]" is not assignable to type "Self@TrajectoryGroup"
        "Awaitable[TrajectoryGroup]" is not assignable to "CoroutineWithMetadata" (reportInconsistentOverload)
2 errors, 0 warnings, 0 informations

You can run type checking with $ uv run pyright src

More generally, I suggest merging main and running scripts/run_checks.sh to ensure everything is working as expected. I also noted one lint issue (import sort issue).

I haven't yet tested cli.py. I'm not sure this will obviate the need for the patching. If you can demonstrate that calling the train endpoint succeeds without the patch, that would be helpful too. One way to do that would be successfully running uv run examples/tic-tac-toe/tic-tac-toe.py --backend skypilot.

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.

3 participants