cqlib-vqe 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.
- cqlib_vqe-0.1.0/LICENSE +201 -0
- cqlib_vqe-0.1.0/MANIFEST.in +8 -0
- cqlib_vqe-0.1.0/PKG-INFO +347 -0
- cqlib_vqe-0.1.0/README.md +305 -0
- cqlib_vqe-0.1.0/README.zh-CN.md +250 -0
- cqlib_vqe-0.1.0/benchmarks/README.md +73 -0
- cqlib_vqe-0.1.0/benchmarks/run_cqlib_benchmark.py +1235 -0
- cqlib_vqe-0.1.0/cqlib_vqe/__init__.py +97 -0
- cqlib_vqe-0.1.0/cqlib_vqe/chemistry/__init__.py +47 -0
- cqlib_vqe-0.1.0/cqlib_vqe/chemistry/active_space.py +398 -0
- cqlib_vqe-0.1.0/cqlib_vqe/chemistry/mapping.py +187 -0
- cqlib_vqe-0.1.0/cqlib_vqe/chemistry/molecule.py +440 -0
- cqlib_vqe-0.1.0/cqlib_vqe/chemistry/uccsd.py +214 -0
- cqlib_vqe-0.1.0/cqlib_vqe/chemistry/uccsd_amplitudes.py +106 -0
- cqlib_vqe-0.1.0/cqlib_vqe/optim/__init__.py +34 -0
- cqlib_vqe-0.1.0/cqlib_vqe/optim/optim.py +619 -0
- cqlib_vqe-0.1.0/cqlib_vqe/utils/__init__.py +16 -0
- cqlib_vqe-0.1.0/cqlib_vqe/utils/profiler.py +55 -0
- cqlib_vqe-0.1.0/cqlib_vqe/vqe/__init__.py +65 -0
- cqlib_vqe-0.1.0/cqlib_vqe/vqe/adaptive.py +644 -0
- cqlib_vqe-0.1.0/cqlib_vqe/vqe/estimator.py +358 -0
- cqlib_vqe-0.1.0/cqlib_vqe/vqe/factory.py +543 -0
- cqlib_vqe-0.1.0/cqlib_vqe/vqe/hamiltonian.py +130 -0
- cqlib_vqe-0.1.0/cqlib_vqe/vqe/solver.py +296 -0
- cqlib_vqe-0.1.0/cqlib_vqe/vqe/tianyan.py +769 -0
- cqlib_vqe-0.1.0/cqlib_vqe.egg-info/PKG-INFO +347 -0
- cqlib_vqe-0.1.0/cqlib_vqe.egg-info/SOURCES.txt +59 -0
- cqlib_vqe-0.1.0/cqlib_vqe.egg-info/dependency_links.txt +1 -0
- cqlib_vqe-0.1.0/cqlib_vqe.egg-info/requires.txt +25 -0
- cqlib_vqe-0.1.0/cqlib_vqe.egg-info/top_level.txt +1 -0
- cqlib_vqe-0.1.0/examples/benchmark_execution_modes.py +100 -0
- cqlib_vqe-0.1.0/examples/h2_vqe_cqlib2.py +58 -0
- cqlib_vqe-0.1.0/examples/h2_vqe_tianyan.py +108 -0
- cqlib_vqe-0.1.0/examples/minimal_compiled_smoke.py +33 -0
- cqlib_vqe-0.1.0/examples/run_five_adaptive_full_pool.py +680 -0
- cqlib_vqe-0.1.0/examples/run_local_accuracy.py +297 -0
- cqlib_vqe-0.1.0/examples/tianyan_grouped_energy_smoke.py +76 -0
- cqlib_vqe-0.1.0/examples/tianyan_pauli_strict_probe.py +116 -0
- cqlib_vqe-0.1.0/examples/tianyan_qwc_compare.py +132 -0
- cqlib_vqe-0.1.0/pyproject.toml +71 -0
- cqlib_vqe-0.1.0/setup.cfg +4 -0
- cqlib_vqe-0.1.0/tests/conftest.py +278 -0
- cqlib_vqe-0.1.0/tests/test_active_space_and_canonical_ucc.py +198 -0
- cqlib_vqe-0.1.0/tests/test_adaptive_full_pool.py +286 -0
- cqlib_vqe-0.1.0/tests/test_api_check_tool.py +19 -0
- cqlib_vqe-0.1.0/tests/test_cqlib2_adapter.py +232 -0
- cqlib_vqe-0.1.0/tests/test_estimator_cache.py +52 -0
- cqlib_vqe-0.1.0/tests/test_mapper_consistency.py +112 -0
- cqlib_vqe-0.1.0/tests/test_optimizer_regressions.py +250 -0
- cqlib_vqe-0.1.0/tests/test_public_api.py +33 -0
- cqlib_vqe-0.1.0/tests/test_qwc.py +24 -0
- cqlib_vqe-0.1.0/tests/test_tianyan.py +322 -0
- cqlib_vqe-0.1.0/tools/benchmark_native_pauli_rotation.py +126 -0
- cqlib_vqe-0.1.0/tools/check_cqlib2_api.py +86 -0
- cqlib_vqe-0.1.0/tools/check_source_sync.py +57 -0
- cqlib_vqe-0.1.0/tools/check_tianyan_api.py +109 -0
- cqlib_vqe-0.1.0/tools/diagnose_initial_point.py +118 -0
- cqlib_vqe-0.1.0/tools/diagnose_zero_amplitude_pool.py +133 -0
- cqlib_vqe-0.1.0/tools/tianyan_raw_result_probe.py +125 -0
- cqlib_vqe-0.1.0/tools/validate_chemistry_correctness.py +111 -0
- cqlib_vqe-0.1.0/tools/verify_native_pauli_rotation.py +94 -0
cqlib_vqe-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 China Telecom Quantum Group
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
cqlib_vqe-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: cqlib-vqe
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Adaptive canonical singlet-UCCSD and active-space VQE for cqlib 2.x
|
|
5
|
+
Author: Cqlib VQE Contributors
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Keywords: quantum computing,variational quantum eigensolver,VQE,UCCSD,quantum chemistry,cqlib
|
|
8
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
16
|
+
Classifier: Topic :: Scientific/Engineering
|
|
17
|
+
Classifier: Topic :: Scientific/Engineering :: Chemistry
|
|
18
|
+
Requires-Python: >=3.11
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Requires-Dist: numpy>=2.1
|
|
22
|
+
Requires-Dist: scipy>=1.11
|
|
23
|
+
Requires-Dist: cqlib>=2.0.0
|
|
24
|
+
Provides-Extra: chemistry
|
|
25
|
+
Requires-Dist: openfermion>=1.6; extra == "chemistry"
|
|
26
|
+
Requires-Dist: openfermionpyscf>=0.5; extra == "chemistry"
|
|
27
|
+
Requires-Dist: pyscf>=2.6; extra == "chemistry"
|
|
28
|
+
Provides-Extra: tianyan
|
|
29
|
+
Requires-Dist: cqlib-tianyan>=0.1.0; extra == "tianyan"
|
|
30
|
+
Provides-Extra: test
|
|
31
|
+
Requires-Dist: pytest>=8; extra == "test"
|
|
32
|
+
Provides-Extra: dev
|
|
33
|
+
Requires-Dist: build>=1.2; extra == "dev"
|
|
34
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
35
|
+
Requires-Dist: ruff>=0.6; extra == "dev"
|
|
36
|
+
Provides-Extra: all
|
|
37
|
+
Requires-Dist: openfermion>=1.6; extra == "all"
|
|
38
|
+
Requires-Dist: openfermionpyscf>=0.5; extra == "all"
|
|
39
|
+
Requires-Dist: pyscf>=2.6; extra == "all"
|
|
40
|
+
Requires-Dist: cqlib-tianyan>=0.1.0; extra == "all"
|
|
41
|
+
Dynamic: license-file
|
|
42
|
+
|
|
43
|
+
# cqlib-vqe
|
|
44
|
+
|
|
45
|
+
[简体中文](README.zh-CN.md)
|
|
46
|
+
|
|
47
|
+
`cqlib-vqe` is a VQE package for molecular electronic-structure calculations on
|
|
48
|
+
cqlib 2.x. It provides molecular-Hamiltonian preparation, canonical
|
|
49
|
+
singlet-UCCSD ansätze, Jordan-Wigner (JW), Bravyi-Kitaev (BK), and parity
|
|
50
|
+
encodings, adaptive operator-pool selection, local statevector execution, and
|
|
51
|
+
Tianyan cloud/hardware measurement support.
|
|
52
|
+
|
|
53
|
+
The primary public import is `cqlib_vqe`.
|
|
54
|
+
|
|
55
|
+
## What the package provides
|
|
56
|
+
|
|
57
|
+
- Molecular preprocessing through PySCF and OpenFermion, including a
|
|
58
|
+
reproducible active-space report and Pauli Hamiltonian.
|
|
59
|
+
- Canonical singlet-UCCSD generators with a stable packed-parameter ordering.
|
|
60
|
+
- Consistent JW, BK, and parity treatment of the Hamiltonian, excitation
|
|
61
|
+
generators, and Hartree-Fock reference state.
|
|
62
|
+
- `DirectStatevectorEstimator` for local high-throughput VQE objectives and
|
|
63
|
+
`NativeStatevectorEstimator` for circuit/statevector expectation values.
|
|
64
|
+
- Complete-pool adaptive selected-UCCSD: a zero CCSD initial amplitude does
|
|
65
|
+
not remove an operator from the candidate pool.
|
|
66
|
+
- QWC-grouped Tianyan measurement plans and strict validation of submitted-task
|
|
67
|
+
and result-qubit metadata.
|
|
68
|
+
|
|
69
|
+
## Installation
|
|
70
|
+
|
|
71
|
+
Python 3.11 or newer is required. Install directly from PyPI:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
# Local VQE from a precompiled ansatz.
|
|
75
|
+
python -m pip install cqlib-vqe
|
|
76
|
+
|
|
77
|
+
# Molecular Hamiltonian and UCCSD preprocessing.
|
|
78
|
+
python -m pip install "cqlib-vqe[chemistry]"
|
|
79
|
+
|
|
80
|
+
# Tianyan execution in addition to molecular preprocessing.
|
|
81
|
+
python -m pip install "cqlib-vqe[chemistry,tianyan]"
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Or clone the repository and install from source in an isolated environment:
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
git clone https://github.com/cq-lib/cqlib-vqe.git
|
|
88
|
+
cd cqlib-vqe
|
|
89
|
+
|
|
90
|
+
python -m venv .venv
|
|
91
|
+
source .venv/bin/activate # Windows PowerShell: .\.venv\Scripts\Activate.ps1
|
|
92
|
+
python -m pip install --upgrade pip
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Install the variant required by the workflow:
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
# Local VQE from a precompiled ansatz.
|
|
99
|
+
python -m pip install -e .
|
|
100
|
+
|
|
101
|
+
# Molecular Hamiltonian and UCCSD preprocessing.
|
|
102
|
+
python -m pip install -e ".[chemistry]"
|
|
103
|
+
|
|
104
|
+
# Tianyan execution in addition to molecular preprocessing.
|
|
105
|
+
python -m pip install -e ".[chemistry,tianyan]"
|
|
106
|
+
|
|
107
|
+
# Development and test dependencies.
|
|
108
|
+
python -m pip install -e ".[chemistry,tianyan,test]"
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Run the complete test suite after installation:
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
pytest -q
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Quick start: a precompiled one-parameter VQE
|
|
118
|
+
|
|
119
|
+
Use `UCCSDFactory.from_compiled` when a Pauli-generator ansatz is already
|
|
120
|
+
available and molecular preprocessing is intentionally not part of the runtime.
|
|
121
|
+
Each generator is a list of `(pauli_string, coefficient)` terms. Pauli strings
|
|
122
|
+
use the package's legacy `q0-left` order: the leftmost character acts on qubit
|
|
123
|
+
0.
|
|
124
|
+
|
|
125
|
+
```python
|
|
126
|
+
from cqlib_vqe import DirectStatevectorEstimator, UCCSDFactory, VQESolver
|
|
127
|
+
|
|
128
|
+
# G = i * 0.5 * Y; the one-qubit Hamiltonian is H = Z.
|
|
129
|
+
factory = UCCSDFactory.from_compiled(
|
|
130
|
+
n_qubits=1,
|
|
131
|
+
n_electrons=0,
|
|
132
|
+
generators=[[('Y', 0.5)]],
|
|
133
|
+
initial_values=[0.1],
|
|
134
|
+
construction_mode='jit',
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
estimator = DirectStatevectorEstimator(n_qubits=1)
|
|
138
|
+
solver = VQESolver(
|
|
139
|
+
factory,
|
|
140
|
+
estimator,
|
|
141
|
+
optimizer_method='COBYLA',
|
|
142
|
+
max_iter=30,
|
|
143
|
+
execution_mode='auto',
|
|
144
|
+
)
|
|
145
|
+
result = solver.run([('Z', 1.0)])
|
|
146
|
+
|
|
147
|
+
print(result['optimal_value'])
|
|
148
|
+
print(result['optimal_params'])
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
`solver.run(...)` returns a dictionary containing `optimal_value`,
|
|
152
|
+
`optimal_params`, `n_evals`, `n_iters`, `success`, `message`,
|
|
153
|
+
`execution_mode`, and the complete energy `history`.
|
|
154
|
+
|
|
155
|
+
This smoke example deliberately caps COBYLA at 30 evaluations. It can therefore
|
|
156
|
+
reach the numerical minimum while still returning `success=False` because the
|
|
157
|
+
evaluation budget is exhausted. Increase `max_iter` and define an
|
|
158
|
+
energy/parameter convergence criterion appropriate to the production study.
|
|
159
|
+
|
|
160
|
+
The runnable version is available as:
|
|
161
|
+
|
|
162
|
+
```bash
|
|
163
|
+
python examples/minimal_compiled_smoke.py
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## Molecular VQE workflow
|
|
167
|
+
|
|
168
|
+
For a molecular calculation, first build `MolecularDataEngine`. Its `run()`
|
|
169
|
+
method performs the electronic-structure preprocessing and exposes
|
|
170
|
+
`n_qubits`, `n_electrons`, `hamiltonian_data`, CCSD initial amplitudes, and
|
|
171
|
+
reference energies. Then construct the UCCSD circuit factory, choose an
|
|
172
|
+
estimator, and start `VQESolver`.
|
|
173
|
+
|
|
174
|
+
```python
|
|
175
|
+
from cqlib_vqe import (
|
|
176
|
+
DirectStatevectorEstimator,
|
|
177
|
+
MolecularDataEngine,
|
|
178
|
+
UCCSDFactory,
|
|
179
|
+
VQESolver,
|
|
180
|
+
)
|
|
181
|
+
|
|
182
|
+
molecule = MolecularDataEngine(
|
|
183
|
+
geometry=[
|
|
184
|
+
('H', (0.0, 0.0, 0.0)),
|
|
185
|
+
('H', (0.0, 0.0, 0.735)),
|
|
186
|
+
],
|
|
187
|
+
basis='sto-3g',
|
|
188
|
+
multiplicity=1,
|
|
189
|
+
charge=0,
|
|
190
|
+
mapper_type='jw',
|
|
191
|
+
excitation_threshold=1e-3,
|
|
192
|
+
).run()
|
|
193
|
+
|
|
194
|
+
factory = UCCSDFactory(
|
|
195
|
+
molecule,
|
|
196
|
+
construction_mode='jit',
|
|
197
|
+
trotter_steps=1,
|
|
198
|
+
trotter_order=2,
|
|
199
|
+
)
|
|
200
|
+
estimator = DirectStatevectorEstimator(n_qubits=molecule.n_qubits)
|
|
201
|
+
solver = VQESolver(
|
|
202
|
+
factory,
|
|
203
|
+
estimator,
|
|
204
|
+
optimizer_method='COBYLA',
|
|
205
|
+
max_iter=100,
|
|
206
|
+
tol=1e-7,
|
|
207
|
+
execution_mode='auto',
|
|
208
|
+
)
|
|
209
|
+
|
|
210
|
+
def progress(_parameters, energy, evaluation):
|
|
211
|
+
if evaluation == 1 or evaluation % 10 == 0:
|
|
212
|
+
print(f'eval={evaluation:4d} energy={energy:.12f} Ha')
|
|
213
|
+
|
|
214
|
+
result = solver.run(molecule.hamiltonian_data, callback=progress)
|
|
215
|
+
print('VQE energy:', result['optimal_value'])
|
|
216
|
+
print('reference energies:', molecule.reference_energies)
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
Run the maintained H2 example directly with:
|
|
220
|
+
|
|
221
|
+
```bash
|
|
222
|
+
python examples/h2_vqe_cqlib2.py
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### Choosing an execution mode
|
|
226
|
+
|
|
227
|
+
`execution_mode='auto'` is the recommended local default. It chooses the
|
|
228
|
+
fused direct-statevector path when the factory and estimator support it, and
|
|
229
|
+
otherwise uses circuit execution. Use `execution_mode='circuit'` when a
|
|
230
|
+
circuit-oriented estimator is required, for example a cloud estimator. Use
|
|
231
|
+
`execution_mode='direct_statevector'` only when both
|
|
232
|
+
`factory.build_statevector(...)` and `estimator.evaluate_parameters(...)` are
|
|
233
|
+
available.
|
|
234
|
+
|
|
235
|
+
`construction_mode='jit'` builds numeric circuits for repeated evaluation.
|
|
236
|
+
`construction_mode='bind'` keeps a symbolic template and is useful when the
|
|
237
|
+
target execution path benefits from parameter binding.
|
|
238
|
+
|
|
239
|
+
## Mapping choice and active spaces
|
|
240
|
+
|
|
241
|
+
Set `mapper_type` to one of `"jw"`, `"bk"`, or `"parity"` when constructing
|
|
242
|
+
`MolecularDataEngine`:
|
|
243
|
+
|
|
244
|
+
```python
|
|
245
|
+
molecule = MolecularDataEngine(
|
|
246
|
+
geometry=[('H', (0.0, 0.0, 0.0)), ('H', (0.0, 0.0, 0.735))],
|
|
247
|
+
basis='sto-3g',
|
|
248
|
+
mapper_type='bk',
|
|
249
|
+
).run()
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
The selected mapping is applied consistently to the molecular Hamiltonian,
|
|
253
|
+
the UCCSD excitation generators, and the Hartree-Fock reference. In BK and
|
|
254
|
+
parity encodings, the reference computational-basis bit pattern is not in
|
|
255
|
+
general characterized by its Hamming weight alone; do not replace the factory
|
|
256
|
+
reference construction with a JW occupancy shortcut.
|
|
257
|
+
|
|
258
|
+
For larger systems, set an explicit active-space policy before running the
|
|
259
|
+
molecule engine. The qubit budget must be positive and even.
|
|
260
|
+
|
|
261
|
+
```python
|
|
262
|
+
from cqlib_vqe import ActiveSpaceConfig, MolecularDataEngine
|
|
263
|
+
|
|
264
|
+
active_space = ActiveSpaceConfig.automatic(
|
|
265
|
+
max_active_qubits=10,
|
|
266
|
+
freeze_core=True,
|
|
267
|
+
min_virtual_orbitals=1,
|
|
268
|
+
)
|
|
269
|
+
molecule = MolecularDataEngine(
|
|
270
|
+
geometry=[('Li', (0.0, 0.0, 0.0)), ('H', (0.0, 0.0, 1.596))],
|
|
271
|
+
basis='sto-3g',
|
|
272
|
+
mapper_type='jw',
|
|
273
|
+
active_space=active_space,
|
|
274
|
+
).run()
|
|
275
|
+
|
|
276
|
+
print(molecule.active_space_report)
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
Use `ActiveSpaceConfig.full()` to retain the full orbital space. The active
|
|
280
|
+
space report should be recorded with every numerical result because it fixes
|
|
281
|
+
the simulated Hamiltonian and parameter pool.
|
|
282
|
+
|
|
283
|
+
## Adaptive selected-UCCSD
|
|
284
|
+
|
|
285
|
+
The adaptive solver initializes an ansatz from canonical CCSD amplitudes and
|
|
286
|
+
then scans the complete remaining canonical operator pool. Candidates with
|
|
287
|
+
zero initial CCSD amplitude remain eligible and are ranked by their measured
|
|
288
|
+
energy gradients.
|
|
289
|
+
|
|
290
|
+
The five-molecule runner provides an auditable end-to-end workflow. Start with
|
|
291
|
+
H2 and a small number of pool scans:
|
|
292
|
+
|
|
293
|
+
```bash
|
|
294
|
+
python examples/run_five_adaptive_full_pool.py h2 \\
|
|
295
|
+
--output-dir run_outputs/h2_adaptive \\
|
|
296
|
+
--pool-rounds 2 \\
|
|
297
|
+
--maxiter 80
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
The output directory contains per-molecule logs and JSON records, plus a CSV
|
|
301
|
+
and JSON summary. The runner accepts `h2`, `h4`, `lih`, `beh2`, and `h2o`; omit
|
|
302
|
+
the positional molecule list to run all five. Use `--active-space-policy full`
|
|
303
|
+
only when the full orbital space is intended and the available resources are
|
|
304
|
+
adequate.
|
|
305
|
+
|
|
306
|
+
## Tianyan execution
|
|
307
|
+
|
|
308
|
+
Tianyan runs submit real measurement tasks and may consume platform credits.
|
|
309
|
+
Install the `tianyan` extra, configure credentials outside version control, and
|
|
310
|
+
inspect the available backend names before submitting a VQE job:
|
|
311
|
+
|
|
312
|
+
```bash
|
|
313
|
+
export TIANYAN_API_KEY='YOUR_API_KEY'
|
|
314
|
+
python tools/check_tianyan_api.py --online
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
Then select a backend and physical-qubit mapping. The mapping is ordered from
|
|
318
|
+
logical qubits to physical qubits and must contain exactly `n_qubits` entries.
|
|
319
|
+
|
|
320
|
+
```bash
|
|
321
|
+
export TIANYAN_DEVICE='BACKEND_NAME'
|
|
322
|
+
export TIANYAN_PHYSICAL_QUBITS='0,1,2,3'
|
|
323
|
+
export TIANYAN_SHOTS=2000
|
|
324
|
+
export TIANYAN_MAXITER=10
|
|
325
|
+
export TIANYAN_CALIBRATION=disabled
|
|
326
|
+
python -u examples/h2_vqe_tianyan.py
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
`TianyanEnergyEstimator` groups qubit-wise commuting Pauli terms before
|
|
330
|
+
submission and validates task ordering, measured qubit headers, and count
|
|
331
|
+
payloads on return. The estimator does not infer routing or silently repair
|
|
332
|
+
backend metadata. Never commit API keys, credential files, or raw cloud output
|
|
333
|
+
that contains account information.
|
|
334
|
+
|
|
335
|
+
## Useful entry points
|
|
336
|
+
|
|
337
|
+
| Task | Command |
|
|
338
|
+
| --- | --- |
|
|
339
|
+
| Minimal precompiled VQE | `python examples/minimal_compiled_smoke.py` |
|
|
340
|
+
| Local H2 UCCSD-VQE | `python examples/h2_vqe_cqlib2.py` |
|
|
341
|
+
| Adaptive H2 workflow | `python examples/run_five_adaptive_full_pool.py h2` |
|
|
342
|
+
| Tianyan interface check | `python tools/check_tianyan_api.py --online` |
|
|
343
|
+
| Full test suite | `pytest -q` |
|
|
344
|
+
|
|
345
|
+
## License
|
|
346
|
+
|
|
347
|
+
Apache License 2.0. See [LICENSE](LICENSE).
|