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

Python SDK - Generate Name functionality for creating experiments. #2272

Conversation

bharathk005
Copy link
Contributor

What this PR does / why we need it:
Adds generate name functionality to Python SDK while creating experiments.
If metadata.name and metadata.generateName are missing, the code appends a new prefix called "exp-" to generateName.
This makes the server generate a new name with the prefix.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #
#2243

@bharathk005 bharathk005 changed the title Feature py sdk create exp generate name Python SDK - Generate Name functionality for creating experiments. Mar 4, 2024
@bharathk005
Copy link
Contributor Author

Please provide feedback on the approach.
I will make changes and do more testing based on this.

@tenzen-y
Copy link
Member

tenzen-y commented Mar 5, 2024

@bharathk005 Could you sign to the DCO?

Copy link
Member

@andreyvelich andreyvelich left a comment

Choose a reason for hiding this comment

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

Thank you for updating the SDK @bharathk005!

I think, the point from @fensterwetter was that our SDK should not block to use generateName parameter while using create_experiment API.

So here when we rise Exception or print that Experiment has been created, SDK will fail since experiment.metadata.name doesn't exist.

I think, we can check that name or generate_name exists before running create_namespaced_custom_object and then use this value later in the code.

@google-oss-prow google-oss-prow bot added size/S and removed size/XS labels Mar 5, 2024
Signed-off-by: Bharath Krishna <bharathk005@gmail.com>
@bharathk005 bharathk005 force-pushed the feature-py-sdk-create-exp-generateName branch from 78e6fba to e7eefc5 Compare March 5, 2024 22:56
@bharathk005
Copy link
Contributor Author

@tenzen-y and @andreyvelich thanks for the suggestions.
Please review the change and let me know.

