wrong partial measurement

This commit is contained in:
Daniel Tsvetkov 2020-02-20 11:38:01 +01:00
parent 5a084aea55
commit b6f54b2db4

View File

@ -294,10 +294,11 @@ class State(Vector):
indexes_for_p_0 = [i for i, index in enumerate(partial_measurement_of_qbit) if index==0]
weights_0 = [self.get_prob(j) for j in indexes_for_p_0]
choices_0 = [format_str.format(i) for i in indexes_for_p_0]
measurement_result = random.choices(choices_0, weights_0)[0]
measurement_result = random.choices(choices_0, weights_0)[0][qubit_n-1]
# TODO: Verify if this is the correct collapse to lower dimension after partial measurement
# https://www.youtube.com/watch?v=MG_9JWsrKtM&list=PL1826E60FD05B44E4&index=16
normalization_factor = np.sqrt(np.sum([self.m[i][0] for i in indexes_for_p_0]))
# TODO: This can be 0...
self.m = [
[(self.m[i][0]**2)/normalization_factor] for i in indexes_for_p_0
]
@ -336,7 +337,7 @@ class State(Vector):
def test_measure_partial():
state = s("|000>")
state = s("|010>")
state.measure_partial(2)