├── .eggs └── README.txt ├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md └── workflows │ ├── flake8.yml │ └── pytest.yml ├── .gitignore ├── LICENSE ├── README.html ├── README.md ├── docs ├── Makefile ├── build │ ├── doctrees │ │ ├── develop.doctree │ │ ├── environment.pickle │ │ ├── index.doctree │ │ ├── install.doctree │ │ ├── introduction.doctree │ │ ├── modules.doctree │ │ ├── qns.doctree │ │ ├── qns.entity.cchannel.doctree │ │ ├── qns.entity.doctree │ │ ├── qns.entity.memory.doctree │ │ ├── qns.entity.monitor.doctree │ │ ├── qns.entity.node.doctree │ │ ├── qns.entity.operator.doctree │ │ ├── qns.entity.qchannel.doctree │ │ ├── qns.entity.timer.doctree │ │ ├── qns.models.core.doctree │ │ ├── qns.models.delay.doctree │ │ ├── qns.models.doctree │ │ ├── qns.models.epr.doctree │ │ ├── qns.models.qubit.doctree │ │ ├── qns.network.doctree │ │ ├── qns.network.protocol.doctree │ │ ├── qns.network.route.doctree │ │ ├── qns.network.topology.doctree │ │ ├── qns.simulator.doctree │ │ ├── qns.utils.doctree │ │ ├── tutorials.doctree │ │ ├── tutorials.entity.cchannel.doctree │ │ ├── tutorials.entity.doctree │ │ ├── tutorials.entity.memory.doctree │ │ ├── tutorials.entity.monitor.doctree │ │ ├── tutorials.entity.node.doctree │ │ ├── tutorials.entity.operator.doctree │ │ ├── tutorials.entity.other.doctree │ │ ├── tutorials.entity.qchannel.doctree │ │ ├── tutorials.models.delay.doctree │ │ ├── tutorials.models.doctree │ │ ├── tutorials.models.epr.doctree │ │ ├── tutorials.models.model.doctree │ │ ├── tutorials.models.qubit.doctree │ │ ├── tutorials.network.doctree │ │ ├── tutorials.network.protocol.doctree │ │ ├── tutorials.network.request.doctree │ │ ├── tutorials.network.route.doctree │ │ ├── tutorials.network.topology.doctree │ │ ├── tutorials.parallel_simulation.doctree │ │ ├── tutorials.quickstart.doctree │ │ ├── tutorials.simulator.doctree │ │ └── tutorials.util.doctree │ └── html │ │ ├── .buildinfo │ │ ├── .nojekyll │ │ ├── _images │ │ └── modules.png │ │ ├── _modules │ │ ├── index.html │ │ └── qns │ │ │ ├── entity │ │ │ ├── cchannel │ │ │ │ └── cchannel.html │ │ │ ├── entity.html │ │ │ ├── memory │ │ │ │ ├── event.html │ │ │ │ └── memory.html │ │ │ ├── monitor │ │ │ │ └── monitor.html │ │ │ ├── node │ │ │ │ ├── app.html │ │ │ │ └── node.html │ │ │ ├── operator │ │ │ │ ├── event.html │ │ │ │ └── operator.html │ │ │ ├── qchannel │ │ │ │ ├── losschannel.html │ │ │ │ └── qchannel.html │ │ │ └── timer │ │ │ │ └── timer.html │ │ │ ├── models │ │ │ ├── core │ │ │ │ └── backend.html │ │ │ ├── delay │ │ │ │ ├── constdelay.html │ │ │ │ ├── delay.html │ │ │ │ ├── normaldelay.html │ │ │ │ └── uniformdelay.html │ │ │ ├── epr │ │ │ │ ├── bell.html │ │ │ │ ├── entanglement.html │ │ │ │ ├── mixed.html │ │ │ │ └── werner.html │ │ │ └── qubit │ │ │ │ ├── const.html │ │ │ │ ├── decoherence.html │ │ │ │ ├── errors.html │ │ │ │ ├── factory.html │ │ │ │ ├── gate.html │ │ │ │ ├── qubit.html │ │ │ │ └── utils.html │ │ │ ├── network │ │ │ ├── network.html │ │ │ ├── protocol │ │ │ │ ├── bb84.html │ │ │ │ ├── classicforward.html │ │ │ │ ├── entanglement_distribution.html │ │ │ │ └── node_process_delay.html │ │ │ ├── requests.html │ │ │ ├── route │ │ │ │ ├── dijkstra.html │ │ │ │ └── route.html │ │ │ └── topology │ │ │ │ ├── basictopo.html │ │ │ │ ├── gridtopo.html │ │ │ │ ├── linetopo.html │ │ │ │ ├── randomtopo.html │ │ │ │ ├── topo.html │ │ │ │ ├── treetopo.html │ │ │ │ └── waxmantopo.html │ │ │ ├── simulator │ │ │ ├── event.html │ │ │ ├── pool.html │ │ │ ├── simulator.html │ │ │ └── ts.html │ │ │ └── utils │ │ │ ├── log.html │ │ │ ├── multiprocess.html │ │ │ ├── random.html │ │ │ └── rnd.html │ │ ├── _sources │ │ ├── develop.rst.txt │ │ ├── index.rst.txt │ │ ├── install.rst.txt │ │ ├── introduction.rst.txt │ │ ├── modules.rst.txt │ │ ├── qns.entity.cchannel.rst.txt │ │ ├── qns.entity.memory.rst.txt │ │ ├── qns.entity.monitor.rst.txt │ │ ├── qns.entity.node.rst.txt │ │ ├── qns.entity.operator.rst.txt │ │ ├── qns.entity.qchannel.rst.txt │ │ ├── qns.entity.rst.txt │ │ ├── qns.entity.timer.rst.txt │ │ ├── qns.models.core.rst.txt │ │ ├── qns.models.delay.rst.txt │ │ ├── qns.models.epr.rst.txt │ │ ├── qns.models.qubit.rst.txt │ │ ├── qns.models.rst.txt │ │ ├── qns.network.protocol.rst.txt │ │ ├── qns.network.route.rst.txt │ │ ├── qns.network.rst.txt │ │ ├── qns.network.topology.rst.txt │ │ ├── qns.rst.txt │ │ ├── qns.simulator.rst.txt │ │ ├── qns.utils.rst.txt │ │ ├── tutorials.entity.cchannel.rst.txt │ │ ├── tutorials.entity.memory.rst.txt │ │ ├── tutorials.entity.monitor.rst.txt │ │ ├── tutorials.entity.node.rst.txt │ │ ├── tutorials.entity.operator.rst.txt │ │ ├── tutorials.entity.other.rst.txt │ │ ├── tutorials.entity.qchannel.rst.txt │ │ ├── tutorials.entity.rst.txt │ │ ├── tutorials.models.delay.rst.txt │ │ ├── tutorials.models.epr.rst.txt │ │ ├── tutorials.models.model.rst.txt │ │ ├── tutorials.models.qubit.rst.txt │ │ ├── tutorials.models.rst.txt │ │ ├── tutorials.network.protocol.rst.txt │ │ ├── tutorials.network.request.rst.txt │ │ ├── tutorials.network.route.rst.txt │ │ ├── tutorials.network.rst.txt │ │ ├── tutorials.network.topology.rst.txt │ │ ├── tutorials.parallel_simulation.rst.txt │ │ ├── tutorials.quickstart.rst.txt │ │ ├── tutorials.rst.txt │ │ ├── tutorials.simulator.rst.txt │ │ └── tutorials.util.rst.txt │ │ ├── _static │ │ ├── basic.css │ │ ├── css │ │ │ ├── badge_only.css │ │ │ ├── fonts │ │ │ │ ├── Roboto-Slab-Bold.woff │ │ │ │ ├── Roboto-Slab-Bold.woff2 │ │ │ │ ├── Roboto-Slab-Regular.woff │ │ │ │ ├── Roboto-Slab-Regular.woff2 │ │ │ │ ├── fontawesome-webfont.eot │ │ │ │ ├── fontawesome-webfont.svg │ │ │ │ ├── fontawesome-webfont.ttf │ │ │ │ ├── fontawesome-webfont.woff │ │ │ │ ├── fontawesome-webfont.woff2 │ │ │ │ ├── lato-bold-italic.woff │ │ │ │ ├── lato-bold-italic.woff2 │ │ │ │ ├── lato-bold.woff │ │ │ │ ├── lato-bold.woff2 │ │ │ │ ├── lato-normal-italic.woff │ │ │ │ ├── lato-normal-italic.woff2 │ │ │ │ ├── lato-normal.woff │ │ │ │ └── lato-normal.woff2 │ │ │ └── theme.css │ │ ├── doctools.js │ │ ├── documentation_options.js │ │ ├── file.png │ │ ├── jquery-3.5.1.js │ │ ├── jquery.js │ │ ├── js │ │ │ ├── badge_only.js │ │ │ ├── html5shiv-printshiv.min.js │ │ │ ├── html5shiv.min.js │ │ │ └── theme.js │ │ ├── language_data.js │ │ ├── minus.png │ │ ├── modules.png │ │ ├── plus.png │ │ ├── pygments.css │ │ ├── searchtools.js │ │ ├── underscore-1.13.1.js │ │ └── underscore.js │ │ ├── develop.html │ │ ├── genindex.html │ │ ├── index.html │ │ ├── install.html │ │ ├── introduction.html │ │ ├── modules.html │ │ ├── objects.inv │ │ ├── py-modindex.html │ │ ├── qns.entity.cchannel.html │ │ ├── qns.entity.html │ │ ├── qns.entity.memory.html │ │ ├── qns.entity.monitor.html │ │ ├── qns.entity.node.html │ │ ├── qns.entity.operator.html │ │ ├── qns.entity.qchannel.html │ │ ├── qns.entity.timer.html │ │ ├── qns.html │ │ ├── qns.models.core.html │ │ ├── qns.models.delay.html │ │ ├── qns.models.epr.html │ │ ├── qns.models.html │ │ ├── qns.models.qubit.html │ │ ├── qns.network.html │ │ ├── qns.network.protocol.html │ │ ├── qns.network.route.html │ │ ├── qns.network.topology.html │ │ ├── qns.simulator.html │ │ ├── qns.utils.html │ │ ├── search.html │ │ ├── searchindex.js │ │ ├── tutorials.entity.cchannel.html │ │ ├── tutorials.entity.html │ │ ├── tutorials.entity.memory.html │ │ ├── tutorials.entity.monitor.html │ │ ├── tutorials.entity.node.html │ │ ├── tutorials.entity.operator.html │ │ ├── tutorials.entity.other.html │ │ ├── tutorials.entity.qchannel.html │ │ ├── tutorials.html │ │ ├── tutorials.models.delay.html │ │ ├── tutorials.models.epr.html │ │ ├── tutorials.models.html │ │ ├── tutorials.models.model.html │ │ ├── tutorials.models.qubit.html │ │ ├── tutorials.network.html │ │ ├── tutorials.network.protocol.html │ │ ├── tutorials.network.request.html │ │ ├── tutorials.network.route.html │ │ ├── tutorials.network.topology.html │ │ ├── tutorials.parallel_simulation.html │ │ ├── tutorials.quickstart.html │ │ ├── tutorials.simulator.html │ │ └── tutorials.util.html ├── make.bat └── source │ ├── .nojekyll │ ├── _imgs │ └── modules.png │ ├── conf.py │ ├── develop.rst │ ├── index.rst │ ├── install.rst │ ├── introduction.rst │ ├── modules.rst │ ├── qns.entity.cchannel.rst │ ├── qns.entity.memory.rst │ ├── qns.entity.monitor.rst │ ├── qns.entity.node.rst │ ├── qns.entity.operator.rst │ ├── qns.entity.qchannel.rst │ ├── qns.entity.rst │ ├── qns.entity.timer.rst │ ├── qns.models.core.rst │ ├── qns.models.delay.rst │ ├── qns.models.epr.rst │ ├── qns.models.qubit.rst │ ├── qns.models.rst │ ├── qns.network.protocol.rst │ ├── qns.network.route.rst │ ├── qns.network.rst │ ├── qns.network.topology.rst │ ├── qns.rst │ ├── qns.simulator.rst │ ├── qns.utils.rst │ ├── tutorials.entity.cchannel.rst │ ├── tutorials.entity.memory.rst │ ├── tutorials.entity.monitor.rst │ ├── tutorials.entity.node.rst │ ├── tutorials.entity.operator.rst │ ├── tutorials.entity.other.rst │ ├── tutorials.entity.qchannel.rst │ ├── tutorials.entity.rst │ ├── tutorials.models.delay.rst │ ├── tutorials.models.epr.rst │ ├── tutorials.models.qubit.rst │ ├── tutorials.models.rst │ ├── tutorials.network.request.rst │ ├── tutorials.network.route.rst │ ├── tutorials.network.rst │ ├── tutorials.network.topology.rst │ ├── tutorials.parallel_simulation.rst │ ├── tutorials.quickstart.rst │ ├── tutorials.rst │ ├── tutorials.simulator.rst │ └── tutorials.util.rst ├── examples ├── DEJMPS.py ├── classic_communication.py ├── classic_packet_forward.py ├── entanglement_distribution_line_topo.py ├── entanglement_distribution_random_topo.py ├── entanglement_swapping.py ├── parallel_experiments.py ├── simple_bb84.py └── trusted_relay_bb84.py ├── qns ├── __init__.py ├── entity │ ├── __init__.py │ ├── cchannel │ │ ├── __init__.py │ │ └── cchannel.py │ ├── entity.py │ ├── memory │ │ ├── __init__.py │ │ ├── event.py │ │ └── memory.py │ ├── monitor │ │ ├── __init__.py │ │ └── monitor.py │ ├── node │ │ ├── __init__.py │ │ ├── app.py │ │ └── node.py │ ├── operator │ │ ├── __init__.py │ │ ├── event.py │ │ └── operator.py │ ├── qchannel │ │ ├── __init__.py │ │ ├── losschannel.py │ │ └── qchannel.py │ └── timer │ │ ├── __init__.py │ │ └── timer.py ├── models │ ├── __init__.py │ ├── core │ │ ├── __init__.py │ │ └── backend.py │ ├── delay │ │ ├── __init__.py │ │ ├── constdelay.py │ │ ├── delay.py │ │ ├── normaldelay.py │ │ └── uniformdelay.py │ ├── epr │ │ ├── __init__.py │ │ ├── bell.py │ │ ├── entanglement.py │ │ ├── mixed.py │ │ └── werner.py │ └── qubit │ │ ├── __init__.py │ │ ├── const.py │ │ ├── decoherence.py │ │ ├── errors.py │ │ ├── factory.py │ │ ├── gate.py │ │ ├── qubit.py │ │ └── utils.py ├── network │ ├── __init__.py │ ├── network.py │ ├── protocol │ │ ├── __init__.py │ │ ├── bb84.py │ │ ├── classicforward.py │ │ ├── entanglement_distribution.py │ │ └── node_process_delay.py │ ├── requests.py │ ├── route │ │ ├── __init__.py │ │ ├── dijkstra.py │ │ └── route.py │ └── topology │ │ ├── __init__.py │ │ ├── barabasialberttopo.py │ │ ├── basictopo.py │ │ ├── dualbarabasialberttopo.py │ │ ├── erdosrenyitopo.py │ │ ├── gridtopo.py │ │ ├── linetopo.py │ │ ├── randomtopo.py │ │ ├── topo.py │ │ ├── treetopo.py │ │ └── waxmantopo.py ├── simulator │ ├── __init__.py │ ├── event.py │ ├── pool.py │ ├── pool.pyx │ ├── simulator.py │ ├── ts.py │ └── ts.pyx └── utils │ ├── __init__.py │ ├── log.py │ ├── multiprocess.py │ └── rnd.py ├── requirements.txt ├── setup-cython.py ├── setup.py ├── test ├── entity │ ├── test_cchannel.py │ ├── test_memory.py │ ├── test_monitor.py │ ├── test_operator.py │ ├── test_qchannel.py │ └── test_timer.py ├── models │ ├── epr │ │ ├── test_bell_state.py │ │ ├── test_mixed_state.py │ │ └── test_werner_state.py │ └── qubit │ │ ├── test_qubit.py │ │ ├── test_qubit_dissipation.py │ │ ├── test_qubit_error.py │ │ ├── test_stochastic_operate.py │ │ └── test_swapping.py ├── network │ ├── test_barabasialberttopo.py │ ├── test_basictopo.py │ ├── test_dualbarabasialberttopo.py │ ├── test_erdosrenyitopo.py │ ├── test_gridtopo.py │ ├── test_linetopo.py │ ├── test_randomtopo.py │ ├── test_route.py │ ├── test_treetopo.py │ └── test_waxman_topo.py ├── protocol │ ├── test_bb84.py │ ├── test_classic_forward.py │ ├── test_entanglement_distribution.py │ └── test_process_delay.py ├── simulator │ ├── test_event.py │ ├── test_multiple_process.py │ ├── test_simulator.py │ └── test_time.py └── test_example_readme.py └── tox.ini /.eggs/README.txt: -------------------------------------------------------------------------------- 1 | This directory contains eggs that were downloaded by setuptools to build, test, and run plug-ins. 2 | 3 | This directory caches those eggs to prevent repeated downloads. 4 | 5 | However, it is safe to delete this directory. 6 | 7 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | 31 | **Smartphone (please complete the following information):** 32 | - Device: [e.g. iPhone6] 33 | - OS: [e.g. iOS8.1] 34 | - Browser [e.g. stock browser, safari] 35 | - Version [e.g. 22] 36 | 37 | **Additional context** 38 | Add any other context about the problem here. 39 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/workflows/flake8.yml: -------------------------------------------------------------------------------- 1 | name: Flake8 Lint 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | flake8-lint: 7 | runs-on: ubuntu-latest 8 | name: Lint 9 | steps: 10 | - name: Check out source repository 11 | uses: actions/checkout@v4 12 | - name: Set up Python environment 13 | uses: actions/setup-python@v5 14 | with: 15 | python-version: "3.9" 16 | - name: flake8 Lint 17 | uses: py-actions/flake8@v2 18 | with: 19 | ignore: "E741,E743,E121,E123,E126,E226,E24,E704,W503,W504" 20 | max-line-length: "128" 21 | -------------------------------------------------------------------------------- /.github/workflows/pytest.yml: -------------------------------------------------------------------------------- 1 | # This is a basic workflow to help you get started with Actions 2 | 3 | name: Pytest 4 | 5 | # Controls when the workflow will run 6 | on: 7 | # Triggers the workflow on push or pull request events but only for the main branch 8 | push: 9 | branches: [ main ] 10 | pull_request: 11 | branches: [ main ] 12 | 13 | # Allows you to run this workflow manually from the Actions tab 14 | workflow_dispatch: 15 | 16 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel 17 | jobs: 18 | # This workflow contains a single job called "build" 19 | build: 20 | # The type of runner that the job will run on 21 | runs-on: ubuntu-latest 22 | 23 | # Steps represent a sequence of tasks that will be executed as part of the job 24 | steps: 25 | # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it 26 | - uses: actions/checkout@v4 27 | - uses: actions/setup-python@v5 28 | with: 29 | python-version: '3.9' # Version range or exact version of a Python version to use, using SemVer's version range syntax 30 | architecture: 'x64' # optional x64 or x86. Defaults to x64 if not specified 31 | cache: 'pip' 32 | cache-dependency-path: requirements.txt # Path to a requirements file to use for caching dependencies 33 | 34 | # Runs a set of commands using the runners shell 35 | - name: Setup packets 36 | run: | 37 | pip3 install -r requirements.txt 38 | python setup.py develop 39 | 40 | - name: Run tests 41 | run: python3 -m pytest 42 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | **/.DS_Store 2 | env 3 | /build 4 | exp 5 | dist 6 | qns.egg-info 7 | qns/**/*.c 8 | qns/**/*.so 9 | qns/**/*.pyd 10 | **/__pycache__ 11 | .vscode 12 | .cspell 13 | .pytest_cache 14 | !docs 15 | .idea 16 | .eggs -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line, and also 5 | # from the environment for the first two. 6 | SPHINXOPTS ?= 7 | SPHINXBUILD ?= sphinx-build 8 | SOURCEDIR = source 9 | BUILDDIR = build 10 | 11 | # Put it first so that "make" without argument is like "make help". 12 | help: 13 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 14 | 15 | .PHONY: help Makefile 16 | 17 | # Catch-all target: route all unknown targets to Sphinx using the new 18 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 19 | %: Makefile 20 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 21 | -------------------------------------------------------------------------------- /docs/build/doctrees/develop.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/doctrees/develop.doctree -------------------------------------------------------------------------------- /docs/build/doctrees/environment.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/doctrees/environment.pickle -------------------------------------------------------------------------------- /docs/build/doctrees/index.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/doctrees/index.doctree -------------------------------------------------------------------------------- /docs/build/doctrees/install.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/doctrees/install.doctree -------------------------------------------------------------------------------- /docs/build/doctrees/introduction.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/doctrees/introduction.doctree -------------------------------------------------------------------------------- /docs/build/doctrees/modules.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/doctrees/modules.doctree -------------------------------------------------------------------------------- /docs/build/doctrees/qns.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/doctrees/qns.doctree -------------------------------------------------------------------------------- /docs/build/doctrees/qns.entity.cchannel.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/doctrees/qns.entity.cchannel.doctree -------------------------------------------------------------------------------- /docs/build/doctrees/qns.entity.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/doctrees/qns.entity.doctree -------------------------------------------------------------------------------- /docs/build/doctrees/qns.entity.memory.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/doctrees/qns.entity.memory.doctree -------------------------------------------------------------------------------- /docs/build/doctrees/qns.entity.monitor.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/doctrees/qns.entity.monitor.doctree -------------------------------------------------------------------------------- /docs/build/doctrees/qns.entity.node.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/doctrees/qns.entity.node.doctree -------------------------------------------------------------------------------- /docs/build/doctrees/qns.entity.operator.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/doctrees/qns.entity.operator.doctree -------------------------------------------------------------------------------- /docs/build/doctrees/qns.entity.qchannel.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/doctrees/qns.entity.qchannel.doctree -------------------------------------------------------------------------------- /docs/build/doctrees/qns.entity.timer.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/doctrees/qns.entity.timer.doctree -------------------------------------------------------------------------------- /docs/build/doctrees/qns.models.core.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/doctrees/qns.models.core.doctree -------------------------------------------------------------------------------- /docs/build/doctrees/qns.models.delay.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/doctrees/qns.models.delay.doctree -------------------------------------------------------------------------------- /docs/build/doctrees/qns.models.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/doctrees/qns.models.doctree -------------------------------------------------------------------------------- /docs/build/doctrees/qns.models.epr.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/doctrees/qns.models.epr.doctree -------------------------------------------------------------------------------- /docs/build/doctrees/qns.models.qubit.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/doctrees/qns.models.qubit.doctree -------------------------------------------------------------------------------- /docs/build/doctrees/qns.network.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/doctrees/qns.network.doctree -------------------------------------------------------------------------------- /docs/build/doctrees/qns.network.protocol.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/doctrees/qns.network.protocol.doctree -------------------------------------------------------------------------------- /docs/build/doctrees/qns.network.route.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/doctrees/qns.network.route.doctree -------------------------------------------------------------------------------- /docs/build/doctrees/qns.network.topology.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/doctrees/qns.network.topology.doctree -------------------------------------------------------------------------------- /docs/build/doctrees/qns.simulator.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/doctrees/qns.simulator.doctree -------------------------------------------------------------------------------- /docs/build/doctrees/qns.utils.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/doctrees/qns.utils.doctree -------------------------------------------------------------------------------- /docs/build/doctrees/tutorials.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/doctrees/tutorials.doctree -------------------------------------------------------------------------------- /docs/build/doctrees/tutorials.entity.cchannel.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/doctrees/tutorials.entity.cchannel.doctree -------------------------------------------------------------------------------- /docs/build/doctrees/tutorials.entity.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/doctrees/tutorials.entity.doctree -------------------------------------------------------------------------------- /docs/build/doctrees/tutorials.entity.memory.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/doctrees/tutorials.entity.memory.doctree -------------------------------------------------------------------------------- /docs/build/doctrees/tutorials.entity.monitor.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/doctrees/tutorials.entity.monitor.doctree -------------------------------------------------------------------------------- /docs/build/doctrees/tutorials.entity.node.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/doctrees/tutorials.entity.node.doctree -------------------------------------------------------------------------------- /docs/build/doctrees/tutorials.entity.operator.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/doctrees/tutorials.entity.operator.doctree -------------------------------------------------------------------------------- /docs/build/doctrees/tutorials.entity.other.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/doctrees/tutorials.entity.other.doctree -------------------------------------------------------------------------------- /docs/build/doctrees/tutorials.entity.qchannel.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/doctrees/tutorials.entity.qchannel.doctree -------------------------------------------------------------------------------- /docs/build/doctrees/tutorials.models.delay.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/doctrees/tutorials.models.delay.doctree -------------------------------------------------------------------------------- /docs/build/doctrees/tutorials.models.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/doctrees/tutorials.models.doctree -------------------------------------------------------------------------------- /docs/build/doctrees/tutorials.models.epr.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/doctrees/tutorials.models.epr.doctree -------------------------------------------------------------------------------- /docs/build/doctrees/tutorials.models.model.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/doctrees/tutorials.models.model.doctree -------------------------------------------------------------------------------- /docs/build/doctrees/tutorials.models.qubit.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/doctrees/tutorials.models.qubit.doctree -------------------------------------------------------------------------------- /docs/build/doctrees/tutorials.network.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/doctrees/tutorials.network.doctree -------------------------------------------------------------------------------- /docs/build/doctrees/tutorials.network.protocol.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/doctrees/tutorials.network.protocol.doctree -------------------------------------------------------------------------------- /docs/build/doctrees/tutorials.network.request.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/doctrees/tutorials.network.request.doctree -------------------------------------------------------------------------------- /docs/build/doctrees/tutorials.network.route.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/doctrees/tutorials.network.route.doctree -------------------------------------------------------------------------------- /docs/build/doctrees/tutorials.network.topology.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/doctrees/tutorials.network.topology.doctree -------------------------------------------------------------------------------- /docs/build/doctrees/tutorials.parallel_simulation.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/doctrees/tutorials.parallel_simulation.doctree -------------------------------------------------------------------------------- /docs/build/doctrees/tutorials.quickstart.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/doctrees/tutorials.quickstart.doctree -------------------------------------------------------------------------------- /docs/build/doctrees/tutorials.simulator.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/doctrees/tutorials.simulator.doctree -------------------------------------------------------------------------------- /docs/build/doctrees/tutorials.util.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/doctrees/tutorials.util.doctree -------------------------------------------------------------------------------- /docs/build/html/.buildinfo: -------------------------------------------------------------------------------- 1 | # Sphinx build info version 1 2 | # This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. 3 | config: 6102d0d5f169590e5cf449252ef8ad0a 4 | tags: 645f666f9bcd5a90fca523b33c5a78b7 5 | -------------------------------------------------------------------------------- /docs/build/html/.nojekyll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/html/.nojekyll -------------------------------------------------------------------------------- /docs/build/html/_images/modules.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/html/_images/modules.png -------------------------------------------------------------------------------- /docs/build/html/_sources/develop.rst.txt: -------------------------------------------------------------------------------- 1 | Develop Guide 2 | ======================================= 3 | 4 | We prefer a standard development method. To ensure this, this guide explains the development rules and instructions. 5 | 6 | Code requirements 7 | --------------------------------------- 8 | 9 | Source code is hosted at `Github `_. Pull requests and issues are welcome. 10 | However, the following requirements need to be met: 11 | 12 | 1. Python codes and the variable's name should follow `PEP 8 `_ standard. An automatic `flake8` check is developed, and all pull requests needs to pass the check. 13 | 14 | 2. Expose APIs should have a `docstrings` to automatic generate API documents. `docstrings` should follow the `Google Style Python Guide `_. 15 | 16 | 3. Methods, Classes needs to provide enough tests (using `pytest`), and all tests needs to pass the automatic check in pull requests. 17 | 18 | Develop and Compile Instruction 19 | ------------------------------------------ 20 | 21 | SimQN is a Python library for quantum networks evaluation. It requires Python > 3.7.0. WE leverage `setuptools `_ to build SimQN: 22 | 23 | .. code-block:: bash 24 | 25 | pip3 install setuptools wheel twine 26 | pip3 install -r requirements 27 | 28 | To setup the development environments, the following command install SimQN into the python library so that we can do `import qns`: 29 | 30 | .. code-block:: bash 31 | 32 | python3 setup.py develop 33 | 34 | To compile and build a SimQN package, we can use: 35 | 36 | .. code-block:: bash 37 | 38 | python3 setup.py bdist_wheel 39 | 40 | Now the SimQN package is `qns--py3-none-any.whl` in `dist` directory. To further install this package, you can use `pip`: 41 | 42 | pip3 install qns--py3-none-any.whl 43 | 44 | 45 | 46 | Compile API documents 47 | ---------------------- 48 | 49 | We adopt `sphinx` to build our documents, and the first thing is to install it: 50 | 51 | .. code-block:: bash 52 | 53 | pip3 install sphinx sphinx_rtd_theme sphinx-autobuild 54 | 55 | To automatic generate the API documents, use the following command: 56 | 57 | .. code-block:: bash 58 | 59 | sphinx-apidoc -o docs/source qns 60 | 61 | To build document website, use the command: 62 | 63 | .. code-block:: bash 64 | cd docs 65 | make html 66 | 67 | Now, the compiled static website is built. Our documents is hosted on the `gh-pages` branch. Use the following command to publish new documents: 68 | 69 | 70 | .. code-block:: bash 71 | 72 | git subtree push --prefix docs/build/html origin gh-pages 73 | -------------------------------------------------------------------------------- /docs/build/html/_sources/index.rst.txt: -------------------------------------------------------------------------------- 1 | .. SimQN documentation master file, created by 2 | sphinx-quickstart on Mon Sep 13 11:28:47 2021. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Welcome to SimQN's documentation! 7 | ======================================= 8 | 9 | Welcome to SimQN's documentation. SimQN is a discrete-event based network simulation platform for quantum networks. 10 | SimQN enables large-scale investigations, including QKD protocols, entanglement distributions protocols, and routing algorithms in quantum networks. 11 | 12 | SimQN can be accelerated with Cython. 13 | 14 | Get Help 15 | --------------------------------------- 16 | 17 | Having trouble? We’d like to help! 18 | 19 | - This `documentation `_ many answer most questions. 20 | - Try the :ref:`modindex` or :ref:`genindex` the detailed table of contents. 21 | - Welcome to report bugs at `Github `_. 22 | 23 | .. toctree:: 24 | :maxdepth: 2 25 | :caption: Users' Guide: 26 | 27 | introduction 28 | install 29 | tutorials 30 | develop 31 | modules 32 | 33 | -------------------------------------------------------------------------------- /docs/build/html/_sources/install.rst.txt: -------------------------------------------------------------------------------- 1 | Install Guide 2 | ================================ 3 | 4 | Install stable version using `pip` 5 | ------------------------------------ 6 | 7 | The SimQN packet is provided by `pypi`. Thus, the stable version can be installed and upgraded with the following command: 8 | 9 | .. code-block:: bash 10 | 11 | pip install -U qns 12 | 13 | Install develop version from source 14 | -------------------------------------- 15 | 16 | Also, the develop version can be installed from source. First, checkout the source code from `Github `_. 17 | 18 | .. code-block:: bash 19 | 20 | git checkout https://github.com/ertuil/SimQN.git 21 | cd SimQN 22 | 23 | Then, install setuptools as the package tool: 24 | 25 | .. code-block:: bash 26 | 27 | pip3 install setuptools wheel 28 | 29 | And build the package: 30 | 31 | .. code-block:: bash 32 | 33 | python3 setup.py bdist_wheel 34 | 35 | This command build the package and it should be located in the `dist` directory, named `qns--py3-none-any.whl`. Finally, install the package to the system python library: 36 | 37 | .. code-block:: bash 38 | 39 | pip3 install qns--py3-none-any.whl 40 | 41 | 42 | Compile with Cython acceleration 43 | -------------------------------------- 44 | 45 | ``Cython`` is a Python library to build Python file into C/C++ libraries to accelerate the simulation. To use Cython, you should first download ``Cython`` along with other development libraries: 46 | 47 | .. code-block:: bash 48 | 49 | pip3 install setuptools wheel cython 50 | 51 | C/C++ compiler is also necessary. For windows platforms, Visual Studio is usually needed, and ``gcc/clang`` is required for ``Linux/MacOS`` platforms respectively. 52 | 53 | Finally, it is possible to build the packet and install the packet: 54 | 55 | .. code-block:: bash 56 | 57 | python3 setup-cython.py bdist_wheel 7777777777777777 58 | pip3 install qns----.whl 59 | -------------------------------------------------------------------------------- /docs/build/html/_sources/introduction.rst.txt: -------------------------------------------------------------------------------- 1 | Introduction 2 | ======================================= 3 | 4 | Overview 5 | --------------------------------------- 6 | 7 | Welcome to SimQN's documentation. SimQN is a discrete-event based network simulation platform for quantum networks. 8 | SimQN enables large-scale investigations, including QKD protocols, entanglement distributions protocols, and routing algorithms, resource allocation schemas in quantum networks. For example, users can use SimQN to design routing algorithms for better QKD performance. 9 | 10 | SimQN is a Python3 library for quantum networking simulation. It is designed to be general propose. It means that SimQN can be used for both QKD network, entanglement distribution network and other kinds of quantum networks' evaluation. The core idea is that SimQN makes no architecture assumption. Since there is currently no recognized network architecture in quantum networks investigations, SimQN stays flexible in this aspect. 11 | 12 | SimQN provides high performance for large-scale network simulation. Besides the common used quantum state based physical models, SimQN provides a higher-layer fidelity based entanglement physical model to reduce the computation overhead and brings convenience for users in evaluation. 13 | 14 | Bootstrap is anther core feature when designing SimQN. SimQN provides several network auxiliary models for easily building network topologies, producing routing tables and managing multiple session requests. 15 | 16 | Module Design 17 | --------------------------------------- 18 | 19 | The architecture of SimQN has several modules, includes: 20 | 21 | - `qns.simulator`, the discrete-event driven simulator. 22 | - `qns.models`, the physical model for qubits or entanglements. 23 | - `qns.entity`, basic entities in the quantum networks, including nodes, memories, channels. 24 | - `qns.network`, network auxiliary tools, such as topology generator, routing algorithms. 25 | - `qns.utils`, logging, random generator and other utilities. 26 | 27 | .. image:: _imgs/modules.png 28 | :align: center 29 | :alt: Moduels 30 | :width: 400px 31 | 32 | Develop Status 33 | --------------------------------------- 34 | 35 | Currently, SimQN is in its initial version that we believe it can help the quantum network researches. We still contribute to enable more features and functionalities, that means APIs may still change. Besides, not all functions are well tested. As a result, SimQN can be used as early validation in this period. 36 | 37 | We encourage the community to report bugs, bring suggestions to us so that we can make SimQN as realistic as possible. The :doc:`develop` contains more information about this topic. -------------------------------------------------------------------------------- /docs/build/html/_sources/modules.rst.txt: -------------------------------------------------------------------------------- 1 | qns 2 | === 3 | 4 | .. toctree:: 5 | :maxdepth: 4 6 | 7 | qns 8 | -------------------------------------------------------------------------------- /docs/build/html/_sources/qns.entity.cchannel.rst.txt: -------------------------------------------------------------------------------- 1 | qns.entity.cchannel package 2 | =========================== 3 | 4 | Submodules 5 | ---------- 6 | 7 | qns.entity.cchannel.cchannel module 8 | ----------------------------------- 9 | 10 | .. automodule:: qns.entity.cchannel.cchannel 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | Module contents 16 | --------------- 17 | 18 | .. automodule:: qns.entity.cchannel 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | -------------------------------------------------------------------------------- /docs/build/html/_sources/qns.entity.memory.rst.txt: -------------------------------------------------------------------------------- 1 | qns.entity.memory package 2 | ========================= 3 | 4 | Submodules 5 | ---------- 6 | 7 | qns.entity.memory.event module 8 | ------------------------------ 9 | 10 | .. automodule:: qns.entity.memory.event 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | qns.entity.memory.memory module 16 | ------------------------------- 17 | 18 | .. automodule:: qns.entity.memory.memory 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | Module contents 24 | --------------- 25 | 26 | .. automodule:: qns.entity.memory 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | -------------------------------------------------------------------------------- /docs/build/html/_sources/qns.entity.monitor.rst.txt: -------------------------------------------------------------------------------- 1 | qns.entity.monitor package 2 | ========================== 3 | 4 | Submodules 5 | ---------- 6 | 7 | qns.entity.monitor.monitor module 8 | --------------------------------- 9 | 10 | .. automodule:: qns.entity.monitor.monitor 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | Module contents 16 | --------------- 17 | 18 | .. automodule:: qns.entity.monitor 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | -------------------------------------------------------------------------------- /docs/build/html/_sources/qns.entity.node.rst.txt: -------------------------------------------------------------------------------- 1 | qns.entity.node package 2 | ======================= 3 | 4 | Submodules 5 | ---------- 6 | 7 | qns.entity.node.app module 8 | -------------------------- 9 | 10 | .. automodule:: qns.entity.node.app 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | qns.entity.node.node module 16 | --------------------------- 17 | 18 | .. automodule:: qns.entity.node.node 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | Module contents 24 | --------------- 25 | 26 | .. automodule:: qns.entity.node 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | -------------------------------------------------------------------------------- /docs/build/html/_sources/qns.entity.operator.rst.txt: -------------------------------------------------------------------------------- 1 | qns.entity.operator package 2 | =========================== 3 | 4 | Submodules 5 | ---------- 6 | 7 | qns.entity.operator.event module 8 | -------------------------------- 9 | 10 | .. automodule:: qns.entity.operator.event 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | qns.entity.operator.operator module 16 | ----------------------------------- 17 | 18 | .. automodule:: qns.entity.operator.operator 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | qns.entity.operator.operator module 24 | ----------------------------------- 25 | 26 | .. automodule:: qns.entity.operator.operator 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | 31 | Module contents 32 | --------------- 33 | 34 | .. automodule:: qns.entity.operator 35 | :members: 36 | :undoc-members: 37 | :show-inheritance: 38 | -------------------------------------------------------------------------------- /docs/build/html/_sources/qns.entity.qchannel.rst.txt: -------------------------------------------------------------------------------- 1 | qns.entity.qchannel package 2 | =========================== 3 | 4 | Submodules 5 | ---------- 6 | 7 | qns.entity.qchannel.losschannel module 8 | -------------------------------------- 9 | 10 | .. automodule:: qns.entity.qchannel.losschannel 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | qns.entity.qchannel.qchannel module 16 | ----------------------------------- 17 | 18 | .. automodule:: qns.entity.qchannel.qchannel 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | Module contents 24 | --------------- 25 | 26 | .. automodule:: qns.entity.qchannel 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | -------------------------------------------------------------------------------- /docs/build/html/_sources/qns.entity.rst.txt: -------------------------------------------------------------------------------- 1 | qns.entity package 2 | ================== 3 | 4 | Subpackages 5 | ----------- 6 | 7 | .. toctree:: 8 | :maxdepth: 4 9 | 10 | qns.entity.cchannel 11 | qns.entity.memory 12 | qns.entity.monitor 13 | qns.entity.node 14 | qns.entity.operator 15 | qns.entity.qchannel 16 | qns.entity.timer 17 | 18 | Submodules 19 | ---------- 20 | 21 | qns.entity.entity module 22 | ------------------------ 23 | 24 | .. automodule:: qns.entity.entity 25 | :members: 26 | :undoc-members: 27 | :show-inheritance: 28 | 29 | Module contents 30 | --------------- 31 | 32 | .. automodule:: qns.entity 33 | :members: 34 | :undoc-members: 35 | :show-inheritance: 36 | -------------------------------------------------------------------------------- /docs/build/html/_sources/qns.entity.timer.rst.txt: -------------------------------------------------------------------------------- 1 | qns.entity.timer package 2 | ======================== 3 | 4 | Submodules 5 | ---------- 6 | 7 | qns.entity.timer.timer module 8 | ----------------------------- 9 | 10 | .. automodule:: qns.entity.timer.timer 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | Module contents 16 | --------------- 17 | 18 | .. automodule:: qns.entity.timer 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | -------------------------------------------------------------------------------- /docs/build/html/_sources/qns.models.core.rst.txt: -------------------------------------------------------------------------------- 1 | qns.models.core package 2 | ======================= 3 | 4 | Submodules 5 | ---------- 6 | 7 | qns.models.core.backend module 8 | ------------------------------ 9 | 10 | .. automodule:: qns.models.core.backend 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | Module contents 16 | --------------- 17 | 18 | .. automodule:: qns.models.core 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | -------------------------------------------------------------------------------- /docs/build/html/_sources/qns.models.delay.rst.txt: -------------------------------------------------------------------------------- 1 | qns.models.delay package 2 | ======================== 3 | 4 | Submodules 5 | ---------- 6 | 7 | qns.models.delay.constdelay module 8 | ---------------------------------- 9 | 10 | .. automodule:: qns.models.delay.constdelay 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | qns.models.delay.delay module 16 | ----------------------------- 17 | 18 | .. automodule:: qns.models.delay.delay 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | qns.models.delay.normaldelay module 24 | ----------------------------------- 25 | 26 | .. automodule:: qns.models.delay.normaldelay 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | 31 | qns.models.delay.uniformdelay module 32 | ------------------------------------ 33 | 34 | .. automodule:: qns.models.delay.uniformdelay 35 | :members: 36 | :undoc-members: 37 | :show-inheritance: 38 | 39 | Module contents 40 | --------------- 41 | 42 | .. automodule:: qns.models.delay 43 | :members: 44 | :undoc-members: 45 | :show-inheritance: 46 | -------------------------------------------------------------------------------- /docs/build/html/_sources/qns.models.epr.rst.txt: -------------------------------------------------------------------------------- 1 | qns.models.epr package 2 | ====================== 3 | 4 | Submodules 5 | ---------- 6 | 7 | qns.models.epr.bell module 8 | -------------------------- 9 | 10 | .. automodule:: qns.models.epr.bell 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | qns.models.epr.entanglement module 16 | ---------------------------------- 17 | 18 | .. automodule:: qns.models.epr.entanglement 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | qns.models.epr.mixed module 24 | --------------------------- 25 | 26 | .. automodule:: qns.models.epr.mixed 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | 31 | qns.models.epr.werner module 32 | ---------------------------- 33 | 34 | .. automodule:: qns.models.epr.werner 35 | :members: 36 | :undoc-members: 37 | :show-inheritance: 38 | 39 | Module contents 40 | --------------- 41 | 42 | .. automodule:: qns.models.epr 43 | :members: 44 | :undoc-members: 45 | :show-inheritance: 46 | -------------------------------------------------------------------------------- /docs/build/html/_sources/qns.models.qubit.rst.txt: -------------------------------------------------------------------------------- 1 | qns.models.qubit package 2 | ======================== 3 | 4 | Submodules 5 | ---------- 6 | 7 | qns.models.qubit.const module 8 | ----------------------------- 9 | 10 | .. automodule:: qns.models.qubit.const 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | qns.models.qubit.decoherence module 16 | ----------------------------------- 17 | 18 | .. automodule:: qns.models.qubit.decoherence 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | qns.models.qubit.errors module 24 | ------------------------------ 25 | 26 | .. automodule:: qns.models.qubit.errors 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | 31 | qns.models.qubit.factory module 32 | ------------------------------- 33 | 34 | .. automodule:: qns.models.qubit.factory 35 | :members: 36 | :undoc-members: 37 | :show-inheritance: 38 | 39 | qns.models.qubit.gate module 40 | ---------------------------- 41 | 42 | .. automodule:: qns.models.qubit.gate 43 | :members: 44 | :undoc-members: 45 | :show-inheritance: 46 | 47 | qns.models.qubit.qubit module 48 | ----------------------------- 49 | 50 | .. automodule:: qns.models.qubit.qubit 51 | :members: 52 | :undoc-members: 53 | :show-inheritance: 54 | 55 | qns.models.qubit.utils module 56 | ----------------------------- 57 | 58 | .. automodule:: qns.models.qubit.utils 59 | :members: 60 | :undoc-members: 61 | :show-inheritance: 62 | 63 | Module contents 64 | --------------- 65 | 66 | .. automodule:: qns.models.qubit 67 | :members: 68 | :undoc-members: 69 | :show-inheritance: 70 | -------------------------------------------------------------------------------- /docs/build/html/_sources/qns.models.rst.txt: -------------------------------------------------------------------------------- 1 | qns.models package 2 | ================== 3 | 4 | Subpackages 5 | ----------- 6 | 7 | .. toctree:: 8 | :maxdepth: 4 9 | 10 | qns.models.core 11 | qns.models.delay 12 | qns.models.epr 13 | qns.models.qubit 14 | 15 | Module contents 16 | --------------- 17 | 18 | .. automodule:: qns.models 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | -------------------------------------------------------------------------------- /docs/build/html/_sources/qns.network.protocol.rst.txt: -------------------------------------------------------------------------------- 1 | qns.network.protocol package 2 | ============================ 3 | 4 | Submodules 5 | ---------- 6 | 7 | qns.network.protocol.bb84 module 8 | -------------------------------- 9 | 10 | .. automodule:: qns.network.protocol.bb84 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | qns.network.protocol.classicforward module 16 | ------------------------------------------ 17 | 18 | .. automodule:: qns.network.protocol.classicforward 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | qns.network.protocol.entanglement\_distribution module 24 | ------------------------------------------------------ 25 | 26 | .. automodule:: qns.network.protocol.entanglement_distribution 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | 31 | qns.network.protocol.node\_process\_delay module 32 | ------------------------------------------------ 33 | 34 | .. automodule:: qns.network.protocol.node_process_delay 35 | :members: 36 | :undoc-members: 37 | :show-inheritance: 38 | 39 | Module contents 40 | --------------- 41 | 42 | .. automodule:: qns.network.protocol 43 | :members: 44 | :undoc-members: 45 | :show-inheritance: 46 | -------------------------------------------------------------------------------- /docs/build/html/_sources/qns.network.route.rst.txt: -------------------------------------------------------------------------------- 1 | qns.network.route package 2 | ========================= 3 | 4 | Submodules 5 | ---------- 6 | 7 | qns.network.route.dijkstra module 8 | --------------------------------- 9 | 10 | .. automodule:: qns.network.route.dijkstra 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | qns.network.route.route module 16 | ------------------------------ 17 | 18 | .. automodule:: qns.network.route.route 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | Module contents 24 | --------------- 25 | 26 | .. automodule:: qns.network.route 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | -------------------------------------------------------------------------------- /docs/build/html/_sources/qns.network.rst.txt: -------------------------------------------------------------------------------- 1 | qns.network package 2 | =================== 3 | 4 | Subpackages 5 | ----------- 6 | 7 | .. toctree:: 8 | :maxdepth: 4 9 | 10 | qns.network.protocol 11 | qns.network.route 12 | qns.network.topology 13 | 14 | Submodules 15 | ---------- 16 | 17 | qns.network.network module 18 | -------------------------- 19 | 20 | .. automodule:: qns.network.network 21 | :members: 22 | :undoc-members: 23 | :show-inheritance: 24 | 25 | qns.network.requests module 26 | --------------------------- 27 | 28 | .. automodule:: qns.network.requests 29 | :members: 30 | :undoc-members: 31 | :show-inheritance: 32 | 33 | Module contents 34 | --------------- 35 | 36 | .. automodule:: qns.network 37 | :members: 38 | :undoc-members: 39 | :show-inheritance: 40 | -------------------------------------------------------------------------------- /docs/build/html/_sources/qns.network.topology.rst.txt: -------------------------------------------------------------------------------- 1 | qns.network.topology package 2 | ============================ 3 | 4 | Submodules 5 | ---------- 6 | 7 | qns.network.topology.basictopo module 8 | ------------------------------------- 9 | 10 | .. automodule:: qns.network.topology.basictopo 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | qns.network.topology.gridtopo module 16 | ------------------------------------ 17 | 18 | .. automodule:: qns.network.topology.gridtopo 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | qns.network.topology.linetopo module 24 | ------------------------------------ 25 | 26 | .. automodule:: qns.network.topology.linetopo 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | 31 | qns.network.topology.randomtopo module 32 | -------------------------------------- 33 | 34 | .. automodule:: qns.network.topology.randomtopo 35 | :members: 36 | :undoc-members: 37 | :show-inheritance: 38 | 39 | qns.network.topology.topo module 40 | -------------------------------- 41 | 42 | .. automodule:: qns.network.topology.topo 43 | :members: 44 | :undoc-members: 45 | :show-inheritance: 46 | 47 | qns.network.topology.treetopo module 48 | ------------------------------------ 49 | 50 | .. automodule:: qns.network.topology.treetopo 51 | :members: 52 | :undoc-members: 53 | :show-inheritance: 54 | 55 | qns.network.topology.waxmantopo module 56 | -------------------------------------- 57 | 58 | .. automodule:: qns.network.topology.waxmantopo 59 | :members: 60 | :undoc-members: 61 | :show-inheritance: 62 | 63 | Module contents 64 | --------------- 65 | 66 | .. automodule:: qns.network.topology 67 | :members: 68 | :undoc-members: 69 | :show-inheritance: 70 | -------------------------------------------------------------------------------- /docs/build/html/_sources/qns.rst.txt: -------------------------------------------------------------------------------- 1 | qns package 2 | =========== 3 | 4 | Subpackages 5 | ----------- 6 | 7 | .. toctree:: 8 | :maxdepth: 4 9 | 10 | qns.entity 11 | qns.models 12 | qns.network 13 | qns.simulator 14 | qns.utils 15 | 16 | Module contents 17 | --------------- 18 | 19 | .. automodule:: qns 20 | :members: 21 | :undoc-members: 22 | :show-inheritance: 23 | -------------------------------------------------------------------------------- /docs/build/html/_sources/qns.simulator.rst.txt: -------------------------------------------------------------------------------- 1 | qns.simulator package 2 | ===================== 3 | 4 | Submodules 5 | ---------- 6 | 7 | qns.simulator.event module 8 | -------------------------- 9 | 10 | .. automodule:: qns.simulator.event 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | qns.simulator.pool module 16 | ------------------------- 17 | 18 | .. automodule:: qns.simulator.pool 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | qns.simulator.pool module 24 | ------------------------- 25 | 26 | .. automodule:: qns.simulator.pool 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | 31 | qns.simulator.simulator module 32 | ------------------------------ 33 | 34 | .. automodule:: qns.simulator.simulator 35 | :members: 36 | :undoc-members: 37 | :show-inheritance: 38 | 39 | qns.simulator.ts module 40 | ----------------------- 41 | 42 | .. automodule:: qns.simulator.ts 43 | :members: 44 | :undoc-members: 45 | :show-inheritance: 46 | 47 | qns.simulator.ts module 48 | ----------------------- 49 | 50 | .. automodule:: qns.simulator.ts 51 | :members: 52 | :undoc-members: 53 | :show-inheritance: 54 | 55 | Module contents 56 | --------------- 57 | 58 | .. automodule:: qns.simulator 59 | :members: 60 | :undoc-members: 61 | :show-inheritance: 62 | -------------------------------------------------------------------------------- /docs/build/html/_sources/qns.utils.rst.txt: -------------------------------------------------------------------------------- 1 | qns.utils package 2 | ================= 3 | 4 | Submodules 5 | ---------- 6 | 7 | qns.utils.log module 8 | -------------------- 9 | 10 | .. automodule:: qns.utils.log 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | qns.utils.multiprocess module 16 | ----------------------------- 17 | 18 | .. automodule:: qns.utils.multiprocess 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | qns.utils.rnd module 24 | -------------------- 25 | 26 | .. automodule:: qns.utils.rnd 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | 31 | Module contents 32 | --------------- 33 | 34 | .. automodule:: qns.utils 35 | :members: 36 | :undoc-members: 37 | :show-inheritance: 38 | -------------------------------------------------------------------------------- /docs/build/html/_sources/tutorials.entity.monitor.rst.txt: -------------------------------------------------------------------------------- 1 | Monitor: for better collecting network status 2 | ================================================== 3 | 4 | ``Monitor`` is a virtual entity to collect network status for better analysis. It can collect network status before the simulation starts, after the simulation finishes, periodically, or when be triggered by a serial of events. It can be initiated by the following input parameters: 5 | 6 | - name, the name of this monitor 7 | - network, a optional input parameter, a ``QuantumNetwork`` object. 8 | 9 | .. code-block:: python 10 | 11 | from qns.entity.Monitor.monitor import Monitor 12 | 13 | monitor = Monitor(name="monitor_1", network = None) 14 | 15 | 16 | Users should instruct monitors how to collect the data by providing a calculate function. They can use the method ``add_attribution`` to add a new watching data. The first parameter is the attribution's name (the column's name in pandas), and the second parameter is the calculate function ``calculate_func``. This function will be called whenever the monitor is triggered. The input of ``calculate_func`` is a tuple (``Simulator``, ``QuantumNetwork``, ``Event``), so that ``calculate_func`` can get what they need from those input. The output is the calculated collecting data. Here are some examples. 17 | 18 | .. code-block:: python 19 | 20 | def watch_send_count(simulator, network, event): 21 | return sp.count 22 | 23 | def watch_recv_count(simulator, network, event): 24 | return rp.count 25 | 26 | monitor.add_attribution(name="send_count", calculate_func=watch_send_count) 27 | monitor.add_attribution(name="recv_count", calculate_func=watch_recv_count) 28 | monitor.add_attribution(name="event_name", calculate_func=lambda s, n, e: e.__class__) 29 | 30 | Finally, users should tell the monitor when to collect data. SimQN provides the following hooks: 31 | 32 | .. code-block:: python 33 | 34 | # before the simulation starts 35 | m.at_start() 36 | 37 | # after it finishes 38 | m.at_finish() 39 | 40 | # at a fixed period time 41 | m.at_period(period_time=1) 42 | 43 | # watch every ``RecvQubitPacket`` Event 44 | m.at_event(RecvQubitPacket) 45 | 46 | Before the simulation start, the monitor should be installed to the simulator by ``install`` method. After the simulation finishes, users can get the collected data using ``get_data`` function. The data will be formed in a ``pandas.DataFrame`` object. 47 | 48 | .. code-block:: python 49 | 50 | m.install(s) 51 | s.run() 52 | data = m.get_data() -------------------------------------------------------------------------------- /docs/build/html/_sources/tutorials.entity.rst.txt: -------------------------------------------------------------------------------- 1 | Entities in quantum networks 2 | ================================== 3 | 4 | A quantum network in SimQN consists of several entities. All entities are child class of ``Entity``. ``Entity`` has two interfaces: 5 | 6 | - ``install``. This method will initial the entity and generate initial events to the simulator. 7 | - ``handle``. This method will be called in case of related event is happened. 8 | 9 | Entities in the quantum networks includes: 10 | 11 | .. toctree:: 12 | :maxdepth: 4 13 | 14 | tutorials.entity.node 15 | tutorials.entity.memory 16 | tutorials.entity.qchannel 17 | tutorials.entity.cchannel 18 | tutorials.entity.operator 19 | tutorials.entity.monitor 20 | tutorials.entity.other -------------------------------------------------------------------------------- /docs/build/html/_sources/tutorials.models.delay.rst.txt: -------------------------------------------------------------------------------- 1 | Delay model 2 | ============================== 3 | 4 | Delay model can be used to describe a random time delay in channels, memories and operators. The basic class is ``DelayModel``. 5 | It implements a method called ``calculate`` to calculate the random time delay. 6 | 7 | Currently, SimQN provides the following three delay models: 8 | 9 | 1. ConstantDelayModel: generate a constant time delay 10 | 11 | .. code-block:: python 12 | 13 | from qns.models.delay import ConstantDelayModel 14 | 15 | delay_model = ConstantDelayModel(delay=0.5) # set time delay to a constant number 0.5 [s] 16 | 17 | delay = delay_model.calculate() # output: 0.5 18 | 19 | 2. UniformDelayModel: generate a random delay in uniform distribution X~U(min, max) 20 | 21 | .. code-block:: python 22 | 23 | from qns.models.delay import UniformDelayModel 24 | 25 | delay_model = UniformDelayModel(min_delay=0.3, max_delay=0.5) # set time delay to a random delay 26 | 27 | delay = delay_model.calculate() # output: 0.44 28 | 29 | 3. NormalDelayModel: generate a random delay in normal distribution X~N(mean_delay, std) 30 | 31 | .. code-block:: python 32 | 33 | from qns.models.delay import NormalDelayModel 34 | 35 | delay_model = NormalDelayModel(mean_delay=0.5, std=0.1) # set time delay to a random delay in normal distribution 36 | 37 | delay = delay_model.calculate() # output: 0.44 38 | 39 | Usages: a ``DelayModel`` can be a input parameters in quantum memories, quantum channels, classic channels and operators, for example: 40 | 41 | .. code-block:: python 42 | 43 | from qns.models.delay import NormalDelayModel 44 | from qns.entity.cchannel import ClassicChannel 45 | 46 | l1 = ClassicChannel(name="l1", bandwidth=10, delay=UniformDelayModel(min_delay=0.1, max_delay=0.3), 47 | drop_rate=0.1, max_buffer_size=30) -------------------------------------------------------------------------------- /docs/build/html/_sources/tutorials.models.model.rst.txt: -------------------------------------------------------------------------------- 1 | The physical model interface 2 | ================================= 3 | -------------------------------------------------------------------------------- /docs/build/html/_sources/tutorials.models.rst.txt: -------------------------------------------------------------------------------- 1 | Physical models 2 | ====================== 3 | 4 | Physical models are the models to describe qubits or entanglements. 5 | SimQN provides an interface (named ``QuantumModel``) to implement multiple physical models. 6 | Currently, SimQN present 2 models, a full functional qubit model and a high level entanglement model. Both models are the child classes of ``QuantumModel``. By extend ``QuantumModel``, other physical models can be built. 7 | 8 | ``QuantumModel`` class provides two abstract motheds, ``storage_error_model`` and ``transfer_error_model`` to describe the errors in quantum memory and channels. ``storage_error_model`` takes the storage time ``t`` and other parameters as the input. It change the quantum state accordingly. ``transfer_error_model`` takes the channel length ``length`` and other parameters as the input. 9 | 10 | .. toctree:: 11 | :maxdepth: 4 12 | 13 | tutorials.models.qubit 14 | tutorials.models.epr 15 | tutorials.models.delay -------------------------------------------------------------------------------- /docs/build/html/_sources/tutorials.network.protocol.rst.txt: -------------------------------------------------------------------------------- 1 | Quantum network protocols 2 | ========================== -------------------------------------------------------------------------------- /docs/build/html/_sources/tutorials.network.request.rst.txt: -------------------------------------------------------------------------------- 1 | Request management 2 | ======================== 3 | 4 | The request management module can select several sessions (a source node and destination node) randomly for large-scale evaluation. A ``Request`` includes the following attributions: 5 | 6 | - ``src``: the source node 7 | - ``dest``: the destination node 8 | - ``attr``: the attributions of this session, such as the fidelity requirement, the QoS or the bandwidth requirement. 9 | 10 | ``QuantumNetwork`` provides ``add_request`` to manually add a new request and ``random_requests`` to randomly generate several requests: 11 | 12 | .. code-block:: python 13 | 14 | # randomly generate 5 requests 15 | net.random_requests(number=5) 16 | 17 | # random generate 5 requests, but nodes can have multiple requests (allow overlay) 18 | net.random_requests(number=5, allow_overlay=True) 19 | 20 | # random generate 5 requests, with certain attributions 21 | net.random_requests(number=5, attr={"qos":2}) 22 | 23 | # manually add a request 24 | net.add_request(Request(src=n1, dest=n3, attr={"qos":2})) 25 | 26 | The network object and the nodes can query the related requests: 27 | 28 | .. code-block:: python 29 | 30 | net.requests # get all requests 31 | 32 | n1.requests # get all requests related to n1 33 | 34 | n1.clear_request() # remote all requests on n1 35 | 36 | Example applications and protocols 37 | ======================================== 38 | 39 | SimQN provides internal applications in ``qns.network.protocol``. 40 | 41 | ``BB84SendApp`` and ``BB84RecvApp`` is the simple demonstration protocol for BB84 QKD protocol without the after procedures, including error detecting, information reconciliation, and privacy amplification. 42 | 43 | ``EntanglementDistributionApp`` provides a hop-by-hop entanglement distribution protocol, where the source distribute entanglements to the destination at a fixed rate. 44 | 45 | ``ClassicPacketForwardApp`` can automatically forward all classic messages if the destination is not the current node. It will use the routing module (``qns.network.route``) to build classic routing tables. 46 | 47 | ``NodeProcessDelayApp`` can add processing delay on quantum nodes if they receive certain events. 48 | 49 | Those examples may be helpful for users to implement their own protocols. SimQN is working on providing more internal protocols for more scenarios. 50 | 51 | -------------------------------------------------------------------------------- /docs/build/html/_sources/tutorials.network.rst.txt: -------------------------------------------------------------------------------- 1 | Construct large-scale networks 2 | =============================== 3 | 4 | SimQN provides a ``QuantumNetwork`` to help build large-scale topologies, generate routing tables and manage multiple sessions. It can be initiate with the follow parameters: 5 | 6 | - ``topo``: the optional quantum network topology generator. It can be used to produce several quantum nodes, channels and form a special topology. 7 | - ``classic_topo``: an ``Enum`` class indicate the classic topology. 8 | - ``route``: the optional routing algorithm implement. 9 | - ``name``: the networks' name 10 | 11 | The ``QuantumNetwork`` provides the following functions: 12 | 13 | .. toctree:: 14 | :maxdepth: 4 15 | 16 | tutorials.network.topology 17 | tutorials.network.route 18 | tutorials.network.request 19 | -------------------------------------------------------------------------------- /docs/build/html/_sources/tutorials.rst.txt: -------------------------------------------------------------------------------- 1 | Tutorials 2 | ============================== 3 | 4 | This tutorial will explain how to use SimQN for quantum network researches. SimQN provides some example use cases in the `example` directory. 5 | 6 | .. toctree:: 7 | :maxdepth: 4 8 | 9 | tutorials.quickstart 10 | tutorials.parallel_simulation 11 | tutorials.models 12 | tutorials.entity 13 | tutorials.network 14 | tutorials.simulator 15 | tutorials.util -------------------------------------------------------------------------------- /docs/build/html/_sources/tutorials.util.rst.txt: -------------------------------------------------------------------------------- 1 | Logging and random generator 2 | ==================================== 3 | 4 | The logging module 5 | ----------------------------------- 6 | 7 | SimQN uses the Python logging package as the logging and data monitor tools. To providing the simulator's internal states (especially the time), SimQN warps the logging. Users can use the ``logger`` from: 8 | 9 | .. code-block:: Python 10 | 11 | import qns.utils.log as log 12 | 13 | s = Simulator() 14 | 15 | # install the log to the simulator to get simulator's internal status 16 | log.install(s) 17 | 18 | Users can set the logging level and record logs: 19 | 20 | .. code-block:: Python 21 | 22 | log.logger.setLevel(logging.INFO) 23 | a = 1 24 | 25 | log.debug("debug message") 26 | log.info("info message", a) 27 | log.warn("warn message", a+1) 28 | log.error("error message") 29 | log.critical("critical message") 30 | 31 | Finally, SimQN provides ``monitor()`` for date output. ``sep`` sets the separator, the default separator is "," (like csv files). ``with_time`` is a boolean indicating whether add a column to record the simulator's current time. 32 | 33 | .. code-block:: Python 34 | 35 | log.monitor(data1, date2, date3, with_date = True) 36 | # output: time, date1, date2, date3 37 | 38 | With the ``Timer`` entity provided by SimQN, it is easy to print the network's status periodically. 39 | 40 | .. code-block:: python 41 | 42 | from qns.simulator.simulator import Simulator 43 | from qns.entity.timer.timer import Timer 44 | import qns.utils.log as log 45 | 46 | s = Simulator(0, 10, 1000) 47 | log.install(s) 48 | 49 | # the trigger function is log network status 50 | def trigger_func(): 51 | print("network status") 52 | 53 | # set the timer with a period 54 | t1 = Timer("t1", 0, 10, 0.5, trigger_func) 55 | t1.install(s) 56 | 57 | # run the simulation 58 | s.run() 59 | 60 | Random generator's seed 61 | -------------------------- 62 | 63 | SimQN uses ``random`` library from both Python standard library and ``numpy`` when measuring qubits or generating random topologies. To make the simulation results reproducible, SimQN provides ``set_seed()`` to fix the random generator's seed: 64 | 65 | .. code-block:: python 66 | 67 | from qns.utils.random import set_seed 68 | 69 | set_seed(1641801012) # fix the random generator's seed 70 | 71 | ``get_randint(low, high)`` can generates an random integer in [low, high]; ``get_rand(low, high)`` can generate a float random number in [low, high); and ``get_choice(a)`` selects an random element in list ``a``. -------------------------------------------------------------------------------- /docs/build/html/_static/css/fonts/Roboto-Slab-Bold.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/html/_static/css/fonts/Roboto-Slab-Bold.woff -------------------------------------------------------------------------------- /docs/build/html/_static/css/fonts/Roboto-Slab-Bold.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/html/_static/css/fonts/Roboto-Slab-Bold.woff2 -------------------------------------------------------------------------------- /docs/build/html/_static/css/fonts/Roboto-Slab-Regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/html/_static/css/fonts/Roboto-Slab-Regular.woff -------------------------------------------------------------------------------- /docs/build/html/_static/css/fonts/Roboto-Slab-Regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/html/_static/css/fonts/Roboto-Slab-Regular.woff2 -------------------------------------------------------------------------------- /docs/build/html/_static/css/fonts/fontawesome-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/html/_static/css/fonts/fontawesome-webfont.eot -------------------------------------------------------------------------------- /docs/build/html/_static/css/fonts/fontawesome-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/html/_static/css/fonts/fontawesome-webfont.ttf -------------------------------------------------------------------------------- /docs/build/html/_static/css/fonts/fontawesome-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/html/_static/css/fonts/fontawesome-webfont.woff -------------------------------------------------------------------------------- /docs/build/html/_static/css/fonts/fontawesome-webfont.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/html/_static/css/fonts/fontawesome-webfont.woff2 -------------------------------------------------------------------------------- /docs/build/html/_static/css/fonts/lato-bold-italic.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/html/_static/css/fonts/lato-bold-italic.woff -------------------------------------------------------------------------------- /docs/build/html/_static/css/fonts/lato-bold-italic.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/html/_static/css/fonts/lato-bold-italic.woff2 -------------------------------------------------------------------------------- /docs/build/html/_static/css/fonts/lato-bold.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/html/_static/css/fonts/lato-bold.woff -------------------------------------------------------------------------------- /docs/build/html/_static/css/fonts/lato-bold.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/html/_static/css/fonts/lato-bold.woff2 -------------------------------------------------------------------------------- /docs/build/html/_static/css/fonts/lato-normal-italic.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/html/_static/css/fonts/lato-normal-italic.woff -------------------------------------------------------------------------------- /docs/build/html/_static/css/fonts/lato-normal-italic.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/html/_static/css/fonts/lato-normal-italic.woff2 -------------------------------------------------------------------------------- /docs/build/html/_static/css/fonts/lato-normal.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/html/_static/css/fonts/lato-normal.woff -------------------------------------------------------------------------------- /docs/build/html/_static/css/fonts/lato-normal.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/html/_static/css/fonts/lato-normal.woff2 -------------------------------------------------------------------------------- /docs/build/html/_static/documentation_options.js: -------------------------------------------------------------------------------- 1 | var DOCUMENTATION_OPTIONS = { 2 | URL_ROOT: document.getElementById("documentation_options").getAttribute('data-url_root'), 3 | VERSION: '0.1.3', 4 | LANGUAGE: 'en', 5 | COLLAPSE_INDEX: false, 6 | BUILDER: 'html', 7 | FILE_SUFFIX: '.html', 8 | LINK_SUFFIX: '.html', 9 | HAS_SOURCE: true, 10 | SOURCELINK_SUFFIX: '.txt', 11 | NAVIGATION_WITH_KEYS: false, 12 | SHOW_SEARCH_SUMMARY: true, 13 | ENABLE_SEARCH_SHORTCUTS: true, 14 | }; -------------------------------------------------------------------------------- /docs/build/html/_static/file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/html/_static/file.png -------------------------------------------------------------------------------- /docs/build/html/_static/js/badge_only.js: -------------------------------------------------------------------------------- 1 | !function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=4)}({4:function(e,t,r){}}); -------------------------------------------------------------------------------- /docs/build/html/_static/js/html5shiv.min.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @preserve HTML5 Shiv 3.7.3 | @afarkas @jdalton @jon_neal @rem | MIT/GPL2 Licensed 3 | */ 4 | !function(a,b){function c(a,b){var c=a.createElement("p"),d=a.getElementsByTagName("head")[0]||a.documentElement;return c.innerHTML="x",d.insertBefore(c.lastChild,d.firstChild)}function d(){var a=t.elements;return"string"==typeof a?a.split(" "):a}function e(a,b){var c=t.elements;"string"!=typeof c&&(c=c.join(" ")),"string"!=typeof a&&(a=a.join(" ")),t.elements=c+" "+a,j(b)}function f(a){var b=s[a[q]];return b||(b={},r++,a[q]=r,s[r]=b),b}function g(a,c,d){if(c||(c=b),l)return c.createElement(a);d||(d=f(c));var e;return e=d.cache[a]?d.cache[a].cloneNode():p.test(a)?(d.cache[a]=d.createElem(a)).cloneNode():d.createElem(a),!e.canHaveChildren||o.test(a)||e.tagUrn?e:d.frag.appendChild(e)}function h(a,c){if(a||(a=b),l)return a.createDocumentFragment();c=c||f(a);for(var e=c.frag.cloneNode(),g=0,h=d(),i=h.length;i>g;g++)e.createElement(h[g]);return e}function i(a,b){b.cache||(b.cache={},b.createElem=a.createElement,b.createFrag=a.createDocumentFragment,b.frag=b.createFrag()),a.createElement=function(c){return t.shivMethods?g(c,a,b):b.createElem(c)},a.createDocumentFragment=Function("h,f","return function(){var n=f.cloneNode(),c=n.createElement;h.shivMethods&&("+d().join().replace(/[\w\-:]+/g,function(a){return b.createElem(a),b.frag.createElement(a),'c("'+a+'")'})+");return n}")(t,b.frag)}function j(a){a||(a=b);var d=f(a);return!t.shivCSS||k||d.hasCSS||(d.hasCSS=!!c(a,"article,aside,dialog,figcaption,figure,footer,header,hgroup,main,nav,section{display:block}mark{background:#FF0;color:#000}template{display:none}")),l||i(a,d),a}var k,l,m="3.7.3-pre",n=a.html5||{},o=/^<|^(?:button|map|select|textarea|object|iframe|option|optgroup)$/i,p=/^(?:a|b|code|div|fieldset|h1|h2|h3|h4|h5|h6|i|label|li|ol|p|q|span|strong|style|table|tbody|td|th|tr|ul)$/i,q="_html5shiv",r=0,s={};!function(){try{var a=b.createElement("a");a.innerHTML="",k="hidden"in a,l=1==a.childNodes.length||function(){b.createElement("a");var a=b.createDocumentFragment();return"undefined"==typeof a.cloneNode||"undefined"==typeof a.createDocumentFragment||"undefined"==typeof a.createElement}()}catch(c){k=!0,l=!0}}();var t={elements:n.elements||"abbr article aside audio bdi canvas data datalist details dialog figcaption figure footer header hgroup main mark meter nav output picture progress section summary template time video",version:m,shivCSS:n.shivCSS!==!1,supportsUnknownElements:l,shivMethods:n.shivMethods!==!1,type:"default",shivDocument:j,createElement:g,createDocumentFragment:h,addElements:e};a.html5=t,j(b),"object"==typeof module&&module.exports&&(module.exports=t)}("undefined"!=typeof window?window:this,document); -------------------------------------------------------------------------------- /docs/build/html/_static/minus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/html/_static/minus.png -------------------------------------------------------------------------------- /docs/build/html/_static/modules.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/html/_static/modules.png -------------------------------------------------------------------------------- /docs/build/html/_static/plus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/html/_static/plus.png -------------------------------------------------------------------------------- /docs/build/html/objects.inv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/build/html/objects.inv -------------------------------------------------------------------------------- /docs/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | pushd %~dp0 4 | 5 | REM Command file for Sphinx documentation 6 | 7 | if "%SPHINXBUILD%" == "" ( 8 | set SPHINXBUILD=sphinx-build 9 | ) 10 | set SOURCEDIR=source 11 | set BUILDDIR=build 12 | 13 | if "%1" == "" goto help 14 | 15 | %SPHINXBUILD% >NUL 2>NUL 16 | if errorlevel 9009 ( 17 | echo. 18 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 19 | echo.installed, then set the SPHINXBUILD environment variable to point 20 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 21 | echo.may add the Sphinx directory to PATH. 22 | echo. 23 | echo.If you don't have Sphinx installed, grab it from 24 | echo.http://sphinx-doc.org/ 25 | exit /b 1 26 | ) 27 | 28 | %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% 29 | goto end 30 | 31 | :help 32 | %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% 33 | 34 | :end 35 | popd 36 | -------------------------------------------------------------------------------- /docs/source/.nojekyll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/source/.nojekyll -------------------------------------------------------------------------------- /docs/source/_imgs/modules.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QNLab-USTC/SimQN/7218f353491bb86a89a94df15c4bb001e2a520c9/docs/source/_imgs/modules.png -------------------------------------------------------------------------------- /docs/source/conf.py: -------------------------------------------------------------------------------- 1 | # Configuration file for the Sphinx documentation builder. 2 | # 3 | # This file only contains a selection of the most common options. For a full 4 | # list see the documentation: 5 | # https://www.sphinx-doc.org/en/master/usage/configuration.html 6 | 7 | # -- Path setup -------------------------------------------------------------- 8 | 9 | # If extensions (or modules to document with autodoc) are in another directory, 10 | # add these directories to sys.path here. If the directory is relative to the 11 | # documentation root, use os.path.abspath to make it absolute, like shown here. 12 | # 13 | import os 14 | import sys 15 | sys.path.insert(0, os.path.abspath('..')) 16 | sys.path.insert(0, os.path.abspath('../qns')) 17 | sys.path.insert(0, os.path.abspath('../..')) 18 | sys.path.insert(0, os.path.abspath('../../qns')) 19 | print(sys.path) 20 | 21 | # -- Project information ----------------------------------------------------- 22 | 23 | project = 'SimQN' 24 | copyright = '2022, Elliot Chen' 25 | author = 'Elliot Chen' 26 | 27 | # The full version, including alpha/beta/rc tags 28 | release = '0.1.3' 29 | 30 | 31 | # -- General configuration --------------------------------------------------- 32 | 33 | # Add any Sphinx extension module names here, as strings. They can be 34 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 35 | # ones. 36 | extensions = [ 37 | 'sphinx.ext.autodoc', 38 | 'sphinx.ext.napoleon', 39 | 'sphinx.ext.viewcode', 40 | 'sphinx.ext.todo' 41 | ] 42 | 43 | # Add any paths that contain templates here, relative to this directory. 44 | templates_path = ['_templates'] 45 | 46 | # List of patterns, relative to source directory, that match files and 47 | # directories to ignore when looking for source files. 48 | # This pattern also affects html_static_path and html_extra_path. 49 | exclude_patterns = [] 50 | 51 | 52 | # -- Options for HTML output ------------------------------------------------- 53 | 54 | # The theme to use for HTML and HTML Help pages. See the documentation for 55 | # a list of builtin themes. 56 | # 57 | html_theme = 'sphinx_rtd_theme' 58 | 59 | # Add any paths that contain custom static files (such as style sheets) here, 60 | # relative to this directory. They are copied after the builtin static files, 61 | # so a file named "default.css" will overwrite the builtin "default.css". 62 | html_static_path = ['_static', '_imgs'] 63 | 64 | 65 | # -- Extension configuration ------------------------------------------------- 66 | 67 | language = "en" 68 | todo_include_todos = True 69 | -------------------------------------------------------------------------------- /docs/source/develop.rst: -------------------------------------------------------------------------------- 1 | Develop Guide 2 | ======================================= 3 | 4 | We prefer a standard development method. To ensure this, this guide explains the development rules and instructions. 5 | 6 | Code requirements 7 | --------------------------------------- 8 | 9 | Source code is hosted at `Github `_. Pull requests and issues are welcome. 10 | However, the following requirements need to be met: 11 | 12 | 1. Python codes and the variable's name should follow `PEP 8 `_ standard. An automatic `flake8` check is developed, and all pull requests needs to pass the check. 13 | 14 | 2. Expose APIs should have a `docstrings` to automatic generate API documents. `docstrings` should follow the `Google Style Python Guide `_. 15 | 16 | 3. Methods, Classes needs to provide enough tests (using `pytest`), and all tests needs to pass the automatic check in pull requests. 17 | 18 | Develop and Compile Instruction 19 | ------------------------------------------ 20 | 21 | SimQN is a Python library for quantum networks evaluation. It requires Python > 3.7.0. WE leverage `setuptools `_ to build SimQN: 22 | 23 | .. code-block:: bash 24 | 25 | pip3 install setuptools wheel twine 26 | pip3 install -r requirements.txt 27 | 28 | To setup the development environments, the following command install SimQN into the python library so that we can do `import qns`: 29 | 30 | .. code-block:: bash 31 | 32 | python3 setup.py develop 33 | 34 | To compile and build a SimQN package, we can use: 35 | 36 | .. code-block:: bash 37 | 38 | python3 setup.py bdist_wheel 39 | 40 | Now the SimQN package is `qns--py3-none-any.whl` in `dist` directory. To further install this package, you can use `pip`: 41 | 42 | pip3 install qns--py3-none-any.whl 43 | 44 | 45 | 46 | Compile API documents 47 | ---------------------- 48 | 49 | We adopt `sphinx` to build our documents, and the first thing is to install it: 50 | 51 | .. code-block:: bash 52 | 53 | pip3 install sphinx sphinx_rtd_theme sphinx-autobuild 54 | 55 | To automatic generate the API documents, use the following command: 56 | 57 | .. code-block:: bash 58 | 59 | sphinx-apidoc -o docs/source qns 60 | 61 | To build document website, use the command: 62 | 63 | .. code-block:: bash 64 | cd docs 65 | make html 66 | 67 | Now, the compiled static website is built. Our documents is hosted on the `gh-pages` branch. Use the following command to publish new documents: 68 | 69 | 70 | .. code-block:: bash 71 | 72 | git subtree push --prefix docs/build/html origin gh-pages 73 | -------------------------------------------------------------------------------- /docs/source/index.rst: -------------------------------------------------------------------------------- 1 | .. SimQN documentation master file, created by 2 | sphinx-quickstart on Mon Sep 13 11:28:47 2021. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Welcome to SimQN's documentation! 7 | ======================================= 8 | 9 | Welcome to SimQN's documentation. SimQN is a discrete-event based network simulation platform for quantum networks. 10 | SimQN enables large-scale investigations, including QKD protocols, entanglement distributions protocols, and routing algorithms in quantum networks. 11 | 12 | SimQN can be accelerated with Cython. 13 | 14 | Get Help 15 | --------------------------------------- 16 | 17 | Having trouble? We’d like to help! 18 | 19 | - This `documentation `_ many answer most questions. 20 | - Try the :ref:`modindex` or :ref:`genindex` the detailed table of contents. 21 | - Welcome to report bugs at `Github `_. 22 | 23 | .. toctree:: 24 | :maxdepth: 2 25 | :caption: Users' Guide: 26 | 27 | introduction 28 | install 29 | tutorials 30 | develop 31 | modules 32 | 33 | -------------------------------------------------------------------------------- /docs/source/install.rst: -------------------------------------------------------------------------------- 1 | Install Guide 2 | ================================ 3 | 4 | Install stable version using `pip` 5 | ------------------------------------ 6 | 7 | The SimQN packet is provided by `pypi`. Thus, the stable version can be installed and upgraded with the following command: 8 | 9 | .. code-block:: bash 10 | 11 | pip install -U qns 12 | 13 | Install develop version from source 14 | -------------------------------------- 15 | 16 | Also, the develop version can be installed from source. First, checkout the source code from `Github `_. 17 | 18 | .. code-block:: bash 19 | 20 | git checkout https://github.com/ertuil/SimQN.git 21 | cd SimQN 22 | 23 | Then, install setuptools as the package tool: 24 | 25 | .. code-block:: bash 26 | 27 | pip3 install setuptools wheel 28 | 29 | And build the package: 30 | 31 | .. code-block:: bash 32 | 33 | python3 setup.py bdist_wheel 34 | 35 | This command build the package and it should be located in the `dist` directory, named `qns--py3-none-any.whl`. Finally, install the package to the system python library: 36 | 37 | .. code-block:: bash 38 | 39 | pip3 install qns--py3-none-any.whl 40 | 41 | 42 | Compile with Cython acceleration 43 | -------------------------------------- 44 | 45 | ``Cython`` is a Python library to build Python file into C/C++ libraries to accelerate the simulation. To use Cython, you should first download ``Cython`` along with other development libraries: 46 | 47 | .. code-block:: bash 48 | 49 | pip3 install setuptools wheel cython 50 | 51 | C/C++ compiler is also necessary. For windows platforms, Visual Studio is usually needed, and ``gcc/clang`` is required for ``Linux/MacOS`` platforms respectively. 52 | 53 | Finally, it is possible to build the packet and install the packet: 54 | 55 | .. code-block:: bash 56 | 57 | python3 setup-cython.py bdist_wheel 7777777777777777 58 | pip3 install qns----.whl 59 | -------------------------------------------------------------------------------- /docs/source/introduction.rst: -------------------------------------------------------------------------------- 1 | Introduction 2 | ======================================= 3 | 4 | Overview 5 | --------------------------------------- 6 | 7 | Welcome to SimQN's documentation. SimQN is a discrete-event based network simulation platform for quantum networks. 8 | SimQN enables large-scale investigations, including QKD protocols, entanglement distributions protocols, and routing algorithms, resource allocation schemas in quantum networks. For example, users can use SimQN to design routing algorithms for better QKD performance. 9 | 10 | SimQN is a Python3 library for quantum networking simulation. It is designed to be general propose. It means that SimQN can be used for both QKD network, entanglement distribution network and other kinds of quantum networks' evaluation. The core idea is that SimQN makes no architecture assumption. Since there is currently no recognized network architecture in quantum networks investigations, SimQN stays flexible in this aspect. 11 | 12 | SimQN provides high performance for large-scale network simulation. Besides the common used quantum state based physical models, SimQN provides a higher-layer fidelity based entanglement physical model to reduce the computation overhead and brings convenience for users in evaluation. 13 | 14 | Bootstrap is anther core feature when designing SimQN. SimQN provides several network auxiliary models for easily building network topologies, producing routing tables and managing multiple session requests. 15 | 16 | Module Design 17 | --------------------------------------- 18 | 19 | The architecture of SimQN has several modules, includes: 20 | 21 | - `qns.simulator`, the discrete-event driven simulator. 22 | - `qns.models`, the physical model for qubits or entanglements. 23 | - `qns.entity`, basic entities in the quantum networks, including nodes, memories, channels. 24 | - `qns.network`, network auxiliary tools, such as topology generator, routing algorithms. 25 | - `qns.utils`, logging, random generator and other utilities. 26 | 27 | .. image:: _imgs/modules.png 28 | :align: center 29 | :alt: Moduels 30 | :width: 400px 31 | 32 | Develop Status 33 | --------------------------------------- 34 | 35 | Currently, SimQN is in its initial version that we believe it can help the quantum network researches. We still contribute to enable more features and functionalities, that means APIs may still change. Besides, not all functions are well tested. As a result, SimQN can be used as early validation in this period. 36 | 37 | We encourage the community to report bugs, bring suggestions to us so that we can make SimQN as realistic as possible. The :doc:`develop` contains more information about this topic. -------------------------------------------------------------------------------- /docs/source/modules.rst: -------------------------------------------------------------------------------- 1 | qns 2 | === 3 | 4 | .. toctree:: 5 | :maxdepth: 4 6 | 7 | qns 8 | -------------------------------------------------------------------------------- /docs/source/qns.entity.cchannel.rst: -------------------------------------------------------------------------------- 1 | qns.entity.cchannel package 2 | =========================== 3 | 4 | Submodules 5 | ---------- 6 | 7 | qns.entity.cchannel.cchannel module 8 | ----------------------------------- 9 | 10 | .. automodule:: qns.entity.cchannel.cchannel 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | Module contents 16 | --------------- 17 | 18 | .. automodule:: qns.entity.cchannel 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | -------------------------------------------------------------------------------- /docs/source/qns.entity.memory.rst: -------------------------------------------------------------------------------- 1 | qns.entity.memory package 2 | ========================= 3 | 4 | Submodules 5 | ---------- 6 | 7 | qns.entity.memory.event module 8 | ------------------------------ 9 | 10 | .. automodule:: qns.entity.memory.event 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | qns.entity.memory.memory module 16 | ------------------------------- 17 | 18 | .. automodule:: qns.entity.memory.memory 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | Module contents 24 | --------------- 25 | 26 | .. automodule:: qns.entity.memory 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | -------------------------------------------------------------------------------- /docs/source/qns.entity.monitor.rst: -------------------------------------------------------------------------------- 1 | qns.entity.monitor package 2 | ========================== 3 | 4 | Submodules 5 | ---------- 6 | 7 | qns.entity.monitor.monitor module 8 | --------------------------------- 9 | 10 | .. automodule:: qns.entity.monitor.monitor 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | Module contents 16 | --------------- 17 | 18 | .. automodule:: qns.entity.monitor 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | -------------------------------------------------------------------------------- /docs/source/qns.entity.node.rst: -------------------------------------------------------------------------------- 1 | qns.entity.node package 2 | ======================= 3 | 4 | Submodules 5 | ---------- 6 | 7 | qns.entity.node.app module 8 | -------------------------- 9 | 10 | .. automodule:: qns.entity.node.app 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | qns.entity.node.node module 16 | --------------------------- 17 | 18 | .. automodule:: qns.entity.node.node 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | Module contents 24 | --------------- 25 | 26 | .. automodule:: qns.entity.node 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | -------------------------------------------------------------------------------- /docs/source/qns.entity.operator.rst: -------------------------------------------------------------------------------- 1 | qns.entity.operator package 2 | =========================== 3 | 4 | Submodules 5 | ---------- 6 | 7 | qns.entity.operator.event module 8 | -------------------------------- 9 | 10 | .. automodule:: qns.entity.operator.event 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | qns.entity.operator.operator module 16 | ----------------------------------- 17 | 18 | .. automodule:: qns.entity.operator.operator 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | qns.entity.operator.operator module 24 | ----------------------------------- 25 | 26 | .. automodule:: qns.entity.operator.operator 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | 31 | Module contents 32 | --------------- 33 | 34 | .. automodule:: qns.entity.operator 35 | :members: 36 | :undoc-members: 37 | :show-inheritance: 38 | -------------------------------------------------------------------------------- /docs/source/qns.entity.qchannel.rst: -------------------------------------------------------------------------------- 1 | qns.entity.qchannel package 2 | =========================== 3 | 4 | Submodules 5 | ---------- 6 | 7 | qns.entity.qchannel.losschannel module 8 | -------------------------------------- 9 | 10 | .. automodule:: qns.entity.qchannel.losschannel 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | qns.entity.qchannel.qchannel module 16 | ----------------------------------- 17 | 18 | .. automodule:: qns.entity.qchannel.qchannel 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | Module contents 24 | --------------- 25 | 26 | .. automodule:: qns.entity.qchannel 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | -------------------------------------------------------------------------------- /docs/source/qns.entity.rst: -------------------------------------------------------------------------------- 1 | qns.entity package 2 | ================== 3 | 4 | Subpackages 5 | ----------- 6 | 7 | .. toctree:: 8 | :maxdepth: 4 9 | 10 | qns.entity.cchannel 11 | qns.entity.memory 12 | qns.entity.monitor 13 | qns.entity.node 14 | qns.entity.operator 15 | qns.entity.qchannel 16 | qns.entity.timer 17 | 18 | Submodules 19 | ---------- 20 | 21 | qns.entity.entity module 22 | ------------------------ 23 | 24 | .. automodule:: qns.entity.entity 25 | :members: 26 | :undoc-members: 27 | :show-inheritance: 28 | 29 | Module contents 30 | --------------- 31 | 32 | .. automodule:: qns.entity 33 | :members: 34 | :undoc-members: 35 | :show-inheritance: 36 | -------------------------------------------------------------------------------- /docs/source/qns.entity.timer.rst: -------------------------------------------------------------------------------- 1 | qns.entity.timer package 2 | ======================== 3 | 4 | Submodules 5 | ---------- 6 | 7 | qns.entity.timer.timer module 8 | ----------------------------- 9 | 10 | .. automodule:: qns.entity.timer.timer 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | Module contents 16 | --------------- 17 | 18 | .. automodule:: qns.entity.timer 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | -------------------------------------------------------------------------------- /docs/source/qns.models.core.rst: -------------------------------------------------------------------------------- 1 | qns.models.core package 2 | ======================= 3 | 4 | Submodules 5 | ---------- 6 | 7 | qns.models.core.backend module 8 | ------------------------------ 9 | 10 | .. automodule:: qns.models.core.backend 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | Module contents 16 | --------------- 17 | 18 | .. automodule:: qns.models.core 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | -------------------------------------------------------------------------------- /docs/source/qns.models.delay.rst: -------------------------------------------------------------------------------- 1 | qns.models.delay package 2 | ======================== 3 | 4 | Submodules 5 | ---------- 6 | 7 | qns.models.delay.constdelay module 8 | ---------------------------------- 9 | 10 | .. automodule:: qns.models.delay.constdelay 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | qns.models.delay.delay module 16 | ----------------------------- 17 | 18 | .. automodule:: qns.models.delay.delay 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | qns.models.delay.normaldelay module 24 | ----------------------------------- 25 | 26 | .. automodule:: qns.models.delay.normaldelay 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | 31 | qns.models.delay.uniformdelay module 32 | ------------------------------------ 33 | 34 | .. automodule:: qns.models.delay.uniformdelay 35 | :members: 36 | :undoc-members: 37 | :show-inheritance: 38 | 39 | Module contents 40 | --------------- 41 | 42 | .. automodule:: qns.models.delay 43 | :members: 44 | :undoc-members: 45 | :show-inheritance: 46 | -------------------------------------------------------------------------------- /docs/source/qns.models.epr.rst: -------------------------------------------------------------------------------- 1 | qns.models.epr package 2 | ====================== 3 | 4 | Submodules 5 | ---------- 6 | 7 | qns.models.epr.bell module 8 | -------------------------- 9 | 10 | .. automodule:: qns.models.epr.bell 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | qns.models.epr.entanglement module 16 | ---------------------------------- 17 | 18 | .. automodule:: qns.models.epr.entanglement 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | qns.models.epr.mixed module 24 | --------------------------- 25 | 26 | .. automodule:: qns.models.epr.mixed 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | 31 | qns.models.epr.werner module 32 | ---------------------------- 33 | 34 | .. automodule:: qns.models.epr.werner 35 | :members: 36 | :undoc-members: 37 | :show-inheritance: 38 | 39 | Module contents 40 | --------------- 41 | 42 | .. automodule:: qns.models.epr 43 | :members: 44 | :undoc-members: 45 | :show-inheritance: 46 | -------------------------------------------------------------------------------- /docs/source/qns.models.qubit.rst: -------------------------------------------------------------------------------- 1 | qns.models.qubit package 2 | ======================== 3 | 4 | Submodules 5 | ---------- 6 | 7 | qns.models.qubit.const module 8 | ----------------------------- 9 | 10 | .. automodule:: qns.models.qubit.const 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | qns.models.qubit.decoherence module 16 | ----------------------------------- 17 | 18 | .. automodule:: qns.models.qubit.decoherence 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | qns.models.qubit.errors module 24 | ------------------------------ 25 | 26 | .. automodule:: qns.models.qubit.errors 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | 31 | qns.models.qubit.factory module 32 | ------------------------------- 33 | 34 | .. automodule:: qns.models.qubit.factory 35 | :members: 36 | :undoc-members: 37 | :show-inheritance: 38 | 39 | qns.models.qubit.gate module 40 | ---------------------------- 41 | 42 | .. automodule:: qns.models.qubit.gate 43 | :members: 44 | :undoc-members: 45 | :show-inheritance: 46 | 47 | qns.models.qubit.qubit module 48 | ----------------------------- 49 | 50 | .. automodule:: qns.models.qubit.qubit 51 | :members: 52 | :undoc-members: 53 | :show-inheritance: 54 | 55 | qns.models.qubit.utils module 56 | ----------------------------- 57 | 58 | .. automodule:: qns.models.qubit.utils 59 | :members: 60 | :undoc-members: 61 | :show-inheritance: 62 | 63 | Module contents 64 | --------------- 65 | 66 | .. automodule:: qns.models.qubit 67 | :members: 68 | :undoc-members: 69 | :show-inheritance: 70 | -------------------------------------------------------------------------------- /docs/source/qns.models.rst: -------------------------------------------------------------------------------- 1 | qns.models package 2 | ================== 3 | 4 | Subpackages 5 | ----------- 6 | 7 | .. toctree:: 8 | :maxdepth: 4 9 | 10 | qns.models.core 11 | qns.models.delay 12 | qns.models.epr 13 | qns.models.qubit 14 | 15 | Module contents 16 | --------------- 17 | 18 | .. automodule:: qns.models 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | -------------------------------------------------------------------------------- /docs/source/qns.network.protocol.rst: -------------------------------------------------------------------------------- 1 | qns.network.protocol package 2 | ============================ 3 | 4 | Submodules 5 | ---------- 6 | 7 | qns.network.protocol.bb84 module 8 | -------------------------------- 9 | 10 | .. automodule:: qns.network.protocol.bb84 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | qns.network.protocol.classicforward module 16 | ------------------------------------------ 17 | 18 | .. automodule:: qns.network.protocol.classicforward 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | qns.network.protocol.entanglement\_distribution module 24 | ------------------------------------------------------ 25 | 26 | .. automodule:: qns.network.protocol.entanglement_distribution 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | 31 | qns.network.protocol.node\_process\_delay module 32 | ------------------------------------------------ 33 | 34 | .. automodule:: qns.network.protocol.node_process_delay 35 | :members: 36 | :undoc-members: 37 | :show-inheritance: 38 | 39 | Module contents 40 | --------------- 41 | 42 | .. automodule:: qns.network.protocol 43 | :members: 44 | :undoc-members: 45 | :show-inheritance: 46 | -------------------------------------------------------------------------------- /docs/source/qns.network.route.rst: -------------------------------------------------------------------------------- 1 | qns.network.route package 2 | ========================= 3 | 4 | Submodules 5 | ---------- 6 | 7 | qns.network.route.dijkstra module 8 | --------------------------------- 9 | 10 | .. automodule:: qns.network.route.dijkstra 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | qns.network.route.route module 16 | ------------------------------ 17 | 18 | .. automodule:: qns.network.route.route 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | Module contents 24 | --------------- 25 | 26 | .. automodule:: qns.network.route 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | -------------------------------------------------------------------------------- /docs/source/qns.network.rst: -------------------------------------------------------------------------------- 1 | qns.network package 2 | =================== 3 | 4 | Subpackages 5 | ----------- 6 | 7 | .. toctree:: 8 | :maxdepth: 4 9 | 10 | qns.network.protocol 11 | qns.network.route 12 | qns.network.topology 13 | 14 | Submodules 15 | ---------- 16 | 17 | qns.network.network module 18 | -------------------------- 19 | 20 | .. automodule:: qns.network.network 21 | :members: 22 | :undoc-members: 23 | :show-inheritance: 24 | 25 | qns.network.requests module 26 | --------------------------- 27 | 28 | .. automodule:: qns.network.requests 29 | :members: 30 | :undoc-members: 31 | :show-inheritance: 32 | 33 | Module contents 34 | --------------- 35 | 36 | .. automodule:: qns.network 37 | :members: 38 | :undoc-members: 39 | :show-inheritance: 40 | -------------------------------------------------------------------------------- /docs/source/qns.network.topology.rst: -------------------------------------------------------------------------------- 1 | qns.network.topology package 2 | ============================ 3 | 4 | Submodules 5 | ---------- 6 | 7 | qns.network.topology.basictopo module 8 | ------------------------------------- 9 | 10 | .. automodule:: qns.network.topology.basictopo 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | qns.network.topology.gridtopo module 16 | ------------------------------------ 17 | 18 | .. automodule:: qns.network.topology.gridtopo 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | qns.network.topology.linetopo module 24 | ------------------------------------ 25 | 26 | .. automodule:: qns.network.topology.linetopo 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | 31 | qns.network.topology.randomtopo module 32 | -------------------------------------- 33 | 34 | .. automodule:: qns.network.topology.randomtopo 35 | :members: 36 | :undoc-members: 37 | :show-inheritance: 38 | 39 | qns.network.topology.topo module 40 | -------------------------------- 41 | 42 | .. automodule:: qns.network.topology.topo 43 | :members: 44 | :undoc-members: 45 | :show-inheritance: 46 | 47 | qns.network.topology.treetopo module 48 | ------------------------------------ 49 | 50 | .. automodule:: qns.network.topology.treetopo 51 | :members: 52 | :undoc-members: 53 | :show-inheritance: 54 | 55 | qns.network.topology.waxmantopo module 56 | -------------------------------------- 57 | 58 | .. automodule:: qns.network.topology.waxmantopo 59 | :members: 60 | :undoc-members: 61 | :show-inheritance: 62 | 63 | qns.network.topology.erdosrenyitopo module 64 | ------------------------------------------ 65 | 66 | .. automodule:: qns.network.topology.erdosrenyitopo 67 | :members: 68 | :undoc-members: 69 | :show-inheritance: 70 | 71 | qns.network.topology.barabasialberttopo module 72 | ---------------------------------------------- 73 | 74 | .. automodule:: qns.network.topology.barabasialberttopo 75 | :members: 76 | :undoc-members: 77 | :show-inheritance: 78 | 79 | qns.network.topology.dualbarabasialberttopo module 80 | -------------------------------------------------- 81 | 82 | .. automodule:: qns.network.topology.dualbarabasialberttopo 83 | :members: 84 | :undoc-members: 85 | :show-inheritance: 86 | 87 | Module contents 88 | --------------- 89 | 90 | .. automodule:: qns.network.topology 91 | :members: 92 | :undoc-members: 93 | :show-inheritance: 94 | -------------------------------------------------------------------------------- /docs/source/qns.rst: -------------------------------------------------------------------------------- 1 | qns package 2 | =========== 3 | 4 | Subpackages 5 | ----------- 6 | 7 | .. toctree:: 8 | :maxdepth: 4 9 | 10 | qns.entity 11 | qns.models 12 | qns.network 13 | qns.simulator 14 | qns.utils 15 | 16 | Module contents 17 | --------------- 18 | 19 | .. automodule:: qns 20 | :members: 21 | :undoc-members: 22 | :show-inheritance: 23 | -------------------------------------------------------------------------------- /docs/source/qns.simulator.rst: -------------------------------------------------------------------------------- 1 | qns.simulator package 2 | ===================== 3 | 4 | Submodules 5 | ---------- 6 | 7 | qns.simulator.event module 8 | -------------------------- 9 | 10 | .. automodule:: qns.simulator.event 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | qns.simulator.pool module 16 | ------------------------- 17 | 18 | .. automodule:: qns.simulator.pool 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | qns.simulator.pool module 24 | ------------------------- 25 | 26 | .. automodule:: qns.simulator.pool 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | 31 | qns.simulator.simulator module 32 | ------------------------------ 33 | 34 | .. automodule:: qns.simulator.simulator 35 | :members: 36 | :undoc-members: 37 | :show-inheritance: 38 | 39 | qns.simulator.ts module 40 | ----------------------- 41 | 42 | .. automodule:: qns.simulator.ts 43 | :members: 44 | :undoc-members: 45 | :show-inheritance: 46 | 47 | qns.simulator.ts module 48 | ----------------------- 49 | 50 | .. automodule:: qns.simulator.ts 51 | :members: 52 | :undoc-members: 53 | :show-inheritance: 54 | 55 | Module contents 56 | --------------- 57 | 58 | .. automodule:: qns.simulator 59 | :members: 60 | :undoc-members: 61 | :show-inheritance: 62 | -------------------------------------------------------------------------------- /docs/source/qns.utils.rst: -------------------------------------------------------------------------------- 1 | qns.utils package 2 | ================= 3 | 4 | Submodules 5 | ---------- 6 | 7 | qns.utils.log module 8 | -------------------- 9 | 10 | .. automodule:: qns.utils.log 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | qns.utils.multiprocess module 16 | ----------------------------- 17 | 18 | .. automodule:: qns.utils.multiprocess 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | qns.utils.rnd module 24 | -------------------- 25 | 26 | .. automodule:: qns.utils.rnd 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | 31 | Module contents 32 | --------------- 33 | 34 | .. automodule:: qns.utils 35 | :members: 36 | :undoc-members: 37 | :show-inheritance: 38 | -------------------------------------------------------------------------------- /docs/source/tutorials.entity.monitor.rst: -------------------------------------------------------------------------------- 1 | Monitor: for better collecting network status 2 | ================================================== 3 | 4 | ``Monitor`` is a virtual entity to collect network status for better analysis. It can collect network status before the simulation starts, after the simulation finishes, periodically, or when be triggered by a serial of events. It can be initiated by the following input parameters: 5 | 6 | - name, the name of this monitor 7 | - network, a optional input parameter, a ``QuantumNetwork`` object. 8 | 9 | .. code-block:: python 10 | 11 | from qns.entity.Monitor.monitor import Monitor 12 | 13 | monitor = Monitor(name="monitor_1", network = None) 14 | 15 | 16 | Users should instruct monitors how to collect the data by providing a calculate function. They can use the method ``add_attribution`` to add a new watching data. The first parameter is the attribution's name (the column's name in pandas), and the second parameter is the calculate function ``calculate_func``. This function will be called whenever the monitor is triggered. The input of ``calculate_func`` is a tuple (``Simulator``, ``QuantumNetwork``, ``Event``), so that ``calculate_func`` can get what they need from those input. The output is the calculated collecting data. Here are some examples. 17 | 18 | .. code-block:: python 19 | 20 | def watch_send_count(simulator, network, event): 21 | return sp.count 22 | 23 | def watch_recv_count(simulator, network, event): 24 | return rp.count 25 | 26 | monitor.add_attribution(name="send_count", calculate_func=watch_send_count) 27 | monitor.add_attribution(name="recv_count", calculate_func=watch_recv_count) 28 | monitor.add_attribution(name="event_name", calculate_func=lambda s, n, e: e.__class__) 29 | 30 | Finally, users should tell the monitor when to collect data. SimQN provides the following hooks: 31 | 32 | .. code-block:: python 33 | 34 | # before the simulation starts 35 | m.at_start() 36 | 37 | # after it finishes 38 | m.at_finish() 39 | 40 | # at a fixed period time 41 | m.at_period(period_time=1) 42 | 43 | # watch every ``RecvQubitPacket`` Event 44 | m.at_event(RecvQubitPacket) 45 | 46 | Before the simulation start, the monitor should be installed to the simulator by ``install`` method. After the simulation finishes, users can get the collected data using ``get_data`` function. The data will be formed in a ``pandas.DataFrame`` object. 47 | 48 | .. code-block:: python 49 | 50 | m.install(s) 51 | s.run() 52 | data = m.get_data() -------------------------------------------------------------------------------- /docs/source/tutorials.entity.rst: -------------------------------------------------------------------------------- 1 | Entities in quantum networks 2 | ================================== 3 | 4 | A quantum network in SimQN consists of several entities. All entities are child class of ``Entity``. ``Entity`` has two interfaces: 5 | 6 | - ``install``. This method will initial the entity and generate initial events to the simulator. 7 | - ``handle``. This method will be called in case of related event is happened. 8 | 9 | Entities in the quantum networks includes: 10 | 11 | .. toctree:: 12 | :maxdepth: 4 13 | 14 | tutorials.entity.node 15 | tutorials.entity.memory 16 | tutorials.entity.qchannel 17 | tutorials.entity.cchannel 18 | tutorials.entity.operator 19 | tutorials.entity.monitor 20 | tutorials.entity.other -------------------------------------------------------------------------------- /docs/source/tutorials.models.delay.rst: -------------------------------------------------------------------------------- 1 | Delay model 2 | ============================== 3 | 4 | Delay model can be used to describe a random time delay in channels, memories and operators. The basic class is ``DelayModel``. 5 | It implements a method called ``calculate`` to calculate the random time delay. 6 | 7 | Currently, SimQN provides the following three delay models: 8 | 9 | 1. ConstantDelayModel: generate a constant time delay 10 | 11 | .. code-block:: python 12 | 13 | from qns.models.delay import ConstantDelayModel 14 | 15 | delay_model = ConstantDelayModel(delay=0.5) # set time delay to a constant number 0.5 [s] 16 | 17 | delay = delay_model.calculate() # output: 0.5 18 | 19 | 2. UniformDelayModel: generate a random delay in uniform distribution X~U(min, max) 20 | 21 | .. code-block:: python 22 | 23 | from qns.models.delay import UniformDelayModel 24 | 25 | delay_model = UniformDelayModel(min_delay=0.3, max_delay=0.5) # set time delay to a random delay 26 | 27 | delay = delay_model.calculate() # output: 0.44 28 | 29 | 3. NormalDelayModel: generate a random delay in normal distribution X~N(mean_delay, std) 30 | 31 | .. code-block:: python 32 | 33 | from qns.models.delay import NormalDelayModel 34 | 35 | delay_model = NormalDelayModel(mean_delay=0.5, std=0.1) # set time delay to a random delay in normal distribution 36 | 37 | delay = delay_model.calculate() # output: 0.44 38 | 39 | Usages: a ``DelayModel`` can be a input parameters in quantum memories, quantum channels, classic channels and operators, for example: 40 | 41 | .. code-block:: python 42 | 43 | from qns.models.delay import NormalDelayModel 44 | from qns.entity.cchannel import ClassicChannel 45 | 46 | l1 = ClassicChannel(name="l1", bandwidth=10, delay=UniformDelayModel(min_delay=0.1, max_delay=0.3), 47 | drop_rate=0.1, max_buffer_size=30) -------------------------------------------------------------------------------- /docs/source/tutorials.models.rst: -------------------------------------------------------------------------------- 1 | Physical models 2 | ====================== 3 | 4 | Physical models are the models to describe qubits or entanglements. 5 | SimQN provides an interface (named ``QuantumModel``) to implement multiple physical models. 6 | Currently, SimQN present 2 models, a full functional qubit model and a high level entanglement model. Both models are the child classes of ``QuantumModel``. By extend ``QuantumModel``, other physical models can be built. 7 | 8 | ``QuantumModel`` class provides two abstract motheds, ``storage_error_model`` and ``transfer_error_model`` to describe the errors in quantum memory and channels. ``storage_error_model`` takes the storage time ``t`` and other parameters as the input. It change the quantum state accordingly. ``transfer_error_model`` takes the channel length ``length`` and other parameters as the input. 9 | 10 | .. toctree:: 11 | :maxdepth: 4 12 | 13 | tutorials.models.qubit 14 | tutorials.models.epr 15 | tutorials.models.delay -------------------------------------------------------------------------------- /docs/source/tutorials.network.request.rst: -------------------------------------------------------------------------------- 1 | Request management 2 | ======================== 3 | 4 | The request management module can select several sessions (a source node and destination node) randomly for large-scale evaluation. A ``Request`` includes the following attributions: 5 | 6 | - ``src``: the source node 7 | - ``dest``: the destination node 8 | - ``attr``: the attributions of this session, such as the fidelity requirement, the QoS or the bandwidth requirement. 9 | 10 | ``QuantumNetwork`` provides ``add_request`` to manually add a new request and ``random_requests`` to randomly generate several requests: 11 | 12 | .. code-block:: python 13 | 14 | # randomly generate 5 requests 15 | net.random_requests(number=5) 16 | 17 | # random generate 5 requests, but nodes can have multiple requests (allow overlay) 18 | net.random_requests(number=5, allow_overlay=True) 19 | 20 | # random generate 5 requests, with certain attributions 21 | net.random_requests(number=5, attr={"qos":2}) 22 | 23 | # manually add a request 24 | net.add_request(Request(src=n1, dest=n3, attr={"qos":2})) 25 | 26 | The network object and the nodes can query the related requests: 27 | 28 | .. code-block:: python 29 | 30 | net.requests # get all requests 31 | 32 | n1.requests # get all requests related to n1 33 | 34 | n1.clear_request() # remote all requests on n1 35 | 36 | Example applications and protocols 37 | ======================================== 38 | 39 | SimQN provides internal applications in ``qns.network.protocol``. 40 | 41 | ``BB84SendApp`` and ``BB84RecvApp`` is the simple demonstration protocol for BB84 QKD protocol without the after procedures, including error detecting, information reconciliation, and privacy amplification. 42 | 43 | ``EntanglementDistributionApp`` provides a hop-by-hop entanglement distribution protocol, where the source distribute entanglements to the destination at a fixed rate. 44 | 45 | ``ClassicPacketForwardApp`` can automatically forward all classic messages if the destination is not the current node. It will use the routing module (``qns.network.route``) to build classic routing tables. 46 | 47 | ``NodeProcessDelayApp`` can add processing delay on quantum nodes if they receive certain events. 48 | 49 | Those examples may be helpful for users to implement their own protocols. SimQN is working on providing more internal protocols for more scenarios. 50 | 51 | -------------------------------------------------------------------------------- /docs/source/tutorials.network.route.rst: -------------------------------------------------------------------------------- 1 | Routing algorithm 2 | ===================== 3 | 4 | SimQN network module also provides a routing algorithm interface and implements the default algorithm based on the Dijkstra's algorithm. 5 | 6 | The routing algorithm interface 7 | ---------------------------------- 8 | 9 | The routing algorithm interface is ``RouteImpl`` with two methods: 10 | 11 | - ``build`` will generate a centralized routing tables. The input is a list of quantum nodes and a list of quantum channels. 12 | - ``query`` will returns the routing query results. The input is a source node and a destionation node. The result is a list of the following result format: 13 | - metric: the routing result's metric (e.g. the total path's length) 14 | - next hop: the next hop after the source node 15 | - path: the whole path, a list of nodes on this path 16 | 17 | .. code-block:: python 18 | 19 | result = [ 20 | [3, n2, [n1, n2, n5]], # first option, metric=3, next hop=n2, path=[n1, n2, n5] 21 | [4, n3, [n1, n3, n4, n5]] # second option 22 | ] 23 | 24 | The Dijkstra's algorithm 25 | --------------------------- 26 | 27 | The ``DijkstraRouteAlgorithm`` implements the ``RouteImpl`` based on the Dijkstra's algorithm. It has a optional injectable metric function ``metric_func``. Its input is the quantum channel and returns the channels' metric. By default, the ``metric_func`` returns 1. But users can provide their own ``metric_func``, such as the bandwidth or the congestion of the channel. 28 | 29 | An example of using this algorithm is: 30 | 31 | .. code-block:: python 32 | 33 | from qns.network.topology import RandomTopology 34 | from qns.network.network import QuantumNetwork 35 | from qns.network.route import DijkstraRouteAlgorithm 36 | 37 | topo = RandomTopology( 38 | nodes_number=5, 39 | lines_number=10, 40 | qchannel_args={"delay": 0.05, "bandwidth": 10}, 41 | cchannel_args={"delay": 0.05}, 42 | memory_args=[{"capacity": 50}], 43 | nodes_apps=[EntanglementDistributionApp(init_fidelity=0.99)]) 44 | 45 | # use the ``DijkstraRouteAlgorithm``, using the bandwidth as the ``metric_func`` 46 | route = DijkstraRouteAlgorithm(metric_func=lambda qchannel: qchannel.bandwidth) 47 | 48 | # build the network, classic topology follows the quantum topology 49 | net = QuantumNetwork(topo=topo, route = route) 50 | 51 | ``QuantuNetwork`` provides two methods: ``build_route`` will build the routing tables, and ``query_route`` will query the routing result. 52 | 53 | .. code-block:: python 54 | 55 | n1 = net.get_node("n1") 56 | n5 = net.get_node("n5") 57 | 58 | # build the routing tables 59 | net.build_route() 60 | 61 | # query the routing result 62 | result = net.query_route(n1, n5) -------------------------------------------------------------------------------- /docs/source/tutorials.network.rst: -------------------------------------------------------------------------------- 1 | Construct large-scale networks 2 | =============================== 3 | 4 | SimQN provides a ``QuantumNetwork`` to help build large-scale topologies, generate routing tables and manage multiple sessions. It can be initiate with the follow parameters: 5 | 6 | - ``topo``: the optional quantum network topology generator. It can be used to produce several quantum nodes, channels and form a special topology. 7 | - ``classic_topo``: an ``Enum`` class indicate the classic topology. 8 | - ``route``: the optional routing algorithm implement. 9 | - ``name``: the networks' name 10 | 11 | The ``QuantumNetwork`` provides the following functions: 12 | 13 | .. toctree:: 14 | :maxdepth: 4 15 | 16 | tutorials.network.topology 17 | tutorials.network.route 18 | tutorials.network.request 19 | -------------------------------------------------------------------------------- /docs/source/tutorials.rst: -------------------------------------------------------------------------------- 1 | Tutorials 2 | ============================== 3 | 4 | This tutorial will explain how to use SimQN for quantum network researches. SimQN provides some example use cases in the `example` directory. 5 | 6 | .. toctree:: 7 | :maxdepth: 4 8 | 9 | tutorials.quickstart 10 | tutorials.parallel_simulation 11 | tutorials.models 12 | tutorials.entity 13 | tutorials.network 14 | tutorials.simulator 15 | tutorials.util -------------------------------------------------------------------------------- /docs/source/tutorials.util.rst: -------------------------------------------------------------------------------- 1 | Logging and random generator 2 | ==================================== 3 | 4 | The logging module 5 | ----------------------------------- 6 | 7 | SimQN uses the Python logging package as the logging and data monitor tools. To providing the simulator's internal states (especially the time), SimQN warps the logging. Users can use the ``logger`` from: 8 | 9 | .. code-block:: Python 10 | 11 | import qns.utils.log as log 12 | 13 | s = Simulator() 14 | 15 | # install the log to the simulator to get simulator's internal status 16 | log.install(s) 17 | 18 | Users can set the logging level and record logs: 19 | 20 | .. code-block:: Python 21 | 22 | import logging 23 | 24 | log.logger.setLevel(logging.INFO) 25 | a = 1 26 | 27 | log.debug("debug message") 28 | log.info("info message %d", a) 29 | log.warn("warn message %d", a + 1) 30 | log.error("error message") 31 | log.critical("critical message") 32 | 33 | Finally, SimQN provides ``monitor()`` for date output. ``sep`` sets the separator, the default separator is "," (like csv files). ``with_time`` is a boolean indicating whether add a column to record the simulator's current time. 34 | 35 | .. code-block:: Python 36 | 37 | log.monitor(data1, date2, date3, with_date = True) 38 | # output: time, date1, date2, date3 39 | 40 | With the ``Timer`` entity provided by SimQN, it is easy to print the network's status periodically. 41 | 42 | .. code-block:: python 43 | 44 | from qns.simulator.simulator import Simulator 45 | from qns.entity.timer.timer import Timer 46 | import qns.utils.log as log 47 | 48 | s = Simulator(0, 10, 1000) 49 | log.install(s) 50 | 51 | # the trigger function is log network status 52 | def trigger_func(): 53 | print("network status") 54 | 55 | # set the timer with a period 56 | t1 = Timer("t1", 0, 10, 0.5, trigger_func) 57 | t1.install(s) 58 | 59 | # run the simulation 60 | s.run() 61 | 62 | Random generator's seed 63 | -------------------------- 64 | 65 | SimQN uses ``random`` library from both Python standard library and ``numpy`` when measuring qubits or generating random topologies. To make the simulation results reproducible, SimQN provides ``set_seed()`` to fix the random generator's seed: 66 | 67 | .. code-block:: python 68 | 69 | from qns.utils.random import set_seed 70 | 71 | set_seed(1641801012) # fix the random generator's seed 72 | 73 | ``get_randint(low, high)`` can generates an random integer in [low, high]; ``get_rand(low, high)`` can generate a float random number in [low, high); and ``get_choice(a)`` selects an random element in list ``a``. -------------------------------------------------------------------------------- /examples/DEJMPS.py: -------------------------------------------------------------------------------- 1 | from qns.models.epr.mixed import MixedStateEntanglement 2 | from qns.models.qubit.gate import RX, CNOT 3 | import numpy as np 4 | 5 | 6 | def DEJMPS(q1, q2, q3, q4): 7 | """ 8 | The BEJMPS distillation protocol 9 | """ 10 | RX(q1, np.pi/2) 11 | RX(q2, np.pi/2) 12 | RX(q3, -np.pi/2) 13 | RX(q4, -np.pi/2) 14 | 15 | CNOT(q1, q2) 16 | CNOT(q3, q4) 17 | c2 = q2.measure() 18 | c4 = q4.measure() 19 | if c2 == c4: 20 | return True, q1, q3 21 | return False, None, None 22 | 23 | 24 | def main(): 25 | fail_count = 0 26 | succ_count = 0 27 | fidelity = None 28 | for _ in range(1000): 29 | e1 = MixedStateEntanglement(fidelity=0.8) 30 | e2 = MixedStateEntanglement(fidelity=0.8) 31 | 32 | q1, q3 = e1.to_qubits() 33 | print(q1.state.state) 34 | q2, q4 = e2.to_qubits() 35 | 36 | ret, q1, q3 = DEJMPS(q1, q2, q3, q4) 37 | if ret: 38 | succ_count += 1 39 | rho = q1.state.rho 40 | phi_p: np.ndarray = 1/np.sqrt(2) * np.array([[1, 0, 0, 1]]) 41 | fidelity = np.dot(phi_p, rho) 42 | fidelity = np.dot(fidelity, phi_p.T.conj()) 43 | else: 44 | fail_count += 1 45 | print(succ_count, fail_count, rho, fidelity) 46 | 47 | 48 | if __name__ == "__main__": 49 | main() 50 | -------------------------------------------------------------------------------- /examples/classic_communication.py: -------------------------------------------------------------------------------- 1 | 2 | from qns.simulator.simulator import Simulator 3 | from qns.simulator.event import Event 4 | from qns.entity.node.app import Application 5 | from qns.entity.node.node import QNode 6 | from qns.entity.cchannel.cchannel import ClassicChannel, ClassicPacket, RecvClassicPacket 7 | from qns.simulator import func_to_event 8 | 9 | 10 | # the send application 11 | class SendApp(Application): 12 | def __init__(self, dest: QNode, cchannel: ClassicChannel, send_rate=1): 13 | super().__init__() 14 | self.dest = dest 15 | self.cchannel = cchannel 16 | self.send_rate = send_rate 17 | 18 | # initiate: generate the first send event 19 | def install(self, node: QNode, simulator: Simulator): 20 | super().install(node, simulator) 21 | 22 | # get start time 23 | 24 | t = simulator.ts 25 | event = func_to_event(t, self.send_packet, by=self) 26 | self._simulator.add_event(event) 27 | 28 | def send_packet(self): 29 | # generate a packet 30 | packet = ClassicPacket(msg="Hello,world", src=self.get_node(), dest=self.dest) 31 | 32 | # send the classic packet 33 | self.cchannel.send(packet=packet, next_hop=self.dest) 34 | 35 | # calculate the next sending time 36 | t = self._simulator.current_time + \ 37 | self._simulator.time(sec=1 / self.send_rate) 38 | 39 | # insert the next send event to the simulator 40 | event = func_to_event(t, self.send_packet, by=self) 41 | self._simulator.add_event(event) 42 | 43 | 44 | class RecvApp(Application): 45 | def __init__(self): 46 | super().__init__() 47 | self.add_handler(self.handleClassicPacket, [RecvClassicPacket], []) 48 | 49 | def handleClassicPacket(self, node: QNode, event: Event): 50 | if isinstance(event, RecvClassicPacket): 51 | packet = event.packet 52 | 53 | # get the packet message 54 | msg = packet.get() 55 | 56 | # handling the receiving packet 57 | # ... 58 | print(msg) 59 | 60 | 61 | # generate quantum nodes 62 | n1 = QNode("n1") 63 | n2 = QNode("n2") 64 | 65 | # generate a classic channel 66 | l1 = ClassicChannel(name="l1") 67 | n1.add_cchannel(l1) 68 | n2.add_cchannel(l1) 69 | 70 | # add apps 71 | n1.add_apps(SendApp(dest=n2, cchannel=l1)) 72 | n2.add_apps(RecvApp()) 73 | 74 | 75 | s = Simulator(0, 10, 10000) 76 | n1.install(s) 77 | n2.install(s) 78 | 79 | # run the simulation 80 | s.run() 81 | -------------------------------------------------------------------------------- /examples/entanglement_distribution_line_topo.py: -------------------------------------------------------------------------------- 1 | import logging 2 | 3 | from qns.network.route.dijkstra import DijkstraRouteAlgorithm 4 | from qns.network.topology.topo import ClassicTopology 5 | from qns.simulator.simulator import Simulator 6 | from qns.network import QuantumNetwork 7 | from qns.network.topology import LineTopology 8 | import qns.utils.log as log 9 | from qns.network.protocol.entanglement_distribution import EntanglementDistributionApp 10 | 11 | 12 | log.logger.setLevel(logging.INFO) 13 | 14 | # constrains 15 | init_fidelity = 0.99 16 | nodes_number = 20 17 | lines_number = 19 18 | qchannel_delay = 0.05 19 | cchannel_delay = 0.05 20 | memory_capacity = 50 21 | send_rate = 10 22 | 23 | nodes_number = 10 24 | for nodes_number in range(2, 21): 25 | result = [] 26 | for delay in [0.1, 0.07, 0.05, 0.03]: 27 | s = Simulator(0, 30, accuracy=10000000) 28 | log.install(s) 29 | topo = LineTopology(nodes_number=nodes_number, 30 | qchannel_args={"delay": delay}, 31 | cchannel_args={"delay": delay}, 32 | memory_args=[{ 33 | "capacity": memory_capacity, 34 | "decoherence_rate": 0.2}], 35 | nodes_apps=[EntanglementDistributionApp(init_fidelity=init_fidelity)]) 36 | 37 | net = QuantumNetwork( 38 | topo=topo, classic_topo=ClassicTopology.All, route=DijkstraRouteAlgorithm()) 39 | net.build_route() 40 | 41 | src = net.get_node("n1") 42 | dst = net.get_node(f"n{nodes_number}") 43 | net.add_request(src=src, dest=dst, attr={"send_rate": send_rate}) 44 | net.install(s) 45 | s.run() 46 | result.append(dst.apps[-1].success[0].fidelity) 47 | log.monitor(f"{nodes_number} {result[0]} {result[1]} {result[2]} {result[3]}") 48 | -------------------------------------------------------------------------------- /examples/entanglement_distribution_random_topo.py: -------------------------------------------------------------------------------- 1 | import logging 2 | 3 | from qns.network.route.dijkstra import DijkstraRouteAlgorithm 4 | from qns.network.topology.topo import ClassicTopology 5 | from qns.simulator.simulator import Simulator 6 | from qns.network import QuantumNetwork 7 | from qns.network.topology import RandomTopology 8 | import qns.utils.log as log 9 | from qns.utils.rnd import set_seed 10 | from qns.network.protocol.entanglement_distribution import EntanglementDistributionApp 11 | 12 | # constrains 13 | init_fidelity = 0.99 14 | nodes_number = 150 15 | lines_number = 450 16 | qchannel_delay = 0.05 17 | cchannel_delay = 0.05 18 | memory_capacity = 50 19 | send_rate = 10 20 | requests_number = 10 21 | 22 | log.logger.setLevel(logging.INFO) 23 | 24 | for requests_number in [10, 20, 30, 40]: 25 | for nodes_number in range(20, 201, 10): 26 | lines_number = 3 * nodes_number 27 | # set a fixed random seed 28 | set_seed(100) 29 | s = Simulator(0, 10, accuracy=1000000) 30 | log.install(s) 31 | 32 | topo = RandomTopology(nodes_number=nodes_number, 33 | lines_number=lines_number, 34 | qchannel_args={"delay": qchannel_delay}, 35 | cchannel_args={"delay": cchannel_delay}, 36 | memory_args=[{"capacity": memory_capacity}], 37 | nodes_apps=[EntanglementDistributionApp(init_fidelity=init_fidelity)]) 38 | 39 | net = QuantumNetwork( 40 | topo=topo, classic_topo=ClassicTopology.All, route=DijkstraRouteAlgorithm()) 41 | 42 | net.build_route() 43 | try: 44 | net.random_requests(requests_number, attr={"send_rate": send_rate}) 45 | except Exception: 46 | continue 47 | net.install(s) 48 | 49 | s.run() 50 | results = [] 51 | for req in net.requests: 52 | src = req.src 53 | results.append(src.apps[0].success_count) 54 | fair = sum(results)**2 / (len(results) * sum([r**2 for r in results])) 55 | log.monitor(requests_number, nodes_number, s.time_spend, sep=" ") 56 | -------------------------------------------------------------------------------- /examples/entanglement_swapping.py: -------------------------------------------------------------------------------- 1 | from qns.models.qubit.qubit import Qubit 2 | from qns.models.qubit.gate import H, CNOT, X, Z 3 | from qns.models.qubit.const import QUBIT_STATE_0 4 | 5 | q0 = Qubit(state=QUBIT_STATE_0, name="q0") 6 | q1 = Qubit(state=QUBIT_STATE_0, name="q1") 7 | 8 | q2 = Qubit(state=QUBIT_STATE_0, name="q2") 9 | q3 = Qubit(state=QUBIT_STATE_0, name="q3") 10 | 11 | # entangle q0 and q1 12 | H(q0) 13 | CNOT(q0, q1) 14 | 15 | # entangle q2 and q3 16 | H(q2) 17 | CNOT(q2, q3) 18 | 19 | # entanglement swapping 20 | CNOT(q1, q2) 21 | H(q1) 22 | 23 | # measure q2 and q1 24 | c0 = q2.measure() 25 | c1 = q1.measure() 26 | 27 | if c0 == 1 and c1 == 0: 28 | X(q3) 29 | elif c0 == 0 and c1 == 1: 30 | Z(q3) 31 | elif c0 == 1 and c1 == 1: 32 | X(q3) 33 | Z(q3) 34 | 35 | # now q0 and q3 are entangled 36 | assert (q0.measure() == q3.measure()) 37 | -------------------------------------------------------------------------------- /examples/parallel_experiments.py: -------------------------------------------------------------------------------- 1 | from qns.utils.multiprocess import MPSimulations 2 | from qns.network.route.dijkstra import DijkstraRouteAlgorithm 3 | from qns.network.topology.topo import ClassicTopology 4 | from qns.simulator.simulator import Simulator 5 | from qns.network import QuantumNetwork 6 | from qns.network.topology import LineTopology 7 | from qns.network.protocol.entanglement_distribution import EntanglementDistributionApp 8 | 9 | 10 | class EPRDistributionSimulation(MPSimulations): 11 | def run(self, setting): 12 | nodes_number = setting["nodes_number"] 13 | delay = setting["delay"] 14 | memory_capacity = setting["memory_capacity"] 15 | send_rate = setting["send_rate"] 16 | s = Simulator(0, 10, accuracy=10000000) 17 | topo = LineTopology(nodes_number=nodes_number, 18 | qchannel_args={"delay": delay, "drop_rate": 0.3}, 19 | cchannel_args={"delay": delay}, 20 | memory_args={ 21 | "capacity": memory_capacity, 22 | "store_error_model_args": {"a": 0.2}}, 23 | nodes_apps=[EntanglementDistributionApp(init_fidelity=0.99)]) 24 | 25 | net = QuantumNetwork( 26 | topo=topo, classic_topo=ClassicTopology.All, route=DijkstraRouteAlgorithm()) 27 | net.build_route() 28 | 29 | src = net.get_node("n1") 30 | dst = net.get_node(f"n{nodes_number}") 31 | net.add_request(src=src, dest=dst, attr={"send_rate": send_rate}) 32 | net.install(s) 33 | s.run() 34 | return {"count": src.apps[0].success_count} 35 | 36 | 37 | if __name__ == "__main__": 38 | ss = EPRDistributionSimulation(settings={ 39 | "nodes_number": [5, 10, 15, 20, 25, 30], 40 | "delay": [0.05], 41 | "memory_capacity": [10, 20, 30], 42 | "send_rate": [1000, 2000] 43 | }, aggregate=True, iter_count=10, cores=20) 44 | ss.start() 45 | print(ss.get_data()) 46 | -------------------------------------------------------------------------------- /examples/simple_bb84.py: -------------------------------------------------------------------------------- 1 | from qns.entity.cchannel.cchannel import ClassicChannel 2 | from qns.entity.qchannel.qchannel import QuantumChannel 3 | from qns.entity import QNode 4 | from qns.simulator.simulator import Simulator 5 | from qns.network.protocol.bb84 import BB84RecvApp, BB84SendApp, KEY_BLOCK_SIZE 6 | import numpy as np 7 | 8 | light_speed = 299791458 9 | 10 | 11 | def drop_rate(length): 12 | # drop 0.2 db/KM 13 | return 1 - np.exp(- length / 50000) 14 | 15 | 16 | for length in [1000, 5000, 10000, 50000, 100000, 150000]: 17 | results = [] 18 | for i in range(10): 19 | s = Simulator(0, 10, accuracy=10000000000) 20 | n1 = QNode(name="n1") 21 | n2 = QNode(name="n2") 22 | 23 | qlink = QuantumChannel(name="l1", delay=length / light_speed, 24 | drop_rate=drop_rate(length)) 25 | 26 | clink = ClassicChannel(name="c1", delay=length / light_speed) 27 | 28 | n1.add_cchannel(clink) 29 | n2.add_cchannel(clink) 30 | n1.add_qchannel(qlink) 31 | n2.add_qchannel(qlink) 32 | 33 | sp = BB84SendApp(n2, qlink, clink, send_rate=1000) 34 | rp = BB84RecvApp(n1, qlink, clink) 35 | n1.add_apps(sp) 36 | n2.add_apps(rp) 37 | 38 | n1.install(s) 39 | n2.install(s) 40 | 41 | s.run() 42 | results.append(len(sp.key_pool)*KEY_BLOCK_SIZE / 10) 43 | print("length", length, "sp key block num", len(sp.key_pool)) 44 | print("length", length, "rp key block num", len(rp.key_pool)) 45 | print(length, np.mean(results), np.std(results)) 46 | -------------------------------------------------------------------------------- /examples/trusted_relay_bb84.py: -------------------------------------------------------------------------------- 1 | from qns.network.topology.topo import ClassicTopology 2 | from qns.simulator.simulator import Simulator 3 | from qns.network import QuantumNetwork 4 | from qns.network.topology import LineTopology 5 | from qns.network.protocol.bb84 import BB84RecvApp, BB84SendApp 6 | 7 | import numpy as np 8 | 9 | light_speed = 299791458 10 | total_length = 100000 11 | 12 | 13 | def drop_rate(length): 14 | # drop 0.2 db/KM 15 | return 1 - np.exp(- length / 50000) 16 | 17 | 18 | for num in [2, 3, 4, 5, 6]: 19 | results = [] 20 | for i in range(10): 21 | length = total_length / (num - 1) 22 | s = Simulator(0, 10, accuracy=10000000000) 23 | 24 | topo = LineTopology(num, nodes_apps=[], qchannel_args={ 25 | "delay": length / light_speed, 26 | "drop_rate": drop_rate(length)}, 27 | cchannel_args={"delay": length / light_speed}) 28 | 29 | net = QuantumNetwork(topo=topo, classic_topo=ClassicTopology.Follow) 30 | 31 | rps = [] 32 | for qchannel in net.qchannels: 33 | (src, dst) = qchannel.node_list 34 | cchannel = None 35 | for c in net.cchannels: 36 | if c.name == f"c-{qchannel.name}": 37 | cchannel = c 38 | assert (cchannel is not None) 39 | 40 | sp = BB84SendApp(dst, qchannel, cchannel, send_rate=1000) 41 | rp = BB84RecvApp(src, qchannel, cchannel) 42 | src.add_apps(sp) 43 | dst.add_apps(rp) 44 | rps.append(rp) 45 | 46 | for n in net.nodes: 47 | n.install(s) 48 | s.run() 49 | rets = [len(rp.succ_key_pool) / 10 for rp in rps] 50 | results.append(min(rets)) 51 | print(num, np.mean(results), np.std(results)) 52 | -------------------------------------------------------------------------------- /qns/__init__.py: -------------------------------------------------------------------------------- 1 | # SimQN: a discrete-event simulator for the quantum networks 2 | # Copyright (C) 2021-2022 Lutong Chen, Jian Li, Kaiping Xue 3 | # University of Science and Technology of China, USTC. 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | version = '0.2.1' 19 | licence = 'GPLv3' 20 | author = 'Lutong Chen, Jian Li and Kaiping Xue' 21 | -------------------------------------------------------------------------------- /qns/entity/__init__.py: -------------------------------------------------------------------------------- 1 | # SimQN: a discrete-event simulator for the quantum networks 2 | # Copyright (C) 2021-2022 Lutong Chen, Jian Li, Kaiping Xue 3 | # University of Science and Technology of China, USTC. 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | from qns.entity.entity import Entity 19 | from qns.entity.node.node import QNode, Application 20 | from qns.entity.timer.timer import Timer 21 | from qns.entity.memory.memory import QuantumMemory 22 | from qns.entity.memory.event import MemoryReadRequestEvent, MemoryReadResponseEvent, \ 23 | MemoryWriteRequestEvent, MemoryWriteResponseEvent 24 | from qns.entity.cchannel.cchannel import ClassicChannel, ClassicPacket, RecvClassicPacket 25 | from qns.entity.qchannel.qchannel import QuantumChannel, RecvQubitPacket 26 | from qns.entity.operator import QuantumOperator, OperateRequestEvent, OperateResponseEvent 27 | from qns.entity.monitor.monitor import Monitor, MonitorEvent 28 | 29 | __all__ = ["Entity", "QNode", "Application", "Timer", "QuantumMemory", "ClassicChannel", "QuantumMemory", 30 | "ClassicPacket", "RecvClassicPacket", "QuantumChannel", "RecvQubitPacket", 31 | "QuantumOperator", "OperateRequestEvent", "OperateResponseEvent", 32 | "MemoryReadRequestEvent", "MemoryReadResponseEvent", 33 | "MemoryWriteRequestEvent", "MemoryWriteResponseEvent", "Monitor", "MonitorEvent"] 34 | -------------------------------------------------------------------------------- /qns/entity/cchannel/__init__.py: -------------------------------------------------------------------------------- 1 | # SimQN: a discrete-event simulator for the quantum networks 2 | # Copyright (C) 2021-2022 Lutong Chen, Jian Li, Kaiping Xue 3 | # University of Science and Technology of China, USTC. 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | from qns.entity.cchannel.cchannel import ClassicChannel, ClassicPacket, RecvClassicPacket 19 | 20 | __all__ = ["ClassicChannel", "ClassicPacket", "RecvClassicPacket"] 21 | -------------------------------------------------------------------------------- /qns/entity/entity.py: -------------------------------------------------------------------------------- 1 | # SimQN: a discrete-event simulator for the quantum networks 2 | # Copyright (C) 2021-2022 Lutong Chen, Jian Li, Kaiping Xue 3 | # University of Science and Technology of China, USTC. 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | from qns.simulator.simulator import Simulator 19 | from qns.simulator.event import Event 20 | 21 | 22 | class Entity(object): 23 | """ 24 | This is the basic entity class, including memories, channels and nodes. 25 | """ 26 | 27 | def __init__(self, name: str = None): 28 | """ 29 | Args: 30 | name (str): the name of this entity 31 | """ 32 | self.name = name 33 | self._is_installed = False 34 | self._simulator = None 35 | 36 | def install(self, simulator: Simulator) -> None: 37 | ''' 38 | ``install`` is called before ``simulator`` runs to initialize or set initial events 39 | 40 | Args: 41 | simulator (qns.simulator.simulator.Simulator): the simulator 42 | ''' 43 | if not self._is_installed: 44 | self._simulator = simulator 45 | self._is_installed = True 46 | 47 | def handle(self, event: Event) -> None: 48 | ''' 49 | ``handle`` is called to process an receiving ``Event``. 50 | 51 | Args: 52 | event (qns.simulator.event.Event): the event that send to this entity 53 | ''' 54 | raise NotImplementedError 55 | 56 | def __repr__(self) -> str: 57 | if self.name is not None: 58 | return f"" 59 | return super().__repr__() 60 | -------------------------------------------------------------------------------- /qns/entity/memory/__init__.py: -------------------------------------------------------------------------------- 1 | # SimQN: a discrete-event simulator for the quantum networks 2 | # Copyright (C) 2021-2022 Lutong Chen, Jian Li, Kaiping Xue 3 | # University of Science and Technology of China, USTC. 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | 19 | from qns.entity.memory.memory import QuantumMemory 20 | from qns.entity.memory.event import MemoryReadRequestEvent, MemoryReadResponseEvent, \ 21 | MemoryWriteRequestEvent, MemoryWriteResponseEvent 22 | 23 | __all__ = ["QuantumMemory", "MemoryReadRequestEvent", "MemoryReadResponseEvent", 24 | "MemoryWriteRequestEvent", "MemoryWriteResponseEvent"] 25 | -------------------------------------------------------------------------------- /qns/entity/monitor/__init__.py: -------------------------------------------------------------------------------- 1 | # SimQN: a discrete-event simulator for the quantum networks 2 | # Copyright (C) 2021-2022 Lutong Chen, Jian Li, Kaiping Xue 3 | # University of Science and Technology of China, USTC. 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | from qns.entity.monitor.monitor import Monitor, MonitorEvent 19 | 20 | __all__ = ["Monitor", "MonitorEvent"] 21 | -------------------------------------------------------------------------------- /qns/entity/node/__init__.py: -------------------------------------------------------------------------------- 1 | # SimQN: a discrete-event simulator for the quantum networks 2 | # Copyright (C) 2021-2022 Lutong Chen, Jian Li, Kaiping Xue 3 | # University of Science and Technology of China, USTC. 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | from qns.entity.node.node import QNode 19 | from qns.entity.node.app import Application 20 | 21 | __all__ = ["QNode", "Application"] 22 | -------------------------------------------------------------------------------- /qns/entity/operator/__init__.py: -------------------------------------------------------------------------------- 1 | # SimQN: a discrete-event simulator for the quantum networks 2 | # Copyright (C) 2021-2022 Lutong Chen, Jian Li, Kaiping Xue 3 | # University of Science and Technology of China, USTC. 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | from qns.entity.operator.operator import QuantumOperator 19 | from qns.entity.operator.event import OperateRequestEvent, OperateResponseEvent 20 | 21 | __all__ = ["QuantumOperator", "OperateRequestEvent", "OperateResponseEvent"] 22 | -------------------------------------------------------------------------------- /qns/entity/operator/event.py: -------------------------------------------------------------------------------- 1 | # SimQN: a discrete-event simulator for the quantum networks 2 | # Copyright (C) 2021-2022 Lutong Chen, Jian Li, Kaiping Xue 3 | # University of Science and Technology of China, USTC. 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | from typing import Any, List, Optional, Union 19 | from qns.entity.node.node import QNode 20 | from qns.models.core.backend import QuantumModel 21 | from qns.simulator.event import Event 22 | from qns.simulator.ts import Time 23 | 24 | 25 | class OperateRequestEvent(Event): 26 | """ 27 | ``OperateRequestEvent`` is the event that request a operator to handle 28 | """ 29 | def __init__(self, operator, qubits: List[QuantumModel] = [], 30 | t: Optional[Time] = None, name: Optional[str] = None, by: Optional[Any] = None): 31 | super().__init__(t=t, name=name, by=by) 32 | from qns.entity.operator.operator import QuantumOperator 33 | self.operator: QuantumOperator = operator 34 | self.qubits = qubits 35 | 36 | def invoke(self) -> None: 37 | self.operator.handle(self) 38 | 39 | 40 | class OperateResponseEvent(Event): 41 | """ 42 | ``OperateResponseEvent`` is the event that returns the operating result 43 | """ 44 | def __init__(self, node: QNode, result: Union[int, List[int]] = None, 45 | request: OperateRequestEvent = None, t: Optional[Time] = None, name: Optional[str] = None, 46 | by: Optional[Any] = None): 47 | super().__init__(t=t, name=name, by=by) 48 | self.node = node 49 | self.result = result 50 | self.request = request 51 | 52 | def invoke(self) -> None: 53 | self.node.handle(self) 54 | -------------------------------------------------------------------------------- /qns/entity/qchannel/__init__.py: -------------------------------------------------------------------------------- 1 | # SimQN: a discrete-event simulator for the quantum networks 2 | # Copyright (C) 2021-2022 Lutong Chen, Jian Li, Kaiping Xue 3 | # University of Science and Technology of China, USTC. 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | from qns.entity.qchannel.qchannel import QuantumChannel, RecvQubitPacket 19 | from qns.entity.qchannel.losschannel import QubitLossChannel 20 | 21 | __all__ = ["QuantumChannel", "QubitLossChannel", "RecvQubitPacket"] 22 | -------------------------------------------------------------------------------- /qns/entity/timer/__init__.py: -------------------------------------------------------------------------------- 1 | # SimQN: a discrete-event simulator for the quantum networks 2 | # Copyright (C) 2021-2022 Lutong Chen, Jian Li, Kaiping Xue 3 | # University of Science and Technology of China, USTC. 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | from qns.entity.timer.timer import Timer 19 | 20 | __all__ = ["Timer"] 21 | -------------------------------------------------------------------------------- /qns/models/__init__.py: -------------------------------------------------------------------------------- 1 | from qns.models.core.backend import QuantumModel 2 | 3 | 4 | __all__ = ["QuantumModel"] 5 | -------------------------------------------------------------------------------- /qns/models/core/__init__.py: -------------------------------------------------------------------------------- 1 | # SimQN: a discrete-event simulator for the quantum networks 2 | # Copyright (C) 2021-2022 Lutong Chen, Jian Li, Kaiping Xue 3 | # University of Science and Technology of China, USTC. 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | from qns.models.core.backend import QuantumModel 19 | 20 | __all__ = ["QuantumModel"] 21 | -------------------------------------------------------------------------------- /qns/models/delay/__init__.py: -------------------------------------------------------------------------------- 1 | # SimQN: a discrete-event simulator for the quantum networks 2 | # Copyright (C) 2021-2022 Lutong Chen, Jian Li, Kaiping Xue 3 | # University of Science and Technology of China, USTC. 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | from qns.models.delay.delay import DelayModel 19 | from qns.models.delay.constdelay import ConstantDelayModel 20 | from qns.models.delay.uniformdelay import UniformDelayModel 21 | from qns.models.delay.normaldelay import NormalDelayModel 22 | 23 | __all__ = ["DelayModel", "ConstantDelayModel", "UniformDelayModel", "NormalDelayModel"] 24 | -------------------------------------------------------------------------------- /qns/models/delay/constdelay.py: -------------------------------------------------------------------------------- 1 | # SimQN: a discrete-event simulator for the quantum networks 2 | # Copyright (C) 2021-2022 Lutong Chen, Jian Li, Kaiping Xue 3 | # University of Science and Technology of China, USTC. 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | from typing import Optional 19 | from qns.models.delay.delay import DelayModel 20 | 21 | 22 | class ConstantDelayModel(DelayModel): 23 | def __init__(self, delay: float = 0, name: Optional[str] = None) -> None: 24 | """ 25 | A constant delay model 26 | 27 | Args: 28 | name (str): the name of this delay model 29 | delay (float): the time delay [s] 30 | """ 31 | super().__init__(name) 32 | self._delay = delay 33 | 34 | def calculate(self) -> float: 35 | """ 36 | Return: 37 | the time delay [s] 38 | """ 39 | return self._delay 40 | -------------------------------------------------------------------------------- /qns/models/delay/delay.py: -------------------------------------------------------------------------------- 1 | # SimQN: a discrete-event simulator for the quantum networks 2 | # Copyright (C) 2021-2022 Lutong Chen, Jian Li, Kaiping Xue 3 | # University of Science and Technology of China, USTC. 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | 19 | from typing import Optional 20 | 21 | 22 | class DelayModel(): 23 | """ 24 | The model for delay in storing, operating and transmitting qubits or eprs. 25 | """ 26 | def __init__(self, name: Optional[str] = None) -> None: 27 | """ 28 | Args: 29 | name (str): the name of this delay model 30 | """ 31 | self.name = name 32 | 33 | def calculate(self) -> float: 34 | """ 35 | Return: 36 | the time delay in second, default is 0 37 | """ 38 | return 0 39 | -------------------------------------------------------------------------------- /qns/models/delay/normaldelay.py: -------------------------------------------------------------------------------- 1 | # SimQN: a discrete-event simulator for the quantum networks 2 | # Copyright (C) 2021-2022 Lutong Chen, Jian Li, Kaiping Xue 3 | # University of Science and Technology of China, USTC. 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | from typing import Optional 19 | from qns.models.delay.delay import DelayModel 20 | from qns.utils.rnd import get_normal 21 | 22 | 23 | class NormalDelayModel(DelayModel): 24 | def __init__(self, mean_delay: float = 0, std: float = 0, name: Optional[str] = None) -> None: 25 | """ 26 | A random delay from normal distribution X~N(mean_delay, std^2) 27 | 28 | Args: 29 | name (str): the name of this delay model 30 | mean_delay (float): the mean of the time delay [s] 31 | std (float): the standand deviation [s] 32 | """ 33 | super().__init__(name) 34 | self._mean_delay = mean_delay 35 | self._std = std 36 | 37 | def calculate(self) -> float: 38 | return get_normal(self._mean_delay, self._std) 39 | -------------------------------------------------------------------------------- /qns/models/delay/uniformdelay.py: -------------------------------------------------------------------------------- 1 | # SimQN: a discrete-event simulator for the quantum networks 2 | # Copyright (C) 2021-2022 Lutong Chen, Jian Li, Kaiping Xue 3 | # University of Science and Technology of China, USTC. 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | from typing import Optional 19 | from qns.models.delay.delay import DelayModel 20 | from qns.utils.rnd import get_rand 21 | 22 | 23 | class UniformDelayModel(DelayModel): 24 | def __init__(self, min_delay: float = 0, max_delay: float = 0, name: Optional[str] = None) -> None: 25 | """ 26 | A random delay from distribution X~U(min, max) 27 | 28 | Args: 29 | name (str): the name of this delay model 30 | min_delay (float): the minimum time delay [s] 31 | max_delay (float): the maximum time delay [s] 32 | """ 33 | super().__init__(name) 34 | assert (max_delay >= min_delay) 35 | self._min_delay = min_delay 36 | self._max_delay = max_delay 37 | 38 | def calculate(self) -> float: 39 | return get_rand(self._min_delay, self._max_delay) 40 | -------------------------------------------------------------------------------- /qns/models/epr/__init__.py: -------------------------------------------------------------------------------- 1 | # SimQN: a discrete-event simulator for the quantum networks 2 | # Copyright (C) 2021-2022 Lutong Chen, Jian Li, Kaiping Xue 3 | # University of Science and Technology of China, USTC. 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | from qns.models.epr.entanglement import BaseEntanglement 19 | from qns.models.epr.bell import BellStateEntanglement 20 | from qns.models.epr.werner import WernerStateEntanglement 21 | from qns.models.epr.mixed import MixedStateEntanglement 22 | 23 | __all__ = ["BellStateEntanglement", "WernerStateEntanglement", "BaseEntanglement", "MixedStateEntanglement"] 24 | -------------------------------------------------------------------------------- /qns/models/qubit/__init__.py: -------------------------------------------------------------------------------- 1 | # SimQN: a discrete-event simulator for the quantum networks 2 | # Copyright (C) 2021-2022 Lutong Chen, Jian Li, Kaiping Xue 3 | # University of Science and Technology of China, USTC. 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | from qns.models.qubit.qubit import Qubit, QState 19 | from qns.models.qubit.gate import X, Y, Z, H, S, T, R, I, CNOT, joint, \ 20 | RX, RY, RZ, U, CZ, CR, CX, CY, ControlledGate, Swap, Toffoli 21 | from qns.models.qubit.utils import single_gate_expand 22 | from qns.models.qubit.decoherence import PrefectMeasureErrorModel, PrefectOperateErrorModel, \ 23 | PrefectStorageErrorModel, PrefectTransferErrorModel, DephaseMeasureErrorModel, \ 24 | DephaseOperateErrorModel, DephaseStorageErrorModel, DephaseTransferErrorModel, \ 25 | DepolarMeasureErrorModel, DepolarOperateErrorModel, DepolarStorageErrorModel, DepolarTransferErrorModel 26 | from qns.models.qubit.factory import QubitFactory 27 | 28 | __all__ = ["Qubit", "QState", "X", "Y", "Z", "H", "S", 29 | "T", "R", "I", "CNOT", "joint", "RX", "RY", "RZ", "U", "CX", "CY", 30 | "CZ", "CR", "ControlledGate", "Swap", "Toffoli", "single_gate_expand", 31 | "PrefectMeasureErrorModel", "PrefectOperateErrorModel", 32 | "PrefectStorageErrorModel", "PrefectTransferErrorModel", "DephaseMeasureErrorModel", 33 | "DephaseOperateErrorModel", "DephaseStorageErrorModel", "DephaseTransferErrorModel", 34 | "DepolarMeasureErrorModel", "DepolarOperateErrorModel", "DepolarStorageErrorModel", 35 | "DepolarTransferErrorModel", "QubitFactory"] 36 | -------------------------------------------------------------------------------- /qns/models/qubit/errors.py: -------------------------------------------------------------------------------- 1 | # SimQN: a discrete-event simulator for the quantum networks 2 | # Copyright (C) 2021-2022 Lutong Chen, Jian Li, Kaiping Xue 3 | # University of Science and Technology of China, USTC. 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | class QStateSizeNotMatchError(Exception): 19 | """ 20 | This error happens when the size of state vector or matrix mismatch occurs 21 | """ 22 | pass 23 | 24 | 25 | class QStateQubitNotInStateError(Exception): 26 | pass 27 | 28 | 29 | class OperatorNotMatchError(Exception): 30 | """ 31 | This error happens when the size of state vector or matrix mismatch occurs 32 | """ 33 | pass 34 | 35 | 36 | class QGateOperatorNotMatchError(Exception): 37 | pass 38 | 39 | 40 | class QGateQubitNotInStateError(Exception): 41 | pass 42 | 43 | 44 | class QGateStateJointError(Exception): 45 | pass 46 | 47 | 48 | class QStateBaseError(Exception): 49 | pass 50 | 51 | 52 | class OperatorError(Exception): 53 | pass 54 | -------------------------------------------------------------------------------- /qns/network/__init__.py: -------------------------------------------------------------------------------- 1 | # SimQN: a discrete-event simulator for the quantum networks 2 | # Copyright (C) 2021-2022 Lutong Chen, Jian Li, Kaiping Xue 3 | # University of Science and Technology of China, USTC. 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | from qns.network.network import QuantumNetwork, QNSNetworkError 19 | from qns.network.requests import Request 20 | from qns.network.topology import Topology, LineTopology, RandomTopology, \ 21 | GridTopology, TreeTopology, BasicTopology, WaxmanTopology, \ 22 | ErdosRenyiTopology, BarabasiAlbertTopology, DualBarabasiAlbertTopology 23 | from qns.network.route.route import RouteImpl, NetworkRouteError 24 | from qns.network.route.dijkstra import DijkstraRouteAlgorithm 25 | 26 | __all__ = ["QuantumNetwork", "Request", "Topology", "LineTopology", "NetworkRouteError", 27 | "RandomTopology", "GridTopology", "TreeTopology", "BasicTopology", "WaxmanTopology", "ErdosRenyiTopology", 28 | "BarabasiAlbertTopology", 29 | "DualBarabasiAlbertTopology", 30 | "RouteImpl", "DijkstraRouteAlgorithm", "QNSNetworkError"] 31 | -------------------------------------------------------------------------------- /qns/network/protocol/__init__.py: -------------------------------------------------------------------------------- 1 | # SimQN: a discrete-event simulator for the quantum networks 2 | # Copyright (C) 2021-2022 Lutong Chen, Jian Li, Kaiping Xue 3 | # University of Science and Technology of China, USTC. 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | from qns.network.protocol.bb84 import BB84SendApp, BB84RecvApp 19 | from qns.network.protocol.entanglement_distribution import EntanglementDistributionApp 20 | from qns.network.protocol.classicforward import ClassicPacketForwardApp 21 | from qns.network.protocol.node_process_delay import NodeProcessDelayApp 22 | 23 | __all__ = ["BB84SendApp", "BB84RecvApp", "EntanglementDistributionApp", 24 | "ClassicPacketForwardApp", "NodeProcessDelayApp"] 25 | -------------------------------------------------------------------------------- /qns/network/requests.py: -------------------------------------------------------------------------------- 1 | # SimQN: a discrete-event simulator for the quantum networks 2 | # Copyright (C) 2021-2022 Lutong Chen, Jian Li, Kaiping Xue 3 | # University of Science and Technology of China, USTC. 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | from typing import Dict 19 | 20 | 21 | class Request(): 22 | """ 23 | A request is a source-destination pair represents a quantum transmitting request. 24 | """ 25 | 26 | def __init__(self, src, dest, attr: Dict = {}) -> None: 27 | """ 28 | Args: 29 | src: the source node 30 | dest: the destination node 31 | attr: other attributions 32 | """ 33 | from qns.entity import QNode 34 | self.src: QNode = src 35 | self.dest: QNode = dest 36 | self.attr: Dict = attr 37 | 38 | def __repr__(self) -> str: 39 | return f"{self.dest}>" 40 | -------------------------------------------------------------------------------- /qns/network/route/__init__.py: -------------------------------------------------------------------------------- 1 | # SimQN: a discrete-event simulator for the quantum networks 2 | # Copyright (C) 2021-2022 Lutong Chen, Jian Li, Kaiping Xue 3 | # University of Science and Technology of China, USTC. 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | from qns.network.route.route import RouteImpl, NetworkRouteError 19 | from qns.network.route.dijkstra import DijkstraRouteAlgorithm 20 | 21 | __all__ = ["RouteImpl", "NetworkRouteError", "DijkstraRouteAlgorithm"] 22 | -------------------------------------------------------------------------------- /qns/network/route/route.py: -------------------------------------------------------------------------------- 1 | # SimQN: a discrete-event simulator for the quantum networks 2 | # Copyright (C) 2021-2022 Lutong Chen, Jian Li, Kaiping Xue 3 | # University of Science and Technology of China, USTC. 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | from typing import List, Tuple, Union 19 | from qns.entity import QNode 20 | from qns.entity.qchannel.qchannel import QuantumChannel 21 | from qns.entity.cchannel.cchannel import ClassicChannel 22 | 23 | 24 | class NetworkRouteError(Exception): 25 | pass 26 | 27 | 28 | class RouteImpl(): 29 | """ 30 | This is the route protocol interface 31 | """ 32 | 33 | def __init__(self, name: str = "route") -> None: 34 | self.name = name 35 | 36 | def build(self, nodes: List[QNode], channels: List[Union[QuantumChannel, ClassicChannel]]): 37 | """ 38 | build static route tables for each nodes 39 | 40 | args: 41 | channels: a list of quantum channels or classic channels 42 | """ 43 | raise NotImplementedError 44 | 45 | def query(self, src: QNode, dest: QNode) -> List[Tuple[float, QNode, List[QNode]]]: 46 | """ 47 | query the metric, nexthop and the path 48 | 49 | Args: 50 | src: the source node 51 | dest: the destination node 52 | 53 | Returns: 54 | A list of route paths. The result should be sortted by the priority. 55 | The element is a tuple containing: metric, the next-hop and the whole path. 56 | """ 57 | raise NotImplementedError 58 | -------------------------------------------------------------------------------- /qns/network/topology/__init__.py: -------------------------------------------------------------------------------- 1 | # SimQN: a discrete-event simulator for the quantum networks 2 | # Copyright (C) 2021-2022 Lutong Chen, Jian Li, Kaiping Xue 3 | # University of Science and Technology of China, USTC. 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | from qns.network.topology.topo import Topology 19 | from qns.network.topology.basictopo import BasicTopology 20 | from qns.network.topology.linetopo import LineTopology 21 | from qns.network.topology.treetopo import TreeTopology 22 | from qns.network.topology.gridtopo import GridTopology 23 | from qns.network.topology.randomtopo import RandomTopology 24 | from qns.network.topology.waxmantopo import WaxmanTopology 25 | from qns.network.topology.erdosrenyitopo import ErdosRenyiTopology 26 | from qns.network.topology.barabasialberttopo import BarabasiAlbertTopology 27 | from qns.network.topology.dualbarabasialberttopo import DualBarabasiAlbertTopology 28 | 29 | __all__ = ["Topology", "BasicTopology", "LineTopology", 30 | "TreeTopology", "GridTopology", "RandomTopology", 31 | "WaxmanTopology", "ErdosRenyiTopology", 32 | "BarabasiAlbertTopology", "DualBarabasiAlbertTopology"] 33 | -------------------------------------------------------------------------------- /qns/network/topology/basictopo.py: -------------------------------------------------------------------------------- 1 | # SimQN: a discrete-event simulator for the quantum networks 2 | # Copyright (C) 2021-2022 Lutong Chen, Jian Li, Kaiping Xue 3 | # University of Science and Technology of China, USTC. 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | from qns.entity.node.app import Application 19 | from qns.entity.qchannel.qchannel import QuantumChannel 20 | from qns.entity.node.node import QNode 21 | from typing import Dict, List, Optional, Tuple 22 | from qns.network.topology.topo import Topology 23 | 24 | 25 | class BasicTopology(Topology): 26 | """ 27 | BasicTopology includes `nodes_number` Qnodes. None of them are connected with each other 28 | """ 29 | def __init__(self, nodes_number, nodes_apps: List[Application] = [], 30 | qchannel_args: Dict = {}, cchannel_args: Dict = {}, 31 | memory_args: Optional[List[Dict]] = {}): 32 | super().__init__(nodes_number, nodes_apps, qchannel_args, cchannel_args, memory_args) 33 | 34 | def build(self) -> Tuple[List[QNode], List[QuantumChannel]]: 35 | nl: List[QNode] = [] 36 | ll = [] 37 | for i in range(self.nodes_number): 38 | n = QNode(f"n{i+1}") 39 | nl.append(n) 40 | 41 | self._add_apps(nl) 42 | self._add_memories(nl) 43 | return nl, ll 44 | -------------------------------------------------------------------------------- /qns/network/topology/linetopo.py: -------------------------------------------------------------------------------- 1 | # SimQN: a discrete-event simulator for the quantum networks 2 | # Copyright (C) 2021-2022 Lutong Chen, Jian Li, Kaiping Xue 3 | # University of Science and Technology of China, USTC. 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | from qns.entity.node.app import Application 19 | from qns.entity.qchannel.qchannel import QuantumChannel 20 | from qns.entity.node.node import QNode 21 | from typing import Dict, List, Optional, Tuple 22 | from qns.network.topology import Topology 23 | 24 | 25 | class LineTopology(Topology): 26 | """ 27 | LineTopology includes `nodes_number` Qnodes. The topology is a line pattern. 28 | """ 29 | def __init__(self, nodes_number, nodes_apps: List[Application] = [], 30 | qchannel_args: Dict = {}, cchannel_args: Dict = {}, 31 | memory_args: Optional[List[Dict]] = {}): 32 | super().__init__(nodes_number, nodes_apps=nodes_apps, 33 | qchannel_args=qchannel_args, cchannel_args=cchannel_args, 34 | memory_args=memory_args) 35 | 36 | def build(self) -> Tuple[List[QNode], List[QuantumChannel]]: 37 | nl: List[QNode] = [] 38 | ll = [] 39 | if self.nodes_number >= 1: 40 | n = QNode(f"n{1}") 41 | nl.append(n) 42 | pn = n 43 | for i in range(self.nodes_number - 1): 44 | n = QNode(f"n{i+2}") 45 | nl.append(n) 46 | link = QuantumChannel(name=f"l{i+1}", **self.qchannel_args) 47 | ll.append(link) 48 | 49 | pn.add_qchannel(link) 50 | n.add_qchannel(link) 51 | pn = n 52 | 53 | self._add_apps(nl) 54 | self._add_memories(nl) 55 | return nl, ll 56 | -------------------------------------------------------------------------------- /qns/network/topology/treetopo.py: -------------------------------------------------------------------------------- 1 | # SimQN: a discrete-event simulator for the quantum networks 2 | # Copyright (C) 2021-2022 Lutong Chen, Jian Li, Kaiping Xue 3 | # University of Science and Technology of China, USTC. 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | from qns.entity.node.app import Application 19 | from qns.entity.qchannel.qchannel import QuantumChannel 20 | from qns.entity.node.node import QNode 21 | from typing import Dict, List, Optional, Tuple 22 | from qns.network.topology import Topology 23 | 24 | 25 | class TreeTopology(Topology): 26 | """ 27 | TreeTopology includes `nodes_number` Qnodes. 28 | The topology is a tree pattern, where each parent has `children_num` children. 29 | """ 30 | def __init__(self, nodes_number, children_number: int = 2, nodes_apps: List[Application] = [], 31 | qchannel_args: Dict = {}, cchannel_args: Dict = {}, 32 | memory_args: Optional[List[Dict]] = {}): 33 | """ 34 | Args: 35 | nodes_number (int): the total number of QNodes 36 | children_number (int): the number of children one parent has 37 | """ 38 | super().__init__(nodes_number, nodes_apps, qchannel_args, cchannel_args, memory_args) 39 | self.children_number = children_number 40 | 41 | def build(self) -> Tuple[List[QNode], List[QuantumChannel]]: 42 | nl: List[QNode] = [] 43 | ll = [] 44 | 45 | for i in range(self.nodes_number): 46 | n = QNode(f"n{i+1}") 47 | nl.append(n) 48 | 49 | for i in range(self.nodes_number): 50 | for j in range(i * self.children_number + 1, (i + 1) * self.children_number + 1): 51 | if j < self.nodes_number: 52 | link = QuantumChannel(name=f"l{i},{j}", **self.qchannel_args) 53 | ll.append(link) 54 | nl[i].add_qchannel(link) 55 | nl[j].add_qchannel(link) 56 | 57 | self._add_apps(nl) 58 | self._add_memories(nl) 59 | return nl, ll 60 | -------------------------------------------------------------------------------- /qns/simulator/__init__.py: -------------------------------------------------------------------------------- 1 | # SimQN: a discrete-event simulator for the quantum networks 2 | # Copyright (C) 2021-2022 Lutong Chen, Jian Li, Kaiping Xue 3 | # University of Science and Technology of China, USTC. 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | from qns.simulator.ts import Time, set_default_accuracy 19 | from qns.simulator.event import Event, func_to_event 20 | from qns.simulator.simulator import Simulator 21 | 22 | __all__ = ["Time", "set_default_accuracy", "Event", "func_to_event", "Simulator"] 23 | -------------------------------------------------------------------------------- /qns/simulator/pool.py: -------------------------------------------------------------------------------- 1 | # SimQN: a discrete-event simulator for the quantum networks 2 | # Copyright (C) 2021-2022 Lutong Chen, Jian Li, Kaiping Xue 3 | # University of Science and Technology of China, USTC. 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | import heapq 19 | from qns.simulator.ts import Time 20 | from qns.simulator.event import Event 21 | 22 | 23 | class DefaultEventPool(object): 24 | """ 25 | The default implement of the event pool 26 | """ 27 | 28 | def __init__(self, ts: Time, te: Time): 29 | ''' 30 | Args: 31 | ts: the start time 32 | te: the end time 33 | ''' 34 | self.ts = ts 35 | self.te = te 36 | self.tc = ts 37 | self.event_list = [] 38 | 39 | @property 40 | def current_time(self) -> Time: 41 | ''' 42 | Get the current time 43 | ''' 44 | return self.tc 45 | 46 | def add_event(self, event: Event) -> bool: 47 | ''' 48 | Insert an event into the pool 49 | 50 | Args: 51 | event (Event): The inserting event 52 | Returns: 53 | if the event is inserted successfully 54 | ''' 55 | if event.t < self.tc or event.t > self.te: 56 | return False 57 | 58 | heapq.heappush(self.event_list, event) 59 | return True 60 | 61 | def next_event(self) -> Event: 62 | ''' 63 | Get the next event to be executed 64 | 65 | Returns: 66 | The next event to be executed 67 | ''' 68 | try: 69 | event: Event = heapq.heappop(self.event_list) 70 | self.tc = event.t 71 | except IndexError: 72 | event = None 73 | self.tc = self.te 74 | return event 75 | -------------------------------------------------------------------------------- /qns/utils/__init__.py: -------------------------------------------------------------------------------- 1 | # SimQN: a discrete-event simulator for the quantum networks 2 | # Copyright (C) 2021-2022 Lutong Chen, Jian Li, Kaiping Xue 3 | # University of Science and Technology of China, USTC. 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | from qns.utils.log import logger, debug, info, error, install, warn, critical, monitor 19 | from qns.utils.rnd import set_seed, get_rand, get_randint, get_choice 20 | 21 | __all__ = ["logger", "debug", "info", "error", "install", 22 | "warn", "critical", "monitor", "set_seed", "get_rand", "get_randint", "get_choice"] 23 | -------------------------------------------------------------------------------- /qns/utils/log.py: -------------------------------------------------------------------------------- 1 | # SimQN: a discrete-event simulator for the quantum networks 2 | # Copyright (C) 2021-2022 Lutong Chen, Jian Li, Kaiping Xue 3 | # University of Science and Technology of China, USTC. 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | import logging 19 | import sys 20 | 21 | logger = logging.getLogger("qns") 22 | """ 23 | The default ``logger`` used by SimQN 24 | """ 25 | 26 | logger.setLevel(logging.INFO) 27 | handle = logging.StreamHandler(sys.stdout) 28 | logger.addHandler(handle) 29 | 30 | 31 | def install(s): 32 | """ 33 | Install the logger to the simulator 34 | 35 | Args: 36 | s (Simulator): the simulator 37 | """ 38 | logger._simulator = s 39 | 40 | 41 | def debug(msg, *args): 42 | if hasattr(logger, "_simulator"): 43 | logger.debug(f"[{logger._simulator.tc}] " + msg, *args) 44 | else: 45 | logger.debug(msg, *args) 46 | 47 | 48 | def info(msg, *args): 49 | if hasattr(logger, "_simulator"): 50 | logger.info(f"[{logger._simulator.tc}] " + msg, *args) 51 | else: 52 | logger.info(msg, *args) 53 | 54 | 55 | def error(msg, *args): 56 | if hasattr(logger, "_simulator"): 57 | logger.error(f"[{logger._simulator.tc}] " + msg, *args) 58 | else: 59 | logger.error(msg, *args) 60 | 61 | 62 | def warn(msg, *args): 63 | if hasattr(logger, "_simulator"): 64 | logger.warn(f"[{logger._simulator.tc}] " + msg, *args) 65 | else: 66 | logger.warn(msg, *args) 67 | 68 | 69 | def critical(msg, *args): 70 | if hasattr(logger, "_simulator"): 71 | logger.critical(f"[{logger._simulator.tc}] " + msg, *args) 72 | else: 73 | logger.critical(msg, *args) 74 | 75 | 76 | def monitor(*args, sep: str = ",", with_time: bool = False): 77 | attrs = list(args) 78 | if with_time: 79 | attrs.insert(0, logger._simulator.tc) 80 | attrs_s = [str(a) for a in attrs] 81 | msg = sep.join(attrs_s) 82 | logger.info(msg) 83 | -------------------------------------------------------------------------------- /qns/utils/rnd.py: -------------------------------------------------------------------------------- 1 | # SimQN: a discrete-event simulator for the quantum networks 2 | # Copyright (C) 2021-2022 Lutong Chen, Jian Li, Kaiping Xue 3 | # University of Science and Technology of China, USTC. 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | import random 19 | from typing import Optional 20 | import numpy as np 21 | 22 | 23 | def set_seed(seed: Optional[int] = None): 24 | """ 25 | Set a seed for random generator 26 | 27 | Args: 28 | seed (int): the seed 29 | """ 30 | if seed is None: 31 | return 32 | random.seed(seed) 33 | np.random.seed(seed) 34 | 35 | 36 | def get_rand(low: float = 0, high: float = 1) -> float: 37 | """ 38 | Get a random number from [low, high) 39 | 40 | Args: 41 | low (int): the low bound 42 | high (int): the high bound 43 | """ 44 | return low + np.random.random() * (high - low) 45 | 46 | 47 | def get_randint(low: int, high: int) -> float: 48 | """ 49 | Get a random integer from [low, high] 50 | 51 | Args: 52 | low (int): the low bound 53 | high (int): the high bound 54 | """ 55 | if low != int(low): 56 | raise ValueError("input low") 57 | if low > high: 58 | raise ValueError("low should smaller than high") 59 | return np.random.randint(low, high+1) 60 | 61 | 62 | def get_choice(a): 63 | """ 64 | return an random element from a list 65 | 66 | Args: 67 | a: a iterable object 68 | """ 69 | return a[get_randint(0, len(a)-1)] 70 | 71 | 72 | def get_weighted_choice(a, weights, k=1): 73 | """ 74 | return k random element from a list with weights 75 | 76 | Args: 77 | a: a iterable object 78 | weights: a list of weights 79 | k: the number of random sample elements 80 | """ 81 | return random.choices(a, weights=weights, k=k) 82 | 83 | 84 | def get_normal(mean: float = 0, std: float = 1): 85 | return np.random.normal(loc=mean, scale=std) 86 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | Cython==0.29.28 2 | numpy==1.22.3 3 | pandas==1.4.2 4 | pytest==7.1.1 5 | twine==4.0.0 6 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | # SimQN: a discrete-event simulator for the quantum networks 2 | # Copyright (C) 2021-2022 Lutong Chen, Jian Li, Kaiping Xue 3 | # University of Science and Technology of China, USTC. 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | from setuptools import setup, find_packages 19 | 20 | with open("README.md", "r", encoding="utf-8") as fh: 21 | long_description = fh.read() 22 | 23 | setup( 24 | name='qns', 25 | author='elliot', 26 | version="0.2.1", 27 | description='A discrete-event scheduler designed for quantum networks', 28 | long_description=long_description, 29 | long_description_content_type="text/markdown", 30 | packages=find_packages(), 31 | include_package_data=True, 32 | url="https://github.com/ertuil/SimQN", 33 | exclude_package_data={'docs': ['.gitkeep']}, 34 | setup_requires=["numpy", "pandas", "twine", "wheel"], 35 | install_requires=["numpy", "pandas"], 36 | classifiers=[ 37 | "Programming Language :: Python :: 3", 38 | "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", 39 | "Operating System :: OS Independent", 40 | ], 41 | ) 42 | -------------------------------------------------------------------------------- /test/entity/test_operator.py: -------------------------------------------------------------------------------- 1 | from typing import Optional 2 | from qns.entity.node.app import Application 3 | from qns.entity.node.node import QNode 4 | from qns.entity.operator.event import OperateResponseEvent 5 | from qns.simulator.event import Event 6 | from qns.simulator.simulator import Simulator 7 | from qns.entity.operator import QuantumOperator, OperateRequestEvent 8 | from qns.models.qubit import Qubit, H 9 | 10 | 11 | def gate_z_and_measure(qubit: Qubit): 12 | H(qubit=qubit) 13 | result = qubit.measure() 14 | return result 15 | 16 | 17 | def test_operator_sync(): 18 | n1 = QNode("n1") 19 | o1 = QuantumOperator(name="o1", node=n1, gate=gate_z_and_measure) 20 | 21 | n1.add_operator(o1) 22 | 23 | s = Simulator(0, 10, 1000) 24 | n1.install(s) 25 | 26 | qubit = Qubit() 27 | ret = o1.operate(qubit) 28 | assert (ret in [0, 1]) 29 | 30 | s.run() 31 | 32 | 33 | class RecvOperateApp(Application): 34 | def __init__(self): 35 | super().__init__() 36 | self.add_handler(self.OperateResponseEventhandler, [OperateResponseEvent], []) 37 | 38 | def OperateResponseEventhandler(self, node, event: Event) -> Optional[bool]: 39 | result = event.result 40 | assert (self._simulator.tc.sec == 0.5) 41 | assert (result in [0, 1]) 42 | 43 | 44 | def test_operator_async(): 45 | n1 = QNode("n1") 46 | o1 = QuantumOperator(name="o1", node=n1, gate=gate_z_and_measure, delay=0.5) 47 | 48 | n1.add_operator(o1) 49 | a1 = RecvOperateApp() 50 | n1.add_apps(a1) 51 | 52 | s = Simulator(0, 10, 1000) 53 | n1.install(s) 54 | 55 | qubit = Qubit() 56 | request = OperateRequestEvent(o1, qubits=[qubit], t=s.time(sec=0), by=n1) 57 | s.add_event(request) 58 | 59 | s.run() 60 | -------------------------------------------------------------------------------- /test/entity/test_timer.py: -------------------------------------------------------------------------------- 1 | from qns.simulator.simulator import Simulator 2 | from qns.entity.timer.timer import Timer 3 | 4 | 5 | def test_timer(): 6 | s = Simulator(0, 10, 1000) 7 | 8 | def trigger_func(): 9 | print(s.current_time) 10 | 11 | t1 = Timer("t1", 0, 10, 0.5, trigger_func) 12 | t1.install(s) 13 | s.run() 14 | -------------------------------------------------------------------------------- /test/models/epr/test_bell_state.py: -------------------------------------------------------------------------------- 1 | from qns.models.epr import BellStateEntanglement 2 | from qns.models.qubit.qubit import Qubit 3 | from qns.models.qubit.const import QUBIT_STATE_1 4 | 5 | 6 | def test_bell_state_epr(): 7 | c0, c1 = 0, 0 8 | for _ in range(1000): 9 | q0 = Qubit(QUBIT_STATE_1) 10 | e1 = BellStateEntanglement(fidelity=1, name="e0") 11 | q2 = e1.teleportion(q0) 12 | if q2.measure() == 0: 13 | c0 += 1 14 | else: 15 | c1 += 1 16 | assert (c0 == 0 and c1 == 1000) 17 | 18 | 19 | if __name__ == "__main__": 20 | test_bell_state_epr() 21 | -------------------------------------------------------------------------------- /test/models/epr/test_mixed_state.py: -------------------------------------------------------------------------------- 1 | from qns.models.epr import MixedStateEntanglement 2 | from qns.models.qubit.const import QUBIT_STATE_0 3 | from qns.models.qubit.qubit import Qubit 4 | 5 | 6 | def test_mixed_state(): 7 | 8 | e1 = MixedStateEntanglement(fidelity=0.95, name="e1") 9 | e2 = MixedStateEntanglement(fidelity=0.95, name="e2") 10 | e3 = e1.swapping(e2) 11 | print(e3.fidelity) 12 | 13 | e4 = MixedStateEntanglement(fidelity=0.95, name="e4") 14 | e5 = MixedStateEntanglement(fidelity=0.95, name="e5") 15 | e6 = e4.swapping(e5) 16 | print(e6.fidelity) 17 | 18 | e7 = e3.distillation(e6) 19 | if e7 is None: 20 | print("distillation failed") 21 | return 22 | print(e7.fidelity) 23 | 24 | e8 = MixedStateEntanglement(fidelity=0.95, name="e8") 25 | e9 = e7.distillation(e8) 26 | if e9 is None: 27 | print("distillation failed") 28 | return 29 | print(e9.fidelity, e9.b, e9.c, e9.d) 30 | 31 | q_in = Qubit(QUBIT_STATE_0) 32 | q_out = e9.teleportion(q_in) 33 | print(q_out.state.rho) 34 | 35 | 36 | if __name__ == "__main__": 37 | test_mixed_state() 38 | -------------------------------------------------------------------------------- /test/models/epr/test_werner_state.py: -------------------------------------------------------------------------------- 1 | from qns.models.epr import WernerStateEntanglement 2 | 3 | 4 | def test_werner_state(): 5 | 6 | e1 = WernerStateEntanglement(fidelity=0.95, name="e1") 7 | e2 = WernerStateEntanglement(fidelity=0.95, name="e2") 8 | e3 = e1.swapping(e2) 9 | print(e3.fidelity) 10 | 11 | e4 = WernerStateEntanglement(fidelity=0.95, name="e4") 12 | e5 = WernerStateEntanglement(fidelity=0.95, name="e5") 13 | e6 = e4.swapping(e5) 14 | print(e6.fidelity) 15 | 16 | e7 = e3.distillation(e6) 17 | if e7 is None: 18 | print("distillation failed") 19 | return 20 | print(e7.fidelity) 21 | -------------------------------------------------------------------------------- /test/models/qubit/test_qubit_dissipation.py: -------------------------------------------------------------------------------- 1 | from qns.models.qubit.const import QUBIT_STATE_1, QUBIT_STATE_0 2 | from qns.models.qubit.decoherence import DissipationStorageErrorModel 3 | from qns.models.qubit.gate import CNOT, H 4 | from qns.models.qubit.factory import QubitFactory 5 | 6 | 7 | def test_qubit_dissipation_1(): 8 | Qubit = QubitFactory(operate_decoherence_rate=0.2, measure_decoherence_rate=0.2) 9 | 10 | q0 = Qubit(state=QUBIT_STATE_1, name="q0") 11 | 12 | DissipationStorageErrorModel(q0, 1, 0.2) 13 | 14 | print(q0.state) 15 | 16 | 17 | def test_qubit_dissipation_epr(): 18 | Qubit = QubitFactory(operate_decoherence_rate=0.5, measure_decoherence_rate=0.5) 19 | 20 | q0 = Qubit(state=QUBIT_STATE_0, name="q0") 21 | q1 = Qubit(state=QUBIT_STATE_0, name="q0") 22 | 23 | H(q0) 24 | CNOT(q0, q1) 25 | 26 | DissipationStorageErrorModel(q0, 1, 1) 27 | 28 | print(q0.state) 29 | print(q1.state) 30 | -------------------------------------------------------------------------------- /test/models/qubit/test_stochastic_operate.py: -------------------------------------------------------------------------------- 1 | from qns.models.qubit.qubit import Qubit 2 | from qns.models.qubit.const import QUBIT_STATE_0, OPERATOR_PAULI_X, OPERATOR_PAULI_I 3 | from qns.models.qubit import H, CNOT, I, X, Y, Z 4 | 5 | 6 | def test_stochastic_operate(): 7 | q0 = Qubit(state=QUBIT_STATE_0, name="q0") 8 | q1 = Qubit(state=QUBIT_STATE_0, name="q1") 9 | H(q0) 10 | CNOT(q0, q1) 11 | 12 | q0.stochastic_operate([OPERATOR_PAULI_I, OPERATOR_PAULI_X], [0.5, 0.5]) 13 | 14 | 15 | def test_stochastic_operate2(): 16 | 17 | q0 = Qubit(state=QUBIT_STATE_0, name="q0") 18 | q0.operate(Y) 19 | print(q0.state) 20 | 21 | q0 = Qubit(state=QUBIT_STATE_0, name="q0") 22 | q0.stochastic_operate([I, X, Y, Z], [0.7, 0.1, 0.1, 0.1]) 23 | -------------------------------------------------------------------------------- /test/models/qubit/test_swapping.py: -------------------------------------------------------------------------------- 1 | from qns.models.qubit.qubit import Qubit 2 | from qns.models.qubit.gate import H, CNOT, X, Z 3 | from qns.models.qubit.const import QUBIT_STATE_0 4 | 5 | 6 | def test_swapping(): 7 | q0 = Qubit(state=QUBIT_STATE_0, name="q0") 8 | q1 = Qubit(state=QUBIT_STATE_0, name="q1") 9 | q2 = Qubit(state=QUBIT_STATE_0, name="q2") 10 | q3 = Qubit(state=QUBIT_STATE_0, name="q3") 11 | 12 | H(q0) 13 | CNOT(q0, q1) 14 | H(q2) 15 | CNOT(q2, q3) 16 | CNOT(q1, q2) 17 | H(q1) 18 | 19 | c0 = q2.measure() 20 | c1 = q1.measure() 21 | 22 | if c0 == 1 and c1 == 0: 23 | X(q3) 24 | elif c0 == 0 and c1 == 1: 25 | Z(q3) 26 | elif c0 == 1 and c1 == 1: 27 | X(q3) 28 | Z(q3) 29 | assert (q0.measure() == q3.measure()) 30 | -------------------------------------------------------------------------------- /test/network/test_barabasialberttopo.py: -------------------------------------------------------------------------------- 1 | from qns.network.network import QuantumNetwork 2 | from qns.network.topology.barabasialberttopo import BarabasiAlbertTopology 3 | 4 | 5 | def test_barabasialbert_topo(): 6 | topo = BarabasiAlbertTopology(nodes_number=100, new_nodes_egdes=1) 7 | net = QuantumNetwork(topo) 8 | 9 | print(net.nodes, net.qchannels) 10 | -------------------------------------------------------------------------------- /test/network/test_basictopo.py: -------------------------------------------------------------------------------- 1 | from qns.network.network import QuantumNetwork 2 | from qns.network.topology.basictopo import BasicTopology 3 | 4 | 5 | def test_basic_topo(): 6 | topo = BasicTopology(nodes_number=3) 7 | net = QuantumNetwork(topo) 8 | 9 | print(net.nodes) 10 | -------------------------------------------------------------------------------- /test/network/test_dualbarabasialberttopo.py: -------------------------------------------------------------------------------- 1 | from qns.network.network import QuantumNetwork 2 | from qns.network.topology.dualbarabasialberttopo import DualBarabasiAlbertTopology 3 | 4 | 5 | def test_dualbarabasialbert_topo(): 6 | topo = DualBarabasiAlbertTopology(nodes_number=100, edges_num1=1, edges_num2=3, prob=0.85) 7 | net = QuantumNetwork(topo) 8 | 9 | print(net.nodes, net.qchannels) 10 | -------------------------------------------------------------------------------- /test/network/test_erdosrenyitopo.py: -------------------------------------------------------------------------------- 1 | from qns.network.network import QuantumNetwork 2 | from qns.network.topology.erdosrenyitopo import ErdosRenyiTopology 3 | 4 | 5 | def test_erdosrenyi_topo(): 6 | topo = ErdosRenyiTopology(nodes_number=20, generate_prob=0.2) 7 | net = QuantumNetwork(topo) 8 | 9 | print(net.nodes, net.qchannels) 10 | -------------------------------------------------------------------------------- /test/network/test_gridtopo.py: -------------------------------------------------------------------------------- 1 | from qns.network.network import QuantumNetwork 2 | from qns.network.topology.gridtopo import GridTopology 3 | 4 | 5 | def test_grid_topo(): 6 | topo = GridTopology(nodes_number=9) 7 | net = QuantumNetwork(topo) 8 | 9 | print(net.nodes, net.qchannels) 10 | -------------------------------------------------------------------------------- /test/network/test_linetopo.py: -------------------------------------------------------------------------------- 1 | from qns.network.network import QuantumNetwork 2 | from qns.network.topology.linetopo import LineTopology 3 | 4 | 5 | def test_line_topo(): 6 | topo = LineTopology(nodes_number=5) 7 | net = QuantumNetwork(topo) 8 | 9 | print(net.nodes, net.qchannels) 10 | -------------------------------------------------------------------------------- /test/network/test_randomtopo.py: -------------------------------------------------------------------------------- 1 | from qns.network.network import QuantumNetwork 2 | from qns.network.topology.randomtopo import RandomTopology 3 | 4 | 5 | def test_random_topo(): 6 | topo = RandomTopology(nodes_number=5, lines_number=10) 7 | net = QuantumNetwork(topo) 8 | 9 | print(net.nodes, net.qchannels) 10 | -------------------------------------------------------------------------------- /test/network/test_route.py: -------------------------------------------------------------------------------- 1 | from qns.network.network import QuantumNetwork 2 | from qns.network.topology import RandomTopology 3 | from qns.network.topology.topo import ClassicTopology 4 | 5 | 6 | def test_route_algorithm(): 7 | topo = RandomTopology(nodes_number=20, lines_number=30) 8 | net = QuantumNetwork(topo=topo, classic_topo=ClassicTopology.All) 9 | 10 | net.build_route() 11 | print(net.nodes) 12 | for link in net.qchannels: 13 | print(link, link.node_list) 14 | 15 | 16 | def test_request(): 17 | topo = RandomTopology(nodes_number=20, lines_number=30) 18 | net = QuantumNetwork(topo=topo, classic_topo=ClassicTopology.Follow) 19 | n1 = net.get_node("n1") 20 | n4 = net.get_node("n4") 21 | print(net.route.route_table) 22 | print(net.query_route(n1, n4)) 23 | 24 | net.add_request(n1, n4) 25 | print(net.requests) 26 | 27 | net.random_requests(5, allow_overlay=False) 28 | print(net.requests) 29 | 30 | net.random_requests(5, allow_overlay=True) 31 | print(net.requests) 32 | -------------------------------------------------------------------------------- /test/network/test_treetopo.py: -------------------------------------------------------------------------------- 1 | from qns.network.network import QuantumNetwork 2 | from qns.network.topology.treetopo import TreeTopology 3 | 4 | topo = TreeTopology(nodes_number=15, children_number=3) 5 | net = QuantumNetwork(topo) 6 | 7 | print(net.nodes, net.qchannels) 8 | -------------------------------------------------------------------------------- /test/network/test_waxman_topo.py: -------------------------------------------------------------------------------- 1 | from qns.network.network import QuantumNetwork 2 | from qns.network.topology.waxmantopo import WaxmanTopology 3 | 4 | topo = WaxmanTopology(nodes_number=10, size=1000, alpha=0.5, beta=0.5) 5 | net = QuantumNetwork(topo) 6 | 7 | print(net.nodes, net.qchannels) 8 | -------------------------------------------------------------------------------- /test/protocol/test_bb84.py: -------------------------------------------------------------------------------- 1 | from qns.entity.cchannel.cchannel import ClassicChannel 2 | from qns.entity.qchannel.qchannel import QuantumChannel 3 | from qns.entity import QNode 4 | from qns.simulator.simulator import Simulator 5 | from qns.network.protocol.bb84 import BB84RecvApp, BB84SendApp 6 | import numpy as np 7 | 8 | light_speed = 299791458 9 | length = 1000 10 | 11 | 12 | def drop_rate(length): 13 | # drop 0.2 db/KM 14 | return 1 - np.exp(- length / 50000) 15 | 16 | 17 | def test_bb84_protocol(): 18 | s = Simulator(0, 10, accuracy=10000000000) 19 | n1 = QNode(name="n1") 20 | n2 = QNode(name="n2") 21 | 22 | qlink = QuantumChannel(name="l1", delay=length / light_speed, 23 | drop_rate=0) 24 | 25 | clink = ClassicChannel(name="c1", delay=length / light_speed) 26 | 27 | n1.add_cchannel(clink) 28 | n2.add_cchannel(clink) 29 | n1.add_qchannel(qlink) 30 | n2.add_qchannel(qlink) 31 | 32 | sp = BB84SendApp(n2, qlink, clink, send_rate=1000) 33 | rp = BB84RecvApp(n1, qlink, clink) 34 | n1.add_apps(sp) 35 | n2.add_apps(rp) 36 | 37 | n1.install(s) 38 | n2.install(s) 39 | 40 | s.run() 41 | print(sp.key_pool) 42 | -------------------------------------------------------------------------------- /test/protocol/test_entanglement_distribution.py: -------------------------------------------------------------------------------- 1 | import logging 2 | from qns.network.route.dijkstra import DijkstraRouteAlgorithm 3 | from qns.network.topology.topo import ClassicTopology 4 | from qns.simulator.simulator import Simulator 5 | from qns.network import QuantumNetwork 6 | from qns.network.topology import LineTopology 7 | import qns.utils.log as log 8 | from qns.network.protocol.entanglement_distribution import EntanglementDistributionApp 9 | 10 | 11 | # constrains 12 | init_fidelity = 0.99 13 | nodes_number = 20 14 | lines_number = 19 15 | delay = 0.05 16 | memory_capacity = 50 17 | send_rate = 10 18 | nodes_number = 10 19 | 20 | 21 | def test_epr_distribution(): 22 | s = Simulator(0, 10, accuracy=10000000) 23 | log.install(s) 24 | log.logger.setLevel(logging.DEBUG) 25 | topo = LineTopology(nodes_number=nodes_number, 26 | qchannel_args={"delay": delay}, 27 | cchannel_args={"delay": delay}, 28 | memory_args={ 29 | "capacity": memory_capacity, 30 | "store_error_model_args": {"a": 0.2}}, 31 | nodes_apps=[EntanglementDistributionApp(init_fidelity=init_fidelity)]) 32 | 33 | net = QuantumNetwork( 34 | topo=topo, classic_topo=ClassicTopology.All, route=DijkstraRouteAlgorithm()) 35 | net.build_route() 36 | 37 | src = net.get_node("n1") 38 | dst = net.get_node(f"n{nodes_number}") 39 | net.add_request(src=src, dest=dst, attr={"send_rate": send_rate}) 40 | net.install(s) 41 | s.run() 42 | -------------------------------------------------------------------------------- /test/protocol/test_process_delay.py: -------------------------------------------------------------------------------- 1 | from typing import Any, Optional 2 | from qns.entity.node.app import Application 3 | from qns.entity.node.node import QNode 4 | from qns.network.protocol.node_process_delay import NodeProcessDelayApp 5 | from qns.simulator.event import Event 6 | from qns.simulator.simulator import Simulator 7 | from qns.simulator.ts import Time 8 | 9 | 10 | class ProcessEvent(Event): 11 | def __init__(self, t: Optional[Time] = None, dest: QNode = None, name: Optional[str] = None, 12 | by: Optional[Any] = None): 13 | super().__init__(t, name=name, by=by) 14 | self.dest = dest 15 | 16 | def invoke(self) -> None: 17 | self.dest.handle(self) 18 | 19 | 20 | class ProcessApp(Application): 21 | def __init__(self): 22 | super().__init__() 23 | self.add_handler(self.EventHandler) 24 | 25 | def install(self, node, simulator: Simulator): 26 | super().install(node, simulator) 27 | 28 | for i in range(0, 10): 29 | t = simulator.time(sec=i) 30 | event = ProcessEvent(t=t, dest=self.get_node(), by=self) 31 | self.get_simulator().add_event(event) 32 | 33 | def EventHandler(self, node, event: Event) -> Optional[bool]: 34 | expected_recv_time = [i+0.5 for i in range(0, 10)] 35 | print(f"recv event at {event.t}") 36 | assert (event.t.sec in expected_recv_time) 37 | 38 | 39 | def test_process_delay(): 40 | n1 = QNode("n1") 41 | n1.add_apps(NodeProcessDelayApp(delay=0.5, delay_event_list=(ProcessEvent,))) 42 | n1.add_apps(ProcessApp()) 43 | 44 | s = Simulator(0, 10) 45 | n1.install(s) 46 | 47 | s.run() 48 | -------------------------------------------------------------------------------- /test/simulator/test_event.py: -------------------------------------------------------------------------------- 1 | from qns.simulator.event import Event, func_to_event 2 | from qns.simulator.ts import Time 3 | 4 | 5 | class PrintEvent(Event): 6 | def invoke(self) -> None: 7 | print("event happened") 8 | 9 | 10 | def test_event_normal(): 11 | te = PrintEvent(t=Time(sec=1), name="test event") 12 | print(te) 13 | 14 | te.invoke() 15 | assert (not te.is_canceled) 16 | te.cancel() 17 | assert te.is_canceled 18 | 19 | 20 | def Print(): 21 | print("event happened") 22 | 23 | 24 | def test_event_simple(): 25 | te = func_to_event(t=Time(sec=1), name="test event", fn=Print) 26 | print(te) 27 | 28 | te.invoke() 29 | -------------------------------------------------------------------------------- /test/simulator/test_multiple_process.py: -------------------------------------------------------------------------------- 1 | from qns.utils.multiprocess import MPSimulations 2 | from qns.network.route.dijkstra import DijkstraRouteAlgorithm 3 | from qns.network.topology.topo import ClassicTopology 4 | from qns.simulator.simulator import Simulator 5 | from qns.network import QuantumNetwork 6 | from qns.network.topology import LineTopology 7 | from qns.network.protocol.entanglement_distribution import EntanglementDistributionApp 8 | 9 | 10 | # def test_multiple_process_1(): 11 | # s = MPSimulations(settings={"node_num": [10, 20, 30, 40], "req_num": [10, 20, 30]}, iter_count=2) 12 | # try: 13 | # s.start() 14 | # except NotImplementedError: 15 | # pass 16 | 17 | 18 | class EPRDistributionSimulation(MPSimulations): 19 | def run(self, setting): 20 | nodes_number = setting["nodes_number"] 21 | delay = setting["delay"] 22 | memory_capacity = setting["memory_capacity"] 23 | send_rate = setting["send_rate"] 24 | s = Simulator(0, 10, accuracy=10000000) 25 | topo = LineTopology(nodes_number=nodes_number, 26 | qchannel_args={"delay": delay, "drop_rate": 0.3}, 27 | cchannel_args={"delay": delay}, 28 | memory_args={ 29 | "capacity": memory_capacity, 30 | "store_error_model_args": {"a": 0.2}}, 31 | nodes_apps=[EntanglementDistributionApp(init_fidelity=0.99)]) 32 | 33 | net = QuantumNetwork( 34 | topo=topo, classic_topo=ClassicTopology.All, route=DijkstraRouteAlgorithm()) 35 | net.build_route() 36 | 37 | src = net.get_node("n1") 38 | dst = net.get_node(f"n{nodes_number}") 39 | net.add_request(src=src, dest=dst, attr={"send_rate": send_rate}) 40 | net.install(s) 41 | s.run() 42 | return {"count": src.apps[0].success_count} 43 | 44 | 45 | def test_multiple_process_2(): 46 | ss = EPRDistributionSimulation(settings={ 47 | "nodes_number": [5, 10], 48 | "delay": [0.05], 49 | "memory_capacity": [10, 20], 50 | "send_rate": [10, 20] 51 | }, aggregate=True, iter_count=10) 52 | ss.start() 53 | print(ss.get_data()) 54 | 55 | 56 | if __name__ == "__main__": 57 | test_multiple_process_2() 58 | -------------------------------------------------------------------------------- /test/simulator/test_simulator.py: -------------------------------------------------------------------------------- 1 | import logging 2 | from qns.simulator.simulator import Simulator 3 | from qns.simulator.event import Event 4 | import qns.utils.log as log 5 | 6 | log.logger.setLevel(logging.DEBUG) 7 | 8 | 9 | class TimerEvent(Event): 10 | def invoke(self) -> None: 11 | log.info(f"{self.name}: it is {self.t} seconds") 12 | 13 | def __repr__(self) -> str: 14 | return f"<{self.name}-{self.t}>" 15 | 16 | 17 | def test_simulator_with_log(): 18 | s = Simulator(0, 15, 1000) 19 | t = 0 20 | while t <= 12: 21 | e = TimerEvent(t=s.time(sec=t), name="t1") 22 | s.add_event(e) 23 | t += 0.5 24 | 25 | t = 5 26 | while t <= 20: 27 | e = TimerEvent(t=s.time(sec=t), name="t2") 28 | s.add_event(e) 29 | t += 1 30 | log.install(s) 31 | s.run() 32 | -------------------------------------------------------------------------------- /test/simulator/test_time.py: -------------------------------------------------------------------------------- 1 | from qns.simulator.ts import Time 2 | 3 | 4 | def test_time(): 5 | t1 = Time(1) 6 | t2 = Time(sec=1.1) 7 | t3 = Time() 8 | t4 = Time(1100000) 9 | 10 | print(t1.sec) 11 | print(t4) 12 | 13 | assert (t1 == t1) 14 | assert (t2 >= t1) 15 | assert (t1 <= t2) 16 | assert (t1 < t2) 17 | assert (t3 < t1) 18 | 19 | 20 | def print_msg(msg): 21 | print(msg) 22 | 23 | 24 | def test_simulator_time(): 25 | ''' 26 | If we modify the default_accuracy of the simulator, 27 | check whether the accuracy of subsequent events will be automatically synchronized with the simulator 28 | without special modification. 29 | ''' 30 | from qns.simulator.simulator import Simulator 31 | from qns.simulator.event import func_to_event 32 | s = Simulator(1, 10, 1000) 33 | s.run() 34 | print_event = func_to_event(Time(sec=1), print_msg, "hello world") 35 | print(print_event.t.accuracy) 36 | assert (print_event.t.accuracy == 1000) 37 | -------------------------------------------------------------------------------- /test/test_example_readme.py: -------------------------------------------------------------------------------- 1 | from qns.simulator.simulator import Simulator 2 | from qns.network.topology import RandomTopology 3 | from qns.network.protocol.entanglement_distribution import EntanglementDistributionApp 4 | from qns.network import QuantumNetwork 5 | from qns.network.route.dijkstra import DijkstraRouteAlgorithm 6 | from qns.network.topology.topo import ClassicTopology 7 | import qns.utils.log as log 8 | import logging 9 | 10 | 11 | def test_example_readme(): 12 | init_fidelity = 0.99 # the initial entanglement's fidelity 13 | nodes_number = 150 # the number of nodes 14 | lines_number = 450 # the number of quantum channels 15 | qchannel_delay = 0.05 # the delay of quantum channels 16 | cchannel_delay = 0.05 # the delay of classic channels 17 | memory_capacity = 50 # the size of quantum memories 18 | send_rate = 10 # the send rate 19 | requests_number = 10 # the number of sessions (SD-pairs) 20 | 21 | # generate the simulator 22 | s = Simulator(0, 10, accuracy=1000000) 23 | 24 | # set the log's level 25 | log.logger.setLevel(logging.INFO) 26 | log.install(s) 27 | 28 | # generate a random topology using the parameters above 29 | # each node will install EntanglementDistributionApp for hop-by-hop entanglement distribution 30 | topo = RandomTopology(nodes_number=nodes_number, 31 | lines_number=lines_number, 32 | qchannel_args={"delay": qchannel_delay}, 33 | cchannel_args={"delay": cchannel_delay}, 34 | memory_args=[{"capacity": memory_capacity}], 35 | nodes_apps=[EntanglementDistributionApp(init_fidelity=init_fidelity)]) 36 | 37 | # build the network, with Dijkstra's routing algorithm 38 | net = QuantumNetwork(topo=topo, classic_topo=ClassicTopology.All, route=DijkstraRouteAlgorithm()) 39 | 40 | # build the routing table 41 | net.build_route() 42 | 43 | # randomly select multiple sessions (SD-pars) 44 | net.random_requests(requests_number, attr={"send_rate": send_rate}) 45 | 46 | # all entities in the network will install the simulator and do initiate works. 47 | net.install(s) 48 | 49 | # run simulation 50 | s.run() 51 | 52 | 53 | if __name__ == "__main__": 54 | test_example_readme() 55 | -------------------------------------------------------------------------------- /tox.ini: -------------------------------------------------------------------------------- 1 | [flake8] 2 | max-line-length = 128 3 | exclude = env/*,build 4 | ignore = E741,E743,E121,E123,E126,E226,E24,E704,W503,W504 --------------------------------------------------------------------------------