Skip to content

Commit 38f7049

Browse files
committed
catch inconsistent inputs
- checking if u and U are consistent - solve issue with __init__ making code completionts impossible
1 parent 8056794 commit 38f7049

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

python/opengen/__init__.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
1-
import opengen.definitions
2-
import opengen.builder
3-
import opengen.config
4-
import opengen.functions
5-
import opengen.constraints
6-
import opengen.tcp
7-
import opengen.ocp
1+
from . import (
2+
definitions,
3+
builder,
4+
config,
5+
functions,
6+
constraints,
7+
tcp,
8+
ocp,
9+
)
10+
11+
__all__ = [
12+
"definitions",
13+
"builder",
14+
"config",
15+
"functions",
16+
"constraints",
17+
"tcp",
18+
"ocp",
19+
]

python/opengen/builder/optimizer_builder.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,15 @@ def __initialize(self):
645645

646646
def __check_user_provided_parameters(self):
647647
self.__logger.info("Checking user parameters")
648+
649+
# Check constraints dimensions
650+
dim_constraints = self.__problem.constraints.dimension()
651+
dim_decision_variables = self.__problem.dim_decision_variables()
652+
if dim_constraints is not None and dim_decision_variables != dim_constraints:
653+
raise ValueError(f"Inconsistent dimensions - decision variables: {dim_decision_variables}",
654+
f"set of constraints: {dim_constraints}")
655+
656+
# Preconditioning...
648657
if self.__solver_config.preconditioning:
649658
# Preconditioning is not allowed when we have general ALM-type constraints of the form
650659
# F1(u, p) in C, unless C is {0} or an orthant (special case of rectangle).

python/test/test_constraints.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ def test_dimension_sphere2(self):
622622
# Zero
623623
# -----------------------------------------------------------------------
624624

625-
def test_zero_dimension(self):
625+
def test_zero_dimension(self):
626626
z = og.opengen.constraints.Zero()
627627
self.assertIsNone(z.dimension())
628628

0 commit comments

Comments
 (0)