qupled 1.3.4__tar.gz → 1.3.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {qupled-1.3.4 → qupled-1.3.5}/PKG-INFO +1 -1
- {qupled-1.3.4 → qupled-1.3.5}/examples/tests/test_examples.py +4 -3
- {qupled-1.3.4 → qupled-1.3.5}/pyproject.toml +1 -1
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/database.py +26 -5
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/hf.py +9 -3
- qupled-1.3.5/src/qupled/native/include/database.hpp +27 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/include/input.hpp +3 -3
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/include/qstls.hpp +13 -4
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/src/CMakeLists.txt +1 -0
- qupled-1.3.5/src/qupled/native/src/database.cpp +12 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/src/input.cpp +1 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/src/python_interface/inputs.cpp +8 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/src/python_interface/utilities.cpp +8 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/src/qstls.cpp +71 -10
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/src/qstlsiet.cpp +1 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled.egg-info/PKG-INFO +1 -1
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled.egg-info/SOURCES.txt +1 -0
- {qupled-1.3.4 → qupled-1.3.5}/tests/test_database.py +24 -8
- {qupled-1.3.4 → qupled-1.3.5}/tests/test_hf.py +5 -2
- qupled-1.3.4/src/qupled/native/include/database.hpp +0 -18
- {qupled-1.3.4 → qupled-1.3.5}/.clang-format +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/.devcontainer/Dockerfile +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/.devcontainer/devcontainer.json +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/.github/workflows/build-and-test.yml +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/.github/workflows/build-linux-wheels.yml +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/.github/workflows/build-macos-wheels.yml +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/.github/workflows/build-sdist.yml +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/.github/workflows/formatting.yml +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/.github/workflows/release.yml +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/.gitignore +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/.readthedocs.yaml +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/LICENSE +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/MANIFEST.in +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/README.md +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/dev/devtool.py +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/dev/requirements-apt.txt +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/dev/requirements-brew.txt +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/dev/requirements-pip.txt +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/devtool +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/docs/_static/css/rdt_theme_python_properties.css +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/docs/conf.py +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/docs/contribute.rst +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/docs/examples.rst +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/docs/index.rst +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/docs/introduction.rst +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/docs/make.bat +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/docs/qupled.rst +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/docs/requirements.txt +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/examples/docs/fixed_adr.py +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/examples/docs/initial_guess_stls.py +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/examples/docs/solve_quantum_schemes.py +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/examples/docs/solve_qvsstls.py +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/examples/docs/solve_rpa_and_esa.py +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/examples/docs/solve_stls.py +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/examples/docs/solve_stls_iet.py +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/examples/docs/solve_vsstls.py +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/examples/readme/create_cover.py +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/examples/readme/qupled_animation_dark.svg +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/examples/readme/qupled_animation_light.svg +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/manylinux/Dockerfile.manylinux_2_28 +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/manylinux/build_manylinux_2_28 +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/setup.cfg +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/setup.py +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/__init__.py +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/esa.py +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/mpi.py +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/include/chemical_potential.hpp +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/include/dual.hpp +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/include/esa.hpp +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/include/format.hpp +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/include/free_energy.hpp +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/include/hf.hpp +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/include/iet.hpp +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/include/internal_energy.hpp +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/include/logger.hpp +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/include/mpi_util.hpp +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/include/num_util.hpp +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/include/numerics.hpp +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/include/python_interface/inputs.hpp +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/include/python_interface/schemes.hpp +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/include/python_interface/util.hpp +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/include/python_interface/utilities.hpp +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/include/qstlsiet.hpp +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/include/qvsstls.hpp +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/include/rdf.hpp +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/include/rpa.hpp +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/include/stls.hpp +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/include/stlsiet.hpp +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/include/thermo_util.hpp +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/include/vector2D.hpp +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/include/vector3D.hpp +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/include/vector_util.hpp +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/include/vsbase.hpp +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/include/vsstls.hpp +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/src/chemical_potential.cpp +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/src/esa.cpp +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/src/free_energy.cpp +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/src/hf.cpp +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/src/iet.cpp +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/src/internal_energy.cpp +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/src/logger.cpp +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/src/mpi_util.cpp +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/src/num_util.cpp +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/src/numerics.cpp +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/src/python_interface/native.cpp +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/src/python_interface/schemes.cpp +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/src/python_interface/util.cpp +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/src/qvsstls.cpp +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/src/rdf.cpp +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/src/rpa.cpp +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/src/stls.cpp +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/src/stlsiet.cpp +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/src/thermo_util.cpp +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/src/vector2D.cpp +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/src/vector3D.cpp +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/src/vector_util.cpp +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/src/vsbase.cpp +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/src/vsstls.cpp +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/output.py +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/qstls.py +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/qstlsiet.py +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/qvsstls.py +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/rpa.py +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/serialize.py +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/stls.py +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/stlsiet.py +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/timer.py +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled/vsstls.py +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled.egg-info/dependency_links.txt +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled.egg-info/not-zip-safe +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled.egg-info/requires.txt +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/src/qupled.egg-info/top_level.txt +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/tests/native/conftest.py +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/tests/native/test_esa_native.py +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/tests/native/test_hf_native.py +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/tests/native/test_qstls_iet_native.py +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/tests/native/test_qstls_native.py +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/tests/native/test_qvsstls_native.py +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/tests/native/test_rpa_native.py +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/tests/native/test_stls_iet_native.py +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/tests/native/test_stls_native.py +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/tests/native/test_vsstls_native.py +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/tests/test_esa.py +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/tests/test_mpi.py +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/tests/test_output.py +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/tests/test_qstls.py +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/tests/test_qstlsiet.py +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/tests/test_qvsstls.py +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/tests/test_rpa.py +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/tests/test_stls.py +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/tests/test_stlsiet.py +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/tests/test_vsstls.py +0 -0
- {qupled-1.3.4 → qupled-1.3.5}/tox.ini +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: qupled
|
3
|
-
Version: 1.3.
|
3
|
+
Version: 1.3.5
|
4
4
|
Summary: qupled: a package to investigate quantum plasmas via the dielectric formalism
|
5
5
|
Author-email: Federico Lucco Castello <federico.luccocastello@gmail.com>
|
6
6
|
License-Expression: GPL-3.0-or-later
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import importlib
|
2
2
|
import os
|
3
|
+
import shutil
|
3
4
|
import sys
|
4
5
|
|
5
6
|
import matplotlib.pyplot as plt
|
@@ -21,9 +22,9 @@ def run_before_each_test():
|
|
21
22
|
@pytest.fixture(autouse=True)
|
22
23
|
def run_after_each_test():
|
23
24
|
yield
|
24
|
-
|
25
|
-
if os.path.exists(
|
26
|
-
|
25
|
+
output_dir = DataBaseHandler.DATABASE_DIRECTORY
|
26
|
+
if os.path.exists(output_dir):
|
27
|
+
shutil.rmtree(output_dir)
|
27
28
|
|
28
29
|
|
29
30
|
@pytest.fixture(autouse=True)
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
4
4
|
|
5
5
|
[project]
|
6
6
|
name = "qupled"
|
7
|
-
version = "v1.3.
|
7
|
+
version = "v1.3.5"
|
8
8
|
description = "qupled: a package to investigate quantum plasmas via the dielectric formalism"
|
9
9
|
readme = "README.md"
|
10
10
|
requires-python = ">=3.10, <3.14"
|
@@ -4,12 +4,15 @@ import struct
|
|
4
4
|
from datetime import datetime
|
5
5
|
from enum import Enum
|
6
6
|
from collections.abc import Callable
|
7
|
+
from pathlib import Path
|
7
8
|
|
8
9
|
import numpy as np
|
9
10
|
import sqlalchemy as sql
|
10
11
|
from sqlalchemy.dialects.sqlite import insert as sqlite_insert
|
11
12
|
import blosc2
|
12
13
|
|
14
|
+
from . import native
|
15
|
+
|
13
16
|
|
14
17
|
class DataBaseHandler:
|
15
18
|
"""
|
@@ -18,10 +21,13 @@ class DataBaseHandler:
|
|
18
21
|
and deleting data, as well as managing the database schema."
|
19
22
|
"""
|
20
23
|
|
24
|
+
BLOB_STORAGE_DIRECTORY = "blob_data"
|
25
|
+
DATABASE_DIRECTORY = "qupled_store"
|
21
26
|
DEFAULT_DATABASE_NAME = "qupled.db"
|
22
|
-
|
27
|
+
FIXED_TABLE_NAME = "fixed"
|
23
28
|
INPUT_TABLE_NAME = "inputs"
|
24
29
|
RESULT_TABLE_NAME = "results"
|
30
|
+
RUN_TABLE_NAME = "runs"
|
25
31
|
|
26
32
|
class TableKeys(Enum):
|
27
33
|
COUPLING = "coupling"
|
@@ -61,12 +67,23 @@ class DataBaseHandler:
|
|
61
67
|
result_table (sqlalchemy.Table): The table schema for storing result data.
|
62
68
|
run_id (int | None): The ID of the current run, or None if no run is active.
|
63
69
|
"""
|
64
|
-
|
65
|
-
|
70
|
+
# Database path
|
71
|
+
database_name = (
|
72
|
+
self.DEFAULT_DATABASE_NAME if database_name is None else database_name
|
66
73
|
)
|
67
|
-
|
68
|
-
|
74
|
+
database_path = Path(self.DATABASE_DIRECTORY) / database_name
|
75
|
+
database_path.parent.mkdir(parents=True, exist_ok=True)
|
76
|
+
# Blob data storage
|
77
|
+
self.blob_storage = (
|
78
|
+
Path(self.DATABASE_DIRECTORY) / self.BLOB_STORAGE_DIRECTORY / database_name
|
79
|
+
)
|
80
|
+
self.blob_storage.mkdir(parents=True, exist_ok=True)
|
81
|
+
self.blob_storage = str(self.blob_storage)
|
82
|
+
# Create database
|
83
|
+
self.engine = sql.create_engine(f"sqlite:///{database_path}")
|
84
|
+
# Set sqlite properties
|
69
85
|
DataBaseHandler._set_sqlite_pragma(self.engine)
|
86
|
+
# Create tables
|
70
87
|
self.table_metadata = sql.MetaData()
|
71
88
|
self.run_table = self._build_run_table()
|
72
89
|
self.input_table = self._build_inputs_table()
|
@@ -252,6 +269,7 @@ class DataBaseHandler:
|
|
252
269
|
Returns:
|
253
270
|
None
|
254
271
|
"""
|
272
|
+
self._delete_blob_data_on_disk(run_id)
|
255
273
|
condition = self.run_table.c[self.TableKeys.PRIMARY_KEY.value] == run_id
|
256
274
|
statement = sql.delete(self.run_table).where(condition)
|
257
275
|
self._execute(statement)
|
@@ -430,6 +448,9 @@ class DataBaseHandler:
|
|
430
448
|
if run_id := result.inserted_primary_key:
|
431
449
|
self.run_id = run_id[0]
|
432
450
|
|
451
|
+
def _delete_blob_data_on_disk(self, run_id: int):
|
452
|
+
native.delete_blob_data_on_disk(self.engine.url.database, run_id)
|
453
|
+
|
433
454
|
@staticmethod
|
434
455
|
def _set_sqlite_pragma(engine):
|
435
456
|
"""
|
@@ -87,7 +87,11 @@ class Solver:
|
|
87
87
|
`self.inputs` with the current `run_id`.
|
88
88
|
"""
|
89
89
|
self.db_handler.insert_run(self.inputs)
|
90
|
-
self.inputs.database_info
|
90
|
+
self.inputs.database_info = DatabaseInfo(
|
91
|
+
blob_storage=self.db_handler.blob_storage,
|
92
|
+
name=self.db_handler.engine.url.database,
|
93
|
+
run_id=self.run_id,
|
94
|
+
)
|
91
95
|
|
92
96
|
def _compute_native(self):
|
93
97
|
"""
|
@@ -197,7 +201,7 @@ class Input:
|
|
197
201
|
processes: int = 1
|
198
202
|
"""Number of MPI processes for parallel calculations. Default = ``1``"""
|
199
203
|
theory: str = "HF"
|
200
|
-
database_info: DatabaseInfo =
|
204
|
+
database_info: DatabaseInfo = None
|
201
205
|
|
202
206
|
def to_native(self, native_input: any):
|
203
207
|
"""
|
@@ -290,7 +294,9 @@ class DatabaseInfo:
|
|
290
294
|
Class used to store the database information passed to the native code.
|
291
295
|
"""
|
292
296
|
|
293
|
-
|
297
|
+
blob_storage: str = None
|
298
|
+
"""Directory used to store the blob data"""
|
299
|
+
name: str = None
|
294
300
|
"""Database name"""
|
295
301
|
run_id: int = None
|
296
302
|
"""ID of the run in the database"""
|
@@ -0,0 +1,27 @@
|
|
1
|
+
#ifndef DATABASE_HPP
|
2
|
+
#define DATABASE_HPP
|
3
|
+
|
4
|
+
#include "num_util.hpp"
|
5
|
+
#include <string>
|
6
|
+
|
7
|
+
namespace databaseUtil {
|
8
|
+
|
9
|
+
struct DatabaseInfo {
|
10
|
+
DatabaseInfo()
|
11
|
+
: runId(numUtil::iNaN) {}
|
12
|
+
// Database name
|
13
|
+
std::string name;
|
14
|
+
// Fodler used to store the blob data
|
15
|
+
std::string blobStorage;
|
16
|
+
// Run id in the database
|
17
|
+
int runId;
|
18
|
+
// Name of the table with the runs in the database
|
19
|
+
std::string runTableName;
|
20
|
+
};
|
21
|
+
|
22
|
+
void deleteBlobDataOnDisk(const std::string &dbInfo, int runId);
|
23
|
+
bool blobDataTableExists(const std::string &dbName);
|
24
|
+
|
25
|
+
} // namespace databaseUtil
|
26
|
+
|
27
|
+
#endif // DATABASE_HPP
|
@@ -40,7 +40,7 @@ public:
|
|
40
40
|
virtual ~Input() = default;
|
41
41
|
// Setters
|
42
42
|
void setCoupling(const double &rs);
|
43
|
-
void setDatabaseInfo(const DatabaseInfo &dbInfo);
|
43
|
+
void setDatabaseInfo(const databaseUtil::DatabaseInfo &dbInfo);
|
44
44
|
void setDegeneracy(const double &Theta);
|
45
45
|
void setInt2DScheme(const std::string &int2DScheme);
|
46
46
|
void setIntError(const double &intError);
|
@@ -54,7 +54,7 @@ public:
|
|
54
54
|
|
55
55
|
// Getters
|
56
56
|
double getCoupling() const { return rs; }
|
57
|
-
DatabaseInfo getDatabaseInfo() const { return dbInfo; }
|
57
|
+
databaseUtil::DatabaseInfo getDatabaseInfo() const { return dbInfo; }
|
58
58
|
double getDegeneracy() const { return Theta; }
|
59
59
|
std::string getInt2DScheme() const { return int2DScheme; }
|
60
60
|
double getIntError() const { return intError; }
|
@@ -85,7 +85,7 @@ protected:
|
|
85
85
|
// Theory to be solved
|
86
86
|
std::string theory;
|
87
87
|
// Database information
|
88
|
-
DatabaseInfo dbInfo;
|
88
|
+
databaseUtil::DatabaseInfo dbInfo;
|
89
89
|
// Wave-vector grid resolution
|
90
90
|
double dx;
|
91
91
|
// Cutoff for the wave-vector grid
|
@@ -52,7 +52,7 @@ private:
|
|
52
52
|
namespace QstlsUtil {
|
53
53
|
|
54
54
|
// -----------------------------------------------------------------
|
55
|
-
//
|
55
|
+
// Utility functions for handling the database
|
56
56
|
// -----------------------------------------------------------------
|
57
57
|
|
58
58
|
constexpr const char *SQL_TABLE_NAME = "fixed";
|
@@ -61,17 +61,26 @@ namespace QstlsUtil {
|
|
61
61
|
CREATE TABLE IF NOT EXISTS {} (
|
62
62
|
run_id INTEGER NOT NULL,
|
63
63
|
name TEXT NOT NULL,
|
64
|
-
|
64
|
+
value TEXT NOT NULL,
|
65
65
|
PRIMARY KEY (run_id, name),
|
66
66
|
FOREIGN KEY(run_id) REFERENCES {}(id) ON DELETE CASCADE
|
67
67
|
);
|
68
68
|
)";
|
69
69
|
|
70
70
|
constexpr const char *SQL_INSERT =
|
71
|
-
"INSERT OR REPLACE INTO {} (run_id, name,
|
71
|
+
"INSERT OR REPLACE INTO {} (run_id, name, value) VALUES (?, ?, ?);";
|
72
72
|
|
73
73
|
constexpr const char *SQL_SELECT =
|
74
|
-
"SELECT
|
74
|
+
"SELECT value FROM {} WHERE run_id = ? AND name = ?;";
|
75
|
+
|
76
|
+
constexpr const char *SQL_SELECT_RUN_ID =
|
77
|
+
"SELECT value FROM {} WHERE run_id = ?";
|
78
|
+
|
79
|
+
constexpr const char *SQL_SELECT_TABLE =
|
80
|
+
"SELECT count(*) FROM sqlite_master WHERE type='table' AND name=?";
|
81
|
+
|
82
|
+
void deleteBlobDataOnDisk(const std::string &dbName, int runId);
|
83
|
+
|
75
84
|
// -----------------------------------------------------------------
|
76
85
|
// Classes for the auxiliary density response
|
77
86
|
// -----------------------------------------------------------------
|
@@ -0,0 +1,12 @@
|
|
1
|
+
#include "database.hpp"
|
2
|
+
#include "format.hpp"
|
3
|
+
#include "qstls.hpp"
|
4
|
+
|
5
|
+
using namespace std;
|
6
|
+
|
7
|
+
namespace databaseUtil {
|
8
|
+
|
9
|
+
void deleteBlobDataOnDisk(const string &dbName, int runId) {
|
10
|
+
QstlsUtil::deleteBlobDataOnDisk(dbName, runId);
|
11
|
+
}
|
12
|
+
} // namespace databaseUtil
|
@@ -4,6 +4,7 @@
|
|
4
4
|
#include <pybind11/pybind11.h>
|
5
5
|
|
6
6
|
namespace py = pybind11;
|
7
|
+
using namespace databaseUtil;
|
7
8
|
using namespace pythonUtil;
|
8
9
|
|
9
10
|
// -----------------------------------------------------------------
|
@@ -138,12 +139,16 @@ void exposeQVSStlsInputClass(py::module_ &m) {
|
|
138
139
|
// -----------------------------------------------------------------
|
139
140
|
|
140
141
|
namespace pythonDatabaseInfo {
|
142
|
+
std::string getBlobStorage(const DatabaseInfo &db) { return db.blobStorage; }
|
141
143
|
std::string getName(const DatabaseInfo &db) { return db.name; }
|
142
144
|
std::string getRunTableName(const DatabaseInfo &db) {
|
143
145
|
return db.runTableName;
|
144
146
|
}
|
145
147
|
int getRunId(const DatabaseInfo &db) { return db.runId; }
|
146
148
|
|
149
|
+
void setBlobStorage(DatabaseInfo &db, const std::string &blobStorage) {
|
150
|
+
db.blobStorage = blobStorage;
|
151
|
+
}
|
147
152
|
void setName(DatabaseInfo &db, const std::string &name) { db.name = name; }
|
148
153
|
void setRunTableName(DatabaseInfo &db, const std::string &runTableName) {
|
149
154
|
db.runTableName = runTableName;
|
@@ -154,6 +159,9 @@ namespace pythonDatabaseInfo {
|
|
154
159
|
void exposeDatabaseInfoClass(py::module_ &m) {
|
155
160
|
py::class_<DatabaseInfo>(m, "DatabaseInfo")
|
156
161
|
.def(py::init<>())
|
162
|
+
.def_property("blob_storage",
|
163
|
+
pythonDatabaseInfo::getBlobStorage,
|
164
|
+
pythonDatabaseInfo::setBlobStorage)
|
157
165
|
.def_property(
|
158
166
|
"name", pythonDatabaseInfo::getName, pythonDatabaseInfo::setName)
|
159
167
|
.def_property(
|
@@ -1,4 +1,5 @@
|
|
1
1
|
#include "python_interface/utilities.hpp"
|
2
|
+
#include "database.hpp"
|
2
3
|
#include "mpi_util.hpp"
|
3
4
|
#include "python_interface/util.hpp"
|
4
5
|
#include "thermo_util.hpp"
|
@@ -56,9 +57,16 @@ namespace pythonWrappers {
|
|
56
57
|
m.attr("uses_mpi") = py::bool_(MPIUtil::isUsed);
|
57
58
|
}
|
58
59
|
|
60
|
+
void exposeDatabaseMethods(py::module_ &m) {
|
61
|
+
m.def("delete_blob_data_on_disk",
|
62
|
+
&databaseUtil::deleteBlobDataOnDisk,
|
63
|
+
"Delete blob data on disk for a given run ID");
|
64
|
+
}
|
65
|
+
|
59
66
|
void exposeUtilities(py::module_ &m) {
|
60
67
|
exposePostProcessingMethods(m);
|
61
68
|
exposeMPIClass(m);
|
69
|
+
exposeDatabaseMethods(m);
|
62
70
|
}
|
63
71
|
|
64
72
|
} // namespace pythonWrappers
|
@@ -5,8 +5,10 @@
|
|
5
5
|
#include "vector_util.hpp"
|
6
6
|
#include <SQLiteCpp/SQLiteCpp.h>
|
7
7
|
#include <cstring>
|
8
|
+
#include <fstream>
|
8
9
|
|
9
10
|
using namespace std;
|
11
|
+
using namespace databaseUtil;
|
10
12
|
using namespace vecUtil;
|
11
13
|
using namespace MPIUtil;
|
12
14
|
using ItgParam = Integrator1D::Param;
|
@@ -111,16 +113,22 @@ void Qstls::writeAdrFixed(const Vector3D &res, const string &name) const {
|
|
111
113
|
QstlsUtil::SQL_TABLE_NAME,
|
112
114
|
dbInfo.runTableName);
|
113
115
|
db.exec(createTable);
|
114
|
-
//
|
115
|
-
|
116
|
-
|
117
|
-
|
116
|
+
// Write to disk
|
117
|
+
string filename = formatUtil::format(
|
118
|
+
"{}/run_{}_{}.bin", dbInfo.blobStorage, dbInfo.runId, name);
|
119
|
+
ofstream out(filename, std::ios::binary);
|
120
|
+
if (!out) { throwError("Failed to open file for writing: " + filename); }
|
121
|
+
out.write(reinterpret_cast<const char *>(res.data()),
|
122
|
+
res.size() * sizeof(double));
|
123
|
+
out.close();
|
124
|
+
|
125
|
+
// Insert path into DB
|
118
126
|
const string insert =
|
119
127
|
formatUtil::format(QstlsUtil::SQL_INSERT, QstlsUtil::SQL_TABLE_NAME);
|
120
128
|
SQLite::Statement statement(db, insert);
|
121
129
|
statement.bind(1, dbInfo.runId);
|
122
130
|
statement.bind(2, name);
|
123
|
-
statement.bind(3,
|
131
|
+
statement.bind(3, filename);
|
124
132
|
statement.exec();
|
125
133
|
} catch (const std::exception &e) {
|
126
134
|
throwError("Failed to write to database: " + string(e.what()));
|
@@ -137,21 +145,74 @@ void Qstls::readAdrFixed(Vector3D &res, const string &name, int runId) const {
|
|
137
145
|
statement.bind(1, runId);
|
138
146
|
statement.bind(2, name);
|
139
147
|
if (statement.executeStep()) {
|
140
|
-
const
|
141
|
-
|
142
|
-
if (
|
148
|
+
const string filename = statement.getColumn(0).getString();
|
149
|
+
ifstream in(filename, std::ios::binary);
|
150
|
+
if (!in) { throwError("Failed to open file for reading: " + filename); }
|
151
|
+
in.read(reinterpret_cast<char *>(res.data()),
|
152
|
+
res.size() * sizeof(double));
|
153
|
+
if (in.gcount()
|
154
|
+
!= static_cast<std::streamsize>(res.size() * sizeof(double))) {
|
143
155
|
throwError(
|
144
156
|
formatUtil::format("Size mismatch: expected {} bytes, got {} bytes",
|
145
157
|
res.size() * sizeof(double),
|
146
|
-
|
158
|
+
in.gcount()));
|
147
159
|
}
|
148
|
-
|
160
|
+
in.close();
|
149
161
|
}
|
150
162
|
} catch (const std::exception &e) {
|
151
163
|
throwError("Failed to read from database: " + string(e.what()));
|
152
164
|
}
|
153
165
|
}
|
154
166
|
|
167
|
+
// -----------------------------------------------------------------
|
168
|
+
// Delete blob data on disk
|
169
|
+
// -----------------------------------------------------------------
|
170
|
+
|
171
|
+
bool blobDataTableExists(const SQLite::Database &db) {
|
172
|
+
const string select = QstlsUtil::SQL_SELECT_TABLE;
|
173
|
+
SQLite::Statement statement(db, select);
|
174
|
+
statement.bind(1, QstlsUtil::SQL_TABLE_NAME);
|
175
|
+
if (statement.executeStep()) { return statement.getColumn(0).getInt() > 0; }
|
176
|
+
return false;
|
177
|
+
}
|
178
|
+
|
179
|
+
void QstlsUtil::deleteBlobDataOnDisk(const string &dbName, int runId) {
|
180
|
+
try {
|
181
|
+
// Setup the database connection
|
182
|
+
SQLite::Database db(dbName, SQLite::OPEN_READONLY);
|
183
|
+
// Check if the table exists
|
184
|
+
if (!blobDataTableExists(db)) { return; }
|
185
|
+
// Select the correct run
|
186
|
+
const string select = formatUtil::format(QstlsUtil::SQL_SELECT_RUN_ID,
|
187
|
+
QstlsUtil::SQL_TABLE_NAME);
|
188
|
+
SQLite::Statement statement(db, select);
|
189
|
+
statement.bind(1, runId);
|
190
|
+
// Execute and collect file paths
|
191
|
+
std::vector<std::string> filePaths;
|
192
|
+
while (statement.executeStep()) {
|
193
|
+
filePaths.push_back(statement.getColumn(0).getString());
|
194
|
+
}
|
195
|
+
// Delete each file path
|
196
|
+
for (const auto &path : filePaths) {
|
197
|
+
try {
|
198
|
+
if (std::filesystem::remove(path)) {
|
199
|
+
// Successfully deleted
|
200
|
+
} else {
|
201
|
+
std::cerr << "Warning: file not found: " << path << std::endl;
|
202
|
+
}
|
203
|
+
} catch (const std::filesystem::filesystem_error &e) {
|
204
|
+
std::cerr << "Warning: failed to delete " << path << ": " << e.what()
|
205
|
+
<< std::endl;
|
206
|
+
}
|
207
|
+
}
|
208
|
+
} catch (const SQLite::Exception &e) {
|
209
|
+
std::cerr << "SQLite error: " << e.what() << std::endl;
|
210
|
+
} catch (const std::exception &e) {
|
211
|
+
std::cerr << "Unexpected error when deleting database files: " << e.what()
|
212
|
+
<< std::endl;
|
213
|
+
}
|
214
|
+
}
|
215
|
+
|
155
216
|
// -----------------------------------------------------------------
|
156
217
|
// AdrBase class
|
157
218
|
// -----------------------------------------------------------------
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: qupled
|
3
|
-
Version: 1.3.
|
3
|
+
Version: 1.3.5
|
4
4
|
Summary: qupled: a package to investigate quantum plasmas via the dielectric formalism
|
5
5
|
Author-email: Federico Lucco Castello <federico.luccocastello@gmail.com>
|
6
6
|
License-Expression: GPL-3.0-or-later
|
@@ -97,6 +97,7 @@ src/qupled/native/include/python_interface/util.hpp
|
|
97
97
|
src/qupled/native/include/python_interface/utilities.hpp
|
98
98
|
src/qupled/native/src/CMakeLists.txt
|
99
99
|
src/qupled/native/src/chemical_potential.cpp
|
100
|
+
src/qupled/native/src/database.cpp
|
100
101
|
src/qupled/native/src/esa.cpp
|
101
102
|
src/qupled/native/src/free_energy.cpp
|
102
103
|
src/qupled/native/src/hf.cpp
|
@@ -3,6 +3,7 @@ import io
|
|
3
3
|
import json
|
4
4
|
import os
|
5
5
|
import struct
|
6
|
+
from pathlib import Path
|
6
7
|
|
7
8
|
import blosc2
|
8
9
|
import numpy as np
|
@@ -19,13 +20,22 @@ from qupled.database import DataBaseHandler
|
|
19
20
|
def db_handler():
|
20
21
|
handler = DataBaseHandler()
|
21
22
|
yield handler
|
22
|
-
|
23
|
-
|
23
|
+
database_url = handler.engine.url.database
|
24
|
+
if os.path.exists(database_url):
|
25
|
+
os.remove(database_url)
|
24
26
|
|
25
27
|
|
26
28
|
def test_database_handler_initialization_with_default_name(db_handler):
|
27
|
-
|
28
|
-
|
29
|
+
expected_database_path = (
|
30
|
+
Path(DataBaseHandler.DATABASE_DIRECTORY) / DataBaseHandler.DEFAULT_DATABASE_NAME
|
31
|
+
)
|
32
|
+
expected_blob_storage = (
|
33
|
+
Path(DataBaseHandler.DATABASE_DIRECTORY)
|
34
|
+
/ DataBaseHandler.BLOB_STORAGE_DIRECTORY
|
35
|
+
/ DataBaseHandler.DEFAULT_DATABASE_NAME
|
36
|
+
)
|
37
|
+
assert db_handler.blob_storage == str(expected_blob_storage)
|
38
|
+
assert db_handler.engine.url.database == str(expected_database_path)
|
29
39
|
assert db_handler.run_id is None
|
30
40
|
inspector = inspect(db_handler.engine)
|
31
41
|
assert set(inspector.get_table_names()) == {
|
@@ -37,9 +47,15 @@ def test_database_handler_initialization_with_default_name(db_handler):
|
|
37
47
|
|
38
48
|
def test_database_handler_initialization_with_custom_name():
|
39
49
|
database_name = "custom.db"
|
50
|
+
expected_database_path = Path(DataBaseHandler.DATABASE_DIRECTORY) / database_name
|
51
|
+
expected_blob_storage = (
|
52
|
+
Path(DataBaseHandler.DATABASE_DIRECTORY)
|
53
|
+
/ DataBaseHandler.BLOB_STORAGE_DIRECTORY
|
54
|
+
/ database_name
|
55
|
+
)
|
40
56
|
db_handler = DataBaseHandler(database_name="custom.db")
|
41
|
-
assert db_handler.
|
42
|
-
assert db_handler.engine.url.database ==
|
57
|
+
assert db_handler.blob_storage == str(expected_blob_storage)
|
58
|
+
assert db_handler.engine.url.database == str(expected_database_path)
|
43
59
|
assert db_handler.run_id is None
|
44
60
|
inspector = inspect(db_handler.engine)
|
45
61
|
assert set(inspector.get_table_names()) == {
|
@@ -47,8 +63,8 @@ def test_database_handler_initialization_with_custom_name():
|
|
47
63
|
DataBaseHandler.INPUT_TABLE_NAME,
|
48
64
|
DataBaseHandler.RESULT_TABLE_NAME,
|
49
65
|
}
|
50
|
-
if os.path.exists(
|
51
|
-
os.remove(
|
66
|
+
if os.path.exists(expected_database_path):
|
67
|
+
os.remove(expected_database_path)
|
52
68
|
|
53
69
|
|
54
70
|
def test_set_sqlite_pragma_valid_engine():
|
@@ -152,7 +152,7 @@ def test_input_initialization(mocker):
|
|
152
152
|
assert inputs.resolution == 0.1
|
153
153
|
assert inputs.threads == 1
|
154
154
|
assert inputs.theory == "HF"
|
155
|
-
assert inputs.database_info
|
155
|
+
assert inputs.database_info is None
|
156
156
|
|
157
157
|
|
158
158
|
def test_input_to_native(mocker, inputs):
|
@@ -209,7 +209,8 @@ def test_result_compute_rdf_with_custom_grid(mocker, results):
|
|
209
209
|
|
210
210
|
def test_database_info_initialization():
|
211
211
|
db_info = hf.DatabaseInfo()
|
212
|
-
assert db_info.
|
212
|
+
assert db_info.blob_storage is None
|
213
|
+
assert db_info.name is None
|
213
214
|
assert db_info.run_id is None
|
214
215
|
assert db_info.run_table_name == hf.database.DataBaseHandler.RUN_TABLE_NAME
|
215
216
|
|
@@ -217,11 +218,13 @@ def test_database_info_initialization():
|
|
217
218
|
def test_database_info_to_native(mocker):
|
218
219
|
native_db_info = mocker.patch("qupled.native.DatabaseInfo")
|
219
220
|
db_info = hf.DatabaseInfo()
|
221
|
+
db_info.blob_storage = "blob_data"
|
220
222
|
db_info.name = "test_db"
|
221
223
|
db_info.run_id = 123
|
222
224
|
db_info.run_table_name = "test_table"
|
223
225
|
native_instance = db_info.to_native()
|
224
226
|
assert native_instance == native_db_info.return_value
|
227
|
+
assert native_instance.blob_storage == "blob_data"
|
225
228
|
assert native_instance.name == "test_db"
|
226
229
|
assert native_instance.run_id == 123
|
227
230
|
assert native_instance.run_table_name == "test_table"
|
@@ -1,18 +0,0 @@
|
|
1
|
-
#ifndef DATABASE_HPP
|
2
|
-
#define DATABASE_HPP
|
3
|
-
|
4
|
-
#include "num_util.hpp"
|
5
|
-
#include <string>
|
6
|
-
|
7
|
-
struct DatabaseInfo {
|
8
|
-
DatabaseInfo()
|
9
|
-
: runId(numUtil::iNaN) {}
|
10
|
-
// Database name
|
11
|
-
std::string name;
|
12
|
-
// Run id in the database
|
13
|
-
int runId;
|
14
|
-
// Name of the table with the runs in the database
|
15
|
-
std::string runTableName;
|
16
|
-
};
|
17
|
-
|
18
|
-
#endif // DATABASE_HPP
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|