1
+ import datahub .metadata .schema_classes as models
2
+ from datahub .emitter .mcp import MetadataChangeProposalWrapper
3
+ from datahub .ingestion .graph .client import DatahubClientConfig , DataHubGraph
4
+ import argparse
5
+
6
+ def create_experiment (
7
+ experiment_id : str ,
8
+ name : str ,
9
+ description : str ,
10
+ platform : str ,
11
+ custom_properties : dict ,
12
+ token : str = None ,
13
+ server_url : str = "http://localhost:8080"
14
+ ) -> None :
15
+ # Create basic experiment properties
16
+ platform_urn = f"urn:li:dataPlatform:{ platform } "
17
+ container_urn = f"urn:li:container:({ platform_urn } ,{ experiment_id } ,PROD)"
18
+ container_subtype = models .SubTypesClass (typeNames = ["ML Experiment" ])
19
+ container_info = models .ContainerPropertiesClass (
20
+ name = name ,
21
+ description = description ,
22
+ customProperties = custom_properties ,
23
+ )
24
+ browse_path = models .BrowsePathsV2Class (path = [])
25
+ platform_instance = models .DataPlatformInstanceClass (
26
+ platform = platform_urn ,
27
+ instance = "PROD" ,
28
+ )
29
+
30
+ # Generate metadata change proposal
31
+ mcps = MetadataChangeProposalWrapper .construct_many (
32
+ entityUrn = container_urn ,
33
+ aspects = [container_subtype , container_info , browse_path , platform_instance ],
34
+ )
35
+
36
+ # Connect to DataHub and emit the changes
37
+ graph = DataHubGraph (DatahubClientConfig (
38
+ server = server_url ,
39
+ token = token ,
40
+ extra_headers = {"Authorization" : f"Bearer { token } " },
41
+ ))
42
+
43
+ with graph :
44
+ for mcp in mcps :
45
+ graph .emit (mcp )
46
+
47
+
48
+ if __name__ == "__main__" :
49
+ # Example usage
50
+ parser = argparse .ArgumentParser ()
51
+ parser .add_argument ("--token" , required = True , help = "DataHub access token" )
52
+ args = parser .parse_args ()
53
+
54
+ create_experiment (
55
+ experiment_id = "airline_forecast_experiment" ,
56
+ name = "Airline Forecast Experiment" ,
57
+ description = "Experiment for forecasting airline passengers" ,
58
+ platform = "mlflow" ,
59
+ custom_properties = {"experiment_type" : "forecasting" },
60
+ token = args .token
61
+ )
0 commit comments