Skip to content

Commit

Permalink
Merge branch 'main' into drop-instruction-dead-weight
Browse files Browse the repository at this point in the history
  • Loading branch information
mtreinish authored Jan 8, 2025
2 parents 0775d3f + 408741c commit 325fe27
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 24 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions qiskit/circuit/library/grover_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def grover_operator(
.. plot::
:include-source:
:context:
:context: close-figs
oracle = QuantumCircuit(1)
oracle.z(0) # the qubit state |1> is the good state
Expand All @@ -133,7 +133,7 @@ def grover_operator(
.. plot::
:include-source:
:context:
:context: close-figs
oracle = QuantumCircuit(4)
oracle.z(3)
Expand All @@ -150,7 +150,7 @@ def grover_operator(
.. plot::
:include-source:
:context:
:context: close-figs
from qiskit.quantum_info import Statevector, DensityMatrix, Operator
Expand Down
2 changes: 1 addition & 1 deletion qiskit/circuit/library/n_local/efficient_su2.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def efficient_su2(
.. plot::
:include-source:
:context:
:context: close-figs
circuit = efficient_su2(4, su2_gates=["rx", "y"], entanglement="circular", reps=1)
circuit.draw("mpl")
Expand Down
2 changes: 1 addition & 1 deletion qiskit/circuit/library/n_local/excitation_preserving.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def excitation_preserving(
.. plot::
:include-source:
:context:
:context: close-figs
from qiskit.circuit.library import excitation_preserving
Expand Down
8 changes: 4 additions & 4 deletions qiskit/circuit/library/n_local/n_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def n_local(
.. plot::
:include-source:
:context:
:context: close-figs
circuit = n_local(3, ["ry", "rz"], "cz", "full", reps=1, insert_barriers=True)
circuit.draw("mpl")
Expand All @@ -170,7 +170,7 @@ def n_local(
.. plot::
:include-source:
:context:
:context: close-figs
circuit = n_local(4, [], "cry", reps=2)
circuit.draw("mpl")
Expand All @@ -179,7 +179,7 @@ def n_local(
.. plot::
:include-source:
:context:
:context: close-figs
entangler_map = [[0, 1], [2, 0]]
circuit = n_local(3, "x", "crx", entangler_map, reps=2)
Expand All @@ -191,7 +191,7 @@ def n_local(
.. plot:
:include-source:
:context:
:context: close-figs
def entanglement(layer_index):
if layer_index % 2 == 0:
Expand Down
6 changes: 3 additions & 3 deletions qiskit/circuit/library/n_local/real_amplitudes.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,21 @@ def real_amplitudes(
.. plot::
:include-source:
:context:
:context: close-figs
ansatz = real_amplitudes(3, entanglement="full", reps=2) # it is the same unitary as above
ansatz.draw("mpl")
.. plot::
:include-source:
:context:
:context: close-figs
ansatz = real_amplitudes(3, entanglement="linear", reps=2, insert_barriers=True)
ansatz.draw("mpl")
.. plot::
:include-source:
:context:
:context: close-figs
ansatz = real_amplitudes(4, reps=2, entanglement=[[0,3], [0,2]], skip_unentangled_qubits=True)
ansatz.draw("mpl")
Expand Down
16 changes: 8 additions & 8 deletions qiskit/quantum_info/operators/symplectic/pauli_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,16 +451,14 @@ 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])
else:
# Blocks are incorrect size
raise QiskitError(
Expand All @@ -471,7 +469,7 @@ def insert(self, ind: int, value: PauliList, qubit: bool = False) -> PauliList:
# Build new array by blocks
z = np.hstack([self.z[:, :ind], value_z, self.z[:, ind:]])
x = np.hstack([self.x[:, :ind], value_x, self.x[:, ind:]])
phase = self.phase + value_phase
phase = self.phase + value.phase

return PauliList.from_symplectic(z, x, phase)

Expand Down Expand Up @@ -1131,6 +1129,8 @@ def from_symplectic(
Returns:
PauliList: the constructed PauliList.
"""
if isinstance(phase, np.ndarray) and np.ndim(phase) > 1:
raise ValueError(f"phase should be at most 1D but has {np.ndim(phase)} dimensions.")
base_z, base_x, base_phase = cls._from_array(z, x, phase)
return cls(BasePauli(base_z, base_x, base_phase))

Expand Down
2 changes: 1 addition & 1 deletion qiskit/transpiler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@
['id', 'rz', 'sx', 'x', 'cx', 'measure', 'delay']
.. plot:
.. plot::
:include-source:
from qiskit.circuit import QuantumCircuit
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
fixes:
- |
Fixed a bug that caused :meth:`.PauliList.insert` with ``qubit=True`` to produce a `phase`
attribute with the wrong shape when the original object was length 1.
Fixed `#13623 <https://github.com/Qiskit/qiskit/issues/13623>`__.
Original file line number Diff line number Diff line change
Expand Up @@ -1560,6 +1560,15 @@ def test_insert(self):
value1 = pauli.insert(1, insert)
self.assertEqual(value1, target1)

# Insert single column to length-1 PauliList:
with self.subTest(msg="length-1, single-column, single-val"):
pauli = PauliList(["X"])
insert = PauliList(["Y"])
target0 = PauliList(["YX"])
value0 = pauli.insert(1, insert, qubit=True)
self.assertEqual(value0, target0)
self.assertEqual(value0.phase.shape, (1,))

# Insert single column
pauli = PauliList(["X", "Y", "Z", "-iI"])
for i in ["I", "X", "Y", "Z", "iY"]:
Expand Down

0 comments on commit 325fe27

Please sign in to comment.