Skip to content
Permalink
Browse files

a lot of shit

  • Loading branch information...
petr.ryabinin
petr.ryabinin committed Apr 1, 2018
1 parent 060b375 commit 4d614e344e1cada6a43c18d8df3117b28f113385
Showing with 434 additions and 47 deletions.
  1. +35 −11 core/projection.py
  2. +0 −1 core/state_configurations.py
  3. +63 −24 customutils/utils.py
  4. +17 −8 main.py
  5. BIN results/coher-coher/area2_state_abs.png
  6. BIN results/coher-coher/area2_state_imag.png
  7. BIN results/coher-coher/area2_state_real.png
  8. BIN results/coher-coher/auxiliary_state.png
  9. BIN results/coher-coher/input_state.png
  10. BIN results/coher-coher/out_abs.png
  11. BIN results/coher-coher/out_imag.png
  12. BIN results/coher-coher/out_real.png
  13. BIN results/coher1-coher1/1st_detector/output_abs.png
  14. BIN results/coher1-coher1/1st_detector/output_imag.png
  15. BIN results/coher1-coher1/1st_detector/output_real.png
  16. BIN results/coher1-coher1/auxiliary_state.png
  17. BIN results/coher1-coher1/both_detectors/output_abs.png
  18. BIN results/coher1-coher1/both_detectors/output_imag.png
  19. BIN results/coher1-coher1/both_detectors/output_real.png
  20. BIN results/coher1-coher1/init_state_real.png
  21. BIN results/coher1-coher1/input_state.png
  22. BIN results/coher1-coher1/state2_abs.png
  23. BIN results/coher1-coher1/state2_imag.png
  24. BIN results/coher1-coher1/state2_real.png
  25. +1 −0 results/formulas.aux
  26. +210 −0 results/formulas.log
  27. BIN results/formulas.pdf
  28. BIN results/formulas.synctex.gz
  29. +105 −0 results/formulas.tex
  30. BIN results/in-coher1_aux-single/1st_det/output_abs.png
  31. BIN results/in-coher1_aux-single/1st_det/output_imag.png
  32. BIN results/in-coher1_aux-single/1st_det/output_real.png
  33. BIN results/{in-coher_aux-single → in-coher1_aux-single}/auxiliary_state.png
  34. BIN results/in-coher1_aux-single/both_det/output_abs.png
  35. BIN results/in-coher1_aux-single/both_det/output_imag.png
  36. BIN results/in-coher1_aux-single/both_det/output_real.png
  37. BIN results/in-coher1_aux-single/init_state_real.png
  38. BIN results/in-coher1_aux-single/input_state.png
  39. BIN results/in-coher1_aux-single/state2_abs.png
  40. BIN results/in-coher1_aux-single/state2_imag.png
  41. BIN results/in-coher1_aux-single/state2_real.png
  42. BIN results/in-coher_aux-single/area2_state_abs.png
  43. BIN results/in-coher_aux-single/area2_state_imag.png
  44. BIN results/in-coher_aux-single/area2_state_real.png
  45. BIN results/in-coher_aux-single/input_state.png
  46. BIN results/in-coher_aux-single/out_abs.png
  47. BIN results/in-coher_aux-single/out_imag.png
  48. BIN results/in-coher_aux-single/out_real.png
  49. BIN results/in-single_aux-coher/area2_state_abs.png
  50. BIN results/in-single_aux-coher/area2_state_imag.png
  51. BIN results/in-single_aux-coher/area2_state_real.png
  52. BIN results/in-single_aux-coher/auxiliary_state.png
  53. BIN results/in-single_aux-coher/out_abs.png
  54. BIN results/in-single_aux-coher/out_imag.png
  55. BIN results/in-single_aux-coher/out_real.png
  56. BIN results/in-single_aux-coher1/1st_det/output_abs.png
  57. BIN results/in-single_aux-coher1/1st_det/output_imag.png
  58. BIN results/in-single_aux-coher1/1st_det/output_real.png
  59. BIN results/in-single_aux-coher1/auxiliary_state.png
  60. BIN results/in-single_aux-coher1/both_det/output_abs.png
  61. BIN results/in-single_aux-coher1/both_det/output_imag.png
  62. BIN results/in-single_aux-coher1/both_det/output_real.png
  63. BIN results/in-single_aux-coher1/init_state_real.png
  64. BIN results/{in-single_aux-coher → in-single_aux-coher1}/input_state.png
  65. BIN results/in-single_aux-coher1/state2_abs.png
  66. BIN results/in-single_aux-coher1/state2_imag.png
  67. BIN results/in-single_aux-coher1/state2_real.png
  68. BIN results/res2.odp
  69. +3 −3 setup_parameters.py
