q-elink 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. q_elink-0.1.0/.gitignore +51 -0
  2. q_elink-0.1.0/LICENSE +202 -0
  3. q_elink-0.1.0/PKG-INFO +154 -0
  4. q_elink-0.1.0/README.md +138 -0
  5. q_elink-0.1.0/examples/dataset/create_dataset_fringe.py +65 -0
  6. q_elink-0.1.0/examples/dataset/create_dataset_local_proba.py +68 -0
  7. q_elink-0.1.0/examples/elementary_link/elemnetary_link.py +22 -0
  8. q_elink-0.1.0/examples/local_proba/fit_analyzer.py +47 -0
  9. q_elink-0.1.0/examples/local_proba/fit_proba.py +48 -0
  10. q_elink-0.1.0/examples/local_proba/proba_coincidence.py +38 -0
  11. q_elink-0.1.0/examples/local_proba/proba_local.py +50 -0
  12. q_elink-0.1.0/examples/visibility/interferences.py +37 -0
  13. q_elink-0.1.0/examples/visibility/visibility.py +26 -0
  14. q_elink-0.1.0/examples/witness/ent_witness.py +75 -0
  15. q_elink-0.1.0/pyproject.toml +25 -0
  16. q_elink-0.1.0/src/q_elink/__init__.py +4 -0
  17. q_elink-0.1.0/src/q_elink/_imports.py +24 -0
  18. q_elink-0.1.0/src/q_elink/core/__init__.py +1 -0
  19. q_elink-0.1.0/src/q_elink/core/_imports.py +1 -0
  20. q_elink-0.1.0/src/q_elink/core/link.py +94 -0
  21. q_elink-0.1.0/src/q_elink/local_probabilities/__init__.py +3 -0
  22. q_elink-0.1.0/src/q_elink/local_probabilities/_imports.py +2 -0
  23. q_elink-0.1.0/src/q_elink/local_probabilities/fitter.py +350 -0
  24. q_elink-0.1.0/src/q_elink/local_probabilities/handler.py +339 -0
  25. q_elink-0.1.0/src/q_elink/local_probabilities/model.py +433 -0
  26. q_elink-0.1.0/src/q_elink/visibility/__init__.py +1 -0
  27. q_elink-0.1.0/src/q_elink/visibility/_imports.py +3 -0
  28. q_elink-0.1.0/src/q_elink/visibility/fitter.py +5 -0
  29. q_elink-0.1.0/src/q_elink/visibility/handler.py +5 -0
  30. q_elink-0.1.0/src/q_elink/visibility/model.py +146 -0
  31. q_elink-0.1.0/src/q_elink/witness/__init__.py +1 -0
  32. q_elink-0.1.0/src/q_elink/witness/_imports.py +3 -0
  33. q_elink-0.1.0/src/q_elink/witness/model.py +310 -0
  34. q_elink-0.1.0/src/q_elink/witness/plotting.py +0 -0
  35. q_elink-0.1.0/uv.lock +509 -0
