From cb2227b0b5107d95ea9e543a6fd7d14b70aeda85 Mon Sep 17 00:00:00 2001 From: Kamal Choudhary Date: Sat, 17 Sep 2022 15:40:12 -0400 Subject: [PATCH] Qiskit upgraded (#254) * Image augmentation. * Augment images. * Augment images. * Specie update. * Add Latt2D, STM image (b-1) fix, image augmentation fix. * Add Latt2D, STM image (b-1) fix, image augmentation fix. * Update conf.py * Update conf.py * Multi-output graph bacthing. * Add EDOS dataset. * Temp. * Add circuit maker. * Add circuit maker. * NELECT update. * Version update, more DBs added. * Fix CHGCAR vasp. * Added volumetric reshape for CHGCAR. * Tmp * Tershoff Hamman update, specie update. * Add crop from center in STM. * Add Fourier transfor in STM. * Update STM pytest. * Add DPI to STM. * Zeo++ added, Atoms cif update, STM update, random vacancy maker added. * Atoms tempfile fix, Potcar from atoms module added. * Test for docs. * C2DB link update, docs Atoms update. * C2DB link update, docs Atoms update. * Version update, COD DB, QM9 JCTC DB added. * Compostion bug fix, elemental descriptor added. * Develop (#186) * Update outputs.py I added the calculation of the Raman intensities inside parse_raman_dat * Update outputs.py * Update outputs.py * Update outputs.py * Update cfid.py * Delete __init__.py * stylecss added. * stylecss added. * Adding extra Makefile/ * Remove examples from docs. * Docs update. * Docs update. * Docs update. * Docs update. * Docs update. * Docs update. * Docs update. * Docs update. * Docs update. * Docs update. * Tutorials update. * Tutorials docs update. * Docs update,pdb reader updated. * Update action_build.yml * Update action_build.yml * Remove pytraj strong dependencies. * Update docs, Added PDBBind and HPOV datasets. * Docs update. * Add thcikness to surface builder. * Surface builder update, Chemical only magpie descriptors added, pdb_core dataset added, zeopp tempfile bugfix. * Typo fix. * Add names to chem descs. * Lessen hermsolver pytest. * Reduced pytest. * Reduced pytest. * Reduced pytest. * Reduced pytest. * Reduced pytest. * No DFT3D * Exclude dft_3d dataset for memory issue. * Update figshare test. * Update figshare test. * Exclude db from coverage. * Exclude db from coverage. * Add magpie.json. * Add magpie.json. * Wien2k bands bug fix. * Wien2k bands bug fix. * Update JARVIS-FF,Elastictensor,LAMMPS parse folder, VASP bandstructure plot code. * JFF update. * Add JQE_TB3 and hMOF dataset. * Update LAMMPS module. * Update LAMMPS module. * Fix elastic tensor module. * Figshare update, docs db name update. * Substitutions. * Update figshare dft_3d, cfid_3d. * Docs data update. * Generate substitutions. * Lint fix. * Update DOS. * Update DOS. * Adding folders for nexus setup. * Update QMOF and hMOF info. * Fixing auto klength error. * Adding zeopp surface area. * Vacancy bug fix, added hmof to docs. * vacancy update. * QE inputs update. * Pyhon 3.9 test, added QE el-ph, VASP XANES, modified hmof db details. * Update Contribution.rst * Minor lint fix. * Update action_build.yml * Update action_build.yml * Fix qiskit requirements. * Fix phonopy requirements. * Fix all requirements. * Fix phonopy requirements. * QE test. * QE test. * Update action_build. * Try other python versions. * Try other python versions. * README updates. * Adding nexus. (#197) * Develop (#196) * Image augmentation. * Augment images. * Augment images. * Specie update. * Add Latt2D, STM image (b-1) fix, image augmentation fix. * Add Latt2D, STM image (b-1) fix, image augmentation fix. * Update conf.py * Update conf.py * Multi-output graph bacthing. * Add EDOS dataset. * Temp. * Add circuit maker. * Add circuit maker. * NELECT update. * Version update, more DBs added. * Fix CHGCAR vasp. * Added volumetric reshape for CHGCAR. * Tmp * Tershoff Hamman update, specie update. * Add crop from center in STM. * Add Fourier transfor in STM. * Update STM pytest. * Add DPI to STM. * Zeo++ added, Atoms cif update, STM update, random vacancy maker added. * Atoms tempfile fix, Potcar from atoms module added. * Test for docs. * C2DB link update, docs Atoms update. * C2DB link update, docs Atoms update. * Version update, COD DB, QM9 JCTC DB added. * Compostion bug fix, elemental descriptor added. * Develop (#186) * Update outputs.py I added the calculation of the Raman intensities inside parse_raman_dat * Update outputs.py * Update outputs.py * Update outputs.py * Update cfid.py * Delete __init__.py * stylecss added. * stylecss added. * Adding extra Makefile/ * Remove examples from docs. * Docs update. * Docs update. * Docs update. * Docs update. * Docs update. * Docs update. * Docs update. * Docs update. * Docs update. * Docs update. * Tutorials update. * Tutorials docs update. * Docs update,pdb reader updated. * Update action_build.yml * Update action_build.yml * Remove pytraj strong dependencies. * Update docs, Added PDBBind and HPOV datasets. * Docs update. * Add thcikness to surface builder. * Surface builder update, Chemical only magpie descriptors added, pdb_core dataset added, zeopp tempfile bugfix. * Typo fix. * Add names to chem descs. * Lessen hermsolver pytest. * Reduced pytest. * Reduced pytest. * Reduced pytest. * Reduced pytest. * Reduced pytest. * No DFT3D * Exclude dft_3d dataset for memory issue. * Update figshare test. * Update figshare test. * Exclude db from coverage. * Exclude db from coverage. * Add magpie.json. * Add magpie.json. * Wien2k bands bug fix. * Wien2k bands bug fix. * Update JARVIS-FF,Elastictensor,LAMMPS parse folder, VASP bandstructure plot code. * JFF update. * Add JQE_TB3 and hMOF dataset. * Update LAMMPS module. * Update LAMMPS module. * Fix elastic tensor module. * Figshare update, docs db name update. * Substitutions. * Update figshare dft_3d, cfid_3d. * Docs data update. * Generate substitutions. * Lint fix. * Update DOS. * Update DOS. Co-authored-by: tavazza Co-authored-by: knc6 Co-authored-by: KAMAL CHOUDHARY * First input. * added black * Example folder. Co-authored-by: Kamal Choudhary Co-authored-by: tavazza Co-authored-by: knc6 Co-authored-by: KAMAL CHOUDHARY * Revert back. * Update .readthedocs.yaml * Update dev-requirements.txt * Docs requirements update. * Update .readthedocs.yaml * Update requirements.txt * Update .readthedocs.yaml * Update requirements.txt * Update .readthedocs.yaml * Update requirements.txt * Update requirements.txt * Update requirements.txt * Update requirements.txt * Update requirements.txt * Update atoms.py * Fixe pbc in ase_to_Atoms. * Add installation tests (#214) * QE inputs, XANES, GHAction updates. (#210) * Image augmentation. * Augment images. * Augment images. * Specie update. * Add Latt2D, STM image (b-1) fix, image augmentation fix. * Add Latt2D, STM image (b-1) fix, image augmentation fix. * Update conf.py * Update conf.py * Multi-output graph bacthing. * Add EDOS dataset. * Temp. * Add circuit maker. * Add circuit maker. * NELECT update. * Version update, more DBs added. * Fix CHGCAR vasp. * Added volumetric reshape for CHGCAR. * Tmp * Tershoff Hamman update, specie update. * Add crop from center in STM. * Add Fourier transfor in STM. * Update STM pytest. * Add DPI to STM. * Zeo++ added, Atoms cif update, STM update, random vacancy maker added. * Atoms tempfile fix, Potcar from atoms module added. * Test for docs. * C2DB link update, docs Atoms update. * C2DB link update, docs Atoms update. * Version update, COD DB, QM9 JCTC DB added. * Compostion bug fix, elemental descriptor added. * Develop (#186) * Update outputs.py I added the calculation of the Raman intensities inside parse_raman_dat * Update outputs.py * Update outputs.py * Update outputs.py * Update cfid.py * Delete __init__.py * stylecss added. * stylecss added. * Adding extra Makefile/ * Remove examples from docs. * Docs update. * Docs update. * Docs update. * Docs update. * Docs update. * Docs update. * Docs update. * Docs update. * Docs update. * Docs update. * Tutorials update. * Tutorials docs update. * Docs update,pdb reader updated. * Update action_build.yml * Update action_build.yml * Remove pytraj strong dependencies. * Update docs, Added PDBBind and HPOV datasets. * Docs update. * Add thcikness to surface builder. * Surface builder update, Chemical only magpie descriptors added, pdb_core dataset added, zeopp tempfile bugfix. * Typo fix. * Add names to chem descs. * Lessen hermsolver pytest. * Reduced pytest. * Reduced pytest. * Reduced pytest. * Reduced pytest. * Reduced pytest. * No DFT3D * Exclude dft_3d dataset for memory issue. * Update figshare test. * Update figshare test. * Exclude db from coverage. * Exclude db from coverage. * Add magpie.json. * Add magpie.json. * Wien2k bands bug fix. * Wien2k bands bug fix. * Update JARVIS-FF,Elastictensor,LAMMPS parse folder, VASP bandstructure plot code. * JFF update. * Add JQE_TB3 and hMOF dataset. * Update LAMMPS module. * Update LAMMPS module. * Fix elastic tensor module. * Figshare update, docs db name update. * Substitutions. * Update figshare dft_3d, cfid_3d. * Docs data update. * Generate substitutions. * Lint fix. * Update DOS. * Update DOS. * Adding folders for nexus setup. * Update QMOF and hMOF info. * Fixing auto klength error. * Adding zeopp surface area. * Vacancy bug fix, added hmof to docs. * vacancy update. * QE inputs update. * Pyhon 3.9 test, added QE el-ph, VASP XANES, modified hmof db details. * Update Contribution.rst * Minor lint fix. * Update action_build.yml * Update action_build.yml * Fix qiskit requirements. * Fix phonopy requirements. * Fix all requirements. * Fix phonopy requirements. * QE test. * QE test. * Update action_build. * Try other python versions. * Try other python versions. * README updates. * Adding nexus. (#197) * Develop (#196) * Image augmentation. * Augment images. * Augment images. * Specie update. * Add Latt2D, STM image (b-1) fix, image augmentation fix. * Add Latt2D, STM image (b-1) fix, image augmentation fix. * Update conf.py * Update conf.py * Multi-output graph bacthing. * Add EDOS dataset. * Temp. * Add circuit maker. * Add circuit maker. * NELECT update. * Version update, more DBs added. * Fix CHGCAR vasp. * Added volumetric reshape for CHGCAR. * Tmp * Tershoff Hamman update, specie update. * Add crop from center in STM. * Add Fourier transfor in STM. * Update STM pytest. * Add DPI to STM. * Zeo++ added, Atoms cif update, STM update, random vacancy maker added. * Atoms tempfile fix, Potcar from atoms module added. * Test for docs. * C2DB link update, docs Atoms update. * C2DB link update, docs Atoms update. * Version update, COD DB, QM9 JCTC DB added. * Compostion bug fix, elemental descriptor added. * Develop (#186) * Update outputs.py I added the calculation of the Raman intensities inside parse_raman_dat * Update outputs.py * Update outputs.py * Update outputs.py * Update cfid.py * Delete __init__.py * stylecss added. * stylecss added. * Adding extra Makefile/ * Remove examples from docs. * Docs update. * Docs update. * Docs update. * Docs update. * Docs update. * Docs update. * Docs update. * Docs update. * Docs update. * Docs update. * Tutorials update. * Tutorials docs update. * Docs update,pdb reader updated. * Update action_build.yml * Update action_build.yml * Remove pytraj strong dependencies. * Update docs, Added PDBBind and HPOV datasets. * Docs update. * Add thcikness to surface builder. * Surface builder update, Chemical only magpie descriptors added, pdb_core dataset added, zeopp tempfile bugfix. * Typo fix. * Add names to chem descs. * Lessen hermsolver pytest. * Reduced pytest. * Reduced pytest. * Reduced pytest. * Reduced pytest. * Reduced pytest. * No DFT3D * Exclude dft_3d dataset for memory issue. * Update figshare test. * Update figshare test. * Exclude db from coverage. * Exclude db from coverage. * Add magpie.json. * Add magpie.json. * Wien2k bands bug fix. * Wien2k bands bug fix. * Update JARVIS-FF,Elastictensor,LAMMPS parse folder, VASP bandstructure plot code. * JFF update. * Add JQE_TB3 and hMOF dataset. * Update LAMMPS module. * Update LAMMPS module. * Fix elastic tensor module. * Figshare update, docs db name update. * Substitutions. * Update figshare dft_3d, cfid_3d. * Docs data update. * Generate substitutions. * Lint fix. * Update DOS. * Update DOS. Co-authored-by: tavazza Co-authored-by: knc6 Co-authored-by: KAMAL CHOUDHARY * First input. * added black * Example folder. Co-authored-by: Kamal Choudhary Co-authored-by: tavazza Co-authored-by: knc6 Co-authored-by: KAMAL CHOUDHARY * Revert back. * Update .readthedocs.yaml * Update dev-requirements.txt * Docs requirements update. * Update .readthedocs.yaml * Update requirements.txt * Update .readthedocs.yaml * Update requirements.txt * Update .readthedocs.yaml * Update requirements.txt * Update requirements.txt * Update requirements.txt * Update requirements.txt * Update requirements.txt * Update atoms.py * Fixe pbc in ase_to_Atoms. Co-authored-by: tavazza Co-authored-by: knc6 Co-authored-by: KAMAL CHOUDHARY Co-authored-by: wines1 <74620550+wines1@users.noreply.github.com> * Add installation tests * Fix codestyle * Fix codestyle with black * Add docstrings * Fix pydocstyle error * Update __init__.py * Update __init__.py Co-authored-by: Kamal Choudhary Co-authored-by: tavazza Co-authored-by: knc6 Co-authored-by: KAMAL CHOUDHARY Co-authored-by: wines1 <74620550+wines1@users.noreply.github.com> * Adding QE super. * Minor changes to QE module, atoms xyz fix. * Adding qe_tb info, and version update. * Update __init__.py * WIP super QE. * Working version of ScSi. * QE inputs and task update. * Add master super. * Add master super. * Lint fix. * Lint fix. * Minor fix. * ET update. * Fix ET test. * Update sanitize atoms. * Additonal checks on supercond. * Debye bug fix. * Pressure in QE Super. * Version fix, publication update, supercond workflow update. * Lint fix. * Tensorboard fix. * Tensorboard fix. * Tensorboard fix. * Melting temp fix. * Update vasp.py (#234) * Local tetra tmp. * Version update. * Lint fix. * HSE06 * Tmp. * Vacancy update, Optimade structureand other minor lint updates. * STEM pytest fix. * Minor lint fix. * Fixed selectrive dynamics issue in Poscar, force reading for single atom system in Vasprun, np.array in core.graps, num_atoms for single atom systems in core.Atoms * Lint fix. * Added phononDos class. * fix pytorch UserWarning in build_undirected_edgedata() (#243) site-packages/jarvis/core/graphs.py:158: UserWarning: Creating a tensor from a list of numpy.ndarrays is extremely slow. Please consider converting the list to a single numpy.ndarray with numpy.array() before converting to a tensor. r = torch.tensor(r).type(torch.get_default_dtype()) * Add PhaseDiagram. * Add PhaseDiagram. * PhaseDiagram update. * STM image pytest increase, requirements upgrade. * STM image pytest increase, requirements upgrade. * STM image pytest increase, requirements upgrade. * Compare atoms, get spg info directly from atoms. * Flake8 fix. * Update publications.rst * Update qiskit. * Update qiskit. * Update test_hermsolver.py * FIix qiskit DOS. * Update test_hermsolver.py * Fix linting. Co-authored-by: tavazza Co-authored-by: knc6 Co-authored-by: KAMAL CHOUDHARY Co-authored-by: wines1 <74620550+wines1@users.noreply.github.com> Co-authored-by: Saurav Maheshkar Co-authored-by: Janosh Riebesell --- DatasetSummary.rst | 15 -- dev-requirements.txt | 17 +- docs/requirements.txt | 17 +- docs/source/publications.rst | 6 +- jarvis/__init__.py | 2 +- jarvis/io/qiskit/inputs.py | 229 +++++++++--------- .../testfiles/io/qiskit/test_hermsolver.py | 91 ++++--- setup.py | 2 +- 8 files changed, 201 insertions(+), 178 deletions(-) delete mode 100644 DatasetSummary.rst diff --git a/DatasetSummary.rst b/DatasetSummary.rst deleted file mode 100644 index a6c0fba5..00000000 --- a/DatasetSummary.rst +++ /dev/null @@ -1,15 +0,0 @@ -* A summary of the projects - - =============== ======================================================================= - Projects Brief description - =============== ======================================================================= - ``JARVIS-DFT`` Density functional theory calculation database for ~40000 3D and ~1000 2D materials. Some of the material-properties include: Heat of formation, Crystal-structural data using OptB88vdW, PBE, LDA functionals, Bandgaps using semi-local, meta-GGA, HSE06 and other beyond DFT methods, Electron and phonon-bandstructures, Elastic, Piezoelectric, Thermoelectric, Dielectric tensors, Exfoliation energies for low-diemnsional materials, Frequency dependent dielectric function, Absorption coefficients, Work-function for 2D materials, Infrared and Raman intensities, Electric field gradient, Magnetic moment, Solar-cell efficiencies, Scanning Tunneling Microscopy (STM) images, Topological spin-orbit spillage, converged k-point and plane wave cut-offs, Wannier-tight binding Hamiltonian parameters and more. The website for JARVIS-DFT: https://www.ctcms.nist.gov/~knc6/JVASP.html - ``JARVIS-FF`` Classical molecular dynamics calculation database for ~2000 3D materials with interatomic potential/force-fields. Some of the properties included in JARVIS-FF are energetics, elastic constants, surface energies, defect formations energies and phonon frequencies of materials. The website for JARVIS-FF: https://www.ctcms.nist.gov/~knc6/periodic.html - ``JARVIS-ML`` Machine learning prediction tools trained on the JARVIS-DFT data. Some of the ML-prediction models are for Heat of formation, GGA/METAGGA bandgaps, Refractive indices, Bulk and shear modulus, Magnetic moment, Thermoelectric, Piezoelectric and Dielectric properties properties, Exfoliation energies, Solar-cell efficiency, and STM image classification. The website for JARVIS-ML: https://www.ctcms.nist.gov/jarvisml - ``JARVIS-Het.`` Heterostructure design tools for 2D materials in the JARVIS-DFT database. Some of the properties available are: work function, Band-alignment, and Heterostructure classification. JARVIS-Heterostructure website: https://www.ctcms.nist.gov/jarvish - ``JARVIS-PV`` Solar-cell/Photovoltaic cell design tools. Dataset is made available and the website will be available soon. - ``JARVIS-STM`` Scanning-tunneling microscopy images for 2D materials. https://jarvis.nist.gov/jarvisstm/. - ``JARVIS-WTB`` Wannier Tight Binding Hamiltonian parameter dataset. Website: https://www.ctcms.nist.gov/jarviswtb - ``JARVIS-EFG`` Electric field gradient dataset. Dataset will be made available and the website will be available soon. - ``Downloads`` Download raw metadat at: https://www.ctcms.nist.gov/~knc6/downloads.html - =============== ======================================================================= diff --git a/dev-requirements.txt b/dev-requirements.txt index 7e667921..e59d6d61 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -64,7 +64,7 @@ multitasking==0.0.10 networkx==2.6.3 ntlm-auth==1.5.0 numpy==1.22.0 -oauthlib==3.1.1 +oauthlib==3.2.1 opencv-python==4.5.4.60 opt-einsum==3.3.0 packaging==21.3 @@ -95,12 +95,13 @@ python-dateutil==2.8.2 pytz==2021.3 PyWavelets==1.2.0 PyYAML==6.0 -qiskit==0.30.1 -qiskit-aer==0.9.0 -qiskit-aqua==0.9.5 -qiskit-ibmq-provider==0.16.0 -qiskit-ignis==0.6.0 -qiskit-terra==0.18.3 +qiskit +#qiskit==0.30.1 +#qiskit-aer==0.9.0 +#qiskit-aqua==0.9.5 +#qiskit-ibmq-provider==0.16.0 +#qiskit-ignis==0.6.0 +#qiskit-terra==0.18.3 Quandl==3.7.0 requests==2.26.0 requests-ntlm==1.1.0 @@ -148,4 +149,4 @@ Werkzeug==2.0.2 wrapt==1.13.3 xmltodict==0.12.0 yfinance==0.1.67 -zipp==3.6.0 +zipp==3.6.0 \ No newline at end of file diff --git a/docs/requirements.txt b/docs/requirements.txt index b7eba6fa..e60dd07a 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -65,7 +65,7 @@ multitasking==0.0.10 networkx==2.6.3 ntlm-auth==1.5.0 numpy==1.22.0 -oauthlib==3.1.1 +oauthlib==3.2.1 opencv-python==4.5.4.60 opt-einsum==3.3.0 packaging==21.3 @@ -96,12 +96,13 @@ python-dateutil==2.8.2 pytz==2021.3 PyWavelets==1.2.0 PyYAML==6.0 -qiskit==0.30.1 -qiskit-aer==0.9.0 -qiskit-aqua==0.9.5 -qiskit-ibmq-provider==0.16.0 -qiskit-ignis==0.6.0 -qiskit-terra==0.18.3 +qiskit +#qiskit==0.30.1 +#qiskit-aer==0.9.0 +#qiskit-aqua==0.9.5 +#qiskit-ibmq-provider==0.16.0 +#qiskit-ignis==0.6.0 +#qiskit-terra==0.18.3 Quandl==3.7.0 requests==2.26.0 requests-ntlm==1.1.0 @@ -150,4 +151,4 @@ Werkzeug==2.0.2 wrapt==1.13.3 xmltodict==0.12.0 yfinance==0.1.67 -zipp==3.6.0 +zipp==3.6.0 \ No newline at end of file diff --git a/docs/source/publications.rst b/docs/source/publications.rst index 0806982c..0fbb205a 100644 --- a/docs/source/publications.rst +++ b/docs/source/publications.rst @@ -76,11 +76,13 @@ JARVIS-ML related [32. Rapid Prediction of Phonon Structure and Properties using an Atomistic Line Graph Neural Network (ALIGNN)](https://arxiv.org/abs/2207.12510) +[33. Unified Graph Neural Network Force-field for the Periodic Table](https://arxiv.org/abs/2209.05554) + JARVIS-QC related ----------------------------------------------------- -[33. Quantum Computation for Predicting Electron and Phonon Properties of Solids., J. Phys.: Cond. Matt.](https://iopscience.iop.org/article/10.1088/1361-648X/ac1154) +[34. Quantum Computation for Predicting Electron and Phonon Properties of Solids., J. Phys.: Cond. Matt.](https://iopscience.iop.org/article/10.1088/1361-648X/ac1154) JARVIS-QETB related ----------------------------------------------------- -[34. Fast and Accurate Prediction of Material Properties with Three-Body Tight-Binding Model for the Periodic Table](https://arxiv.org/abs/2112.11585) +[35. Fast and Accurate Prediction of Material Properties with Three-Body Tight-Binding Model for the Periodic Table](https://arxiv.org/abs/2112.11585) diff --git a/jarvis/__init__.py b/jarvis/__init__.py index 24e5607e..a3ab81bd 100644 --- a/jarvis/__init__.py +++ b/jarvis/__init__.py @@ -1,5 +1,5 @@ """Version number.""" -__version__ = "2022.08.27" +__version__ = "2022.09.16" import os diff --git a/jarvis/io/qiskit/inputs.py b/jarvis/io/qiskit/inputs.py index 2737abb4..63c958ea 100644 --- a/jarvis/io/qiskit/inputs.py +++ b/jarvis/io/qiskit/inputs.py @@ -1,28 +1,59 @@ -"""Module to solve Hermitian Matrix.""" -# Reference: https://arxiv.org/abs/2102.11452 -import numpy as np -from qiskit import aqua +"""Module to solve Hermitian Matrix and predict badstructures.""" +# Reference: https://doi.org/10.1088/1361-648X/ac1154 -from jarvis.core.kpoints import generate_kgrid +import numpy as np +import itertools +import functools from qiskit import Aer - -# from qiskit.circuit.library import EfficientSU2 -import matplotlib.pyplot as plt +from qiskit.utils import QuantumInstance, algorithm_globals +from qiskit.opflow import I, X, Y, Z +from qiskit.algorithms import VQE from jarvis.core.kpoints import Kpoints3D as Kpoints from jarvis.db.figshare import get_hk_tb +from jarvis.core.kpoints import generate_kgrid +import matplotlib.pyplot as plt plt.switch_backend("agg") +# from qiskit.algorithms.optimizers import SLSQP + + +def decompose_Hamiltonian(H): + """Decompose Hermitian matrix into Pauli basis.""" + # Inspired from + # https://github.com/PennyLaneAI/pennylane/blob/master/pennylane/utils.py#L45 + # https://qiskit.org/documentation/tutorials/algorithms/04_vqe_advanced.html + x, y = H.shape + N = int(np.log2(len(H))) + if len(H) - 2 ** N != 0 or x != y: + raise ValueError( + "Hamiltonian should be in the form (2^n x 2^n), for any n>=1" + ) + pauilis = [I, X, Y, Z] + decomposedH = 0 + for term in itertools.product(pauilis, repeat=N): + matrices = [i.to_matrix() for i in term] + # coefficient of the pauli string = (1/2^N) * (Tr[pauliOp x H]) + coeff = np.trace(functools.reduce(np.kron, matrices) @ H) / (2 ** N) + coeff = np.real_if_close(coeff).item() + if coeff == 0: + continue + obs = 1 + for i in term: + obs = obs ^ i + decomposedH += coeff * obs + return decomposedH class HermitianSolver(object): """Solve a Hermitian matrix using quantum algorithms.""" - def __init__(self, mat=[]): + def __init__(self, mat=[], verbose=False): """Initialize with a numpy Hermitian matrix.""" N = int(np.ceil(np.log2(len(mat)))) hk = np.zeros((2 ** N, 2 ** N), dtype="complex") hk[: mat.shape[0], : mat.shape[1]] = mat self.mat = hk + self.verbose = verbose if not self.check_hermitian(): raise ValueError("Only implemented for Hermitian matrix.") @@ -44,19 +75,27 @@ def run_vqe( mode="min_val", ): """Run variational quantum eigensolver.""" - # N=int(np.ceil(np.log2(len(self.mat)))) - # hk = np.zeros((2**N,2**N),dtype='complex') - # hk[:self.mat.shape[0], :self.mat.shape[1]] = self.mat + seed = 50 + algorithm_globals.random_seed = seed N = self.n_qubits() + qi = QuantumInstance( + Aer.get_backend("statevector_simulator"), + seed_transpiler=seed, + seed_simulator=seed, + ) + # n_qubits = self.n_qubits + if mode == "max_val": - Hamil_mat = aqua.operators.MatrixOperator(-1 * self.mat) - # Hamil_mat = MatrixOperator(-1 * self.mat) + Hamil_qop = decompose_Hamiltonian(-1 * self.mat) + np_eig = min(np.linalg.eig(-1 * self.mat)[0]) + if self.verbose: + print("np_eig", np_eig) else: - Hamil_mat = aqua.operators.MatrixOperator(self.mat) - # Hamil_mat = MatrixOperator(self.mat) - Hamil_qop = aqua.operators.op_converter.to_weighted_pauli_operator( - Hamil_mat - ) + Hamil_qop = decompose_Hamiltonian(self.mat) + np_eig = min(np.linalg.eig(self.mat)[0]) + if self.verbose: + print("np_eig", np_eig) + if var_form is None: if reps is None: reps = 2 @@ -65,46 +104,40 @@ def run_vqe( var_form = EfficientSU2(N, reps=reps) if optimizer is None: - vqe = aqua.algorithms.VQE(Hamil_qop, var_form) - # vqe = VQE(Hamil_qop, var_form) + vqe = VQE(var_form, quantum_instance=qi) + else: - vqe = aqua.algorithms.VQE(Hamil_qop, var_form, optimizer) - # vqe = VQE(Hamil_qop, var_form, optimizer) - vqe_result = vqe.run(backend) - en = np.real(vqe_result["eigenvalue"]) - # params=vqe.optimal_params - # circuit=vqe.construct_circuit(params) + vqe = VQE(var_form, optimizer=optimizer, quantum_instance=qi) + result = vqe.compute_minimum_eigenvalue(operator=Hamil_qop) + en = result.eigenvalue + if mode == "max_val": en = -1 * en - # states = np.sort( - # np.real( - # vqe.expectation.convert( - # StateFn(vqe.operator, is_measurement=True) - # ).to_matrix() - # ) - # ) - return en, vqe_result, vqe + + return en, result, vqe def run_numpy(self): """Obtain eigenvalues and vecs using Numpy solvers.""" return np.linalg.eigh(self.mat) - def run_qpe(self, n_ancillae=8): - """Run quantum phase estimations.""" - quantum_instance = aqua.QuantumInstance( - backend=Aer.get_backend("statevector_simulator"), shots=1 - ) - Hamil_mat = aqua.operators.MatrixOperator(self.mat) - # Hamil_mat = MatrixOperator(self.mat) - Hamil_qop = aqua.operators.op_converter.to_weighted_pauli_operator( - Hamil_mat - ) - # Hamil_qop = op_converter.to_weighted_pauli_operator(Hamil_mat) - qpe = aqua.algorithms.QPE(Hamil_qop, num_ancillae=n_ancillae) - qpe_result = qpe.run(quantum_instance) - # qc = qpe.construct_circuit(measurement=True) - print("qpe_result", qpe_result) - return qpe_result["eigenvalue"], qpe_result, qpe + # def run_qpe(self, n_ancillae=8): + # """Run quantum phase estimations.""" + # quantum_instance = aqua.QuantumInstance( + # backend=Aer.get_backend("statevector_simulator"), shots=1 + # ) + # Hamil_mat = aqua.operators.MatrixOperator(self.mat) + # # Hamil_mat = MatrixOperator(self.mat) + # #Hamil_qop = aqua.operators.op_converter.to_weighted_pauli_operator( + # # Hamil_mat + # #) + # # Hamil_qop = op_converter.to_weighted_pauli_operator(Hamil_mat) + + # Hamil_qop = decompose_Hamiltonian(self.mat) + # qpe = aqua.algorithms.QPE(Hamil_qop, num_ancillae=n_ancillae) + # qpe_result = qpe.run(quantum_instance) + # # qc = qpe.construct_circuit(measurement=True) + # print("qpe_result", qpe_result) + # return qpe_result["eigenvalue"], qpe_result, qpe def run_vqd( self, @@ -125,6 +158,8 @@ def run_vqd( ) eigvals = [max_eigval] eigstates = [vqe_result.eigenstate] + # eigvals = [] + # eigstates= [] for r in range(len(tmp.mat) - 1): val, vqe_result, vqe = tmp.run_vqe( backend=backend, @@ -153,7 +188,7 @@ def get_bandstruct( atoms={}, ef=0, line_density=1, - ylabel="Energy (cm-1)", + ylabel="eV", # "Energy ($cm^{-1}$)", font=22, var_form=None, filename="bands.png", @@ -161,13 +196,16 @@ def get_bandstruct( neigs=None, max_nk=None, tol=None, + factor=1, + verbose=False, ): """Compare bandstructures using quantum algos.""" info = {} kpoints = Kpoints().kpath(atoms, line_density=line_density) labels = kpoints.to_dict()["labels"] kpts = kpoints.to_dict()["kpoints"] - print("kpts", len(kpts)) + if verbose: + print("Number of kpoints:", len(kpts)) eigvals_q = [] eigvals_np = [] @@ -178,13 +216,15 @@ def get_bandstruct( print("breaking here", ii, max_nk) else: try: - print("kp=", ii, i) + hk = get_hk_tb(w=w, k=i) HS = HermitianSolver(hk) vqe_vals, _ = HS.run_vqd(var_form=var_form) np_vals, _ = HS.run_numpy() - print("np_vals", np_vals) - print("vqe_vals", vqe_vals) + if verbose: + print("kp=", ii, i) + print("np_vals", np_vals) + print("vqe_vals", vqe_vals) eigvals_q.append(vqe_vals) eigvals_np.append(np_vals) # break @@ -197,20 +237,20 @@ def get_bandstruct( except Exception as exp: print(exp) pass - eigvals_q = 3.14 * np.array(eigvals_q) - eigvals_np = 3.14 * np.array(eigvals_np) + eigvals_q = factor * np.array(eigvals_q) # 3.14 for phonon + eigvals_np = factor * np.array(eigvals_np) for ii, i in enumerate(eigvals_q.T - ef): if ii == 0: - plt.plot(i, c="b", label="VQD") + plt.plot(i, "*", c="b", label="VQD") else: - plt.plot(i, c="b") + plt.plot(i, "*", c="b") for ii, i in enumerate(eigvals_np.T - ef): if ii == 0: - plt.plot(i, c="r", label="Numpy") + plt.plot(i, c="g", label="Numpy") else: - plt.plot(i, c="r") + plt.plot(i, c="g") new_kp = [] new_labels = [] count = 0 @@ -231,7 +271,8 @@ def get_bandstruct( info["new_kp"] = list(np.array(new_kp).tolist()) info["new_labels"] = list(new_labels) info["ef"] = ef - print(info) + if verbose: + print(info) if tol is not None: plt.ylim([tol, np.max(eigvals_q)]) plt.rcParams.update({"font.size": font}) @@ -266,7 +307,7 @@ def get_dos( nk = len(kpoints) q_vals = np.zeros((nk, nwan), dtype=float) np_vals = np.zeros((nk, nwan), dtype=float) - pvals = np.zeros((nk, nwan), dtype=float) + pvals = np.zeros((nk, nwan - 1), dtype=float) # if use_dask: # def get_vqd_vals(k): # hk = get_hk_tb(w=w, k=k) @@ -281,10 +322,10 @@ def get_dos( HS = HermitianSolver(hk) vqe_vals, _ = HS.run_vqd() n_vals, _ = HS.run_numpy() + print("np_vals", n_vals, len(n_vals), np_vals.shape) + print("vqe_vals", vqe_vals, len(vqe_vals), q_vals.shape) q_vals[i, :] = vqe_vals np_vals[i, :] = n_vals - print("np_vals", n_vals) - print("vqe_vals", vqe_vals) if xrange is None: vmin = np.min(q_vals[:]) @@ -295,9 +336,7 @@ def get_dos( # plt.xlim(xrange) energies = np.arange( - xrange[0], - xrange[1] + 1e-5, - (xrange[1] - xrange[0]) / float(nenergy), + xrange[0], xrange[1] + 1e-5, (xrange[1] - xrange[0]) / float(nenergy), ) dos = np.zeros(np.size(energies)) pdos = np.zeros(np.size(energies)) @@ -323,53 +362,25 @@ def get_dos( if proj is not None: print("np.sum(pdos) ", np.sum(pdos * de)) plt.plot(energies, dos) - plt.savefig(filename) - plt.close() + if savefig: + plt.savefig(filename) + plt.close() + else: + plt.show() return energies, dos, pdos """ if __name__ == "__main__": from jarvis.db.figshare import ( - get_wann_phonon, - get_hk_tb, get_wann_electron, + get_wann_phonon, ) - from jarvis.core.atoms import Atoms - from jarvis.db.jsonutils import dumpjson - - w, ef, atoms = get_wann_electron("JVASP-816") - info = get_bandstruct( - w=w, - line_density=5, - atoms=atoms, - ef=ef, - filename="Alelect.png", - ylabel="Energy (eV)", - ) - dumpjson(data=info, filename="Alelect.json") - w, atoms = get_wann_phonon("JVASP-54", factor=34.3) - info = get_bandstruct( - w=w, - line_density=11, - atoms=atoms, - tol=0.1, - filename="Alphon.png", - ylabel="Freq.(cm$^{-1}$)", - ) - # dumpjson(data=info,filename='Alphon.json') - hk = get_hk_tb(w=w, k=[0.0, 0.0, 0.0]) + from jarvis.core.circuits import QuantumCircuitLibrary + + wtbh, ef, atoms = get_wann_electron("JVASP-816") + hk = get_hk_tb(w=wtbh, k=[0.0, 0.0, 0.0]) H = HermitianSolver(hk) - en, vqe_result, vqe = H.run_vqe(mode="max_val") - print("en=", en) - # eigs,vecs=H.run_vqd() - # print(eigs) - # print(vecs) - - # eigs, vecs = H.run_numpy() - # print(eigs) - # print(vecs) - # get_bandstruct(w=w, atoms=atoms, tol=0.1) - # get_dos(w=w) - # H.run_qpe() + qc = QuantumCircuitLibrary(n_qubits=3).circuit6() # 2^3 = 8 + en, vqe_result, vqe = H.run_vqe(mode="min_val", var_form=qc) """ diff --git a/jarvis/tests/testfiles/io/qiskit/test_hermsolver.py b/jarvis/tests/testfiles/io/qiskit/test_hermsolver.py index 29af7f66..f6784e9c 100644 --- a/jarvis/tests/testfiles/io/qiskit/test_hermsolver.py +++ b/jarvis/tests/testfiles/io/qiskit/test_hermsolver.py @@ -1,5 +1,5 @@ # -#from qiskit.circuit.library import EfficientSU2 +# from qiskit.circuit.library import EfficientSU2 from qiskit.circuit import QuantumCircuit from qiskit import circuit from jarvis.db.figshare import ( @@ -9,12 +9,14 @@ ) from jarvis.core.atoms import Atoms from jarvis.db.jsonutils import dumpjson -from jarvis.io.qiskit.inputs import HermitianSolver,get_bandstruct,get_dos +from jarvis.io.qiskit.inputs import HermitianSolver, get_bandstruct, get_dos import matplotlib.pyplot as plt -plt.switch_backend('agg') + +plt.switch_backend("agg") from qiskit.circuit import QuantumCircuit, ParameterVector from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister -from qiskit import aqua + +# from qiskit import aqua import numpy as np from qiskit import Aer, execute @@ -23,19 +25,38 @@ gc.collect() -def nCr(n,r): + +def nCr(n, r): f = math.factorial - return int(f(n) / f(r) / f(n-r)) + return int(f(n) / f(r) / f(n - r)) + + +# def test_hermitian_solver(): +# from jarvis.db.figshare import ( +# get_wann_electron, +# get_wann_phonon, +# ) +# from jarvis.core.circuits import QuantumCircuitLibrary + +# wtbh, ef, atoms = get_wann_electron("JVASP-816") +# hk = get_hk_tb(w=wtbh, k=[0.0, 0.0, 0.0]) +# H = HermitianSolver(hk) +# qc = QuantumCircuitLibrary(n_qubits=3).circuit6() # 2^3 = 8 +# en, vqe_result, vqe = H.run_vqe(mode="min_val", var_form=qc) + -def variational_circuit(num_qubits = 2,reps = 1): +def variational_circuit(num_qubits=2, reps=1): # import required qiskit libraries if additional libraries are required # build the variational circuit - #var_circuit = EfficientSU2(num_qubits=3, su2_gates= ['rx', 'ry'], entanglement='circular', reps=3) - #var_circuit = EfficientSU2(num_qubits=4, su2_gates= ['rx', 'ry'], entanglement='circular', reps=3) - + # var_circuit = EfficientSU2(num_qubits=3, su2_gates= ['rx', 'ry'], entanglement='circular', reps=3) + # var_circuit = EfficientSU2(num_qubits=4, su2_gates= ['rx', 'ry'], entanglement='circular', reps=3) + # return the variational circuit which is either a VaritionalForm or QuantumCircuit object from qiskit.circuit import QuantumCircuit, ParameterVector - x = ParameterVector('x', length=num_qubits) # creating a list of Parameters + + x = ParameterVector( + "x", length=num_qubits + ) # creating a list of Parameters custom_circ = QuantumCircuit(num_qubits) # defining our parametric form @@ -47,33 +68,33 @@ def variational_circuit(num_qubits = 2,reps = 1): custom_circ.cx(i, j) custom_circ.u1(x[i] * x[j], j) custom_circ.cx(i, j) - - - - - -qc=variational_circuit() + +qc = variational_circuit() + def test_inp(): w, ef, atoms = get_wann_electron("JVASP-816") -# info = get_bandstruct( -# w=w, -# line_density=1, -# atoms=atoms, -# ef=ef, -# filename="Alelect.png", -# ylabel="Energy (eV)", -# ) - #dumpjson(data=info, filename="Alelect.json") + # info = get_bandstruct( + # w=w, + # line_density=1, + # atoms=atoms, + # ef=ef, + # filename="Alelect.png", + # ylabel="Energy (eV)", + # ) + # dumpjson(data=info, filename="Alelect.json") w, atoms = get_wann_phonon("JVASP-816", factor=34.3) hk = get_hk_tb(w=w, k=[0.0, 0.0, 0.0]) - print ('shape=',hk.shape) + print("shape=", hk.shape) H = HermitianSolver(hk) from jarvis.core.circuits import QuantumCircuitLibrary - qc=QuantumCircuitLibrary(n_qubits=2).circuit1() - #en, vqe_result, vqe = H.run_vqe(mode="max_val", reps=1)#,optimizer=optimizer) - en, vqe_result, vqe = H.run_vqe(mode="max_val", var_form=qc)#,optimizer=optimizer) + + qc = QuantumCircuitLibrary(n_qubits=2).circuit1() + # en, vqe_result, vqe = H.run_vqe(mode="max_val", reps=1)#,optimizer=optimizer) + en, vqe_result, vqe = H.run_vqe( + mode="max_val", var_form=qc + ) # ,optimizer=optimizer) print("en=", en) info = get_bandstruct( w=w, @@ -86,7 +107,7 @@ def test_inp(): ylabel="Freq.(cm$^{-1}$)", ) ## dumpjson(data=info,filename='Alphon.json') - #eigs,vecs=H.run_vqd() + # eigs,vecs=H.run_vqd() # print(eigs) # print(vecs) @@ -94,6 +115,8 @@ def test_inp(): print(eigs) # print(vecs) # get_bandstruct(w=w, atoms=atoms, tol=0.1) - get_dos(w=w,grid=[2,1,1]) - H.run_qpe() -#test_inp() + get_dos(w=w, grid=[2, 1, 1]) + # H.run_qpe() + + +# test_inp() diff --git a/setup.py b/setup.py index 0259a0a8..d79cee4f 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ setup( name="jarvis-tools", - version="2022.08.27", + version="2022.09.16", long_description=long_d, install_requires=[ "numpy>=1.19.5",