Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
giadarol committed Nov 9, 2024
1 parent 121e199 commit 33228b4
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/test_optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,34 @@ def my_function(x):

xo.assert_allclose(opt.get_merit_function().get_x(), [0.0001, 0.0003, -0.0005], atol=1e-6, rtol=0)

def test_optimize_scipy_algorithms():

def my_function(x):
return [(x[0]-0.0001)**2, (x[1]-0.0003)**2, (x[2]+0.0005)**2, 3.0]

x0 = [0., 0., 0.]
limits = [[-1, 1], [-1, 1], [-1, 1]]
targets = [0., 0., 0., 3.]
steps = [1e-6, 1e-6, 1e-6, 1e-6]
tols = [1e-12, 1e-12, 1e-12, 1e-12]

opt = xd.Optimize.from_callable(my_function, x0=x0, steps=steps, tar=targets, tols=tols, limits=limits)
opt.run_bfgs()
xo.assert_allclose(opt.get_merit_function().get_x(), [0.0001, 0.0003, -0.0005], atol=1e-6, rtol=0)

opt.reload(0)
opt.run_l_bfgs_b()
xo.assert_allclose(opt.get_merit_function().get_x(), [0.0001, 0.0003, -0.0005], atol=1e-6, rtol=0)

opt.reload(0)
opt.run_ls_trf()
xo.assert_allclose(opt.get_merit_function().get_x(), [0.0001, 0.0003, -0.0005], atol=1e-6, rtol=0)

opt.reload(0)
opt.run_ls_dogbox()
xo.assert_allclose(opt.get_merit_function().get_x(), [0.0001, 0.0003, -0.0005], atol=1e-6, rtol=0)

assert 'bfgs' in opt.log()['tag']
assert 'l-bfgs-b' in opt.log()['tag']
assert 'trf' in opt.log()['tag']
assert 'dogbox' in opt.log()['tag']

0 comments on commit 33228b4

Please sign in to comment.