diff --git a/src/controllers/aer_controller.hpp b/src/controllers/aer_controller.hpp index 77f013e064..fc69c974cc 100755 --- a/src/controllers/aer_controller.hpp +++ b/src/controllers/aer_controller.hpp @@ -1941,19 +1941,20 @@ void Controller::run_circuit_without_sampled_noise(Circuit &circ, const bool can_sample = check_measure_sampling_opt(circ, method); // Cache blocking pass + uint_t block_bits = 0; if (cache_blocking) { auto cache_block_pass = transpile_cache_blocking(method, circ, dummy_noise, config); cache_block_pass.set_sample_measure(can_sample); cache_block_pass.optimize_circuit(circ, dummy_noise, state.opset(), result); - uint_t block_bits = 0; if (cache_block_pass.enabled()) { block_bits = cache_block_pass.block_bits(); } - // allocate qubit register - state.allocate(max_qubits_, block_bits); } - // Check if measure sampler and optimization are valid + // allocate qubit register + state.allocate(max_qubits_, block_bits); + + // Check if measure sampler and optimization are valid if (can_sample) { // Implement measure sampler auto& ops = circ.ops; @@ -2005,16 +2006,18 @@ void Controller::run_circuit_with_sampled_noise( result); fusion_pass.optimize_circuit(noise_circ, dummy_noise, state.opset(), result); + uint_t block_bits = 0; if (cache_blocking) { cache_block_pass.optimize_circuit(noise_circ, dummy_noise, state.opset(), result); - uint_t block_bits = 0; if (cache_block_pass.enabled()) { block_bits = cache_block_pass.block_bits(); } - // allocate qubit register - state.allocate(max_qubits_, block_bits); } + + // allocate qubit register + state.allocate(max_qubits_, block_bits); + run_single_shot(noise_circ, state, result, rng); } } diff --git a/src/simulators/superoperator/superoperator_state.hpp b/src/simulators/superoperator/superoperator_state.hpp index 8d34b7c93d..598fc187d6 100755 --- a/src/simulators/superoperator/superoperator_state.hpp +++ b/src/simulators/superoperator/superoperator_state.hpp @@ -23,6 +23,9 @@ #include "framework/utils.hpp" #include "simulators/state.hpp" #include "superoperator.hpp" +#ifdef AER_THRUST_SUPPORTED +#include "superoperator_thrust.hpp" +#endif namespace AER { namespace QubitSuperoperator { @@ -100,6 +103,8 @@ class State : public Base::State { // Config: {"omp_qubit_threshold": 3} virtual void set_config(const json_t &config) override; + virtual void allocate(uint_t num_qubits,uint_t block_bits) override; + //----------------------------------------------------------------------- // Additional methods //----------------------------------------------------------------------- @@ -348,6 +353,11 @@ template void State::initialize_omp() { BaseState::threads_); // set allowed OMP threads in qubitvector } +template +void State::allocate(uint_t num_qubits, uint_t block_bits){ + BaseState::qreg_.chunk_setup(num_qubits * 2, num_qubits * 2, 0, 1); +} + //========================================================================= // Implementation: Reset //========================================================================= diff --git a/src/simulators/superoperator/superoperator_thrust.hpp b/src/simulators/superoperator/superoperator_thrust.hpp index 205ab56223..9e97bd3b36 100755 --- a/src/simulators/superoperator/superoperator_thrust.hpp +++ b/src/simulators/superoperator/superoperator_thrust.hpp @@ -46,8 +46,8 @@ class SuperoperatorThrust : public DensityMatrixThrust { SuperoperatorThrust() : SuperoperatorThrust(0) {}; explicit SuperoperatorThrust(size_t num_qubits); - SuperoperatorThrust(const Superoperator& obj) = delete; - Superoperator &operator=(const Superoperator& obj) = delete; + SuperoperatorThrust(const SuperoperatorThrust& obj) = delete; + SuperoperatorThrust &operator=(const SuperoperatorThrust& obj) = delete; //----------------------------------------------------------------------- // Utility functions @@ -86,7 +86,7 @@ class SuperoperatorThrust : public DensityMatrixThrust { //------------------------------------------------------------------------------ template -SuperOperatorThrust::SuperoperatorThrust(size_t num_qubits) { +SuperoperatorThrust::SuperoperatorThrust(size_t num_qubits) { set_num_qubits(num_qubits); } @@ -95,7 +95,7 @@ SuperOperatorThrust::SuperoperatorThrust(size_t num_qubits) { //------------------------------------------------------------------------------ template -void SuperOperatorThrust::set_num_qubits(size_t num_qubits) { +void SuperoperatorThrust::set_num_qubits(size_t num_qubits) { num_qubits_ = num_qubits; // Superoperator is same size matrix as a unitary matrix // of twice as many qubits @@ -104,7 +104,7 @@ void SuperOperatorThrust::set_num_qubits(size_t num_qubits) { template -void SuperOperatorThrust::initialize() { +void SuperoperatorThrust::initialize() { // Set underlying unitary matrix to identity BaseUnitary::initialize(); } @@ -112,7 +112,7 @@ void SuperOperatorThrust::initialize() { template template -void SuperOperatorThrust::initialize_from_matrix(const matrix> &mat) { +void SuperoperatorThrust::initialize_from_matrix(const matrix> &mat) { if (AER::Utils::is_square(mat)) { const size_t nrows = mat.GetRows(); if (nrows == BaseUnitary::rows_) { @@ -140,7 +140,7 @@ void SuperOperatorThrust::initialize_from_matrix(const matrix -void SuperOperatorThrust::initialize_from_matrix(matrix> &&mat) { +void SuperoperatorThrust::initialize_from_matrix(matrix> &&mat) { if (AER::Utils::is_square(mat)) { const size_t nrows = mat.GetRows(); if (nrows == BaseUnitary::rows_) { @@ -176,7 +176,7 @@ void SuperOperatorThrust::initialize_from_matrix(matrix -inline std::ostream &operator<<(std::ostream &out, const AER::QV::SuperOperatorThrust&m) { +inline std::ostream &operator<<(std::ostream &out, const AER::QV::SuperoperatorThrust&m) { out << m.copy_to_matrix(); return out; }