Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/inlet outlet connections #143

Merged
merged 4 commits into from
Jun 25, 2024
Merged

Fix/inlet outlet connections #143

merged 4 commits into from
Jun 25, 2024

Conversation

schmoelder
Copy link
Contributor

@schmoelder schmoelder commented Jun 19, 2024

With this PR, an exception is raised whenever a user tries to connect an Outlet unit operation to another unit, or some unit to an Inlet unit operation.

@hannahlanzrath @daklauss Do we already handle this in #95?

Fixes #139

Todo

  • Raise Exceptions
  • Add tests

@schmoelder schmoelder changed the base branch from master to dev June 19, 2024 06:41
@hannahlanzrath
Copy link
Collaborator

AFAIK this is not explicitly caught, but inexplicitly via "CADETProcessError: Origin/Destination unit does not support ports."

@schmoelder
Copy link
Contributor Author

Thanks. Would you be up for adding some tests to this branch here?

@hannahlanzrath
Copy link
Collaborator

Will do 👍

@daklauss
Copy link
Collaborator

daklauss commented Jun 19, 2024

I wrote a small test on #95 and we actually do not caugh the exception. It actually errors out by subscripting over non existant dict entrys, in the connections dict. So yeah we still have to catch this error.

import unittest

from CADETProcess import CADETProcessError
from CADETProcess.processModel import ComponentSystem
from CADETProcess.processModel import Inlet, Outlet, Cstr
from CADETProcess.processModel import FlowSheet
from CADETProcess.processModel import Process

class Test_inlet_outlet(unittest.TestCase):
    
    def test_io(self):
        comp_sys = ComponentSystem(1)

        flow_sheet = FlowSheet(comp_sys)

        inlet = Inlet(comp_sys, "inlet")
        outlet = Outlet(comp_sys, "outlet")
        cstr = Cstr(comp_sys, "cstr")


        flow_sheet.add_unit(inlet)
        flow_sheet.add_unit(outlet)
        flow_sheet.add_unit(cstr)

        self.assertRaises(RuntimeError,flow_sheet.add_connection(outlet, cstr))

        self.assertRaises(RuntimeError,flow_sheet.add_connection(cstr, inlet))

        self.assertRaises(RuntimeError,flow_sheet.add_connection(outlet, inlet))`



./test_io.py::Test_inlet_outlet::test_io Failed with Error: 'NoneType' object is not subscriptable
  File "C:\Users\klauss\AppData\Local\miniconda3\envs\cadsem\Lib\unittest\case.py", line 57, in testPartExecutor
    yield
  File "C:\Users\klauss\AppData\Local\miniconda3\envs\cadsem\Lib\unittest\case.py", line 623, in run
    self._callTestMethod(testMethod)
  File "C:\Users\klauss\AppData\Local\miniconda3\envs\cadsem\Lib\unittest\case.py", line 579, in _callTestMethod
    if method() is not None:
       ^^^^^^^^
  File "c:\Users\klauss\Documents\Arbeitsprojekte\ModSim\Ports\CADET-Process\tests\test_io.py", line 25, in test_io
    self.assertRaises(RuntimeError,flow_sheet.add_connection(outlet, cstr))
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\klauss\Documents\Arbeitsprojekte\ModSim\Ports\CADET-Process\CADETProcess\processModel\flowSheet.py", line 99, in wrapper
    return func(self, origin, destination, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\klauss\Documents\Arbeitsprojekte\ModSim\Ports\CADET-Process\CADETProcess\processModel\flowSheet.py", line 129, in wrapper
    results = func(self, *args, **kwargs)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\klauss\Documents\Arbeitsprojekte\ModSim\Ports\CADET-Process\CADETProcess\processModel\flowSheet.py", line 445, in add_connection
    if destination_port in self._connections[origin]['destinations'][origin_port][destination]:
                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
TypeError: 'NoneType' object is not subscriptable```

@hannahlanzrath
Copy link
Collaborator

We will sort it out. This week didn't work out unfortunately but next week @daklauss and I will do an intense cadet-process + ports session.

@daklauss
Copy link
Collaborator

Wrote some tests for checking errorraising of wrong inlet/outlet connections. Additionaly added tests for the other cases in which add_connection raises errors. The "connection already exists" case may already be covered in test_name_decorator, but the others are not.

@daklauss daklauss merged commit df97b3b into dev Jun 25, 2024
5 checks passed
@daklauss daklauss deleted the fix/inlet_outlet_connections branch June 25, 2024 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Conneting Outlet unit operation to other unit operation should raise an Exception
3 participants