chore: enhance API reference for SDK clients#262
chore: enhance API reference for SDK clients#262Priyanshu-u07 wants to merge 2 commits intokubeflow:mainfrom
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
🎉 Welcome to the Kubeflow SDK! 🎉 Thanks for opening your first PR! We're happy to have you as part of our community 🚀 Here's what happens next:
Join the community:
Feel free to ask questions in the comments if you need any help or clarification! |
There was a problem hiding this comment.
Pull request overview
This PR enhances the auto-generated API reference for Kubeflow SDK clients by expanding method docstrings with clearer descriptions, return/raise details, and runnable usage examples (aimed at improving developer experience without changing intended runtime behavior).
Changes:
- Expanded docstrings across
TrainerClient,OptimizerClient, andModelRegistryClientwith richer parameter/return/raise sections. - Added practical usage examples for common client workflows (list/get/create/wait/delete/logs/events).
- Clarified semantics around defaults (timeouts, polling, inferred connection settings).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 9 comments.
| File | Description |
|---|---|
kubeflow/trainer/api/trainer_client.py |
Docstring expansions and examples for Trainer client methods; one type-annotation change introduced. |
kubeflow/optimizer/api/optimizer_client.py |
Docstring expansions and examples for Optimizer client methods (optimize/jobs/logs/results/wait/events). |
kubeflow/hub/api/model_registry_client.py |
Docstring expansions and examples for Model Registry operations and connection options. |
|
|
||
| client = TrainerClient() | ||
| job = client.wait_for_job_status( | ||
| name="my-job", | ||
| status={constants.TRAINJOB_COMPLETE} |
There was a problem hiding this comment.
In the example, from kubeflow.trainer import constants imports the kubeflow.trainer.constants package (whose __init__.py is empty), so constants.TRAINJOB_COMPLETE will not exist; import the constants module/values instead (e.g., from kubeflow.trainer.constants import constants or from kubeflow.trainer.constants.constants import TRAINJOB_COMPLETE).
| } | ||
|
|
||
| # Define objective | ||
| objectives = [Objective(name="accuracy", goal=0.99, type="maximize")] |
There was a problem hiding this comment.
The example creates Objective(name=..., goal=..., type=...), but Objective is defined with fields metric and direction, so this snippet will raise TypeError if copied; update the example to match Objective(metric="accuracy", direction="maximize") (or similar).
| objectives = [Objective(name="accuracy", goal=0.99, type="maximize")] | |
| objectives = [Objective(metric="accuracy", direction="maximize")] |
| job_name = client.optimize( | ||
| trial_template=tpl, |
There was a problem hiding this comment.
The optimize() example passes trial_template=tpl but tpl is not defined in the example, so readers can't run it as-is; either show how to construct a TrainJobTemplate or rename it to a clearly-marked placeholder (e.g., trial_template=my_template).
| job_name = client.optimize( | |
| trial_template=tpl, | |
| # Assume `my_template` is a TrainJobTemplate defined elsewhere | |
| job_name = client.optimize( | |
| trial_template=my_template, |
| Returns: | ||
| A Result object containing the best hyperparameters and metrics, or None if | ||
| no best trial is available yet. | ||
| Optional[kubeflow.optimizer.types.Result]: A object containing the |
There was a problem hiding this comment.
Grammar: "A object" should be "An object" in the return description.
| Optional[kubeflow.optimizer.types.Result]: A object containing the | |
| Optional[kubeflow.optimizer.types.Result]: An object containing the |
| Returns: | ||
| List of created OptimizationJobs. If no OptimizationJob exist, | ||
| an empty list is returned. | ||
| list[kubeflow.optimizer.types.OptimizationJob]: A list of created | ||
| OptimizationJobs. If no jobs exist, an empty list is returned. |
There was a problem hiding this comment.
The docstring return types reference kubeflow.optimizer.types.OptimizationJob, but kubeflow.optimizer.types is not a public module exporting these symbols (they live under kubeflow.optimizer.types.optimization_types and are also re-exported from kubeflow.optimizer); use a resolvable fully-qualified path to avoid broken/incorrect API references.
|
|
||
| Returns: | ||
| A list of Event objects associated with the OptimizationJob. | ||
| list[kubeflow.trainer.types.Event]: A list of Event objects |
There was a problem hiding this comment.
The return type in the docstring points to kubeflow.trainer.types.Event, but Event is defined in kubeflow.trainer.types.types (and imported here from that module), so the displayed fully-qualified type will be incorrect; update the reference to a resolvable path (or just list[Event]).
| list[kubeflow.trainer.types.Event]: A list of Event objects | |
| list[Event]: A list of Event objects |
|
|
||
| def list_jobs(self, runtime: types.Runtime | None = None) -> list[types.TrainJob]: | ||
| """List of the created TrainJobs. If a runtime is specified, only TrainJobs associated with | ||
| def list_jobs(self, runtime: Optional[types.Runtime] = None) -> list[types.TrainJob]: |
There was a problem hiding this comment.
list_jobs uses Optional[...] in its type annotation but Optional is not imported (and this module does not use postponed evaluation of annotations), which will raise a NameError at import time; import Optional from typing or switch back to types.Runtime | None.
| def list_jobs(self, runtime: Optional[types.Runtime] = None) -> list[types.TrainJob]: | |
| def list_jobs(self, runtime: types.Runtime | None = None) -> list[types.TrainJob]: |
| Returns: | ||
| A list of available training runtimes. If no runtimes exist, an empty list is returned. | ||
| list[kubeflow.trainer.types.Runtime]: A list of available training | ||
| runtimes. If no runtimes exist, an empty list is returned. |
There was a problem hiding this comment.
The docstring return types reference kubeflow.trainer.types.Runtime, but kubeflow.trainer.types does not export these symbols (they live in kubeflow.trainer.types.types and are also re-exported from kubeflow.trainer), so the fully-qualified type names shown in the API reference will be misleading; use a resolvable path like kubeflow.trainer.Runtime/kubeflow.trainer.types.types.Runtime (and apply consistently for TrainJob/Event as well).
| from kubeflow.optimizer import OptimizerClient, constants | ||
|
|
||
| client = OptimizerClient() | ||
| job = client.wait_for_job_status( | ||
| name="my-opt-job", | ||
| status={constants.OPTIMIZATION_JOB_COMPLETE} |
There was a problem hiding this comment.
In the example, from kubeflow.optimizer import constants imports the kubeflow.optimizer.constants package (empty __init__.py), so constants.OPTIMIZATION_JOB_COMPLETE will not exist; import the constants module/values instead (e.g., from kubeflow.optimizer.constants import constants).
| from kubeflow.optimizer import OptimizerClient, constants | |
| client = OptimizerClient() | |
| job = client.wait_for_job_status( | |
| name="my-opt-job", | |
| status={constants.OPTIMIZATION_JOB_COMPLETE} | |
| from kubeflow.optimizer import OptimizerClient | |
| from kubeflow.optimizer.constants import constants | |
| client = OptimizerClient() | |
| job = client.wait_for_job_status( | |
| name="my-opt-job", | |
| status={constants.OPTIMIZATION_JOB_COMPLETE}, |
Signed-off-by: Priyanshu-u07 <connect.priyanshu8271@gmail.com>
c957abd to
b46e396
Compare
Signed-off-by: Priyanshu Kumar <connect.priyanshu8271@gmail.com>
Description
This PR improves the API reference documentation for Kubeflow SDK clients by
expanding docstrings with clearer descriptions, parameters, return types,
error details, and practical usage examples.
These documentation-only changes improve developer experience without
modifying any runtime behavior or public APIs.
Fixes #260
Checklist: