From 708b159dfe069e6556306a369e90622036420f78 Mon Sep 17 00:00:00 2001 From: Daniel Tsvetkov Date: Thu, 26 Mar 2020 18:16:46 +0100 Subject: [PATCH] empty set photon --- lib_q_computer_math.py | 13 +++++++++++-- play.py | 3 ++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib_q_computer_math.py b/lib_q_computer_math.py index 33c3052..19a41b8 100644 --- a/lib_q_computer_math.py +++ b/lib_q_computer_math.py @@ -11,6 +11,7 @@ from load_test import sizeof_fmt ListOrNdarray = Union[list, np.ndarray] +REPR_EMPTY_SET = "Ø" REPR_TENSOR_OP = "⊗" REPR_GREEK_BETA = "β" REPR_GREEK_PSI = "ψ" @@ -263,8 +264,10 @@ class State(Vector): if self.measurement_result: return self.measurement_result weights = [self.get_prob(j) for j in range(len(self))] + empty_prob = 1.0 - sum(weights) format_str = self.get_fmt_of_element() - choices = [format_str.format(i) for i in range(len(weights))] + choices = [REPR_EMPTY_SET] + [format_str.format(i) for i in range(len(weights))] + weights = [empty_prob] + weights self.measurement_result = random.choices(choices, weights)[0] return self.measurement_result @@ -298,7 +301,7 @@ class State(Vector): 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(np.abs([self.m[i][0] for i in indexes_for_p_0])**2)) + normalization_factor = np.sqrt(np.sum(np.abs([self.m[i][0] for i in indexes_for_p_0]) ** 2)) # TODO: This can be 0... post_measurement_state = [ [self.m[i][0] / normalization_factor] for i in indexes_for_p_0 @@ -609,6 +612,11 @@ class TwoQubitOperator(UnitaryOperator): Define States and Operators """ +# EMPTY STATE +_E = State([[0], + [0]], + name=REPR_EMPTY_SET) + _0 = State([[1], [0]], name='0') @@ -706,6 +714,7 @@ CNOT = TwoQubitOperator([ [0, 0, 1, 0], ], C_partial, x_partial, I, X) + # TOFFOLLI_GATE = ThreeQubitOperator([ # [1, 0, 0, 0, 0, 0, 0, 0], # [0, 1, 0, 0, 0, 0, 0, 0], diff --git a/play.py b/play.py index b443510..a3f5712 100644 --- a/play.py +++ b/play.py @@ -1,5 +1,5 @@ import numpy as np -from lib_q_computer_math import Vector, Matrix, MeasurementOperator, _0, _1, _p, normalize_state +from lib_q_computer_math import Vector, Matrix, MeasurementOperator, _0, _1, _p, normalize_state, State def main(): @@ -8,6 +8,7 @@ def main(): hor_filter = MeasurementOperator.create_from_prob(Matrix(_0.m), name='h') diag_filter = MeasurementOperator.create_from_prob(Matrix(_p.m), name='d') ver_filter = MeasurementOperator.create_from_prob(Matrix(_1.m), name='v') + State(hor_filter.on(random_light).m).measure() print(hor_filter.on(_0)) print(ver_filter.on(_0)) print(ver_filter.on(hor_filter.on(_0)))