|
24 | 24 | from google.cloud.aiplatform.compat.types import execution as gca_execution
|
25 | 25 | from google.cloud.aiplatform.metadata import constants
|
26 | 26 | from google.cloud.aiplatform.metadata import execution
|
| 27 | +from google.cloud.aiplatform.metadata import metadata |
27 | 28 |
|
28 | 29 |
|
29 | 30 | class BaseExecutionSchema(metaclass=abc.ABCMeta):
|
@@ -112,3 +113,75 @@ def create(
|
112 | 113 | credentials=credentials,
|
113 | 114 | )
|
114 | 115 | return self.execution
|
| 116 | + |
| 117 | + def start_execution( |
| 118 | + self, |
| 119 | + *, |
| 120 | + metadata_store_id: Optional[str] = "default", |
| 121 | + resume: bool = False, |
| 122 | + project: Optional[str] = None, |
| 123 | + location: Optional[str] = None, |
| 124 | + credentials: Optional[auth_credentials.Credentials] = None, |
| 125 | + ) -> "execution.Execution": |
| 126 | + """Create and starts a new Metadata Execution or resumes a previously created Execution. |
| 127 | +
|
| 128 | + This method is similar to create_execution with additional support for Experiments. |
| 129 | + If an Experiment is set prior to running this command, the Experiment will be |
| 130 | + associtaed with the created execution, otherwise this method behaves the same |
| 131 | + as create_execution. |
| 132 | +
|
| 133 | + To start a new execution: |
| 134 | + ``` |
| 135 | + instance_of_execution_schema = execution_schema.ContainerExecution(...) |
| 136 | + with instance_of_execution_schema.start_execution() as exc: |
| 137 | + exc.assign_input_artifacts([my_artifact]) |
| 138 | + model = aiplatform.Artifact.create(uri='gs://my-uri', schema_title='system.Model') |
| 139 | + exc.assign_output_artifacts([model]) |
| 140 | + ``` |
| 141 | +
|
| 142 | + To continue a previously created execution: |
| 143 | + ``` |
| 144 | + with execution_schema.ContainerExecution(resource_id='my-exc', resume=True) as exc: |
| 145 | + ... |
| 146 | + ``` |
| 147 | + Args: |
| 148 | + metadata_store_id (str): |
| 149 | + Optional. The <metadata_store_id> portion of the resource name with |
| 150 | + the format: |
| 151 | + projects/123/locations/us-central1/metadataStores/<metadata_store_id>/executions/<executions_id> |
| 152 | + If not provided, the MetadataStore's ID will be set to "default". Currently only the 'default' |
| 153 | + MetadataStore ID is supported. |
| 154 | + resume (bool): |
| 155 | + Resume an existing execution. |
| 156 | + project (str): |
| 157 | + Optional. Project used to create this Execution. Overrides project set in |
| 158 | + aiplatform.init. |
| 159 | + location (str): |
| 160 | + Optional. Location used to create this Execution. Overrides location set in |
| 161 | + aiplatform.init. |
| 162 | + credentials (auth_credentials.Credentials): |
| 163 | + Optional. Custom credentials used to create this Execution. Overrides |
| 164 | + credentials set in aiplatform.init. |
| 165 | + Returns: |
| 166 | + Execution: Instantiated representation of the managed Metadata Execution. |
| 167 | + Raises: |
| 168 | + ValueError: If metadata_store_id other than 'default' is provided. |
| 169 | + """ |
| 170 | + if metadata_store_id != "default": |
| 171 | + raise ValueError( |
| 172 | + f"metadata_store_id {metadata_store_id} is not supported. Only the default MetadataStore ID is supported." |
| 173 | + ) |
| 174 | + |
| 175 | + return metadata._ExperimentTracker().start_execution( |
| 176 | + schema_title=self.schema_title, |
| 177 | + display_name=self.display_name, |
| 178 | + resource_id=self.execution_id, |
| 179 | + metadata=self.metadata, |
| 180 | + schema_version=self.schema_version, |
| 181 | + description=self.description, |
| 182 | + # TODO: Add support for metadata_store_id once it is supported in experiment. |
| 183 | + resume=resume, |
| 184 | + project=project, |
| 185 | + location=location, |
| 186 | + credentials=credentials, |
| 187 | + ) |
0 commit comments