Python API
qupled is a hybrid Python/C++ package designed to simulate and analyze dielectric response schemes, both classical and quantum. Python orchestrates the workflow: setting up simulations, managing input/output, and storing results in an SQLite database. C++ performs the heavy numerical computations, accessed via pybind11 bindings.
To run a simulation, users configure input parameters through Python classes
(e.g., qupled.schemes.hf.Input) and launch the computation using the corresponding solver
class (e.g., qupled.schemes.hf.HF). Results are returned in dedicated result objects
(e.g., qupled.schemes.hf.Result) and automatically written to an SQLite database for
post-processing or analysis.
The database is implemented in standard SQLite format and can be accessed using any
compatible external tool (e.g., sqlite3, DB Browser for SQLite). For convenience,
the package provides a dedicated Python interface in the qupled.postprocess.output.Database
class, which includes helper methods to query, inspect, and extract stored simulation
data programmatically.
The sections below describe the supported schemes in more detail, including their respective input, solver, and result classes.
Classic schemes
HF scheme
The qupled.schemes.hf module is used to setup and perform all the necessary calculations
for the solution of the Hartree-Fock approximation.
The solution parameters are specified with a dedicated class called qupled.schemes.hf.Input.
After the solution is completed the results are stored in an object qupled.schemes.hf.Result
and written to the output database.
- class qupled.schemes.hf.Solver
Class used to solve the HF scheme.
- property run_id
Property that retrieves the run ID from the database handler.
- Returns
The run ID associated with the current database handler.
- Return type
str
- compute_rdf(rdf_grid: ndarray = None)
Computes the radial distribution function (RDF) using the provided RDF grid.
- Parameters
rdf_grid – A numpy array representing the RDF grid. If not provided, a default grid will be used.
- compute_itcf(tau: numpy.ndarray | None = None)
Computes the imaginary-time correlation function (ITCF) using the provided imaginary-time grid.
- Parameters
tau – A numpy array representing the imaginary-time grid. If not provided, a default grid will be used.
- get_solver_status() RunStatus
Retrieves the current status of the solver based on the native scheme status.
- Returns
The corresponding run status from the
- Return type
RunStatus
- class qupled.schemes.hf.Input(coupling: float, degeneracy: float, chemical_potential: list[float] = <factory>, cutoff: float = 10.0, dimension: ~qupled.util.dimension.Dimension = Dimension._3D, frequency_cutoff: float = 10.0, integral_error: float = 1e-05, integral_strategy: str = 'full', matsubara: int = 128, resolution: float = 0.1, threads: int = 1, processes: int = 1, theory: str = 'HF', database_info: ~qupled.schemes.hf.DatabaseInfo = None)
Class used to store the inputs for the
qupled.hf.HFclass.- coupling: float
Coupling parameter.
- degeneracy: float
Degeneracy parameter.
- chemical_potential: list[float]
Initial guess for the chemical potential. Default =
[-10, 10]
- cutoff: float = 10.0
Cutoff for the wave-vector grid. Default =
10.0
- frequency_cutoff: float = 10.0
Cutoff for the frequency (applies only in the ground state). Default =
10.0
- integral_error: float = 1e-05
Accuracy (relative error) in the computation of integrals. Default =
1.0e-5
- integral_strategy: str = 'full'
Scheme used to solve two-dimensional integrals allowed options include:
full: the inner integral is evaluated at arbitrary points selected automatically by the quadrature rule
segregated: the inner integral is evaluated on a fixed grid that depends on the integrand that is being processed
Segregated is usually faster than full but it could become less accurate if the fixed points are not chosen correctly. Default =
'full'
- matsubara: int = 128
Number of Matsubara frequencies. Default =
128
- resolution: float = 0.1
Resolution of the wave-vector grid. Default =
0.1
- threads: int = 1
Number of OMP threads for parallel calculations. Default =
1
- processes: int = 1
Number of MPI processes for parallel calculations. Default =
1
- class qupled.schemes.hf.Result(chemical_potential: float = None, idr: ndarray = None, itcf: ndarray = None, lfc: ndarray = None, rdf: ndarray = None, rdf_grid: ndarray = None, sdr: ndarray = None, ssf: ndarray = None, tau: ndarray = None, uint: float = None, wvg: ndarray = None)
Class used to store the results for the
qupled.hf.HFclass.- chemical_potential: float = None
Chemical potential
- idr: ndarray = None
Ideal density response
- itcf: ndarray = None
Imaginary-time correlation function
- lfc: ndarray = None
Local field correction
- rdf: ndarray = None
Radial distribution function
- rdf_grid: ndarray = None
Radial distribution function grid
- sdr: ndarray = None
Static density response
- ssf: ndarray = None
Static structure factor
- tau: ndarray = None
Imaginary-time grid
- uint: float = None
Internal energy
- wvg: ndarray = None
Wave-vector grid
- compute_itcf(inputs: Input, tau: numpy.ndarray | None = None)
Compute the imaginary-time correlation function (ITCF) for the system.
The imaginary-time grid is in absolute units [0, 1/theta], where theta is the degeneracy parameter. For ground-state calculations (theta = 0), tau is unbounded and defaults to np.arange(0.0, 10.1, 0.1). For finite-temperature calculations, tau is clipped to [0, 1/theta] and defaults to np.arange(0.0, 1.1, 0.1) / theta.
- Parameters
inputs – Input parameters used for the ITCF computation.
tau (np.ndarray | None, optional) – A 1D array of imaginary-time points in absolute units [0, 1/theta]. If None, a default grid is generated based on the degeneracy parameter.
- Raises
ValueError – If the wave-vector grid (wvg) or the local field correction (lfc) is not available.
- Returns
- The computed ITCF and imaginary-time grid are stored in the self.itcf
and self.tau attributes respectively.
- Return type
None
Rpa scheme
The qupled.schemes.rpa module is used to setup and perform all the necessary calculations
for the solution of the Random-Phase Approximation.
The solution parameters are specified with a dedicated class called qupled.schemes.rpa.Input.
After the solution is completed the results are stored in an object qupled.schemes.hf.Result
and written to the output database.
- class qupled.schemes.rpa.Input(coupling: float, degeneracy: float, chemical_potential: list[float] = <factory>, cutoff: float = 10.0, dimension: Dimension = Dimension._3D, frequency_cutoff: float = 10.0, integral_error: float = 1e-05, integral_strategy: str = 'full', matsubara: int = 128, resolution: float = 0.1, threads: int = 1, processes: int = 1, theory: str = 'RPA', database_info: DatabaseInfo = None)
Bases:
InputClass used to manage the input for the
qupled.rpa.Rpaclass.
Stls scheme
The qupled.schemes.stls module is used to setup and perform all the necessary calculations
for the solution of the Stls scheme.
The solution parameters are specified with a dedicated class called qupled.schemes.stls.Input.
After the solution is completed the results are stored in an object qupled.schemes.stls.Result
and written to the output database.
- class qupled.schemes.stls.Solver
Bases:
SolverClass used to solve the Stls scheme.
- static get_initial_guess(run_id: int, database_name: str | None = None) Guess
Constructs an initial guess object by extracting the information from a database.
- Parameters
run_id – The unique identifier for the run whose data is to be retrieved.
database_name – The name of the database to query. If None, the default database will be used.
- Returns
An instance of Guess containing the initial guess data.
- class qupled.schemes.stls.Input(coupling: float, degeneracy: float, chemical_potential: list[float] = <factory>, cutoff: float = 10.0, dimension: Dimension = Dimension._3D, frequency_cutoff: float = 10.0, integral_error: float = 1e-05, integral_strategy: str = 'full', matsubara: int = 128, resolution: float = 0.1, threads: int = 1, processes: int = 1, theory: str = 'STLS', database_info: DatabaseInfo = None, error: float = 1e-05, mixing: float = 1.0, iterations: int = 1000, guess: Guess = <factory>)
Bases:
InputClass used to manage the input for the
qupled.stls.Stlsclass.- error: float = 1e-05
Minimum error for convergence. Default =
1.0e-5
- mixing: float = 1.0
Mixing parameter. Default =
1.0
- iterations: int = 1000
Maximum number of iterations. Default =
1000
- class qupled.schemes.stls.Result(chemical_potential: float = None, idr: ndarray = None, itcf: ndarray = None, lfc: ndarray = None, rdf: ndarray = None, rdf_grid: ndarray = None, sdr: ndarray = None, ssf: ndarray = None, tau: ndarray = None, uint: float = None, wvg: ndarray = None, error: float = None)
Bases:
ResultClass used to store the results for the
qupled.stls.Stlsclass.- error: float = None
Final error of the scheme. Default =
None
Stls-IET schemes
The qupled.schemes.stlsiet module is used to setup and perform all the necessary calculations
for the solution of the Stls-IET schemes.
The solution parameters are specified with a dedicated class called qupled.schemes.stlsiet.Input.
After the solution is completed the results are stored in an object qupled.schemes.stlsiet.Result
and written to the output database.
- class qupled.schemes.stlsiet.Solver
Bases:
SolverClass used to solve the StlsIet schemes.
- static get_initial_guess(run_id: str, database_name: str | None = None) Guess
Retrieves the initial guess for a computation based on a specific run ID from a database.
- Parameters
run_id – The unique identifier for the run whose data is to be retrieved.
database_name – The name of the database to query. If None, the default database is used.
- Returns
An object containing the initial guess values, including results and inputs extracted from the database.
- Return type
- class qupled.schemes.stlsiet.Input(coupling: float, degeneracy: float, chemical_potential: list[float] = <factory>, cutoff: float = 10.0, dimension: Dimension = Dimension._3D, frequency_cutoff: float = 10.0, integral_error: float = 1e-05, integral_strategy: str = 'full', matsubara: int = 128, resolution: float = 0.1, threads: int = 1, processes: int = 1, theory: str = 'STLS', database_info: DatabaseInfo = None, error: float = 1e-05, mixing: float = 1.0, iterations: int = 1000, guess: Guess = <factory>, mapping: str = 'standard')
Bases:
InputClass used to manage the input for the
qupled.stlsiet.StlsIetclass. Accepted theories:STLS-HNC,STLS-IOIandSTLS-LCT.- mapping: str = 'standard'
Mapping for the classical-to-quantum coupling parameter \(\Gamma\) used in the iet schemes. Allowed options include:
standard: \(\Gamma \propto \Theta^{-1}\)
sqrt: \(\Gamma \propto (1 + \Theta)^{-1/2}\)
linear: \(\Gamma \propto (1 + \Theta)^{-1}\)
where \(\Theta\) is the degeneracy parameter. Far from the ground state (i.e. \(\Theta\gg1\)) all mappings lead identical results, but at the ground state they can differ significantly (the standard mapping diverges). Default =
standard.
- class qupled.schemes.stlsiet.Result(chemical_potential: float = None, idr: ndarray = None, itcf: ndarray = None, lfc: ndarray = None, rdf: ndarray = None, rdf_grid: ndarray = None, sdr: ndarray = None, ssf: ndarray = None, tau: ndarray = None, uint: float = None, wvg: ndarray = None, error: float = None, bf: ndarray = None)
Bases:
ResultClass used to store the results for the
qupled.stlsiet.StlsIetclass.- bf: ndarray = None
Bridge function adder
VSStls scheme
The qupled.schemes.vsstls module is used to setup and perform all the necessary calculations
for the solution of the VSStls scheme.
The solution parameters are specified with a dedicated class called qupled.schemes.vsstls.Input.
After the solution is completed the results are stored in an object qupled.schemes.vsstls.Result
and written to the output database.
- class qupled.schemes.vsstls.Input(coupling: float, degeneracy: float, chemical_potential: list[float] = <factory>, cutoff: float = 10.0, dimension: Dimension = Dimension._3D, frequency_cutoff: float = 10.0, integral_error: float = 1e-05, integral_strategy: str = 'full', matsubara: int = 128, resolution: float = 0.1, threads: int = 9, processes: int = 1, theory: str = 'VSSTLS', database_info: DatabaseInfo = None, error: float = 1e-05, mixing: float = 1.0, iterations: int = 1000, guess: Guess = <factory>, alpha: list[float] = <factory>, coupling_resolution: float = 0.1, degeneracy_resolution: float = 0.1, error_alpha: float = 0.001, iterations_alpha: int = 50, free_energy_integrand: FreeEnergyIntegrand = <factory>)
Bases:
InputClass used to manage the input for the
qupled.vsstls.VSStlsclass.- alpha: list[float]
Initial guess for the free parameter. Default =
[0.5, 1.0]
- coupling_resolution: float = 0.1
Resolution of the coupling parameter grid. Default =
0.1
- degeneracy_resolution: float = 0.1
Resolution of the degeneracy parameter grid. Default =
0.1
- error_alpha: float = 0.001
Minimum error for convergence in the free parameter. Default =
1.0e-3
- iterations_alpha: int = 50
Maximum number of iterations to determine the free parameter. Default =
50
- free_energy_integrand: FreeEnergyIntegrand
Pre-computed free energy integrand.
- threads: int = 9
Number of threads. Default =
9
- class qupled.schemes.vsstls.Result(chemical_potential: float = None, idr: ndarray = None, itcf: ndarray = None, lfc: ndarray = None, rdf: ndarray = None, rdf_grid: ndarray = None, sdr: ndarray = None, ssf: ndarray = None, tau: ndarray = None, uint: float = None, wvg: ndarray = None, error: float = None, free_energy_grid: ndarray = None, free_energy_integrand: ndarray = None, alpha: float = None)
Bases:
ResultClass used to store the results for the
qupled.vsstls.VSStlsclass.- free_energy_grid: ndarray = None
Free energy grid
- free_energy_integrand: ndarray = None
Free energy integrand
- alpha: float = None
Free parameter
Hybrid schemes
ESA scheme
The qupled.schemes.esa module is used to setup and perform all the necessary calculations
for the solution of the Effective Static Approximation.
The solution parameters are specified with a dedicated class called qupled.schemes.esa.Input.
After the solution is completed the results are stored in an object qupled.schemes.hf.Result
and written to the output database.
- class qupled.schemes.esa.Input(coupling: float, degeneracy: float, chemical_potential: list[float] = <factory>, cutoff: float = 10.0, dimension: Dimension = Dimension._3D, frequency_cutoff: float = 10.0, integral_error: float = 1e-05, integral_strategy: str = 'full', matsubara: int = 128, resolution: float = 0.1, threads: int = 1, processes: int = 1, theory: str = 'ESA', database_info: DatabaseInfo = None)
Bases:
InputClass used to manage the input for the
qupled.esa.ESAclass.
Quantum schemes
Qstls scheme
The qupled.schemes.qstls module is used to setup and perform all the necessary calculations
for the solution of the Qstls scheme.
TThe solution parameters are specified with a dedicated class called qupled.schemes.qstls.Input.
After the solution is completed the results are stored in an object qupled.schemes.stls.Result
and written to the output database.
- class qupled.schemes.qstls.Input(coupling: float, degeneracy: float, chemical_potential: list[float] = <factory>, cutoff: float = 10.0, dimension: Dimension = Dimension._3D, frequency_cutoff: float = 10.0, integral_error: float = 1e-05, integral_strategy: str = 'full', matsubara: int = 128, resolution: float = 0.1, threads: int = 1, processes: int = 1, theory: str = 'QSTLS', database_info: DatabaseInfo = None, error: float = 1e-05, mixing: float = 1.0, iterations: int = 1000, guess: Guess = <factory>, fixed_run_id: int | None = None)
Bases:
InputClass used to manage the input for the
qupled.qstls.Qstlsclass.
Qstls-IET scheme
The qupled.schemes.qstlsiet module is used to setup and perform all the necessary calculations
for the solution of the Qstls-IET schemes.
The solution parameters are specified with a dedicated class called qupled.schemes.qstlsiet.Input.
After the solution is completed the results are stored in an object qupled.schemes.stlsiet.Result
and written to the output database.
- class qupled.schemes.qstlsiet.Solver
Bases:
SolverClass used to solve the Qstls-IET schemes.
- static get_initial_guess(run_id: str, database_name: str | None = None) Guess
Constructs an initial guess object by extracting the information from a database.
- Parameters
run_id – The unique identifier for the run whose data is to be retrieved.
database_name – The name of the database to query. If None, the default database will be used.
- Returns
An instance of Guess containing the initial guess data.
- class qupled.schemes.qstlsiet.Input(coupling: float, degeneracy: float, chemical_potential: list[float] = <factory>, cutoff: float = 10.0, dimension: Dimension = Dimension._3D, frequency_cutoff: float = 10.0, integral_error: float = 1e-05, integral_strategy: str = 'full', matsubara: int = 128, resolution: float = 0.1, threads: int = 1, processes: int = 1, theory: str = 'STLS', database_info: DatabaseInfo = None, error: float = 1e-05, mixing: float = 1.0, iterations: int = 1000, guess: Guess = <factory>, fixed_run_id: int | None = None, mapping: str = 'standard')
-
Class used to manage the input for the
qupled.qstlsiet.QStlsIetclass. Accepted theories:QSTLS-HNC,QSTLS-IOIandQSTLS-LCT.
QVSStls scheme
The qupled.schemes.qvsstls.QVSStls class is used to setup and perform all the necessary calculations
for the solution of the QVStls schemes. The solution parameters are specified with a dedicated class
called qupled.schemes.qvsstls.Input. After the solution is completed the results are stored in an
object qupled.schemes.vsstls.Result and written to the output database.
- class qupled.schemes.qvsstls.Input(coupling: float, degeneracy: float, chemical_potential: list[float] = <factory>, cutoff: float = 10.0, dimension: Dimension = Dimension._3D, frequency_cutoff: float = 10.0, integral_error: float = 1e-05, integral_strategy: str = 'full', matsubara: int = 128, resolution: float = 0.1, threads: int = 9, processes: int = 1, theory: str = 'QVSSTLS', database_info: DatabaseInfo = None, error: float = 1e-05, mixing: float = 1.0, iterations: int = 1000, guess: Guess = <factory>, fixed_run_id: int | None = None, alpha: list[float] = <factory>, coupling_resolution: float = 0.1, degeneracy_resolution: float = 0.1, error_alpha: float = 0.001, iterations_alpha: int = 50, free_energy_integrand: FreeEnergyIntegrand = <factory>)
-
Class used to manage the input for the
qupled.qvsstls.QVSStlsclass.
Finite Size Correction
The qupled.postprocess.finite_size_correction.FiniteSizeCorrection class is used to setup and perform
all the necessary calculations to compute the finite size correction. The solution parameters are
specified with a dedicated class called qupled.postprocess.finite_size_correction.Input. After the
solution is completed the results are stored in an object qupled.postprocess.finite_size_correction.Result
and written to the output database.
- class qupled.postprocess.finite_size_correction.FiniteSizeCorrection
Post-processing FSC solver. It computes and writes results into the scheme run at (rs=target_rs, theta, dimension).
- property run_id
Property that retrieves the run ID from the database handler.
- Returns
The run ID associated with the current database handler.
- Return type
str
- class qupled.postprocess.finite_size_correction.Input(number_of_particles: int, drs: float = 0.1, scheme: Input = None)
Class used to store the inputs for the
qupled.finite_size_correction.FiniteSizeCorrectionclass.- number_of_particles: int
Number of particles.
- drs: float = 0.1
Coupling parameter resolution. Default =
0.1
Output database
The output generated by qupled is stored in an SQL database named qupled.db, which is created in
the directory where qupled is executed. If the database doesn’t already exist, it will be created
automatically; otherwise, new results are added to the existing database. The qupled.postprocess.output.DataBase
class provides functionality for accessing the data stored in the database.
- class qupled.postprocess.output.DataBase
Class to read and delete data from a database generated by qupled
- static inspect_runs(type: OutputType = OutputType.SCHEME, database_name: str | None = None) dict
Reads runs from the database and returns the content in the form of a dictionary.
- Parameters
type – The type of output to inspect. Defaults to OutputType.SCHEME.
database_name – Name of the database to read from. Defaults to None.
- Returns
A dictionary whose keys are the run IDs and values are the corresponding run information.
- Return type
dict
- static read_run(run_id: int, type: OutputType = OutputType.SCHEME, database_name: str | None = None, input_names: list[str] | None = None, result_names: list[str] | None = None) qupled.database.base_tables.RunData | None
Reads a specific run from the database.
- Parameters
run_id – The ID of the run to read.
type – The type of output to read. Defaults to OutputType.SCHEME.
database_name – The name of the database to read from. Defaults to None.
input_names – A list of input names to retrieve. Defaults to None.
result_names – A list of result names to retrieve. Defaults to None.
- Returns
Object containing the run data, or None if not found.
- Return type
RunData
- static read_inputs(run_id: int, type: OutputType = OutputType.SCHEME, database_name: str | None = None, names: list[str] | None = None) dict
Reads inputs from the database and returns the content in the form of a dictionary.
- Parameters
run_id – Identifier of the run to read inputs for.
type – The type of output to read inputs for. Defaults to OutputType.SCHEME.
database_name – Name of the database to read from. Defaults to None.
names – A list of quantities to read. Defaults to None, which reads all available quantities.
- Returns
A dictionary whose keys are the quantities listed in names and values are the corresponding inputs.
- Return type
dict
- static read_results(run_id: int, type: OutputType = OutputType.SCHEME, database_name: str | None = None, names: list[str] | None = None) dict
Reads results from the database and returns the content in the form of a dictionary.
- Parameters
type – The type of output to read results for.
run_id – Identifier of the run to read results for. Defaults to OutputType.SCHEME.
database_name – Name of the database to read from. Defaults to None.
names – A list of quantities to read. Defaults to None, which reads all available quantities.
- Returns
A dictionary whose keys are the quantities listed in names and values are the corresponding results.
- Return type
dict
- static delete_run(run_id: int, type: OutputType = OutputType.SCHEME, database_name: str | None = None)
Deletes a run entry from the database based on the provided run ID.
- Parameters
run_id – The unique identifier of the run to be deleted.
type – The type of output to delete. Defaults to OutputType.SCHEME.
database_name – The name of the database to connect to. Defaults to None.
- class qupled.postprocess.output.OutputType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)
An enumerator representing the output types.
Values:
SCHEME: Output from a scheme calculation.FINITE_SIZE_CORRECTION: Output from a finite size correction calculation.
Dimenions
- class qupled.util.dimension.Dimension(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)
An enumerator representing spatial dimensions.
Values:
_2D: Represents a two-dimensional space._3D: Represents a three-dimensional space.