Skip to content

Commit

Permalink
Merge pull request #145 from sequence-toolbox/RnD
Browse files Browse the repository at this point in the history
Version update 0.3.2
  • Loading branch information
Alex-Kolar authored Jul 6, 2022
2 parents 97be99a + 7840d22 commit 15b1c3a
Show file tree
Hide file tree
Showing 10 changed files with 172 additions and 62 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `Mirror` class for simple reflection of photons
- Sends photon to another node with quantum channel connection to the local node
- Quantum++ package acknowledgement to README

## [0.3.2]
### Changed
- Corrected units in jupyter notebook example files
- Corrected units for the optical channel class
- Bug fixes for tutorial scripts
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
author = 'Xiaoliang Wu, Joaquin Chung, Alexander Kolar, Eugene Wang, Tian Zhong, Rajkumar Kettimuthu, Martin Suchara'

# The full version, including alpha/beta/rc tags
release = '0.3.1'
release = '0.3.2'


# -- General configuration ---------------------------------------------------
Expand Down
9 changes: 8 additions & 1 deletion docs/source/tutorial/chapter2/example1.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@
from sequence.components.memory import Memory
from sequence.components.optical_channel import QuantumChannel
from sequence.components.detector import Detector
from sequence.components.circuit import Circuit
from sequence.topology.node import Node


NUM_TRIALS = 1000
FREQUENCY = 1e3

_meas_circuit = Circuit(1)
_meas_circuit.measure(0)


class Counter():
def __init__(self):
Expand All @@ -36,7 +40,10 @@ def __init__(self, name, timeline):
self.detector.owner = self

def receive_qubit(self, src, qubit):
if not qubit.is_null:
qm = self.timeline.quantum_manager
key = qubit.qstate_key
meas_res = qm.run_circuit(_meas_circuit, [key], self.get_generator().random())[key]
if meas_res:
self.detector.get()


Expand Down
21 changes: 19 additions & 2 deletions docs/source/tutorial/chapter2/hardware.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ from sequence.kernel.timeline import Timeline
from sequence.topology.node import Node
from sequence.components.memory import Memory
from sequence.components.detector import Detector
from sequence.components.circuit import Circuit

_meas_circuit = Circuit(1)
_meas_circuit.measure(0)

class SenderNode(Node):
def __init__(self, name: str, timeline: Timeline):
Expand All @@ -55,11 +59,24 @@ class ReceiverNode(Node):
self.detector.owner = self

