Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wrong argument supplied to _identity_op() #9201

Merged
merged 6 commits into from
Mar 1, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion qiskit/circuit/commutation_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def commute(
# being the lowest possible indices so the identity can be tensored before it.
extra_qarg2 = num_qubits - len(qarg1)
if extra_qarg2:
id_op = _identity_op(2**extra_qarg2)
id_op = _identity_op(extra_qarg2)
operator_1 = id_op.tensor(operator_1)
op12 = operator_1.compose(operator_2, qargs=qarg2, front=False)
op21 = operator_1.compose(operator_2, qargs=qarg2, front=True)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
fixes:
- |
Fixed an issue with the :class:`~.CommutationChecker` class where it would
attempt to internally allocate an array for :math:`2^{n}` qubits when it
only needed an array to represent :math:`n` qubits. This could cause
an excessive amount of memory for wide gates, for example a 4 qubit
gate would require 32 gigabytes instead of 2 kilobytes.
Fixed `#9197 <https://github.com/Qiskit/qiskit-terra/issues/9197>`__
8 changes: 7 additions & 1 deletion test/python/circuit/test_commutation_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from qiskit import ClassicalRegister
from qiskit.test import QiskitTestCase

from qiskit.circuit import QuantumRegister, Parameter
from qiskit.circuit import QuantumRegister, Parameter, Qubit
from qiskit.circuit import CommutationChecker
from qiskit.circuit.library import (
ZGate,
Expand Down Expand Up @@ -357,6 +357,12 @@ def test_complex_gates(self):
res = comm_checker.commute(lf3, [0, 1, 2], [], lf4, [0, 1, 2], [])
self.assertTrue(res)

def test_c7x_gate(self):
"""Test wide gate works correctly."""
qargs = [Qubit() for _ in [None] * 8]
res = CommutationChecker().commute(XGate(), qargs[:1], [], XGate().control(7), qargs, [])
self.assertFalse(res)


if __name__ == "__main__":
unittest.main()