Repository: sequence-toolbox/SeQUeNCe (language: python)

Issue:
[Minor] Fix Small issues in Tutorial and entanglement_management/swapping.py
Hi SeQUeNCe team,

Recently I tried SeQUeNCe mainly via reading the tutorial and coding the examples myself. I found a couple of minor issues and fixed them in this pull request.

1. In tutorial/chapter3/example1.py, add the import for class Message and ignore the classical channel connecting a node to the same node itself, which does not make sense
2. In tutorial/chapter3/example3.py, also ignore the classical channel from a node to itself
3. In entanglement_management/swapping.py, fix minor comment issue in EntanglementSwappingB

Note: 
For 1) and 2), I only fixed the example.py code in the tutorial but didn't update the tutorial's text.
Apart from this pull request, I also created some issues for slightly larger problems.

Thank you for your time,
Caitao


Discussion / hints:

Fix patch:
diff --git a/.gitignore b/.gitignore
index 45732e60..64ef08b9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -139,3 +139,6 @@ src/gui/test_run.py
 
 # macos
 .DS_Store
+
+# tmp folder
+tmp/
diff --git a/README.md b/README.md
index 9adfb201..f33ff778 100644
--- a/README.md
+++ b/README.md
@@ -10,16 +10,21 @@ SeQUeNCe is an open source, discrete-event simulator for quantum networks. As de
 These modules can be edited by users to define additional functionality and test protocol schemes, or may be used as-is to test network parameters and topologies.
 
 ## Installing
