Skip to content

Fix #49: reject an empty batch before it spawns a Python process - #98

Open
corgab wants to merge 2 commits into
mainfrom
fix/49-empty-batch-guard
Open

Fix #49: reject an empty batch before it spawns a Python process#98
corgab wants to merge 2 commits into
mainfrom
fix/49-empty-batch-guard

Conversation

@corgab

@corgab corgab commented Sep 8, 2026

Copy link
Copy Markdown
Owner

Summary

BatchBuilder accepted an empty circuit list. The constructor's driver-mismatch loop and run()'s per-circuit validation were both no-ops, so Quantum::batch([])->run() went straight to executeBatch([]), which started a full Python interpreter, imported the Braket SDK and came back with {"results": []}. An application that filters a circuit list down to nothing got an empty BatchResult and no signal of the mistake, at the price of a subprocess spawn for no work. The same applied to executeBatch([]) called directly on a driver.

Plan

Of the two options in the issue, throw rather than return an empty result: the package already refuses operations that would do nothing (measure([]) throws emptyMeasurementTargets()), and an empty batch is almost always a bug in the caller. Fail in the builder's constructor so Quantum::batch([]) throws at the call site, and in the driver so the BatchableDevice path is covered too.

Changes

  • BatchBuilder::__construct(): throws InvalidCircuitException::emptyBatch() for an empty list, before the driver-mismatch loop.
  • AbstractQuantumDriver::executeBatch(): the same guard before preflight(), so a direct executeBatch([]) never reaches the bridge.
  • InvalidCircuitException::emptyBatch(): says at least one circuit is needed and why an empty batch is refused.
  • README "Batch Execution": one bullet on the empty-batch behaviour.

No config change, no new dependencies, no change for non-empty batches.

Tests

  • BatchBuilderTest: an empty batch throws with the expected message and the fake device records no batch run.
  • AbstractQuantumDriverTest: executeBatch([]) throws and the bridge's execute() is never called.
  • Both fail on main.

Local: pint passed, pest 793 tests passed.

Closes #49

BatchBuilder accepted an empty circuit list: both validation loops were
no-ops and run() went on to start a full Python interpreter, import the
Braket SDK and come back with no results, silently hiding what is almost
always a programming mistake. The constructor now throws
InvalidCircuitException::emptyBatch(), so Quantum::batch([]) fails at the
call site, consistent with measure([]) refusing a measurement of nothing.

Closes #49
Quantum::batch([]) now fails in the builder, but executeBatch([]) on a
driver is public API through the BatchableDevice contract and still went
through to Python; the driver refuses it before preflight as well.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[circuit] BatchBuilder::run() with an empty circuits array still spawns a Python subprocess

1 participant