Data of OpenQP - Open-Quantum-Platform/openqp GitHub Wiki

Combining high-performance compiled languages with the flexible Python environment provides an ideal framework but introduces challenges in data sharing across multiple languages. To address this, successful modularization relies on data abstraction—a fundamental concept that hides the complexities of data storage and processing, presenting only essential information in a simplified manner to the user.

To tackle this challenge, we first define a structured data type, information, which encompasses all the fundamental scalar data needed by OpenQP. The Fortran definition of information is shown below, where each element is also a structured data type. This information is initially allocated in the Python layer as mol, as depicted in Fig. below. Instead of passing individual data through arguments, its handler is passed to Fortran via the C API. By using a single structured data type, mol, the complexities of data exchange are minimized, thereby simplifying workflow extension. With this handler, the Fortran layer can directly read from and write to mol. Consequently, the calculation results from Fortran modules are saved in mol, making them immediately accessible from the Python environment without needing to pass data through a sequence of arguments.

sharing_memory

The derived information type is defined in source/types.F90 as follows:

type, public :: information
    type(molecule) :: mol_prop
    type(energy_results) :: mol_energy
    type(dft_parameters) :: dft
    type(control_parameters) :: control
    type(atomic_structure) :: atoms
    type(functional_t) :: functional
    type(tddft_parameters) :: tddft
    type(container_t) :: dat
    type(basis_set) :: basis
contains
    generic :: set_atoms => set_atoms_arr, set_atoms_atm
    procedure, pass :: set_atoms_arr => info_set_atoms_arr
    procedure, pass :: set_atoms_atm => info_set_atoms_atm
end type information

C API Integration

Certain components of the derived information type are accessible through the C API under the name oqp_handle_t, which is defined in include/oqp.h as follows:

typedef struct oqp_handle_t {
    void *inf;
    xyz_t *xyz;
    double *qn;
    double *mass;
    xyz_t *grad;
    struct molecule *mol_prop;
    struct energy_results *mol_energy;
    struct dft_parameters *dft;
    struct tddft_parameters *tddft;
    struct control_parameters *control;
} oqp_handle_t;

Memory Management and Data Access

While most of the data involved are relatively small and can be defined using static memory, certain critical intermediate quantities—such as the Fock matrix—require dynamic memory allocation. Moreover, it is essential that this dynamically allocated data be transparently accessible across all layers of OpenQP, ensuring bidirectional access between Python and Fortran environments.

Interoperability Solution: Tagarray

To facilitate seamless data access and interoperability between Python and Fortran, a separate tool named tagarray has been developed. This tool allows for the efficient handling and exchange of dynamically allocated data between different layers and languages within OpenQP.

Going back to Developer Documentation