From 4563c33eb31cf387d2ca78d187abd3acb7ad65d2 Mon Sep 17 00:00:00 2001 From: Daniel Pozsar Date: Fri, 8 Nov 2024 17:13:09 +0100 Subject: [PATCH] updating --- README.md | 1 - src/grogupy/__init__.py | 8 - src/grogupy/grogu.py | 14 ++ src/grogupy/io.py | 15 -- test.ipynb | 425 +++------------------------------------- 5 files changed, 40 insertions(+), 423 deletions(-) diff --git a/README.md b/README.md index a36b258..b61db61 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,6 @@ More on the theoretical background can be seen on [arXiv](https://arxiv.org/abs/ - Run tests on different magnetic materials and compare it to Grogu Matlab --> ran on Jij_for_Marci_6p45ang, but I could not compare data ## Developing -- Add documentation to `useful` functions and more... - Check the symmetrization of the Hamiltonian and overlap matrix to make them hermitian - Check if exchange field has scalar part - Add more tests!! diff --git a/src/grogupy/__init__.py b/src/grogupy/__init__.py index 9f10512..3864f4b 100644 --- a/src/grogupy/__init__.py +++ b/src/grogupy/__init__.py @@ -22,11 +22,3 @@ from grogupy.core import * from grogupy.io import * from grogupy.magnetism import * from grogupy.utils import * - -try: - from tqdm import tqdm - - tqdm_imported = True -except: - print("Please install tqdm for nice progress bar.") - tqdm_imported = False diff --git a/src/grogupy/grogu.py b/src/grogupy/grogu.py index 208a946..fc9c759 100644 --- a/src/grogupy/grogu.py +++ b/src/grogupy/grogu.py @@ -23,10 +23,24 @@ import warnings from sys import getsizeof from timeit import default_timer as timer +# use numpy number of threads one +from threadpoolctl import threadpool_info, threadpool_limits + +user_api = threadpool_info()[0]["user_api"] +threadpool_limits(limits=1, user_api=user_api) + import numpy as np import sisl from mpi4py import MPI +try: + from tqdm import tqdm + + tqdm_imported = True +except: + print("Please install tqdm for nice progress bar.") + tqdm_imported = False + from grogupy import * diff --git a/src/grogupy/io.py b/src/grogupy/io.py index bb5b474..3a1821f 100644 --- a/src/grogupy/io.py +++ b/src/grogupy/io.py @@ -133,12 +133,6 @@ def print_parameters(simulation_parameters): print( "================================================================================================================================================================" ) - if simulation_parameters["calculate_charge"]: - print("The calculated charge of the Hamiltonian in the quantization axes: ") - print(simulation_parameters["charges"]) - print( - "================================================================================================================================================================" - ) def print_atoms_and_pairs(magnetic_entities, pairs): @@ -319,12 +313,3 @@ def print_job_description(simulation_parameters): print( "================================================================================================================================================================" ) - if simulation_parameters["calculate_charge"]: - print( - "Charge calculation required: True WARNING: This causes a slowdown, because we have to use the complete Greens function!" - ) - else: - print("Charge calculation required: False") - print( - "================================================================================================================================================================" - ) diff --git a/test.ipynb b/test.ipynb index dd9d50d..69468fd 100644 --- a/test.ipynb +++ b/test.ipynb @@ -2,73 +2,31 @@ "cells": [ { "cell_type": "code", - "execution_count": 29, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[{'architecture': 'armv8',\n", - " 'filepath': '/Users/danielpozsar/Documents/oktatás/elte/phd/grogu_project/.venv/lib/python3.9/site-packages/numpy/.dylibs/libopenblas64_.0.dylib',\n", - " 'internal_api': 'openblas',\n", - " 'num_threads': 1,\n", - " 'prefix': 'libopenblas',\n", - " 'threading_layer': 'pthreads',\n", - " 'user_api': 'blas',\n", - " 'version': '0.3.21'},\n", - " {'architecture': 'neoversen1',\n", - " 'filepath': '/Users/danielpozsar/Documents/oktatás/elte/phd/grogu_project/.venv/lib/python3.9/site-packages/scipy/.dylibs/libopenblas.0.dylib',\n", - " 'internal_api': 'openblas',\n", - " 'num_threads': 1,\n", - " 'prefix': 'libopenblas',\n", - " 'threading_layer': 'pthreads',\n", - " 'user_api': 'blas',\n", - " 'version': '0.3.27'}]\n" - ] - } - ], - "source": [ - "from threadpoolctl import threadpool_info\n", - "from pprint import pprint\n", - "import numpy\n", - "\n", - "pprint(threadpool_info())" - ] - }, - { - "cell_type": "code", - "execution_count": 2, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ - "import os\n", - "\n", - "os.environ[\"OMP_NUM_THREADS\"] = \"1\" # export OMP_NUM_THREADS=1\n", - "os.environ[\"OPENBLAS_NUM_THREADS\"] = \"1\" # export OPENBLAS_NUM_THREADS=1\n", - "os.environ[\"MKL_NUM_THREADS\"] = \"1\" # export MKL_NUM_THREADS=1\n", - "os.environ[\"VECLIB_MAXIMUM_THREADS\"] = \"1\" # export VECLIB_MAXIMUM_THREADS=1\n", - "os.environ[\"NUMEXPR_NUM_THREADS\"] = \"1\" # export NUMEXPR_NUM_THREADS=1" + "# use numpy number of threads one\n", + "# from threadpoolctl import threadpool_info, threadpool_limits\n", + "# print(threadpool_info())\n", + "# user_api = threadpool_info()[0][\"user_api\"]\n", + "# threadpool_limits(limits=1, user_api=user_api)" ] }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "0.14.3\n", - "1.24.4\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "[Daniels-Air:88431] shmem: mmap: an error occurred while determining whether or not /var/folders/yh/dx7xl94n3g52ts3td8qcxjcc0000gn/T//ompi.Daniels-Air.501/jf.0/455868416/sm_segment.Daniels-Air.501.1b2c0000.0 could be created.\n" + "ename": "ImportError", + "evalue": "attempted relative import with no known parent package", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mImportError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[6], line 5\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mtimeit\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m default_timer \u001b[38;5;28;01mas\u001b[39;00m timer\n\u001b[1;32m 4\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01msisl\u001b[39;00m\n\u001b[0;32m----> 5\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01msrc\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mgrogupy\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;241m*\u001b[39m\n\u001b[1;32m 6\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mmpi4py\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m MPI\n\u001b[1;32m 7\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mwarnings\u001b[39;00m\n", + "\u001b[0;31mImportError\u001b[0m: attempted relative import with no known parent package" ] } ], @@ -77,8 +35,7 @@ "from timeit import default_timer as timer\n", "\n", "import sisl\n", - "import sisl.viz\n", - "from src.grogu_magn import *\n", + "from src.grogupy import *\n", "from mpi4py import MPI\n", "import warnings\n", "\n", @@ -103,7 +60,7 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 3, "metadata": {}, "outputs": [ { @@ -120,7 +77,7 @@ " [0., 1., 0.]])}]" ] }, - "execution_count": 32, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } @@ -237,7 +194,7 @@ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)", "Cell \u001b[0;32mIn[5], line 43\u001b[0m\n\u001b[1;32m 40\u001b[0m uc_in_sc_idx \u001b[38;5;241m=\u001b[39m dh\u001b[38;5;241m.\u001b[39mlattice\u001b[38;5;241m.\u001b[39msc_index([\u001b[38;5;241m0\u001b[39m, \u001b[38;5;241m0\u001b[39m, \u001b[38;5;241m0\u001b[39m])\n\u001b[1;32m 42\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m rank \u001b[38;5;241m==\u001b[39m root_node:\n\u001b[0;32m---> 43\u001b[0m \u001b[43mprint_parameters\u001b[49m\u001b[43m(\u001b[49m\u001b[43msimulation_parameters\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 44\u001b[0m times[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124msetup_time\u001b[39m\u001b[38;5;124m\"\u001b[39m] \u001b[38;5;241m=\u001b[39m timer()\n\u001b[1;32m 45\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mSetup done. Elapsed time: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mtimes[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124msetup_time\u001b[39m\u001b[38;5;124m'\u001b[39m]\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m s\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n", - "File \u001b[0;32m~/Documents/oktatás/elte/phd/grogu_project/src/grogu_magn/io.py:116\u001b[0m, in \u001b[0;36mprint_parameters\u001b[0;34m(simulation_parameters)\u001b[0m\n\u001b[1;32m 112\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mEsetp: \u001b[39m\u001b[38;5;124m\"\u001b[39m, simulation_parameters[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mesetp\u001b[39m\u001b[38;5;124m\"\u001b[39m])\n\u001b[1;32m 113\u001b[0m \u001b[38;5;28mprint\u001b[39m(\n\u001b[1;32m 114\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m================================================================================================================================================================\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 115\u001b[0m )\n\u001b[0;32m--> 116\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[43msimulation_parameters\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mcalculate_charge\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m]\u001b[49m:\n\u001b[1;32m 117\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mThe calculated charge of the Hamiltonian in the quantization axes: \u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 118\u001b[0m \u001b[38;5;28mprint\u001b[39m(simulation_parameters[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcharges\u001b[39m\u001b[38;5;124m\"\u001b[39m])\n", + "File \u001b[0;32m~/Documents/oktatás/elte/phd/grogu_project/.venv/lib/python3.9/site-packages/grogupy/io.py:132\u001b[0m, in \u001b[0;36mprint_parameters\u001b[0;34m(simulation_parameters)\u001b[0m\n\u001b[1;32m 128\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mEsetp: \u001b[39m\u001b[38;5;124m\"\u001b[39m, simulation_parameters[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mesetp\u001b[39m\u001b[38;5;124m\"\u001b[39m])\n\u001b[1;32m 129\u001b[0m \u001b[38;5;28mprint\u001b[39m(\n\u001b[1;32m 130\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m================================================================================================================================================================\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 131\u001b[0m )\n\u001b[0;32m--> 132\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[43msimulation_parameters\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mcalculate_charge\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m]\u001b[49m:\n\u001b[1;32m 133\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mThe calculated charge of the Hamiltonian in the quantization axes: \u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 134\u001b[0m \u001b[38;5;28mprint\u001b[39m(simulation_parameters[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcharges\u001b[39m\u001b[38;5;124m\"\u001b[39m])\n", "\u001b[0;31mKeyError\u001b[0m: 'calculate_charge'" ] } @@ -297,16 +254,7 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Hamiltonian and exchange field rotated. Elapsed time: 2435.900105791 s\n", - "================================================================================================================================================================\n" - ] - } - ], + "outputs": [], "source": [ "hh, ss, NO = build_hh_ss(dh)\n", "\n", @@ -358,16 +306,7 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Site and pair dictionaries created. Elapsed time: 2438.737295 s\n", - "================================================================================================================================================================\n" - ] - } - ], + "outputs": [], "source": [ "pairs, magnetic_entities = setup_pairs_and_magnetic_entities(\n", " magnetic_entities, pairs, dh, simulation_parameters\n", @@ -387,23 +326,7 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "k loop: 0%| | 0/9 [00:00