+
    #jx#                       R t ^ RIHt ^ RIt^ RIt^ RIt^ RIt^ RIHtH	t	 ^ RI
Ht ]P                  P                  ^ ]! ]! ]4      P!                  4       P"                  4      4       ^ RIHtHtHtHtHtHtHtHt ^ RIHtHtHt ^ RIHt R R	 lt R
 R lt!RR R llt"]#R8X  d   ]PH                  ! ]"! 4       4       R# R# )u  
run_batch.py — Run a workflow many times, varying parameters per run.

Two modes:
  1. --count N --randomize-seed
       Submit N runs, each with a fresh random seed. Use for quick variations.
  2. --sweep '{"seed": [1,2,3], "steps": [20,30]}'
       Cartesian product of values. With cloud subscription, runs in parallel
       up to your tier's concurrent-job limit.

Both modes write each run's outputs into output-dir/run_NNN/.

Examples:
    python3 run_batch.py --workflow flux_dev.json         --args '{"prompt": "a cat"}'         --count 8 --randomize-seed         --output-dir ./outputs/cat-batch

    python3 run_batch.py --workflow sdxl.json         --args '{"prompt": "abstract"}'         --sweep '{"seed": [1,2,3], "steps": [20, 40]}'         --output-dir ./outputs/sweep
)annotationsN)ThreadPoolExecutoras_completed)Path)DEFAULT_LOCAL_HOSTENV_API_KEYcoerce_seed	emit_jsonloglooks_like_video_workflowresolve_api_keyunwrap_workflow)ComfyRunnerdownload_outputsinject_params)extract_schemac          
     ,    V ^8  d   QhRRRRRRRRRR	/# )
   sweepdict	base_argscountintrandomize_seedboolreturnz
list[dict] )formats   "c/opt/hermes-venv/lib/python3.14/site-packages/../../../skills/creative/comfyui/scripts/run_batch.py__annotate__r   .   s0        c 4 T^     c                   V '       d   \        V P                  4       4      pV Uu. uF0  p\        W,          \         4      '       d	   W,          MW,          .NK2  	  pp. p\        P                  ! V!   F7  p\        V4      p	\        WH4       F	  w  rZWV&   K  	  VP                  V	4       K9  	  V# . p\        V4       F5  p\        V4      p	V'       d   \        R4      V	R&   VP                  V	4       K7  	  V# u upi )z+Generate a list of args dicts for each run.Nseed)
listkeys
isinstance	itertoolsproductr   zipappendranger   )r   r   r   r   r$   kvaluesrunscomboarv_s   &&&&        r   expand_sweepr2   .   s    EJJL!RVWRVQj488%(uxjHRVW&&/EiBD(1 )KKO	 0
 D5\)_$T*BvJB	 
 K Xs   6C9c               8    V ^8  d   QhRRRRRRRRRRR	R
RRRR/# )r   runnerr   workflowr   schemaargs
output_dirr   timeoutr   wsr   r   r   )r   s   "r   r   r   E   sN     % %%#'%15%=A%%"%%+/% 
%r    c          
     T   \        WV4      w  rxV P                  V4      p	R V	9   d   RRRRRV	P                  R4      RV/# V	P                  R4      p
V
'       g   RRRRR	V	RV/# V	P                  R
4      '       d   RRRRR
V	R
,          RV/# V'       d   V P                  WR7      pMV P	                  WR7      pVR,          R8w  d!   RVR,          RV
RVP                  R4      RV/# VP                  R4      ;'       g    V P                  V
4      p\        WVRR7      pRRRV
RVRVRV/# )_http_errorstatuserrorzsubmission HTTP errordetailsbodyr7   	prompt_idzno prompt_idresponsenode_errorszvalidation failed)r9   successdataoutputsF)preserve_subfolderwarnings)r   submitget
monitor_wspoll_statusget_outputsr   )r4   r5   r6   r7   r8   r9   r:   wfrH   subpidresultrF   
downloadeds   &&&&$$$       r   execute_onerS   E   sb    !48LB
--
C'7,C3776?FD: 	:
''+
C'7NJVUYZZ
ww}'7,?s=164A 	A 
""3"8##C#9h9$fX&vzz&)D	
 	
 jj#>>v'9'9#'>G!&:RWXJ)S:H r    c                    V ^8  d   QhRRRR/# )r   argvzlist[str] | Noner   r   r   )r   s   "r   r   r   m   s     B% B% B%3 B%r    c                0   \         P                  ! R R7      pVP                  RRR7       VP                  RRRR7       VP                  R	\        ^ R
