From e837c5f4ce05c6fd66023b8df9155141eda10b53 Mon Sep 17 00:00:00 2001 From: Yuichi Motoyama Date: Fri, 13 Sep 2024 15:19:52 +0900 Subject: [PATCH] use dcorelib.triqs_compat by default when triqs is not installed --- doc/install.rst | 55 ++++++++++++++++++---------------------- src/dcore/_dispatcher.py | 37 +++++++++++++++++++-------- 2 files changed, 51 insertions(+), 41 deletions(-) diff --git a/doc/install.rst b/doc/install.rst index 25826824..810fb576 100644 --- a/doc/install.rst +++ b/doc/install.rst @@ -11,12 +11,6 @@ Prerequisites #. Python3 -#. `TRIQS 3.x `_ and `TRIQS/DFTTools 3.x `_. - They must be installed prior to installing all other programs. - The current version of DCore supports TRIQS 3.x. - Please make sure that the triqs and triqs_dft_tools modules are loadable in your Python environment. - You may use `MateriAppsInstaller `_, a collection of install scripts, to install prerequisites (TRIQS). - #. You will also need at least one impurity solver. For example, the following programs are supported: @@ -25,28 +19,36 @@ Prerequisites * :doc:`ALPS/CT-HYB` * :doc:`ALPS/CT-HYB-SEGMENT` * :doc:`TRIQS/cthyb` + * :doc:`Pomerol solver` We recommend to use the Hubbard-I solver for tests because this is fast. See :doc:`impuritysolvers` for a complete list of supported impurity solvers and their user manuals. +#. [OPTIONAL] `TRIQS 3.x `_ and `TRIQS/DFTTools 3.x `_. + + TRIQS can improve the performance of DCore. + The current version of DCore supports TRIQS 3.x. + Please make sure that the triqs and triqs_dft_tools modules are loadable in your Python environment. + You may use `MateriAppsInstaller `_, a collection of install scripts, to install prerequisites (TRIQS). + If you installed TRIQS but want not to use it, please set the environment variable "DCORE_TRIQS_COMPAT" to "1" as follows. + + .. code-block:: bash + + $ export DCORE_TRIQS_COMPAT=1 + Installation ------------------ +(NOTE: Using a virtual environment such as `venv `_ is recommended to avoid conflicts with other Python packages.) + You can install the latest version of DCore using ``pip`` command as follows. :: - $ pip3 install dcore -U + $ pip3 install dcore -U Here, ``-U`` stands for ''Upgrade''. The installed packages are upgraded to the latest version, if you already have packages installed. -Further, if you do not have root privileges, you need to add ``--user`` option as - - :: - - $ pip3 install dcore -U --user - -Then, the packages are installed into .local directory in your home directory. Make sure that **$HOME/.local/bin** is included in PATH environment variable. Installation (only for developers) @@ -81,12 +83,6 @@ You can download the source files in two ways. $ pip3 install . - If you do not have root privileges, please try - - .. code-block:: bash - - $ pip3 install . --user - If both of them did not work, you could build a binary package and install it as follows .. code-block:: bash @@ -97,17 +93,6 @@ You can download the source files in two ways. One can run unit tests using the installed DCore by executing the following commands. - Executables such as dcore_pre may be installed into $HOME/.local/bin/dcore if you install DCore with the "--user" option. - Please add this directory to your PATH environment if needed. - - You can build documentations as follows. - - .. code-block:: bash - - $ pip3 install sphinx wild_sphinx_theme matplotlib - $ python3 -m dcore.option_tables doc/reference - $ sphinx-build -b html doc html - Non-MPI tests can be run as follows. .. code-block:: bash @@ -132,3 +117,11 @@ You can download the source files in two ways. Note that it is not allowed to run MPI programs interactively on some system. In this case, please run MPI tests as a parallel job with one process. + + You can build documentations as follows. + + .. code-block:: bash + + $ pip3 install sphinx wild_sphinx_theme matplotlib + $ python3 -m dcore.option_tables doc/reference + $ sphinx-build -b html doc html diff --git a/src/dcore/_dispatcher.py b/src/dcore/_dispatcher.py index 6872f244..c8b8d936 100644 --- a/src/dcore/_dispatcher.py +++ b/src/dcore/_dispatcher.py @@ -1,9 +1,32 @@ import os, sys import importlib.util +TRIQS_FOUND = True -if int(os.environ.get('DCORE_TRIQS_COMPAT', 1)) == 1: - TRIQS_COMPAT = True +triqs_libs = ['triqs', 'triqs_dft_tools'] +for l in triqs_libs: + if not importlib.util.find_spec(l): + TRIQS_FOUND = False + +if "DCORE_TRIQS_COMPAT" in os.environ: + dtc = os.environ["DCORE_TRIQS_COMPAT"] + if dtc == "1": + TRIQS_COMPAT = True + else: + TRIQS_COMPAT = False + + if TRIQS_FOUND and TRIQS_COMPAT: + print("INFO: TRIQS is found but DCORE_TRIQS_COMPAT is set to 1.") + print(" dcorelib.triqs_compat will be used") + + if not TRIQS_FOUND and not TRIQS_COMPAT: + print("ERROR: TRIQS is required (DCORE_TRIQS_COMPAT={}) but TRIQS is not found!".format(dtc)) + sys.exit(1) +else: + TRIQS_COMPAT = not TRIQS_FOUND + + +if TRIQS_COMPAT: from dcorelib.triqs_compat import * from dcorelib.triqs_compat import h5 from dcorelib.triqs_compat.gf import * @@ -16,14 +39,6 @@ from dcorelib.triqs_compat.dft_tools import SumkDFT, SumkDFTTools from dcorelib.triqs_compat.plot import mpl_interface else: - TRIQS_COMPAT = False - triqs_libs = ['triqs', 'triqs_dft_tools'] - for l in triqs_libs: - if not importlib.util.find_spec(l): - print(f"{l} is not installed!") - print("We can use a TRIQS-compatible library instead by setting environment variable DCORE_TRIQS_COMPAT to 1.") - raise RuntimeError("TRIQS is not found!") - from triqs.gf.gf import * from triqs.gf import * from h5 import * @@ -37,3 +52,5 @@ from triqs_dft_tools import SumkDFT, SumkDFTTools else: from .backend import _triqs_mpi as mpi + + print("INFO: TRIQS library is used") \ No newline at end of file