Skip to content

Commit

Permalink
Adjust weight calculation in measurement
Browse files Browse the repository at this point in the history
Signed-off-by: Jonas Jelonek <[email protected]>
  • Loading branch information
jonasjelonek committed Oct 26, 2023
1 parent 1c87e9c commit d165828
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions qsfw/circuitry/quantum_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ def __do_measurement(self, qubit: int):
else:
zero_components[c_key] = val

weight_zero = abs(functools.reduce(lambda a,b: a + (np.power([b], [2]))[0], zero_components.values(), 0.0+0j))
weight_one = abs(functools.reduce(lambda a,b: a + (np.power([b], [2]))[0], one_components.values(), 0.0+0j))
pow_and_acc = lambda a,b: a + pow(b.real, 2) + pow(b.imag, 2)
weight_zero = abs(functools.reduce(pow_and_acc, zero_components.values(), 0.0))
weight_one = abs(functools.reduce(pow_and_acc, one_components.values(), 0.0))
if round(weight_one + weight_zero) != 1:
print("Houston, we have a problem!")
raise ValueError(f"0: {weight_zero} | 1: {weight_one} >> sum must be 1")
Expand Down

0 comments on commit d165828

Please sign in to comment.