Skip to content

Commit

Permalink
Added tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonSekavcnik committed Dec 18, 2023
1 parent 692b75d commit ce0e4a7
Show file tree
Hide file tree
Showing 9 changed files with 190 additions and 47 deletions.
29 changes: 25 additions & 4 deletions quasi/devices/beam_splitters/ideal_beam_splitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
ensure_output_compute)
from quasi.devices.port import Port
from quasi.signals import (GenericSignal,
QuantumContentType,
GenericQuantumSignal)

from quasi.gui.icons import icon_list
from quasi.simulation import ModeManager


class IdealBeamSplitter(GenericDevice):
Expand All @@ -18,11 +20,11 @@ class IdealBeamSplitter(GenericDevice):
"""
ports = {
"A": Port(label="A", direction="input", signal=None,
signal_type=GenericSignal, device=None),
signal_type=GenericQuantumSignal, device=None),
"B": Port(label="B", direction="output", signal=None,
signal_type=GenericQuantumSignal, device=None),
"C": Port(label="C", direction="input", signal=None,
signal_type=GenericSignal, device=None),
signal_type=GenericQuantumSignal, device=None),
"D": Port(label="D", direction="output", signal=None,
signal_type=GenericQuantumSignal, device=None),
}
Expand All @@ -32,6 +34,25 @@ class IdealBeamSplitter(GenericDevice):
gui_tags = ["ideal"]
gui_name = "Ideal Beam Splitter"

power_average = 0
power_peak = 0
reference = None

@wait_input_compute
def compute_outputs(self):
print("TEST")
def compute_outputs(self, *args, **kwargs):
mm = ModeManager()

m_id_a = self.ports["A"].signal.mode_id
m_id_b = self.ports["B"].signal.mode_id

self.ports["C"].signal.set_contents(
content_type=QuantumContentType.FOCK,
mode_id=m_id_a)

self.ports["D"].signal.set_contents(
content_type=QuantumContentType.FOCK,
mode_id=m_id_b)
print(mm.modes.keys())

self.ports["C"].signal.set_computed()
self.ports["D"].signal.set_computed()
4 changes: 2 additions & 2 deletions quasi/devices/sources/ideal_coherent_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ def compute_outputs(self, *args, **kwargs):
density_matrix = np.zeros((
mm.simulation.dimensions,
mm.simulation.dimensions), dtype=np.complex128)
alpha = 1
alpha = 10

for m in range(mm.simulation.dimensions):
for n in range(mm.simulation.dimensions):
density_matrix[m, n] = ((alpha**m * np.conj(alpha)**n) /
np.sqrt(factorial(m) * factorial(n)))
np.sqrt(factorial(m) * factorial(n)))

density_matrix /= np.pi

Expand Down
4 changes: 3 additions & 1 deletion quasi/devices/sources/ideal_single_photon_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ def compute_outputs(self, *args, **kwargs):
AD = adagger(mm.simulation.dimensions)
A = a(mm.simulation.dimensions)
mode = mm.get_mode(m_id)
mm.modes[m_id] = np.matmul(AD, np.matmul(mode, A))

mode=np.matmul(AD, np.matmul(mode, A))
mm.modes[m_id]=np.matmul(AD, np.matmul(mode, A))
self.ports["output"].signal.set_contents(
content_type=QuantumContentType.FOCK,
mode_id=m_id)
Expand Down
40 changes: 36 additions & 4 deletions quasi/gui/bar/simulation_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from quasi.gui.icons import icon_list
from quasi.gui.simulation.simulation_wrapper import SimulationWrapper
from quasi.simulation import Simulation


class SimulationBar(ft.UserControl):
Expand All @@ -23,24 +24,55 @@ def __init__(self) -> None:
on_click=self.on_click_simulate
)

self.dimensions = ft.Container(
height=25,
width=100,
content=ft.Row(
controls=[
ft.Icon(
name=ft.icons.ALL_OUT,
color="white"),
ft.TextField(
multiline=False,
width=40,
filled=False,
disabled=False,
value=str(Simulation.dimensions),
content_padding=0,
bgcolor="#2b223b",
color="white",
border=ft.InputBorder.NONE,
input_filter=ft.NumbersOnlyInputFilter(),
dense=True,
on_change=self.on_dimensions_change
),
]
)
)


self.bar = ft.Container(
bgcolor="#2b223b",
top=25,
top=0,
left=0,
right=0,
height=25,
content=ft.Row(
[
ft.Container(width=2),
self.simulate_button
]
self.simulate_button,
self.dimensions,
],
vertical_alignment=ft.MainAxisAlignment.CENTER)
)
)

def build(self) -> ft.Dropdown:
return self.bar

def on_click_simulate(self, e) -> None:
self.sim_warpper.execute()


def on_dimensions_change(self, e):
print("changing dimensions")
Simulation.set_dimensions(int(e.control.value))
4 changes: 2 additions & 2 deletions quasi/gui/board/board.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def __init__(self, page: ft.Page):
self.content,
])
self.board_wrapper = ft.Container(
top=50,
top=0,
left=0,
right=0,
bottom=0,
Expand Down Expand Up @@ -105,7 +105,7 @@ def drag_accept(self, e: ft.DragUpdateEvent):
d = Device(
page=self.page,
board=self,
top=(e.y-self.offset_y)/2,
top=(e.y-self.offset_y-75)/2,
left=(e.x-self.offset_x)/2,
device_instance=dev_instance)

Expand Down
28 changes: 17 additions & 11 deletions quasi/gui/board/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,12 @@ def __init__(self, *args, **kwargs):
height=self.content_height - self.header_height
)

self.image_left = 0
self.image_right = 0
if len(self.ports_in.ports) > 0:
self._body_controls.append(self.ports_in)
self._body_controls.append(self.image)
self.image_left = 10
if len(self.ports_out.ports) > 0:
self._body_controls.append(self.ports_out)



self.image_right = 10


self.set_contents(
Expand All @@ -67,11 +65,19 @@ def __init__(self, *args, **kwargs):
right=0,
bottom=0,
bgcolor="#3f3e42",
content=ft.Row(
alignment=ft.MainAxisAlignment.SPACE_AROUND,
spacing=0,
controls=self._body_controls
)
content=ft.Stack(
controls=[self.ports_in,
self.ports_out,
ft.Container(
top=0,
left=self.image_left,
right=self.image_right,
bottom=0,
content=self.image
)
],
expand=True
)
)
)

Expand Down
17 changes: 12 additions & 5 deletions quasi/gui/board/ports.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,18 @@ def __init__(
self.side = Ports.right_side
self.create_ports(self.side)

def build(self) -> ft.Column():
return ft.Column(
spacing=5,
alignment=ft.MainAxisAlignment.SPACE_AROUND,
controls=self.ports_controls
def build(self) -> ft.Container():
return ft.Container(
top=0,
bottom=0,
right=0 if self.side == Ports.right_side else None,
left=0 if self.side == Ports.left_side else None,
width=10,
content=ft.Column(
spacing=5,
alignment=ft.MainAxisAlignment.SPACE_AROUND,
controls=self.ports_controls
)
)

def create_ports(self, side):
Expand Down
57 changes: 48 additions & 9 deletions quasi/gui/menus/menu_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,21 @@ def __init__(self, page: ft.Page) -> None:
)
self.menu_items = ft.Row(
[
ft.Text("Exit", color="white"),
ft.Container(width=2),
ft.Container(
on_click=self.on_minimize,
content=ft.Icon(
name=ft.icons.MINIMIZE,
color="white"
)
),
ft.Container(
on_click=self.on_exit,
content=ft.Icon(
name=ft.icons.CLOSE,
color="white"
)
),
ft.Container(width=1),
]
)
self.container = ft.Container(
Expand All @@ -34,16 +47,42 @@ def __init__(self, page: ft.Page) -> None:
right=0,
height=self.height,
bgcolor="#1f1c1e",
content=ft.Row(
[
self.window_commands,
self.menu_items
],
width=self.page.window_width,
alignment=ft.MainAxisAlignment.SPACE_BETWEEN
content=ft.GestureDetector(
drag_interval=10,
content=ft.Row(
[
self.window_commands,
self.menu_items
],
width=self.page.window_width,
alignment=ft.MainAxisAlignment.SPACE_BETWEEN
),
on_vertical_drag_update=self.move_application_window,
on_double_tap=self.toggle_full_screen
)
)

def move_application_window(self, e) -> None:
print("——————————————————")
print(e.delta_x, e.delta_y)
print(e.local_x, e.local_y)
print(e.global_x, e.global_y)
self.page.window_left = e.global_x
self.page.window_top = e.global_y
self.page.update()

def toggle_full_screen(self, e) -> None:
self.page.window_full_screen = not self.page.window_full_screen
self.page.update()


def on_minimize(self, e) -> None:
self.page.minimized=True
self.page.update()

def on_exit(self, e) -> None:
self.page.window_destroy()

def on_click_simulate(self, e) -> None:
self.sim_warpper.execute()

Expand Down
54 changes: 45 additions & 9 deletions quasi/gui/panels/main_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,52 @@ class MainPanel(ft.UserControl):
def __init__(self, page: ft.Page):
super().__init__()
self.simulation_bar = SimulationBar()
self.container = ft.Container(
top=0,
left=0,
right=0,
bottom=0,
content=ft.Stack(
[Board(self.page),
self.simulation_bar]
self.container=ft.Stack(
[ft.Container(
top=25,
left=0,
right=0,
bottom=0,
bgcolor="#130925",
content=ft.Tabs(
tab_alignment=ft.TabAlignment.START,
indicator_color="white",
divider_color="black",
unselected_label_color="white",
indicator_padding=0,
indicator_tab_size=5,
label_color="blue",
tabs=[
ft.Tab(
text="Board",
content=ft.Stack(
[
ft.Container(
top=0,
left=0,
right=0,
bottom=0,
content=ft.Stack(
[
Board(self.page),
self.simulation_bar
]
))]
)
),
ft.Tab(
text="Report",
),
ft.Tab(
text="Beam Splitter",
)
]
)
)
]
)

def build(self) -> ft.Container:
return self.container


0 comments on commit ce0e4a7

Please sign in to comment.