Skip to content

Commit

Permalink
Add a property external_id to Artifact class
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 627820253
  • Loading branch information
tfx-copybara committed Apr 24, 2024
1 parent 01a4b3d commit 7d43004
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
8 changes: 4 additions & 4 deletions tfx/orchestration/experimental/core/task_gen_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -750,8 +750,8 @@ def get_unprocessed_inputs(
local_id_by_external_id: Dict[str, int] = {}
for input_and_param in resolved_info.input_and_params:
for artifact in itertools.chain(*input_and_param.input_artifacts.values()):
if artifact.mlmd_artifact.external_id:
local_id_by_external_id[artifact.mlmd_artifact.external_id] = -1
if artifact.external_id:
local_id_by_external_id[artifact.external_id] = -1
if local_id_by_external_id:
try:
for artifact in metadata_handle.store.get_artifacts_by_external_ids(
Expand All @@ -778,9 +778,9 @@ def get_unprocessed_inputs(
for a in artifacts:
if a.id:
resolved_input_ids_by_key[key].append(a.id)
elif a.mlmd_artifact.external_id:
elif a.external_id:
resolved_input_ids_by_key[key].append(
local_id_by_external_id[a.mlmd_artifact.external_id]
local_id_by_external_id[a.external_id]
)
resolved_input_ids_by_key[key] = tuple(resolved_input_ids_by_key[key])

Expand Down
4 changes: 2 additions & 2 deletions tfx/orchestration/portable/mlmd/execution_lib_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,13 +339,13 @@ def testPutExecutions(self):
input_example_4.type_id = common_utils.register_type_if_not_exist(
self._mlmd_handle, input_example_4.artifact_type
).id
input_example_4.mlmd_artifact.external_id = 'external_id'
input_example_4.external_id = 'external_id'
input_example_5 = standard_artifacts.Examples()
input_example_5.uri = 'example'
input_example_5.type_id = common_utils.register_type_if_not_exist(
self._mlmd_handle, input_example_5.artifact_type
).id
input_example_5.mlmd_artifact.external_id = 'external_id'
input_example_5.external_id = 'external_id'

[input_example_1.id, input_example_2.id,
input_example_3.id] = self._mlmd_handle.store.put_artifacts([
Expand Down
11 changes: 11 additions & 0 deletions tfx/types/artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,17 @@ def producer_component(self, producer_component: str):
"""Set producer component of the artifact."""
self._set_system_property('producer_component', producer_component)

@property
@doc_controls.do_not_doc_in_subclasses
def external_id(self) -> str:
"""external id of the underlying artifact."""
return self._artifact.external_id

@external_id.setter
def external_id(self, external_id: str):
"""Set external id of the underlying artifact."""
self._artifact.external_id = external_id

# LINT.IfChange
@property
@doc_controls.do_not_doc_in_subclasses
Expand Down
5 changes: 5 additions & 0 deletions tfx/types/artifact_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ def testArtifact(self):
self.assertEqual('MyTypeName', instance.type_name)
self.assertEqual('', instance.state)
self.assertFalse(instance.is_external)
self.assertEqual('', instance.external_id)

# Default property does not have span or split_names.
with self.assertRaisesRegex(AttributeError, "has no property 'span'"):
Expand Down Expand Up @@ -229,6 +230,9 @@ def testArtifact(self):
)
self.assertFalse(instance.get_bool_custom_property('fake_key'))

instance.mlmd_artifact.external_id = 'external_id'
self.assertEqual('external_id', instance.external_id)

self.assertEqual(
textwrap.dedent("""\
Artifact(artifact: id: 1
Expand Down Expand Up @@ -272,6 +276,7 @@ def testArtifact(self):
}
state: DELETED
name: "test_artifact"
external_id: "external_id"
, artifact_type: name: "MyTypeName"
properties {
key: "bool1"
Expand Down

0 comments on commit 7d43004

Please sign in to comment.