parityos 0.0.6__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.

Potentially problematic release.


This version of parityos might be problematic. Click here for more details.

Files changed (151) hide show
  1. parityos-0.0.6/License.txt +37 -0
  2. parityos-0.0.6/PKG-INFO +34 -0
  3. parityos-0.0.6/README.md +113 -0
  4. parityos-0.0.6/parityos/__init__.py +15 -0
  5. parityos-0.0.6/parityos/api_interface/__init__.py +0 -0
  6. parityos-0.0.6/parityos/api_interface/authentication.py +87 -0
  7. parityos-0.0.6/parityos/api_interface/compiler_run.py +113 -0
  8. parityos-0.0.6/parityos/api_interface/connection.py +139 -0
  9. parityos-0.0.6/parityos/api_interface/exceptions.py +36 -0
  10. parityos-0.0.6/parityos/base/__init__.py +48 -0
  11. parityos-0.0.6/parityos/base/circuit.py +219 -0
  12. parityos-0.0.6/parityos/base/constraints.py +123 -0
  13. parityos-0.0.6/parityos/base/exceptions.py +20 -0
  14. parityos-0.0.6/parityos/base/gates.py +704 -0
  15. parityos-0.0.6/parityos/base/problem_representation.py +322 -0
  16. parityos-0.0.6/parityos/base/qubits.py +83 -0
  17. parityos-0.0.6/parityos/base/utils.py +124 -0
  18. parityos-0.0.6/parityos/compiler_client.py +146 -0
  19. parityos-0.0.6/parityos/device_model.py +181 -0
  20. parityos-0.0.6/parityos/encodings/__init__.py +0 -0
  21. parityos-0.0.6/parityos/encodings/mappings.py +110 -0
  22. parityos-0.0.6/parityos/encodings/parity_decoder.py +268 -0
  23. parityos-0.0.6/parityos/encodings/parity_encoder.py +39 -0
  24. parityos-0.0.6/parityos/encodings/parityos_output.py +248 -0
  25. parityos-0.0.6/parityos.egg-info/PKG-INFO +34 -0
  26. parityos-0.0.6/parityos.egg-info/SOURCES.txt +149 -0
  27. parityos-0.0.6/parityos.egg-info/dependency_links.txt +1 -0
  28. parityos-0.0.6/parityos.egg-info/requires.txt +32 -0
  29. parityos-0.0.6/parityos.egg-info/top_level.txt +3 -0
  30. parityos-0.0.6/parityos_addons/benchmarking/__init__.py +11 -0
  31. parityos-0.0.6/parityos_addons/benchmarking/benchmark_compiler_runs.py +79 -0
  32. parityos-0.0.6/parityos_addons/benchmarking/benchmark_parityos_outputs.py +48 -0
  33. parityos-0.0.6/parityos_addons/benchmarking/dataframe_construction/__init__.py +0 -0
  34. parityos-0.0.6/parityos_addons/benchmarking/dataframe_construction/add_column.py +38 -0
  35. parityos-0.0.6/parityos_addons/benchmarking/dataframe_construction/benchmark_circuits.py +47 -0
  36. parityos-0.0.6/parityos_addons/benchmarking/dataframe_construction/benchmark_compiler_runs.py +46 -0
  37. parityos-0.0.6/parityos_addons/benchmarking/dataframe_construction/benchmark_problem_representations.py +52 -0
  38. parityos-0.0.6/parityos_addons/benchmarking/metrics/__init__.py +27 -0
  39. parityos-0.0.6/parityos_addons/benchmarking/metrics/circuit_metrics.py +125 -0
  40. parityos-0.0.6/parityos_addons/benchmarking/metrics/circuit_utils.py +37 -0
  41. parityos-0.0.6/parityos_addons/benchmarking/metrics/compilation_metrics.py +75 -0
  42. parityos-0.0.6/parityos_addons/documentation/__init__.py +0 -0
  43. parityos-0.0.6/parityos_addons/documentation/html/_images/hypergraph_solution_tutorial.png +0 -0
  44. parityos-0.0.6/parityos_addons/documentation/html/_images/hypergraph_tutorial.png +0 -0
  45. parityos-0.0.6/parityos_addons/documentation/html/_sources/api_reference/api_interface.rst.txt +6 -0
  46. parityos-0.0.6/parityos_addons/documentation/html/_sources/api_reference/base.rst.txt +14 -0
  47. parityos-0.0.6/parityos_addons/documentation/html/_sources/api_reference/encodings.rst.txt +11 -0
  48. parityos-0.0.6/parityos_addons/documentation/html/_sources/api_reference/index.rst.txt +11 -0
  49. parityos-0.0.6/parityos_addons/documentation/html/_sources/api_reference/parityos.rst.txt +6 -0
  50. parityos-0.0.6/parityos_addons/documentation/html/_sources/api_reference/parityos_addons.rst.txt +17 -0
  51. parityos-0.0.6/parityos_addons/documentation/html/_sources/asynchronous_submission.rst.txt +67 -0
  52. parityos-0.0.6/parityos_addons/documentation/html/_sources/benchmarking.rst.txt +132 -0
  53. parityos-0.0.6/parityos_addons/documentation/html/_sources/custom_device_models.rst.txt +221 -0
  54. parityos-0.0.6/parityos_addons/documentation/html/_sources/index.rst.txt +15 -0
  55. parityos-0.0.6/parityos_addons/documentation/html/_sources/installation.rst.txt +33 -0
  56. parityos-0.0.6/parityos_addons/documentation/html/_sources/parity_decoder.rst.txt +69 -0
  57. parityos-0.0.6/parityos_addons/documentation/html/_sources/quickstart.rst.txt +199 -0
  58. parityos-0.0.6/parityos_addons/documentation/html/_sources/tutorial.rst.txt +449 -0
  59. parityos-0.0.6/parityos_addons/documentation/html/_static/_sphinx_javascript_frameworks_compat.js +123 -0
  60. parityos-0.0.6/parityos_addons/documentation/html/_static/basic.css +914 -0
  61. parityos-0.0.6/parityos_addons/documentation/html/_static/css/badge_only.css +1 -0
  62. parityos-0.0.6/parityos_addons/documentation/html/_static/css/fonts/Roboto-Slab-Bold.woff +0 -0
  63. parityos-0.0.6/parityos_addons/documentation/html/_static/css/fonts/Roboto-Slab-Bold.woff2 +0 -0
  64. parityos-0.0.6/parityos_addons/documentation/html/_static/css/fonts/Roboto-Slab-Regular.woff +0 -0
  65. parityos-0.0.6/parityos_addons/documentation/html/_static/css/fonts/Roboto-Slab-Regular.woff2 +0 -0
  66. parityos-0.0.6/parityos_addons/documentation/html/_static/css/fonts/fontawesome-webfont.eot +0 -0
  67. parityos-0.0.6/parityos_addons/documentation/html/_static/css/fonts/fontawesome-webfont.svg +2671 -0
  68. parityos-0.0.6/parityos_addons/documentation/html/_static/css/fonts/fontawesome-webfont.ttf +0 -0
  69. parityos-0.0.6/parityos_addons/documentation/html/_static/css/fonts/fontawesome-webfont.woff +0 -0
  70. parityos-0.0.6/parityos_addons/documentation/html/_static/css/fonts/fontawesome-webfont.woff2 +0 -0
  71. parityos-0.0.6/parityos_addons/documentation/html/_static/css/fonts/lato-bold-italic.woff +0 -0
  72. parityos-0.0.6/parityos_addons/documentation/html/_static/css/fonts/lato-bold-italic.woff2 +0 -0
  73. parityos-0.0.6/parityos_addons/documentation/html/_static/css/fonts/lato-bold.woff +0 -0
  74. parityos-0.0.6/parityos_addons/documentation/html/_static/css/fonts/lato-bold.woff2 +0 -0
  75. parityos-0.0.6/parityos_addons/documentation/html/_static/css/fonts/lato-normal-italic.woff +0 -0
  76. parityos-0.0.6/parityos_addons/documentation/html/_static/css/fonts/lato-normal-italic.woff2 +0 -0
  77. parityos-0.0.6/parityos_addons/documentation/html/_static/css/fonts/lato-normal.woff +0 -0
  78. parityos-0.0.6/parityos_addons/documentation/html/_static/css/fonts/lato-normal.woff2 +0 -0
  79. parityos-0.0.6/parityos_addons/documentation/html/_static/css/theme.css +4 -0
  80. parityos-0.0.6/parityos_addons/documentation/html/_static/doctools.js +149 -0
  81. parityos-0.0.6/parityos_addons/documentation/html/_static/documentation_options.js +13 -0
  82. parityos-0.0.6/parityos_addons/documentation/html/_static/file.png +0 -0
  83. parityos-0.0.6/parityos_addons/documentation/html/_static/fonts/Lato/lato-bold.eot +0 -0
  84. parityos-0.0.6/parityos_addons/documentation/html/_static/fonts/Lato/lato-bold.ttf +0 -0
  85. parityos-0.0.6/parityos_addons/documentation/html/_static/fonts/Lato/lato-bold.woff +0 -0
  86. parityos-0.0.6/parityos_addons/documentation/html/_static/fonts/Lato/lato-bold.woff2 +0 -0
  87. parityos-0.0.6/parityos_addons/documentation/html/_static/fonts/Lato/lato-bolditalic.eot +0 -0
  88. parityos-0.0.6/parityos_addons/documentation/html/_static/fonts/Lato/lato-bolditalic.ttf +0 -0
  89. parityos-0.0.6/parityos_addons/documentation/html/_static/fonts/Lato/lato-bolditalic.woff +0 -0
  90. parityos-0.0.6/parityos_addons/documentation/html/_static/fonts/Lato/lato-bolditalic.woff2 +0 -0
  91. parityos-0.0.6/parityos_addons/documentation/html/_static/fonts/Lato/lato-italic.eot +0 -0
  92. parityos-0.0.6/parityos_addons/documentation/html/_static/fonts/Lato/lato-italic.ttf +0 -0
  93. parityos-0.0.6/parityos_addons/documentation/html/_static/fonts/Lato/lato-italic.woff +0 -0
  94. parityos-0.0.6/parityos_addons/documentation/html/_static/fonts/Lato/lato-italic.woff2 +0 -0
  95. parityos-0.0.6/parityos_addons/documentation/html/_static/fonts/Lato/lato-regular.eot +0 -0
  96. parityos-0.0.6/parityos_addons/documentation/html/_static/fonts/Lato/lato-regular.ttf +0 -0
  97. parityos-0.0.6/parityos_addons/documentation/html/_static/fonts/Lato/lato-regular.woff +0 -0
  98. parityos-0.0.6/parityos_addons/documentation/html/_static/fonts/Lato/lato-regular.woff2 +0 -0
  99. parityos-0.0.6/parityos_addons/documentation/html/_static/fonts/RobotoSlab/roboto-slab-v7-bold.eot +0 -0
  100. parityos-0.0.6/parityos_addons/documentation/html/_static/fonts/RobotoSlab/roboto-slab-v7-bold.ttf +0 -0
  101. parityos-0.0.6/parityos_addons/documentation/html/_static/fonts/RobotoSlab/roboto-slab-v7-bold.woff +0 -0
  102. parityos-0.0.6/parityos_addons/documentation/html/_static/fonts/RobotoSlab/roboto-slab-v7-bold.woff2 +0 -0
  103. parityos-0.0.6/parityos_addons/documentation/html/_static/fonts/RobotoSlab/roboto-slab-v7-regular.eot +0 -0
  104. parityos-0.0.6/parityos_addons/documentation/html/_static/fonts/RobotoSlab/roboto-slab-v7-regular.ttf +0 -0
  105. parityos-0.0.6/parityos_addons/documentation/html/_static/fonts/RobotoSlab/roboto-slab-v7-regular.woff +0 -0
  106. parityos-0.0.6/parityos_addons/documentation/html/_static/fonts/RobotoSlab/roboto-slab-v7-regular.woff2 +0 -0
  107. parityos-0.0.6/parityos_addons/documentation/html/_static/jquery.js +2 -0
  108. parityos-0.0.6/parityos_addons/documentation/html/_static/js/badge_only.js +1 -0
  109. parityos-0.0.6/parityos_addons/documentation/html/_static/js/theme.js +1 -0
  110. parityos-0.0.6/parityos_addons/documentation/html/_static/js/versions.js +228 -0
  111. parityos-0.0.6/parityos_addons/documentation/html/_static/language_data.js +192 -0
  112. parityos-0.0.6/parityos_addons/documentation/html/_static/minus.png +0 -0
  113. parityos-0.0.6/parityos_addons/documentation/html/_static/plus.png +0 -0
  114. parityos-0.0.6/parityos_addons/documentation/html/_static/pygments.css +75 -0
  115. parityos-0.0.6/parityos_addons/documentation/html/_static/searchtools.js +632 -0
  116. parityos-0.0.6/parityos_addons/documentation/html/_static/sphinx_highlight.js +154 -0
  117. parityos-0.0.6/parityos_addons/documentation/html/api_reference/api_interface.html +124 -0
  118. parityos-0.0.6/parityos_addons/documentation/html/api_reference/base.html +1262 -0
  119. parityos-0.0.6/parityos_addons/documentation/html/api_reference/encodings.html +352 -0
  120. parityos-0.0.6/parityos_addons/documentation/html/api_reference/index.html +133 -0
  121. parityos-0.0.6/parityos_addons/documentation/html/api_reference/parityos.html +704 -0
  122. parityos-0.0.6/parityos_addons/documentation/html/api_reference/parityos_addons.html +382 -0
  123. parityos-0.0.6/parityos_addons/documentation/html/asynchronous_submission.html +185 -0
  124. parityos-0.0.6/parityos_addons/documentation/html/benchmarking.html +251 -0
  125. parityos-0.0.6/parityos_addons/documentation/html/custom_device_models.html +337 -0
  126. parityos-0.0.6/parityos_addons/documentation/html/genindex.html +768 -0
  127. parityos-0.0.6/parityos_addons/documentation/html/index.html +128 -0
  128. parityos-0.0.6/parityos_addons/documentation/html/installation.html +142 -0
  129. parityos-0.0.6/parityos_addons/documentation/html/objects.inv +0 -0
  130. parityos-0.0.6/parityos_addons/documentation/html/parity_decoder.html +189 -0
  131. parityos-0.0.6/parityos_addons/documentation/html/py-modindex.html +193 -0
  132. parityos-0.0.6/parityos_addons/documentation/html/quickstart.html +324 -0
  133. parityos-0.0.6/parityos_addons/documentation/html/search.html +127 -0
  134. parityos-0.0.6/parityos_addons/documentation/html/searchindex.js +1 -0
  135. parityos-0.0.6/parityos_addons/documentation/html/tutorial.html +530 -0
  136. parityos-0.0.6/parityos_addons/documentation/show.py +24 -0
  137. parityos-0.0.6/parityos_addons/examples/__init__.py +0 -0
  138. parityos-0.0.6/parityos_addons/examples/example1.py +60 -0
  139. parityos-0.0.6/parityos_addons/examples/example2.py +54 -0
  140. parityos-0.0.6/parityos_addons/examples/example3.py +58 -0
  141. parityos-0.0.6/parityos_addons/examples/example4.py +70 -0
  142. parityos-0.0.6/parityos_addons/examples/runner.py +33 -0
  143. parityos-0.0.6/parityos_addons/interfaces/__init__.py +22 -0
  144. parityos-0.0.6/parityos_addons/interfaces/cirq_exporter.py +184 -0
  145. parityos-0.0.6/parityos_addons/interfaces/openqasm_exporter.py +426 -0
  146. parityos-0.0.6/parityos_addons/interfaces/qiskit_exporter.py +251 -0
  147. parityos-0.0.6/parityos_addons/qaoa/__init__.py +12 -0
  148. parityos-0.0.6/parityos_addons/qaoa/qaoa_scheduler.py +105 -0
  149. parityos-0.0.6/parityos_addons/spin_hamiltonians.py +102 -0
  150. parityos-0.0.6/setup.cfg +4 -0
  151. parityos-0.0.6/setup.py +53 -0
