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: Made display_name parameter optional for most calls #882

Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
65224d6
feat: Made display_name optional for most calls
Ark-kun Dec 3, 2021
b2958ae
Reverted the change to _Dataset.create interface
Ark-kun Feb 3, 2022
b0e19fe
Extracted the display name generation to the _generate_display_name m…
Ark-kun Feb 3, 2022
47563a0
Made Model.batch_predict(job_display_name=) optional
Ark-kun Feb 3, 2022
b3234dc
Removed the unused imports
Ark-kun Feb 3, 2022
c0d2aee
Added a unit test
Ark-kun Feb 3, 2022
f08c19b
Fixed getting the class name.
Ark-kun Feb 5, 2022
9e5a800
Fixed code style
Ark-kun Feb 7, 2022
1cfc9c1
Fixed the unit test
Ark-kun Feb 7, 2022
54c658f
Merge branch 'main' into feat--Made-display_name-optional-for-most-calls
kweinmeister Feb 18, 2022
701bbbd
Merge branch 'main' into feat--Made-display_name-optional-for-most-calls
kweinmeister Feb 23, 2022
00977be
Restore the parameter ordering as requested by reviewer
Ark-kun Feb 25, 2022
8c8c8aa
Marked the BatchPredictJob.create job_display_name parameter as optional
Ark-kun Mar 2, 2022
8e69108
Merge branch 'main' into feat--Made-display_name-optional-for-most-calls
kweinmeister Mar 3, 2022
560b0a8
Merge branch 'main' into feat--Made-display_name-optional-for-most-calls
kweinmeister Mar 7, 2022
dfd164d
Restored the parameter order in jobs.py as asked by reviewer
Ark-kun Mar 7, 2022
93acea0
Added bug link to the TODO comments
Ark-kun Mar 7, 2022
348b51c
Annotated _Dataset.create(display_name) as Optional
Ark-kun Mar 7, 2022
57b1241
Changed docstringg as asked by the reviewer
Ark-kun Mar 17, 2022
fee7b89
Implemented the reviewer request: Removed the Optional[str] annotatio…
Ark-kun Apr 1, 2022
a695fb5
Merge branch 'main' into feat--Made-display_name-optional-for-most-calls
Ark-kun Apr 1, 2022
92c1eaf
Fixed code formatting
Ark-kun Apr 1, 2022
3ce47f6
Merge branch 'main' into feat--Made-display_name-optional-for-most-calls
kweinmeister Apr 5, 2022
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
7 changes: 7 additions & 0 deletions google/cloud/aiplatform/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,13 @@ def to_dict(self) -> Dict[str, Any]:
"""Returns the resource proto as a dictionary."""
return json_format.MessageToDict(self.gca_resource._pb)

@classmethod
def _generate_display_name(cls, prefix: Optional[str] = None) -> str:
"""Returns a display name containing class name and time string."""
if not prefix:
prefix = cls.__name__
return prefix + " " + datetime.datetime.now().isoformat(sep=" ")


