@@ -117,6 +117,7 @@ def snapshot(self) -> dict[str, int]:
117117 # enhanced_cps.py produces both the dataset and calibration log
118118 "policyengine_us_data/datasets/cps/enhanced_cps.py" : [
119119 "policyengine_us_data/storage/enhanced_cps_2024.h5" ,
120+ "policyengine_us_data/storage/enhanced_cps_2024.clone_diagnostics.json" ,
120121 "calibration_log.csv" ,
121122 ],
122123 "policyengine_us_data/calibration/create_stratified_cps.py" : (
@@ -317,12 +318,15 @@ def validate_and_maybe_upload_datasets(
317318 upload : bool ,
318319 skip_enhanced_cps : bool ,
319320 env : dict ,
321+ require_small_enhanced_cps : bool = True ,
320322 stage_only : bool = False ,
321323 run_id : str = "" ,
322324) -> None :
323325 validation_args = ["--validate-only" ]
324326 if skip_enhanced_cps :
325327 validation_args .append ("--no-require-enhanced-cps" )
328+ elif not require_small_enhanced_cps :
329+ validation_args .append ("--no-require-small-enhanced-cps" )
326330
327331 print ("=== Validating built datasets ===" )
328332 run_script (
@@ -335,6 +339,8 @@ def validate_and_maybe_upload_datasets(
335339 upload_args = []
336340 if skip_enhanced_cps :
337341 upload_args .append ("--no-require-enhanced-cps" )
342+ elif not require_small_enhanced_cps :
343+ upload_args .append ("--no-require-small-enhanced-cps" )
338344 if stage_only :
339345 upload_args .append ("--stage-only" )
340346 if run_id :
@@ -504,6 +510,7 @@ def write_dataset_build_contract(
504510 upload_requested : bool ,
505511 stage_only : bool ,
506512 skip_enhanced_cps : bool ,
513+ skip_stage_5 : bool = False ,
507514) -> StageContract :
508515 """Write the Stage 1 semantic handoff contract next to copied artifacts."""
509516 contract = build_dataset_build_output_contract (
@@ -518,6 +525,7 @@ def write_dataset_build_contract(
518525 upload_requested = upload_requested ,
519526 stage_only = stage_only ,
520527 skip_enhanced_cps = skip_enhanced_cps ,
528+ skip_stage_5 = skip_stage_5 ,
521529 )
522530 write_contract (
523531 contract ,
@@ -559,6 +567,7 @@ def build_datasets(
559567 clear_checkpoints : bool = False ,
560568 skip_tests : bool = False ,
561569 skip_enhanced_cps : bool = False ,
570+ skip_stage_5 : bool = False ,
562571 stage_only : bool = False ,
563572 run_id : str = "" ,
564573):
@@ -572,6 +581,8 @@ def build_datasets(
572581 skip_tests: Skip running the test suite (useful for calibration runs).
573582 skip_enhanced_cps: Skip enhanced_cps.py and small_enhanced_cps.py
574583 (useful for calibration runs that only need source_imputed H5).
584+ skip_stage_5: Skip source-imputed CPS and small enhanced CPS after
585+ enhanced_cps_2024.h5 is built.
575586 stage_only: Upload to HF staging only, without promoting a release.
576587 """
577588 setup_gcp_credentials ()
@@ -645,6 +656,12 @@ def build_datasets(
645656
646657 if sequential :
647658 for script , output in SCRIPT_OUTPUTS .items ():
659+ if skip_stage_5 and script in (
660+ "policyengine_us_data/calibration/create_source_imputed_cps.py" ,
661+ "policyengine_us_data/datasets/cps/small_enhanced_cps.py" ,
662+ ):
663+ print (f"Skipping { script } (--skip-stage-5)" )
664+ continue
648665 if skip_enhanced_cps and script in (
649666 "policyengine_us_data/datasets/cps/enhanced_cps.py" ,
650667 "policyengine_us_data/datasets/cps/small_enhanced_cps.py" ,
@@ -761,33 +778,21 @@ def build_datasets(
761778 # GROUP 4: After Phase 4 - run in parallel
762779 # create_source_imputed_cps needs stratified_cps
763780 # small_enhanced_cps needs enhanced_cps
764- print (
765- "=== Phase 5: Building source imputed CPS "
766- "and small enhanced CPS (parallel) ==="
767- )
768- phase5_futures = []
769- with ThreadPoolExecutor (max_workers = 2 ) as executor :
770- phase5_futures .append (
771- executor .submit (
772- run_script_with_checkpoint ,
773- "policyengine_us_data/calibration/create_source_imputed_cps.py" ,
774- SCRIPT_OUTPUTS [
775- "policyengine_us_data/calibration/create_source_imputed_cps.py"
776- ],
777- branch ,
778- checkpoint_volume ,
779- env = env ,
780- log_file = log_file ,
781- checkpoint_stats = checkpoint_stats ,
782- )
781+ if skip_stage_5 :
782+ print ("Skipping Phase 5 (--skip-stage-5)" )
783+ else :
784+ print (
785+ "=== Phase 5: Building source imputed CPS "
786+ "and small enhanced CPS (parallel) ==="
783787 )
784- if not skip_enhanced_cps :
788+ phase5_futures = []
789+ with ThreadPoolExecutor (max_workers = 2 ) as executor :
785790 phase5_futures .append (
786791 executor .submit (
787792 run_script_with_checkpoint ,
788- "policyengine_us_data/datasets/cps/small_enhanced_cps .py" ,
793+ "policyengine_us_data/calibration/create_source_imputed_cps .py" ,
789794 SCRIPT_OUTPUTS [
790- "policyengine_us_data/datasets/cps/small_enhanced_cps .py"
795+ "policyengine_us_data/calibration/create_source_imputed_cps .py"
791796 ],
792797 branch ,
793798 checkpoint_volume ,
@@ -796,10 +801,25 @@ def build_datasets(
796801 checkpoint_stats = checkpoint_stats ,
797802 )
798803 )
799- else :
800- print ("Skipping small_enhanced_cps.py (--skip-enhanced-cps)" )
801- for future in as_completed (phase5_futures ):
802- future .result ()
804+ if not skip_enhanced_cps :
805+ phase5_futures .append (
806+ executor .submit (
807+ run_script_with_checkpoint ,
808+ "policyengine_us_data/datasets/cps/small_enhanced_cps.py" ,
809+ SCRIPT_OUTPUTS [
810+ "policyengine_us_data/datasets/cps/small_enhanced_cps.py"
811+ ],
812+ branch ,
813+ checkpoint_volume ,
814+ env = env ,
815+ log_file = log_file ,
816+ checkpoint_stats = checkpoint_stats ,
817+ )
818+ )
819+ else :
820+ print ("Skipping small_enhanced_cps.py (--skip-enhanced-cps)" )
821+ for future in as_completed (phase5_futures ):
822+ future .result ()
803823
804824 # Checkpoint the build log so it survives preemption
805825 log_file .flush ()
@@ -857,6 +877,7 @@ def build_datasets(
857877 upload_requested = upload ,
858878 stage_only = stage_only ,
859879 skip_enhanced_cps = skip_enhanced_cps ,
880+ skip_stage_5 = skip_stage_5 ,
860881 )
861882 pipeline_volume .commit ()
862883 print ("Pipeline artifacts committed to shared volume" )
@@ -871,6 +892,7 @@ def build_datasets(
871892 validate_and_maybe_upload_datasets (
872893 upload = upload ,
873894 skip_enhanced_cps = skip_enhanced_cps ,
895+ require_small_enhanced_cps = not skip_stage_5 ,
874896 env = env ,
875897 stage_only = stage_only ,
876898 run_id = run_id ,
@@ -890,6 +912,7 @@ def main(
890912 clear_checkpoints : bool = False ,
891913 skip_tests : bool = False ,
892914 skip_enhanced_cps : bool = False ,
915+ skip_stage_5 : bool = False ,
893916 stage_only : bool = False ,
894917 run_id : str = "" ,
895918):
@@ -905,6 +928,7 @@ def main(
905928 clear_checkpoints = clear_checkpoints ,
906929 skip_tests = skip_tests ,
907930 skip_enhanced_cps = skip_enhanced_cps ,
931+ skip_stage_5 = skip_stage_5 ,
908932 stage_only = stage_only ,
909933 run_id = run_id ,
910934 )
0 commit comments