77from citrine ._serialization .properties import String , LinkOrElse
88from citrine ._utils .functions import format_escaped_url
99from citrine .resources .data_concepts import _make_link_by_uid
10+ from citrine .resources .data_concepts import CITRINE_TAG_PREFIX
1011from citrine .resources .material_spec import MaterialSpecCollection
1112from citrine .resources .object_runs import ObjectRun , ObjectRunCollection
1213from gemd .entity .file_link import FileLink
@@ -49,6 +50,16 @@ class MaterialRun(
4950 The material specification of which this is an instance.
5051 file_links: List[FileLink], optional
5152 Links to associated files, with resource paths into the files API.
53+ default_labels: List[str], optional
54+ An optional set of default labels to apply to this material run.
55+ Default labels are used to:
56+ - Populate labels on the ingredient run, if none are explicitly
57+ specified, when the material run is later used as an ingredient
58+ - Marking the material run as a potential replacement ingredient for a
59+ particular label when generating new candidates using a
60+ design space. Note that during design, default labels are only applicable
61+ if the material run has no associated ingredient run within the
62+ training set in question.
5263
5364 """
5465
@@ -74,12 +85,14 @@ def __init__(self,
7485 process : Optional [GEMDProcessRun ] = None ,
7586 sample_type : Optional [str ] = "unknown" ,
7687 spec : Optional [GEMDMaterialSpec ] = None ,
77- file_links : Optional [List [FileLink ]] = None ):
88+ file_links : Optional [List [FileLink ]] = None ,
89+ default_labels : Optional [List [str ]] = None ):
7890 if uids is None :
7991 uids = dict ()
92+ all_tags = _inject_default_label_tags (tags , default_labels )
8093 super (ObjectRun , self ).__init__ ()
8194 GEMDMaterialRun .__init__ (self , name = name , uids = uids ,
82- tags = tags , process = process ,
95+ tags = all_tags , process = process ,
8396 sample_type = sample_type , spec = spec ,
8497 file_links = file_links , notes = notes )
8598
@@ -216,3 +229,22 @@ def list_by_template(self,
216229 specs = spec_collection .list_by_template (uid = _make_link_by_uid (uid ))
217230 return (run for runs in (self .list_by_spec (spec ) for spec in specs )
218231 for run in runs )
232+
233+
234+ _CITRINE_DEFAULT_LABEL_PREFIX = f'{ CITRINE_TAG_PREFIX } ::mat_label'
235+
236+
237+ def _inject_default_label_tags (
238+ original_tags : Optional [List [str ]], default_labels : Optional [List [str ]]
239+ ) -> Optional [List [str ]]:
240+ if default_labels is None :
241+ all_tags = original_tags
242+ else :
243+ labels_as_tags = [
244+ f"{ _CITRINE_DEFAULT_LABEL_PREFIX } ::{ label } " for label in default_labels
245+ ]
246+ if original_tags is None :
247+ all_tags = labels_as_tags
248+ else :
249+ all_tags = list (original_tags ) + labels_as_tags
250+ return all_tags
0 commit comments