quantumlib / Cirq

A Python framework for creating, editing, and invoking Noisy Intermediate Scale Quantum (NISQ) circuits.
Apache License 2.0
4.24k stars 1.01k forks source link

Dynamical decoupling: Support pulling through the whole circuit with non-clifford moments #6718

Closed babacry closed 4 days ago

babacry commented 3 weeks ago

Previously, we only insert dd for split Clifford pieces. While, some use cases require

  1. insert into consecutive idle moments cross Clifford pieces.
  2. pull through clifford op even the moment contains non-clifford ops.
  3. etc

Example: schema=(X, Y, X, Y)


Input:
                                                              ┌────────────────────────┐                             ┌──┐
0: ─────────────────────────────────PhXZ(a=0.2,x=0.2,z=0.1)────@───────────────────────────PhXZ(a=0.2,x=0.2,z=0.1)────@─────PhXZ(a=0.2,x=0.2,z=0.1)───H───
                                                               │                                                      │
1: ─────────────────────────────────PhXZ(a=0.2,x=0.2,z=0.1)────@───────────────────────────PhXZ(a=0.2,x=0.2,z=0.1)────@─────PhXZ(a=0.2,x=0.2,z=0.1)───H───

2: ───PhXZ(a=0.2,x=0.2,z=0.1)───@───PhXZ(a=0.2,x=0.2,z=0.1)────@───────────────────────────PhXZ(a=0.2,x=0.2,z=0.1)────@───────────────────────────────H───
                                │                              │                                                      │
3: ─────────────────────────────┼───PhXZ(a=0.2,x=0.2,z=0.1)────┼──────────────────────@───────────────────────────────┼@──────────────────────────────H───
                                │                              │                      │                               ││
4: ─────────────────────────────┼──────────────────────────────┼──────────────────────@───────────────────────────────┼┼──────────────────────────────H───
                                │                              │                                                      ││
5: ───PhXZ(a=0.2,x=0.2,z=0.1)───@───PhXZ(a=0.2,x=0.2,z=0.1)────@───────────────────────────PhXZ(a=0.2,x=0.2,z=0.1)────@┼────PhXZ(a=0.2,x=0.2,z=0.1)───H───
                                                                                                                       │
6: ────────────────────────────────────────────────────────────PhXZ(a=0.2,x=0.2,z=0.1)─────────────────────────────────@────PhXZ(a=0.2,x=0.2,z=0.1)───H───
                                                              └────────────────────────┘                             └──┘
Output:
                                                              ┌────────────────────────┐                             ┌──┐
0: ─────────────────────────────────PhXZ(a=0.2,x=0.2,z=0.1)────@───────────────────────────PhXZ(a=0.2,x=0.2,z=0.1)────@─────PhXZ(a=0.2,x=0.2,z=0.1)─────H────────────────────────
                                                               │                                                      │
1: ─────────────────────────────────PhXZ(a=0.2,x=0.2,z=0.1)────@───────────────────────────PhXZ(a=0.2,x=0.2,z=0.1)────@─────PhXZ(a=0.2,x=0.2,z=0.1)─────H────────────────────────

2: ───PhXZ(a=0.2,x=0.2,z=0.1)───@───PhXZ(a=0.2,x=0.2,z=0.1)────@───────────────────────────PhXZ(a=0.2,x=0.2,z=0.1)────@─────X───────────────────────────PhXZ(a=-0.5,x=0.5,z=0)───
                                │                              │                                                      │
3: ─────────────────────────────┼───PhXZ(a=0.2,x=0.2,z=0.1)────┼──────────────────────@────X──────────────────────────┼@────Y───────────────────────────H────────────────────────
                                │                              │                      │                               ││
4: ─────────────────────────────┼──────────────────────────────┼──────────────────────@────X──────────────────────────┼┼────Y───────────────────────────PhXZ(a=0.5,x=0.5,z=0)────
                                │                              │                                                      ││
5: ───PhXZ(a=0.2,x=0.2,z=0.1)───@───PhXZ(a=0.2,x=0.2,z=0.1)────@───────────────────────────PhXZ(a=0.2,x=0.2,z=0.1)────@┼────PhXZ(a=0.2,x=0.2,z=0.1)─────H────────────────────────
                                                                                                                       │
6: ────────────────────────────────────────────────────────────PhXZ(a=0.2,x=0.2,z=0.1)─────X───────────────────────────@────PhXZ(a=-0.2,x=0.8,z=-0.5)───H────────────────────────
                                                              └────────────────────────┘                             └──┘
    """
codecov[bot] commented 3 weeks ago

Codecov Report

Attention: Patch coverage is 99.31034% with 1 line in your changes missing coverage. Please review.

Project coverage is 97.83%. Comparing base (bb24dae) to head (0b42839). Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...irq-core/cirq/transformers/dynamical_decoupling.py 99.21% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #6718 +/- ## ========================================== - Coverage 97.83% 97.83% -0.01% ========================================== Files 1077 1077 Lines 92537 92558 +21 ========================================== + Hits 90535 90555 +20 - Misses 2002 2003 +1 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

babacry commented 1 week ago

I have simplified the code with some abstractions.

Also added comments in a couple of places, especially pulling through mechanisms.

babacry commented 4 days ago

Thanks for the careful review Nour, will submit the code shortly.

eliottrosenberg commented 4 days ago

Thank you both!!