diff --git a/cadet/cadet.py b/cadet/cadet.py index 7644d88..957a994 100644 --- a/cadet/cadet.py +++ b/cadet/cadet.py @@ -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 @@ -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 + if cadet_dll_path is not None: + try: + self._cadet_dll_runner = CadetDLLRunner(cadet_dll_path) + self.cadet_dll_path = cadet_dll_path + except ValueError: + pass @property def cadet_path(self) -> Optional[Path]: diff --git a/cadet/cadet_dll.py b/cadet/cadet_dll.py index 69ca98f..a93005d 100644 --- a/cadet/cadet_dll.py +++ b/cadet/cadet_dll.py @@ -1668,12 +1668,22 @@ 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)) + cdtGetLatestCAPIVersion = self._lib.cdtGetLatestCAPIVersion + 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