diff --git a/releasenotes/notes/bug-fix-required-memory-check-a970c4dc6eb2896f.yaml b/releasenotes/notes/bug-fix-required-memory-check-a970c4dc6eb2896f.yaml new file mode 100644 index 0000000000..e4d79b1aef --- /dev/null +++ b/releasenotes/notes/bug-fix-required-memory-check-a970c4dc6eb2896f.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + When required memory is smaller than the system memory, multi-chunk was enabled + and simulation was started though memory is short. This fix corrects this behavior + to throw an exception. \ No newline at end of file diff --git a/src/controllers/controller.hpp b/src/controllers/controller.hpp index b5aaed4022..28369835fc 100755 --- a/src/controllers/controller.hpp +++ b/src/controllers/controller.hpp @@ -467,16 +467,23 @@ void Controller::set_parallelization_circuit(const Circuit &circ, } bool Controller::multiple_chunk_required(const Circuit &circ, - const Noise::NoiseModel &noise) const -{ - if(circ.num_qubits < 3) + const Noise::NoiseModel &noise) const { + if (circ.num_qubits < 3) return false; - if(num_process_per_experiment_ > 1 || Controller::get_min_memory_mb() < required_memory_mb(circ, noise)) + if (cache_block_qubit_ >= 2 && cache_block_qubit_ < circ.num_qubits) return true; - if(cache_block_qubit_ >= 2 && cache_block_qubit_ < circ.num_qubits) - return true; + if(num_process_per_experiment_ == 1 && cache_block_qubit_ >= 2 && num_gpus_ > 0) + return (max_gpu_memory_mb_ / num_gpus_ < required_memory_mb(circ, noise)); + + if(num_process_per_experiment_ > 1) { + size_t total_mem = max_memory_mb_; + if(cache_block_qubit_ >= 2) + total_mem += max_gpu_memory_mb_; + if(total_mem*num_process_per_experiment_ > required_memory_mb(circ, noise)) + return true; + } return false; }