-SeQUeNCe requires an installation of Python 3.8 or later. This can be found at the [Python Website](https://www.python.org/downloads/).
-Then, simply download the package, navigate to its directory, and install with
+SeQUeNCe requires an installation of [Python 3.8](https://www.python.org/downloads/) or later.
+Then, simply download the package, navigate to its directory, and install with `pip install --editable .`
 ```
-$ pip install .
+git clone https://github.com/sequence-toolbox/SeQUeNCe.git
+cd SeQUeNCe
+pip install --editable .
 ```
-Or, using the included makefile,
+Note: With `--editable`, any changes you make to the package code are immediately reflected when you import the package. This greatly speeds up the development process because you don't have to repeatedly uninstall/install the package after making changes. You are free to skip the `--editable` option.
+
+<!-- Or, using the included makefile
 ```
-$ make install
+make install
 ```
-This will install the sequence library as well as the package dependencies.
+
+This will install the sequence library as well as the package dependencies. -->
 
 ## Citation
 Please cite us, thank you!
diff --git a/src/__init__.py b/sequence/__init__.py
similarity index 88%
rename from src/__init__.py
rename to sequence/__init__.py
index c338055d..060d844c 100644
--- a/src/__init__.py
+++ b/sequence/__init__.py
@@ -1,7 +1,7 @@
 __all__ = ['app', 'components', 'entanglement_management', 'kernel', 'network_management', 'qkd', 'resource_management',
            'topology', 'utils', 'message', 'protocol', 'gui']
 
-__version__ = '0.2.3_dev_GUI'
+__version__ = '0.6.2'
 
 def __dir__():
     return sorted(__all__)
diff --git a/src/app/__init__.py b/sequence/app/__init__.py
similarity index 100%
rename from src/app/__init__.py
rename to sequence/app/__init__.py
diff --git a/src/app/random_request.py b/sequence/app/random_request.py
similarity index 100%
rename from src/app/random_request.py
rename to sequence/app/random_request.py
diff --git a/src/app/request_app.py b/sequence/app/request_app.py
similarity index 100%
rename from src/app/request_app.py
rename to sequence/app/request_app.py
diff --git a/src/components/__init__.py b/sequence/components/__init__.py
similarity index 100%
rename from src/components/__init__.py
rename to sequence/components/__init__.py
diff --git a/src/components/beam_splitter.py b/sequence/components/beam_splitter.py
similarity index 100%
rename from src/components/beam_splitter.py
rename to sequence/components/beam_splitter.py
diff --git a/src/components/bsm.py b/sequence/components/bsm.py
similarity index 100%
rename from src/components/bsm.py
rename to sequence/components/bsm.py
diff --git a/src/components/circuit.py b/sequence/components/circuit.py
similarity index 100%
rename from src/components/circuit.py
rename to sequence/components/circuit.py
diff --git a/src/components/detector.py b/sequence/components/detector.py
similarity index 100%
rename from src/components/detector.py
rename to sequence/components/detector.py
diff --git a/src/components/fiber_stretcher.py b/sequence/components/fiber_stretcher.py
similarity index 100%
rename from src/components/fiber_stretcher.py
rename to sequence/components/fiber_stretcher.py
diff --git a/src/components/interferometer.py b/sequence/components/interferometer.py
similarity index 100%
rename from src/components/interferometer.py
rename to sequence/components/interferometer.py
diff --git a/src/components/light_source.py b/sequence/components/light_source.py
similarity index 100%
rename from src/components/light_source.py
rename to sequence/components/light_source.py
diff --git a/src/components/memory.py b/sequence/components/memory.py
similarity index 100%
rename from src/components/memory.py
rename to sequence/components/memory.py
diff --git a/src/components/mirror.py b/sequence/components/mirror.py
similarity index 100%
rename from src/components/mirror.py
rename to sequence/components/mirror.py
diff --git a/src/components/optical_channel.py b/sequence/components/optical_channel.py
similarity index 90%
rename from src/components/optical_channel.py
rename to sequence/components/optical_channel.py
index 89c650bd..24147b95 100644
--- a/src/components/optical_channel.py
+++ b/sequence/components/optical_channel.py
@@ -27,7 +27,7 @@ class OpticalChannel(Entity):
         name (str): label for channel instance.
         timeline (Timeline): timeline for simulation.
         sender (Node): node at sending end of optical channel.
-        receiver (Node): node at receiving end of optical channel.
+        receiver (str): name of the node at receiving end of optical channel.
         attenuation (float): attenuation of the fiber (in dB/m).
         distance (int): length of the fiber (in m).
         polarization_fidelity (float): probability of no polarization error for a transmitted qubit.
@@ -71,7 +71,7 @@ class QuantumChannel(OpticalChannel):
         name (str): label for channel instance.
         timeline (Timeline): timeline for simulation.
         sender (Node): node at sending end of optical channel.
-        receiver (Node): node at receiving end of optical channel.
+        receiver (str): name of the node at receiving end of optical channel.
         attenuation (float): attenuation of the fiber (in dB/m).
         distance (int): length of the fiber (in m).
         polarization_fidelity (float): probability of no polarization error for a transmitted qubit.
@@ -117,10 +117,7 @@ def set_ends(self, sender: "Node", receiver: str) -> None:
             receiver (str): name of node receiving qubits.
         """
 
-        log.logger.info(
-            "Set {} {} as ends of quantum channel {}".format(sender.name,
-                                                             receiver,
-                                                             self.name))
+        log.logger.info("Set {} {} as ends of quantum channel {}".format(sender.name, receiver, self.name))
         self.sender = sender
         self.receiver = receiver
         sender.assign_qchannel(self, receiver)
@@ -136,10 +133,8 @@ def transmit(self, qubit: "Photon", source: "Node") -> None:
             Receiver node may receive the qubit (via the `receive_qubit` method).
         """
 
-        log.logger.info(
-            "{} send qubit with state {} to {} by Channel {}".format(
-                self.sender.name, qubit.quantum_state, self.receiver,
-                self.name))
+        log.logger.info("{} send qubit with state {} to {} by Channel {}".format(
+                        self.sender.name, qubit.quantum_state, self.receiver, self.name))
 
         assert self.delay >= 0 and self.loss < 1, \
             "QuantumChannel init() function has not been run for {}".format(self.name)
@@ -233,7 +228,7 @@ class ClassicalChannel(OpticalChannel):
         name (str): label for channel instance.
         timeline (Timeline): timeline for simulation.
         sender (Node): node at sending end of optical channel.
-        receiver (Node): node at receiving end of optical channel.
+        receiver (str): name of the node at receiving end of optical channel.
         distance (float): length of the fiber (in m).
         delay (float): delay (in ps) of message transmission (default distance / light_speed).
     """
@@ -264,10 +259,7 @@ def set_ends(self, sender: "Node", receiver: str) -> None:
             receiver (str): name of node receiving classical messages.
         """
 
-        log.logger.info(
-            "Set {} {} as ends of classical channel {}".format(sender.name,
-                                                               receiver,
-                                                               self.name))
+        log.logger.info("Set {} {} as ends of classical channel {}".format(sender.name, receiver, self.name))
         self.sender = sender
         self.receiver = receiver
         sender.assign_cchannel(self, receiver)
@@ -284,11 +276,7 @@ def transmit(self, message: "Message", source: "Node", priority: int) -> None:
             Receiver node may receive the qubit (via the `receive_qubit` method).
         """
 
-        log.logger.info(
-            "{} send message {} to {} by Channel {}".format(self.sender.name,
-                                                            message,
-                                                            self.receiver,
-                                                            self.name))
+        log.logger.info("{} send message {} to {} by Channel {}".format(self.sender.name, message, self.receiver, self.name))
         assert source == self.sender
 
         future_time = round(self.timeline.now() + int(self.delay))
diff --git a/src/components/photon.py b/sequence/components/photon.py
similarity index 100%
rename from src/components/photon.py
rename to sequence/components/photon.py
diff --git a/src/components/spdc_lens.py b/sequence/components/spdc_lens.py
similarity index 100%
rename from src/components/spdc_lens.py
rename to sequence/components/spdc_lens.py
diff --git a/src/components/switch.py b/sequence/components/switch.py
similarity index 100%
rename from src/components/switch.py
rename to sequence/components/switch.py
diff --git a/src/entanglement_management/__init__.py b/sequence/entanglement_management/__init__.py
similarity index 100%
rename from src/entanglement_management/__init__.py
rename to sequence/entanglement_management/__init__.py
diff --git a/src/entanglement_management/entanglement_protocol.py b/sequence/entanglement_management/entanglement_protocol.py
similarity index 100%
rename from src/entanglement_management/entanglement_protocol.py
rename to sequence/entanglement_management/entanglement_protocol.py
diff --git a/src/entanglement_management/generation.py b/sequence/entanglement_management/generation.py
similarity index 100%
rename from src/entanglement_management/generation.py
rename to sequence/entanglement_management/generation.py
diff --git a/src/entanglement_management/purification.py b/sequence/entanglement_management/purification.py
similarity index 98%
rename from src/entanglement_management/purification.py
rename to sequence/entanglement_management/purification.py
index a2a801c7..09818318 100644
--- a/src/entanglement_management/purification.py
+++ b/sequence/entanglement_management/purification.py
@@ -41,6 +41,9 @@ def __init__(self, msg_type: BBPSSWMsgType, receiver: str, **kwargs):
             self.meas_res = kwargs['meas_res']
         else:
             raise Exception("BBPSSW protocol create unknown type of message: %s" % str(msg_type))
+    
+    def __str__(self):
+        return f"\"BBPSSW: type={self.msg_type}, meas_res={self.meas_res}\""
 
 
 class BBPSSW(EntanglementProtocol):
diff --git a/src/entanglement_management/swapping.py b/sequence/entanglement_management/swapping.py
similarity index 100%
rename from src/entanglement_management/swapping.py
rename to sequence/entanglement_management/swapping.py
diff --git a/src/gui/__init__.py b/sequence/gui/__init__.py
similarity index 100%
rename from src/gui/__init__.py
rename to sequence/gui/__init__.py
diff --git a/src/gui/app.py b/sequence/gui/app.py
similarity index 100%
rename from src/gui/app.py
rename to sequence/gui/app.py
diff --git a/src/gui/assets/argonne.png b/sequence/gui/assets/argonne.png
similarity index 100%
rename from src/gui/assets/argonne.png
rename to sequence/gui/assets/argonne.png
diff --git a/src/gui/assets/attributions_req b/sequence/gui/assets/attributions_req
similarity index 100%
rename from src/gui/assets/attributions_req
rename to sequence/gui/assets/attributions_req
diff --git a/src/gui/assets/bsmnode.png b/sequence/gui/assets/bsmnode.png
similarity index 100%
rename from src/gui/assets/bsmnode.png
rename to sequence/gui/assets/bsmnode.png
diff --git a/src/gui/assets/detector.png b/sequence/gui/assets/detector.png
similarity index 100%
rename from src/gui/assets/detector.png
rename to sequence/gui/assets/detector.png
diff --git a/src/gui/assets/logo.png b/sequence/gui/assets/logo.png
similarity index 100%
rename from src/gui/assets/logo.png
rename to sequence/gui/assets/logo.png
diff --git a/src/gui/assets/photonsource.png b/sequence/gui/assets/photonsource.png
similarity index 100%
rename from src/gui/assets/photonsource.png
rename to sequence/gui/assets/photonsource.png
diff --git a/src/gui/assets/quantum.png b/sequence/gui/assets/quantum.png
similarity index 100%
rename from src/gui/assets/quantum.png
rename to sequence/gui/assets/quantum.png
diff --git a/src/gui/assets/repeater.png b/sequence/gui/assets/repeater.png
similarity index 100%
rename from src/gui/assets/repeater.png
rename to sequence/gui/assets/repeater.png
diff --git a/src/gui/assets/router.png b/sequence/gui/assets/router.png
similarity index 100%
rename from src/gui/assets/router.png
rename to sequence/gui/assets/router.png
diff --git a/src/gui/assets/sequence.jpg b/sequence/gui/assets/sequence.jpg
similarity index 100%
rename from src/gui/assets/sequence.jpg
rename to sequence/gui/assets/sequence.jpg
diff --git a/src/gui/assets/svg/bsmnode.svg b/sequence/gui/assets/svg/bsmnode.svg
similarity index 100%
rename from src/gui/assets/svg/bsmnode.svg
rename to sequence/gui/assets/svg/bsmnode.svg
diff --git a/src/gui/assets/svg/detector.svg b/sequence/gui/assets/svg/detector.svg
similarity index 100%
rename from src/gui/assets/svg/detector.svg
rename to sequence/gui/assets/svg/detector.svg
diff --git a/src/gui/assets/svg/photonsource.svg b/sequence/gui/assets/svg/photonsource.svg
similarity index 100%
rename from src/gui/assets/svg/photonsource.svg
rename to sequence/gui/assets/svg/photonsource.svg
diff --git a/src/gui/assets/svg/quantum.svg b/sequence/gui/assets/svg/quantum.svg
similarity index 100%
rename from src/gui/assets/svg/quantum.svg
rename to sequence/gui/assets/svg/quantum.svg
diff --git a/src/gui/assets/svg/repeater.svg b/sequence/gui/assets/svg/repeater.svg
similarity index 100%
rename from src/gui/assets/svg/repeater.svg
rename to sequence/gui/assets/svg/repeater.svg
diff --git a/src/gui/assets/svg/router.svg b/sequence/gui/assets/svg/router.svg
similarity index 100%
rename from src/gui/assets/svg/router.svg
rename to sequence/gui/assets/svg/router.svg
diff --git a/src/gui/assets/svg/temp.svg b/sequence/gui/assets/svg/temp.svg
similarity index 100%
rename from src/gui/assets/svg/temp.svg
rename to sequence/gui/assets/svg/temp.svg
diff --git a/src/gui/assets/temp.png b/sequence/gui/assets/temp.png
similarity index 100%
rename from src/gui/assets/temp.png
rename to sequence/gui/assets/temp.png
diff --git a/src/gui/css_styles.py b/sequence/gui/css_styles.py
similarity index 100%
rename from src/gui/css_styles.py
rename to sequence/gui/css_styles.py
diff --git a/src/gui/default_params.json b/sequence/gui/default_params.json
similarity index 100%
rename from src/gui/default_params.json
rename to sequence/gui/default_params.json
diff --git a/src/gui/default_templates.json b/sequence/gui/default_templates.json
similarity index 100%
rename from src/gui/default_templates.json
rename to sequence/gui/default_templates.json
diff --git a/src/gui/graph_comp.py b/sequence/gui/graph_comp.py
similarity index 100%
rename from src/gui/graph_comp.py
rename to sequence/gui/graph_comp.py
diff --git a/src/gui/layout.py b/sequence/gui/layout.py
similarity index 100%
rename from src/gui/layout.py
rename to sequence/gui/layout.py
diff --git a/src/gui/menus.py b/sequence/gui/menus.py
similarity index 100%
rename from src/gui/menus.py
rename to sequence/gui/menus.py
diff --git a/src/gui/run_gui.py b/sequence/gui/run_gui.py
similarity index 100%
rename from src/gui/run_gui.py
rename to sequence/gui/run_gui.py
diff --git a/src/gui/simulator_bindings.py b/sequence/gui/simulator_bindings.py
similarity index 100%
rename from src/gui/simulator_bindings.py
rename to sequence/gui/simulator_bindings.py
diff --git a/src/gui/starlight.json b/sequence/gui/starlight.json
similarity index 100%
rename from src/gui/starlight.json
rename to sequence/gui/starlight.json
diff --git a/src/gui/user_templates.json b/sequence/gui/user_templates.json
similarity index 100%
rename from src/gui/user_templates.json
rename to sequence/gui/user_templates.json
diff --git a/src/kernel/__init__.py b/sequence/kernel/__init__.py
similarity index 100%
rename from src/kernel/__init__.py
rename to sequence/kernel/__init__.py
diff --git a/src/kernel/entity.py b/sequence/kernel/entity.py
similarity index 100%
rename from src/kernel/entity.py
rename to sequence/kernel/entity.py
diff --git a/src/kernel/event.py b/sequence/kernel/event.py
similarity index 100%
rename from src/kernel/event.py
rename to sequence/kernel/event.py
diff --git a/src/kernel/eventlist.py b/sequence/kernel/eventlist.py
similarity index 100%
rename from src/kernel/eventlist.py
rename to sequence/kernel/eventlist.py
diff --git a/src/kernel/process.py b/sequence/kernel/process.py
similarity index 100%
rename from src/kernel/process.py
rename to sequence/kernel/process.py
diff --git a/src/kernel/quantum_manager.py b/sequence/kernel/quantum_manager.py
similarity index 100%
rename from src/kernel/quantum_manager.py
rename to sequence/kernel/quantum_manager.py
diff --git a/src/kernel/quantum_state.py b/sequence/kernel/quantum_state.py
similarity index 100%
rename from src/kernel/quantum_state.py
rename to sequence/kernel/quantum_state.py
diff --git a/src/kernel/quantum_utils.py b/sequence/kernel/quantum_utils.py
similarity index 100%
rename from src/kernel/quantum_utils.py
rename to sequence/kernel/quantum_utils.py
diff --git a/src/kernel/timeline.py b/sequence/kernel/timeline.py
similarity index 100%
rename from src/kernel/timeline.py
rename to sequence/kernel/timeline.py
diff --git a/src/message.py b/sequence/message.py
similarity index 100%
rename from src/message.py
rename to sequence/message.py
diff --git a/src/network_management/__init__.py b/sequence/network_management/__init__.py
similarity index 100%
rename from src/network_management/__init__.py
rename to sequence/network_management/__init__.py
diff --git a/src/network_management/network_manager.py b/sequence/network_management/network_manager.py
similarity index 100%
rename from src/network_management/network_manager.py
rename to sequence/network_management/network_manager.py
diff --git a/src/network_management/reservation.py b/sequence/network_management/reservation.py
similarity index 100%
rename from src/network_management/reservation.py
rename to sequence/network_management/reservation.py
diff --git a/src/network_management/routing.py b/sequence/network_management/routing.py
similarity index 100%
rename from src/network_management/routing.py
rename to sequence/network_management/routing.py
diff --git a/src/protocol.py b/sequence/protocol.py
similarity index 100%
rename from src/protocol.py
rename to sequence/protocol.py
diff --git a/src/qkd/BB84.py b/sequence/qkd/BB84.py
similarity index 100%
rename from src/qkd/BB84.py
rename to sequence/qkd/BB84.py
diff --git a/src/qkd/__init__.py b/sequence/qkd/__init__.py
similarity index 100%
rename from src/qkd/__init__.py
rename to sequence/qkd/__init__.py
diff --git a/src/qkd/cascade.py b/sequence/qkd/cascade.py
similarity index 100%
rename from src/qkd/cascade.py
rename to sequence/qkd/cascade.py
diff --git a/src/resource_management/__init__.py b/sequence/resource_management/__init__.py
similarity index 100%
rename from src/resource_management/__init__.py
rename to sequence/resource_management/__init__.py
diff --git a/src/resource_management/memory_manager.py b/sequence/resource_management/memory_manager.py
similarity index 100%
rename from src/resource_management/memory_manager.py
rename to sequence/resource_management/memory_manager.py
diff --git a/src/resource_management/resource_manager.py b/sequence/resource_management/resource_manager.py
similarity index 100%
rename from src/resource_management/resource_manager.py
rename to sequence/resource_management/resource_manager.py
diff --git a/src/resource_management/rule_manager.py b/sequence/resource_management/rule_manager.py
similarity index 100%
rename from src/resource_management/rule_manager.py
rename to sequence/resource_management/rule_manager.py
diff --git a/src/topology/__init__.py b/sequence/topology/__init__.py
similarity index 100%
rename from src/topology/__init__.py
rename to sequence/topology/__init__.py
diff --git a/src/topology/node.py b/sequence/topology/node.py
similarity index 100%
rename from src/topology/node.py
rename to sequence/topology/node.py
diff --git a/src/topology/qkd_topo.py b/sequence/topology/qkd_topo.py
similarity index 100%
rename from src/topology/qkd_topo.py
rename to sequence/topology/qkd_topo.py
diff --git a/src/topology/router_net_topo.py b/sequence/topology/router_net_topo.py
similarity index 100%
rename from src/topology/router_net_topo.py
rename to sequence/topology/router_net_topo.py
diff --git a/src/topology/topology.py b/sequence/topology/topology.py
similarity index 100%
rename from src/topology/topology.py
rename to sequence/topology/topology.py
diff --git a/src/utils/__init__.py b/sequence/utils/__init__.py
similarity index 100%
rename from src/utils/__init__.py
rename to sequence/utils/__init__.py
diff --git a/src/utils/encoding.py b/sequence/utils/encoding.py
similarity index 100%
rename from src/utils/encoding.py
rename to sequence/utils/encoding.py
diff --git a/src/utils/log.py b/sequence/utils/log.py
similarity index 100%
rename from src/utils/log.py
rename to sequence/utils/log.py
diff --git a/setup.py b/setup.py
index 96af5754..0ea109d0 100644
--- a/setup.py
+++ b/setup.py
@@ -6,11 +6,11 @@
     author="Xiaoliang Wu, Joaquin Chung, Alexander Kolar, Alexander Kiefer, Eugene Wang, Tian Zhong, Rajkumar Kettimuthu, Martin Suchara",
     author_email="xwu64@hawk.iit.edu, chungmiranda@anl.gov, akolar@anl.gov, akiefer@iu.edu, eugenewang@yahoo.com, tzh@uchicago.edu, kettimut@mcs.anl.gov, msuchara@anl.gov",
     description="Simulator of Quantum Network Communication: SEQUENCE-Python is a prototype version of the official SEQUENCE release.",
-    # packages = find_packages('src'),
+    # packages = find_packages('sequence'),
     packages=['sequence', 'sequence.app', 'sequence.kernel', 'sequence.components',
               'sequence.network_management', 'sequence.entanglement_management', 'sequence.qkd',
               'sequence.resource_management', 'sequence.topology', 'sequence.utils', 'sequence.gui'],
-    package_dir={'sequence': 'src'},
+    package_dir={'sequence': 'sequence'},
     package_data={'sequence': ['gui/user_templates.json', 'gui/default_params.json', 'gui/starlight.json']},
     include_package_data=True,
     install_requires=[


Test patch:
diff --git a/src/gui/test.txt b/sequence/gui/test.txt
similarity index 100%
rename from src/gui/test.txt
rename to sequence/gui/test.txt
diff --git a/tests/kernel/test_quantum_manager.py b/tests/kernel/test_quantum_manager.py
index 75c11c5c..67e95194 100644
--- a/tests/kernel/test_quantum_manager.py
+++ b/tests/kernel/test_quantum_manager.py
@@ -343,7 +343,7 @@ def test_qmanager__measure_density():
     assert abs((len(meas_0) / NUM_TESTS) - 0.5) < 0.1
 
 
-def test_qmanager__prepare_state_fock():
+def test_qmanager_prepare_state_fock():
     qm = QuantumManagerDensityFock(truncation=2)
     state_0 = [1, 0, 0]
     state_1 = [0, 1, 0]