Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Photonics tool
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bernabeu Lou
Photonics tool
Commits
1d536faa
Commit
1d536faa
authored
4 years ago
by
Lamy Raphael
Browse files
Options
Downloads
Patches
Plain Diff
Add new file
parent
1e896407
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
definition.py
+144
-0
144 additions, 0 deletions
definition.py
with
144 additions
and
0 deletions
definition.py
0 → 100644
+
144
−
0
View file @
1d536faa
from
__future__
import
(
absolute_import
,
division
,
print_function
,
unicode_literals
)
from
cmath
import
cos
,
sin
,
exp
,
polar
,
acos
from
math
import
pi
import
matplotlib
as
mpl
from
mpl_toolkits.mplot3d
import
Axes3D
import
numpy
as
np
import
matplotlib.pyplot
as
plt
from
matplotlib.backends.backend_tkagg
import
FigureCanvasTkAgg
mpl
.
rcParams
[
'
legend.fontsize
'
]
=
10
class
Plate
:
"""
type =
''
LR,
'
LP
'
,
'
CP
'
Fast axis unchanged convention (pour un LR)
orientation = Right, Left (pour un CP)
"""
def
__init__
(
self
,
element
,
theta
=
0
,
delta
=
0
,
orientation
=
""
):
self
.
element
=
element
self
.
delta
=
delta
self
.
theta
=
theta
self
.
orientation
=
orientation
def
coef
(
real
,
imag
):
a
=
0
if
real
!=
0
:
a
=
real
if
imag
!=
0
:
a
+=
imag
*
1j
return
(
a
)
class
Photon
:
def
__init__
(
self
,
state0
,
state1
):
self
.
state0
=
[
state0
]
self
.
state1
=
[
state1
]
def
state
(
self
):
print
(
self
.
state0
[
-
1
],
"
|0> +
"
,
self
.
state1
[
-
1
],
"
|1>
"
)
def
round_state
(
self
,
decimal
,
i
):
s_0r
=
round
((
self
.
state0
[
i
]).
real
,
decimal
)
s_0i
=
round
((
self
.
state0
[
i
]).
imag
,
decimal
)
s_1r
=
round
((
self
.
state1
[
i
]).
real
,
decimal
)
s_1i
=
round
((
self
.
state1
[
i
]).
imag
,
decimal
)
return
(
s_0r
,
s_0i
,
s_1r
,
s_1i
)
def
is_2D
(
self
,
i
):
s_0r
=
round
((
self
.
state0
[
i
]).
real
,
3
)
s_0i
=
round
((
self
.
state0
[
i
]).
imag
,
3
)
s_1r
=
round
((
self
.
state1
[
i
]).
real
,
3
)
s_1i
=
round
((
self
.
state1
[
i
]).
imag
,
3
)
return
(
s_0r
*
s_0i
==
0
and
s_1r
*
s_1i
==
0
and
s_0r
*
s_1i
==
0
and
s_1r
*
s_0i
==
0
)
def
pur
(
self
,
i
):
rho0
,
phi0
=
polar
(
self
.
state0
[
i
])
rho1
,
phi1
=
polar
(
self
.
state1
[
i
])
return
(
2
*
acos
(
rho0
),
phi1
-
phi0
)
def
gate
(
self
,
plate
):
alpha
=
self
.
state0
[
-
1
]
beta
=
self
.
state1
[
-
1
]
if
plate
.
element
==
'
LP
'
:
self
.
state0
.
append
(
alpha
*
cos
(
plate
.
theta
)
*
cos
(
plate
.
theta
)
+
beta
*
cos
(
plate
.
theta
)
*
sin
(
plate
.
theta
))
self
.
state1
.
append
(
alpha
*
cos
(
plate
.
theta
)
*
sin
(
plate
.
theta
)
+
beta
*
sin
(
plate
.
theta
)
*
sin
(
plate
.
theta
))
if
plate
.
element
==
'
LR
'
:
self
.
state0
.
append
(
alpha
*
(
cos
(
plate
.
theta
)
*
cos
(
plate
.
theta
)
+
exp
(
1j
*
plate
.
delta
)
*
sin
(
plate
.
theta
)
*
sin
(
plate
.
theta
))
+
beta
*
(
1
-
exp
(
1j
*
plate
.
delta
))
*
cos
(
plate
.
theta
)
*
sin
(
plate
.
theta
))
self
.
state1
.
append
(
alpha
*
(
1
-
exp
(
1j
*
plate
.
delta
))
*
cos
(
plate
.
theta
)
*
sin
(
plate
.
theta
)
+
beta
*
(
sin
(
plate
.
theta
)
*
sin
(
plate
.
theta
)
+
exp
(
1j
*
plate
.
delta
)
*
cos
(
plate
.
theta
)
*
cos
(
plate
.
theta
)))
else
:
if
plate
.
orientation
==
"
Right
"
:
self
.
state0
.
append
(
1
/
2
*
(
alpha
+
1j
*
beta
))
self
.
state1
.
append
(
1
/
2
*
(
beta
-
1j
*
alpha
))
else
:
self
.
state0
.
append
(
1
/
2
*
(
alpha
-
1j
*
beta
))
self
.
state1
.
append
(
1
/
2
*
(
beta
+
1j
*
alpha
))
def
representation
(
self
,
i
):
#Bloch Sphere
fig
=
plt
.
figure
()
ax
=
fig
.
gca
(
projection
=
'
3d
'
)
"""
thismanager = plt.get_current_fig_manager()
thismanager.window.SetPosition((500, 0))
thismanager.window.wm_geometry(
"
+500+0
"
)
"""
ax
.
set_title
(
'
Step
'
+
str
(
i
))
theta
=
np
.
linspace
(
0
,
2
*
np
.
pi
,
100
)
z
=
np
.
zeros
(
100
)
x
=
np
.
sin
(
theta
)
y
=
np
.
cos
(
theta
)
ax
.
plot
(
x
,
y
,
z
,
color
=
'
black
'
,
linestyle
=
'
dashed
'
,
linewidth
=
0.5
,
label
=
'
sphere
'
)
ax
.
plot
(
y
,
z
,
x
,
color
=
'
black
'
,
linestyle
=
'
dashed
'
,
linewidth
=
0.5
)
ax
.
plot
(
z
,
x
,
y
,
color
=
'
black
'
,
linestyle
=
'
dashed
'
,
linewidth
=
0.5
)
ax
.
quiver
(
0
,
0
,
0
,
0
,
0
,
1
,
color
=
'
black
'
,
arrow_length_ratio
=
0.1
)
ax
.
text
(
0
,
0
,
1.1
,
'
|0>
'
,
color
=
'
black
'
)
ax
.
quiver
(
0
,
0
,
0
,
0
,
0
,
-
1
,
color
=
'
black
'
,
arrow_length_ratio
=
0.1
)
ax
.
text
(
0
,
0
,
-
1.1
,
'
|1>
'
,
color
=
'
black
'
)
if
i
>
0
:
theta
,
phi
=
self
.
pur
(
i
-
1
)
ax
.
quiver
(
0
,
0
,
0
,
sin
(
theta
)
*
cos
(
phi
),
sin
(
theta
)
*
sin
(
phi
),
cos
(
theta
),
color
=
'
red
'
,
arrow_length_ratio
=
0.1
,
label
=
'
before
'
)
ax
.
text
(
sin
(
theta
)
*
cos
(
phi
)
+
0.1
,
sin
(
theta
)
*
sin
(
phi
)
+
0.1
,
cos
(
theta
)
+
0.1
,
'
before
'
,
color
=
'
red
'
)
theta
,
phi
=
self
.
pur
(
i
)
ax
.
quiver
(
0
,
0
,
0
,
sin
(
theta
)
*
cos
(
phi
),
sin
(
theta
)
*
sin
(
phi
),
cos
(
theta
),
color
=
'
green
'
,
arrow_length_ratio
=
0.1
,
label
=
'
after
'
)
ax
.
text
(
sin
(
theta
)
*
cos
(
phi
)
+
0.1
,
sin
(
theta
)
*
sin
(
phi
)
+
0.1
,
cos
(
theta
)
+
0.1
,
'
after
'
,
color
=
'
green
'
)
ax
.
grid
(
False
)
ax
.
axis
(
False
)
ax
.
legend
()
#2D representation
if
self
.
is_2D
(
i
):
fig2
=
plt
.
figure
()
ax_2D
=
fig2
.
add_subplot
(
111
)
theta
=
np
.
linspace
(
0
,
2
*
np
.
pi
,
100
)
x
=
np
.
sin
(
theta
)
y
=
np
.
cos
(
theta
)
ax_2D
.
plot
(
x
,
y
,
color
=
'
black
'
,
linestyle
=
'
dashed
'
,
linewidth
=
0.5
,
label
=
'
circle
'
)
ax_2D
.
quiver
(
*
[
0
,
0
],
[
0
,
1
],
[
1
,
0
],
scale
=
1
,
scale_units
=
'
xy
'
,
color
=
'
black
'
)
ax_2D
.
text
(
0
,
1.1
,
'
|0>
'
,
color
=
'
black
'
)
ax_2D
.
text
(
1.1
,
0
,
'
|1>
'
,
color
=
'
black
'
)
ax_2D
.
grid
(
False
)
ax_2D
.
axis
(
False
)
ax_2D
.
legend
()
(
s_0r
,
s_0i
,
s_1r
,
s_1i
)
=
self
.
round_state
(
3
,
i
)
if
(
s_0r
!=
0
or
s_1r
!=
0
):
ax_2D
.
quiver
(
*
[
0
,
0
],
[
s_1r
],
[
s_0r
],
scale
=
1
,
scale_units
=
'
xy
'
,
color
=
'
red
'
,
label
=
'
Phase nul
'
)
ax_2D
.
text
(
s_1r
+
0.1
,
s_0r
+
0.1
,
'
after
'
,
color
=
'
red
'
)
else
:
ax_2D
.
quiver
(
*
[
0
,
0
],
[
s_1i
],
[
s_0i
],
scale
=
1
,
scale_units
=
'
xy
'
,
color
=
'
red
'
,
label
=
'
Phase pi/2
'
)
ax_2D
.
text
(
s_1i
+
0.1
,
s_0i
+
0.1
,
'
after
'
,
color
=
'
red
'
)
if
i
>
0
:
if
self
.
is_2D
(
i
-
1
):
(
s_0r
,
s_0i
,
s_1r
,
s_1i
)
=
self
.
round_state
(
3
,
i
-
1
)
if
(
s_0r
!=
0
or
s_1r
!=
0
):
ax_2D
.
quiver
(
*
[
0
,
0
],
[
s_1r
],
[
s_0r
],
scale
=
1
,
scale_units
=
'
xy
'
,
color
=
'
green
'
,
label
=
'
Phase nul
'
)
ax_2D
.
text
(
s_1r
+
0.1
,
s_0r
+
0.1
,
'
before
'
,
color
=
'
green
'
)
else
:
ax_2D
.
quiver
(
*
[
0
,
0
],
[
s_1i
],
[
s_0i
],
scale
=
1
,
scale_units
=
'
xy
'
,
color
=
'
green
'
,
label
=
'
Phase pi/2
'
)
ax_2D
.
text
(
s_1i
+
0.1
,
s_0i
+
0.1
,
'
before
'
,
color
=
'
green
'
)
plt
.
show
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment