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.
Files changed (153) hide show
  1. {qupled-1.3.4 → qupled-1.3.5}/PKG-INFO +1 -1
  2. {qupled-1.3.4 → qupled-1.3.5}/examples/tests/test_examples.py +4 -3
  3. {qupled-1.3.4 → qupled-1.3.5}/pyproject.toml +1 -1
  4. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/database.py +26 -5
  5. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/hf.py +9 -3
  6. qupled-1.3.5/src/qupled/native/include/database.hpp +27 -0
  7. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/include/input.hpp +3 -3
  8. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/include/qstls.hpp +13 -4
  9. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/src/CMakeLists.txt +1 -0
  10. qupled-1.3.5/src/qupled/native/src/database.cpp +12 -0
  11. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/src/input.cpp +1 -0
  12. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/src/python_interface/inputs.cpp +8 -0
  13. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/src/python_interface/utilities.cpp +8 -0
  14. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/src/qstls.cpp +71 -10
  15. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/src/qstlsiet.cpp +1 -0
  16. {qupled-1.3.4 → qupled-1.3.5}/src/qupled.egg-info/PKG-INFO +1 -1
  17. {qupled-1.3.4 → qupled-1.3.5}/src/qupled.egg-info/SOURCES.txt +1 -0
  18. {qupled-1.3.4 → qupled-1.3.5}/tests/test_database.py +24 -8
  19. {qupled-1.3.4 → qupled-1.3.5}/tests/test_hf.py +5 -2
  20. qupled-1.3.4/src/qupled/native/include/database.hpp +0 -18
  21. {qupled-1.3.4 → qupled-1.3.5}/.clang-format +0 -0
  22. {qupled-1.3.4 → qupled-1.3.5}/.devcontainer/Dockerfile +0 -0
  23. {qupled-1.3.4 → qupled-1.3.5}/.devcontainer/devcontainer.json +0 -0
  24. {qupled-1.3.4 → qupled-1.3.5}/.github/workflows/build-and-test.yml +0 -0
  25. {qupled-1.3.4 → qupled-1.3.5}/.github/workflows/build-linux-wheels.yml +0 -0
  26. {qupled-1.3.4 → qupled-1.3.5}/.github/workflows/build-macos-wheels.yml +0 -0
  27. {qupled-1.3.4 → qupled-1.3.5}/.github/workflows/build-sdist.yml +0 -0
  28. {qupled-1.3.4 → qupled-1.3.5}/.github/workflows/formatting.yml +0 -0
  29. {qupled-1.3.4 → qupled-1.3.5}/.github/workflows/release.yml +0 -0
  30. {qupled-1.3.4 → qupled-1.3.5}/.gitignore +0 -0
  31. {qupled-1.3.4 → qupled-1.3.5}/.readthedocs.yaml +0 -0
  32. {qupled-1.3.4 → qupled-1.3.5}/LICENSE +0 -0
  33. {qupled-1.3.4 → qupled-1.3.5}/MANIFEST.in +0 -0
  34. {qupled-1.3.4 → qupled-1.3.5}/README.md +0 -0
  35. {qupled-1.3.4 → qupled-1.3.5}/dev/devtool.py +0 -0
  36. {qupled-1.3.4 → qupled-1.3.5}/dev/requirements-apt.txt +0 -0
  37. {qupled-1.3.4 → qupled-1.3.5}/dev/requirements-brew.txt +0 -0
  38. {qupled-1.3.4 → qupled-1.3.5}/dev/requirements-pip.txt +0 -0
  39. {qupled-1.3.4 → qupled-1.3.5}/devtool +0 -0
  40. {qupled-1.3.4 → qupled-1.3.5}/docs/_static/css/rdt_theme_python_properties.css +0 -0
  41. {qupled-1.3.4 → qupled-1.3.5}/docs/conf.py +0 -0
  42. {qupled-1.3.4 → qupled-1.3.5}/docs/contribute.rst +0 -0
  43. {qupled-1.3.4 → qupled-1.3.5}/docs/examples.rst +0 -0
  44. {qupled-1.3.4 → qupled-1.3.5}/docs/index.rst +0 -0
  45. {qupled-1.3.4 → qupled-1.3.5}/docs/introduction.rst +0 -0
  46. {qupled-1.3.4 → qupled-1.3.5}/docs/make.bat +0 -0
  47. {qupled-1.3.4 → qupled-1.3.5}/docs/qupled.rst +0 -0
  48. {qupled-1.3.4 → qupled-1.3.5}/docs/requirements.txt +0 -0
  49. {qupled-1.3.4 → qupled-1.3.5}/examples/docs/fixed_adr.py +0 -0
  50. {qupled-1.3.4 → qupled-1.3.5}/examples/docs/initial_guess_stls.py +0 -0
  51. {qupled-1.3.4 → qupled-1.3.5}/examples/docs/solve_quantum_schemes.py +0 -0
  52. {qupled-1.3.4 → qupled-1.3.5}/examples/docs/solve_qvsstls.py +0 -0
  53. {qupled-1.3.4 → qupled-1.3.5}/examples/docs/solve_rpa_and_esa.py +0 -0
  54. {qupled-1.3.4 → qupled-1.3.5}/examples/docs/solve_stls.py +0 -0
  55. {qupled-1.3.4 → qupled-1.3.5}/examples/docs/solve_stls_iet.py +0 -0
  56. {qupled-1.3.4 → qupled-1.3.5}/examples/docs/solve_vsstls.py +0 -0
  57. {qupled-1.3.4 → qupled-1.3.5}/examples/readme/create_cover.py +0 -0
  58. {qupled-1.3.4 → qupled-1.3.5}/examples/readme/qupled_animation_dark.svg +0 -0
  59. {qupled-1.3.4 → qupled-1.3.5}/examples/readme/qupled_animation_light.svg +0 -0
  60. {qupled-1.3.4 → qupled-1.3.5}/manylinux/Dockerfile.manylinux_2_28 +0 -0
  61. {qupled-1.3.4 → qupled-1.3.5}/manylinux/build_manylinux_2_28 +0 -0
  62. {qupled-1.3.4 → qupled-1.3.5}/setup.cfg +0 -0
  63. {qupled-1.3.4 → qupled-1.3.5}/setup.py +0 -0
  64. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/__init__.py +0 -0
  65. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/esa.py +0 -0
  66. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/mpi.py +0 -0
  67. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/include/chemical_potential.hpp +0 -0
  68. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/include/dual.hpp +0 -0
  69. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/include/esa.hpp +0 -0
  70. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/include/format.hpp +0 -0
  71. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/include/free_energy.hpp +0 -0
  72. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/include/hf.hpp +0 -0
  73. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/include/iet.hpp +0 -0
  74. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/include/internal_energy.hpp +0 -0
  75. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/include/logger.hpp +0 -0
  76. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/include/mpi_util.hpp +0 -0
  77. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/include/num_util.hpp +0 -0
  78. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/include/numerics.hpp +0 -0
  79. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/include/python_interface/inputs.hpp +0 -0
  80. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/include/python_interface/schemes.hpp +0 -0
  81. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/include/python_interface/util.hpp +0 -0
  82. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/include/python_interface/utilities.hpp +0 -0
  83. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/include/qstlsiet.hpp +0 -0
  84. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/include/qvsstls.hpp +0 -0
  85. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/include/rdf.hpp +0 -0
  86. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/include/rpa.hpp +0 -0
  87. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/include/stls.hpp +0 -0
  88. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/include/stlsiet.hpp +0 -0
  89. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/include/thermo_util.hpp +0 -0
  90. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/include/vector2D.hpp +0 -0
  91. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/include/vector3D.hpp +0 -0
  92. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/include/vector_util.hpp +0 -0
  93. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/include/vsbase.hpp +0 -0
  94. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/include/vsstls.hpp +0 -0
  95. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/src/chemical_potential.cpp +0 -0
  96. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/src/esa.cpp +0 -0
  97. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/src/free_energy.cpp +0 -0
  98. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/src/hf.cpp +0 -0
  99. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/src/iet.cpp +0 -0
  100. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/src/internal_energy.cpp +0 -0
  101. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/src/logger.cpp +0 -0
  102. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/src/mpi_util.cpp +0 -0
  103. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/src/num_util.cpp +0 -0
  104. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/src/numerics.cpp +0 -0
  105. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/src/python_interface/native.cpp +0 -0
  106. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/src/python_interface/schemes.cpp +0 -0
  107. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/src/python_interface/util.cpp +0 -0
  108. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/src/qvsstls.cpp +0 -0
  109. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/src/rdf.cpp +0 -0
  110. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/src/rpa.cpp +0 -0
  111. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/src/stls.cpp +0 -0
  112. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/src/stlsiet.cpp +0 -0
  113. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/src/thermo_util.cpp +0 -0
  114. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/src/vector2D.cpp +0 -0
  115. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/src/vector3D.cpp +0 -0
  116. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/src/vector_util.cpp +0 -0
  117. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/src/vsbase.cpp +0 -0
  118. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/native/src/vsstls.cpp +0 -0
  119. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/output.py +0 -0
  120. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/qstls.py +0 -0
  121. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/qstlsiet.py +0 -0
  122. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/qvsstls.py +0 -0
  123. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/rpa.py +0 -0
  124. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/serialize.py +0 -0
  125. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/stls.py +0 -0
  126. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/stlsiet.py +0 -0
  127. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/timer.py +0 -0
  128. {qupled-1.3.4 → qupled-1.3.5}/src/qupled/vsstls.py +0 -0
  129. {qupled-1.3.4 → qupled-1.3.5}/src/qupled.egg-info/dependency_links.txt +0 -0
  130. {qupled-1.3.4 → qupled-1.3.5}/src/qupled.egg-info/not-zip-safe +0 -0
  131. {qupled-1.3.4 → qupled-1.3.5}/src/qupled.egg-info/requires.txt +0 -0
  132. {qupled-1.3.4 → qupled-1.3.5}/src/qupled.egg-info/top_level.txt +0 -0
  133. {qupled-1.3.4 → qupled-1.3.5}/tests/native/conftest.py +0 -0
  134. {qupled-1.3.4 → qupled-1.3.5}/tests/native/test_esa_native.py +0 -0
  135. {qupled-1.3.4 → qupled-1.3.5}/tests/native/test_hf_native.py +0 -0
  136. {qupled-1.3.4 → qupled-1.3.5}/tests/native/test_qstls_iet_native.py +0 -0
  137. {qupled-1.3.4 → qupled-1.3.5}/tests/native/test_qstls_native.py +0 -0
  138. {qupled-1.3.4 → qupled-1.3.5}/tests/native/test_qvsstls_native.py +0 -0
  139. {qupled-1.3.4 → qupled-1.3.5}/tests/native/test_rpa_native.py +0 -0
  140. {qupled-1.3.4 → qupled-1.3.5}/tests/native/test_stls_iet_native.py +0 -0
  141. {qupled-1.3.4 → qupled-1.3.5}/tests/native/test_stls_native.py +0 -0
  142. {qupled-1.3.4 → qupled-1.3.5}/tests/native/test_vsstls_native.py +0 -0
  143. {qupled-1.3.4 → qupled-1.3.5}/tests/test_esa.py +0 -0
  144. {qupled-1.3.4 → qupled-1.3.5}/tests/test_mpi.py +0 -0
  145. {qupled-1.3.4 → qupled-1.3.5}/tests/test_output.py +0 -0
  146. {qupled-1.3.4 → qupled-1.3.5}/tests/test_qstls.py +0 -0
  147. {qupled-1.3.4 → qupled-1.3.5}/tests/test_qstlsiet.py +0 -0
  148. {qupled-1.3.4 → qupled-1.3.5}/tests/test_qvsstls.py +0 -0
  149. {qupled-1.3.4 → qupled-1.3.5}/tests/test_rpa.py +0 -0
  150. {qupled-1.3.4 → qupled-1.3.5}/tests/test_stls.py +0 -0
  151. {qupled-1.3.4 → qupled-1.3.5}/tests/test_stlsiet.py +0 -0
  152. {qupled-1.3.4 → qupled-1.3.5}/tests/test_vsstls.py +0 -0
  153. {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.4
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
- database_name = DataBaseHandler.DEFAULT_DATABASE_NAME
25
- if os.path.exists(database_name):
26
- os.remove(database_name)
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.4"
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
- RUN_TABLE_NAME = "runs"
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
- self.database_name = (
65
- database_name if database_name is not None else self.DEFAULT_DATABASE_NAME
70
+ # Database path
71
+ database_name = (
72
+ self.DEFAULT_DATABASE_NAME if database_name is None else database_name
66
73
  )
67
- self.engine = sql.create_engine(f"sqlite:///{self.database_name}")
68
- # Enforce foreign keys in sqlite
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.run_id = self.run_id
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 = field(default_factory=lambda: 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
- name: str = database.DataBaseHandler.DEFAULT_DATABASE_NAME
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
- // SQL queries
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
- adr BLOB NOT NULL,
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, adr) VALUES (?, ?, ?);";
71
+ "INSERT OR REPLACE INTO {} (run_id, name, value) VALUES (?, ?, ?);";
72
72
 
73
73
  constexpr const char *SQL_SELECT =
74
- "SELECT adr FROM {} WHERE run_id = ? AND name = ?;";
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
  // -----------------------------------------------------------------
@@ -49,6 +49,7 @@ add_compile_options(-Wall -Wextra -Wpedantic -O3)
49
49
  # Source code
50
50
  pybind11_add_module(native
51
51
  logger.cpp
52
+ database.cpp
52
53
  numerics.cpp
53
54
  vector2D.cpp
54
55
  vector3D.cpp
@@ -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 <cmath>
5
5
 
6
6
  using namespace std;
7
+ using namespace databaseUtil;
7
8
  using namespace MPIUtil;
8
9
 
9
10
  // -----------------------------------------------------------------
@@ -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
- // Prepare binary data
115
- const void *adrData = static_cast<const void *>(res.data());
116
- const int adrSize = static_cast<int>(res.size() * sizeof(double));
117
- // Insert data
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, adrData, adrSize);
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 void *adrData = statement.getColumn(0).getBlob();
141
- int adrBytes = statement.getColumn(0).getBytes();
142
- if (static_cast<size_t>(adrBytes) != res.size() * sizeof(double)) {
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
- adrBytes));
158
+ in.gcount()));
147
159
  }
148
- memcpy(res.data(), adrData, adrBytes);
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
  // -----------------------------------------------------------------
@@ -10,6 +10,7 @@
10
10
  #include <numeric>
11
11
 
12
12
  using namespace std;
13
+ using namespace databaseUtil;
13
14
  using namespace vecUtil;
14
15
  using namespace MPIUtil;
15
16
  using ItgParam = Integrator1D::Param;
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: qupled
3
- Version: 1.3.4
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
- if os.path.exists(handler.database_name):
23
- os.remove(handler.database_name)
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
- assert db_handler.database_name == DataBaseHandler.DEFAULT_DATABASE_NAME
28
- assert db_handler.engine.url.database == DataBaseHandler.DEFAULT_DATABASE_NAME
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.database_name == database_name
42
- assert db_handler.engine.url.database == database_name
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(db_handler.database_name):
51
- os.remove(db_handler.database_name)
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 == dbInfo.return_value
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.name == hf.database.DataBaseHandler.DEFAULT_DATABASE_NAME
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