Occasionally, the annealer finds CX blocks where two of the same CNOTs are added together. This is inefficient.
This is because the line of code that checks whether the CNOTs are preceding or not only checks the surrounding layers.
So suppose I have 5 layers in the CX block with only CNOT(1,2) in the first layer, then the third layer might also obtain CNOT(1,2).
In OptimizedCircuit.random_flip_cx() :
if layer_idx < len(self._cx_block)-1 and self._cx_block[layer_idx+1].has_cx(ctrl, trgt):
# Try again if CX gate already present in layer above (to avoid redundancy)
continue
if layer_idx > 0 and self._cx_block[layer_idx-1].has_cx(ctrl, trgt):
# Try again if CX gate already present in layer below (to avoid redundancy)
Occasionally, the annealer finds CX blocks where two of the same CNOTs are added together. This is inefficient.
This is because the line of code that checks whether the CNOTs are preceding or not only checks the surrounding layers.
So suppose I have 5 layers in the CX block with only CNOT(1,2) in the first layer, then the third layer might also obtain CNOT(1,2).
In
OptimizedCircuit.random_flip_cx():