@@ -458,36 +458,40 @@ def execute_circuits_parallel(circuits, num_shots):
458458 # Each record is either:
459459 # {"kind": "expdata", ...} -> submitted ParallelExperiment, collect later
460460 # {"kind": "counts", ...} -> single-circuit sequential counts already available
461- submitted_batches = []
461+ # Phase 1: create all batches first, without submitting anything.
462+ planned_batches = []
462463
463- # Build greedy qubit-limited batches from the input circuit list.
464464 batch = []
465465 batch_qubits = 0
466466
467467 for circuit in circuits :
468468 circuit_qubits = circuit .num_qubits
469469
470- # If adding this circuit would exceed the batch qubit budget,
471- # submit the current batch first, then start a new batch.
472470 if batch and batch_qubits + circuit_qubits > MAX_PARALLEL_QUBITS :
473- submitted_batches .extend (
474- _submit_parallel_batch_with_retry (batch , num_shots )
475- )
476-
471+ planned_batches .append (batch )
477472 batch = []
478473 batch_qubits = 0
479474
480- # Add the current circuit to the active batch.
481475 batch .append (circuit )
482476 batch_qubits += circuit_qubits
483477
484- # Submit the final partially filled batch, if any.
485478 if batch :
479+ planned_batches .append (batch )
480+
481+ print (
482+ "... created planned batches:" ,
483+ [[c .num_qubits for c in b ] for b in planned_batches ]
484+ )
485+
486+ # Phase 2: submit all planned batches.
487+ submitted_batches = []
488+
489+ for batch in planned_batches :
486490 submitted_batches .extend (
487491 _submit_parallel_batch_with_retry (batch , num_shots )
488492 )
489493
490- print (f"... prepared { len (submitted_batches )} batch record(s); now collecting results" )
494+ print (f"... submitted/ prepared { len (submitted_batches )} batch record(s); now collecting results" )
491495 # Collect and normalize results from all batch records.
492496 counts_list = []
493497
0 commit comments