From 19c5a91e257dae079ddcf451a5dd0c471002eabb Mon Sep 17 00:00:00 2001 From: Lou Bernabeu <lou.bernabeu@student-cs.fr> Date: Wed, 6 Jan 2021 00:22:54 +0100 Subject: [PATCH] fixed bugs, added .gigtignore --- .gitignore | 1 + __init__.py | 0 __main__.py | 4 ++++ elements/__init__.py | 2 ++ elements/main.py | 15 ++++++++++----- 5 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 __init__.py diff --git a/.gitignore b/.gitignore index e69de29..264daca 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1 @@ +*__pycache__ \ No newline at end of file diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/__main__.py b/__main__.py index e69de29..86d59a2 100644 --- a/__main__.py +++ b/__main__.py @@ -0,0 +1,4 @@ +import elements +import graphics + +print("Hi World!") diff --git a/elements/__init__.py b/elements/__init__.py index 9664db0..fa0c9bc 100644 --- a/elements/__init__.py +++ b/elements/__init__.py @@ -1,2 +1,4 @@ import numpy as np import cmath + +from .main import * diff --git a/elements/main.py b/elements/main.py index 03a9816..2026c2b 100644 --- a/elements/main.py +++ b/elements/main.py @@ -1,3 +1,5 @@ +import numpy as np + ### ------ Special elements ------ class Source: def __init__(self, initial_vector=np.array([1., 0.+0j])): ## if no input state given, starts a |0> @@ -13,11 +15,12 @@ class Screen: self.previous = previous def show(self): - previous_component, previous_component_output_side = previous + previous_component, previous_component_output_side = self.previous print(previous_component.out(previous_component_output_side)) def out(self): - return previous_component.out(previous_component_output_site) + previous_component, previous_component_output_side = self.previous + return previous_component.out(previous_component_output_side) @@ -28,19 +31,21 @@ class Element: self.next = None class Plate(Element): - def __init__(self, jones_matrix = np.eye((2, 2), dtype='complex')): + def __init__(self, previous, jones_matrix = np.eye(2, dtype='complex')): + Element.__init__(self, previous) self.jones_matrix = jones_matrix self.output_vector = None def out(self, side): previous_element = self.previous[0] previous_element_output_side = self.previous[1] - self.output_vector = self.jones_matrix @ previous_element(previous_element_output_side) # matrix-vector product : jones matrix times state vector given by the out(side) method of the previous component + self.output_vector = self.jones_matrix @ previous_element.out(previous_element_output_side) # matrix-vector product : jones matrix times state vector given by the out(side) method of the previous component return self.output_vector class BeamSplitter(Element): """matrix is a 4x4 complex ndarray, two first dimensions regard left input, two next are right. So it's blockwise defined.""" - def __init__(self, matrix = np.eye((4, 4), dtype='complex')): + def __init__(self, previous, matrix = np.eye(4, dtype='complex')): + Element.__init__(self, previous) self.matrix = matrix self.output_vector = None -- GitLab