diff --git a/src/simulators/qasm/qasm_controller.hpp b/src/simulators/qasm/qasm_controller.hpp index b32581bf46..4afa8ddd12 100755 --- a/src/simulators/qasm/qasm_controller.hpp +++ b/src/simulators/qasm/qasm_controller.hpp @@ -566,7 +566,7 @@ void QasmController::set_parallelization_circuit(const Circuit& circ, switch (method) { case Method::statevector: case Method::tensor_network: { - if ((noise_model_.ideal() || !noise_model_.has_quantum_errors()) && + if ((noise_model.is_ideal() || !noise_model.has_quantum_errors()) && check_measure_sampling_opt(circ, Method::statevector).first) { parallel_shots_ = 1; parallel_state_update_ = max_parallel_threads_; @@ -624,16 +624,11 @@ OutputData QasmController::run_circuit_helper(const Circuit &circ, data.add_additional_data("metadata", json_t::object({{"measure_sampling", false}})); // Check if there is noise for the implementation -<<<<<<< HEAD - if (noise_model_.ideal()) { - run_circuit_without_noise(circ, shots, state, initial_state, data, rng); - } else if (!noise_model_.has_quantum_errors()) { - run_circuit_without_noise(noise_model_.sample_noise(circ, rng), - shots, state, initial_state, data, rng); -======= if (noise.is_ideal()) { run_circuit_without_noise(circ, shots, state, initial_state, method, data, rng); ->>>>>>> upstream/master + } else if (!noise.has_quantum_errors()) { + run_circuit_without_noise(noise.sample_noise(circ, rng), + shots, state, initial_state, method, data, rng); } else { run_circuit_with_noise(circ, noise, shots, state, initial_state, method, data, rng); } @@ -710,14 +705,9 @@ void QasmController::run_circuit_without_noise(const Circuit &circ, // Get measurement operations and set of measured qubits ops = std::vector(opt_circ.ops.begin() + pos, opt_circ.ops.end()); measure_sampler(ops, shots, state, data, rng); -<<<<<<< HEAD - data.add_additional_data("metadata", - json_t::object({{"measure", "sampling"}})); -======= // Add measure sampling metadata data.add_additional_data("metadata", json_t::object({{"measure_sampling", true}})); ->>>>>>> upstream/master } } @@ -738,11 +728,6 @@ QasmController::check_measure_sampling_opt(const Circuit &circ, auto start = circ.ops.begin(); while (start != circ.ops.end()) { const auto type = start->type; -<<<<<<< HEAD - if (type == Operations::OpType::reset || - type == Operations::OpType::initialize || - type == Operations::OpType::kraus) { -======= if (method != Method::density_matrix) { if(type == Operations::OpType::reset || type == Operations::OpType::initialize || @@ -751,13 +736,6 @@ QasmController::check_measure_sampling_opt(const Circuit &circ, return std::make_pair(false, 0); } } - if (type == Operations::OpType::roerror) { - // TODO: Readout errors should be allowed with - // measurement sampling as long as they are - // all moved to occur after measurements. ->>>>>>> upstream/master - return std::make_pair(false, 0); - } if (type == Operations::OpType::measure || type == Operations::OpType::roerror) break; diff --git a/test/terra/backends/qasm_simulator/qasm_measure.py b/test/terra/backends/qasm_simulator/qasm_measure.py index c7ddde73e7..c905512b65 100644 --- a/test/terra/backends/qasm_simulator/qasm_measure.py +++ b/test/terra/backends/qasm_simulator/qasm_measure.py @@ -166,19 +166,6 @@ def test_measure_nondeterministic_multi_qubit_without_sampling(self): self.assertIn("measure_sampling", res.metadata) self.assertEqual(res.metadata["measure_sampling"], False) - # --------------------------------------------------------------------- - # Test measure with noise model - # --------------------------------------------------------------------- - def sampling_enabled(self, result): - """Check sampling is enabled""" - for r in result.as_dict()['results']: - self.assertTrue('metadata' in r) - if 'measure' not in r['metadata']: - return False - if r['metadata']['measure'] != 'sampling': - return False - return True - def test_measure_sampling_with_readouterror(self): """Test QasmSimulator measure with deterministic counts with sampling and readout-error""" readout_error = [0.01, 0.1] @@ -197,7 +184,11 @@ def test_measure_sampling_with_readouterror(self): noise_model=noise_model, backend_options=self.BACKEND_OPTS).result() self.is_completed(result) - self.assertTrue(self.sampling_enabled(result)) + + # Test sampling was disabled + for res in result.results: + self.assertIn("measure_sampling", res.metadata) + self.assertEqual(res.metadata["measure_sampling"], True) def test_measure_sampling_with_quantum_noise(self): """Test QasmSimulator measure with deterministic counts with sampling and readout-error"""