Skip to content

Commit

Permalink
Merge pull request #9 from tqsd/time-awareness
Browse files Browse the repository at this point in the history
Time awareness
  • Loading branch information
SimonSekavcnik authored Apr 30, 2024
2 parents 891d66b + 9424c79 commit 657f8ca
Show file tree
Hide file tree
Showing 87 changed files with 2,806 additions and 409 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.local_dir.el
.*.el

.DS_Store
.idea
*.log
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "photon-weave"]
path = photon-weave
url = git@github.com:tqsd/photon_weave.git
100 changes: 100 additions & 0 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,104 @@ implemented in [[file:./quasi/signals/generic_signal.py][quasi/signals/generic_s
Each device design stems from the Abstract Base Class ~GenericDevice(ABC)~,
implemented in [[file:./quasi/devices/generic_device.py][quasi/devices/generic_device.py]].




* Installing
QuaSi is currently in Alpha stage, it can be installed using github. Here we
give the tutorial on how to install the quasi program from github.
** Windows
*** Miniconda
On the webpage [[https://conda.io/projects/conda/en/latest/user-guide/install/windows.html][Miniconda]] find the appropriate installer and install the
package. After completion, you can open the Anaconda Prompt and create a new
virtual environment pertaining to quasi:

#+begin_src bash :results output
conda create --name quasi python=3.12
#+end_src

Upon the completed process you can in the same prompt activate the environment
#+begin_src bash :results output
conda activate quasi
#+end_src
If you want to deactivate the virtual environment, type:
#+begin_src bash :results output
conda deactivate
#+end_src
*** Generating ssh-keys
Run powershell as an administrator.
Then activate the ssh-agent:
#+begin_src bash :results output
# Check if the ssh-agent service is running
Get-Service ssh-agent

# If the service is stopped, you can set it to start automatically
Set-Service -Name ssh-agent -StartupType Automatic

# Start the service if it's not already running
Start-Service ssh-agent
#+end_src

Now you can start by generating the key:
#+begin_src bash :results output
ssh-keygen -t ed25519 -C "your_email@example.com"
#+end_src

If your machine doesn't support ed25519 you can use ~-t rsa -b 4096~ instead.

*** Git for Windows
You will need to install git for windows from [[https://git-scm.com/download/win][Git]]. After installing you need to
start the git terminal and configure name and email:

#+begin_src bash :results output
git config global.name "<Your Name>"
git config global.email "<Your Email>"
#+end_src

Now you can add the ssh key:

#+begin_src bash :results output
ssh-add ~\.ssh\id_ed25519
#+end_src
Or other location if you did not choose the default location.

You should now add the public key to your github account. You can copy the
public key (to your clipboard) by:

#+begin_src bash :results output
clip < ~/.ssh/id_ed25519.pub
#+end_src

Now go to the Github settings and add the key to your account.


*** Cloning

With the previous steps completed, you can now clone the repository using Git
for windows.

Make sure you checkout the correct branch.


*** Installing
Open miniconda and activate the environment. ~cd~ into the cloned directory, it
should contain ~setup.py~ and install the package:
#+begin_src bash :results output
pip install -e .
#+end_src


*** Running the GUI
Now you should be able to run the gui
#+begin_src bash :results output
quasi-gui
#+end_src
or manually by
#+begin_src bash :results output
# quasi/gui/
python main.py
#+end_src

* Usage
Currently QuaSi is in development process, so you should use it as a developer.
Please read the notes on Conributing.
Expand Down Expand Up @@ -52,3 +150,5 @@ In order to develop the framework:
#+begin_src bash
pip install -e .
#+end_src


1 change: 1 addition & 0 deletions examples/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

120 changes: 42 additions & 78 deletions examples/beam_splitter_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,92 +2,56 @@
Ideal Beam Splitter experiment example
"""

from quasi.simulation import Simulation
from quasi.devices.ideal import BeamSplitter
from quasi.devices.ideal import SinglePhotonSource
from quasi.devices.ideal import SinglePhotonDetector
from quasi.devices.ideal import Fiber
from quasi.devices import connect_ports
from quasi.signals import GenericQuantumSignal
from quasi.simulation import Simulation, SimulationType
from quasi.devices.sources import IdealNPhotonSource, IdealCoherentSource
from quasi.devices.control import SimpleTrigger
from quasi.devices.beam_splitters import IdealBeamSplitter
from quasi.signals import GenericBoolSignal, GenericQuantumSignal
from quasi.experiment import Experiment
from quasi.backend.fock_first_backend import FockBackendFirst
import numpy as np
np.set_printoptions(precision=3, suppress=True)

Sim = Simulation()
sim = Simulation()
sim.set_backend(FockBackendFirst())
sim.set_dimensions(5)

sim.set_simulation_type(SimulationType.FOCK)

""" ╭───────────╮
│ DEVICES │
╰───────────╯
"""
s1 = IdealCoherentSource()
s1.set_displacement(2,0)
#s1 = IdealNPhotonSource()
#s1.set_photon_num(1)

# Single Photon Sources
sps1 = SinglePhotonSource(name="SPS1")
sps2 = SinglePhotonSource(name="SPS2")

s2 = IdealNPhotonSource()
s2.set_photon_num(0)

# Beam Splitter
bs = BeamSplitter(name="BS")
st1 = SimpleTrigger()
sig_trigger_1 = GenericBoolSignal()
st1.register_signal(signal=sig_trigger_1, port_label="trigger")

# Detectors
spd1 = SinglePhotonDetector(name="SPD1")
spd2 = SinglePhotonDetector(name="SPD2")
st2 = SimpleTrigger()
sig_trigger_2 = GenericBoolSignal()
st2.register_signal(signal=sig_trigger_2, port_label="trigger")

# Fibers
fib1 = Fiber(name="FIB1", length=10)
fib2 = Fiber(name="FIB2", length=10)
fib3 = Fiber(name="FIB3", length=10)
fib4 = Fiber(name="FIB4", length=10)

# Prints a table of devices, registered with the simulation
# Each object instance registers itself with simulation with
# Initiation method
Sim.list_devices()
bs = IdealBeamSplitter()

""" ╭────────────────────╮
│ EXPERIMENT SETUP │
╰────────────────────╯
We should create a utility where the devices and connections
can be set up using yaml language
"""
qs1 = GenericQuantumSignal()
s1.register_signal(signal=qs1, port_label="output")
bs.register_signal(signal=qs1, port_label="A")
qs2 = GenericQuantumSignal()
s2.register_signal(signal=qs2, port_label="output")
bs.register_signal(signal=qs2, port_label="B")

# Connect the devices, through signals
sig1 = GenericQuantumSignal()
sps1.register_signal(signal=sig1, port_label="OUT")
fib1.register_signal(signal=sig1, port_label="IN")

sig2 = GenericQuantumSignal()
sps2.register_signal(signal=sig2, port_label="OUT")
fib2.register_signal(signal=sig2, port_label="IN")

sig3 = GenericQuantumSignal()
fib1.register_signal(signal=sig3, port_label="OUT")
bs.register_signal(signal=sig3, port_label="A")

sig4 = GenericQuantumSignal()
fib2.register_signal(signal=sig4, port_label="OUT")
bs.register_signal(signal=sig4, port_label="B")

sig5 = GenericQuantumSignal()
bs.register_signal(signal=sig5, port_label="C")
fib3.register_signal(signal=sig5, port_label="IN")

sig6 = GenericQuantumSignal()
bs.register_signal(signal=sig6, port_label="D")
fib4.register_signal(signal=sig6, port_label="IN")

sig7 = GenericQuantumSignal()
fib3.register_signal(signal=sig7, port_label="OUT")
spd1.register_signal(signal=sig7, port_label="IN")

sig8 = GenericQuantumSignal()
fib4.register_signal(signal=sig8, port_label="OUT")
spd2.register_signal(signal=sig8, port_label="IN")

# Registers which devices should be triggered when
# simulation starts
Sim.register_triggers(sps1,sps2)
Sim.list_triggered_devices()
""" ╭────────────────────╮
│ RUN SIMULATION │
╰────────────────────╯
"""
Sim.set_dimensions(50)
Sim.run()


sim.run()

exp = Experiment.get_instance()

print(exp.state.all_fock_probs())
state = exp.state
print(state.mean_photon(mode=[0]))
print(state.mean_photon(mode=[1]))
1 change: 1 addition & 0 deletions examples/custom_phase_shift/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .custom_phase_shifter_device import CustomPhaseShift
38 changes: 38 additions & 0 deletions examples/custom_phase_shift/example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from .custom_phase_shifter_device import CustomPhaseShift


from quasi.simulation import Simulation, SimulationType, ModeManager
from quasi.devices.sources import IdealNPhotonSource, IdealCoherentSource
from quasi.devices.control import SimpleTrigger
from quasi.backend.fock_first_backend import FockBackendFirst
from quasi.signals import GenericBoolSignal, GenericQuantumSignal

import numpy as np
from math import pi
np.set_printoptions(suppress=True)
np.set_printoptions(linewidth=200)

sim = Simulation()
sim.set_backend(FockBackendFirst())
sim.set_dimensions(3)


S = IdealNPhotonSource("Source")
S.set_photon_num(1)
trigger = SimpleTrigger()

signals = {}
signals["trigger"] = GenericBoolSignal()
signals["qsig1"] = GenericQuantumSignal()

trigger.register_signal(signal=signals["trigger"], port_label="trigger")
S.register_signal(signal=signals["trigger"], port_label="trigger")

PS = CustomPhaseShift("Custom Phase Shift")
PS.set_params(pi/4, 1, 1, 0)

S.register_signal(signal=signals["qsig1"], port_label="output")
PS.register_signal(signal=signals["qsig1"], port_label="input")

state = exp.state
print(state.all_fock_probs())
Loading

0 comments on commit 657f8ca

Please sign in to comment.