SimVascular / svZeroDSolver-Archived

A Python lumped-parameter solver for blood flow and pressure in hemodynamic networks
Other
12 stars 15 forks source link

svZeroDSolver fails with a syntax error when run from SimVascular #77

Closed ktbolt closed 11 months ago

ktbolt commented 11 months ago

When run from SimVascular the svZeroDSolver fails with

Traceback (most recent call last):
  File "run-python-zdsolver.py", line 2, in <module>
    from svZeroDSolver import svzerodsolver
  File "/Users/parkerda/tmp/SimVascular-last/SimVascular/Python/site-packages/svZeroDSolver/svzerodsolver/__init__.py", line 34, in <module>
    from .solver import run_from_c 
  File "/Users/parkerda/tmp/SimVascular-last/SimVascular/Python/site-packages/svZeroDSolver/svzerodsolver/solver.py", line 81, in <module>
    from . import use_steady_bcs
  File "/Users/parkerda/tmp/SimVascular-last/SimVascular/Python/site-packages/svZeroDSolver/svzerodsolver/use_steady_bcs.py", line 177
    assert volume_internal[0] == volume_internal[1], f"Entries of Pim are not equal."
                                                                                    ^
SyntaxError: invalid syntax

The problem is an assert statement that uses an f-strings formatting introduced in Python 3.6; SimVascular uses Python 3.5.

ktbolt commented 11 months ago

Note that we should not be using asserts in production code so I will remove them.

ktbolt commented 11 months ago

Since we need to do this check at run time I've replaced the asserts

assert volume_internal.size == 2, "Pim should be size 2."
assert volume_internal[0] == volume_internal[1], "Entries of Pim are not equal."

with throwing exceptions

if volume_internal.size != 2:
    raise Exception("The input Pim data should be size of size 2.")

 if volume_internal[0] != volume_internal[1]:
    raise Exception("The input Pim data entries are not equal.")
ktbolt commented 11 months ago

Merged into master.