diff --git a/.gitignore b/.gitignore index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..264dacab5a7aa25c1c26c6c3b20d48d637fe4b49 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 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/__main__.py b/__main__.py index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..86d59a274a0b8d734ecb3c3f16b446e8ec19ce63 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 9664db059251e7c9e9a2e29007f3fe619d4c6b51..fa0c9bc11702417e6c46868e3bbf31e908fdb3b8 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 03a98168c6b2b9634757a19428a1681b28ec55f4..2026c2b4875b5ed75f202040b8b47496a1af75bd 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