-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.m
executable file
·96 lines (71 loc) · 2.83 KB
/
main.m
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
% Quantum Teleportation Algorhytm
% https://github.com/iiiicaro/quantum-teleportation
clear;
qlib; %Qlib dependecy
%%% Constants
Id = [1 0; 0 1];
ket0 = [1; 0];
ket1 = [0; 1];
CNOT = [1 0 0 0; 0 1 0 0; 0 0 0 1; 0 0 1 0];
Hadamard = (1/sqrt(2))*[1 1; 1 -1];
% Getting the QBit to teleport
qBitToTeleport = getQBitToTeleport();
qBitToTeleportDensityMatrix = qBitToTeleport * qBitToTeleport';
disp('Quantum bit to teleport');
disp(qBitToTeleportDensityMatrix);
% Time Operator
disp('Apply noise to the teleportation process?');
disp('[1] - No');
disp('[2] - Yes (Teleportation might not fully work. Fidelity to the expected result will be shown');
willApplyNoise = input('> ');
% Throws error if invalid option
if ((willApplyNoise ~= 1) && (willApplyNoise ~= 2))
error('Invalid option chosen');
end
% Get the noise matrices and time operator
if (willApplyNoise == 2)
gama = getNoiseIntensity();
time = getNoiseDuration();
timeOperator = exp(-gama*time);
[M1, M2] = getNoiseOperator(timeOperator);
end
% The channel and receiver share a maximum entangled state
maxEntangledState = (kron(ket0,ket0)+kron(ket1,ket1))/sqrt(2);
% Density Matrix of the system
system = kron(qBitToTeleport,maxEntangledState);
systemDensityMatrix = system *system';
% Applying noise
if (willApplyNoise == 2)
systemDensityMatrix = applyNoise(systemDensityMatrix, M1, M2);
end
% Applying CNOT Gate
CNOT = kron(CNOT, Id);
systemDensityMatrix = CNOT * systemDensityMatrix * CNOT';
% Applying noise
if (willApplyNoise == 2)
systemDensityMatrix = applyNoise(systemDensityMatrix, M1, M2);
end
H = kron(kron(Hadamard,Id),Id);
systemDensityMatrix = H * systemDensityMatrix * H';
% Applying noise
if (willApplyNoise == 2)
systemDensityMatrix = applyNoise(systemDensityMatrix, M1, M2);
end
% Measuring the first QBit
systemDensityMatrix = measureSingleQBit(systemDensityMatrix, [1 0 0]);
% Measuring the second QBit
systemDensityMatrix = measureSingleQBit(systemDensityMatrix, [0 1 0]);
qBitToTeleportAfterMeasurementDensityMatrix = partial_trace(systemDensityMatrix, [1 0 0]);
qBitToTeleportAfterMeasurement = dm2pure(qBitToTeleportAfterMeasurementDensityMatrix);
channelQBitAfterMeasurementDensityMatrix = partial_trace(systemDensityMatrix, [0 1 0]);
channelQBitAfterMeasurement = dm2pure(channelQBitAfterMeasurementDensityMatrix);
teleportedQBitDensityMatrix = partial_trace(systemDensityMatrix, [0 0 1]);
teleportedQBit = dm2pure(teleportedQBitDensityMatrix);
finalQBitDensityMatrix = operationAfterMeasure(qBitToTeleportAfterMeasurement, channelQBitAfterMeasurement, teleportedQBitDensityMatrix);
disp('Teleported quantum bit:');
disp(finalQBitDensityMatrix);
if (willApplyNoise == 2)
fidelity = trace(qBitToTeleportDensityMatrix * finalQBitDensityMatrix);
disp('Fidelity of the results over the expected (the closer to 1, the better):');
disp(fidelity);
end