@bharathk005 bharathk005 requested a review from andreyvelich March 5, 2024 22:59
Signed-off-by: Bharath Krishna <bharathk005@gmail.com>
@@ -93,29 +93,35 @@ def create_experiment(

namespace = namespace or self.namespace

if 'name' in experiment.metadata and experiment.metadata.name:
Copy link
Member

Choose a reason for hiding this comment

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

I think, it will raise Exception if experiment.metadata.name is not set.
We might need to have something like this:

         experiment_name = None

        if type(experiment) == models.V1beta1Experiment:
            if experiment.metadata.name is not None:
                experiment_name = experiment.metadata.name
            elif experiment.metadata.generate_name is not None:
                experiment_name = experiment.metadata.generate_name
        elif "name" in experiment["metadata"]:
            experiment_name = experiment["metadata"]["name"]
        elif "generateName" in experiment["metadata"]:
            experiment_name = experiment["metadata"]["generateName"]
        if experiment_name is None:
            raise ValueError("Experiment must have name or generateName")

Any thoughts @droctothorpe @tenzen-y @johnugeorge @bharathk005 @fensterwetter

Copy link
Contributor Author

@bharathk005 bharathk005 Mar 7, 2024

Choose a reason for hiding this comment

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

@andreyvelich thanks for the review.
I have added some changes based on your suggestions. Test cases pass on my machine.

Regarding the type assertion, the function already expects a "models.V1beta1Experiment" type:

def create_experiment(
self,
experiment: models.V1beta1Experiment,

Please let me know if we still need to check for the type.

Copy link
Member

Choose a reason for hiding this comment

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

I think, it will raise Exception if experiment.metadata.name is not set. We might need to have something like this:

         experiment_name = None

        if type(experiment) == models.V1beta1Experiment:
            if experiment.metadata.name is not None:
                experiment_name = experiment.metadata.name
            elif experiment.metadata.generate_name is not None:
                experiment_name = experiment.metadata.generate_name
        elif "name" in experiment["metadata"]:
            experiment_name = experiment["metadata"]["name"]
        elif "generateName" in experiment["metadata"]:
            experiment_name = experiment["metadata"]["generateName"]
        if experiment_name is None:
            raise ValueError("Experiment must have name or generateName")

Any thoughts @droctothorpe @tenzen-y @johnugeorge @bharathk005 @fensterwetter

Additionally, I would suggest to add the Exception if both name and generateName are specified.
@andreyvelich WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

Won't Kubernetes Python client throw an error when we try to create custom resources in that case ?

Copy link
Member

Choose a reason for hiding this comment

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

Regarding the type assertion, the function already expects a "models.V1beta1Experiment" type:

That's true, but since Python is not strong typed language, users can still send dict as Experiment. Otherwise, we need to check type(experiment) and through exception. Do we want to give users functionality to pass dict with create_experiment API @droctothorpe @tenzen-y @johnugeorge ?

Copy link
Member

@tenzen-y tenzen-y Mar 7, 2024

Choose a reason for hiding this comment

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

Won't Kubernetes Python client throw an error when we try to create custom resources in that case ?

I imaged like 102-103:

if experiment_name is None:
raise ValueError("Experiment must have a name or generateName")

So, my concerns have gone away. Thanks.

Copy link
Member

Choose a reason for hiding this comment

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

That's true, but since Python is not strong typed language, users can still send dict as Experiment. Otherwise, we need to check type(experiment) and through exception. Do we want to give users functionality to pass dict with create_experiment API @droctothorpe @tenzen-y @johnugeorge ?

I agree with the necessary for type assertion, but I think this is PR to support name generation.
So, I'm ok with working on it in another PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tenzen-y @andreyvelich thanks for the comments.

  1. Type assertion
  2. Throwing error if both name and generateName are provided
    Are these the changes that need to be implemented?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tenzen-y @andreyvelich Thanks for your time. I have pushed a commit with the changes mentioned in this thread. Please review and let me know.

Signed-off-by: Bharath Krishna <bharathk005@gmail.com>
Signed-off-by: Bharath Krishna <bharathk005@gmail.com>
Signed-off-by: Bharath Krishna <bharathk005@gmail.com>
@andreyvelich
Copy link
Member

Thank you for the updates @bharathk005!
/lgtm
/assign @tenzen-y @johnugeorge

Copy link
Member

@tenzen-y tenzen-y left a comment

Choose a reason for hiding this comment

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

I hope to add implementing some unit tests, but we don't have any unit tests now for SDK :(

ref: #2184

/lgtm
/approve

@kubeflow/wg-automl-leads Could you restart some CI jobs?

@tenzen-y
Copy link
Member

/hold

@andreyvelich
Copy link
Member

Thank you for your contribution @bharathk005 🎉
/hold cancel

@bharathk005
Copy link
Contributor Author

@andreyvelich is this part of 0.17?

@andreyvelich
Copy link
Member

andreyvelich commented Apr 1, 2024

@andreyvelich is this part of 0.17?

Sure, sorry that we haven't merged this PR yet.
@bharathk005 Please can you try to rebase it ? The tests might be fixed.

Signed-off-by: Bharath Krishna <bharathk005@gmail.com>
Signed-off-by: Bharath Krishna <bharathk005@gmail.com>
Signed-off-by: Bharath Krishna <bharathk005@gmail.com>
Signed-off-by: Bharath Krishna <bharathk005@gmail.com>
Signed-off-by: Bharath Krishna <bharathk005@gmail.com>
…harathk005/katib into feature-py-sdk-create-exp-generateName
@bharathk005
Copy link
Contributor Author

@andreyvelich is this part of 0.17?

Sure, sorry that we haven't merged this PR yet. @bharathk005 Please can you try to rebase it ? The tests might be fixed.

@andreyvelich Done. Please validate.

Copy link
Member

@andreyvelich andreyvelich left a comment

Choose a reason for hiding this comment

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

Thanks for the update @bharathk005!
/lgtm
/approve

@google-oss-prow google-oss-prow bot added the lgtm label Apr 2, 2024
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: andreyvelich, bharathk005, tenzen-y

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [andreyvelich,tenzen-y]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@google-oss-prow google-oss-prow bot merged commit 36150bc into kubeflow:master Apr 2, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants