empty set photon

This commit is contained in:
Daniel Tsvetkov 2020-03-26 18:16:46 +01:00
parent 26bc532a81
commit 708b159dfe
2 changed files with 13 additions and 3 deletions

View File

@ -11,6 +11,7 @@ from load_test import sizeof_fmt
ListOrNdarray = Union[list, np.ndarray] ListOrNdarray = Union[list, np.ndarray]
REPR_EMPTY_SET = "Ø"
REPR_TENSOR_OP = "" REPR_TENSOR_OP = ""
REPR_GREEK_BETA = "β" REPR_GREEK_BETA = "β"
REPR_GREEK_PSI = "ψ" REPR_GREEK_PSI = "ψ"
@ -263,8 +264,10 @@ class State(Vector):
if self.measurement_result: if self.measurement_result:
return self.measurement_result return self.measurement_result
weights = [self.get_prob(j) for j in range(len(self))] weights = [self.get_prob(j) for j in range(len(self))]
empty_prob = 1.0 - sum(weights)
format_str = self.get_fmt_of_element() 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] self.measurement_result = random.choices(choices, weights)[0]
return self.measurement_result return self.measurement_result
@ -609,6 +612,11 @@ class TwoQubitOperator(UnitaryOperator):
Define States and Operators Define States and Operators
""" """
# EMPTY STATE
_E = State([[0],
[0]],
name=REPR_EMPTY_SET)
_0 = State([[1], _0 = State([[1],
[0]], [0]],
name='0') name='0')
@ -706,6 +714,7 @@ CNOT = TwoQubitOperator([
[0, 0, 1, 0], [0, 0, 1, 0],
], C_partial, x_partial, I, X) ], C_partial, x_partial, I, X)
# TOFFOLLI_GATE = ThreeQubitOperator([ # TOFFOLLI_GATE = ThreeQubitOperator([
# [1, 0, 0, 0, 0, 0, 0, 0], # [1, 0, 0, 0, 0, 0, 0, 0],
# [0, 1, 0, 0, 0, 0, 0, 0], # [0, 1, 0, 0, 0, 0, 0, 0],

View File

@ -1,5 +1,5 @@
import numpy as np 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(): def main():
@ -8,6 +8,7 @@ def main():
hor_filter = MeasurementOperator.create_from_prob(Matrix(_0.m), name='h') hor_filter = MeasurementOperator.create_from_prob(Matrix(_0.m), name='h')
diag_filter = MeasurementOperator.create_from_prob(Matrix(_p.m), name='d') diag_filter = MeasurementOperator.create_from_prob(Matrix(_p.m), name='d')
ver_filter = MeasurementOperator.create_from_prob(Matrix(_1.m), name='v') 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(hor_filter.on(_0))
print(ver_filter.on(_0)) print(ver_filter.on(_0))
print(ver_filter.on(hor_filter.on(_0))) print(ver_filter.on(hor_filter.on(_0)))