Skip to content

Commit

Permalink
switch order of if-clauses
Browse files Browse the repository at this point in the history
`len(value) == 1` is the simplest case, and is also the case where the problematic clause `len(value) == size` fails.

This commit switches the order, so we check for `len(value) == 1` first.

This ensures that when the `len(value) == size` clause runs, we know that `size != 1`, avoiding the bug in Qiskit#13623.
  • Loading branch information
aeddins-ibm committed Jan 8, 2025
1 parent 93d796f commit 92161ec
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions qiskit/quantum_info/operators/symplectic/pauli_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,16 +451,16 @@ def insert(self, ind: int, value: PauliList, qubit: bool = False) -> PauliList:
f"Index {ind} is greater than number of qubits"
f" in the PauliList ({self.num_qubits})"
)
if len(value) == 1:
# Pad blocks to correct size
value_x = np.vstack(size * [value.x])
value_z = np.vstack(size * [value.z])
value_phase = np.vstack(size * [value.phase])
elif len(value) == size:
if len(value) == size:
# Blocks are already correct size
value_x = value.x
value_z = value.z
value_phase = value.phase
elif len(value) == 1:
# Pad blocks to correct size
value_x = np.vstack(size * [value.x])
value_z = np.vstack(size * [value.z])
value_phase = np.vstack(size * [value.phase])
else:
# Blocks are incorrect size
raise QiskitError(
Expand Down

0 comments on commit 92161ec

Please sign in to comment.