Skip to content

Commit 62f74c7

Browse files
authored
Remove unwanted remapping (#15872)
1 parent 9c8f4fc commit 62f74c7

3 files changed

Lines changed: 25 additions & 3 deletions

File tree

qiskit/circuit/quantumcircuit.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2412,9 +2412,7 @@ def map_vars(op):
24122412
new_clbits=mapped_clbits,
24132413
)
24142414
if append_existing:
2415-
dest._current_scope().extend(
2416-
append_existing, qubits=mapped_qubits, clbits=mapped_clbits
2417-
)
2415+
dest._current_scope().extend(append_existing)
24182416

24192417
return None if inplace else dest
24202418

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
fixes:
2+
- |
3+
Fixed :meth:`.QuantumCircuit.compose` raising :exc:`ValueError` (``'qubits'
4+
argument is the wrong length``) when ``front=True`` is used with an explicit
5+
``qubits`` mapping.
6+
7+
See `#15834 <https://github.com/Qiskit/qiskit/issues/15834>`__.

test/python/circuit/test_compose.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,23 @@ def test_compose_front_gate(self):
550550

551551
self.assertEqual(output, expected)
552552

553+
def test_compose_front_smaller_circuit(self):
554+
"""Test composing a smaller circuit at the front with explicit qubits mapping."""
555+
556+
qc_base = QuantumCircuit(2)
557+
qc_base.h(0)
558+
559+
qc_x = QuantumCircuit(1)
560+
qc_x.x(0)
561+
562+
output = qc_base.compose(qc_x, qubits=[0], front=True)
563+
564+
expected = QuantumCircuit(2)
565+
expected.x(0)
566+
expected.h(0)
567+
568+
self.assertEqual(output, expected)
569+
553570
def test_compose_adds_parameters(self):
554571
"""Test the composed circuit contains all parameters."""
555572
a, b = Parameter("a"), Parameter("b")

0 commit comments

Comments
 (0)