Skip to content

chore: Add filtering for experiment.list method #5336

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions google/cloud/aiplatform/metadata/experiment_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ def get_or_create(
def list(
cls,
*,
filter: Optional[str] = None,
project: Optional[str] = None,
location: Optional[str] = None,
credentials: Optional[auth_credentials.Credentials] = None,
Expand All @@ -327,6 +328,8 @@ def list(
```

Args:
filter (str):
Optional. A query to filter available resources for matching results.
project (str):
Optional. Project to list these experiments from. Overrides project set in
aiplatform.init.
Expand All @@ -343,6 +346,8 @@ def list(
filter_str = metadata_utils._make_filter_string(
schema_title=constants.SYSTEM_EXPERIMENT
)
if filter:
filter_str = f"{filter_str} AND ({filter})"

with _SetLoggerLevel(resource):
experiment_contexts = context.Context.list(
Expand Down
21 changes: 21 additions & 0 deletions tests/system/aiplatform/test_experiments.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,27 @@ def test_get_run(self):
assert run.name == _RUN
assert run.state == aiplatform.gapic.Execution.State.RUNNING

def test_list_experiment(self):
experiments = aiplatform.Experiment.list(
project=e2e_base._PROJECT,
location=e2e_base._LOCATION,
)
assert isinstance(experiments, list)
assert any(
experiment.name == self._experiment_name for experiment in experiments
)

def test_list_experiment_filter(self):
experiments = aiplatform.Experiment.list(
filter=f"display_name = {self._experiment_name}",
project=e2e_base._PROJECT,
location=e2e_base._LOCATION,
)
assert len(experiments) == 1
assert any(
experiment.name == self._experiment_name for experiment in experiments
)

def test_log_params(self):
aiplatform.init(
project=e2e_base._PROJECT,
Expand Down