Skip to content

AttributeError: 'SingleQubitPauliStringGateOperation' object has no attribute 'pauli_string' in move_pauli_strings_into_circuit #7934

@huhu37

Description

@huhu37

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

Metadata

Metadata

Assignees

Labels

good first issueThis issue can be resolved by someone who is not familiar with the codebase. A good starting issue.good for learningFor beginners in QC, this will help picking up some knowledge. Bit harder than "good first issues"kind/bug-reportSomething doesn't seem to work.triage/acceptedA consensus emerged that this bug report, feature request, or other action should be worked on

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions