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

Directly use psutil to get total system memory #2002

Merged
merged 1 commit into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 4 additions & 2 deletions qiskit_aer/backends/backend_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@
"""
import os
from math import log2
from qiskit.utils import local_hardware_info

import psutil
from qiskit.circuit import QuantumCircuit
from qiskit.compiler import assemble
from qiskit.qobj import QasmQobjInstruction
from qiskit.result import ProbDistribution
from qiskit.quantum_info import Clifford

from .compatibility import Statevector, DensityMatrix, StabilizerState, Operator, SuperOp

# Available system memory
SYSTEM_MEMORY_GB = local_hardware_info()["memory"]
SYSTEM_MEMORY_GB = psutil.virtual_memory().total / (1024**3)

# Max number of qubits for complex double statevector
# given available system memory
Expand Down
5 changes: 3 additions & 2 deletions qiskit_aer/backends/statevector_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
import copy
import logging
from warnings import warn
from qiskit.utils import local_hardware_info

import psutil
from qiskit.providers.options import Options
from qiskit.providers.models import QasmBackendConfiguration

Expand Down Expand Up @@ -364,7 +365,7 @@ def _validate(self, qobj):
if n_qubits > max_qubits:
raise AerError(
f"Number of qubits ({n_qubits}) is greater than max ({max_qubits}) "
f'for "{name}" with {int(local_hardware_info()["memory"])} GB system memory.'
f'for "{name}" with {int(psutil.virtual_memory().total / (1024**3))} GB system memory.'
)

if qobj.config.shots != 1:
Expand Down
5 changes: 3 additions & 2 deletions qiskit_aer/backends/unitary_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
import copy
import logging
from warnings import warn
from qiskit.utils import local_hardware_info

import psutil
from qiskit.providers.options import Options
from qiskit.providers.models import QasmBackendConfiguration

Expand Down Expand Up @@ -351,7 +352,7 @@ def _validate(self, qobj):
raise AerError(
f"Number of qubits ({n_qubits}) is greater than "
f'max ({max_qubits}) for "{name}" with '
f"{int(local_hardware_info()['memory'])} GB system memory."
f"{int(psutil.virtual_memory().total / (1024**3))} GB system memory."
)
if qobj.config.shots != 1:
logger.info('"%s" only supports 1 shot. Setting shots=1.', name)
Expand Down
9 changes: 9 additions & 0 deletions releasenotes/notes/psutil-added-ffb2a4b5956fa03d.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
upgrade:
- |
Added `psutil <https://pypi.org/project/psutil/>`__ as a dependency for
Qiskit Aer. This is used to determine the amount of physical resources
available. ``psutil`` is currently a dependency of Qiskit, which is a
requirement for Qiskit Aer, so ``psutil`` was effectively already required
for any ``qiskit-aer`` installation. But, as qiskit-aer is now using it
directly is now a direct dependency for ``qiskit-aer``.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"qiskit>=0.44.0",
"numpy>=1.16.3",
"scipy>=1.0",
"psutil>=5",
]

classifiers = [
Expand Down
Loading