@@ -4,20 +4,23 @@


def measure_state(state_before, clicked):
# Both detectors was clicked
if clicked is 'BOTH':
b1, b2, b3, b4 = sp.symbols('b1 b2 b3 b4')
state_after_pre = 0

# iterate over all sum members
for arg in state_before.args:
if b1 in arg.free_symbols:
# finding power of b1
if not arg.is_Mul and not arg.is_complex:
print('Det. Type is neither mul nor complex. Type : ', type(arg), arg)
# Condition for both detectors being clicked
if b1 in arg.free_symbols and b3 in arg.free_symbols:
# Finding power of b1
for item in arg.args:
if item == b1:
b1_power = 1
elif item.is_Pow and b1 in item.free_symbols:
b1_power = item.args[1]
# finding power of b3
# Finding power of b3
b3_power = 0
if b3 in arg.free_symbols:
for item in arg.args:
@@ -28,14 +31,35 @@ def measure_state(state_before, clicked):
state_after_pre = state_after_pre + arg * sqrt(factorial(b1_power)) * sqrt(factorial(b3_power)) / (
b1 ** b1_power * b3 ** b3_power)

state_after = 0
# filter constants ??? TODO
for arg in state_after_pre.args:
if b2 in list(arg.free_symbols) or b4 in list(arg.free_symbols):
state_after = state_after + arg
state_after = state_after_pre
# state_after = 0
# Filtering elements from other channels (1st and 3rd).
# for arg in state_after_pre.args:
# if b2 in list(arg.free_symbols) or b4 in list(arg.free_symbols):
# state_after = state_after + arg
return state_after
# TODO
# Only first detector was clicked
if clicked is 'FIRST':
return
b1, b2, b3, b4 = sp.symbols('b1 b2 b3 b4')
state_after_pre = 0
for arg in state_before.args:
if not arg.is_Mul and not arg.is_complex:
print('Det. Type is neither mul nor complex. Type : ', type(arg), arg)
# Condition for only first detector being clicked
if b1 in arg.free_symbols and b3 not in arg.free_symbols:
# Finding power of b1
for item in arg.args:
if item == b1:
b1_power = 1
elif item.is_Pow and b1 in item.free_symbols:
b1_power = item.args[1]
state_after_pre = state_after_pre + arg * sqrt(factorial(b1_power)) / b1 ** b1_power
state_after = state_after_pre
# state_after = 0
# Filtering elements from other channels (1st and 3rd).
# for arg in state_after_pre.args:
# if b2 in list(arg.free_symbols) or b4 in list(arg.free_symbols):
# state_after = state_after + arg
return state_after
else:
raise ValueError('Wrong configuration')
@@ -2,7 +2,6 @@
import numpy as np
from math import factorial, exp


DEF_SERIES_LEN = 100


@@ -1,29 +1,60 @@
import matplotlib.pyplot as plt
import numpy as np
import sympy as sp
from math import factorial


# Works only for a state in two channels.
def get_state_coeffs(state, max_power):
a1, a2 = sp.symbols('a1 a2')
state_coeffs = np.zeros((max_power, max_power), dtype=complex)
for arg in state.args:
# Cases of only one element in the series
if state.is_Symbol:
if state is a1:
state_coeffs[1, 0] = 1
if state is a2:
state_coeffs[0, 1] = 1
elif state.is_Pow:
if a1 in state.free_symbols:
state_coeffs[state.args[1], 0] = 1
if a2 in state.free_symbols:
state_coeffs[0, state.args[1]] = 1
elif state.is_Mul:
pows = [0] * 2
for x in list(arg.args):
if a1 in x.free_symbols:
if x == a1:
pows[0] = 1
else:
pows[0] = x.args[1]
if a2 in x.free_symbols:
if x == a2:
pows[1] = 1
else:
pows[1] = x.args[1]

if pows[0] + pows[1] > 0:
state_coeffs[pows[0], pows[1]] = state_coeffs[pows[0], pows[1]] + complex(sp.Poly(arg, domain='CC').coeffs()[0])
else:
state_coeffs[0, 0] = arg
for arg in list(state.args):
if arg is a1:
pows[0] = 1
elif a1 in arg.free_symbols:
pows[0] = arg.args[1]
if arg is a2:
pows[1] = 1
elif a2 in arg.free_symbols:
pows[1] = arg.args[1]
state_coeffs[pows[0], pows[1]] = complex(list(state.args)[0])
# Several elements in the sum
elif state.is_Add:
for arg in state.args:
if arg.is_complex:
state_coeffs[0, 0] = state_coeffs[0, 0] + complex(arg)
if not arg.is_Mul and not arg.is_complex:
print('Coeffs. Type is neither mul nor complex. Type: ', type(arg), arg)
pows = [0] * 2
for x in list(arg.args):
if a1 in x.free_symbols:
if x == a1:
pows[0] = 1
else:
pows[0] = x.args[1]
if a2 in x.free_symbols:
if x == a2:
pows[1] = 1
else:
pows[1] = x.args[1]

