Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Normalize probabilities #53

Merged
merged 5 commits into from
Apr 21, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
`SimulatorDevice` class for general IonQ devices.
[(#50)](https://github.com/PennyLaneAI/PennyLane-IonQ/pull/50)

### Bug Fixes

* Since the probabilities returned don't always perfectly sum to one, they are now normalized.
albi3ro marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What probabilities are referred to here? Maybe good to rephrase from the user's point of view.

albi3ro marked this conversation as resolved.
Show resolved Hide resolved

### Contributors

This release contains contributions from (in alphabetical order):

Jon Donovan, Antal Száva
Jon Donovan, Christina Lee, Antal Száva

---

Expand Down
7 changes: 5 additions & 2 deletions pennylane_ionq/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down