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
c8fabfc0
Commit
c8fabfc0
authored
4 years ago
by
Bernabeu Lou
Browse files
Options
Downloads
Patches
Plain Diff
Updated tests and made Screen printing prettier
parent
3dfcd532
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
__main__.py
+11
-18
11 additions, 18 deletions
__main__.py
elements.py
+5
-2
5 additions, 2 deletions
elements.py
matrices.py
+1
-1
1 addition, 1 deletion
matrices.py
with
17 additions
and
21 deletions
__main__.py
+
11
−
18
View file @
c8fabfc0
...
@@ -3,34 +3,27 @@ import matplotlib as mpl
...
@@ -3,34 +3,27 @@ import matplotlib as mpl
import
matplotlib.pyplot
as
plt
import
matplotlib.pyplot
as
plt
import
elements
import
elements
import
graphics
import
graphics
import
matrices
print
(
"
Hi World!
"
)
print
(
"
Hi World!
"
)
## Tests
## Tests
H
=
(
1
/
np
.
sqrt
(
2
))
*
np
.
array
([[
1
,
1
],[
1
,
-
1
]],
dtype
=
'
complex
'
)
H_rev
=
(
1
/
np
.
sqrt
(
2
))
*
np
.
array
([[
-
1
,
1
],[
1
,
1
]],
dtype
=
'
complex
'
)
A
=
np
.
kron
(
H_rev
,
np
.
eye
(
2
,
dtype
=
'
complex
'
))
# first beam splitter matrix
B
=
np
.
kron
(
H
,
np
.
eye
(
2
,
dtype
=
'
complex
'
))
# second beam splitter matrix
X
=
np
.
array
([[
0
,
1
],
[
1
,
0
]],
dtype
=
'
complex
'
)
Z
=
np
.
array
([[
1
,
0
],
[
0
,
-
1
]],
dtype
=
'
complex
'
)
source
=
elements
.
Source
(
initial_vector
=
np
.
array
([
1.
+
0j
,
0.
]))
source
=
elements
.
Source
(
initial_vector
=
np
.
array
([
1.
+
0j
,
0.
]))
BS1
=
elements
.
BeamSplitter
(
previous
=
{
"
left
"
:
(
source
,
"
left
"
),
"
right
"
:
None
},
matrix
=
A
)
BS1
=
elements
.
BeamSplitter
(
previous
=
{
"
left
"
:
(
source
,
"
left
"
),
"
right
"
:
None
},
matrix
=
matrices
.
HALF_MIRROR_LEFT_ACTIVE
)
X_left_1
=
elements
.
Plate
(
previous
=
(
BS1
,
"
left
"
),
jones_matrix
=
X
)
X_left_1
=
elements
.
Plate
(
previous
=
(
BS1
,
"
left
"
),
jones_matrix
=
matrices
.
X
)
Z_left_2
=
elements
.
Plate
(
previous
=
(
X_left_1
,
"
left
"
),
jones_matrix
=
Z
)
Z_left_2
=
elements
.
Plate
(
previous
=
(
X_left_1
,
"
left
"
),
jones_matrix
=
matrices
.
Z
)
Z_right_1
=
elements
.
Plate
(
previous
=
(
BS1
,
"
right
"
),
jones_matrix
=
Z
)
Z_right_1
=
elements
.
Plate
(
previous
=
(
BS1
,
"
right
"
),
jones_matrix
=
matrices
.
Z
)
X_right_2
=
elements
.
Plate
(
previous
=
(
Z_right_1
,
"
left
"
),
jones_matrix
=
X
)
X_right_2
=
elements
.
Plate
(
previous
=
(
Z_right_1
,
"
left
"
),
jones_matrix
=
matrices
.
X
)
BS2
=
elements
.
BeamSplitter
(
previous
=
{
"
left
"
:
(
Z_left_2
,
"
left
"
),
"
right
"
:
(
X_right_2
,
"
left
"
)},
matrix
=
B
)
BS2
=
elements
.
BeamSplitter
(
previous
=
{
"
left
"
:
(
Z_left_2
,
"
left
"
),
"
right
"
:
(
X_right_2
,
"
left
"
)},
matrix
=
matrices
.
HALF_MIRROR_RIGHT_ACTIVE
)
screen
=
elements
.
Screen
(
previous
=
(
BS2
,
"
left
"
))
screen_right
=
elements
.
Screen
(
previous
=
(
BS2
,
"
right
"
))
screen_left
=
elements
.
Screen
(
previous
=
(
BS2
,
"
left
"
))
print
(
screen
.
out
())
screen_right
.
show
(
"
right
"
)
screen_left
.
show
(
"
left
"
)
This diff is collapsed.
Click to expand it.
elements.py
+
5
−
2
View file @
c8fabfc0
...
@@ -14,9 +14,12 @@ class Screen:
...
@@ -14,9 +14,12 @@ class Screen:
def
__init__
(
self
,
previous
=
(
None
,
None
)):
def
__init__
(
self
,
previous
=
(
None
,
None
)):
self
.
previous
=
previous
self
.
previous
=
previous
def
show
(
self
):
def
show
(
self
,
name
=
'
ψ
'
):
previous_component
,
previous_component_output_side
=
self
.
previous
previous_component
,
previous_component_output_side
=
self
.
previous
print
(
previous_component
.
out
(
previous_component_output_side
))
ket
=
previous_component
.
out
(
previous_component_output_side
)
alpha
=
round
(
ket
[
0
])
beta
=
round
(
ket
[
1
])
print
(
f
"
|
{
name
}
⟩ =
{
alpha
}
|0⟩ +
{
beta
}
|1⟩
"
)
def
out
(
self
):
def
out
(
self
):
previous_component
,
previous_component_output_side
=
self
.
previous
previous_component
,
previous_component_output_side
=
self
.
previous
...
...
This diff is collapsed.
Click to expand it.
matrices.py
+
1
−
1
View file @
c8fabfc0
...
@@ -67,7 +67,7 @@ HALF_MIRROR_LEFT_ACTIVE = (1/np.sqrt(2))*np.array([[-1, 0, 1, 0],
...
@@ -67,7 +67,7 @@ HALF_MIRROR_LEFT_ACTIVE = (1/np.sqrt(2))*np.array([[-1, 0, 1, 0],
[
1
,
0
,
1
,
0
],
[
1
,
0
,
1
,
0
],
[
0
,
1
,
0
,
-
1
]],
dtype
=
'
complex
'
)
[
0
,
1
,
0
,
-
1
]],
dtype
=
'
complex
'
)
HALF_MIRROR_
LEF
T_ACTIVE
=
(
1
/
np
.
sqrt
(
2
))
*
np
.
array
([[
1
,
0
,
1
,
0
],
HALF_MIRROR_
RIGH
T_ACTIVE
=
(
1
/
np
.
sqrt
(
2
))
*
np
.
array
([[
1
,
0
,
1
,
0
],
[
0
,
-
1
,
0
,
1
],
[
0
,
-
1
,
0
,
1
],
[
1
,
0
,
-
1
,
0
],
[
1
,
0
,
-
1
,
0
],
[
0
,
1
,
0
,
1
]],
dtype
=
'
complex
'
)
[
0
,
1
,
0
,
1
]],
dtype
=
'
complex
'
)
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