!31124 Split test cases of bfgs method.

Merge pull request !31124 from hezhenhao1/fix_scipy
This commit is contained in:
i-robot 2022-03-11 01:10:00 +00:00 committed by Gitee
commit e14d0ca36b
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
1 changed files with 108 additions and 5 deletions

View File

@ -54,11 +54,114 @@ def matyas(np):
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_x86_cpu
@pytest.mark.env_onecard
@pytest.mark.parametrize('dtype', [onp.float32, onp.float64])
@pytest.mark.parametrize('func_x0', [(rosenbrock, onp.zeros(2)),
(himmelblau, onp.zeros(2)),
(matyas, onp.ones(2))])
def test_bfgs(dtype, func_x0):
@pytest.mark.parametrize('dtype', [onp.float32])
@pytest.mark.parametrize('func_x0', [(rosenbrock, onp.zeros(2))])
def test_bfgs1(dtype, func_x0):
"""
Feature: ALL TO ALL
Description: test cases for bfgs in PYNATIVE mode
Expectation: the result match scipy
"""
func, x0 = func_x0
x0 = x0.astype(dtype)
x0_tensor = Tensor(x0)
ms_res = msp.optimize.minimize(func(mnp), x0_tensor, method='BFGS',
options=dict(maxiter=None, gtol=1e-6))
scipy_res = osp.optimize.minimize(func(onp), x0, method='BFGS')
match_array(ms_res.x.asnumpy(), scipy_res.x, error=5, err_msg=str(ms_res))
@pytest.mark.level0
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_x86_cpu
@pytest.mark.env_onecard
@pytest.mark.parametrize('dtype', [onp.float32])
@pytest.mark.parametrize('func_x0', [(himmelblau, onp.zeros(2))])
def test_bfgs2(dtype, func_x0):
"""
Feature: ALL TO ALL
Description: test cases for bfgs in PYNATIVE mode
Expectation: the result match scipy
"""
func, x0 = func_x0
x0 = x0.astype(dtype)
x0_tensor = Tensor(x0)
ms_res = msp.optimize.minimize(func(mnp), x0_tensor, method='BFGS',
options=dict(maxiter=None, gtol=1e-6))
scipy_res = osp.optimize.minimize(func(onp), x0, method='BFGS')
match_array(ms_res.x.asnumpy(), scipy_res.x, error=5, err_msg=str(ms_res))
@pytest.mark.level0
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_x86_cpu
@pytest.mark.env_onecard
@pytest.mark.parametrize('dtype', [onp.float32])
@pytest.mark.parametrize('func_x0', [(matyas, onp.ones(2))])
def test_bfgs3(dtype, func_x0):
"""
Feature: ALL TO ALL
Description: test cases for bfgs in PYNATIVE mode
Expectation: the result match scipy
"""
func, x0 = func_x0
x0 = x0.astype(dtype)
x0_tensor = Tensor(x0)
ms_res = msp.optimize.minimize(func(mnp), x0_tensor, method='BFGS',
options=dict(maxiter=None, gtol=1e-6))
scipy_res = osp.optimize.minimize(func(onp), x0, method='BFGS')
match_array(ms_res.x.asnumpy(), scipy_res.x, error=5, err_msg=str(ms_res))
@pytest.mark.level0
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_x86_cpu
@pytest.mark.env_onecard
@pytest.mark.parametrize('dtype', [onp.float64])
@pytest.mark.parametrize('func_x0', [(rosenbrock, onp.zeros(2))])
def test_bfgs4(dtype, func_x0):
"""
Feature: ALL TO ALL
Description: test cases for bfgs in PYNATIVE mode
Expectation: the result match scipy
"""
func, x0 = func_x0
x0 = x0.astype(dtype)
x0_tensor = Tensor(x0)
ms_res = msp.optimize.minimize(func(mnp), x0_tensor, method='BFGS',
options=dict(maxiter=None, gtol=1e-6))
scipy_res = osp.optimize.minimize(func(onp), x0, method='BFGS')
match_array(ms_res.x.asnumpy(), scipy_res.x, error=5, err_msg=str(ms_res))
@pytest.mark.level0
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_x86_cpu
@pytest.mark.env_onecard
@pytest.mark.parametrize('dtype', [onp.float64])
@pytest.mark.parametrize('func_x0', [(himmelblau, onp.zeros(2))])
def test_bfgs5(dtype, func_x0):
"""
Feature: ALL TO ALL
Description: test cases for bfgs in PYNATIVE mode
Expectation: the result match scipy
"""
func, x0 = func_x0
x0 = x0.astype(dtype)
x0_tensor = Tensor(x0)
ms_res = msp.optimize.minimize(func(mnp), x0_tensor, method='BFGS',
options=dict(maxiter=None, gtol=1e-6))
scipy_res = osp.optimize.minimize(func(onp), x0, method='BFGS')
match_array(ms_res.x.asnumpy(), scipy_res.x, error=5, err_msg=str(ms_res))
@pytest.mark.level0
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_x86_cpu
@pytest.mark.env_onecard
@pytest.mark.parametrize('dtype', [onp.float64])
@pytest.mark.parametrize('func_x0', [(matyas, onp.ones(2))])
def test_bfgs6(dtype, func_x0):
"""
Feature: ALL TO ALL
Description: test cases for bfgs in PYNATIVE mode