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

Always hook omp functions in Mac #2128

Merged
merged 4 commits into from
May 21, 2024
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
4 changes: 4 additions & 0 deletions qiskit_aer/backends/backend_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@

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

# pylint: disable=import-error, no-name-in-module, abstract-method
from .controller_wrappers import aer_initialize_libraries

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

Expand All @@ -35,6 +38,7 @@
# Location where we put external libraries that will be
# loaded at runtime by the simulator extension
LIBRARY_DIR = os.path.dirname(__file__)
aer_initialize_libraries(LIBRARY_DIR)

LEGACY_METHOD_MAP = {
"statevector_cpu": ("statevector", "CPU"),
Expand Down
2 changes: 2 additions & 0 deletions qiskit_aer/backends/wrappers/aer_controller_binding.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ void read_value(const py::tuple &t, size_t index, T &v) {

template <typename MODULE>
void bind_aer_controller(MODULE m) {
m.def("aer_initialize_libraries", &initialize_libraries);

py::class_<ControllerExecutor<Controller>> aer_ctrl(m,
"aer_controller_execute");
aer_ctrl.def(py::init<>());
Expand Down
6 changes: 6 additions & 0 deletions releasenotes/notes/init_omp_first-c9d19dbfa1a0fc2b.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
fixes:
- |
In Mac, to use OpenMP, setup of hooks to omp functions is necessary. However, this setup
works only for backend services and not for quantum_info classes of ``AerStatevector`` and
``AerDensityMatrix``. This fix calls the setup in quantum_info also.
18 changes: 6 additions & 12 deletions src/controllers/controller_execute.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,15 @@

namespace AER {

void initialize_libraries(const std::string &lib_dir) {
// Fix for MacOS and OpenMP library double initialization crash.
// Issue: https://github.com/Qiskit/qiskit-aer/issues/1
Hacks::maybe_load_openmp(lib_dir);
}

template <class controller_t, typename inputdata_t>
Result controller_execute(const inputdata_t &qobj) {
controller_t controller;

// Fix for MacOS and OpenMP library double initialization crash.
// Issue: https://github.com/Qiskit/qiskit-aer/issues/1
if (Parser<inputdata_t>::check_key("config", qobj)) {
std::string path;
const auto &config = Parser<inputdata_t>::get_value("config", qobj);
Parser<inputdata_t>::get_value(path, "library_dir", config);
Hacks::maybe_load_openmp(path);
}
return controller.execute(qobj);
}

Expand Down Expand Up @@ -229,9 +226,6 @@ Result controller_execute(std::vector<std::shared_ptr<Circuit>> &input_circs,
auto time_taken =
std::chrono::duration<double>(myclock_t::now() - timer_start).count();

// Fix for MacOS and OpenMP library double initialization crash.
// Issue: https://github.com/Qiskit/qiskit-aer/issues/1
Hacks::maybe_load_openmp(config.library_dir);
controller.set_config(config);
auto ret = controller.execute(circs, noise_model, config);

Expand Down
Loading