11import os
2+ import yaml
3+ import mlflow
4+
25from src .feature_engineering .build_feature_extractor import run_feature_engineering
36from src .hyperparameter_tuning .tune_with_qaoa import run_hyperparameter_tuning
47from src .production_monitoring .monitor_with_qsvm import run_drift_detection
5-
6- # --- ADD IMPORTS FOR THE NEW VISUALIZATION MODULES ---
7- from src .visualisation .plot_stage_1 import create_feature_space_plot
8- from src .visualisation .plot_stage_2 import create_hpo_search_plot
9- from src .visualisation .plot_stage_3 import create_drift_detection_plots
10- from src .visualisation .plot_stage_3_fast import create_drift_detection_plot_fast
8+ from src .visualization .plot_stage_1 import create_feature_space_plot
9+ from src .visualization .plot_stage_2 import create_hpo_search_plot
10+ from src .visualization .plot_stage_3 import create_drift_detection_plots
1111
1212def main ():
13- """Executes the entire Quantum-Native MLOps pipeline from end to end."""
14- print ("==========================================================" )
15- print ("=== EXECUTING END-TO-END QUANTUM-NATIVE MLOPS PIPELINE ===" )
16- print ("==========================================================" )
17-
18- # --- Stage 1: Feature Engineering ---
19- p1_params = {
20- 'latent_dim' : 4 , 'epochs' : 3 , 'lr' : 0.005 ,
21- 'batch_size' : 16 , 'n_samples' : 200 , 'img_size' : 14
22- }
23- run_feature_engineering (** p1_params )
24-
25- stage1_output_exists = os .path .exists ("saved_models/feature_extractor/hae_encoder.pth" )
26- if not stage1_output_exists :
27- print ("\n [ERROR] Stage 1 did not produce model files. Aborting pipeline." )
28- return
13+ with open ('config.yaml' , 'r' ) as f :
14+ config = yaml .safe_load (f )
2915
30- # --- Stage 2: Hyperparameter Tuning ---
31- run_hyperparameter_tuning ( )
16+ mlflow . set_tracking_uri ( config [ 'mlflow_tracking_uri' ])
17+ mlflow . set_experiment ( config [ 'project_name' ] )
3218
33- # --- Stage 3: Production Monitoring ---
34- run_drift_detection ()
35-
36- # --- Stage 4: Visualization ---
37- print ("-----GENERATING VISUALS-----" )
38- create_feature_space_plot ()
39- create_hpo_search_plot ()
40- # Option 1: Fast Plot (Runs in < 5 minutes)
41- create_drift_detection_plot_fast ()
42- # Option 2: High-Quality Slow Plot (Can take 40+ minutes)
43- # To run this, comment out the line above and uncomment the line below.
44- # create_drift_detection_plots()
45-
19+ with mlflow .start_run () as run :
20+ run_id = run .info .run_id
21+ print (f"==========================================================" )
22+ print (f"=== STARTING MLFLOW RUN ID: { run_id } ===" )
23+ print (f"==========================================================" )
24+
25+ # --- THE FIX: Create a single dictionary with unique keys before logging ---
26+ params_to_log = {
27+ ** config ['stage_1_feature_engineering' ],
28+ ** config ['stage_2_hyperparameter_tuning' ],
29+ ** config ['stage_3_production_monitoring' ]
30+ }
31+ # MLflow cannot log nested dictionaries, so we remove this one.
32+ params_to_log .pop ('hyperparameter_space' , None )
33+
34+ print ("Logging configuration parameters to MLflow..." )
35+ mlflow .log_params (params_to_log )
36+
37+ run_feature_engineering (config )
38+ run_hyperparameter_tuning (config )
39+ run_drift_detection (config )
4640
47- print ("\n ==========================================================" )
48- print ("=== MLOPS PIPELINE EXECUTION COMPLETE ===" )
49- print ("==========================================================" )
41+ print ("\n ==========================================================" )
42+ print ("=== MAIN PIPELINE COMPLETE. NOW GENERATING VISUALS... ===" )
43+ print ("==========================================================" )
44+
45+ create_feature_space_plot (config )
46+ create_hpo_search_plot (config )
47+ create_drift_detection_plots (config )
48+
49+ print ("\n Logging visualization artifacts to MLflow..." )
50+ mlflow .log_artifact ("visualization_stage_1_feature_space.png" )
51+ mlflow .log_artifact ("visualization_stage_2_hpo_search.png" )
52+ mode = config ['stage_3_production_monitoring' ]['visualization_mode' ]
53+ if mode == 'fast' :
54+ mlflow .log_artifact ("visualization_stage_3_drift_FAST.png" )
55+ mlflow .log_artifact (f"visualization_stage_3_confusion_matrix_{ mode .upper ()} .png" )
56+ else :
57+ mlflow .log_artifact ("visualization_stage_3_drift_boundary.png" )
58+ mlflow .log_artifact (f"visualization_stage_3_confusion_matrix_{ mode .upper ()} .png" )
59+
60+ print ("\n ==========================================================" )
61+ print (f"=== MLOPS PIPELINE EXECUTION COMPLETE FOR RUN ID: { run_id } ===" )
62+ print (f"=== View results in the MLflow UI: `mlflow ui` ===" )
63+ print (f"==========================================================" )
5064
5165if __name__ == '__main__' :
5266 main ()
0 commit comments