1+ import importlib
2+
13import numpy as np
24import pandas as pd
35import pytest
3032from bofire .strategies .doe .utils import get_formula_from_string
3133
3234
35+ CYIPOPT_AVAILABLE = importlib .util .find_spec ("cyipopt" ) is not None
36+
37+
3338def test_Objective_model_jacobian_t ():
3439 # "small" model
3540 domain = Domain .from_lists (
3641 inputs = [
3742 ContinuousInput (
38- key = f"x{ i + 1 } " ,
43+ key = f"x{ i + 1 } " ,
3944 bounds = (0 , 1 ),
4045 )
4146 for i in range (3 )
@@ -98,7 +103,7 @@ def test_Objective_model_jacobian_t():
98103 domain = Domain .from_lists (
99104 inputs = [
100105 ContinuousInput (
101- key = f"x{ i + 1 } " ,
106+ key = f"x{ i + 1 } " ,
102107 bounds = (0 , 1 ),
103108 )
104109 for i in range (5 )
@@ -383,7 +388,7 @@ def test_Objective_convert_input_to_model_tensor():
383388 domain = Domain .from_lists (
384389 inputs = [
385390 ContinuousInput (
386- key = f"x{ i + 1 } " ,
391+ key = f"x{ i + 1 } " ,
387392 bounds = (0 , 1 ),
388393 )
389394 for i in range (3 )
@@ -404,7 +409,7 @@ def test_DOptimality_instantiation():
404409 domain = Domain .from_lists (
405410 inputs = [
406411 ContinuousInput (
407- key = f"x{ i + 1 } " ,
412+ key = f"x{ i + 1 } " ,
408413 bounds = (0 , 1 ),
409414 )
410415 for i in range (3 )
@@ -451,7 +456,7 @@ def test_DOptimality_instantiation():
451456 domain = Domain .from_lists (
452457 inputs = [
453458 ContinuousInput (
454- key = f"x{ i + 1 } " ,
459+ key = f"x{ i + 1 } " ,
455460 bounds = (0 , 1 ),
456461 )
457462 for i in range (3 )
@@ -487,7 +492,7 @@ def get_jacobian(x: np.ndarray, delta=1e-3) -> np.ndarray: # type: ignore
487492 domain = Domain .from_lists (
488493 inputs = [
489494 ContinuousInput (
490- key = f"x{ i + 1 } " ,
495+ key = f"x{ i + 1 } " ,
491496 bounds = (0 , 1 ),
492497 )
493498 for i in range (2 )
@@ -642,7 +647,7 @@ def test_DOptimality_evaluate():
642647 domain = Domain .from_lists (
643648 inputs = [
644649 ContinuousInput (
645- key = f"x{ i + 1 } " ,
650+ key = f"x{ i + 1 } " ,
646651 bounds = (0 , 1 ),
647652 )
648653 for i in range (3 )
@@ -660,7 +665,7 @@ def test_AOptimality_evaluate():
660665 domain = Domain .from_lists (
661666 inputs = [
662667 ContinuousInput (
663- key = f"x{ i + 1 } " ,
668+ key = f"x{ i + 1 } " ,
664669 bounds = (0 , 1 ),
665670 )
666671 for i in range (3 )
@@ -803,6 +808,7 @@ def test_SpaceFilling_evaluate_jacobian():
803808 assert np .allclose (space_filling .evaluate_jacobian (x ), [- 1 , - 1 , 2 , 0 ])
804809
805810
811+ @pytest .mark .skipif (not CYIPOPT_AVAILABLE , reason = "requires cyipopt" )
806812def test_MinMaxTransform ():
807813 domain = Domain .from_lists (
808814 inputs = [ContinuousInput (key = "x1" , bounds = (0 , 1 ))],
@@ -888,6 +894,7 @@ def test_MinMaxTransform():
888894 )
889895
890896
897+ @pytest .mark .skipif (not CYIPOPT_AVAILABLE , reason = "requires cyipopt" )
891898def test_IOptimality_instantiation ():
892899 # no constraints
893900 domain = Domain .from_lists (
@@ -906,7 +913,7 @@ def test_IOptimality_instantiation():
906913
907914 # inequality constraints
908915 domain = Domain .from_lists (
909- inputs = [ContinuousInput (key = f"x{ i + 1 } " , bounds = (0 , 1 )) for i in range (2 )],
916+ inputs = [ContinuousInput (key = f"x{ i + 1 } " , bounds = (0 , 1 )) for i in range (2 )],
910917 outputs = [ContinuousOutput (key = "y" )],
911918 constraints = [
912919 LinearInequalityConstraint (
@@ -930,7 +937,7 @@ def test_IOptimality_instantiation():
930937
931938 # equality constraints
932939 domain = Domain .from_lists (
933- inputs = [ContinuousInput (key = f"x{ i + 1 } " , bounds = (0 , 1 )) for i in range (2 )],
940+ inputs = [ContinuousInput (key = f"x{ i + 1 } " , bounds = (0 , 1 )) for i in range (2 )],
934941 outputs = [ContinuousOutput (key = "y" )],
935942 constraints = [
936943 LinearEqualityConstraint (features = ["x1" , "x2" ], coefficients = [1 , 1 ], rhs = 1 )
0 commit comments