6767REPO_URL = "https://github.com/PolicyEngine/policyengine-us-data.git"
6868PIPELINE_MOUNT = "/pipeline"
6969STAGING_MOUNT = "/staging"
70- ARTIFACTS_DIR = f"{ PIPELINE_MOUNT } /artifacts"
70+ ARTIFACTS_BASE = f"{ PIPELINE_MOUNT } /artifacts"
7171RUNS_DIR = f"{ PIPELINE_MOUNT } /runs"
7272
7373
74+ def artifacts_dir_for_run (run_id : str ) -> str :
75+ """Return the run-scoped artifacts directory.
76+
77+ When run_id is empty, falls back to the flat base path
78+ for backward compatibility with standalone invocations.
79+ """
80+ if run_id :
81+ return f"{ ARTIFACTS_BASE } /{ run_id } "
82+ return ARTIFACTS_BASE
83+
84+
7485# ── Run metadata ─────────────────────────────────────────────────
7586
7687
@@ -302,7 +313,7 @@ def stage_base_datasets(
302313 version: Package version string for the commit.
303314 branch: Git branch for repo clone.
304315 """
305- artifacts = Path (ARTIFACTS_DIR )
316+ artifacts = Path (artifacts_dir_for_run ( run_id ) )
306317
307318 files_with_paths = []
308319
@@ -666,8 +677,8 @@ def run_pipeline(
666677 run_dir .mkdir (parents = True , exist_ok = True )
667678 (run_dir / "diagnostics" ).mkdir (exist_ok = True )
668679
669- # Create artifacts directory
670- Path (ARTIFACTS_DIR ).mkdir (parents = True , exist_ok = True )
680+ # Create run-scoped artifacts directory
681+ Path (artifacts_dir_for_run ( run_id ) ).mkdir (parents = True , exist_ok = True )
671682
672683 write_run_meta (meta , pipeline_volume )
673684
@@ -704,6 +715,7 @@ def run_pipeline(
704715 clear_checkpoints = clear_checkpoints ,
705716 skip_tests = True ,
706717 skip_enhanced_cps = False ,
718+ run_id = run_id ,
707719 )
708720
709721 # The build_datasets step produces files in its
@@ -732,6 +744,7 @@ def run_pipeline(
732744 branch = branch ,
733745 workers = num_workers ,
734746 n_clones = n_clones ,
747+ run_id = run_id ,
735748 )
736749 print (f" Package at: { pkg_path } " )
737750
@@ -750,7 +763,7 @@ def run_pipeline(
750763 print ("\n [Step 3/5] Fitting calibration weights..." )
751764 step_start = time .time ()
752765
753- vol_path = "/pipeline/artifacts /calibration_package.pkl"
766+ vol_path = f" { artifacts_dir_for_run ( run_id ) } /calibration_package.pkl"
754767 target_cfg = "policyengine_us_data/calibration/target_config.yaml"
755768
756769 # Spawn regional fit
@@ -794,16 +807,17 @@ def run_pipeline(
794807 regional_result = regional_handle .get ()
795808 print (" Regional fit complete. Writing to volume..." )
796809
797- # Write regional results to pipeline volume
810+ # Write regional results to pipeline volume (run-scoped)
811+ artifacts_rel = f"artifacts/{ run_id } " if run_id else "artifacts"
798812 with pipeline_volume .batch_upload (force = True ) as batch :
799813 batch .put_file (
800814 BytesIO (regional_result ["weights" ]),
801- "artifacts /calibration_weights.npy" ,
815+ f" { artifacts_rel } /calibration_weights.npy" ,
802816 )
803817 if regional_result .get ("config" ):
804818 batch .put_file (
805819 BytesIO (regional_result ["config" ]),
806- "artifacts /unified_run_config.json" ,
820+ f" { artifacts_rel } /unified_run_config.json" ,
807821 )
808822
809823 archive_diagnostics (
@@ -822,12 +836,12 @@ def run_pipeline(
822836 with pipeline_volume .batch_upload (force = True ) as batch :
823837 batch .put_file (
824838 BytesIO (national_result ["weights" ]),
825- "artifacts /national_calibration_weights.npy" ,
839+ f" { artifacts_rel } /national_calibration_weights.npy" ,
826840 )
827841 if national_result .get ("config" ):
828842 batch .put_file (
829843 BytesIO (national_result ["config" ]),
830- "artifacts /national_unified_run_config.json" ,
844+ f" { artifacts_rel } /national_unified_run_config.json" ,
831845 )
832846
833847 archive_diagnostics (
0 commit comments