Skip to content

Commit

Permalink
resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
hhorii committed Aug 1, 2019
1 parent da06d65 commit 552c297
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 40 deletions.
30 changes: 4 additions & 26 deletions src/simulators/qasm/qasm_controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -710,14 +705,9 @@ void QasmController::run_circuit_without_noise(const Circuit &circ,
// Get measurement operations and set of measured qubits
ops = std::vector<Operations::Op>(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
}
}

Expand All @@ -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 ||
Expand All @@ -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;
Expand Down
19 changes: 5 additions & 14 deletions test/terra/backends/qasm_simulator/qasm_measure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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"""
Expand Down

0 comments on commit 552c297

Please sign in to comment.