Skip to content

Commit

Permalink
fix BasicAer sampling bug (Qiskit#1624)
Browse files Browse the repository at this point in the history
* fix BasicAer sampling bug

* changelog

* remove legacysimulator from test_compile
  • Loading branch information
ajavadia authored and jaygambetta committed Dec 29, 2018
1 parent 3a4495c commit 5f7b2e7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ Changed
- The snapshot instruction now takes ``label`` and ``snap_type`` instead of
``slot`` (#1615).

Fixed
-----

- Fixed a bug with measurement sampling optimization in BasicAer
qasm_simulator (#1624).

Removed
-------

Expand Down
4 changes: 2 additions & 2 deletions qiskit/providers/builtinsimulators/qasm_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ def _add_sample_measure(self, measure_params, num_samples):
memory = []
for sample in samples:
classical_state = self._classical_state
for qubit, cbit in measure_params:
qubit_outcome = int((sample & (1 << qubit)) >> qubit)
for count, (qubit, cbit) in enumerate(sorted(measure_params)):
qubit_outcome = int((sample & (1 << count)) >> count)
bit = 1 << cbit
classical_state = (classical_state & (~bit)) | (qubit_outcome << cbit)
value = bin(classical_state)[2:]
Expand Down
5 changes: 2 additions & 3 deletions test/python/tools/test_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from qiskit.providers.ibmq import least_busy
from .._mockutils import FakeBackend
from ..common import QiskitTestCase
from ..common import requires_qe_access, requires_cpp_simulator
from ..common import requires_qe_access


class TestCompiler(QiskitTestCase):
Expand Down Expand Up @@ -472,13 +472,12 @@ def test_compile_coupling_map(self):
threshold = 0.05 * shots
self.assertDictAlmostEqual(counts, target, threshold)

@requires_cpp_simulator
def test_example_swap_bits(self):
"""Test a toy example swapping a set bit around.
Uses the mapper. Pass if results are correct.
"""
backend = qiskit.Aer.get_backend('qasm_simulator')
backend = qiskit.BasicAer.get_backend('qasm_simulator')
coupling_map = [[0, 1], [0, 8], [1, 2], [1, 9], [2, 3], [2, 10],
[3, 4], [3, 11], [4, 5], [4, 12], [5, 6], [5, 13],
[6, 7], [6, 14], [7, 15], [8, 9], [9, 10], [10, 11],
Expand Down

0 comments on commit 5f7b2e7

Please sign in to comment.