diff --git a/.github/workflows/action_build.yml b/.github/workflows/action_build.yml index 13b5ec29..a32b8d3e 100644 --- a/.github/workflows/action_build.yml +++ b/.github/workflows/action_build.yml @@ -23,17 +23,20 @@ jobs: - name: Install requirements run: | + find . -type f > before_test_files.txt pip install --upgrade pip pip install pycodestyle flake8 pydocstyle flake8 --ignore E203,W503 --exclude=examples,tests --statistics --count --exit-zero jarvis pycodestyle --ignore E203,W503 --exclude=examples,testfiles jarvis pydocstyle --match-dir=core --match-dir=io --match-dir=io --match-dir=ai --match-dir=analysis --match-dir=db --match-dir=tasks --count jarvis - + #python setup.py develop #pip install --upgrade --upgrade-strategy eager -r dev-requirements.txt -e . #conda install -c ambermd pytraj - pip install numpy scipy matplotlib - pip install -r dev-requirements.txt + conda install pandas numpy matplotlib --quiet + conda env create -f environment.yml + #pip install numpy scipy matplotlib + #pip install -r dev-requirements.txt pip install -e . echo 'CONDA LIST' conda list @@ -49,6 +52,11 @@ jobs: coverage report -m -i codecov codecov --token="b61081a0-39de-44a8-8a9c-97d4be82af6d" + find . -type f > after_test_files.txt + #comm -13 <(sort before_test_files.txt) <(sort after_test_files.txt) > new_files.txt + #cat new_files.txt | xargs rm + #rm before_test_files.txt after_test_files.txt new_files.txt + # git clone https://github.com/QEF/q-e.git # cd q-e # ./configure @@ -149,4 +157,4 @@ jobs: # # git clone https://github.com/QEF/q-e.git # # cd q-e # # ./configure -# # make pw \ No newline at end of file +# # make pw diff --git a/environment.yml b/environment.yml new file mode 100644 index 00000000..f35d8c1f --- /dev/null +++ b/environment.yml @@ -0,0 +1,274 @@ +name: my_jarvis +channels: + - conda-forge + - defaults +dependencies: + - _libgcc_mutex=0.1=conda_forge + - _openmp_mutex=4.5=2_gnu + - alsa-lib=1.2.11=hd590300_1 + - archspec=0.2.2=pyhd8ed1ab_0 + - attr=2.5.1=h166bdaf_1 + - boltons=23.1.1=pyhd8ed1ab_0 + - brotli=1.1.0=hd590300_1 + - brotli-bin=1.1.0=hd590300_1 + - brotli-python=1.1.0=py310hc6cd4ac_1 + - bzip2=1.0.8=hd590300_5 + - c-ares=1.24.0=hd590300_0 + - ca-certificates=2024.2.2=hbcca054_0 + - cairo=1.18.0=h3faef2a_0 + - certifi=2024.2.2=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 + - contourpy=1.2.0=py310hd41b1e2_0 + - cycler=0.12.1=pyhd8ed1ab_0 + - dbus=1.13.6=h5008d03_3 + - distro=1.8.0=pyhd8ed1ab_0 + - expat=2.6.2=h59595ed_0 + - fmt=10.1.1=h00ab1b0_1 + - font-ttf-dejavu-sans-mono=2.37=hab24e00_0 + - font-ttf-inconsolata=3.000=h77eed37_0 + - font-ttf-source-code-pro=2.038=h77eed37_0 + - font-ttf-ubuntu=0.83=h77eed37_1 + - fontconfig=2.14.2=h14ed4e7_0 + - fonts-conda-ecosystem=1=0 + - fonts-conda-forge=1=0 + - fonttools=4.50.0=py310h2372a71_0 + - freetype=2.12.1=h267a509_2 + - gettext=0.21.1=h27087fc_0 + - glib=2.80.0=hf2295e7_0 + - glib-tools=2.80.0=hde27a5a_0 + - graphite2=1.3.13=h58526e2_1001 + - gst-plugins-base=1.22.9=h8e1006c_0 + - gstreamer=1.22.9=h98fc4e7_0 + - harfbuzz=8.3.0=h3d44ed6_0 + - 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 + - kiwisolver=1.4.5=py310hd41b1e2_1 + - krb5=1.21.2=h659d440_0 + - lame=3.100=h166bdaf_1003 + - lcms2=2.16=hb7c19ff_0 + - ld_impl_linux-64=2.40=h41732ed_0 + - lerc=4.0.0=h27087fc_0 + - libarchive=3.7.2=h2aa1ff5_1 + - libblas=3.9.0=21_linux64_openblas + - libbrotlicommon=1.1.0=hd590300_1 + - libbrotlidec=1.1.0=hd590300_1 + - libbrotlienc=1.1.0=hd590300_1 + - libcap=2.69=h0f662aa_0 + - libcblas=3.9.0=21_linux64_openblas + - libclang=15.0.7=default_hb11cfb5_4 + - libclang13=15.0.7=default_ha2b6cf4_4 + - libcups=2.3.3=h4637d8d_4 + - libcurl=8.5.0=hca28451_0 + - libdeflate=1.19=hd590300_0 + - libedit=3.1.20191231=he28a2e2_2 + - libev=4.33=hd590300_2 + - libevent=2.1.12=hf998b51_1 + - libexpat=2.6.2=h59595ed_0 + - libffi=3.4.2=h7f98852_5 + - libflac=1.4.3=h59595ed_0 + - libgcc-ng=13.2.0=h807b86a_3 + - libgcrypt=1.10.3=hd590300_0 + - libgfortran-ng=13.2.0=h69a702a_5 + - libgfortran5=13.2.0=ha4646dd_5 + - libglib=2.80.0=hf2295e7_0 + - libgomp=13.2.0=h807b86a_3 + - libgpg-error=1.48=h71f35ed_0 + - libiconv=1.17=hd590300_2 + - libjpeg-turbo=3.0.0=hd590300_1 + - liblapack=3.9.0=21_linux64_openblas + - libllvm15=15.0.7=hb3ce162_4 + - libmamba=1.5.5=had39da4_0 + - libmambapy=1.5.5=py310h39ff949_0 + - libnghttp2=1.58.0=h47da74e_1 + - libnsl=2.0.1=hd590300_0 + - libogg=1.3.4=h7f98852_1 + - libopenblas=0.3.26=pthreads_h413a1c8_0 + - libopus=1.3.1=h7f98852_1 + - libpng=1.6.43=h2797004_0 + - libpq=16.2=h33b98f1_1 + - libsndfile=1.2.2=hc60ed4a_1 + - 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 + - libsystemd0=255=h3516f8a_1 + - libtiff=4.6.0=ha9c0a0a_2 + - libuuid=2.38.1=h0b41bf4_0 + - libvorbis=1.3.7=h9c3ff4c_0 + - libwebp-base=1.3.2=hd590300_0 + - libxcb=1.15=h0b41bf4_0 + - libxkbcommon=1.6.0=hd429924_1 + - 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 + - matplotlib=3.8.3=py310hff52083_0 + - matplotlib-base=3.8.3=py310h62c0568_0 + - menuinst=2.0.1=py310hff52083_0 + - mpg123=1.32.4=h59595ed_0 + - munkres=1.1.4=pyh9f0ad1d_0 + - mysql-common=8.0.33=hf1915f5_6 + - mysql-libs=8.0.33=hca2cd23_6 + - ncurses=6.4=h59595ed_2 + - nspr=4.35=h27087fc_0 + - nss=3.97=h1d7d5a4_0 + - openjpeg=2.5.2=h488ebb8_0 + - openssl=3.2.1=hd590300_1 + - packaging=23.2=pyhd8ed1ab_0 + - pandas=2.2.1=py310hcc13569_0 + - pcre2=10.43=hcad00b1_0 + - pillow=10.2.0=py310h01dd4db_0 + - pip=23.3.2=pyhd8ed1ab_0 + - pixman=0.43.2=h59595ed_0 + - platformdirs=4.1.0=pyhd8ed1ab_0 + - ply=3.11=py_1 + - pthread-stubs=0.4=h36c2ea0_1001 + - pulseaudio-client=16.1=hb77b528_5 + - pybind11-abi=4=hd8ed1ab_3 + - pycosat=0.6.6=py310h2372a71_0 + - pycparser=2.21=pyhd8ed1ab_0 + - pyparsing=3.1.2=pyhd8ed1ab_0 + - pyqt=5.15.9=py310h04931ad_5 + - pyqt5-sip=12.12.2=py310hc6cd4ac_5 + - pysocks=1.7.1=pyha2e5f31_6 + - python=3.10.13=hd12c33a_0_cpython + - python-tzdata=2024.1=pyhd8ed1ab_0 + - python_abi=3.10=4_cp310 + - pytz=2024.1=pyhd8ed1ab_0 + - qt-main=5.15.8=h450f30e_18 + - readline=8.2=h8228510_1 + - reproc=14.2.4.post0=hd590300_1 + - reproc-cpp=14.2.4.post0=h59595ed_1 + - ruamel.yaml=0.18.5=py310h2372a71_0 + - ruamel.yaml.clib=0.2.7=py310h2372a71_2 + - setuptools=68.2.2=pyhd8ed1ab_0 + - sip=6.7.12=py310hc6cd4ac_0 + - six=1.16.0=pyh6c4a22f_0 + - tk=8.6.13=noxft_h4845f30_101 + - toml=0.10.2=pyhd8ed1ab_0 + - tomli=2.0.1=pyhd8ed1ab_0 + - tornado=6.4=py310h2372a71_0 + - tqdm=4.66.1=pyhd8ed1ab_0 + - truststore=0.8.0=pyhd8ed1ab_0 + - tzdata=2023c=h71feb2d_0 + - unicodedata2=15.1.0=py310h2372a71_0 + - wheel=0.42.0=pyhd8ed1ab_0 + - xcb-util=0.4.0=hd590300_1 + - xcb-util-image=0.4.0=h8ee46fc_1 + - xcb-util-keysyms=0.4.0=h8ee46fc_1 + - xcb-util-renderutil=0.3.9=hd590300_1 + - xcb-util-wm=0.4.1=h8ee46fc_1 + - xkeyboard-config=2.41=hd590300_0 + - xorg-kbproto=1.0.7=h7f98852_1002 + - xorg-libice=1.1.1=hd590300_0 + - xorg-libsm=1.2.4=h7391055_0 + - xorg-libx11=1.8.7=h8ee46fc_0 + - xorg-libxau=1.0.11=hd590300_0 + - xorg-libxdmcp=1.1.3=h7f98852_0 + - xorg-libxext=1.3.4=h0b41bf4_2 + - xorg-libxrender=0.9.11=hd590300_0 + - xorg-renderproto=0.11.1=h7f98852_1002 + - xorg-xextproto=7.3.0=h0b41bf4_1003 + - xorg-xf86vidmodeproto=2.3.1=h7f98852_1002 + - xorg-xproto=7.0.31=h7f98852_1007 + - xz=5.2.6=h166bdaf_0 + - yaml-cpp=0.8.0=h59595ed_0 + - zlib=1.2.13=hd590300_5 + - zstandard=0.22.0=py310h1275a96_0 + - zstd=1.5.5=hfc55251_0 + - pip: + - annotated-types==0.6.0 + - appdirs==1.4.4 + - autograd==1.6.2 + - babel==2.14.0 + - bokeh==2.4.2 + - cif2cell==2.1.0 + - click==8.1.7 + - coverage==7.4.4 + - cryptography==42.0.5 + - dgl==2.1.0 + - dill==0.3.8 + - exceptiongroup==1.2.0 + - filelock==3.13.1 + - fsspec==2024.3.1 + - future==1.0.0 + - ghp-import==2.1.0 + - h5py==3.10.0 + - iniconfig==2.0.0 + - jinja2==3.1.3 + - joblib==1.3.2 + - lightgbm==3.3.1 + - markdown==3.6 + - markupsafe==2.1.5 + - mergedeep==1.3.4 + - mkdocs==1.5.3 + - mkdocs-material==9.5.14 + - mkdocs-material-extensions==1.3.1 + - mpmath==1.3.0 + - networkx==3.2.1 + - ntlm-auth==1.5.0 + - numpy==1.23.5 + - nvidia-cublas-cu12==12.1.3.1 + - nvidia-cuda-cupti-cu12==12.1.105 + - nvidia-cuda-nvrtc-cu12==12.1.105 + - nvidia-cuda-runtime-cu12==12.1.105 + - nvidia-cudnn-cu12==8.9.2.26 + - nvidia-cufft-cu12==11.0.2.54 + - nvidia-curand-cu12==10.3.2.106 + - nvidia-cusolver-cu12==11.4.5.107 + - nvidia-cusparse-cu12==12.1.0.106 + - nvidia-nccl-cu12==2.19.3 + - nvidia-nvjitlink-cu12==12.4.99 + - nvidia-nvtx-cu12==12.1.105 + - paginate==0.5.6 + - pathspec==0.12.1 + - pbr==6.0.0 + - pennylane==0.14.1 + - phonopy==2.10.0 + - pluggy==1.4.0 + - psutil==5.9.8 + - pycifrw==4.4.6 + - pydantic==2.6.4 + - pydantic-core==2.16.3 + - pygments==2.17.2 + - pymdown-extensions==10.7.1 + - pytest==8.1.1 + - python-dateutil==2.8.2 + - pyyaml==6.0.1 + - pyyaml-env-tag==0.1 + - qiskit==0.41.1 + - qiskit-aer==0.11.2 + - qiskit-ibmq-provider==0.20.1 + - qiskit-terra==0.23.2 + - regex==2023.12.25 + - requests==2.28.2 + - requests-ntlm==1.1.0 + - rustworkx==0.14.2 + - scikit-learn==1.4.1.post1 + - scipy==1.12.0 + - semantic-version==2.6.0 + - spglib==2.3.1 + - stevedore==5.2.0 + - symengine==0.11.0 + - sympy==1.12 + - threadpoolctl==3.3.0 + - toolz==0.12.1 + - torch==2.2.1 + - torchdata==0.7.1 + - triton==2.2.0 + - typing-extensions==4.10.0 + - urllib3==1.26.18 + - watchdog==4.0.0 + - websocket-client==1.5.3 + - websockets==10.4 + - xmltodict==0.13.0 diff --git a/jarvis/core/graphs.py b/jarvis/core/graphs.py index 8229ffa0..b3295e48 100644 --- a/jarvis/core/graphs.py +++ b/jarvis/core/graphs.py @@ -1,4 +1,5 @@ """Module to generate networkx graphs.""" + from jarvis.core.atoms import get_supercell_dims from jarvis.core.specie import Specie from jarvis.core.utils import random_colors @@ -11,18 +12,16 @@ # from jarvis.core.atoms import Atoms from collections import defaultdict from typing import List, Tuple, Sequence, Optional - -try: - import torch - from tqdm import tqdm - import dgl -except Exception as exp: - print("dgl/torch/tqdm is not installed.", exp) - pass +import torch +from tqdm import tqdm +import dgl def canonize_edge( - src_id, dst_id, src_image, dst_image, + src_id, + dst_id, + src_image, + dst_image, ): """Compute canonical edge representation. @@ -46,7 +45,11 @@ def canonize_edge( def nearest_neighbor_edges( - atoms=None, cutoff=8, max_neighbors=12, id=None, use_canonize=False, + atoms=None, + cutoff=8, + max_neighbors=12, + id=None, + use_canonize=False, ): """Construct k-NN edge list.""" # returns List[List[Tuple[site, distance, index, image]]] @@ -118,7 +121,8 @@ def nearest_neighbor_edges( def build_undirected_edgedata( - atoms=None, edges={}, + atoms=None, + edges={}, ): """Build undirected graph data from edge set. diff --git a/jarvis/tests/testfiles/io/qiskit/test_hermsolver.py b/jarvis/tests/testfiles/io/qiskit/test_hermsolver.py index e034c590..39c39825 100644 --- a/jarvis/tests/testfiles/io/qiskit/test_hermsolver.py +++ b/jarvis/tests/testfiles/io/qiskit/test_hermsolver.py @@ -1,3 +1,85 @@ +from qiskit import Aer +from qiskit.utils import QuantumInstance, algorithm_globals +from qiskit.algorithms import VQE +from qiskit.algorithms.optimizers import SLSQP +import numpy as np +import itertools, functools +from qiskit.opflow import I, X, Y, Z +from jarvis.db.figshare import get_wann_electron, get_wann_phonon, get_hk_tb +from jarvis.core.circuits import QuantumCircuitLibrary +from jarvis.io.qiskit.inputs import HermitianSolver +from qiskit import Aer + + +def decompose_Hamiltonian(H): + # 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 + + +def test_qiskit(): + wtbh, Ef, atoms = get_wann_electron("JVASP-816") + kpt = [0.5, 0.0, 0.5] # X-point + hk = get_hk_tb(w=wtbh, k=kpt) + wtbh_op = decompose_Hamiltonian(hk) + + seed = 50 + algorithm_globals.random_seed = seed + qi = QuantumInstance( + Aer.get_backend("statevector_simulator"), + seed_transpiler=seed, + seed_simulator=seed, + ) + n_qubits = int(np.log2(len(hk))) + # ansatz = TwoLocal(rotation_blocks='ry', entanglement_blocks='cz') + ansatz = QuantumCircuitLibrary(n_qubits=n_qubits, reps=1).circuit6() + slsqp = SLSQP(maxiter=1000) + vqe = VQE(ansatz, optimizer=slsqp, quantum_instance=qi) + result = vqe.compute_minimum_eigenvalue(operator=wtbh_op) + np_eig = min(np.linalg.eig(hk)[0]) + print("numpy min. eig", np_eig) + + eigenvalue = result.eigenvalue + # print(result) + print("VQE eig.", eigenvalue) + + +def test_statvector(): + backend = Aer.get_backend("statevector_simulator") + # Aluminum JARVIS-ID: JVASP-816 + wtbh, Ef, atoms = get_wann_electron("JVASP-816") + kpt = [0.5, 0.0, 0.5] # X-point + hk = get_hk_tb(w=wtbh, k=kpt) + HS = HermitianSolver(hk) + n_qubits = HS.n_qubits() + circ = QuantumCircuitLibrary(n_qubits=n_qubits, reps=1).circuit6() + en, vqe_result, vqe = HS.run_vqe(var_form=circ, backend=backend) + vals, vecs = HS.run_numpy() + # Ef: Fermi-level + print("Classical, VQE (eV):", vals[0] - Ef, en - Ef) + print("Show model\n", circ) + + """ # Commenting due to pypi conflicts in qiskit #