qharm-eigenbridge 0.0.2__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.
@@ -0,0 +1,110 @@
1
+ # Copyright 2026 QHARM
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ ---
16
+ Language: Cpp
17
+ # BasedOnStyle: Mozilla
18
+ AccessModifierOffset: -4
19
+ AlignAfterOpenBracket: Align
20
+ AlignConsecutiveAssignments: true
21
+ AlignConsecutiveDeclarations: false
22
+ AlignEscapedNewlines: Left
23
+ AlignOperands: true
24
+ AlignTrailingComments: true
25
+ AllowAllParametersOfDeclarationOnNextLine: true
26
+ AllowShortBlocksOnASingleLine: true
27
+ AllowShortCaseLabelsOnASingleLine: true
28
+ AllowShortFunctionsOnASingleLine: All
29
+ AllowShortIfStatementsOnASingleLine: true
30
+ AllowShortLoopsOnASingleLine: true
31
+ AlwaysBreakAfterDefinitionReturnType: false
32
+ AlwaysBreakAfterReturnType: None
33
+ AlwaysBreakBeforeMultilineStrings: false
34
+ AlwaysBreakTemplateDeclarations: true
35
+ BinPackArguments: true
36
+ BinPackParameters: true
37
+ BraceWrapping:
38
+ AfterClass: false
39
+ AfterControlStatement: false
40
+ AfterEnum: false
41
+ AfterFunction: false
42
+ AfterNamespace: false
43
+ AfterObjCDeclaration: false
44
+ AfterStruct: false
45
+ AfterUnion: false
46
+ BeforeCatch: false
47
+ BeforeElse: false
48
+ IndentBraces: false
49
+ BreakAfterJavaFieldAnnotations: false
50
+ BreakBeforeBinaryOperators: None
51
+ BreakBeforeBraces: Custom
52
+ BreakBeforeInheritanceComma: false
53
+ BreakBeforeTernaryOperators: false
54
+ BreakConstructorInitializers: AfterColon
55
+ BreakStringLiterals: true
56
+ ColumnLimit: 80
57
+ CommentPragmas: '^ IWYU pragma:'
58
+ CompactNamespaces: false
59
+ ConstructorInitializerAllOnOneLineOrOnePerLine: true
60
+ ConstructorInitializerIndentWidth: 2
61
+ ContinuationIndentWidth: 2
62
+ Cpp11BracedListStyle: true
63
+ DerivePointerAlignment: false
64
+ DisableFormat: false
65
+ ExperimentalAutoDetectBinPacking: false
66
+ FixNamespaceComments: true
67
+ ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
68
+ IncludeCategories:
69
+ - Regex: '^"'
70
+ Priority: 1
71
+ - Regex: '^<'
72
+ Priority: 2
73
+ IncludeIsMainRegex: '(Test)$'
74
+ IndentCaseLabels: true
75
+ IndentWidth: 4
76
+ IndentWrappedFunctionNames: false
77
+ JavaScriptQuotes: Leave
78
+ JavaScriptWrapImports: true
79
+ KeepEmptyLinesAtTheStartOfBlocks: false
80
+ MacroBlockBegin: ''
81
+ MacroBlockEnd: ''
82
+ MaxEmptyLinesToKeep: 1
83
+ NamespaceIndentation: None
84
+ ObjCBlockIndentWidth: 4
85
+ ObjCSpaceAfterProperty: true
86
+ ObjCSpaceBeforeProtocolList: false
87
+ PenaltyBreakBeforeFirstCallParameter: 19
88
+ PenaltyBreakComment: 300
89
+ PenaltyBreakFirstLessLess: 120
90
+ PenaltyBreakString: 1000
91
+ PenaltyExcessCharacter: 1000000
92
+ PenaltyReturnTypeOnItsOwnLine: 200
93
+ PointerAlignment: Left
94
+ ReflowComments: true
95
+ SortIncludes: true
96
+ SpaceAfterCStyleCast: false
97
+ SpaceAfterTemplateKeyword: false
98
+ SpaceBeforeAssignmentOperators: true
99
+ SpaceBeforeParens: Never
100
+ SpaceInEmptyParentheses: false
101
+ SpacesBeforeTrailingComments: 1
102
+ SpacesInAngles: false
103
+ SpacesInCStyleCastParentheses: false
104
+ SpacesInContainerLiterals: false
105
+ SpacesInParentheses: false
106
+ SpacesInSquareBrackets: false
107
+ Standard: Cpp11
108
+ TabWidth: 8
109
+ UseTab: Never
110
+ ...
@@ -0,0 +1,25 @@
1
+ name: Merge Workflow
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+
8
+ jobs:
9
+ tag-commit:
10
+ uses: NWChemEx/.github/.github/workflows/tag.yaml@master
11
+ secrets: inherit
12
+
13
+ deploy_to_pypi:
14
+ needs: tag-commit
15
+ runs-on: ubuntu-latest
16
+ permissions:
17
+ id-token: write
18
+ steps:
19
+ - name: Build PyPI Distribution
20
+ uses: NWChemEx/.github/.github/actions/build_pypi_dist@master
21
+
22
+ - name: Publish to PyPI
23
+ uses: pypa/gh-action-pypi-publish@release/v1
24
+ with:
25
+ packages-dir: dist/
@@ -0,0 +1,50 @@
1
+ name: Pull Request Workflow
2
+
3
+ on:
4
+ pull_request:
5
+ branches:
6
+ - main
7
+
8
+ jobs:
9
+ # Build and test Python bindings.
10
+ test_python:
11
+ runs-on: ubuntu-24.04
12
+ steps:
13
+ - uses: actions/checkout@v5
14
+ with:
15
+ fetch-depth: 0
16
+ - name: Install LAPACK and LAPACKE
17
+ run: sudo apt-get install -y liblapacke-dev
18
+ shell: bash
19
+ - name: Setup Python
20
+ uses: actions/setup-python@v6
21
+ with:
22
+ python-version: "3.x"
23
+ - name: Build and Test
24
+ run: |
25
+ pip install .
26
+ cd tests/unit_tests
27
+ python -m unittest
28
+ shell: bash
29
+
30
+ test_pypi_deploy:
31
+ runs-on: ubuntu-latest
32
+ steps:
33
+ - name: Build PyPI Distribution
34
+ uses: NWChemEx/.github/.github/actions/build_pypi_dist@master
35
+
36
+ # Run pre-commit hooks
37
+ pre-commit:
38
+ runs-on: ubuntu-latest
39
+ steps:
40
+ - name: Checkout Source
41
+ uses: actions/checkout@v5
42
+ - name: Setup Python
43
+ uses: actions/setup-python@v6
44
+ with:
45
+ python-version: "3.x"
46
+ - name: Install and Run pre-commit
47
+ run: |
48
+ pip install pre-commit
49
+ pre-commit run --all-files
50
+ shell: bash
@@ -0,0 +1,82 @@
1
+ # Copyright 2026 QHARM
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ # These are directories used by IDEs for storing settings
16
+ .idea/
17
+ .vscode/
18
+ .cache/
19
+
20
+ # These are common build directory names
21
+ build*/
22
+ docs/build
23
+ docs/source/_build
24
+ docs/doxyoutput
25
+ docs/source/api
26
+ *-build-*/
27
+ _build/
28
+ Debug/
29
+ Release/
30
+
31
+ # Project automation
32
+ .tox/
33
+
34
+ # Users commonly store their specific CMake settings in a toolchain file
35
+ toolchain.cmake
36
+
37
+ # Users often install under the root directory
38
+ install/
39
+
40
+ # Per-project virtualenvs
41
+ *venv*/
42
+ .conda*/
43
+ .python-version
44
+
45
+ # Python distribution / packaging
46
+ .Python
47
+ build/
48
+ develop-eggs/
49
+ dist/
50
+ downloads/
51
+ eggs/
52
+ .eggs/
53
+ lib/
54
+ lib64/
55
+ parts/
56
+ sdist/
57
+ var/
58
+ wheels/
59
+ share/python-wheels/
60
+ *.egg-info/
61
+ .installed.cfg
62
+ *.egg
63
+ MANIFEST
64
+
65
+ # These are extensions commonly used to denote temporary files
66
+ *.tmp
67
+ *.autosave
68
+ *.bak
69
+ *~
70
+ *.py[cod]
71
+ *.so
72
+ *.cfg
73
+ !.isort.cfg
74
+ !setup.cfg
75
+ *.orig
76
+ *.log
77
+ *.pot
78
+ __pycache__/*
79
+ .cache/*
80
+ .*.swp
81
+ */.ipynb_checkpoints/*
82
+ .DS_Store
@@ -0,0 +1,26 @@
1
+ # Copyright 2026 QHARM
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ #
15
+ header:
16
+ license:
17
+ spdx-id: Apache-2.0
18
+ copyright-owner: QHARM
19
+
20
+ paths-ignore:
21
+ - .github/
22
+ - LICENSE
23
+ - build/
24
+ - venv/
25
+
26
+ comment: never
@@ -0,0 +1,68 @@
1
+ # Copyright 2026 QHARM
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ repos:
16
+ - repo: https://github.com/pre-commit/pre-commit-hooks
17
+ rev: v5.0.0
18
+ hooks:
19
+ - id: trailing-whitespace
20
+ - id: check-added-large-files
21
+ - id: check-ast
22
+ - id: check-json
23
+ - id: check-merge-conflict
24
+ - id: check-xml
25
+ - id: check-yaml
26
+ - id: debug-statements
27
+ - id: end-of-file-fixer
28
+ - id: requirements-txt-fixer
29
+ - id: mixed-line-ending
30
+ args: ["--fix=auto"]
31
+
32
+ - repo: https://github.com/psf/black
33
+ rev: 23.11.0
34
+ hooks:
35
+ - id: black
36
+ language_version: python3
37
+ args: ["--line-length=79"]
38
+
39
+ - repo: https://github.com/pycqa/isort
40
+ rev: 5.12.0
41
+ hooks:
42
+ - id: isort
43
+ args:
44
+ [
45
+ "--profile",
46
+ "black",
47
+ "--filter-files",
48
+ "--multi-line",
49
+ "3",
50
+ "--line-length",
51
+ "79",
52
+ ]
53
+
54
+ - repo: https://github.com/PyCQA/flake8
55
+ rev: 6.1.0
56
+ hooks:
57
+ - id: flake8
58
+ args: ["--max-line-length=88"]
59
+
60
+ - repo: local
61
+ hooks:
62
+ - id: license-eye
63
+ name: license-eye
64
+ additional_dependencies:
65
+ - github.com/apache/skywalking-eyes/cmd/license-eye@v0.4.0
66
+ entry: license-eye header fix --verbosity error
67
+ language: golang
68
+ pass_filenames: false
@@ -0,0 +1,177 @@
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
@@ -0,0 +1,55 @@
1
+ Metadata-Version: 2.4
2
+ Name: qharm-eigenbridge
3
+ Version: 0.0.2
4
+ Summary: Quantum eigensolver implementation using Qiskit
5
+ Author-email: Jonathan Waldrop <jwaldrop@ameslab.gov>, Mahir Anand <mahiranand@outlook.com>
6
+ Classifier: Development Status :: 4 - Beta
7
+ Classifier: Programming Language :: Python :: 3 :: Only
8
+ Classifier: Programming Language :: Python :: 3.9
9
+ Classifier: Programming Language :: Python :: 3.10
10
+ Classifier: Programming Language :: Python :: 3.11
11
+ Classifier: Programming Language :: Python :: 3.12
12
+ Classifier: Programming Language :: Python :: 3.13
13
+ Classifier: Programming Language :: Python :: 3.14
14
+ Requires-Python: >=3.9
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Requires-Dist: numpy
18
+ Requires-Dist: pybind11
19
+ Requires-Dist: qiskit
20
+ Requires-Dist: qiskit-algorithms
21
+ Requires-Dist: qiskit-aer
22
+ Requires-Dist: qiskit-ibm-runtime
23
+ Provides-Extra: dev
24
+ Requires-Dist: pre-commit; extra == "dev"
25
+ Requires-Dist: pytest; extra == "dev"
26
+ Dynamic: license-file
27
+
28
+ <!--
29
+ ~ Copyright 2026 QHARM
30
+ ~
31
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
32
+ ~ you may not use this file except in compliance with the License.
33
+ ~ You may obtain a copy of the License at
34
+ ~
35
+ ~ http://www.apache.org/licenses/LICENSE-2.0
36
+ ~
37
+ ~ Unless required by applicable law or agreed to in writing, software
38
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
39
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
40
+ ~ See the License for the specific language governing permissions and
41
+ ~ limitations under the License.
42
+ -->
43
+
44
+ # EigenBridge
45
+
46
+ There are two quantum solvers. VQD can return several eigenvalues; QAOA returns only the ground state.
47
+
48
+ VQD -> `run_vqd_eigensolver(matrix, k)` -> `solve_vqd` -> lowest `k` eigenvalues (`k` defaults to all)
49
+ QAOA -> `run_qaoa_eigensolver(matrix, use_noise=false)` -> `solve_qaoa` -> ground state only
50
+
51
+ **Uncertainties (`uq_values` / `uq_vectors`)**
52
+ - Noiseless solvers (LAPACK, VQD, noiseless QAOA): `uq_* = 0`
53
+ - Noisy QAOA (`use_noise=true`): at the final circuit, `uq_values[0] = |E_noisy − E_exact|`; Unused slots and `uq_vectors` stay 0
54
+
55
+ The noisy QAOA unit test checks that `uq_values[0] = |E_noisy − E_exact|` (at the final circuit) and `|λ_noisy − λ_LAPACK|` agree within a factor of 10 (ratio < 10).
@@ -0,0 +1,28 @@
1
+ <!--
2
+ ~ Copyright 2026 QHARM
3
+ ~
4
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
5
+ ~ you may not use this file except in compliance with the License.
6
+ ~ You may obtain a copy of the License at
7
+ ~
8
+ ~ http://www.apache.org/licenses/LICENSE-2.0
9
+ ~
10
+ ~ Unless required by applicable law or agreed to in writing, software
11
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
12
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ ~ See the License for the specific language governing permissions and
14
+ ~ limitations under the License.
15
+ -->
16
+
17
+ # EigenBridge
18
+
19
+ There are two quantum solvers. VQD can return several eigenvalues; QAOA returns only the ground state.
20
+
21
+ VQD -> `run_vqd_eigensolver(matrix, k)` -> `solve_vqd` -> lowest `k` eigenvalues (`k` defaults to all)
22
+ QAOA -> `run_qaoa_eigensolver(matrix, use_noise=false)` -> `solve_qaoa` -> ground state only
23
+
24
+ **Uncertainties (`uq_values` / `uq_vectors`)**
25
+ - Noiseless solvers (LAPACK, VQD, noiseless QAOA): `uq_* = 0`
26
+ - Noisy QAOA (`use_noise=true`): at the final circuit, `uq_values[0] = |E_noisy − E_exact|`; Unused slots and `uq_vectors` stay 0
27
+
28
+ The noisy QAOA unit test checks that `uq_values[0] = |E_noisy − E_exact|` (at the final circuit) and `|λ_noisy − λ_LAPACK|` agree within a factor of 10 (ratio < 10).
@@ -0,0 +1,63 @@
1
+ # Copyright 2026 QHARM
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ [build-system]
16
+ requires = ["setuptools>=64", "setuptools-scm>=8"]
17
+ build-backend = "setuptools.build_meta"
18
+
19
+
20
+ [project]
21
+ name = "qharm-eigenbridge"
22
+ authors = [
23
+ { name = "Jonathan Waldrop", email = "jwaldrop@ameslab.gov" },
24
+ { name = "Mahir Anand", email = "mahiranand@outlook.com" },
25
+ ]
26
+ description = "Quantum eigensolver implementation using Qiskit"
27
+ readme = "README.md"
28
+ requires-python = ">=3.9"
29
+ classifiers = [
30
+ "Development Status :: 4 - Beta",
31
+ "Programming Language :: Python :: 3 :: Only",
32
+ "Programming Language :: Python :: 3.9",
33
+ "Programming Language :: Python :: 3.10",
34
+ "Programming Language :: Python :: 3.11",
35
+ "Programming Language :: Python :: 3.12",
36
+ "Programming Language :: Python :: 3.13",
37
+ "Programming Language :: Python :: 3.14",
38
+ ]
39
+ dynamic = ["version"]
40
+ dependencies = [
41
+ "numpy",
42
+ "pybind11",
43
+ "qiskit",
44
+ "qiskit-algorithms",
45
+ "qiskit-aer",
46
+ "qiskit-ibm-runtime",
47
+ ]
48
+
49
+ [project.optional-dependencies]
50
+ dev = ["pre-commit", "pytest"]
51
+
52
+ [tool.setuptools.packages.find]
53
+ where = ["python"]
54
+
55
+ [tool.setuptools_scm]
56
+ fallback_version = "0.0.0"
57
+
58
+ [tool.pytest.ini_options]
59
+ minversion = "6.0"
60
+ addopts = "-ra -q -p no:warnings" # Silencing warnings b/c Qiskit
61
+ testpaths = [
62
+ "tests",
63
+ ]
@@ -0,0 +1,18 @@
1
+ # Copyright 2026 QHARM
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ from .quantum_solvers import ( # noqa: F401
16
+ run_qaoa_eigensolver,
17
+ run_vqd_eigensolver,
18
+ )
@@ -0,0 +1,270 @@
1
+ # Copyright 2026 QHARM
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ import numpy as np
16
+ from qiskit import QuantumCircuit
17
+ from qiskit.circuit.library import EfficientSU2, QAOAAnsatz
18
+ from qiskit.primitives import StatevectorEstimator
19
+ from qiskit.quantum_info import SparsePauliOp, Statevector
20
+ from qiskit_algorithms import VQD
21
+ from qiskit_algorithms.algorithm_job import AlgorithmJob
22
+ from qiskit_algorithms.minimum_eigensolvers import VQE
23
+ from qiskit_algorithms.optimizers import COBYLA, SLSQP
24
+ from qiskit_algorithms.state_fidelities import (
25
+ BaseStateFidelity,
26
+ StateFidelityResult,
27
+ )
28
+
29
+
30
+ class _ExactStatevectorFidelity(BaseStateFidelity):
31
+ def create_fidelity_circuit(self, circuit_1, circuit_2):
32
+ return circuit_1.copy()
33
+
34
+ def _run(
35
+ self,
36
+ circuits_1,
37
+ circuits_2,
38
+ values_1=None,
39
+ values_2=None,
40
+ *,
41
+ shots=None,
42
+ ):
43
+ if isinstance(circuits_1, QuantumCircuit):
44
+ circuits_1 = [circuits_1]
45
+ if isinstance(circuits_2, QuantumCircuit):
46
+ circuits_2 = [circuits_2]
47
+ values_1 = self._preprocess_values(circuits_1, values_1)
48
+ values_2 = self._preprocess_values(circuits_2, values_2)
49
+ # _preprocess_values returns a single empty row when values is None
50
+ if len(values_1) == 1 and len(circuits_1) > 1:
51
+ values_1 = list(values_1) * len(circuits_1)
52
+ if len(values_2) == 1 and len(circuits_2) > 1:
53
+ values_2 = list(values_2) * len(circuits_2)
54
+
55
+ def _call():
56
+ fidelities = []
57
+ for circuit_1, circuit_2, val_1, val_2 in zip(
58
+ circuits_1, circuits_2, values_1, values_2
59
+ ):
60
+ bound_1 = (
61
+ circuit_1.assign_parameters(val_1) if val_1 else circuit_1
62
+ )
63
+ bound_2 = (
64
+ circuit_2.assign_parameters(val_2) if val_2 else circuit_2
65
+ )
66
+ overlap = Statevector(bound_1).inner(Statevector(bound_2))
67
+ fidelities.append(float(np.abs(overlap) ** 2))
68
+ return StateFidelityResult(
69
+ fidelities=fidelities,
70
+ raw_fidelities=fidelities,
71
+ metadata=[{} for _ in fidelities],
72
+ shots=0,
73
+ )
74
+
75
+ return AlgorithmJob(_call)
76
+
77
+
78
+ def _statevector_to_real_eigenvector(circuit, parameters, n):
79
+ # Turn the VQD circuit into a real unit vector of length n.
80
+ bound = circuit.assign_parameters(parameters)
81
+ vec = np.asarray(Statevector(bound).data[:n], dtype=complex)
82
+ idx = int(np.argmax(np.abs(vec)))
83
+ peak = vec[idx]
84
+ if np.abs(peak) > 0:
85
+ vec = vec * np.conj(peak) / np.abs(peak)
86
+ vec = np.real(vec)
87
+ if vec[idx] < 0:
88
+ vec = -vec
89
+ norm = np.linalg.norm(vec)
90
+ if norm > 0:
91
+ vec = vec / norm
92
+ return vec
93
+
94
+
95
+ def _matrix_to_observable(flat_matrix, n):
96
+ # Reshape into an n x n NumPy array and pad to the next power of two.
97
+ mat = np.array(flat_matrix, dtype=float).reshape((n, n))
98
+ next_pow2 = 1 << (n - 1).bit_length()
99
+ if next_pow2 != n:
100
+ padded_mat = np.zeros((next_pow2, next_pow2))
101
+ padded_mat[:n, :n] = mat
102
+ penalty = 10.0 * max(1.0, float(np.max(np.abs(mat))))
103
+ for i in range(n, next_pow2):
104
+ padded_mat[i, i] = penalty
105
+ mat = padded_mat
106
+ return SparsePauliOp.from_operator(mat), next_pow2
107
+
108
+
109
+ def _make_estimator(use_noise):
110
+ if not use_noise:
111
+ return StatevectorEstimator(), None
112
+ try:
113
+ from qiskit.transpiler.preset_passmanagers import (
114
+ generate_preset_pass_manager,
115
+ )
116
+ from qiskit_aer import AerSimulator
117
+ from qiskit_aer.noise import NoiseModel
118
+ from qiskit_aer.primitives import EstimatorV2 as AerEstimatorV2
119
+ from qiskit_ibm_runtime.fake_provider import FakeManilaV2
120
+ except ImportError as exc:
121
+ raise ImportError(
122
+ "Noisy QAOA requires qiskit-aer and qiskit-ibm-runtime. "
123
+ "Install with: pip install qiskit-aer qiskit-ibm-runtime"
124
+ ) from exc
125
+
126
+ fake_backend = FakeManilaV2()
127
+ noise_model = NoiseModel.from_backend(fake_backend, warnings=False)
128
+ aer_simulator = AerSimulator(noise_model=noise_model)
129
+ pass_manager = generate_preset_pass_manager(
130
+ optimization_level=1, backend=aer_simulator
131
+ )
132
+
133
+ estimator = AerEstimatorV2(
134
+ options={"backend_options": {"noise_model": noise_model}}
135
+ )
136
+ return estimator, pass_manager
137
+
138
+
139
+ def _expect_energy(estimator, circuit, observable, parameters):
140
+ op = observable
141
+ if getattr(circuit, "layout", None) is not None:
142
+ op = observable.apply_layout(circuit.layout)
143
+ evs = np.asarray(
144
+ estimator.run([(circuit, op, parameters)]).result()[0].data.evs,
145
+ dtype=float,
146
+ ).reshape(-1)
147
+ return float(np.real(evs[0]))
148
+
149
+
150
+ def _energy_diff_uncertainty(circuit, parameters, observable, noisy_estimator):
151
+ exact_energy = _expect_energy(
152
+ StatevectorEstimator(), circuit, observable, parameters
153
+ )
154
+ noisy_energy = _expect_energy(
155
+ noisy_estimator, circuit, observable, parameters
156
+ )
157
+ # Predicted noise = |E_noisy - E_exact| on the final circuit
158
+ return abs(noisy_energy - exact_energy)
159
+
160
+
161
+ def run_vqd_eigensolver(flat_matrix, n, k=None):
162
+ """
163
+ Takes a flat matrix of size n*n, and returns the lowest k eigenvalues
164
+ and matching eigenvectors using VQD.
165
+ """
166
+ if k is None:
167
+ k = n
168
+ if k < 1 or k > n:
169
+ raise ValueError(f"k must satisfy 1 <= k <= n, got k={k}, n={n}")
170
+
171
+ observable, next_pow2 = _matrix_to_observable(flat_matrix, n)
172
+ num_qubits = int(np.log2(next_pow2))
173
+
174
+ ansatz = EfficientSU2(num_qubits, reps=1, entanglement="linear")
175
+ optimizer = SLSQP(maxiter=1000, ftol=1e-9)
176
+ estimator = StatevectorEstimator()
177
+ fidelity = _ExactStatevectorFidelity()
178
+
179
+ # Overlap weights on the scale of the original matrix, not the padding.
180
+ beta = 10.0 * max(
181
+ 1.0, float(np.max(np.abs(np.array(flat_matrix, dtype=float))))
182
+ )
183
+ betas = np.full(k, beta)
184
+ rng = np.random.default_rng(0)
185
+ if k == 1:
186
+ initial_points = np.zeros(ansatz.num_parameters)
187
+ else:
188
+ initial_points = [np.zeros(ansatz.num_parameters)]
189
+ for _ in range(k - 1):
190
+ initial_points.append(
191
+ rng.uniform(-np.pi, np.pi, ansatz.num_parameters)
192
+ )
193
+
194
+ vqd = VQD(estimator, fidelity, ansatz, optimizer, k=k, betas=betas)
195
+ vqd.initial_point = initial_points
196
+
197
+ result = vqd.compute_eigenvalues(observable)
198
+
199
+ eigenvalues = [float(np.real(e)) for e in result.eigenvalues]
200
+ eigenvectors = np.zeros((n, n), dtype=float)
201
+ for i in range(k):
202
+ eigenvectors[:, i] = _statevector_to_real_eigenvector(
203
+ result.optimal_circuits[i], result.optimal_points[i], n
204
+ )
205
+ uq_values = [0.0] * len(eigenvalues)
206
+ uq_vectors = [0.0] * (n * n)
207
+
208
+ return eigenvalues, eigenvectors.ravel().tolist(), uq_values, uq_vectors
209
+
210
+
211
+ def run_qaoa_eigensolver(flat_matrix, n, use_noise=False, reps=3):
212
+ """
213
+ Takes a flat matrix of size n*n, and returns the ground eigenvalue,
214
+ and matching eigenvector using QAOA.
215
+ """
216
+ observable, _ = _matrix_to_observable(flat_matrix, n)
217
+ ansatz = QAOAAnsatz(observable, reps=reps)
218
+ estimator, pass_manager = _make_estimator(use_noise)
219
+ if use_noise:
220
+ optimizer = COBYLA(maxiter=50)
221
+ vqe = VQE(estimator, ansatz, optimizer, transpiler=pass_manager)
222
+ else:
223
+ optimizer = SLSQP(maxiter=1000, ftol=1e-9)
224
+ vqe = VQE(estimator, ansatz, optimizer)
225
+ rng = np.random.default_rng(2)
226
+ vqe.initial_point = rng.uniform(0, np.pi, ansatz.num_parameters)
227
+
228
+ result = vqe.compute_minimum_eigenvalue(observable)
229
+
230
+ eigenvalues = [float(np.real(result.eigenvalue))]
231
+ eigenvectors = np.zeros((n, n), dtype=float)
232
+ eigenvectors[:, 0] = _statevector_to_real_eigenvector(
233
+ result.optimal_circuit, result.optimal_point, n
234
+ )
235
+
236
+ uq_values = [0.0] * len(eigenvalues)
237
+ uq_vectors = [0.0] * (n * n)
238
+ if use_noise:
239
+ uq_values[0] = _energy_diff_uncertainty(
240
+ result.optimal_circuit, result.optimal_point, observable, estimator
241
+ )
242
+
243
+ return eigenvalues, eigenvectors.ravel().tolist(), uq_values, uq_vectors
244
+
245
+
246
+ # Quick Test
247
+ if __name__ == "__main__":
248
+ # The same 3x3 matrix from the C++ test file
249
+ test_matrix = [3.0, 5.0, 2.0, 5.0, 1.0, 3.0, 2.0, 3.0, 2.0]
250
+ values, vectors = run_vqd_eigensolver(test_matrix, 3)
251
+ print(f"VQD Eigenvalues: {values}")
252
+ print(f"VQD Eigenvectors: {vectors}")
253
+ qaoa_values, qaoa_vectors, qaoa_uq_v, qaoa_uq_vec = run_qaoa_eigensolver(
254
+ test_matrix, 3
255
+ )
256
+ print(f"QAOA Eigenvalue: {qaoa_values}")
257
+ print(f"QAOA Eigenvector: {qaoa_vectors}")
258
+ print(f"QAOA uq_values: {qaoa_uq_v}")
259
+ try:
260
+ (
261
+ qaoa_noisy_values,
262
+ qaoa_noisy_vectors,
263
+ noisy_uq_v,
264
+ noisy_uq_vec,
265
+ ) = run_qaoa_eigensolver(test_matrix, 3, use_noise=True)
266
+ print(f"QAOA Eigenvalue (noise): {qaoa_noisy_values}")
267
+ print(f"QAOA Eigenvector (noise): {qaoa_noisy_vectors}")
268
+ print(f"QAOA uq_values (noise): {noisy_uq_v}")
269
+ except ImportError as exc:
270
+ print(f"Skipping noisy QAOA demo: {exc}")
@@ -0,0 +1,55 @@
1
+ Metadata-Version: 2.4
2
+ Name: qharm-eigenbridge
3
+ Version: 0.0.2
4
+ Summary: Quantum eigensolver implementation using Qiskit
5
+ Author-email: Jonathan Waldrop <jwaldrop@ameslab.gov>, Mahir Anand <mahiranand@outlook.com>
6
+ Classifier: Development Status :: 4 - Beta
7
+ Classifier: Programming Language :: Python :: 3 :: Only
8
+ Classifier: Programming Language :: Python :: 3.9
9
+ Classifier: Programming Language :: Python :: 3.10
10
+ Classifier: Programming Language :: Python :: 3.11
11
+ Classifier: Programming Language :: Python :: 3.12
12
+ Classifier: Programming Language :: Python :: 3.13
13
+ Classifier: Programming Language :: Python :: 3.14
14
+ Requires-Python: >=3.9
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Requires-Dist: numpy
18
+ Requires-Dist: pybind11
19
+ Requires-Dist: qiskit
20
+ Requires-Dist: qiskit-algorithms
21
+ Requires-Dist: qiskit-aer
22
+ Requires-Dist: qiskit-ibm-runtime
23
+ Provides-Extra: dev
24
+ Requires-Dist: pre-commit; extra == "dev"
25
+ Requires-Dist: pytest; extra == "dev"
26
+ Dynamic: license-file
27
+
28
+ <!--
29
+ ~ Copyright 2026 QHARM
30
+ ~
31
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
32
+ ~ you may not use this file except in compliance with the License.
33
+ ~ You may obtain a copy of the License at
34
+ ~
35
+ ~ http://www.apache.org/licenses/LICENSE-2.0
36
+ ~
37
+ ~ Unless required by applicable law or agreed to in writing, software
38
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
39
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
40
+ ~ See the License for the specific language governing permissions and
41
+ ~ limitations under the License.
42
+ -->
43
+
44
+ # EigenBridge
45
+
46
+ There are two quantum solvers. VQD can return several eigenvalues; QAOA returns only the ground state.
47
+
48
+ VQD -> `run_vqd_eigensolver(matrix, k)` -> `solve_vqd` -> lowest `k` eigenvalues (`k` defaults to all)
49
+ QAOA -> `run_qaoa_eigensolver(matrix, use_noise=false)` -> `solve_qaoa` -> ground state only
50
+
51
+ **Uncertainties (`uq_values` / `uq_vectors`)**
52
+ - Noiseless solvers (LAPACK, VQD, noiseless QAOA): `uq_* = 0`
53
+ - Noisy QAOA (`use_noise=true`): at the final circuit, `uq_values[0] = |E_noisy − E_exact|`; Unused slots and `uq_vectors` stay 0
54
+
55
+ The noisy QAOA unit test checks that `uq_values[0] = |E_noisy − E_exact|` (at the final circuit) and `|λ_noisy − λ_LAPACK|` agree within a factor of 10 (ratio < 10).
@@ -0,0 +1,19 @@
1
+ .clang-format
2
+ .gitignore
3
+ .licenserc.yaml
4
+ .pre-commit-config.yaml
5
+ LICENSE
6
+ README.md
7
+ pyproject.toml
8
+ .github/workflows/merge.yaml
9
+ .github/workflows/pull_request.yaml
10
+ python/eigenbridge/__init__.py
11
+ python/eigenbridge/quantum_solvers.py
12
+ python/qharm_eigenbridge.egg-info/PKG-INFO
13
+ python/qharm_eigenbridge.egg-info/SOURCES.txt
14
+ python/qharm_eigenbridge.egg-info/dependency_links.txt
15
+ python/qharm_eigenbridge.egg-info/requires.txt
16
+ python/qharm_eigenbridge.egg-info/scm_file_list.json
17
+ python/qharm_eigenbridge.egg-info/scm_version.json
18
+ python/qharm_eigenbridge.egg-info/top_level.txt
19
+ tests/unit_tests/test_eigensolvers.py
@@ -0,0 +1,10 @@
1
+ numpy
2
+ pybind11
3
+ qiskit
4
+ qiskit-algorithms
5
+ qiskit-aer
6
+ qiskit-ibm-runtime
7
+
8
+ [dev]
9
+ pre-commit
10
+ pytest
@@ -0,0 +1,16 @@
1
+ {
2
+ "files": [
3
+ ".clang-format",
4
+ ".github/workflows/merge.yaml",
5
+ ".github/workflows/pull_request.yaml",
6
+ ".gitignore",
7
+ ".licenserc.yaml",
8
+ ".pre-commit-config.yaml",
9
+ "LICENSE",
10
+ "README.md",
11
+ "pyproject.toml",
12
+ "python/eigenbridge/__init__.py",
13
+ "python/eigenbridge/quantum_solvers.py",
14
+ "tests/unit_tests/test_eigensolvers.py"
15
+ ]
16
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "tag": "0.0.2",
3
+ "distance": 0,
4
+ "node": "g4e9a0a279e66d7ca617ba5c9e3270f3580a2e3f0",
5
+ "dirty": false,
6
+ "branch": "main",
7
+ "node_date": "2026-09-01"
8
+ }
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,82 @@
1
+ # Copyright 2026 QHARM
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ import unittest
16
+
17
+ import eigenbridge
18
+
19
+
20
+ class TestEigensolvers(unittest.TestCase):
21
+ def setUp(self):
22
+ # Define a 3x3 matrix
23
+ self.flat_matrix = [3.0, 5.0, 2.0, 5.0, 1.0, 3.0, 2.0, 3.0, 2.0]
24
+ # Correct results
25
+ self.correct_eigenvalues = [
26
+ -3.3610452994996525,
27
+ 0.5038738768058354,
28
+ 8.8571714226938152,
29
+ ]
30
+ self.correct_eigenvectors = [
31
+ -0.5518254419285664,
32
+ -0.5057445690691208,
33
+ -0.6631071651682192,
34
+ 0.7984036023978691,
35
+ -0.0906811731252565,
36
+ -0.5952550818924042,
37
+ -0.2409156892326610,
38
+ 0.8579040480716453,
39
+ -0.4538284642723896,
40
+ ]
41
+
42
+ def _check_results(
43
+ self,
44
+ results,
45
+ val_places=14,
46
+ vec_places=14,
47
+ uq_val=1e-16,
48
+ uq_vec=1e-16,
49
+ ):
50
+ # Check the results
51
+ eigenvalues, eigenvectors, uq_values, uq_vectors = results
52
+ for i in zip(eigenvalues, self.correct_eigenvalues):
53
+ self.assertAlmostEqual(i[0], i[1], places=val_places)
54
+ for i in zip(eigenvectors, self.correct_eigenvectors):
55
+ self.assertAlmostEqual(abs(i[0]), abs(i[1]), places=vec_places)
56
+ for i in uq_values:
57
+ self.assertEqual(i, uq_val)
58
+ for i in uq_vectors:
59
+ self.assertEqual(i, uq_vec)
60
+
61
+ def test_vqd_eigensolver(self):
62
+ results = eigenbridge.run_vqd_eigensolver(self.flat_matrix, n=3)
63
+ self._check_results(
64
+ results, val_places=8, vec_places=4, uq_val=0.0, uq_vec=0.0
65
+ )
66
+
67
+ def test_qaoa_eigensolver(self):
68
+ # Adjust the correct eigenvalues and eigenvectors for QAOA's output
69
+ # The QAOA solver will not return all eigenvalues/eigenvectors, so we
70
+ # zero out the ones that are not expected to be returned.
71
+ for i in range(len(self.correct_eigenvalues)):
72
+ if i % 3 != 0:
73
+ self.correct_eigenvalues[i] = 0.0
74
+ for i in range(len(self.correct_eigenvectors)):
75
+ if i % 3 != 0:
76
+ self.correct_eigenvectors[i] = 0.0
77
+ results = eigenbridge.run_qaoa_eigensolver(
78
+ self.flat_matrix, n=3, use_noise=False
79
+ )
80
+ self._check_results(
81
+ results, val_places=8, vec_places=4, uq_val=0.0, uq_vec=0.0
82
+ )