Skip to content

Commit

Permalink
Merge pull request #528 from qiboteam/fixprobs
Browse files Browse the repository at this point in the history
Fix probabilities do not sum to 1
  • Loading branch information
scarrazza committed Dec 27, 2021
2 parents 20fb08d + 9c81b47 commit 5ebf0d1
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/qibo/backends/numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def cast(self, x, dtype='DTYPECPX'):
if isinstance(dtype, str):
dtype = self.dtypes(dtype)
if isinstance(x, self.backend.ndarray):
return x.astype(dtype)
return x.astype(dtype, copy=False)
return self.backend.array(x, dtype=dtype)

def diag(self, x, dtype='DTYPECPX'):
Expand Down
2 changes: 1 addition & 1 deletion src/qibo/core/states.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def probabilities(self, qubits=None, measurement_gate=None):
unmeasured_qubits = tuple(i for i in range(self.nqubits)
if i not in qubits)
state = K.reshape(K.square(K.abs(K.cast(self.tensor))), self.nqubits * (2,))
return K.sum(state, axis=unmeasured_qubits)
return K.sum(K.cast(state, dtype="float64"), axis=unmeasured_qubits)

def measure(self, gate, nshots, registers=None):
self.measurements = gate(self, nshots)
Expand Down

0 comments on commit 5ebf0d1

Please sign in to comment.