Skip to content

fix: treat a single OpenQASM string or Circuit as one ProgramSet entry - #1352

Merged
sesmart merged 2 commits into
amazon-braket:mainfrom
alyabouzaid:fix-program-set-single-openqasm-string
Sep 23, 2026
Merged

sesmart merged 2 commits into
amazon-braket:mainfrom
alyabouzaid:fix-program-set-single-openqasm-string

Conversation

@alyabouzaid

@alyabouzaid alyabouzaid commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Problem

ProgramSet.__init__ wraps only CircuitBinding and Program in a list. A bare OpenQASM string is therefore treated as a sequence and iterated character by character, silently:

qasm = "OPENQASM 3.0;\nbit[2] b;\nqubit[2] q;\nh q[0];\ncnot q[0], q[1];\nb = measure q;"
ps = ProgramSet(qasm)
ps.total_executables        # 75  (== len(qasm))
ps.to_ir().programs[0]      # Program(source='O')

No error is raised; the malformed program set is only caught at the service. A bare Circuit hits the same line and raises TypeError: 'Circuit' object is not iterable.

Both types are already valid list entries, and a standalone Program is already supported (test_standalone_openqasm_program), so a standalone string or circuit is a natural thing to write.

Fix

Include Circuit and str in the isinstance check that wraps a single entry, and widen the type hint/docstring accordingly. ProgramSet(qasm) now equals ProgramSet([qasm]), and a single Circuit with result types now raises the intended ValueError: Circuit cannot have result types.

Verification

  • Added test_standalone_openqasm_string and test_standalone_circuit, mirroring the existing test_standalone_openqasm_program. Both fail on main (75-character split / TypeError) and pass with the fix.
  • pytest test/unit_tests: 3492 passed, 131 xfailed.
  • ruff check src, ruff format --check ., mypy: clean.
  • Exercised manually: entries, len, total_executables, total_shots, to_ir, enumerate_executables, split, __eq__, __add__ on a standalone string and a standalone circuit, plus the unchanged CircuitBinding / Program / mixed-list paths.

AI disclosure: this PR was prepared with the assistance of Claude Code (Anthropic's Claude); I review and test all changes.

ProgramSet only wrapped CircuitBinding and Program instances in a list, so
a bare OpenQASM string was treated as a sequence and iterated character by
character: ProgramSet(qasm) silently produced one single-character program
per character of the source, with total_executables equal to len(qasm).
A bare Circuit raised "TypeError: 'Circuit' object is not iterable".

Both are already valid list entry types, and a standalone Program is
already supported, so accept any single entry on its own.
@alyabouzaid
alyabouzaid requested a review from a team as a code owner September 12, 2026 17:06
@codecov

codecov Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (3ff5f36) to head (9b27ae5).

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #1352   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          171       171           
  Lines        11648     11648           
  Branches      1538      1538           
=========================================
  Hits         11648     11648           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sesmart sesmart left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simple fix, nice!

@sesmart
sesmart merged commit 8019e5a into amazon-braket:main Sep 23, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants