Skip to content

Conversation

@shiavm006
Copy link
Contributor

@shiavm006 shiavm006 commented Nov 12, 2025

Purpose

Fixes crash in Cirq backend when executing 0-qubit circuits with measurements.

Related Issues

closes #608

Changes Made

  • Added guard in execute_circuit() to handle empty circuits before adding measurements
  • Returns Cirq-formatted result [{0: shots}] for 0-qubit case
  • Prevents crash when cirq.measure() is called on empty qubit list

Technical Details

The issue occurred at line 106 where circuit.append(cirq.measure(*circuit.all_qubits(), key="result")) crashes on empty circuits because circuit.all_qubits() returns an empty list.

This fix aligns with existing behavior in the main QuMat class (lines 92-97 in qumat.py) which already handles 0-qubit circuits. Moving this logic to the backend makes it self-contained and robust.

Breaking Changes

None. This is a bug fix that maintains existing behavior.

Checklist

  • Code follows project style guidelines
  • Changes are minimal and focused on the issue
  • Implementation aligns with maintainer feedback
  • No breaking changes introduced

@guan404ming guan404ming changed the title MAHOUT-608 handle 0-qubit circuits in cirq backend to prevent crash MAHOUT-608: handle 0-qubit circuits in cirq backend to prevent crash Nov 12, 2025
Copy link
Member

@guan404ming guan404ming left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@guan404ming guan404ming merged commit dcd95e9 into apache:main Nov 12, 2025
4 checks passed
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.

[Bug] Cirq backend crashes when adding measurements to 0-qubit circuits

2 participants