@@ -0,0 +1,37 @@
1
+ ParityOS Client Software License Terms (BSD-3-Clause)
2
+ =====================================================
3
+
4
+ Copyright 2023 Parity Quantum Computing GmbH (ParityQC)
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ 1. Redistributions of source code must retain the above copyright notice,
10
+ this list of conditions and the following disclaimer.
11
+
12
+ 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ 3. Neither the name of the copyright holder nor the names of its contributors
17
+ may be used to endorse or promote products derived from this software
18
+ without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
21
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
+
31
+ ===============================================================================
32
+
33
+ Parity Quantum Computing GmbH
34
+ Rennweg 1 / Top 314 / 6020 Innsbruck, Austria
35
+ info@parityqc.com / www.parityqc.com
36
+
37
+ ===============================================================================
@@ -0,0 +1,34 @@
1
+ Metadata-Version: 2.1
2
+ Name: parityos
3
+ Version: 0.0.6
4
+ Summary: Python bindings to the ParityOS API
5
+ Home-page: https://parityqc.com/
6
+ Requires-Python: >=3.9
7
+ License-File: License.txt
8
+ Requires-Dist: requests
9
+ Provides-Extra: cirq
10
+ Requires-Dist: cirq-core; extra == "cirq"
11
+ Provides-Extra: qiskit
12
+ Requires-Dist: qiskit; extra == "qiskit"
13
+ Provides-Extra: spinz
14
+ Requires-Dist: sympy; extra == "spinz"
15
+ Provides-Extra: benchmarking
16
+ Requires-Dist: pandas; extra == "benchmarking"
17
+ Requires-Dist: numpy; extra == "benchmarking"
18
+ Provides-Extra: all
19
+ Requires-Dist: sympy; extra == "all"
20
+ Requires-Dist: numpy; extra == "all"
21
+ Requires-Dist: cirq-core; extra == "all"
22
+ Requires-Dist: pandas; extra == "all"
23
+ Requires-Dist: qiskit; extra == "all"
24
+ Provides-Extra: dev
25
+ Requires-Dist: black; extra == "dev"
26
+ Requires-Dist: numpy; extra == "dev"
27
+ Requires-Dist: pip-tools; extra == "dev"
28
+ Requires-Dist: pytest; extra == "dev"
29
+ Requires-Dist: qiskit-aer; extra == "dev"
30
+ Requires-Dist: sympy; extra == "dev"
31
+ Requires-Dist: numpy; extra == "dev"
32
+ Requires-Dist: cirq-core; extra == "dev"
33
+ Requires-Dist: pandas; extra == "dev"
34
+ Requires-Dist: qiskit; extra == "dev"
@@ -0,0 +1,113 @@
1
+ # ParityOS
2
+ Parity Quantum Computing GmbH
3
+ Rennweg 1 Top 314
4
+ 6020 Innsbruck, Austria
5
+ Copyright (c) 2020-2023.
6
+
7
+ This package contains the client software to use the ParityOS cloud service.
8
+
9
+ ## Installation
10
+ It is recommended to install this package in a separate Python `venv` or Conda environment.
11
+ ```commandline
12
+ # To create a standard Python environment:
13
+ python -m venv my_new_venv && source my_new_venv/bin/activate
14
+ # Or, alternatively, to create a Anaconda/Miniconda environment:
15
+ conda create --name my_new_conda_env && conda activate my_new_conda_env
16
+ ```
17
+
18
+ Installation is done with the following command:
19
+ ```commandline
20
+ pip install parityos
21
+ ```
22
+ This will install two Python libraries: `parityos` and `parityos_addons`.
23
+
24
+ Some addons depend on external libraries like Cirq, Sympy or Qiskit.
25
+ The `pip` command will resolve these dependencies automatically if you specify which addons you
26
+ want to include. E.g. to include dependencies for the `spin_hamiltonians` and `qiskit_exporter`
27
+ addons, use this command:
28
+ ```commandline
29
+ pip install 'parityos[spinz,qiksit]'
30
+ ```
31
+ or to use `spin_hamiltonians` and `cirq_exporter`:
32
+ ```commandline
33
+ pip install 'parityos[spinz,cirq]'
34
+ ```
35
+ These commands will make sure that additional dependencies like `sympy`, `qiskit` or `cirq`
36
+ are installed correctly.
37
+ If you want to make sure that all optional dependencies are included, use:
38
+ ```commandline
39
+ pip install 'parityos[all]'
40
+ ```
41
+
42
+
43
+ ## ParityOS
44
+ A Python package that provides the `CompilerClient` class to connect to
45
+ the ParityOS cloud service. The package defines data structures to construct
46
+ the inputs and to process the outputs from the ParityOS cloud service.
47
+
48
+ from parityos import CompilerClient, RectangularDigitalDevice
49
+
50
+ username = '' # Put here your ParityOS username or set the PARITYOS_USER environment variable.
51
+ compiler_client = CompilerClient(username)
52
+ device_model = RectangularDigitalDevice(4, 4)
53
+ parityos_output = compiler_client.compile(hamiltonian, device_model)
54
+
55
+ ## ParityOS Addons
56
+ Additional tools that help you to get the most out of the ParityOS framework.
57
+
58
+ ### addon documentation
59
+ Detailed documentation on how to use the ParityOS framework, including a
60
+ quickstart guide and a QAOA tutorial.
61
+
62
+ To open the documentation in your web browser, type the following command
63
+ on the command line:
64
+
65
+ python -m parityos_addons.documentation.show
66
+
67
+ ### addon examples
68
+ Some examples of ParityOS compilations can be found in `parityos_addons_examples`.
69
+ These can be run directly from the command line:
70
+
71
+ python -m parityos_addons.examples.example1
72
+ python -m parityos_addons.examples.example2
73
+ python -m parityos_addons.examples.example3
74
+ python -m parityos_addons.examples.example4
75
+ python -m parityos_addons.examples.example5
76
+
77
+ ### addon spin_hamiltonians
78
+ A Python package that provides tools to construct a spin Hamiltonian as a product
79
+ of Pauli spin Z operators. An example:
80
+
81
+ from parityos_addons.spin_hamiltonians import spinz_to_hamiltonian, SpinZ as Z
82
+
83
+ hamiltonian = spinz_to_hamiltonian(
84
+ Z('a') + Z('b') - 2 * Z('c') + 4 * Z('a') * Z('b') - (Z('a') + Z('b')) * Z('c')
85
+ )
86
+
87
+ ### addon qaoa
88
+ A Python package that provides tools to construct a QAOA circuit from the
89
+ output returned by the ParityOS cloud service.
90
+
91
+ from parityos_addons.qaoa import generate_qaoa
92
+
93
+ parityos_circuit, parameter_bounds = generate_qaoa(parityos_output=parityos_output,
94
+ unitary_pattern='ZCX' * 4)
95
+
96
+ ### addon interfaces
97
+ Provides the tools to export quantum circuits from ParityOS to other
98
+ frameworks like Cirq or Qiskit. Here is an example with Qiskit:
99
+
100
+ from qiskit.circuit import Parameter
101
+ from parityos_addons.interfaces import QiskitExporter
102
+
103
+ # Map ParityOS parameters onto Qiskit parameters
104
+ parameter_map = {key: Parameter(str(key)) for key in parameter_bounds.keys()}
105
+ # Instantiate the exporter
106
+ qiskit_exporter = QiskitExporter(parameter_map=parameter_map, qubit_map=qubit_map)
107
+ # Convert the ParityOS circuit to a qiskit circuit
108
+ qiskit_circuit = qiskit_exporter.to_qiskit(parityos_circuit)
109
+
110
+ ## License
111
+ Since version 2.1.0, the ParityOS Client software package is made available
112
+ under the 3-Clause BSD License. See the file `License.txt` for details.
113
+
@@ -0,0 +1,15 @@
1
+ """
2
+ Parity Quantum Computing GmbH
3
+ Rennweg 1 Top 314
4
+ 6020 Innsbruck, Austria
5
+
6
+ Copyright (c) 2020-2024.
7
+ All rights reserved.
8
+
9
+ Tools to use the ParityOS cloud services.
10
+ """
11
+
12
+ from .base import Hamiltonian, ProblemRepresentation, ParityOSException, ParityOSImportError, Qubit
13
+ from .device_model import RectangularAnalogDevice, RectangularDigitalDevice
14
+ from .encodings.parityos_output import ParityOSOutput
15
+ from .compiler_client import CompilerClient
File without changes
@@ -0,0 +1,87 @@
1
+ """
2
+ Parity Quantum Computing GmbH
3
+ Rennweg 1 Top 314
4
+ 6020 Innsbruck, Austria
5
+
6
+ Copyright (c) 2020-2023.
7
+ All rights reserved.
8
+
9
+ Tools to authenticate with the ParityOS cloud services.
10
+ """
11
+
12
+ from collections.abc import Iterator
13
+ import getpass
14
+ import os
15
+ import warnings
16
+
17
+
18
+ def generate_credentials(
19
+ username: str = None,
20
+ username_variable: str = "",
21
+ password_variable: str = "",
22
+ intents: int = 3,
23
+ ) -> Iterator[dict[str, str]]:
24
+ """
25
+ Generates a series of JSON compatible dictionaries with a username and a password.
26
+ The username can be provided as an argument. Otherwise, it is taken from the given system
27
+ variable (this is tried only once), or requested from the user on the prompt.
28
+ For security reasons, the password can not be provided as an argument. It is either taken
29
+ from the given system variable (this is tried only once), or requested from the user on the
30
+ prompt.
31
+ The argument `intents` sets the maximum number of times to ask for a username or password,
32
+ either from the environment or from the prompt.
33
+ To make this generator fully non-interactive, set intents to 1 and set the correct system
34
+ variables.
35
+
36
+ :param str username: The username for the account on the server.
37
+ :param str username_variable: System variable to query for the username
38
+ :param str password_variable: System variable to query for the password
39
+ :param int intents: Maximum number of times to ask for a username or password.
40
+ """
41
+ # The credentials object allows for a number of intents to provide the password.
42
+ # First intent: get data from the environment variables or else from prompt.
43
+ username = username or _get_username(username, username_variable)
44
+ password = _get_password(password_variable=password_variable)
45
+ yield {"username": username, "password": password}
46
+
47
+ # The next intents are always interactive.
48
+ for intent in range(1, intents):
49
+ print("Login failed. Please provide the correct credentials.")
50
+ username = _get_username(username)
51
+ password = _get_password(password)
52
+ yield {"username": username, "password": password}
53
+
54
+
55
+ def _get_username(username: str = "", username_variable: str = "") -> str:
56
+ """
57
+ Ask for a username, either from the provided environment variable or on the prompt.
58
+ If a username argument is given, then this is shown as a suggestion on the prompt
59
+ and returned as the result if the user only types return.
60
+ """
61
+ if username_variable and not username:
62
+ username = os.getenv(username_variable)
63
+ if username:
64
+ return username
65
+
66
+ suggestion = f" [{username}]" if username else ""
67
+ username = input(f"ParityOS Username{suggestion}: ") or username
68
+ return username
69
+
70
+
71
+ def _get_password(password: str = "", password_variable: str = "") -> str:
72
+ """
73
+ Ask for a password, either from the provided environment variable or on the prompt.
74
+ If a password argument is given, then "***" is shown as a suggestion on the prompt
75
+ and the given value is returned as the result if the user only types return.
76
+ """
77
+ if password_variable and not password:
78
+ with warnings.catch_warnings():
79
+ warnings.simplefilter("ignore")
80
+ password = os.getenv(password_variable)
81
+
82
+ if password:
83
+ return password
84
+
85
+ suggestion = " [***]" if password else ""
86
+ password = getpass.getpass(f"ParityOS Password{suggestion}: ") or password
87
+ return password
@@ -0,0 +1,113 @@
1
+ """
2
+ Parity Quantum Computing GmbH
3
+ Rennweg 1 Top 314
4
+ 6020 Innsbruck, Austria
5
+
6
+ Copyright (c) 2020-2024.
7
+ All rights reserved.
8
+
9
+ Tools to process the results from the ParityOS cloud service.
10
+ """
11
+
12
+ from dataclasses import dataclass
13
+ from datetime import datetime
14
+ from enum import Enum
15
+ from typing import Optional, Union
16
+
17
+ from parityos.base import JSONMappingType
18
+
19
+
20
+ DateStr = Union[datetime, str] # type: TypeAlias
21
+
22
+
23
+ class CompilerRunStatus(Enum):
24
+ """
25
+ Enum for compiler run status.
26
+ """
27
+
28
+ SUBMITTED = "S"
29
+ RUNNING = "R"
30
+ COMPLETED = "C"
31
+ FAILED = "F"
32
+
33
+
34
+ @dataclass
35
+ class CompilerRun:
36
+ """
37
+ Encapsulates a compiler run; has attributes which describe relevant times
38
+ at which they were submitted, started, and eventually finished or failed
39
+ (in which case, a reason for failure is also given).
40
+
41
+ :param id: The UUID4 id of the compiler run in ParityOS cloud database.
42
+ :param submission_id: The UUID4 id of the submission which triggered compile run.
43
+ :param status: The status of the submission; see the `CompilerRunStatus` enum.
44
+ :param submitted_at: Time at which the run was queued for execution, as `datetime` object.
45
+ :param started_at: Time at which the run started being executed, as `datetime` object.
46
+ :param finished_at: Time at which the run was completed, as `datetime` object.
47
+ :param failed_at: time at which run failed
48
+ :param failure_reason: reason for which run failed
49
+ """
50
+
51
+ id: str
52
+ submission_id: str
53
+ status: Union[CompilerRunStatus, str]
54
+ submitted_at: Optional[DateStr] = None
55
+ started_at: Optional[DateStr] = None
56
+ finished_at: Optional[DateStr] = None
57
+ failed_at: Optional[DateStr] = None
58
+ failure_reason: Optional[str] = ""
59
+
60
+ def __post_init__(self):
61
+ """Convert attributes to their intended type if they were provided as strings."""
62
+ # Map the status to the corresponding Enum instance.
63
+ self.status = CompilerRunStatus(self.status)
64
+ # Map date times in string format to datetime instances
65
+ self.submitted_at = _str_to_datetime(self.submitted_at)
66
+ self.started_at = _str_to_datetime(self.started_at)
67
+ self.finished_at = _str_to_datetime(self.finished_at)
68
+ self.failed_at = _str_to_datetime(self.failed_at)
69
+
70
+ @classmethod
71
+ def from_json(cls, data: JSONMappingType) -> "Self":
72
+ """
73
+ Creates a CompilerRun object from a JSON-like data dictionary.
74
+ :return: a CompilerRun object
75
+ """
76
+ return cls(**data)
77
+
78
+ def __str__(self) -> str:
79
+ """
80
+ Return useful information about the compiler run in string format.
81
+ """
82
+ info_lines = [f"Compiler run {self.id}. ", f"Status: {self.status}"]
83
+ if self.submitted_at:
84
+ info_lines.append(f"The compiler run was submitted at {self.submitted_at.ctime()}.")
85
+
86
+ if self.started_at:
87
+ info_lines.append(f"The compilation started at {self.started_at.ctime()}.")
88
+ if self.finished_at:
89
+ duration_in_seconds = (self.finished_at - self.started_at).total_seconds()
90
+ info_lines.append(f"The compilation took {duration_in_seconds:0.2f} seconds.")
91
+
92
+ if self.failed_at:
93
+ if self.started_at:
94
+ duration_in_seconds = (self.failed_at - self.started_at).total_seconds()
95
+ info_lines.append(
96
+ f"The compilation was aborted after {duration_in_seconds:0.2f} seconds."
97
+ )
98
+ else:
99
+ info_lines.append(f"An error occurred at {self.failed_at.ctime()}.")
100
+
101
+ if self.failure_reason:
102
+ info_lines.append(self.failure_reason)
103
+
104
+ return "\n".join(info_lines)
105
+
106
+
107
+ def _str_to_datetime(date: Union[datetime, str]) -> datetime:
108
+ """Helper method to convert dates in string format to datetime instances."""
109
+ return (
110
+ datetime.fromisoformat(date.replace("Z", "+00:00"))
111
+ if date and isinstance(date, str)
112
+ else date
113
+ )
@@ -0,0 +1,139 @@
1
+ """
2
+ Parity Quantum Computing GmbH
3
+ Rennweg 1 Top 314
4
+ 6020 Innsbruck, Austria
5
+
6
+ Copyright (c) 2020-2022.
7
+ All rights reserved.
8
+
9
+ Tools to connect to the ParityOS cloud services.
10
+ """
11
+
12
+ from json.decoder import JSONDecodeError
13
+
14
+ from requests import Session, Response
15
+ from requests.adapters import HTTPAdapter
16
+ from requests.packages.urllib3.util.retry import Retry
17
+
18
+ from parityos.api_interface.authentication import generate_credentials
19
+ from parityos.api_interface.exceptions import ParityOSAuthError, ParityOSRequestError
20
+
21
+
22
+ DEFAULT_HOST = "api.parityqc.com"
23
+
24
+ # Define environment variables that can hold the credentials for the default host.
25
+ DEFAULT_ENVIRONMENT = dict(
26
+ username_variable="PARITYOS_USER",
27
+ password_variable="PARITYOS_PASS",
28
+ )
29
+ # Define the environment variables that can hold the credentials for alternative hosts.
30
+ ALTERNATIVE_ENVIRONMENT = dict(
31
+ username_variable="PARITYOS_ALTUSER",
32
+ password_variable="PARITYOS_ALTPASS",
33
+ )
34
+
35
+
36
+ class ClientBase:
37
+ """
38
+ Base class that sets up HTTP parameters (authentication, API endpoints, and so on).
39
+ It should not be used directly unless you are debugging HTTP requests,
40
+ use parityos.CompilerClient instead.
41
+ """
42
+
43
+ def __init__(
44
+ self,
45
+ username: str = None,
46
+ host: str = DEFAULT_HOST,
47
+ url_prefix: str = "v1",
48
+ http_retries: int = 3,
49
+ http_timeout: int = 10,
50
+ http_backoff_factor: float = 0.02,
51
+ intents: int = 3,
52
+ ):
53
+ """
54
+ :param str username: ParityOS id of the user.
55
+ :param str host: ParityAPI host name.
56
+ :param str url_prefix: Prefix to REST API paths, used mostly for versioning.
57
+ :param int http_retries: Number of http retries.
58
+ :param int http_timeout: Maximum time in seconds to wait for a http response.
59
+ :param int http_backoff_factor: Http exponential backoff factor.
60
+ :param int intents: Maximum number of intents with different passwords.
61
+ """
62
+ self.username = username
63
+ self.host = host
64
+ self.url_prefix = url_prefix
65
+ self.base_url = f"https://{self.host}/{self.url_prefix}"
66
+ self.http_timeout = http_timeout
67
+ self.http_retries = http_retries
68
+ self.http_backoff_factor = http_backoff_factor
69
+ self.intents = intents
70
+ self._setup_connection()
71
+
72
+ def _setup_connection(self):
73
+ """
74
+ Connects to the ParityAPI server, logs the user in and stores the session token.
75
+ """
76
+ # Credentials are instantiated here so that the password information
77
+ # is garbage collected as soon as this method terminates.
78
+ self.http = Session()
79
+ adapter = HTTPAdapter(
80
+ max_retries=Retry(total=self.http_retries, backoff_factor=self.http_backoff_factor)
81
+ )
82
+ self.http.mount("https://", adapter)
83
+ self.username, token = self._get_authentication()
84
+ # Only the username is stored in self so that the password information
85
+ # can be garbage collected.
86
+ self.http.headers.update({"Authorization": f"Token {token}"})
87
+
88
+ def _get_authentication(self) -> tuple[str, str]:
89
+ """
90
+ Log in on the server to obtain an authentication token for future requests.
91
+ """
92
+ # The credentials object allows for a number of intents to provide the password.
93
+ environment_variables = (
94
+ DEFAULT_ENVIRONMENT if self.host == DEFAULT_HOST else ALTERNATIVE_ENVIRONMENT
95
+ )
96
+ authentication_intents = generate_credentials(
97
+ self.username,
98
+ **environment_variables,
99
+ intents=self.intents,
100
+ )
101
+ username = self.username
102
+ for credentials_data in authentication_intents:
103
+ response = self.http.post(f"{self.base_url}/auth", data=credentials_data)
104
+ data = response.json()
105
+ username = credentials_data["username"]
106
+ if "token" in data:
107
+ return username, data["token"]
108
+
109
+ # No authentication intents left after failed logins
110
+ raise ParityOSAuthError(f"Failed login for user {username} on server {self.host}.")
111
+
112
+ def _send_request(self, method: str, url: str, data: dict = None) -> Response:
113
+ """
114
+ Send a http request
115
+
116
+ :param method: request method to use ('GET', 'POST', 'PUT', ... )
117
+ :param url: target url
118
+ :param data: payload data as a dictionary
119
+ :return: requests.Response object
120
+ """
121
+ try:
122
+ response = self.http.request(method, url=url, json=data, timeout=self.http_timeout)
123
+ except Exception as err:
124
+ message = f"Failed to receive valid response after at most {self.http_retries} retries."
125
+ err.args = (*err.args, message)
126
+ raise err
127
+
128
+ if response.ok:
129
+ return response
130
+ else:
131
+ try:
132
+ error_data = response.json()
133
+ except JSONDecodeError:
134
+ error_data = "None"
135
+
136
+ raise ParityOSRequestError(
137
+ f"{method} on {url}: {response.status_code}, {error_data}",
138
+ response=response,
139
+ )
@@ -0,0 +1,36 @@
1
+ """
2
+ Parity Quantum Computing GmbH
3
+ Rennweg 1 Top 314
4
+ 6020 Innsbruck, Austria
5
+
6
+ Copyright (c) 2020-2024.
7
+ All rights reserved.
8
+ """
9
+
10
+ from requests.exceptions import RequestException
11
+
12
+ from parityos.base.exceptions import ParityOSException
13
+
14
+
15
+ class ParityOSAuthError(RequestException, ValueError):
16
+ """
17
+ Exception for failed logins to the ParityAPI server.
18
+ """
19
+
20
+
21
+ class ParityOSRequestError(RequestException):
22
+ """
23
+ Exception for failed logins to the ParityAPI server.
24
+ """
25
+
26
+
27
+ class ParityOSCompilerError(ParityOSException):
28
+ """
29
+ Exception resulting from errors in the compiler on the ParityOS cloud server.
30
+ """
31
+
32
+
33
+ class ParityOSTimeoutException(ParityOSException):
34
+ """
35
+ Exception resulting from time-outs waiting for a response from the ParityOS cloud server.
36
+ """
@@ -0,0 +1,48 @@
1
+ """
2
+ Parity Quantum Computing GmbH
3
+ Rennweg 1 Top 314
4
+ 6020 Innsbruck, Austria
5
+
6
+ Copyright (c) 2020-2024.
7
+ All rights reserved.
8
+
9
+ Basic data structures to describe gates, circuits and optimization problems.
10
+ """
11
+
12
+ from .circuit import Circuit
13
+ from .constraints import ConfigurationType, EqualityConstraint, evaluate_parity, ParityConstraint
14
+ from .exceptions import ParityOSException, ParityOSImportError
15
+ from .gates import (
16
+ CCNOT,
17
+ CH,
18
+ CNOT,
19
+ CP,
20
+ CRx,
21
+ CRy,
22
+ CRz,
23
+ CY,
24
+ CZ,
25
+ DEFAULT_PARAMETER_NAME,
26
+ Gate,
27
+ H,
28
+ ISwap,
29
+ MultiControlledH,
30
+ MultiControlledRx,
31
+ MultiControlledRy,
32
+ MultiControlledRz,
33
+ Rx,
34
+ Ry,
35
+ Rz,
36
+ Rxx,
37
+ Ryy,
38
+ Rzz,
39
+ Rzzzz,
40
+ Swap,
41
+ SX,
42
+ X,
43
+ Y,
44
+ Z,
45
+ )
46
+ from .problem_representation import Hamiltonian, ProblemRepresentation
47
+ from .qubits import Qubit, QubitLabel
48
+ from .utils import json_wrap, dict_filter, JSONType, JSONMappingType, JSONLoadSaveMixin