1
$\begingroup$

The main functionality for ordering gates in a cirq circuit that I'm aware of is using the predefined insert strategies of cirq.Circuit.insert(). As far as I see, none of the predefined strategies use the possibility to shuffle commuting gates to reduce circuit depth, i.e. that CNOTs that share the same target or control commute, etc. The docs also don't seem to mention anything like this.

I'd like to specifically use the commutation rules of CNOTs to reduce the depth of my circuits, and before I start writing my own code, my question is: does cirq provide any functionality of this sort?

$\endgroup$
0
$\begingroup$

No, there's no built-in functionality to optimize the circuit in that way.

There is cirq.commutes(A, B) which will tell you if A and B commute. However, cirq.commutes is permitted to fail instead of giving a result, and it is somewhat new so there's still several landmines you can hit when using it. For example, it currently will refuse to check if an operation commutes with a moment. You can instead use cirq.definitely_commutes(A, B), which replaces the failures with false negatives, keeping in mind that you will sometimes see things that you know commute not moving through each other because the comparison isn't supported yet.

$\endgroup$
1
  • $\begingroup$ Thanks for pointing out cirq.commutes(), that's also very helpful! $\endgroup$
    – skola
    Aug 28 '20 at 8:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.