Skip to content

Conversation

@Vivek1106-04
Copy link

@Vivek1106-04 Vivek1106-04 commented Dec 17, 2025

Add Directed Graph Support to RouteCQC

Fixes #5863

This PR adds support for directed device graphs to Cirq’s RouteCQC router.
The router now handles unidirectional couplings using a Hadamard-based decomposition when required.


Summary of Changes

1️⃣ Removed Directed Graph Restriction

File: route_circuit_cqc.py

  • Updated __init__ to accept both directed and undirected graphs
  • Removed the ValueError previously raised for directed graphs
  • Updated docstring to reflect expanded device support

2️⃣ Implemented _emit_swap (Direction-Aware SWAP Emission)

File: route_circuit_cqc.py

Added a new classmethod _emit_swap that emits SWAP operations based on edge directionality:

  • Case A: Bidirectional edge

    • Uses standard SWAP
    • Automatically decomposed by Cirq into 3 CNOTs
  • Case B: Unidirectional edge (q1 → q2)

    • Uses Hadamard-based decomposition:
      CNOT(q1, q2) H(q1), H(q2) CNOT(q1, q2) H(q1), H(q2) CNOT(q1, q2) 
    • Basis change allows effective CNOT direction reversal
  • Case C: Unidirectional edge (q2 → q1)

    • Same logic as Case B with qubits flipped
  • Case D: No edge

    • Raises ValueError (should not occur for valid routing)

3️⃣ Updated Routing Logic

File: route_circuit_cqc.py

  • Added device_graph parameter to _route
  • Updated route_circuit to pass self.device_graph
  • Replaced direct SWAP insertion with _emit_swap

4️⃣ Updated Tests

File: route_circuit_cqc_test.py

  • test_directed_device

    • Now accepts directed graphs
    • Verifies routing of basic CNOT circuits
  • test_directed_device_swap_decomposition (NEW)

    • Routes a SWAP on a directed ring device
    • Asserts presence of Hadamard gates
    • Confirms unidirectional edge handling is exercised
@Vivek1106-04 Vivek1106-04 requested review from a team and vtomole as code owners December 17, 2025 07:26
@Vivek1106-04 Vivek1106-04 requested a review from maffoo December 17, 2025 07:26
@github-actions github-actions bot added the size: M 50< lines changed <250 label Dec 17, 2025
@github-actions github-actions bot added size: L 250< lines changed <1000 and removed size: M 50< lines changed <250 labels Dec 18, 2025
@Vivek1106-04
Copy link
Author

Added additional tests to cover edge cases for directed device graphs and the tag_inserted_swaps parameter.

@codecov
Copy link

codecov bot commented Dec 18, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.57%. Comparing base (16d4406) to head (bced992).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@ Coverage Diff @@ ## main #7810 +/- ## ======================================== Coverage 99.56% 99.57% ======================================== Files 1102 1102 Lines 98668 98873 +205 ======================================== + Hits 98242 98452 +210  + Misses 426 421 -5 

☔ View full report in Codecov by Sentry.
📢 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: L 250< lines changed <1000

1 participant