def optional_sync(
construct_object_on_arg: Optional[str] = None,
Expand Down
5 changes: 3 additions & 2 deletions google/cloud/aiplatform/datasets/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def create(

Args:
display_name (str):
Required. The user-defined name of the Dataset.
Ark-kun marked this conversation as resolved.
Show resolved Hide resolved
Optional. The user-defined name of the Dataset.
The name can be up to 128 characters long and can be consist
of any UTF-8 characters.
metadata_schema_uri (str):
Expand Down Expand Up @@ -208,7 +208,8 @@ def create(
dataset (Dataset):
Instantiated representation of the managed dataset resource.
"""

if not display_name:
sasha-gitg marked this conversation as resolved.
Show resolved Hide resolved
display_name = cls._generate_display_name()
utils.validate_display_name(display_name)
if labels:
utils.validate_labels(labels)
Expand Down
6 changes: 4 additions & 2 deletions google/cloud/aiplatform/datasets/image_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ImageDataset(datasets._Dataset):
@classmethod
def create(
cls,
display_name: str,
display_name: Optional[str] = None,
gcs_source: Optional[Union[str, Sequence[str]]] = None,
import_schema_uri: Optional[str] = None,
data_item_labels: Optional[Dict] = None,
Expand All @@ -53,7 +53,7 @@ def create(

Args:
display_name (str):
Required. The user-defined name of the Dataset.
Optional. The user-defined name of the Dataset.
The name can be up to 128 characters long and can be consist
of any UTF-8 characters.
gcs_source (Union[str, Sequence[str]]):
Expand Down Expand Up @@ -126,6 +126,8 @@ def create(
image_dataset (ImageDataset):
Instantiated representation of the managed image dataset resource.
"""
if not display_name:
display_name = cls._generate_display_name()

utils.validate_display_name(display_name)
if labels:
Expand Down
7 changes: 4 additions & 3 deletions google/cloud/aiplatform/datasets/tabular_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class TabularDataset(datasets._ColumnNamesDataset):
@classmethod
def create(
cls,
display_name: str,
display_name: Optional[str] = None,
gcs_source: Optional[Union[str, Sequence[str]]] = None,
bq_source: Optional[str] = None,
project: Optional[str] = None,
Expand All @@ -51,7 +51,7 @@ def create(

Args:
display_name (str):
Required. The user-defined name of the Dataset.
Optional. The user-defined name of the Dataset.
The name can be up to 128 characters long and can be consist
of any UTF-8 characters.
gcs_source (Union[str, Sequence[str]]):
Expand Down Expand Up @@ -107,7 +107,8 @@ def create(
tabular_dataset (TabularDataset):
Instantiated representation of the managed tabular dataset resource.
"""

if not display_name:
display_name = cls._generate_display_name()
utils.validate_display_name(display_name)
if labels:
utils.validate_labels(labels)
Expand Down
7 changes: 4 additions & 3 deletions google/cloud/aiplatform/datasets/text_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class TextDataset(datasets._Dataset):
@classmethod
def create(
cls,
display_name: str,
display_name: Optional[str] = None,
gcs_source: Optional[Union[str, Sequence[str]]] = None,
import_schema_uri: Optional[str] = None,
data_item_labels: Optional[Dict] = None,
Expand All @@ -60,7 +60,7 @@ def create(

Args:
display_name (str):
Required. The user-defined name of the Dataset.
Optional. The user-defined name of the Dataset.
The name can be up to 128 characters long and can be consist
of any UTF-8 characters.
gcs_source (Union[str, Sequence[str]]):
Expand Down Expand Up @@ -133,7 +133,8 @@ def create(
text_dataset (TextDataset):
Instantiated representation of the managed text dataset resource.
"""

if not display_name:
display_name = cls._generate_display_name()
utils.validate_display_name(display_name)
if labels:
utils.validate_labels(labels)
Expand Down
7 changes: 4 additions & 3 deletions google/cloud/aiplatform/datasets/time_series_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class TimeSeriesDataset(datasets._ColumnNamesDataset):
@classmethod
def create(
cls,
display_name: str,
display_name: Optional[str] = None,
gcs_source: Optional[Union[str, Sequence[str]]] = None,
bq_source: Optional[str] = None,
project: Optional[str] = None,
Expand All @@ -51,7 +51,7 @@ def create(

Args:
display_name (str):
Required. The user-defined name of the Dataset.
Optional. The user-defined name of the Dataset.
The name can be up to 128 characters long and can be consist
of any UTF-8 characters.
gcs_source (Union[str, Sequence[str]]):
Expand Down Expand Up @@ -108,7 +108,8 @@ def create(
Instantiated representation of the managed time series dataset resource.

"""

if not display_name:
display_name = cls._generate_display_name()
utils.validate_display_name(display_name)
if labels:
utils.validate_labels(labels)
Expand Down
7 changes: 4 additions & 3 deletions google/cloud/aiplatform/datasets/video_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class VideoDataset(datasets._Dataset):
@classmethod
def create(
cls,
display_name: str,
display_name: Optional[str] = None,
gcs_source: Optional[Union[str, Sequence[str]]] = None,
import_schema_uri: Optional[str] = None,
data_item_labels: Optional[Dict] = None,
Expand All @@ -53,7 +53,7 @@ def create(

Args:
display_name (str):
Required. The user-defined name of the Dataset.
Optional. The user-defined name of the Dataset.
The name can be up to 128 characters long and can be consist
of any UTF-8 characters.
gcs_source (Union[str, Sequence[str]]):
Expand Down Expand Up @@ -126,7 +126,8 @@ def create(
video_dataset (VideoDataset):
Instantiated representation of the managed video dataset resource.
"""

if not display_name:
display_name = cls._generate_display_name()
utils.validate_display_name(display_name)
if labels:
utils.validate_labels(labels)
Expand Down
24 changes: 16 additions & 8 deletions google/cloud/aiplatform/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ def completion_stats(self) -> Optional[gca_completion_stats.CompletionStats]:
@classmethod
def create(
cls,
job_display_name: str,
job_display_name: Optional[str],
Ark-kun marked this conversation as resolved.
Show resolved Hide resolved
model_name: Union[str, "aiplatform.Model"],
instances_format: str = "jsonl",
predictions_format: str = "jsonl",
Expand Down Expand Up @@ -374,7 +374,7 @@ def create(

Args:
job_display_name (str):
Required. The user-defined name of the BatchPredictionJob.
Optional. The user-defined name of the BatchPredictionJob.
The name can be up to 128 characters long and can be consist
of any UTF-8 characters.
model_name (Union[str, aiplatform.Model]):
Expand Down Expand Up @@ -527,6 +527,8 @@ def create(
(jobs.BatchPredictionJob):
Instantiated representation of the created batch prediction job.
"""
if not job_display_name:
job_display_name = cls._generate_display_name()

utils.validate_display_name(job_display_name)

Expand Down Expand Up @@ -977,9 +979,9 @@ class CustomJob(_RunnableJob):

def __init__(
self,
display_name: str,
worker_pool_specs: Union[List[Dict], List[aiplatform.gapic.WorkerPoolSpec]],
base_output_dir: Optional[str] = None,
display_name: Optional[str] = None,
Ark-kun marked this conversation as resolved.
Show resolved Hide resolved
project: Optional[str] = None,
location: Optional[str] = None,
credentials: Optional[auth_credentials.Credentials] = None,
Expand Down Expand Up @@ -1023,7 +1025,7 @@ def __init__(

Args:
display_name (str):
Required. The user-defined name of the HyperparameterTuningJob.
Optional. The user-defined name of the HyperparameterTuningJob.
The name can be up to 128 characters long and can be consist
of any UTF-8 characters.
worker_pool_specs (Union[List[Dict], List[aiplatform.gapic.WorkerPoolSpec]]):
Expand Down Expand Up @@ -1081,6 +1083,9 @@ def __init__(
staging_bucket, "aiplatform-custom-job"
)

if not display_name:
display_name = self.__class__._generate_display_name()

self._gca_resource = gca_custom_job_compat.CustomJob(
display_name=display_name,
job_spec=gca_custom_job_compat.CustomJobSpec(
Expand Down Expand Up @@ -1133,7 +1138,6 @@ def _log_web_access_uris(self):
@classmethod
def from_local_script(
cls,
display_name: str,
script_path: str,
container_uri: str,
args: Optional[Sequence[str]] = None,
Expand All @@ -1149,6 +1153,7 @@ def from_local_script(
reduction_server_machine_type: Optional[str] = None,
reduction_server_container_uri: Optional[str] = None,
base_output_dir: Optional[str] = None,
display_name: Optional[str] = None,
project: Optional[str] = None,
location: Optional[str] = None,
credentials: Optional[auth_credentials.Credentials] = None,
Expand Down Expand Up @@ -1176,7 +1181,7 @@ def from_local_script(

Args:
display_name (str):
Required. The user-defined name of this CustomJob.
Optional. The user-defined name of this CustomJob.
script_path (str):
Required. Local path to training script.
container_uri (str):
Expand Down Expand Up @@ -1452,7 +1457,6 @@ class HyperparameterTuningJob(_RunnableJob):

def __init__(
self,
display_name: str,
custom_job: CustomJob,
metric_spec: Dict[str, str],
parameter_spec: Dict[str, hyperparameter_tuning._ParameterSpec],
Expand All @@ -1461,6 +1465,7 @@ def __init__(
max_failed_trial_count: int = 0,
search_algorithm: Optional[str] = None,
measurement_selection: Optional[str] = "best",
display_name: Optional[str] = None,
Ark-kun marked this conversation as resolved.
Show resolved Hide resolved
project: Optional[str] = None,
location: Optional[str] = None,
credentials: Optional[auth_credentials.Credentials] = None,
Expand Down Expand Up @@ -1526,7 +1531,7 @@ def __init__(

Args:
display_name (str):
Required. The user-defined name of the HyperparameterTuningJob.
Optional. The user-defined name of the HyperparameterTuningJob.
The name can be up to 128 characters long and can be consist
of any UTF-8 characters.
custom_job (aiplatform.CustomJob):
Expand Down Expand Up @@ -1648,6 +1653,9 @@ def __init__(
],
)

if not display_name:
display_name = self.__class__._generate_display_name()

self._gca_resource = gca_hyperparameter_tuning_job_compat.HyperparameterTuningJob(
display_name=display_name,
study_spec=study_spec,
Expand Down
Loading