Skip to content

Commit ba16653

Browse files
committed
✅test passes
1 parent 6c8fc55 commit ba16653

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

tests/test_optimize.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,23 @@ def simulate(
4040
return pd.Series({"f_out": self.x**2})
4141

4242

43+
class X2Curve(PyModel):
44+
def __init__(self):
45+
super().__init__(is_dynamic=True)
46+
self.x = 10
47+
48+
def simulate(
49+
self,
50+
property_dict=None,
51+
simulation_options=None,
52+
**simulation_kwargs,
53+
):
54+
if property_dict is not None:
55+
self.set_property_values(property_dict)
56+
57+
return pd.DataFrame({"f_out": [self.x**2]})
58+
59+
4360
class PyRosen(PyModel):
4461
def __init__(self, x_init=1.0, y_init=1.0):
4562
super().__init__(is_dynamic=False)
@@ -337,3 +354,15 @@ def test_sci_optimizer(self):
337354
res = sci_opt.scalar_minimize("f_out")
338355

339356
assert res.x == 0
357+
358+
def test_curve_fit_simple(self):
359+
parameter = Parameter("x_param", interval=(-10, 10), model_property="x")
360+
sci_opt = SciOptimizer(parameters=[parameter], model=X2Curve())
361+
reference = pd.Series([4.0])
362+
363+
popt, _ = sci_opt.curve_fit(
364+
indicator_config=("f_out", lambda x, y: x, reference),
365+
p0=[3.0],
366+
)
367+
368+
assert np.isclose(popt[0], 2.0, atol=1e-2)

0 commit comments

Comments
 (0)