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

feat: add get_associated_experiment method to pipeline_jobs #1476

Merged
merged 5 commits into from Jul 7, 2022

Conversation

sararob
Copy link
Contributor

@sararob sararob commented Jul 6, 2022

Added a get_associated_experiment method to PipelineJob to return the Experiment associated with the provided pipeline job.

@sararob sararob requested a review from sasha-gitg July 6, 2022 14:45
@product-auto-label product-auto-label bot added size: m Pull request size is medium. api: vertex-ai Issues related to the googleapis/python-aiplatform API. labels Jul 6, 2022
@@ -776,3 +776,31 @@ def clone(
)

return cloned

def get_associated_experiment(self) -> Optional["experiment_resources.Experiment"]:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
def get_associated_experiment(self) -> Optional["experiment_resources.Experiment"]:
def get_associated_experiment(self) -> Optional["aiplatform.Experiment"]:


def get_associated_experiment(self) -> Optional["experiment_resources.Experiment"]:
"""Returns the aiplatform.Experiment associated with this PipelineJob,
or None if this PipelineJob is not associated with an experiment."""
Copy link
Member

Choose a reason for hiding this comment

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

Returns section.

pipeline_experiment_resource_names = []

for i in pipeline_context_resources:
if i.schema_title == "system.Experiment":
Copy link
Member

Choose a reason for hiding this comment

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


pipeline_parent_contexts = (
self._gca_resource.job_detail.pipeline_run_context.parent_contexts
)
Copy link
Member

Choose a reason for hiding this comment

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

You can locally filter out the pipeline_context to avoid an additional GET: https://github.com/googleapis/python-aiplatform/blob/main/google/cloud/aiplatform_v1/types/pipeline_job.py#L309

ie:

pipeline_parent_context = [c for c in pipeline_parent_contexts if c.name != self._gca_resource.job_detail.pipeline_context.name


if len(pipeline_experiment_resource_names) > 1:
_LOGGER.warning(
"There are more than experiments associated with this pipeline, returning only one..."
Copy link
Member

Choose a reason for hiding this comment

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

More informative logging message, logging all the found experiments and and experiment that is being returned.


for i in pipeline_context_resources:
if i.schema_title == "system.Experiment":
pipeline_experiment_resource_names.append(i.name.split("contexts/")[1])
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 you can use context.name

google/cloud/aiplatform/pipeline_jobs.py Outdated Show resolved Hide resolved
@@ -29,6 +29,10 @@
from google.cloud import aiplatform
Copy link
Member

Choose a reason for hiding this comment

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

Please also update the experiment system tests to test this functinality. Add a test right after this test: https://github.com/googleapis/python-aiplatform/blob/main/tests/system/aiplatform/test_experiments.py#L263

It should be able to get the pipeline_job using job = aiplatform.PipelineJob(self._pipeline_job_id and then verify the associated experiment is self._experiment_name.

Copy link
Contributor Author

@sararob sararob Jul 7, 2022

Choose a reason for hiding this comment

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

I added a call to get_associated_experiment to test_add_pipeline_job_to_experiment. Verified it passed on my test project and just kicked off our system tests from my branch.

@sararob sararob requested a review from sasha-gitg July 6, 2022 23:46
@sararob sararob merged commit e9f2c3c into googleapis:main Jul 7, 2022
sararob added a commit to sararob/python-aiplatform that referenced this pull request Jul 7, 2022
…is#1476)

* feat: add get_associated_experiment method to pipeline_jobs

* updates from reviewer feedback

* clean up system test

* re-add check for experiment schema title
sararob added a commit to sararob/python-aiplatform that referenced this pull request Jul 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: vertex-ai Issues related to the googleapis/python-aiplatform API. size: m Pull request size is medium.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants