diff --git a/CHANGELOG.md b/CHANGELOG.md index 058c1a6..a089397 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,11 +6,17 @@ `SimulatorDevice` class for general IonQ devices. [(#50)](https://github.com/PennyLaneAI/PennyLane-IonQ/pull/50) +### Bug Fixes + +* Since the histogram of probabilities returned from the remote simulator does not always sum exactly to one, + the PennyLane device normalizes them to higher precision. + [(#53)](https://github.com/PennyLaneAI/PennyLane-IonQ/pull/53) + ### Contributors This release contains contributions from (in alphabetical order): -Jon Donovan, Antal Száva +Jon Donovan, Christina Lee, Antal Száva --- diff --git a/pennylane_ionq/device.py b/pennylane_ionq/device.py index 1c4fd69..596edc0 100644 --- a/pennylane_ionq/device.py +++ b/pennylane_ionq/device.py @@ -129,7 +129,6 @@ def apply(self, operations, **kwargs): for operation in rotations: self._apply_operation(operation) - # print(self.job) self._submit_job() def _apply_operation(self, operation): @@ -194,7 +193,11 @@ def prob(self): # convert the sparse probs into a probability array self._prob_array = np.zeros([2**self.num_wires]) - self._prob_array[idx] = np.fromiter(self.histogram.values(), float) + + # histogram values don't always perfectly sum to exactly one + histogram_values = self.histogram.values() + norm = sum(histogram_values) + self._prob_array[idx] = np.fromiter(histogram_values, float) / norm return self._prob_array diff --git a/tests/conftest.py b/tests/conftest.py index 1ba979b..b9e7901 100755 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -79,7 +79,7 @@ def init_state(scope="session"): def _init_state(n): state = np.random.randint(0, 2, [n]) - ket = np.zeros([2 ** n]) + ket = np.zeros([2**n]) ket[np.ravel_multi_index(state, [2] * n)] = 1 return state, ket