From 6cd0215531732641d09f7f2967d4cf01b3f24a0f Mon Sep 17 00:00:00 2001 From: "Christopher J. Wood" Date: Fri, 1 May 2020 09:57:37 -0400 Subject: [PATCH] Fix number of parallel shots for statevector and unitary sims (#725) * Prevent statevector and unitary controller from running parallel shots This was causing bugs where number of shots of a statevector and unitary simulators would be the number of CPU cores. --- .../fix-controller-parallel-shots-d32967c029259790.yaml | 5 +++++ src/controllers/statevector_controller.hpp | 4 ++++ src/controllers/unitary_controller.hpp | 4 ++++ 3 files changed, 13 insertions(+) create mode 100644 releasenotes/notes/fix-controller-parallel-shots-d32967c029259790.yaml diff --git a/releasenotes/notes/fix-controller-parallel-shots-d32967c029259790.yaml b/releasenotes/notes/fix-controller-parallel-shots-d32967c029259790.yaml new file mode 100644 index 0000000000..86aefecec7 --- /dev/null +++ b/releasenotes/notes/fix-controller-parallel-shots-d32967c029259790.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - | + Fixed bug with statevector and unitary simulators running a number of (parallel) + shots equal to the number of CPU threads instead of only running a single shot. diff --git a/src/controllers/statevector_controller.hpp b/src/controllers/statevector_controller.hpp index 769a17712e..883194ab0f 100755 --- a/src/controllers/statevector_controller.hpp +++ b/src/controllers/statevector_controller.hpp @@ -137,6 +137,10 @@ void StatevectorController::set_config(const json_t& config) { // Set base controller config Base::Controller::set_config(config); + // Override max parallel shots to be 1 since this should only be used + // for single shot simulations + Base::Controller::max_parallel_shots_ = 1; + // Add custom initial state if (JSON::get_value(initial_state_, "initial_statevector", config)) { // Check initial state is normalized diff --git a/src/controllers/unitary_controller.hpp b/src/controllers/unitary_controller.hpp index 147154d571..eb3cf4dac9 100755 --- a/src/controllers/unitary_controller.hpp +++ b/src/controllers/unitary_controller.hpp @@ -129,6 +129,10 @@ void UnitaryController::set_config(const json_t &config) { // Set base controller config Base::Controller::set_config(config); + // Override max parallel shots to be 1 since this should only be used + // for single shot simulations + Base::Controller::max_parallel_shots_ = 1; + // Add custom initial unitary if (JSON::get_value(initial_unitary_, "initial_unitary", config)) { // Check initial state is unitary