@@ -0,0 +1,51 @@
1
+ # uv local overrides
2
+ uv.toml
3
+
4
+ # Byte-compiled
5
+ __pycache__/
6
+ *.py[cod]
7
+ *$py.class
8
+
9
+ # Packageing
10
+ build/
11
+ dist/
12
+ *.egg-info/
13
+ .eggs/
14
+
15
+ # Environments
16
+ .venv/
17
+ venv/
18
+ env/
19
+ .env
20
+
21
+ # Testing
22
+ .pytest_cache/
23
+ .coverage
24
+ htmlcov/
25
+ .tox/
26
+ .nox/
27
+
28
+ # Type checkers
29
+ .mypy_cache/
30
+ .ruff_cache/
31
+ .pyright/
32
+
33
+ # Jupyter
34
+ .ipynb_checkpoints/
35
+
36
+ # IDE
37
+ .vscode/
38
+ .idea/
39
+
40
+ # OS
41
+ .DS_Store
42
+
43
+ # AI assistants
44
+ .gemini/
45
+ .claude/
46
+ CLAUDE.md
47
+
48
+ # Others...
49
+ local/
50
+ tmp/
51
+ repomix-*.xml
q_elink-0.1.0/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2016 Bastien Grivet
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
q_elink-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,154 @@
1
+ Metadata-Version: 2.4
2
+ Name: q-elink
3
+ Version: 0.1.0
4
+ Summary: Numerical characterization of an elementary link of a quantum repeater: local probabilities, visibility, entanglement witness, etc.
5
+ Author-email: Bastien Grivet <73183679+BastienGrvt@users.noreply.github.com>
6
+ License-Expression: Apache-2.0
7
+ License-File: LICENSE
8
+ Requires-Python: <4,>=3.13
9
+ Requires-Dist: bastools>=0.1.1
10
+ Requires-Dist: matplotlib<4,>=3.10.3
11
+ Requires-Dist: numpy<3,>=2.3.1
12
+ Requires-Dist: rich<15,>=14.1.0
13
+ Requires-Dist: scipy<2,>=1.16.1
14
+ Requires-Dist: tqdm<5,>=4.67.1
15
+ Description-Content-Type: text/markdown
16
+
17
+ # q-elink
18
+
19
+ A Python library for the modelization of quantum elementary links. It provides tools to simulate, analyze, and fit experimental data related to quantum entanglement and quantum communication.
20
+
21
+ ## Features
22
+
23
+ - **Quantum Elementary Link Modeling**: Core classes to define and parameterize a quantum elementary link.
24
+ - **Local Probability Calculation**: Compute heralded and local detection probabilities.
25
+ - **Entanglement Witnessing**: Tools for entanglement witnessing analysis.
26
+ - **Data Fitting**: Functionality to fit the theoretical model to experimental data.
27
+ - **Visualization**: Built-in plotting functions to visualize results.
28
+
29
+ ## Installation
30
+
31
+ ### From PyPI
32
+
33
+ Using [uv](https://docs.astral.sh/uv/):
34
+
35
+ ```bash
36
+ uv add q-elink
37
+ ```
38
+
39
+ Or with pip:
40
+
41
+ ```bash
42
+ pip install q-elink
43
+ ```
44
+
45
+ ### From source
46
+
47
+ For development or to run the examples:
48
+
49
+ 1. Clone the repository:
50
+ ```bash
51
+ git clone https://github.com/your-username/q-elink.git
52
+ cd q-elink
53
+ ```
54
+
55
+ 2. Install dependencies using uv:
56
+ ```bash
57
+ uv sync
58
+ ```
59
+
60
+ ## Basic Usage
61
+
62
+ Here is a minimal example of how to use the library to define an elementary link, set its parameters, and calculate local probabilities.
63
+
64
+ ```python
65
+ import q_elink as ql
66
+
67
+ # 1. Define the parameters for the elementary link
68
+ param_elink = {
69
+ 'p_A': 0.01,
70
+ 'p_B': 0.08,
71
+ 'eta_0': 1e-3,
72
+ 'eta_A': 0.01,
73
+ 'eta_B': 0.01,
74
+ 'dc_0': 1e-4,
75
+ 'dc_A': 1e-4,
76
+ 'dc_B': 1e-4,
77
+ }
78
+
79
+ # 2. Create an ElementaryLink instance and set its parameters
80
+ elink = ql.ElementaryLink()
81
+ elink.set_param(param_elink)
82
+
83
+ # 3. Create a LocalProbabilityModel for calculations
84
+ local_proba = ql.LocalProbabilityModel(elink)
85
+
86
+ # Optional: Set parameters for local detection stages
87
+ param_detect = {
88
+ 'eta_A': 1.0,
89
+ 'eta_B': 1.0,
90
+ 'dc_A': 0.0,
91
+ 'dc_B': 0.0,
92
+ }
93
+ local_proba.set_param(param_detect)
94
+
95
+ # 4. Calculate probabilities
96
+ proba_herald = local_proba.get_p_herald()
97
+ p00, p01, p10, p11 = local_proba.get_proba()
98
+
99
+ # 5. Print the results
100
+ print("=== Probabilities ===")
101
+ print(f"Heralding probability: {proba_herald}")
102
+ print(f"Local probabilities:")
103
+ print(f"p00 (no-click | no-click) = {p00}")
104
+ print(f"p01 (no-click | click) = {p01}")
105
+ print(f"p10 (click | no-click) = {p10}")
106
+ print(f"p11 (click | click) = {p11}")
107
+
108
+ # 6. Plot the probabilities against pump values
109
+ # fig, ax = local_proba.plot_proba()
110
+ # fig.show()
111
+ ```
112
+
113
+ ## Modules
114
+
115
+ The library is organized into the following main modules:
116
+
117
+ - `src/q_elink/core/link.py`: Contains the core data structure `ElementaryLink` for the quantum elementary link model.
118
+ - `src/q_elink/local_probabilities/model.py`: Contains `LocalProbabilityModel` and `CoincidenceProbabilityModel` for calculating detection probabilities and coincidences.
119
+ - `src/q_elink/local_probabilities/fitter.py`: Contains `LocalProbabilityFitter` and `LocalProbabilityExperiment` classes for fitting the theoretical model to experimental data.
120
+ - `src/q_elink/local_probabilities/handler.py`: Contains `FitResultAnalyzer` for processing and analyzing fit results.
121
+ - `src/q_elink/visibility/model.py`: Contains `InterferenceModel` for visibility and interference calculations.
122
+ - `src/q_elink/witness/model.py`: Provides the `EntanglementWitness` class and related tools for entanglement witnessing.
123
+
124
+ ## Running the Examples
125
+
126
+ The `examples/` directory contains scripts that demonstrate various features of the library. Each example is meant to be run as-is from the repository root with `uv run`.
127
+
128
+ For example, to run the elementary link example:
129
+ ```bash
130
+ uv run python examples/elementary_link/elemnetary_link.py
131
+ ```
132
+
133
+ To run the coincidence measurement example:
134
+ ```bash
135
+ uv run python examples/local_proba/proba_coincidence.py
136
+ ```
137
+
138
+ To run the local probability fitting example, first generate a synthetic
139
+ dataset (written to `local/dataset/`), then fit and analyze it (figures are
140
+ written to `local/fig/`):
141
+ ```bash
142
+ uv run python examples/dataset/create_dataset_local_proba.py
143
+ uv run python examples/local_proba/fit_proba.py
144
+ uv run python examples/local_proba/fit_analyzer.py
145
+ ```
146
+
147
+ ## Core Dependencies
148
+
149
+ Standard python dependencies:
150
+ - [NumPy](https://numpy.org/): For numerical operations.
151
+ - [SciPy](https://scipy.org/): For scientific computing, particularly for data fitting.
152
+ - [Matplotlib](https://matplotlib.org/): For plotting and visualizations.
153
+ - [tqdm](https://github.com/tqdm/tqdm): For progress bars.
154
+
@@ -0,0 +1,138 @@
1
+ # q-elink
2
+
3
+ A Python library for the modelization of quantum elementary links. It provides tools to simulate, analyze, and fit experimental data related to quantum entanglement and quantum communication.
4
+
5
+ ## Features
6
+
7
+ - **Quantum Elementary Link Modeling**: Core classes to define and parameterize a quantum elementary link.
8
+ - **Local Probability Calculation**: Compute heralded and local detection probabilities.
9
+ - **Entanglement Witnessing**: Tools for entanglement witnessing analysis.
10
+ - **Data Fitting**: Functionality to fit the theoretical model to experimental data.
11
+ - **Visualization**: Built-in plotting functions to visualize results.
12
+
13
+ ## Installation
14
+
15
+ ### From PyPI
16
+
17
+ Using [uv](https://docs.astral.sh/uv/):
18
+
19
+ ```bash
20
+ uv add q-elink
21
+ ```
22
+
23
+ Or with pip:
24
+
25
+ ```bash
26
+ pip install q-elink
27
+ ```
28
+
29
+ ### From source
30
+
31
+ For development or to run the examples:
32
+
33
+ 1. Clone the repository:
34
+ ```bash
35
+ git clone https://github.com/your-username/q-elink.git
36
+ cd q-elink
37
+ ```
38
+
39
+ 2. Install dependencies using uv:
40
+ ```bash
41
+ uv sync
42
+ ```
43
+
44
+ ## Basic Usage
45
+
46
+ Here is a minimal example of how to use the library to define an elementary link, set its parameters, and calculate local probabilities.
47
+
48
+ ```python
49
+ import q_elink as ql
50
+
51
+ # 1. Define the parameters for the elementary link
52
+ param_elink = {
53
+ 'p_A': 0.01,
54
+ 'p_B': 0.08,
55
+ 'eta_0': 1e-3,
56
+ 'eta_A': 0.01,
57
+ 'eta_B': 0.01,
58
+ 'dc_0': 1e-4,
59
+ 'dc_A': 1e-4,
60
+ 'dc_B': 1e-4,
61
+ }
62
+
63
+ # 2. Create an ElementaryLink instance and set its parameters
64
+ elink = ql.ElementaryLink()
65
+ elink.set_param(param_elink)
66
+
67
+ # 3. Create a LocalProbabilityModel for calculations
68
+ local_proba = ql.LocalProbabilityModel(elink)
69
+
70
+ # Optional: Set parameters for local detection stages
71
+ param_detect = {
72
+ 'eta_A': 1.0,
73
+ 'eta_B': 1.0,
74
+ 'dc_A': 0.0,
75
+ 'dc_B': 0.0,
76
+ }
77
+ local_proba.set_param(param_detect)
78
+
79
+ # 4. Calculate probabilities
80
+ proba_herald = local_proba.get_p_herald()
81
+ p00, p01, p10, p11 = local_proba.get_proba()
82
+
83
+ # 5. Print the results
84
+ print("=== Probabilities ===")
85
+ print(f"Heralding probability: {proba_herald}")
86
+ print(f"Local probabilities:")
87
+ print(f"p00 (no-click | no-click) = {p00}")
88
+ print(f"p01 (no-click | click) = {p01}")
89
+ print(f"p10 (click | no-click) = {p10}")
90
+ print(f"p11 (click | click) = {p11}")
91
+
92
+ # 6. Plot the probabilities against pump values
93
+ # fig, ax = local_proba.plot_proba()
94
+ # fig.show()
95
+ ```
96
+
97
+ ## Modules
98
+
99
+ The library is organized into the following main modules:
100
+
101
+ - `src/q_elink/core/link.py`: Contains the core data structure `ElementaryLink` for the quantum elementary link model.
102
+ - `src/q_elink/local_probabilities/model.py`: Contains `LocalProbabilityModel` and `CoincidenceProbabilityModel` for calculating detection probabilities and coincidences.
103
+ - `src/q_elink/local_probabilities/fitter.py`: Contains `LocalProbabilityFitter` and `LocalProbabilityExperiment` classes for fitting the theoretical model to experimental data.
104
+ - `src/q_elink/local_probabilities/handler.py`: Contains `FitResultAnalyzer` for processing and analyzing fit results.
105
+ - `src/q_elink/visibility/model.py`: Contains `InterferenceModel` for visibility and interference calculations.
106
+ - `src/q_elink/witness/model.py`: Provides the `EntanglementWitness` class and related tools for entanglement witnessing.
107
+
108
+ ## Running the Examples
109
+
110
+ The `examples/` directory contains scripts that demonstrate various features of the library. Each example is meant to be run as-is from the repository root with `uv run`.
111
+
112
+ For example, to run the elementary link example:
113
+ ```bash
114
+ uv run python examples/elementary_link/elemnetary_link.py
115
+ ```
116
+
117
+ To run the coincidence measurement example:
118
+ ```bash
119
+ uv run python examples/local_proba/proba_coincidence.py
120
+ ```
121
+
122
+ To run the local probability fitting example, first generate a synthetic
123
+ dataset (written to `local/dataset/`), then fit and analyze it (figures are
124
+ written to `local/fig/`):
125
+ ```bash
126
+ uv run python examples/dataset/create_dataset_local_proba.py
127
+ uv run python examples/local_proba/fit_proba.py
128
+ uv run python examples/local_proba/fit_analyzer.py
129
+ ```
130
+
131
+ ## Core Dependencies
132
+
133
+ Standard python dependencies:
134
+ - [NumPy](https://numpy.org/): For numerical operations.
135
+ - [SciPy](https://scipy.org/): For scientific computing, particularly for data fitting.
136
+ - [Matplotlib](https://matplotlib.org/): For plotting and visualizations.
137
+ - [tqdm](https://github.com/tqdm/tqdm): For progress bars.
138
+
@@ -0,0 +1,65 @@
1
+ """Generate a synthetic interference-fringe dataset to test a visibility fit.
2
+
3
+ Sets a known elementary link, computes the coincidence probability as a
4
+ function of the analysis phase theta over [-pi, pi], then adds noise: a
5
+ constant vertical offset, a small global phase drift, and per-point scatter.
6
+ The dataset is stored in local/dataset/.
7
+ """
8
+ import json
9
+ from pathlib import Path
10
+
11
+ import numpy as np
12
+
13
+ import q_elink as ql
14
+
15
+ # ----- Output path -----
16
+ path_dataset = Path("local/dataset")
17
+ path_dataset.mkdir(parents=True, exist_ok=True)
18
+ out_file = path_dataset / "fringe.json"
19
+
20
+ # ----- Ground-truth model -----
21
+ rng_seed = 42
22
+ rng = np.random.default_rng(rng_seed)
23
+
24
+ ground_truth = {
25
+ "p_A": 0.05,
26
+ "p_B": 0.05,
27
+ "eta_0": 1e-2,
28
+ "eta_A": 0.1,
29
+ "eta_B": 0.1,
30
+ "dc_0": 1e-4,
31
+ "dc_A": 1e-4,
32
+ "dc_B": 1e-4,
33
+ }
34
+
35
+ elink = ql.ElementaryLink()
36
+ elink.set_param(ground_truth)
37
+ model_visib = ql.InterferenceModel(elink)
38
+
39
+ # ----- Phase sampling -----
40
+ n_data = 10
41
+ theta = np.linspace(-np.pi, np.pi, n_data)
42
+
43
+ # ----- Noise model -----
44
+ offset = 5e-3 # constant vertical offset
45
+ phase_drift = 0.15 # small global phase drift (rad)
46
+ noise_std_ratio = 0.03 # per-point relative scatter
47
+
48
+ proba_clean = np.array([model_visib.get_proba_coincidence(t + phase_drift) for t in theta])
49
+ proba_noisy = proba_clean + offset + rng.normal(0, noise_std_ratio * np.abs(proba_clean))
50
+
51
+ # ----- Save -----
52
+ dataset = {
53
+ "ground_truth": ground_truth,
54
+ "noise": {
55
+ "offset": offset,
56
+ "phase_drift": phase_drift,
57
+ "noise_std_ratio": noise_std_ratio,
58
+ },
59
+ "theta": theta.tolist(),
60
+ "proba_coincidence": proba_noisy.tolist(),
61
+ }
62
+ with open(out_file, "w") as f:
63
+ json.dump(dataset, f, indent=4)
64
+
65
+ print(f"Fringe dataset written to {out_file}")
@@ -0,0 +1,68 @@
1
+ """Generate a synthetic local-probability dataset to test the fit.
2
+
3
+ Sets a known elementary link, computes the local probabilities
4
+ (p00, p01, p10, p11) without displacement (alpha = beta = 0) for a handful of
5
+ pump values, adds a bit of noise, and stores the result in local/dataset/.
6
+ The dataset is consumed by examples/local_proba/fit_proba.py.
7
+ """
8
+ import json
9
+ from pathlib import Path
10
+
11
+ import numpy as np
12
+
13
+ import q_elink as ql
14
+
15
+ # ----- Output path -----
16
+ path_dataset = Path("local/dataset")
17
+ path_dataset.mkdir(parents=True, exist_ok=True)
18
+ out_file = path_dataset / "local_proba.json"
19
+
20
+ # ----- Ground-truth model -----
21
+ rng_seed = 42
22
+ rng = np.random.default_rng(rng_seed)
23
+
24
+ # NB: dark counts are given on a log10 scale (set_param with log_dc=True).
25
+ ground_truth = {
26
+ "eta_0": 1e-2,
27
+ "eta_A": 0.1,
28
+ "eta_B": 0.1,
29
+ "dc_0": -4,
30
+ "dc_A": -4,
31
+ "dc_B": -4,
32
+ }
33
+
34
+ elink = ql.ElementaryLink()
35
+ elink.set_param(ground_truth, log_dc=True)
36
+ local_proba = ql.LocalProbabilityModel(elink)
37
+
38
+ # ----- Pump sampling (max pump p = 0.2) -----
39
+ n_data = 5
40
+ p_min, p_max = 0.03, 0.2
41
+ p_A = np.linspace(p_min, p_max, n_data)
42
+ p_B = p_A + rng.normal(0, 0.03 * np.abs(p_A)) # slight A/B asymmetry
43
+
44
+ # ----- Compute local probabilities (no displacement: alpha = beta = 0) -----
45
+ def sample(getter, p_a, p_b):
46
+ local_proba.set_pump(p_A=p_a, p_B=p_b)
47
+ return getter()
48
+
49
+ proba_dict = {}
50
+ for key, getter in [
51
+ ("p00", local_proba.get_p00),
52
+ ("p01", local_proba.get_p01),
53
+ ("p10", local_proba.get_p10),
54
+ ("p11", local_proba.get_p11),
55
+ ]:
56
+ values = np.array([sample(getter, p_a, p_b) for p_a, p_b in zip(p_A, p_B)])
57
+ proba_dict[key] = values + rng.normal(0, 0.01 * np.abs(values)) # relative noise
58
+
59
+ # ----- Save -----
60
+ dataset = {
61
+ "ground_truth": ground_truth,
62
+ "pump_dict": {"p_A": p_A.tolist(), "p_B": p_B.tolist()},
63
+ "proba_dict": {key: value.tolist() for key, value in proba_dict.items()},
64
+ }
65
+ with open(out_file, "w") as f:
66
+ json.dump(dataset, f, indent=4)
67
+
68
+ print(f"Local-probability dataset written to {out_file}")