From b6f54b2db48014b5d05f5a6ee1be95a65cc8697a Mon Sep 17 00:00:00 2001 From: Daniel Tsvetkov Date: Thu, 20 Feb 2020 11:38:01 +0100 Subject: [PATCH] wrong partial measurement --- lib_q_computer_math.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib_q_computer_math.py b/lib_q_computer_math.py index 2f3826e..6e31508 100644 --- a/lib_q_computer_math.py +++ b/lib_q_computer_math.py @@ -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)