R7       VP                  RRRR7       VP                  RRRR7       VP                  R\        R7       VP                  RR\
         2R7       VP                  R4       VP                  R\        ^RR7       VP                  RRR7       VP                  R\        ^ R7       VP                  RRR 7       VP                  R!RR"R7       VP                  V 4      pVP                  ^ 8:  d"   VP                  '       g   \        R#R$/4       ^# VP                  P                  4       '       d!   \        P                  ! VP                  4      M/ pVP                  P                  4       '       d!   \        P                  ! VP                  4      M/ pV'       d   \        V\        4      '       g   \        R#R%/4       ^# VP!                  4        UUu. uF1  w  rV\        V\"        4      '       g   K  \%        V4      ^ 8X  g   K/  VNK3  	  pppV'       d   \        R#R&V 2/4       ^# VP                  '       g   VP&                  '       d   \)        R'4       \+        VP,                  4      P/                  4       pVP1                  4       '       g   \        R#R(VP,                   2/4       ^#  VP3                  4       ;_uu_ 4       p	\5        \        P6                  ! V	4      4      p
R)R)R)4       \?        X
4      p\A        YCTP                  TP&                  4      p\)        R*\%        T4       R+24       \C        TPD                  4      p\G        TPH                  YPJ                  R,7      pTPM                  4       w  ppT'       g   \        R#R-R.TR/TPH                  /4       ^# TPN                  pT^ 8:  d   \Q        T
4      '       d   R0MR1p\+        TPR                  4      P/                  4       pTPU                  RRR27       . p^ pTPV                  ^8  EdH   \Y        TPV                  R37      ;_uu_ 4       p/ p\[        T4       F>  w  ppTR4TR5 2,          pTP]                  \^        YTTTTTP`                  R67      pTTT&   K@  	  \c        T4       F  pTT,          p TPe                  4       pTTR9&   TPi                  T4       TR7,          R:8w  dV   T^,          p\)        R;T R<TR7,           R=TPk                  R#R>4       24       TPl                  '       g   \)        R?4        M1K  \)        R;T R@\%        TPk                  RA. 4      4       RB24       K  	  R)R)R)4       M\[        T4       F  w  ppTR4TR5 2,          p\_        YTTTTTP`                  R67      pTTR9&   TPi                  T4       TR7,          R:8w  dV   T^,          p\)        R;T R<TR7,           R=TPk                  R#R>4       24       TPl                  '       g   \)        R?4        M1K  \)        R;T R@\%        TPk                  RA. 4      4       RB24       K  	  TPo                  RC RD7       \        R7T^ 8X  d   R:MRERF\%        T4      RG\q        RH T 4       4      RITRJ\=        T4      RKT/4       T^ 8X  d   ^ # ^# u uppi   + '       g   i     EL; i  \8        \        P:                  3 d"   p\        R#\=        T4      /4        R)p?^# R)p?ii ; i  \f         d$   pR7R#R#\=        T4      R8TT,          /p R)p?ELtR)p?ii ; i  + '       g   i     L; i)Lz5Submit a workflow many times with varying parameters.)descriptionz
--workflowT)requiredz--argsz{}zBase parameters JSON)defaulthelpz--countz*Number of runs (use with --randomize-seed))typerY   rZ   z--sweep u[   JSON dict of param→list of values. Cartesian product. e.g. '{"seed":[1,2,3],"cfg":[5,8]}'z--randomize-seed
store_truez"In --count mode, vary seed per run)actionrZ   z--host)rY   z	--api-keyzor set $)rZ   z--partner-keyz
--parallelzMConcurrent submissions (cloud: up to your tier limit). Default 1 (sequential)z--output-dirz./outputs/batchz	--timeout)r[   rY   z--ws)r^   z--continue-on-errorz%Don't stop the batch when a run failsr>   z$Specify --count N or --sweep '{...}'z/--sweep must be a JSON object {param: [values]}z+--sweep parameters have empty value lists: zI--sweep set; ignoring --count / --randomize-seed (sweep defines the runs)zWorkflow not found: NzPlanned z run(s))hostapi_keypartner_keyzCannot reach serverr?   r_   i  i,  )parentsexist_ok)max_workersrun_04d)r8   r9   r:   r=   r7   indexrD   z  run u    → z: ?z-  --continue-on-error not set; aborting batchu    → success: rF   z filesc                &    V P                  R ^ 4      # )rg   )rJ   )xs   &r   <lambda>main.<locals>.<lambda>   s    quuWa0r    )keypartialtotal	completedc              3  D   "   T F  qR ,          R8X  g   K  ^x  K  	  R# 5i)r=   rD   Nr   ).0rs   & r   	<genexpr>main.<locals>.<genexpr>   s     HGq{i/GGs    
 failedr8   results)9argparseArgumentParseradd_argumentr   r   r   
parse_argsr   r   r	   r7   stripjsonloadsr%   r   itemsr#   lenr   r
   r   r5   
expanduserexistsopenr   load
ValueErrorJSONDecodeErrorstrr   r2   r   r`   r   r_   ra   check_serverr9   r   r8   mkdirparallelr   	enumeraterI   rS   r:   r   rQ   	Exceptionr)   rJ   continue_on_errorsortsum)rU   pr7   r   r   r+   r0   emptywf_pathfr5   er6   r-   r`   r4   okinfor9   base_dirrw   failuresexfuture_to_idxir/   run_dirfutrs   s   &                            r   mainr   m   s   K	A NN<$N/NN8T0FNGNN93D  FNN9b@  A NN%l<  >NN8%7N8NN;x}%=N>NN?#NN<c11  2 NN>+<N=NN;S!N4NN6,N/NN(?  A<<DzzQtzzz7BCD)-):):

499%I&*jj&6&6&8&8DJJtzz"bE %&&w QRS${{}T}tq
1d0CARS}Tw"MeW UVW:::,,,[\4==!,,.G>>724==/BCD\\^^q&tyy|4H  H%F$**d6I6IJD(3t9+W%&dll+GdiiFVFVWF""$HB719dFDIIVWllG!|28<<##DOO$//1HNN4$N/GH}}qDMM::bM"42"tAc7^3ii62&DGG    &'c" ) $M2!#&N

A '
q!X;)+MH&58Rgc8J7KLM111KL 2 &>#aeeIr6J2K1LFST 3 ;:4 t_EAr4#w/GFfb&-w477LAAgJNN1{i'AfQCuQx[MAEE'#4F3GHI---GH . fQC~c!%%	22F.G-HOP % LL0L1x1}))TSHGHH(c(m7  A1$1$y U ^^,,- 7CF#$P ! N!7GSVVT!WMAN ;:s   4[;[;%[;\ % \\ A'^9]	B(^\	\ \ ]0]]^	]=	7^=^	^^	__main__)N)%__doc__
__future__r   rx   r&   r}   sysconcurrent.futuresr   r   pathlibr   pathinsertr   __file__resolveparent_commonr   r   r   r	   r
   r   r   r   run_workflowr   r   r   r   r2   rS   r   __name__exitr   r    r   <module>r      s   0 #    
 ?  3tH~--/667 8    *.%PB%J zHHTV r    