From 814d07fb94aa0556d15aa905e019cb3bc5dc4998 Mon Sep 17 00:00:00 2001 From: user Date: Thu, 18 Jun 2026 09:07:27 -0400 Subject: [PATCH 1/4] README.m update --- README.md | 225 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 220 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e355c03..d4a7b21 100644 --- a/README.md +++ b/README.md @@ -2,14 +2,229 @@ # AtomQC -Atomistic Calculations on Quantum Computers +**Atomistic Calculations on Quantum Computers** +AtomQC is a toolkit for running materials-science electronic-structure and lattice-dynamics +calculations on quantum computers and quantum simulators. It maps the *Wannier tight-binding +Hamiltonians* (WTBH) of real materials — taken from the [JARVIS-DFT](https://jarvis.nist.gov/jarvisdft/) +database — onto qubits and solves for their eigenvalues using variational quantum algorithms such +as the **Variational Quantum Eigensolver (VQE)**, **ADAPT-VQE**, and the **Variational Quantum +Deflation (VQD)** method. From these eigenvalues it reconstructs electronic and phonon +**bandstructures** that can be compared directly against classical (NumPy) diagonalization. +The approach is described in: -Reference: ---------------- +> **K. Choudhary, "Quantum computation for predicting electron and phonon properties of solids",** +> *J. Phys.: Condens. Matter* **33**, 385501 (2021). +> [doi:10.1088/1361-648X/ac1154](https://iopscience.iop.org/article/10.1088/1361-648X/ac1154/meta) -[K. Choudhary, J. Phys.: Condens. Matter 33 (2021) 385501]( https://iopscience.iop.org/article/10.1088/1361-648X/ac1154/meta) +Related work on AI-driven atomistic modeling: +> **AtomGPT and generative materials design**, *J. Comput. Chem.* (2025). +> [doi:10.1002/jcc.70202](https://onlinelibrary.wiley.com/doi/full/10.1002/jcc.70202) -Note: This project was originally developed under the github.com/usnistgov organization. New updates and developments will be carried out here. +> **Note:** This project was originally developed under the +> [github.com/usnistgov](https://github.com/usnistgov) organization. New updates and developments +> are now carried out here. + +--- + +## Why quantum computing for materials? + +Predicting the electronic and vibrational properties of solids reduces to finding the eigenvalues +of a Hamiltonian matrix `H(k)` at each point `k` in the Brillouin zone. For a compact basis such as +maximally-localized Wannier functions, these matrices are small enough that their **qubit-mapped** +versions can be diagonalized on today's noisy quantum hardware and simulators, making materials a +practical testbed for near-term quantum algorithms. + +AtomQC provides the glue between: + +- **JARVIS-DFT** WTBHs (`get_wann_electron`, `get_wann_phonon`, `get_hk_tb`) — the physics inputs, +- **Qiskit** quantum algorithms and simulators — the quantum back end, and +- **jarvis-tools** `HermitianSolver` / `get_bandstruct` — the solver layer that maps `H(k)` to + Pauli operators, runs the variational circuits, and assembles bandstructures. + +--- + +## Features + +- 🔬 **Electronic & phonon eigenvalues** of real materials from JARVIS-DFT WTBHs. +- ⚛️ **VQE** with a library of hardware-efficient ansätze (`QuantumCircuitLibrary`). +- ⚙️ **ADAPT-VQE** — iteratively grows a compact ansatz from a Pauli excitation pool, choosing the + operator with the largest energy gradient at each step. +- 📈 **VQD bandstructures** along high-symmetry `k`-paths via `get_bandstruct`. +- 🧮 **Classical cross-check** against exact NumPy diagonalization for every run. +- 🖥️ **Multiple back ends** — exact statevector, Qiskit Aer simulators, and real IBM Quantum + hardware (with an API token). +- 🌐 **Live web app** — interactive VQE / ADAPT-VQE / VQD explorer at + [atomgpt.org/quantum](https://atomgpt.org/quantum). + +--- + +## Installation + +AtomQC targets Python ≥ 3.8 and builds on `jarvis-tools` and `qiskit`. + +### From source + +```bash +git clone https://github.com/atomgptlab/atomqc.git +cd atomqc +pip install -e . +``` + +### With conda (reproducible environment) + +A pinned environment is provided in `environment.yml`: + +```bash +conda env create -f environment.yml +conda activate my_atomqc +``` + +### Core dependencies + +`jarvis-tools`, `qiskit`, `qiskit-aer`, `qiskit-algorithms`, `numpy`, `scipy`, `pandas`, +`scikit-learn`, `matplotlib`. For real IBM hardware also install `qiskit-ibm-runtime`. + +> The Qiskit API has changed substantially over time. The example scripts in `atomqc/scripts/` +> were written against the older `qiskit.aqua` API, while the AtomGPT web app (see below) uses the +> modern `qiskit>=1.2` / `qiskit-algorithms` primitives. Match the Qiskit version to the entry +> point you intend to run. + +--- + +## Quick start + +Run a single-`k`-point VQE on FCC aluminum (`JVASP-816`) and compare against classical +diagonalization: + +```python +from jarvis.db.figshare import get_wann_electron, get_hk_tb +from jarvis.io.qiskit.inputs import HermitianSolver + +# 1. Fetch the Wannier tight-binding Hamiltonian for Al from JARVIS-DFT +w, ef, atoms = get_wann_electron(jid="JVASP-816") + +# 2. Build H(k) at a chosen k-point +hk = get_hk_tb(w=w, k=[0.5, 0.5, 0.0]) + +# 3. Solve for eigenvalues with VQE and with exact NumPy diagonalization +HS = HermitianSolver(hk) +vqe_energy, vqe_result, vqe = HS.run_vqe() # min eigenvalue via VQE +classical_vals, classical_vecs = HS.run_numpy() # exact reference + +print("VQE ground state:", vqe_energy) +print("Classical minimum:", min(classical_vals.real)) +``` + +### Full bandstructure (VQD) + +```python +from jarvis.db.figshare import get_wann_electron +from jarvis.io.qiskit.inputs import get_bandstruct + +w, ef, atoms = get_wann_electron(jid="JVASP-816") +out = get_bandstruct(w=w, atoms=atoms, line_density=1, savefig=True) +# out["eigvals_q"] -> quantum (VQD) eigenvalues along the k-path +# out["eigvals_np"] -> classical reference eigenvalues +``` + +--- + +## Repository layout + +``` +atomqc/ +├── atomqc/ +│ ├── __init__.py # version +│ ├── scripts/ +│ │ ├── aluminum_example.py # VQE on Al with several classical optimizers +│ │ ├── circuit_comparison.py # compare ansätze from QuantumCircuitLibrary +│ │ ├── compare_elect_vqe.py # batch electron VQE vs NumPy over JARVIS jids +│ │ └── compare_phonons_vqe.py # batch phonon VQE vs NumPy over JARVIS jids +│ └── data/ +│ ├── electron_vqe_np_jid.csv # benchmark: electron VQE vs classical +│ └── phonon_vqe_np_jid.csv # benchmark: phonon VQE vs classical +├── environment.yml # pinned conda environment +├── setup.py +└── README.md +``` + +### Example scripts + +| Script | What it does | +| --- | --- | +| `aluminum_example.py` | Runs VQE on the Al Hamiltonian sweeping COBYLA, L-BFGS-B, SLSQP, CG, SPSA optimizers and plots convergence. | +| `circuit_comparison.py` | Benchmarks the six ansätze in `QuantumCircuitLibrary` at several `k`-points. | +| `compare_elect_vqe.py` | Loops over JARVIS jids, computes min/max electronic eigenvalues with VQE and NumPy, and dumps JSON. | +| `compare_phonons_vqe.py` | Same as above for phonon Hamiltonians. | + +The CSV files under `atomqc/data/` hold pre-computed VQE-vs-classical benchmark results referenced +in the paper. + +--- + +## AtomGPT.org Quantum Computation Explorer + +A hosted, interactive version of these workflows runs at **[atomgpt.org/quantum](https://atomgpt.org/quantum)**. +It lets you pick a material, choose a back end, and run VQE / ADAPT-VQE at a single `k`-point or +compute a full VQD bandstructure — all from the browser, with live circuit diagrams, statevector / +Bloch-sphere visualizations, and the Hamiltonian matrix shown alongside the results. + +The web app is implemented in the AtomGPT / Open WebUI backend: + +- **Routes:** `my-open-webui/backend/open_webui/custom_routes/quantum.py` +- **UI:** `my-open-webui/backend/open_webui/custom_templates/quantum.html` + +Endpoints exposed by the app: + +| Method & path | Purpose | +| --- | --- | +| `GET /quantum` | Serves the interactive HTML page. | +| `POST /quantum/vqe` | Run Qiskit VQE at a single `k`-point. | +| `POST /quantum/adaptvqe` | Run Qiskit ADAPT-VQE at a single `k`-point. | +| `POST /quantum/bandstructure` | Full VQD bandstructure via `get_bandstruct`. | +| `GET /quantum/materials` | List the available demo WTBHs. | +| `GET /quantum/backends` | List available simulator/hardware back ends. | + +Demo materials include FCC Al, diamond Si, hexagonal PbS, and FCC Cu (electron Hamiltonians) plus +Al and Si phonon Hamiltonians. The same JARVIS-DFT + `HermitianSolver` machinery used in the +scripts powers the app; it adds modern `qiskit>=1.2` primitives, optional IBM Quantum hardware +execution, and per-qubit Bloch-vector / statevector extraction for visualization. + +--- + +## Citation + +If you use AtomQC in your research, please cite: + +```bibtex +@article{choudhary2021quantum, + title = {Quantum computation for predicting electron and phonon properties of solids}, + author = {Choudhary, Kamal}, + journal = {Journal of Physics: Condensed Matter}, + volume = {33}, + number = {38}, + pages = {385501}, + year = {2021}, + doi = {10.1088/1361-648X/ac1154} +} +``` + +--- + +## References & links + +- 📄 Paper: [J. Phys.: Condens. Matter 33, 385501 (2021)](https://iopscience.iop.org/article/10.1088/1361-648X/ac1154/meta) +- 📄 Related: [J. Comput. Chem. (2025), doi:10.1002/jcc.70202](https://onlinelibrary.wiley.com/doi/full/10.1002/jcc.70202) +- 🌐 Web app: [atomgpt.org/quantum](https://atomgpt.org/quantum) +- 📓 Colab notebook: [Qiskit-based electronic bandstructure](https://colab.research.google.com/github/knc6/jarvis-tools-notebooks/blob/master/jarvis-tools-notebooks/Qiskit_based_electronic_bandstructure_.ipynb) +- 🧰 JARVIS-Tools: [github.com/usnistgov/jarvis](https://github.com/usnistgov/jarvis) +- ⚛️ Qiskit: [qiskit.org](https://www.qiskit.org/) + +--- + +## License + +Distributed under the terms of the [LICENSE](LICENSE.md) included in this repository. From eafe19c8d3e40bee8d64eaa4628c28a6c631b135 Mon Sep 17 00:00:00 2001 From: user Date: Thu, 18 Jun 2026 12:56:46 -0400 Subject: [PATCH 2/4] AtomQC --- .github/workflows/main.yml | 4 +- atomqc/__init__.py | 2 +- environment.yml | 222 +++++++++++++++---------------------- setup.py | 16 ++- 4 files changed, 102 insertions(+), 142 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index edf507a..0babb4a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -9,8 +9,8 @@ jobs: matrix: os: ["ubuntu-latest"] steps: - - uses: actions/checkout@v2 - - uses: conda-incubator/setup-miniconda@v2 + - uses: actions/checkout@v3 + - uses: conda-incubator/setup-miniconda@v3 with: activate-environment: test environment-file: environment.yml diff --git a/atomqc/__init__.py b/atomqc/__init__.py index 2683b5a..df904d3 100644 --- a/atomqc/__init__.py +++ b/atomqc/__init__.py @@ -1,3 +1,3 @@ """Version number.""" -__version__ = "2024.3.24" +__version__ = "2025.10.11" diff --git a/environment.yml b/environment.yml index 62e74d0..ac7cecf 100644 --- a/environment.yml +++ b/environment.yml @@ -2,140 +2,94 @@ name: my_atomqc channels: - conda-forge dependencies: - - _libgcc_mutex=0.1=conda_forge - - _openmp_mutex=4.5=2_gnu - - archspec=0.2.2=pyhd8ed1ab_0 - - boltons=23.1.1=pyhd8ed1ab_0 - - brotli-python=1.1.0=py310hc6cd4ac_1 - - bzip2=1.0.8=hd590300_5 - - c-ares=1.24.0=hd590300_0 - - ca-certificates=2023.11.17=hbcca054_0 - - certifi=2023.11.17=pyhd8ed1ab_0 - - cffi=1.16.0=py310h2fee648_0 - - charset-normalizer=3.3.2=pyhd8ed1ab_0 - - colorama=0.4.6=pyhd8ed1ab_0 - - conda=23.11.0=py310hff52083_1 - - conda-libmamba-solver=23.12.0=pyhd8ed1ab_0 - - conda-package-handling=2.2.0=pyh38be061_0 - - conda-package-streaming=0.9.0=pyhd8ed1ab_0 - - distro=1.8.0=pyhd8ed1ab_0 - - fmt=10.1.1=h00ab1b0_1 - - icu=73.2=h59595ed_0 - - idna=3.6=pyhd8ed1ab_0 - - jsonpatch=1.33=pyhd8ed1ab_0 - - jsonpointer=2.4=py310hff52083_3 - - keyutils=1.6.1=h166bdaf_0 - - krb5=1.21.2=h659d440_0 - - ld_impl_linux-64=2.40=h41732ed_0 - - libarchive=3.7.2=h2aa1ff5_1 - - libcurl=8.5.0=hca28451_0 - - libedit=3.1.20191231=he28a2e2_2 - - libev=4.33=hd590300_2 - - libffi=3.4.2=h7f98852_5 - - libgcc-ng=13.2.0=h807b86a_3 - - libgomp=13.2.0=h807b86a_3 - - libiconv=1.17=hd590300_2 - - libmamba=1.5.5=had39da4_0 - - libmambapy=1.5.5=py310h39ff949_0 - - libnghttp2=1.58.0=h47da74e_1 - - libnsl=2.0.1=hd590300_0 - - libsolv=0.7.27=hfc55251_0 - - libsqlite=3.44.2=h2797004_0 - - libssh2=1.11.0=h0841786_0 - - libstdcxx-ng=13.2.0=h7e041cc_3 - - libuuid=2.38.1=h0b41bf4_0 - - libxml2=2.12.3=h232c23b_0 - - libzlib=1.2.13=hd590300_5 - - lz4-c=1.9.4=hcb278e6_0 - - lzo=2.10=h516909a_1000 - - mamba=1.5.5=py310h51d5547_0 - - menuinst=2.0.1=py310hff52083_0 - - ncurses=6.4=h59595ed_2 - - openssl=3.2.0=hd590300_1 - - packaging=23.2=pyhd8ed1ab_0 - - pandas=2.2.1=py310hcc13569_0 - - pip=23.3.2=pyhd8ed1ab_0 - - platformdirs=4.1.0=pyhd8ed1ab_0 - - pluggy=1.3.0=pyhd8ed1ab_0 - - pybind11-abi=4=hd8ed1ab_3 - - pycosat=0.6.6=py310h2372a71_0 - - pycparser=2.21=pyhd8ed1ab_0 - - pysocks=1.7.1=pyha2e5f31_6 - - python=3.10.13=hd12c33a_0_cpython - - python_abi=3.10=4_cp310 - - readline=8.2=h8228510_1 - - reproc=14.2.4.post0=hd590300_1 - - reproc-cpp=14.2.4.post0=h59595ed_1 - - requests=2.31.0=pyhd8ed1ab_0 - - ruamel.yaml=0.18.5=py310h2372a71_0 - - ruamel.yaml.clib=0.2.7=py310h2372a71_2 - - setuptools=68.2.2=pyhd8ed1ab_0 - - tk=8.6.13=noxft_h4845f30_101 - - tqdm=4.66.1=pyhd8ed1ab_0 - - truststore=0.8.0=pyhd8ed1ab_0 - - tzdata=2023c=h71feb2d_0 - - urllib3=2.1.0=pyhd8ed1ab_0 - - wheel=0.42.0=pyhd8ed1ab_0 - - xz=5.2.6=h166bdaf_0 - - yaml-cpp=0.8.0=h59595ed_0 - - zstandard=0.22.0=py310h1275a96_0 - - zstd=1.5.5=hfc55251_0 + - _openmp_mutex=4.5=20_gnu + - bzip2=1.0.8=hda65f42_9 + - ca-certificates=2026.6.17=hbd8a1cb_0 + - ld_impl_linux-64=2.45.1=default_hbd61a6d_102 + - libexpat=2.8.1=hecca717_1 + - libffi=3.5.2=h3435931_0 + - libgcc=15.2.0=he0feb66_19 + - libgcc-ng=15.2.0=h69a702a_19 + - libgomp=15.2.0=he0feb66_19 + - liblzma=5.8.3=hb03c661_0 + - libnsl=2.0.1=hb9d3cd8_1 + - libsqlite=3.53.2=h0c1763c_0 + - libuuid=2.42.2=h5347b49_0 + - libxcrypt=4.4.36=hd590300_1 + - libzlib=1.3.2=h25fd6f3_2 + - ncurses=6.6=hdb14827_0 + - openssl=3.6.3=h35e630c_0 + - packaging=26.2=pyhc364b38_0 + - pip=26.1.2=pyh8b19718_0 + - python=3.12.13=hd63d673_0_cpython + - readline=8.3=h853b02a_0 + - setuptools=82.0.1=pyh332efcf_0 + - tk=8.6.13=noxft_h366c992_103 + - tzdata=2025c=hc9c84f9_1 + - wheel=0.47.0=pyhd8ed1ab_0 + - zstd=1.5.7=hb78ec9c_6 - pip: - - babel==2.14.0 - - click==8.1.7 - - contourpy==1.2.0 - - cryptography==42.0.5 + - certifi==2026.6.17 + - cffi==2.0.0 + - charset-normalizer==3.4.7 + - contourpy==1.3.3 + - cryptography==49.0.0 - cycler==0.12.1 - - dill==0.3.8 - - fonttools==4.50.0 - - ghp-import==2.1.0 - - h5py==3.10.0 - - jarvis-tools==2024.3.24 - - jinja2==3.1.3 - - joblib==1.3.2 - - kiwisolver==1.4.5 - - markdown==3.6 - - markupsafe==2.1.5 - - matplotlib==3.8.3 - - mergedeep==1.3.4 - - mkdocs==1.5.3 - - mkdocs-material==9.5.15 - - mkdocs-material-extensions==1.3.1 - - mpmath==1.3.0 - - ntlm-auth==1.5.0 - - numpy==1.23.5 - - paginate==0.5.6 - - pathspec==0.12.1 - - pbr==6.0.0 - - pillow==10.2.0 - - ply==3.11 - - psutil==5.9.8 - - pygments==2.17.2 - - pymdown-extensions==10.7.1 - - pyparsing==3.1.2 - - pyscf==2.5.0 + - dill==0.4.1 + - docutils==0.23 + - fonttools==4.63.0 + - h5py==3.16.0 + - id==1.6.1 + - idna==3.18 + - iniconfig==2.3.0 + - jaraco-classes==3.4.0 + - jaraco-context==6.1.2 + - jaraco-functools==4.5.0 + - jarvis-tools==2026.6.12 + - jeepney==0.9.0 + - joblib==1.5.3 + - keyring==25.7.0 + - kiwisolver==1.5.0 + - markdown-it-py==4.2.0 + - matplotlib==3.11.0 + - mdurl==0.1.2 + - more-itertools==11.1.0 + - narwhals==2.22.1 + - nh3==0.3.5 + - numpy==2.4.6 + - phonopy==4.2.1 + - phonors==0.2.1 + - pillow==12.2.0 + - pluggy==1.6.0 + - psutil==7.2.2 + - pycparser==3.0 + - pygments==2.20.0 + - pylatexenc==2.10 + - pyparsing==3.3.2 + - pytest==9.1.0 - python-dateutil==2.9.0.post0 - - pyyaml==6.0.1 - - pyyaml-env-tag==0.1 - - qiskit==0.43.1 - - qiskit-aer==0.12.0 - - qiskit-ibmq-provider==0.20.2 - - qiskit-nature==0.6.2 - - qiskit-terra==0.24.1 - - regex==2023.12.25 - - requests-ntlm==1.1.0 - - rustworkx==0.14.2 - - scikit-learn==1.4.1.post1 - - scipy==1.12.0 - - six==1.16.0 - - spglib==2.3.1 - - stevedore==5.2.0 - - symengine==0.9.2 - - sympy==1.12 - - threadpoolctl==3.4.0 - - toolz==0.12.1 - - typing-extensions==4.10.0 - - watchdog==4.0.0 - - websocket-client==1.7.0 - - websockets==12.0 - - xmltodict==0.13.0 + - pyyaml==6.0.3 + - qiskit==2.4.2 + - qiskit-aer==0.17.2 + - qiskit-algorithms==0.4.0 + - readme-renderer==45.0 + - requests==2.34.2 + - requests-toolbelt==1.0.0 + - rfc3986==2.0.0 + - rich==15.0.0 + - rustworkx==0.18.0 + - scikit-learn==1.9.0 + - scipy==1.17.1 + - secretstorage==3.5.0 + - six==1.17.0 + - slakonet==2026.4.1 + - spglib==2.7.0 + - stevedore==5.8.0 + - symfc==1.7.2 + - threadpoolctl==3.6.0 + - toolz==1.1.0 + - tqdm==4.68.3 + - twine==6.2.0 + - typing-extensions==4.15.0 + - urllib3==2.7.0 + - xmltodict==1.0.4 diff --git a/setup.py b/setup.py index 7e4509b..31e57db 100644 --- a/setup.py +++ b/setup.py @@ -5,15 +5,21 @@ setuptools.setup( name="atomqc", # Replace with your own username - version="2021.10.11", + version="2025.10.11", author="Kamal Choudhary", - author_email="kamal.choudhary@nist.gov", + author_email="drkamal@jhu.edu", description="atomqc", install_requires=[ "numpy>=1.19.5", "scipy>=1.6.3", - "jarvis-tools>=2021.07.19", - "qiskit", + "jarvis-tools", + "qiskit>=2.0", + "qiskit-aer", + "slakonet", + "qiskit_algorithms", + "spglib", + "rustworkx", + "phonopy", "scikit-learn>=0.24.1", "matplotlib>=3.4.1", "seaborn>=0.11.2", @@ -26,7 +32,7 @@ ], long_description=long_description, long_description_content_type="text/markdown", - url="https://github.com/usnistgov/atomqc", + url="https://github.com/atomgptlab/atomqc", packages=setuptools.find_packages(), classifiers=[ "Programming Language :: Python :: 3", From ab40ca9d7314a09805028ef7b640543912228740 Mon Sep 17 00:00:00 2001 From: user Date: Thu, 18 Jun 2026 13:01:06 -0400 Subject: [PATCH 3/4] conda update --- .github/workflows/main.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0babb4a..d53641a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -14,7 +14,6 @@ jobs: with: activate-environment: test environment-file: environment.yml - python-version: "3.10" auto-activate-base: false - shell: bash -l {0} run: | From 947a76f2a57ce515eb9817af5e0b6370e39dfd77 Mon Sep 17 00:00:00 2001 From: user Date: Thu, 18 Jun 2026 13:06:49 -0400 Subject: [PATCH 4/4] conda update --- README.md | 18 +++++++ .../test_qiskit.cpython-312-pytest-9.1.0.pyc | Bin 0 -> 7584 bytes atomqc/tests/test_qiskit.py | 44 ++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 atomqc/tests/__pycache__/test_qiskit.cpython-312-pytest-9.1.0.pyc create mode 100644 atomqc/tests/test_qiskit.py diff --git a/README.md b/README.md index d4a7b21..66efffb 100644 --- a/README.md +++ b/README.md @@ -132,6 +132,22 @@ out = get_bandstruct(w=w, atoms=atoms, line_density=1, savefig=True) --- +## Testing + +A small, fast test suite covers the core Hamiltonian → qubit → VQE pipeline: + +```bash +pip install pytest +pytest atomqc/tests/ +``` + +The tests in `atomqc/tests/test_qiskit.py` build a small synthetic Hermitian `H(k)`, +decompose it into Pauli strings, and check that VQE reproduces the exact NumPy ground state. +They run offline in a few seconds (no JARVIS downloads), which is also what CI runs on every +push. + +--- + ## Repository layout ``` @@ -143,6 +159,8 @@ atomqc/ │ │ ├── circuit_comparison.py # compare ansätze from QuantumCircuitLibrary │ │ ├── compare_elect_vqe.py # batch electron VQE vs NumPy over JARVIS jids │ │ └── compare_phonons_vqe.py # batch phonon VQE vs NumPy over JARVIS jids +│ ├── tests/ +│ │ └── test_qiskit.py # fast offline tests: H(k) -> Pauli -> VQE │ └── data/ │ ├── electron_vqe_np_jid.csv # benchmark: electron VQE vs classical │ └── phonon_vqe_np_jid.csv # benchmark: phonon VQE vs classical diff --git a/atomqc/tests/__pycache__/test_qiskit.cpython-312-pytest-9.1.0.pyc b/atomqc/tests/__pycache__/test_qiskit.cpython-312-pytest-9.1.0.pyc new file mode 100644 index 0000000000000000000000000000000000000000..f4205351fbe1261a6e95bf6bbf77a655423601e1 GIT binary patch literal 7584 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 literal 0 HcmV?d00001 diff --git a/atomqc/tests/test_qiskit.py b/atomqc/tests/test_qiskit.py new file mode 100644 index 0000000..669c27b --- /dev/null +++ b/atomqc/tests/test_qiskit.py @@ -0,0 +1,44 @@ +"""Superquick tests for the Hamiltonian -> qiskit -> VQE pipeline. + +These mirror the core of the AtomQC tutorial notebook (build a Hermitian +H(k), decompose it into Pauli strings, solve it with VQE/VQD) but use a +small synthetic matrix so they run in seconds with no network downloads. +""" +import numpy as np +import pytest + +from jarvis.io.qiskit.inputs import HermitianSolver, decompose_Hamiltonian +from jarvis.core.circuits import QuantumCircuitLibrary + + +def _hermitian(n=4, seed=0): + """Return a small random Hermitian matrix to stand in for H(k).""" + rng = np.random.RandomState(seed) + a = rng.rand(n, n) + 1j * rng.rand(n, n) + return a + a.conj().T + + +def test_hermitian_solver_basics(): + """HermitianSolver pads to 2**n and reports the right qubit count.""" + hk = _hermitian(4) + hs = HermitianSolver(hk) + assert hs.check_hermitian() + assert hs.n_qubits() == 2 # 4x4 -> 2 qubits + + +def test_pauli_decomposition_roundtrip(): + """Pauli decomposition of H reconstructs the original matrix (qiskit).""" + hk = _hermitian(4) + op = decompose_Hamiltonian(hk) + assert len(op) > 0 + assert np.allclose(op.to_matrix(), hk) + + +def test_vqe_matches_numpy_ground_state(): + """VQE ground-state energy matches exact NumPy diagonalization.""" + hk = _hermitian(4) + hs = HermitianSolver(hk) + vals, _ = hs.run_numpy() + circ = QuantumCircuitLibrary(n_qubits=hs.n_qubits(), reps=2).circuit6() + en_vqe, _, _ = hs.run_vqe(var_form=circ, backend="statevector_simulator") + assert en_vqe == pytest.approx(float(vals[0]), abs=1e-2)