if pows[0] + pows[1] > 0:
state_coeffs[pows[0], pows[1]] = state_coeffs[pows[0], pows[1]] + complex(sp.Poly(arg, domain='CC').coeffs()[0])
else:
raise ValueError('Incorrect state type!')

return state_coeffs

@@ -32,31 +63,39 @@ def plot_state(state_coeffs, name, size=8, value='abs'):
if value is 'abs':
plt.matshow(np.abs(state_coeffs)[0:size, 0:size])
plt.title(name + ', Abs value')
plt.xlabel('a2')
plt.ylabel('a1')
plt.xlabel('a2 degree')
plt.ylabel('a1 degree')
plt.colorbar()
plt.show()
return
if value is 'real':
plt.matshow(np.real(state_coeffs)[0:size, 0:size])
plt.title(name + ', Real value')
plt.xlabel('a2')
plt.ylabel('a1')
plt.xlabel('a2 degree')
plt.ylabel('a1 degree')
plt.colorbar()
plt.show()
return
if value is 'imag':
plt.matshow(np.imag(state_coeffs)[0:size, 0:size])
plt.title(name + ', Imag value')
plt.xlabel('a2')
plt.ylabel('a1')
plt.xlabel('a2 degree')
plt.ylabel('a1 degree')
plt.colorbar()
plt.show()
return
else:
raise ValueError('Wrong configuration')


# TODO
# For input and auxiliary states
def get_state_norm(state):
norm = 0
for i in range(len(state)):
norm = norm + state[i] * np.conj(state[i]) * factorial(i)
return norm


# TODO get norm from state in 2 channels
def get_norm():
pass
25 main.py
@@ -7,20 +7,26 @@


# Parameters for states
input_series_length = 9
auxiliary_series_length = 9
input_series_length = 10
auxiliary_series_length = 10
max_power = input_series_length + auxiliary_series_length

# Set up input and auxiliary states as a Taylor series
# input_st[n] = state with 'n' photons !!!

# INPUT
# input_st = single_photon(2)
input_st = coherent_state(input_series_length, alpha=1)
input_st = single_photon(2)
# input_st = coherent_state(input_series_length, alpha=1)
print('Input state norm:', get_state_norm(input_st))

# AUXILIARY
# auxiliary_st = single_photon(2)
auxiliary_st = coherent_state(auxiliary_series_length, alpha=1)
print('Auxiliary state norm:', get_state_norm(auxiliary_st))

# Measurement detectors configuration
DET_CONF = 'BOTH' # both 1st and 3rd detectors clicked
# DET_CONF = 'FIRST' # 1st detector clicked


# Setting up state before first BS.
@@ -37,7 +43,7 @@

state1_coeffs = get_state_coeffs(sp.expand(state1), max_power + 1)

plot_state(state1_coeffs, 'Initial State', size=8, value='abs')
plot_state(state1_coeffs, 'Initial State', size=8, value='real')

# State after mixing at first BS
state2 = state1
@@ -57,9 +63,9 @@
# Plot state2
state2_coeffs = get_state_coeffs(state2, max_power + 1)

plot_state(state2_coeffs, 'State2', size=8, value='abs')
plot_state(state2_coeffs, 'State2', size=8, value='real')
plot_state(state2_coeffs, 'State2', size=8, value='imag')
# plot_state(state2_coeffs, 'State2', size=8, value='abs')
# plot_state(state2_coeffs, 'State2', size=8, value='real')
# plot_state(state2_coeffs, 'State2', size=8, value='imag')

# 'state2' is a state after BS

@@ -107,6 +113,7 @@
plot_state(state5_coeffs, 'Final State', size=8, value='real')
plot_state(state5_coeffs, 'Final State', size=8, value='imag')

'''
# plot input states
plt.bar(list(range(len(input_st))), input_st, width=1, edgecolor='c')
@@ -121,4 +128,6 @@
plt.xlabel('Number of photons')
plt.show()
'''

# save setup configuration in file TODO
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1 @@
\relax
Oops, something went wrong.

0 comments on commit 4d614e3

Please sign in to comment.
You can’t perform that action at this time.