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

Add unit test for create_experiment in the katib_client module #2325

Merged

Conversation

tariq-hasan
Copy link
Contributor

@tariq-hasan tariq-hasan commented May 6, 2024

What this PR does / why we need it:

  • Unit test has been added for the create_experiment function as part of this commit.
  • Code refactoring has been done as part of other commits in the PR.
  • I plan to create a second PR to add unit test for the tune function once this is merged.

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 #2184

Test Plan: The code for the Python tests has been verified as part of this CI workflow.

Checklist:

  • Docs included if any changes are user facing

@tariq-hasan tariq-hasan changed the title Add unit tests for katib client Add unit test for create_experiment in the katib_client module May 6, 2024
@tariq-hasan tariq-hasan force-pushed the add-unit-tests-for-katib-client branch from 1545807 to 2aacab9 Compare May 6, 2024 06:10
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 so much for taking this @tariq-hasan and sorry for the late review!
I left a few comments.

import logging
logging.basicConfig()
log = logging.getLogger("kubeflow.katib.api.katib_client")
log.setLevel(logging.DEBUG)
Copy link
Member

Choose a reason for hiding this comment

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

Thank you for adding this!

constants.KUBEFLOW_GROUP,
constants.KATIB_VERSION,
namespace,
constants.EXPERIMENT_PLURAL,
experiment,
)
experiment_name = outputs["metadata"][
"name"
] # if "generate_name" is used, "name" gets a prefix from server
Copy link
Member

Choose a reason for hiding this comment

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

We need to keep that in case experiment is created using generate_name

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it. My understanding of the code was not complete hence I removed it incorrectly. I have reverted this code change and updated the create_namespaced_custom_object_response function to account for the output of the create_namespaced_custom_object function.

"experiment": create_experiment(name="experiment-mnist-ci-test"),
"namespace": "test",
},
"success",
Copy link
Member

Choose a reason for hiding this comment

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

Can we make this string as constant ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I created a constant to replace "success".

Comment on lines 210 to 214
"experiment": create_experiment(
name="experiment-mnist-ci-test",
generate_name="experiment-mnist-ci-test",
),
"namespace": "test"
Copy link
Member

Choose a reason for hiding this comment

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

If we pass generate_name and name how does Kubernetes Python client create the Experiment ?

Copy link
Contributor Author

@tariq-hasan tariq-hasan Jun 15, 2024

Choose a reason for hiding this comment

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

I suppose that name is used when both name and generate_name are provided.
Ref: https:/tariq-hasan/katib/blob/master/sdk/python/v1beta1/kubeflow/katib/api/katib_client.py#L102-L105.

Would you suggest making changes to this case?

Copy link
Member

Choose a reason for hiding this comment

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

These parameters are mutually exclusive. Users can set name or generate_name

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay. I have removed the two test cases where both name and generate_name are specified.

Comment on lines 76 to 77
logger.debug(f"Current Optimal Trial:\n {experiment.status.current_optimal_trial}")
logger.debug(f"Experiment conditions:\n {experiment.status.conditions}")
Copy link
Member

Choose a reason for hiding this comment

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

Do we want to keep print here similar to get_job_logs API in Training Client: https:/kubeflow/training-operator/blob/master/sdk/python/kubeflow/training/api/training_client.py#L1193 ?
Since when user runs this API, the SDK works like CLI and user wants to get output.
WDYT @droctothorpe @tariq-hasan @kubeflow/wg-automl-leads ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have reverted the changes to keep print.

@andreyvelich
Copy link
Member

Hi @tariq-hasan, do you have some time to finish this PR ?

@tariq-hasan
Copy link
Contributor Author

Hi @tariq-hasan, do you have some time to finish this PR ?

Hi @andreyvelich I will try to complete it this week. Sorry about the delay.

@tariq-hasan tariq-hasan force-pushed the add-unit-tests-for-katib-client branch 3 times, most recently from c4e9bf4 to 4e963bc Compare June 15, 2024 18:49
@tariq-hasan tariq-hasan force-pushed the add-unit-tests-for-katib-client branch 3 times, most recently from 2092eec to ab56bf9 Compare June 15, 2024 19:40
@google-oss-prow google-oss-prow bot added size/XXL and removed size/L labels Jun 15, 2024
@tariq-hasan tariq-hasan force-pushed the add-unit-tests-for-katib-client branch from ab56bf9 to 85dc9a1 Compare June 15, 2024 19:41
@google-oss-prow google-oss-prow bot added size/L and removed size/XXL labels Jun 15, 2024
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, only 1 comment from me @tariq-hasan.
/assign @johnugeorge @tenzen-y

@@ -56,3 +57,6 @@
BASE_IMAGE_MXNET = "docker.io/mxnet/python:1.9.1_native_py3"

DEFAULT_DB_MANAGER_ADDRESS = "katib-db-manager.kubeflow:6789"

# Test result constants
TEST_RESULT_SUCCESS = "success"
Copy link
Member

Choose a reason for hiding this comment

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

Please keep this variable in the katib_client_test.py since we use it only in that file.

@tariq-hasan tariq-hasan force-pushed the add-unit-tests-for-katib-client branch from 887a69b to 6dbea78 Compare June 18, 2024 22:31
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 this great contribution @tariq-hasan 🎉
/lgtm
/approve

Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: andreyvelich

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:

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 99ba1d5 into kubeflow:master Jun 20, 2024
60 checks passed
@tariq-hasan
Copy link
Contributor Author

Thank you for this great contribution @tariq-hasan 🎉 /lgtm /approve

I suppose that the next step is to write unit test for the tune function.

@andreyvelich
Copy link
Member

andreyvelich commented Jun 24, 2024

Thank you for this great contribution @tariq-hasan 🎉 /lgtm /approve

I suppose that the next step is to write unit test for the tune function.

That's right @tariq-hasan. Please feel free to create an issue and assign it to yourself.

Additionally, it would be nice to add e2e test for tune API, like for create_experiment here: https:/kubeflow/katib/blob/master/test/e2e/v1beta1/scripts/gh-actions/run-e2e-experiment.py#L172
Similar to Training Operator tests: https:/kubeflow/training-operator/blob/master/sdk/python/test/e2e/test_e2e_pytorchjob.py#L174

@tariq-hasan tariq-hasan deleted the add-unit-tests-for-katib-client branch June 29, 2024 17:49
shashank-iitbhu pushed a commit to shashank-iitbhu/katib that referenced this pull request Jun 30, 2024
…ubeflow#2325)

* added logger for katib_client module

Signed-off-by: tariq-hasan <[email protected]>

* added API_VERSION as a constant

Signed-off-by: tariq-hasan <[email protected]>

* updated the KatibClient constructor to match the TrainingClient constructor

Signed-off-by: tariq-hasan <[email protected]>

* added test for create_experiment in katib_client

Signed-off-by: tariq-hasan <[email protected]>

---------

Signed-off-by: tariq-hasan <[email protected]>
shashank-iitbhu pushed a commit to shashank-iitbhu/katib that referenced this pull request Jul 25, 2024
…ubeflow#2325)

* added logger for katib_client module

Signed-off-by: tariq-hasan <[email protected]>

* added API_VERSION as a constant

Signed-off-by: tariq-hasan <[email protected]>

* updated the KatibClient constructor to match the TrainingClient constructor

Signed-off-by: tariq-hasan <[email protected]>

* added test for create_experiment in katib_client

Signed-off-by: tariq-hasan <[email protected]>

---------

Signed-off-by: tariq-hasan <[email protected]>
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.

Add unit tests to the Katib SDK
4 participants