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]
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],

View File

@ -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)))