Skip to content

Commit

Permalink
Merged from beam-splitter branch
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonSekavcnik committed Dec 14, 2023
2 parents 5a863bf + e573ea2 commit 3e5f659
Show file tree
Hide file tree
Showing 21 changed files with 1,395 additions and 65 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install pylint
pip install numpy
pip install numba
pip install black
- name: Analysing the code with pylint
run: |
pylint $(git ls-files '*.py')
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,7 @@ flycheck_*.el

# network security
/network-security.data

.vscode
.\vscode
./vscode
233 changes: 233 additions & 0 deletions examples/demo.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "1855e140",
"metadata": {},
"outputs": [],
"source": [
"from quasi.simulation import Simulation\n",
"from quasi.experiement import Experiement\n",
"from quasi.components.gates import Squeezing, Beamsplitter, Phase\n",
"from math import pi\n",
"import numpy as np\n",
"from quasi._math.fock import mean_photon"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "8d6b64f9",
"metadata": {},
"outputs": [],
"source": [
"squeezing_gate = Squeezing(r=1, phi=pi, cutoff=10)\n",
"\n",
"bs_gate = Beamsplitter(theta=pi/4, phi=0, cutoff=10)\n",
"\n",
"phase_gate = Phase(phi=pi/4, cutoff=10)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "20f41390",
"metadata": {},
"outputs": [],
"source": [
"from quasi.components.gates import Components\n",
"\n",
"my_comp = Components(doi=\"https://doi.org/10.1038/s41467-023-36159-y\")\n",
"my_comp.matrix = np.identity(3)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "102388e4",
"metadata": {},
"outputs": [],
"source": [
"exp_1 = Experiement(num_modes=2, cutoff=10)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "37871484",
"metadata": {},
"outputs": [],
"source": [
"exp_1.state_init(1, [0])\n",
"\n",
"exp_1.add_operation(bs_gate.get_operator().transpose((0, 2, 1, 3)), [0, 1])\n",
"#exp_1.add_operation(squeezing_gate.get_operator(), [0])"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "abc8426c",
"metadata": {},
"outputs": [],
"source": [
"exp_1.execute()"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "f50de5c9",
"metadata": {},
"outputs": [],
"source": [
"state = exp_1.state"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "69b22218",
"metadata": {},
"outputs": [],
"source": [
"state."
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "2c49f439",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[0. , 0.5, 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ],\n",
" [0.5, 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ],\n",
" [0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ],\n",
" [0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ],\n",
" [0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ],\n",
" [0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ],\n",
" [0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ],\n",
" [0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ],\n",
" [0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ],\n",
" [0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ]])"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"probs = state.all_fock_probs()\n",
"probs"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "885ba32a",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(0.4999999999999999, 0.5000000000000001)"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"probs[0, 1], probs[1, 0]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0abd708a",
"metadata": {},
"outputs": [],
"source": [
"len(np.diagonal(state.dm()))"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "f1eef253",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.5000000000000001"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"state.mean_photon(mode=[0])"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "53740890",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(True,\n",
" ' @article{Jerbi_2023, title={Quantum machine learning beyond kernel methods}, volume={14}, ISSN={2041-1723}, url={http://dx.doi.org/10.1038/s41467-023-36159-y}, DOI={10.1038/s41467-023-36159-y}, number={1}, journal={Nature Communications}, publisher={Springer Science and Business Media LLC}, author={Jerbi, Sofiene and Fiderer, Lukas J. and Poulsen Nautrup, Hendrik and Kübler, Jonas M. and Briegel, Hans J. and Dunjko, Vedran}, year={2023}, month=jan }\\n')"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"my_comp.generate_bibtex(doi=\"https://doi.org/10.1038/s41467-023-36159-y\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d58349ca",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
28 changes: 28 additions & 0 deletions examples/fock_ops.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from quasi.components.gates import Beamsplitter, Displacment, Phase, Squeezing
from quasi._math.fock import (
vacuum_state,
mean_photon_number,
fock_probability,
)
from quasi.components.gates import Components
import numpy as np

qumode = 1
cutoff = 10
init_state = vacuum_state(n=qumode, cutoff=cutoff)

doi = "https://doi.org/10.1088/1742-6596/1612/1/012015"
user_defined_component = Components(cutoff=cutoff, doi=doi)

user_defined_component.matrix = np.identity(n=10)
bibtex_file = user_defined_component.generate_bibtex(doi)

displacement_operator = Displacment(1, 0.5, cutoff=10).matrix

displaced_state = displacement_operator @ init_state

displaced_state_unphased = Phase(-0.5, cutoff=10).matrix @ displaced_state

assert mean_photon_number(state=displaced_state) == 1**2

assert fock_probability([0], displaced_state) == displaced_state[0].real ** 2
19 changes: 17 additions & 2 deletions examples/hong_ou_mandel.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@
"""

from quasi.simulation import Simulation
from quasi.experiement import Experiement
from quasi.components.gates import Squeezing, Beamsplitter
from math import pi

S = Simulation.get_instance()
print(S)
Sim = Simulation.get_instance()

squeezing_gate = Squeezing(r=2, phi=0)

bs_gate = Beamsplitter(theta=0.5, phi=pi / 2)


exp_1 = Experiement()

exp_1.state_init("type of state")
exp_1.add_operation(squeezing_gate, modes=0)
exp_1.add_operation(bs_gate, modes=[0, 1])

Sim.execute(exp_1)
23 changes: 23 additions & 0 deletions quasi/_math/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from .fock.ops import (
displacement,
phase,
mean_photon_number,
squeezing,
adagger,
a,
beamsplitter,
vacuum_state,
calculate_fidelity,
coherent_state,
fock_state,
fock_probability,
kerr,
apply_channel,
apply_gate_einsum,
thermalState,
partial_trace,
calculate_trace,
cubicPhase,
lossChannel,
tensor,
)
19 changes: 19 additions & 0 deletions quasi/_math/fock/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from .ops import (
displacement,
beamsplitter,
phase,
vacuum_state,
coherent_state,
adagger,
a,
mean_photon_number,
fock_probability,
squeezing,
calculate_fidelity,
calculate_trace,
lossChannel,
cubicPhase,
apply_channel,
apply_gate_einsum,
tensor,
)
Loading

0 comments on commit 3e5f659

Please sign in to comment.