Skip to content

Commit

Permalink
Add method to check C-API version of CADET-Core
Browse files Browse the repository at this point in the history
  • Loading branch information
schmoelder authored and ronald-jaepel committed Aug 23, 2024
1 parent 4a190fb commit 9d8411f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 15 deletions.
26 changes: 17 additions & 9 deletions cadet/cadet.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,14 @@ def __init__(self, install_path: Optional[Path] = None, use_dll: bool = False, *
self.use_dll = use_dll

if hasattr(self, "cadet_dll_path") and self.cadet_dll_path is not None:
self._cadet_dll_runner: Optional[CadetDLLRunner] = CadetDLLRunner(
self.cadet_dll_path
)
try:
self._cadet_dll_runner: Optional[CadetDLLRunner] = CadetDLLRunner(
self.cadet_dll_path
)
except ValueError:
self.cadet_dll_path = None
self._cadet_dll_runner: Optional[CadetCLIRunner] = None
self.use_dll = False
else:
self._cadet_dll_runner: Optional[CadetCLIRunner] = None
self.use_dll = use_dll
Expand Down Expand Up @@ -263,15 +268,18 @@ def install_path(self, install_path: Optional[os.PathLike]) -> None:
root_path, cadet_cli_path, cadet_dll_path, create_lwe_path = install_path_to_cadet_paths(install_path)

self._install_path = root_path
self.cadet_cli_path = cadet_cli_path
self.cadet_dll_path = cadet_dll_path
self.cadet_create_lwe_path = create_lwe_path

if self.cadet_cli_path is not None:
self._cadet_cli_runner = CadetCLIRunner(self.cadet_cli_path)
if self.cadet_dll_path is not None:
self._cadet_dll_runner = CadetDLLRunner(self.cadet_dll_path)
if cadet_cli_path is not None:
self._cadet_cli_runner = CadetCLIRunner(cadet_cli_path)
self.cadet_cli_path = cadet_cli_path

self.cadet_dll_path = cadet_dll_path
if cadet_dll_path is not None:
try:
self._cadet_dll_runner = CadetDLLRunner(cadet_dll_path)
except ValueError:
pass

@property
def cadet_path(self) -> Optional[Path]:
Expand Down
27 changes: 21 additions & 6 deletions cadet/cadet_dll.py
Original file line number Diff line number Diff line change
Expand Up @@ -1668,12 +1668,27 @@ def __init__(self, dll_path: os.PathLike | str) -> None:
self._default_log_level = 2

# Query API
cdtGetAPIv010000 = self._lib.cdtGetAPIv010000
cdtGetAPIv010000.argtypes = [ctypes.POINTER(CADETAPIV010000)]
cdtGetAPIv010000.restype = c_cadet_result

self._api = CADETAPIV010000()
cdtGetAPIv010000(ctypes.byref(self._api))
try:
cdtGetLatestCAPIVersion = self._lib.cdtGetLatestCAPIVersion#
except AttributeError:
raise ValueError(
"CADET-Python does not support CADET-CAPI at all."
)
cdtGetLatestCAPIVersion.restype = ctypes.c_char_p
self._cadet_capi_version = cdtGetLatestCAPIVersion().decode('utf-8')

# Check which C-API is provided by CADET (given the current install path)
if self._cadet_capi_version == "1.0.0":
cdtGetAPIv010000 = self._lib.cdtGetAPIv010000
cdtGetAPIv010000.argtypes = [ctypes.POINTER(CADETAPIV010000)]
cdtGetAPIv010000.restype = c_cadet_result
self._api = CADETAPIV010000()
cdtGetAPIv010000(ctypes.byref(self._api))
else:
raise ValueError(
"CADET-Python does not support CADET-CAPI version "
f"({self._cadet_capi_version})."
)

self._driver = self._api.createDriver()
self.res: Optional[SimulationResult] = None
Expand Down

0 comments on commit 9d8411f

Please sign in to comment.