Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 6 commits into from
Sep 24, 2024

Conversation

babacry
Copy link
Collaborator

@babacry babacry commented Sep 5, 2024

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────────────────────────
                                                              └────────────────────────┘                             └──┘
    """

Copy link

codecov bot commented Sep 5, 2024

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 ⚠️
Additional details and impacted files
@@            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     

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

@babacry babacry changed the title Support a new feature of adding dd. Support a pulling through non-clifford moments in adding dd Sep 6, 2024
@babacry babacry changed the title Support a pulling through non-clifford moments in adding dd Dynamical decoupling: Support pulling through the whole circuit with non-clifford moments Sep 6, 2024
Copy link
Collaborator

@eliottrosenberg eliottrosenberg left a comment

Choose a reason for hiding this comment

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

Looks good to me! Thank you so much, Renyi!

Copy link
Collaborator

@NoureldinYosri NoureldinYosri left a comment

Choose a reason for hiding this comment

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

my original concern still holds, the DD logic is getting more complex. can you simplify it?

cirq-core/cirq/transformers/dynamical_decoupling.py Outdated Show resolved Hide resolved
cirq-core/cirq/transformers/dynamical_decoupling.py Outdated Show resolved Hide resolved
cirq-core/cirq/transformers/dynamical_decoupling.py Outdated Show resolved Hide resolved
for qid, gate in enumerate(pulled_through_pauli_ops):
pulled_through *= gate.on(qubit_order[qid])
if _is_clifford_op(op_at_moment):
prev_circuit = cirq.Circuit(cirq.Moment(op_at_moment))
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is inefficient. looks like you only need the unitary which you can get using cirq.protocols.unitary_protocol.unitary(op)

@CirqBot CirqBot added the size: L 250< lines changed <1000 label Sep 10, 2024
Previously, we only insert dd for split Clifford pieces. While, one use
case is to insert into consecutive idle moments cross Clifford pieces.
We also support merging remaining Puali op of dd sequence into starting
/ ending single-qubit operations of each consecutive idle ops.
@babacry
Copy link
Collaborator Author

babacry commented Sep 19, 2024

I have simplified the code with some abstractions.

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

Copy link
Collaborator

@NoureldinYosri NoureldinYosri left a comment

Choose a reason for hiding this comment

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

a few nits, otherwise LGTM

return False
return True
def _is_clifford_op(op: 'cirq.Operation') -> bool:
if op.gate is not None and isinstance(op.gate, cirq.MeasurementGate):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if op.gate is not None and isinstance(op.gate, cirq.MeasurementGate):
if op.gate is not None or isinstance(op.gate, cirq.MeasurementGate):

cirq-core/cirq/transformers/dynamical_decoupling.py Outdated Show resolved Hide resolved
cirq-core/cirq/transformers/dynamical_decoupling.py Outdated Show resolved Hide resolved
cirq-core/cirq/transformers/dynamical_decoupling.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@NoureldinYosri NoureldinYosri left a comment

Choose a reason for hiding this comment

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

I just noticed you import cirq. this will cause circular imports. please follow the google style for imports

cirq-core/cirq/transformers/dynamical_decoupling.py Outdated Show resolved Hide resolved
cirq-core/cirq/transformers/dynamical_decoupling.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@NoureldinYosri NoureldinYosri left a comment

Choose a reason for hiding this comment

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

thanks for the changes, great job

@babacry
Copy link
Collaborator Author

babacry commented Sep 23, 2024

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

@babacry babacry enabled auto-merge (squash) September 23, 2024 22:52
@babacry babacry merged commit 756abe3 into quantumlib:main Sep 24, 2024
35 checks passed
@eliottrosenberg
Copy link
Collaborator

Thank you both!!

harry-phasecraft pushed a commit to PhaseCraft/Cirq that referenced this pull request Oct 31, 2024
…non-clifford moments (quantumlib#6718)

* Support a new feature of adding dd.

Previously, we only insert dd for split Clifford pieces. While, one use
case is to insert into consecutive idle moments cross Clifford pieces.
We also support merging remaining Puali op of dd sequence into starting
/ ending single-qubit operations of each consecutive idle ops.

* Pull through all the way.

* Apply comments; simply the code a bit; Add comments.

* apply reviews

* import cirq -> import ops, ...
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants