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

Excessive memory usage while transpiling at optimization level 2 #9693

Closed
ArfatSalman opened this issue Mar 1, 2023 · 1 comment · Fixed by #9201
Closed

Excessive memory usage while transpiling at optimization level 2 #9693

ArfatSalman opened this issue Mar 1, 2023 · 1 comment · Fixed by #9201
Labels
bug Something isn't working

Comments

@ArfatSalman
Copy link
Contributor

Environment

  • Qiskit Terra version: {'qiskit-terra': '0.23.2', 'qiskit-aer': '0.11.2', 'qiskit-ignis': None, 'qiskit-ibmq-provider': '0.20.0', 'qiskit': '0.41.0', 'qiskit-nature': None, 'qiskit-finance': None, 'qiskit-optimization': None, 'qiskit-machine-learning': None}
  • Python version: Python 3.9.12
  • Operating system: MacOS Ventura 13.1 (22C65)

What is happening?

While transpiling this circuit, the python process tried to allocate more than 70 GB of memory (as far as I could see in the Activity Monitor of MacOS). The process is eventually killed.

Screenshot 2023-03-01 at 09 49 07

At any other optimization level (0, 1, or 3), the circuit behaves normally.

Not sure what the issue is. It seems like it is related to this issue #9197 which leads to a large memory allocation.

How can we reproduce the issue?

from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister
from qiskit.circuit.library.standard_gates import *


qr = QuantumRegister(7, name="qr")
cr = ClassicalRegister(7, name="cr")
qc = QuantumCircuit(qr, cr, name="qc")
qc.append(
    UGate(2.2050953212701585, 3.3615540885941595, 4.353999488160196),
    qargs=[qr[4]],
    cargs=[],
)
qc.append(C3XGate(), qargs=[qr[4], qr[1], qr[3], qr[5]], cargs=[])
qc.append(
    CUGate(
        1.8216381126900292, 1.1397633674319172, 5.883270079132554, 6.151280357960994
    ),
    qargs=[qr[2], qr[6]],
    cargs=[],
)
qc.append(RZGate(0.8251147604978816), qargs=[qr[1]], cargs=[])
qc.append(XGate(), qargs=[qr[1]], cargs=[])
qc.append(RZZGate(3.4573000463617367), qargs=[qr[5], qr[0]], cargs=[])
qc.append(CXGate(), qargs=[qr[6], qr[4]], cargs=[])
qc.append(RCCXGate(), qargs=[qr[1], qr[3], qr[4]], cargs=[])
qc.append(U2Gate(2.647545737192122, 3.1045763954315304), qargs=[qr[6]], cargs=[])
qc.append(ZGate(), qargs=[qr[1]], cargs=[])
qc.append(
    CU3Gate(1.3925947961767187, 3.8341186215245604, 3.461675537985181),
    qargs=[qr[5], qr[1]],
    cargs=[],
)
qc.append(ZGate(), qargs=[qr[6]], cargs=[])
qc.append(C3XGate(), qargs=[qr[3], qr[0], qr[4], qr[2]], cargs=[])
qc.append(RZXGate(6.045230636776243), qargs=[qr[4], qr[6]], cargs=[])
qc.append(TdgGate(), qargs=[qr[1]], cargs=[])
qc.append(RZZGate(1.627140919622475), qargs=[qr[4], qr[2]], cargs=[])
qc.append(C3XGate(), qargs=[qr[3], qr[5], qr[1], qr[2]], cargs=[])
qc.append(
    CU3Gate(1.4873061282104487, 6.193271645272907, 0.08920760414730318),
    qargs=[qr[5], qr[1]],
    cargs=[],
)
qc.append(IGate(), qargs=[qr[3]], cargs=[])
qc.append(HGate(), qargs=[qr[4]], cargs=[])
qc.append(C4XGate(), qargs=[qr[0], qr[2], qr[6], qr[5], qr[3]], cargs=[])
qc.append(ECRGate(), qargs=[qr[1], qr[0]], cargs=[])
qc.append(CXGate(), qargs=[qr[6], qr[2]], cargs=[])
qc.append(CXGate(), qargs=[qr[6], qr[1]], cargs=[])

qc.measure(qr, cr)

from qiskit import transpile

qc = transpile(qc, basis_gates=None, optimization_level=2, coupling_map=None)

What should happen?

The circuit should transpile correctly.

Any suggestions?

No response

@ArfatSalman ArfatSalman added the bug Something isn't working label Mar 1, 2023
@jakelishman jakelishman linked a pull request Mar 1, 2023 that will close this issue
@mtreinish
Copy link
Member

Yeah I'm pretty sure this is a duplicate of #9197, it's only effecting you on optimization level 2 because at optimization level 3 the other passes run decompose the large multiqubit gates to 1 and 2 qubit gates (in order to do additional optimization passes). For lower optimization levels commutative cancellation isn't run. #9201 should fix this

@mergify mergify bot closed this as completed in #9201 Mar 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants