Skip to content

Commit

Permalink
Added simulation bar
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonSekavcnik committed Dec 15, 2023
1 parent 99374ad commit da082fd
Show file tree
Hide file tree
Showing 17 changed files with 408 additions and 151 deletions.
9 changes: 5 additions & 4 deletions quasi/devices/investigation_devices/photon_distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class PhotonDistribution(GenericDevice):

# Gui Configuration
gui_icon = icon_list.HISTOGRAM
gui_tags = ["investigate"]
gui_tags = ["investigate", "chart"]
gui_name = "Photon Distribution"

power_average = 0
Expand All @@ -45,7 +45,6 @@ def compute_outputs(self, *args, **kwargs):
mm = ModeManager()
m_id = self.ports["IN"].signal.mode_id
mode = mm.get_mode(m_id)
print(mode)
probabilities = np.real(np.diag(mode))

histogram_data = {
Expand All @@ -58,6 +57,8 @@ def compute_outputs(self, *args, **kwargs):
title='Fock State Density Matrix Histogram')

# Show the plot
fig.show()
#fig.show()
if hasattr(self, "coordinator"):
self.coordinator.set_chart(fig)



64 changes: 57 additions & 7 deletions quasi/devices/investigation_devices/wigner_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,81 @@
Create wigner distribution plots
"""

import numpy as np
from scipy.linalg import sqrtm
from scipy.fft import fftn, fftfreq
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import plotly.graph_objects as go

from quasi.devices import (GenericDevice,
wait_input_compute,
coordinate_gui,
ensure_output_compute)
from quasi.devices.port import Port
from quasi.signals import (GenericSignal,
GenericQuantumSignal)

from quasi.gui.icons import icon_list

from quasi.simulation import ModeManager

from qutip.wigner import wigner
from qutip import Qobj


class WignerControl(GenericDevice):
"""
Implements Ideal Single Photon Source
Implements Wigner Plot creation device
"""
ports = {
"input": Port(label="A", direction="input", signal=None,
signal_type=GenericQuantumSignal, device=None),
"IN": Port(
label="IN",
direction="input",
signal=None,
signal_type=GenericQuantumSignal, device=None),
}

# Gui Configuration
gui_icon = icon_list.WIGNER_CONTROL
gui_tags = ["investigate"]
gui_tags = ["investigate", "chart"]
gui_name = "Wigner Quasi Probability"

@ensure_output_compute
power_average = 0
power_peak = 0
reference = 0

@wait_input_compute
def compute_outputs(self):
pass
@coordinate_gui
def compute_outputs(self, *args, **kwargs):
mm = ModeManager()
m_id = self.ports["IN"].signal.mode_id
mode = mm.get_mode(m_id)
# Show the plot


# Plot Wigner probability
print(mode)
xvec = np.linspace(-5,5,200)

W = wigner(Qobj(mode), xvec, xvec)

fig = go.Figure()

fig.add_trace(go.Surface(z=W, x=xvec, y=xvec, colorscale="Viridis"))

# Set the layout of the figure
fig.update_layout(
title="Wigner Function",
scene=dict(
xaxis_title="Re(alpha)",
yaxis_title="Im(alpha)",
zaxis_title="Wigner Function",
)
)

if hasattr(self, "coordinator"):
self.coordinator.set_chart(fig)



1 change: 1 addition & 0 deletions quasi/devices/sources/ideal_single_photon_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

from quasi._math.fock.ops import adagger, a


class IdealSinglePhotonSource(GenericDevice):
"""
Implements Ideal Single Photon Source
Expand Down
Binary file added quasi/gui/assets/play.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file added quasi/gui/bar/__init__.py
Empty file.
46 changes: 46 additions & 0 deletions quasi/gui/bar/simulation_bar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import flet as ft

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


class SimulationBar(ft.UserControl):
"""
Implements file menu functionality
"""

def __init__(self) -> None:
super().__init__()

self.sim_warpper = SimulationWrapper()
self.simulate_button = ft.Container(
width=25,
height=25,
content=ft.Icon(
name=ft.icons.PLAY_CIRCLE_OUTLINED,
color="white"
),
on_click=self.on_click_simulate
)


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

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

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

172 changes: 172 additions & 0 deletions quasi/gui/board/base_device_component.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
"""
This module implements the base
functionality, common for all
devices
"""

import flet as ft



class BaseDeviceComponent(ft.UserControl):

"""
Displays the chart
"""
def __init__(self,
page: ft.Page,
top: float,
left: float,
board,
device_instance=None,
label="",
resizable=False,
height=100,
width=100,
):
super().__init__()
self.top = top
self.left = left
print(self.top, self.left)
self.board = board
self.label = label
self.device_instance = device_instance
self.resizable = resizable
self.resize_size = 10
self.header_height = 15
self.base_wrapper_height = height
self.base_wrapper_width = width
self.content_height = self._compute_content_height()
self.content_width = self._compute_content_width()

self.base_processing = ft.Container(
top=2,
left=2,
height=5,
width=5,
visible=False,
content=ft.ProgressRing(
color="white",
stroke_width=2
)
)

self.base_header = ft.Container(
top=0,
left=0,
right=0,
height=self.header_height,
bgcolor="black",
content=ft.Stack(
[
self.base_processing,
ft.Container(
left=8,
content=ft.Text(
label,
size=12,
color="white")
),
ft.GestureDetector(
drag_interval=1,
on_vertical_drag_update=self.handle_device_move,
mouse_cursor=ft.MouseCursor.GRAB
)
]
)
)

self.contents = None
self.content_wrapper = ft.Container(
top=15,
bottom=0,
left=0,
right=0,
bgcolor="#3f3e42",
content=ft.Stack([])
)

self.resize_container = ft.Container(
right=0,
bottom=0,
opacity=0.2,
height=self.resize_size,
width=self.resize_size,
visible=self.resizable,
bgcolor="black",
content=ft.GestureDetector(
drag_interval=5,
on_vertical_drag_update=self.handle_device_resize,
mouse_cursor=ft.MouseCursor.RESIZE_DOWN_RIGHT
)
)

self.base_wrapper = ft.Container(
width=self.base_wrapper_width,
height=self.base_wrapper_height,
top=self.top,
left=self.left,
bgcolor="red",
content=ft.Stack(
[self.base_header,
self.content_wrapper,
self.resize_container]
)
)

def set_contents(self, device_content):
self.content_wrapper.content.controls.append(
device_content)


def build(self):
return self.base_wrapper

# GUI Logic
def _compute_content_height(self) -> float:
h = self.base_wrapper_height
return h - self.header_height

def _compute_content_width(self) -> float:
return self.base_wrapper_width

# Handlers
def handle_device_move(self, e):
"""
Handling the movement of the device
"""
self.top += e.delta_y/2
self.left += e.delta_x/2
self.base_wrapper.top = self.top
self.base_wrapper.left = self.left
if hasattr(self, "ports_in"):
self.ports_in.move(e.delta_x, e.delta_y)
if hasattr(self, "ports_out"):
self.ports_out.move(e.delta_x, e.delta_y)
self.base_wrapper.update()
self.board.content.update()
e.control.update()

def handle_device_resize(self, e):
"""
Handling the resizing of the device
"""
self.base_wrapper.width = max(
self.base_wrapper.width + e.delta_x,
50)
self.base_wrapper.height = max(
self.base_wrapper.height + e.delta_x,
50)

self.content_height = self._compute_content_height()
self.content_width = self._compute_content_height()
self.base_wrapper.update()


def start_processing(self):
self.base_processing.visible = True
self.base_wrapper.update()

def stop_processing(self):
self.base_processing.visible = False
self.base_wrapper.update()
24 changes: 16 additions & 8 deletions quasi/gui/board/board.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

class Board(ft.UserControl):
__instance = None

def __init__(self, page: ft.Page):
super().__init__()
self.sim_wrapper = SimulationWrapper()
Expand Down Expand Up @@ -52,13 +53,19 @@ def __init__(self, page: ft.Page):
),
self.content,
])
self.board_wrapper = ft.DragTarget(
group="device",
content=ft.Container(
expand=True,
bgcolor="#a19bac",#"#27262c",
content= self.board),
on_accept=self.drag_accept
self.board_wrapper = ft.Container(
top=50,
left=0,
right=0,
bottom=0,
content=ft.DragTarget(
group="device",
content=ft.Container(
expand=True,
bgcolor="#a19bac",#"#27262c",
content= self.board),
on_accept=self.drag_accept
)
)
Board.__instance = self

Expand Down Expand Up @@ -94,6 +101,7 @@ def drag_accept(self, e: ft.DragUpdateEvent):
"""
dev = self.page.get_control(e.src_id)
dev_instance = dev.device_class()

d = Device(
page=self.page,
board=self,
Expand All @@ -103,7 +111,7 @@ def drag_accept(self, e: ft.DragUpdateEvent):

self.content.controls.append(d)
self.content.update()
self.sim_wrapper.add_device(dev_instance, d.sim_gui_coordinator)
self.sim_wrapper.add_device(dev_instance)
e.control.update()

def build(self) -> ft.Container():
Expand Down
Loading

0 comments on commit da082fd

Please sign in to comment.