Describe the issue
The move_pauli_strings_into_circuit function in cirq.contrib.paulistring.recombine fails with an AttributeError when processing a circuit containing a standard single-qubit gate (such as cirq.X).
Explain how to reproduce the bug or problem
This issue can be reproduced by running the provided code snippet
import cirq
from cirq.contrib.paulistring.recombine import move_pauli_strings_into_circuit
q = cirq.GridQubit(0, 0)
circuit_left = cirq.Circuit(cirq.X(q))
circuit_right = cirq.Circuit()
move_pauli_strings_into_circuit(circuit_left, circuit_right)
Details
Traceback (most recent call last):
File "path/to/trigger.py", line 8, in
move_pauli_strings_into_circuit(circuit_left, circuit_right)
File "path/to/cirq/contrib/paulistring/recombine.py", line 82, in move_pauli_strings_into_circuit
placements = _sorted_best_string_placements(rightmost_nodes, output_ops)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "path/to/cirq/contrib/paulistring/recombine.py", line 65, in _sorted_best_string_placements
return sorted(node_maxes, key=sort_key, reverse=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "path/to/cirq/contrib/paulistring/recombine.py", line 32, in
sort_key = lambda placement: (-len(placement[0].pauli_string), placement[1])
^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'SingleQubitPauliStringGateOperation' object has no attribute 'pauli_string'. Did you mean: '_as_pauli_string'?
Tell us the version of Cirq where this happens
cirq 1.6.1
Describe the issue
The
move_pauli_strings_into_circuitfunction incirq.contrib.paulistring.recombinefails with anAttributeErrorwhen processing a circuit containing a standard single-qubit gate (such as cirq.X).Explain how to reproduce the bug or problem
This issue can be reproduced by running the provided code snippet
Details
Traceback (most recent call last):
File "path/to/trigger.py", line 8, in
move_pauli_strings_into_circuit(circuit_left, circuit_right)
File "path/to/cirq/contrib/paulistring/recombine.py", line 82, in move_pauli_strings_into_circuit
placements = _sorted_best_string_placements(rightmost_nodes, output_ops)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "path/to/cirq/contrib/paulistring/recombine.py", line 65, in _sorted_best_string_placements
return sorted(node_maxes, key=sort_key, reverse=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "path/to/cirq/contrib/paulistring/recombine.py", line 32, in
sort_key = lambda placement: (-len(placement[0].pauli_string), placement[1])
^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'SingleQubitPauliStringGateOperation' object has no attribute 'pauli_string'. Did you mean: '_as_pauli_string'?
Tell us the version of Cirq where this happens
cirq 1.6.1