empty set photon
This commit is contained in:
parent
26bc532a81
commit
708b159dfe
@ -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
|
||||
|
||||
@ -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],
|
||||
|
3
play.py
3
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)))
|
||||
|
Loading…
Reference in New Issue
Block a user