Skip to content

Commit 816e7f6

Browse files
committed
✅test passes
1 parent 13f973b commit 816e7f6

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
@@ -45,6 +45,23 @@ def simulate(
4545
return pd.Series({"f_out": self.x**2})
4646

4747

48+
class X2Curve(PyModel):
49+
def __init__(self):
50+
super().__init__(is_dynamic=True)
51+
self.x = 10
52+
53+
def simulate(
54+
self,
55+
property_dict=None,
56+
simulation_options=None,
57+
**simulation_kwargs,
58+
):
59+
if property_dict is not None:
60+
self.set_property_values(property_dict)
61+
62+
return pd.DataFrame({"f_out": [self.x**2]})
63+
64+
4865
class PyRosen(PyModel):
4966
def __init__(self, x_init=1.0, y_init=1.0):
5067
super().__init__(is_dynamic=False)
@@ -370,3 +387,15 @@ def test_sci_optimizer(self):
370387
res = sci_opt.scalar_minimize("f_out")
371388

372389
assert res.x == 0
390+
391+
def test_curve_fit_simple(self):
392+
parameter = Parameter("x_param", interval=(-10, 10), model_property="x")
393+
sci_opt = SciOptimizer(parameters=[parameter], model=X2Curve())
394+
reference = pd.Series([4.0])
395+
396+
popt, _ = sci_opt.curve_fit(
397+
indicator_config=("f_out", lambda x, y: x, reference),
398+
p0=[3.0],
399+
)
400+
401+
assert np.isclose(popt[0], 2.0, atol=1e-2)

0 commit comments

Comments
 (0)