Skip to content

cirq.MergeInteractions not canceling out single qubit gates for a circuit with two cirq.CZ layers #4815

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

Closed
vtomole opened this issue Jan 8, 2022 · 5 comments
Labels
area/transformers kind/bug-report Something doesn't seem to work. triage/discuss Needs decision / discussion, bring these up during Cirq Cynque

Comments

@vtomole
Copy link
Collaborator

vtomole commented Jan 8, 2022

How to reproduce the issue

import cirq
import sys

print(f"Python version {sys.version}")
print(f"Cirq version {cirq.__version__}")
qubits = cirq.LineQubit.range(2)
circuit = cirq.Circuit(cirq.CZ(*qubits), cirq.CZ(*qubits))
print(circuit)
print("\n--------------------\n")
cirq.MergeInteractions().optimize_circuit(circuit)
print(circuit)
Python version 3.8.10 (default, Nov 26 2021, 20:14:08) 
[GCC 9.3.0]
Cirq version 0.14.0.dev20220105215702
0: ───@───@───
      │   │
1: ───@───@───

--------------------

0: ───S───S^-1───

S and S^-1 should cancel out; leading to an empty circuit.

@vtomole vtomole added triage/discuss Needs decision / discussion, bring these up during Cirq Cynque kind/bug-report Something doesn't seem to work. area/transformers labels Jan 8, 2022
@MichaelBroughton
Copy link
Collaborator

cc: @tanujkhattar to xref with new Transformers implementation.

@tanujkhattar
Copy link
Collaborator

You can achieve your desired behavior via

 def post_clean_up(ops):
     c = cirq.Circuit(ops)
     cirq.merge_single_qubit_gates_into_phxz(c)
     return c.all_operations()

 cirq.MergeInteractions(post_clean_up=post_clean_up).optimize_circuit(circuit)

@vtomole
Copy link
Collaborator Author

vtomole commented Jan 12, 2022

@tanujkhattar Thanks! Do we want to keep this open for your transformer work or should we open a new issue? Maybe you already have a note of this so we don't need an issue about it.

@tanujkhattar
Copy link
Collaborator

Opened #4831 to track the specific issue and drive a broader discussion on differences in the decomposer APIs.

@vtomole
Copy link
Collaborator Author

vtomole commented Jan 12, 2022

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/transformers kind/bug-report Something doesn't seem to work. triage/discuss Needs decision / discussion, bring these up during Cirq Cynque
Projects
None yet
Development

No branches or pull requests

3 participants