-
Notifications
You must be signed in to change notification settings - Fork 369
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
base: main
Are you sure you want to change the base?
Refactor: Simplify TrajectoryGroup and remove monkey-patching #307
Conversation
@bradhilton you're probably the best person to review here! |
@Mirza-Samad-Ahmed-Baig could you review the failing code quality checks and fix if necessary? |
There was a problem hiding this 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
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.
Done, further lowered the required |
There was a problem hiding this 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
.
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.