-
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.
Started to work on the example for TUD
- Loading branch information
1 parent
cd00e0b
commit a6993cb
Showing
8 changed files
with
391 additions
and
3 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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
from quasi.simulation import Simulation | ||
from quasi.devices.control import SimpleTrigger | ||
from quasi.devices.sources import IdealNPhotonSource | ||
from quasi.devices.fiber import IdealFiber | ||
from quasi.devices.detectors import IdealDetector | ||
from quasi.devices.beam_splitters import IdealBeamSplitter | ||
from quasi.signals import GenericBoolSignal, GenericQuantumSignal, GenericIntSignal | ||
import mpmath | ||
|
||
# Helper function for connecting devices with signals | ||
def connect(sig_cls, dev1, port1, dev2=None, port2=None): | ||
sig = sig_cls() | ||
dev1.register_signal( | ||
signal=sig, | ||
port_label=port1 | ||
) | ||
if dev2 is not None and port2 is not None: | ||
dev2.register_signal( | ||
signal=sig, | ||
port_label=port2 | ||
) | ||
return sig | ||
|
||
# Devices | ||
trigger = SimpleTrigger("Trigger", time=0) | ||
source = IdealNPhotonSource("Source") | ||
bs1 = IdealBeamSplitter("BS1") | ||
f1 = IdealFiber("Fiber") | ||
f1.set_length(1000) | ||
|
||
# connecting | ||
signals = {} | ||
signals["qsig1"] = connect( | ||
GenericBoolSignal, | ||
trigger,"trigger", | ||
source, "trigger" | ||
) | ||
signals["qsig2"] = connect( | ||
GenericQuantumSignal, | ||
source, "output", | ||
f1, "input" | ||
) | ||
signals["qsig3"] = connect( | ||
GenericQuantumSignal, | ||
f1, "output", | ||
bs1, "A" | ||
) | ||
signals["photon_num"] = connect( | ||
GenericIntSignal, source, "photon_num") | ||
signals["photon_num"].set_int(3) | ||
|
||
if __name__ == "__main__": | ||
simulation = Simulation.get_instance() | ||
simulation.run_des(1) | ||
|
||
|
||
|
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
Empty file.
Empty file.
85 changes: 85 additions & 0 deletions
85
examples/time_synchronization/custom_components/custom_fiber.py
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,85 @@ | ||
""" | ||
created with template | ||
""" | ||
from typing import Union | ||
from quasi.devices import (GenericDevice, | ||
wait_input_compute, | ||
schedule_next_event, | ||
coordinate_gui, | ||
log_action, | ||
ensure_output_compute) | ||
|
||
from quasi.devices.port import Port | ||
from quasi.simulation import ModeManager | ||
from quasi.simulation.constants import C | ||
from quasi.signals import * | ||
|
||
|
||
class CustomFiber(GenericDevice): | ||
ports = { | ||
|
||
"input": Port( | ||
label="input", | ||
direction="input", | ||
signal=None, | ||
signal_type=GenericQuantumSignal, | ||
device=None), | ||
|
||
|
||
"output": Port( | ||
label="output", | ||
direction="output", # Changed from "input" to "output" for clarity | ||
signal=None, | ||
signal_type=GenericQuantumSignal, | ||
device=None), | ||
|
||
} | ||
|
||
gui_icon = None | ||
gui_tags = None | ||
gui_documentation= None | ||
|
||
power_peak = 0 | ||
power_average = 0 | ||
|
||
reference = None | ||
|
||
def __init__(self, name, uid, length=-1): | ||
super().__init__(name, uid) | ||
self.length=length | ||
|
||
def set_length(self, length): | ||
self.length = length | ||
|
||
@ensure_output_compute | ||
@coordinate_gui | ||
@wait_input_compute | ||
def compute_outputs(self, *args, **kwargs): | ||
""" | ||
Implement to use the regular backend | ||
""" | ||
pass | ||
|
||
@log_action | ||
@schedule_next_event | ||
def des(self, time, *args, **kwargs): | ||
""" | ||
Implement to use discrete event simulation | ||
""" | ||
n = 1.45 | ||
# Speed of light in fiber | ||
v = C/n | ||
t = self.length/v | ||
s = kwargs["signals"]["input"] | ||
env = s.contents | ||
|
||
return [("output", s, time+t)] | ||
|
||
@log_action | ||
@schedule_next_event | ||
def des_action(self, time=None, *args, **kwargs): | ||
""" | ||
Or implement this if you are implementing a trigger | ||
""" | ||
pass |
81 changes: 81 additions & 0 deletions
81
examples/time_synchronization/custom_components/custom_filter.py
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,81 @@ | ||
""" | ||
created with template | ||
""" | ||
from typing import Union | ||
from quasi.devices import (GenericDevice, | ||
wait_input_compute, | ||
schedule_next_event, | ||
coordinate_gui, | ||
log_action, | ||
ensure_output_compute) | ||
|
||
from quasi.devices.port import Port | ||
from quasi.simulation import ModeManager | ||
from quasi.signals import * | ||
|
||
|
||
class CustomFilter(GenericDevice): | ||
ports = { | ||
|
||
"input": Port( | ||
label="input", | ||
direction="input", | ||
signal=None, | ||
signal_type=GenericQuantumSignal, | ||
device=None), | ||
|
||
|
||
"exciton": Port( | ||
label="exciton", | ||
direction="output", # Changed from "input" to "output" for clarity | ||
signal=None, | ||
signal_type=GenericQuantumSignal, | ||
device=None), | ||
|
||
"biexciton": Port( | ||
label="biexciton", | ||
direction="output", # Changed from "input" to "output" for clarity | ||
signal=None, | ||
signal_type=GenericQuantumSignal, | ||
device=None), | ||
|
||
} | ||
|
||
gui_icon = None | ||
gui_tags = None | ||
gui_documentation= None | ||
|
||
power_peak = 0 | ||
power_average = 0 | ||
|
||
reference = None | ||
|
||
@ensure_output_compute | ||
@coordinate_gui | ||
@wait_input_compute | ||
def compute_outputs(self, *args, **kwargs): | ||
""" | ||
Implement to use the regular backend | ||
""" | ||
pass | ||
|
||
@log_action | ||
@schedule_next_event | ||
def des(self, time, *args, **kwargs): | ||
""" | ||
Implement to use discrete event simulation | ||
""" | ||
s = kwargs["signals"]["input"] | ||
env = s.contents | ||
if env.wavelength < 825: | ||
return [("exciton", s, time)] | ||
return [("biexciton", s, time)] | ||
|
||
@log_action | ||
@schedule_next_event | ||
def des_action(self, time=None, *args, **kwargs): | ||
""" | ||
Or implement this if you are implementing a trigger | ||
""" | ||
pass |
100 changes: 100 additions & 0 deletions
100
examples/time_synchronization/custom_components/entangled_photon_source.py
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,100 @@ | ||
""" | ||
created with template | ||
""" | ||
import mpmath | ||
from typing import Union | ||
from quasi.devices import (GenericDevice, | ||
wait_input_compute, | ||
schedule_next_event, | ||
coordinate_gui, | ||
log_action, | ||
ensure_output_compute) | ||
from quasi.devices.port import Port | ||
from quasi.simulation import ModeManager | ||
from quasi.signals import * | ||
from photon_weave.state.envelope import Envelope | ||
from photon_weave.state.composite_envelope import CompositeEnvelope | ||
from photon_weave.operation.polarization_operations import ( | ||
PolarizationOperation, PolarizationOperationType | ||
) | ||
from photon_weave.operation.fock_operation import ( | ||
FockOperationType, FockOperation | ||
) | ||
from photon_weave.operation.composite_operation import ( | ||
CompositeOperation, CompositeOperationType | ||
) | ||
|
||
class EntangledPhotonSource(GenericDevice): | ||
ports = { | ||
"trigger": Port( | ||
label="trigger", | ||
direction="input", | ||
signal=None, | ||
signal_type=GenericBoolSignal, | ||
device=None), | ||
"output": Port( | ||
label="output", | ||
direction="output", # Changed from "input" to "output" for clarity | ||
signal=None, | ||
signal_type=GenericQuantumSignal, | ||
device=None), | ||
} | ||
|
||
gui_icon = None | ||
gui_tags = None | ||
gui_documentation= None | ||
|
||
power_peak = 0 | ||
power_average = 0 | ||
|
||
reference = None | ||
|
||
@ensure_output_compute | ||
@coordinate_gui | ||
@wait_input_compute | ||
def compute_outputs(self, *args, **kwargs): | ||
""" | ||
Implement to use the regular backend | ||
""" | ||
pass | ||
|
||
@log_action | ||
@schedule_next_event | ||
def des(self, time, *args, **kwargs): | ||
""" | ||
Implement to use discrete event simulation | ||
""" | ||
# biexciton | ||
env1 = Envelope(wavelength=830) | ||
# exciton | ||
env2 = Envelope(wavelength=820) | ||
# Modify Value | ||
photon_num = 5 | ||
a_dagger = FockOperation(FockOperationType.Creation, apply_count=photon_num) | ||
|
||
env1.apply_operation(a_dagger) | ||
env2.apply_operation(a_dagger) | ||
|
||
H = PolarizationOperation(operation=PolarizationOperationType.H) | ||
env1.apply_operation(H) | ||
CNOT = CompositeOperation(CompositeOperationType.CNOT) | ||
c = CompositeEnvelope(env1, env2) | ||
c.apply_operation(CNOT, env1, env2) | ||
# Time after the biexciton decays | ||
t1 = mpmath.mpf("0.0000000000001") | ||
t2 = mpmath.mpf("0.0000000000002") | ||
s1 = GenericQuantumSignal() | ||
s1.set_contents(content=env1) | ||
s2 = GenericQuantumSignal() | ||
s2.set_contents(content=env2) | ||
return [("output", s1, time+t1),("output", s2, time+t2)] | ||
|
||
|
||
|
||
@log_action | ||
@schedule_next_event | ||
def des_action(self, time=None, *args, **kwargs): | ||
""" | ||
Or implement this if you are implementing a trigger | ||
""" | ||
pass |
Oops, something went wrong.