Skip to content

Allow inserting DD sequences with non-Cirq rules#3065

Open
natestemen wants to merge 2 commits into
mainfrom
fix/ddd-non-cirq-rules
Open

Allow inserting DD sequences with non-Cirq rules#3065
natestemen wants to merge 2 commits into
mainfrom
fix/ddd-non-cirq-rules

Conversation

@natestemen

@natestemen natestemen commented Jun 20, 2026

Copy link
Copy Markdown
Member

Summary

The DDD rule functions (e.g. xx, xyxy) are typed as returning QPROGRAM, and the public API (insert_ddd_sequences, execute_with_ddd, etc.) accepts Callable[[int], QPROGRAM]. However, the internal implementation of insert_ddd_sequences called Cirq-specific methods directly on the rule's return value, so any rule returning a non-Cirq circuit would fail at runtime:

from qiskit import QuantumCircuit
from mitiq.ddd.insertion import insert_ddd_sequences
from mitiq.interface.mitiq_qiskit import to_qiskit
from mitiq.ddd.rules import xx

def qiskit_xx(slack_length: int) -> QuantumCircuit:
    return to_qiskit(xx(slack_length))

qreg = QuantumCircuit(2)
qreg.h([0, 1])
qreg.id([0, 1])
qreg.id([0, 1])
qreg.h([0, 1])

# Raises AttributeError: 'QuantumCircuit' has no attribute 'transform_qubits'
insert_ddd_sequences(qreg, rule=qiskit_xx)
  • Widen the rule parameter type from Callable[[int], Circuit] to Callable[[int], QPROGRAM] in insert_ddd_sequences / _insert_ddd_sequences
  • Add an internal cirq_rule wrapper that converts the rule output to a Cirq Circuit (via convert_to_mitiq) and normalizes qubit indexing to LineQubits before the Cirq-specific DDD insertion logic runs

Test plan

  • New test test_insert_sequences_with_qiskit_rule verifies a Qiskit-returning rule produces the same result as the equivalent Cirq rule
  • All 170 existing DDD tests continue to pass

AI was used in helping create this PR.

Convert DDD rule output to Cirq inside `_insert_ddd_sequences`,
so rules returning any QPROGRAM (e.g. Qiskit QuantumCircuit) work
correctly instead of failing at Cirq-specific method calls.
@natestemen natestemen added ddd Digital Dynamical Decoupling bug Something isn't working labels Jun 20, 2026
@natestemen natestemen changed the title Allow DD sequences with non-Cirq rules Allow inserting DD sequences with non-Cirq rules Jun 20, 2026
@codecov

codecov Bot commented Jun 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.40%. Comparing base (dd06bb2) to head (163d027).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3065   +/-   ##
=======================================
  Coverage   98.40%   98.40%           
=======================================
  Files         112      112           
  Lines        4940     4946    +6     
=======================================
+ Hits         4861     4867    +6     
  Misses         79       79           

☔ 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.

@natestemen natestemen requested a review from purva-thakre June 20, 2026 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working ddd Digital Dynamical Decoupling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant