-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
891d66b
commit b4d2c72
Showing
29 changed files
with
405 additions
and
242 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
.local_dir.el | ||
.*.el | ||
|
||
.DS_Store | ||
.idea | ||
*.log | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .ideal_fiber import IdealFiber |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
""" | ||
This module implements a generic fiber | ||
all fibers must extend this fiber abstraction | ||
""" | ||
|
||
from quasi.devices.generic_device import GenericDevice | ||
from quasi.signals.generic_float_signal import GenericFloatSignal | ||
from quasi.devices import Port | ||
from quasi.signals.generic_quantum_signal import GenericQuantumSignal | ||
|
||
from abc import ABCMeta, ABC | ||
|
||
class EnforcePortsMeta(ABCMeta): | ||
def __init__(cls, name, bases, namespace, **kwargs): | ||
super().__init__(name, bases, namespace) | ||
# Only enforce ports structure on subclasses, not on GenericDevice itself | ||
if bases != (ABC,) and 'GenericDevice' in [base.__name__ for base in bases]: | ||
# Ensure the class has a 'ports' class variable and it's a dictionary | ||
if not hasattr(cls, 'ports') or not isinstance(cls.ports, dict): | ||
raise TypeError(f"{cls.__name__} must have a 'ports' class variable of type dict") | ||
|
||
# Specify the required keys | ||
required_keys = {'length', 'input', 'output'} | ||
# Check if the 'ports' dictionary has all the required keys | ||
if not required_keys.issubset(cls.ports.keys()): | ||
missing_keys = required_keys - cls.ports.keys() | ||
raise TypeError(f"{cls.__name__}'s 'ports' dictionary is missing keys: {missing_keys}") | ||
|
||
|
||
class GenericFiber(GenericDevice, metaclass=EnforcePortsMeta): | ||
""" | ||
Generic Fiber specifies the format for all Fiber Devices | ||
Every Fiber device must extend this abstract base class | ||
""" | ||
|
||
ports = { | ||
"length": Port( | ||
label="control", | ||
direction="length", | ||
signal=None, | ||
signal_type=GenericFloatSignal, | ||
device=None), | ||
"input": Port( | ||
label="input", | ||
direction="input", | ||
signal=None, | ||
signal_type=GenericQuantumSignal, | ||
device=None), | ||
"output": Port( | ||
label="output", | ||
direction="output", | ||
signal=None, | ||
signal_type=GenericQuantumSignal, | ||
device=None), | ||
} | ||
|
||
|
||
def set_length(self, length: float): | ||
""" | ||
Sets the length of the fiber | ||
""" | ||
length_signal = GenericFloatSignal() | ||
length_signal.set_float(length) | ||
self.register_signal(signal=length_signal, port_label="length") | ||
length_signal.set_computed() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
""" | ||
Ideal Fiber Implementation | ||
ideal fiber has no attenuation, it just adds a delay to the signal | ||
the delay is proportional to the length of the fiber | ||
""" | ||
from typing import Union | ||
from quasi.devices import (GenericDevice, | ||
wait_input_compute, | ||
coordinate_gui, | ||
ensure_output_compute) | ||
|
||
from quasi.devices.fiber.generic_fiber import GenericFiber | ||
from quasi.devices.port import Port | ||
from quasi.signals.generic_float_signal import GenericFloatSignal | ||
from quasi.signals.generic_int_signal import GenericIntSignal | ||
from quasi.signals.generic_quantum_signal import GenericQuantumSignal | ||
from quasi.gui.icons import icon_list | ||
from quasi.simulation import ModeManager | ||
|
||
class IdealFiber(GenericFiber): | ||
""" | ||
Ideal Fiber | ||
- no attenuation | ||
- only time delay | ||
""" | ||
|
||
ports = { | ||
"length": Port( | ||
label="length", | ||
direction="input", # Implement control | ||
signal=None, | ||
signal_type=GenericFloatSignal, | ||
device=None), | ||
"input": Port( | ||
label="input", | ||
direction="input", | ||
signal=None, | ||
signal_type=GenericQuantumSignal, | ||
device=None), | ||
"output": Port( | ||
label="output", | ||
direction="output", | ||
signal=None, | ||
signal_type=GenericQuantumSignal, | ||
device=None), | ||
} | ||
|
||
# Gui Configuration | ||
gui_icon = icon_list.FIBER | ||
gui_tags = ["ideal"] | ||
gui_name = "Ideal Fiber" | ||
gui_documentation = "ideal_fiber.md" | ||
|
||
power_peak = 0 | ||
power_average = 0 | ||
|
||
reference = None | ||
|
||
|
||
@ensure_output_compute | ||
@coordinate_gui | ||
@wait_input_compute | ||
def compute_outputs(self, *args, **kwargs): | ||
""" | ||
Ideal fiber only adds delay to the signal, | ||
without any distortions | ||
""" | ||
self.ports["output"].signal.set_contents( | ||
timestamp=0, | ||
mode_id=self.ports["input"].signal.mode_id | ||
) | ||
self.ports["output"].signal.set_computed() |
Oops, something went wrong.