Skip to content

Commit

Permalink
Adds get_cadet_version()
Browse files Browse the repository at this point in the history
This commit adds a get_cadet_version() function and calls it inside
run_simulation.
  • Loading branch information
hannahlanzrath committed Jul 12, 2024
1 parent 73b3758 commit 353e448
Showing 1 changed file with 35 additions and 4 deletions.
39 changes: 35 additions & 4 deletions tests/create_LWE.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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')

0 comments on commit 353e448

Please sign in to comment.