def receive_qubit(self, src: str, qubit) -> None:
if not qubit.is_null:
qm = self.timeline.quantum_manager
key = qubit.qstate_key
meas_res = qm.run_circuit(_meas_circuit, [key], self.get_generator().random())[key]
if meas_res:
self.detector.get()
```

Notice that we also needed to change the `receive_qubit` method of the base `Node` class. This method is invoked by the quantum channel when transmitting photons, and by default is set to do nothing. For this method, the `src` input specifies the name of the node sending the qubit. In our case, we don’t care about the source node, so we can ignore it. The `qubit` input is the transmitted photon. For single atom memories, this photon may be in a null state, signified with a true value for the `is_null` attribute. A photon may be marked as null if it is somehow lost or should not have been emitted by the memory originally (if the memory is in the up state or has low fidelity). In this case, we must ignore the photon and not record it. Otherwise, it is sent to the detector for measurement. The detector uses the `get` method to receive photons, and this interface is shared by many other optical hardware elements.
Notice that we also needed to change the `receive_qubit` method of the base `Node` class.
This method is invoked by the quantum channel when transmitting photons, and by default is set to do nothing.
For this method, the `src` input specifies the name of the node sending the qubit.
In our case, we don’t care about the source node, so we can ignore it.
The `qubit` input is the transmitted photon.
For single atom memories, the memory state heralded by the denotes the presence or absence of a photon.
This corresponds to the up or down state of the memory.
We will thus measure the memory state and record the photon accordingly (this will be done automatically in future updates).
If we measure 0, we must ignore the photon and not record it.
Otherwise, it is sent to the detector for recording.
The detector uses the `get` method to receive photons, and this interface is shared by many other optical hardware elements.


### Step 2: Custom Protocol
Expand Down
31 changes: 22 additions & 9 deletions example/random_request_network.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
},
{
"cell_type": "code",
"execution_count": 24,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -86,6 +86,7 @@
" sim_time: duration of simulation time (ms)\n",
" qc_atten: quantum channel attenuation (dB/km)\n",
" \"\"\"\n",
" \n",
" network_config = \"star_network.json\"\n",
"\n",
" # here, we make a new topology using the configuration JSON file.\n",
Expand Down Expand Up @@ -163,13 +164,20 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"def set_parameters(topology, simulation_time, attenuation):\n",
"def set_parameters(topology, sim_time, qc_atten):\n",
" \"\"\"\n",
" sim_time: duration of simulation time (ms)\n",
" qc_atten: attenuation on quantum channels (db/m)\n",
" \"\"\"\n",
" \n",
" PS_PER_MS = 1e9\n",
" \n",
" # set timeline stop time\n",
" topology.get_timeline().stop_time = (simulation_time * 1e12)\n",
" topology.get_timeline().stop_time = (sim_time * PS_PER_MS)\n",
" \n",
" # set memory parameters\n",
" MEMO_FREQ = 2e3\n",
Expand Down Expand Up @@ -199,7 +207,7 @@
" node.network_manager.protocol_stack[1].set_swapping_degradation(SWAP_DEGRADATION)\n",
" \n",
" # set quantum channel parameters\n",
" ATTENUATION = attenuation\n",
" ATTENUATION = qc_atten\n",
" QC_FREQ = 1e11\n",
" for qc in topology.qchannels:\n",
" qc.attenuation = ATTENUATION\n",
Expand All @@ -212,20 +220,25 @@
"source": [
"### Running the Simulation\n",
"\n",
"All that is left is to run the simulation with user input. Note that different hardware parameters or network topologies may cause the simulation to run for a very long time."
"All that is left is to run the simulation with user input. We'll specify:\n",
"\n",
" sim_time: duration of simulation time (ms)\n",
" qc_atten: attenuation on quantum channels (db/m)\n",
"\n",
"Note that different hardware parameters or network topologies may cause the simulation to run for a very long time."
]
},
{
"cell_type": "code",
"execution_count": 25,
"execution_count": 7,
"metadata": {
"scrolled": false
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "6b8e00c4681e4657865cdb0ae9687707",
"model_id": "dd506771a175451fa4b6bb1c50b8232b",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -242,7 +255,7 @@
"<function __main__.test(sim_time, qc_atten)>"
]
},
"execution_count": 25,
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
Expand Down
28 changes: 18 additions & 10 deletions example/random_request_network_mod.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -39,7 +39,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -80,7 +80,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -89,6 +89,7 @@
" sim_time: duration of simulation time (ms)\n",
" qc_atten: quantum channel attenuation (dB/km)\n",
" \"\"\"\n",
" \n",
" network_config = \"star_network.json\"\n",
" \n",
" # here, we make a new topology using the configuration JSON file.\n",
Expand Down Expand Up @@ -167,13 +168,20 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"def set_parameters(topology, simulation_time, attenuation):\n",
"def set_parameters(topology, sim_time, qc_atten):\n",
" \"\"\"\n",
" sim_time: duration of simulation time (ms)\n",
" qc_atten: attenuation on quantum channels (db/m)\n",
" \"\"\"\n",
" \n",
" PS_PER_MS = 1e9\n",
" \n",
" # set timeline stop time\n",
" topology.get_timeline().stop_time = (simulation_time * 1e12)\n",
" topology.get_timeline().stop_time = (sim_time * PS_PER_MS)\n",
" \n",
" # set memory parameters\n",
" MEMO_FREQ = 2e3\n",
Expand Down Expand Up @@ -203,7 +211,7 @@
" node.network_manager.protocol_stack[1].set_swapping_degradation(SWAP_DEGRADATION)\n",
" \n",
" # set quantum channel parameters\n",
" ATTENUATION = attenuation\n",
" ATTENUATION = qc_atten\n",
" QC_FREQ = 1e11\n",
" for qc in topology.qchannels:\n",
" qc.attenuation = ATTENUATION\n",
Expand All @@ -221,15 +229,15 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 5,
"metadata": {
"scrolled": false
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "7fe65a6237ca41fcaebab1ae42a3cb08",
"model_id": "7779e45afd3b4de9a73594ae711ee7e7",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -246,7 +254,7 @@
"<function __main__.test(sim_time, qc_atten)>"
]
},
"execution_count": 15,
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
Expand Down
29 changes: 20 additions & 9 deletions example/three_node_eg_ep_es.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,21 @@
"def test(sim_time, cc_delay, qc_atten, qc_dist):\n",
" \"\"\"\n",
" sim_time: duration of simulation time (ms)\n",
" cc_delay: delay on classical channels (ns)\n",
" cc_delay: delay on classical channels (ms)\n",
" qc_atten: attenuation on quantum channels (db/m)\n",
" qc_dist: distance of quantum channels (km)\n",
" \"\"\"\n",
" cc_delay *= 1e6\n",
" qc_dist *= 1e3\n",
" PS_PER_MS = 1e9\n",
" M_PER_KM = 1e3\n",
" \n",
" # convert units for cc delay (to ps) and qc distance (to m)\n",
" cc_delay *= PS_PER_MS\n",
" qc_dist *= M_PER_KM\n",
" \n",
" raw_fidelity = 0.85\n",
" \n",
" # construct the simulation timeline; the constructor argument is the simulation time (in ps)\n",
" tl = Timeline(sim_time * 1e9)\n",
" tl.seed(0)\n",
" tl = Timeline(sim_time * PS_PER_MS)\n",
" \n",
" ## create our quantum network and update parameters as needed\n",
" \n",
Expand All @@ -111,6 +116,12 @@
" m1 = BSMNode(\"m1\", tl, [\"r1\", \"r2\"])\n",
" m2 = BSMNode(\"m2\", tl, [\"r2\", \"r3\"])\n",
" \n",
" r1.set_seed(0)\n",
" r2.set_seed(1)\n",
" r3.set_seed(2)\n",
" m1.set_seed(3)\n",
" m2.set_seed(4)\n",
" \n",
" r1.add_bsm_node(m1.name, r2.name)\n",
" r2.add_bsm_node(m1.name, r1.name)\n",
" r2.add_bsm_node(m2.name, r3.name)\n",
Expand Down Expand Up @@ -262,7 +273,7 @@
"Parameters:\n",
"\n",
" sim_time: duration of simulation time (ms)\n",
" cc_delay: delay on classical channels (ns)\n",
" cc_delay: delay on classical channels (ms)\n",
" qc_atten: attenuation on quantum channels (db/m)\n",
" qc_dist: distance of quantum channels (km)\n",
" \n",
Expand All @@ -279,12 +290,12 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "71c13bbf69664b55a2fffeffcd21f59a",
"model_id": "2a827b474ef6441aa31a56e6340ed219",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"interactive(children=(IntSlider(value=3000, description='sim_time', max=4000, min=2000, step=500), IntSlider(v"
"interactive(children=(IntSlider(value=3000, description='sim_time', max=4000, min=2000, step=500), FloatSlider"
]
},
"metadata": {},
Expand All @@ -302,7 +313,7 @@
}
],
"source": [
"interactive_plot = interact(test, sim_time=(2000, 4000, 500), cc_delay=(100, 1000, 100), qc_atten=[1e-5, 2e-5, 3e-5], qc_dist=(1, 10, 1))\n",
"interactive_plot = interact(test, sim_time=(2000, 4000, 500), cc_delay=(0.1, 1, 0.1), qc_atten=[1e-5, 2e-5, 3e-5], qc_dist=(1, 10, 1))\n",
"interactive_plot"
]
},
Expand Down
Loading

0 comments on commit 15b1c3a

Please # to comment.