Coverage for backend/ahuora-builder/src/ahuora_builder/methods/pyomo_expressions.py: 79%

15 statements  

« prev     ^ index     » next       coverage.py v7.10.7, created at 2026-06-23 21:51 +0000

1from pyomo.environ import units as pyunits 

2 

3 

4def sum_pyomo_expressions(expressions): 

5 """Sum Pyomo expressions without introducing a unitless zero seed.""" 

6 

7 iterator = iter(expressions) 

8 try: 

9 total = next(iterator) 

10 except StopIteration: 

11 return 0 

12 for expression in iterator: 

13 total += expression 

14 return total 

15 

16 

17def dimensionless_objective_expression(expression): 

18 """Return an objective expression that Pyomo can combine with unitless seeds.""" 

19 

20 units = pyunits.get_units(expression) 

21 if units is None: 21 ↛ 22line 21 didn't jump to line 22 because the condition on line 21 was never true

22 return expression 

23 return expression / units