-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests_experiments.py
More file actions
77 lines (76 loc) · 5.41 KB
/
tests_experiments.py
File metadata and controls
77 lines (76 loc) · 5.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import unittest
import math
from LibVectoresyMatricesComplejas import *
class TestMathMethods(unittest.TestCase):
global bol
bol=matriz([[ [0,0],[0,0],[0,0],[0,0],[0,0],[0,0] ],
[ [0,0],[0,0],[0,0],[1,0],[0,0],[0,0] ],
[ [0,0],[1,0],[0,0],[0,0],[0,0],[1,0] ],
[ [0,0],[0,0],[1,0],[0,0],[0,0],[0,0] ],
[ [0,0],[0,0],[0,0],[0,0],[1,0],[0,0] ],
[ [1,0],[0,0],[0,0],[0,0],[0,0],[0,0] ] ] )
def test01_simularCircuito(self):
x=matriz([ [[0,0],[1,0]],[[1,0],[0,0]] ])
m= matriz( [ [[1,0],[1,0]],[[1,0],[-1,0]] ])
c1=complejo(1/math.sqrt(2),0)
h=m.multiplicaEscalar(c1)
v0=matriz([ [[1,0]],[[0,0]] ] )
v1=matriz([ [[1,0]],[[0,0]] ])
v00=v0.productoTensor(v1)
m1=x.productoTensor(h)
m2=h.productoTensor(h)
self.assertTrue((m2).multiplica(m1).multiplica(v00)==matriz([ [[ 1/math.sqrt(2),0 ]],[[ 0,0 ]],[[-1/math.sqrt(2),0]],[[ 0,0]] ]))
def test01_cambiarEstado(self):
vector = matriz( [ [[0,0]],[[0,0]],[[0,0]],[[0,0]],[[0,0]],[[1,0]] ])
self.assertTrue(bol.state(vector,2019)==matriz([ [[ 0,0 ]],[[ 1,0 ]],[[0,0]],[[ 0,0]],[[0,0]],[[ 0,0]] ]))
def test02_cambiarEstado(self):
xi=matriz([ [[6,0]],[[0,0]],[[3,0]],[[5,0]],[[3,0]],[[8,0]] ])
self.assertTrue(bol.state(xi,5000)==matriz([ [[ 0,0 ]],[[ 3,0 ]],[[11,0]],[[ 8,0]],[[3,0]],[[ 0,0]] ]))
def test03_cambiarEstado(self):
xi=matriz([ [[6,0]],[[5,0]],[[4,0]],[[3,0]],[[2,0]],[[1,0]] ])
self.assertTrue(bol.state(xi,3000)==matriz([ [[ 0,0 ]],[[ 6,0 ]],[[4,0]],[[ 9,0]],[[2,0]],[[ 0,0]] ]))
def test01_combinarMatrices(self):
pos=matriz( [[ [0,0],[1/6,0],[5/6,0] ],
[ [1/3,0],[1/2,0],[1/6,0] ],
[ [2/3,0],[1/3,0],[0,0] ] ])
per=matriz([[ [1/3,0],[2/3,0] ],
[ [2/3,0],[1/3,0] ] ])
epos=matriz([ [[1,0]],[[0,0]],[[0,0]] ])
eper=matriz([ [[4/5,0]],[[1/5,0]]])
self.assertTrue(matriz.combinar(pos,per,epos,eper,0)==matriz([ [[ 0.8,0 ]],[[ 0.2,0 ]],[[0,0]],[[ 0,0]],[[0,0]],[[ 0,0]] ]))
def test01_experimentoProbabilistico_DobleRendija(self):
ways=matriz([ [ [0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0] ],
[ [1/2,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0] ],
[ [1/2,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0] ],
[ [0,0],[1/3,0],[0,0],[1,0],[0,0],[0,0],[0,0],[0,0] ],
[ [0,0],[1/3,0],[0,0],[0,0],[1,0],[0,0],[0,0],[0,0] ],
[ [0,0],[1/3,0],[1/3,0],[0,0],[0,0],[1,0],[0,0],[0,0] ],
[ [0,0],[0,0],[1/3,0],[0,0],[0,0],[0,0],[1,0],[0,0] ],
[ [0,0],[0,0],[1/3,0],[0,0],[0,0],[0,0],[0,0],[1,0] ]] )
x=matriz([ [[1,0]],[[0,0]],[[0,0]],[[0,0]],[[0,0]],[[0,0]],[[0,0]],[[0,0]] ])
ans=ways.state(x,2)
self.assertTrue(ans==matriz([ [[ 0,0 ]],[[ 0,0 ]],[[ 0,0 ]],[[1/6,0]],[[ 1/6,0]],[[ 1/3,0]],[[1/6,0]],[[ 1/6,0]] ]))
def test01_experimentoProbabilistico_DobleRendija_Fotones(self):
ways=matriz([ [ [0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0] ],
[ [1/math.sqrt(2),0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0] ],
[ [1/math.sqrt(2),0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0] ],
[ [0,0],[-math.sqrt(6)/6,math.sqrt(6)/6],[0,0],[1,0],[0,0],[0,0],[0,0],[0,0] ],
[ [0,0],[-math.sqrt(6)/6,-math.sqrt(6)/6],[0,0],[0,0],[1,0],[0,0],[0,0],[0,0] ],
[ [0,0],[math.sqrt(6)/6,-math.sqrt(6)/6],[-math.sqrt(6)/6,math.sqrt(6)/6],[0,0],[0,0],[1,0],[0,0],[0,0] ],
[ [0,0],[0,0],[-math.sqrt(6)/6,-math.sqrt(6)/6],[0,0],[0,0],[0,0],[1,0],[0,0] ],
[ [0,0],[0,0],[math.sqrt(6)/6,-math.sqrt(6)/6],[0,0],[0,0],[0,0],[0,0],[1,0] ]] )
ways=ways.potencia(2)
for i in range(len(ways.c)):
for j in range(len(ways.c[0])):
ways.c[i][j]=complejo(ways.c[i][j].modulo()*ways.c[i][j].modulo(),0)
esperado=matriz([ [ [0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0] ],
[ [0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0] ],
[ [0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0] ],
[ [1/6,0],[1/3,0],[0,0],[1,0],[0,0],[0,0],[0,0],[0,0] ],
[ [1/6,0],[1/3,0],[0,0],[0,0],[1,0],[0,0],[0,0],[0,0] ],
[ [0,0],[1/3,0],[1/3,0],[0,0],[0,0],[1,0],[0,0],[0,0] ],
[ [1/6,0],[0,0],[1/3,0],[0,0],[0,0],[0,0],[1,0],[0,0] ],
[ [1/6,0],[0,0],[1/3,0],[0,0],[0,0],[0,0],[0,0],[1,0] ]])
self.assertTrue(ways==esperado)
if __name__ == '__main__':
unittest.main()