From 353e448e81ba21e001e935bc0b074daf2f97c9af Mon Sep 17 00:00:00 2001 From: "Lanzrath, Hannah" Date: Fri, 12 Jul 2024 16:06:16 +0200 Subject: [PATCH] Adds get_cadet_version() This commit adds a get_cadet_version() function and calls it inside run_simulation. --- tests/create_LWE.py | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/tests/create_LWE.py b/tests/create_LWE.py index c86458ee6..ce0294180 100644 --- a/tests/create_LWE.py +++ b/tests/create_LWE.py @@ -1,5 +1,8 @@ import numpy as np from typing import NoReturn +import subprocess +import re +import warnings from CADETProcess.simulator import Cadet from CADETProcess import CADETProcessError @@ -76,16 +79,43 @@ def create_lwe(unit_type: str, **kwargs) -> Process: def run_simulation(process: Process, cadet_install_path: str = None) -> NoReturn: - process_simulator = Cadet( - install_path=cadet_install_path) + process_simulator = Cadet(install_path=cadet_install_path) simulation_results = process_simulator.simulate(process) + cadet_version = get_cadet_version(process_simulator.cadet_path) + + if cadet_version < '5.0.0': + warnings.warn( + f'You are using CADET version {cadet_version}, which might not support all unit operations.' + f'Please make sure to point to the correct CADET installation.', + UserWarning + ) + if simulation_results.exit_flag == 0: print( f'CADET-Process LWE test simulation for unit {process.flow_sheet.unit_names[1]} completed successfully') else: raise CADETProcessError( - f'CADET-Process LWE test simulation failed with {simulation_results.exit_message}') + f'CADET-Process LWE test simulation failed with {simulation_results.exit_message}' + ) + + +def get_cadet_version(cadet_install_path: str) -> str: + version_output = subprocess.run( + [cadet_install_path, '--version'], + check=True, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + text=True + ).stdout.strip() + + version_match = re.search(r'cadet-cli version (\d+\.\d+\.\d+)', version_output) + if version_match: + cadet_version = version_match.group(1) + else: + raise ValueError("Unable to determine CADET version from the output") + + return cadet_version def run_simulation_for_all_units(cadet_install_path: str = None) -> None: @@ -300,4 +330,5 @@ def configure_flow_direction(unit_operation, **kwargs): if __name__ == "__main__": process = create_lwe('cstr') run_simulation(process) - run_simulation_for_all_units(cadet_install_path='C:/new_cadet_build/CADET/out/install/aRELEASE') + run_simulation_for_all_units( + cadet_install_path='C:/new_cadet_build/CADET/out/install/aRELEASE')