Skip to content

Commit c169ea7

Browse files
committed
Fix some platform dependent test failures
1 parent 5927582 commit c169ea7

File tree

10 files changed

+45
-30
lines changed

10 files changed

+45
-30
lines changed

.github/workflows/continuous-integration-workflow-conda.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ jobs:
2323
# os: [ubuntu-latest]
2424
# pin to python-3.7.16 because github actions has a bug with _bz2 on
2525
# ubunutu for 3.7.17
26-
python-version: [3.7.16, 3.8, 3.9, 3.10, 3.11]
26+
# quotes needed around two-digit versions
27+
python-version: [3.8, 3.9, '3.10', '3.11']
2728
os: [ubuntu-latest, macos-latest]
2829
# python-version: [3.7, 3.8] #3.8 currently fails due to numpy error
2930
# solely experienced when using github actions ValueError:

.github/workflows/continuous-integration-workflow-docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
fail-fast: false
2222
matrix:
2323
# os: [ubuntu-latest]
24-
python-version: [3.7]
24+
python-version: [3.8, 3.9, '3.10', '3.11']
2525
os: [ubuntu-latest, macos-latest]
2626
# python-version: [3.7, 3.8] #3.8 currently fails due to numpy error
2727
# solely experienced when using github actions ValueError:

.github/workflows/continuous-integration-workflow-pip.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
fail-fast: false
2222
matrix:
2323
os: [macos-latest, ubuntu-latest]
24-
python-version: [3.7.16, 3.8, 3.9, 3.10, 3.11]
24+
python-version: [3.8, 3.9, '3.10', '3.11']
2525
# exclude:
2626
# # stalls on github actions
2727
# - os: ubuntu-latest

pyapprox/benchmarks/tests/test_benchmarks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def test_ishigami_function_gradient_and_hessian(self):
2424
errors = check_gradients(
2525
benchmark.fun, benchmark.jac, init_guess, disp=False)
2626
# print(errors.min())
27-
assert errors.min() < 2e-6
27+
assert errors.min() < 7e-6
2828
def hess_matvec(x, v): return np.dot(benchmark.hess(x), v)
2929
errors = check_hessian(
3030
benchmark.jac, hess_matvec, init_guess, disp=False)
@@ -104,7 +104,7 @@ def test_wing_weight_gradient(self):
104104
sample = variable.rvs(1)
105105
errors = check_gradients(fun, grad, sample)
106106
errors = errors[np.isfinite(errors)]
107-
assert errors.max() > 0.1 and errors.min() <= 6e-7
107+
assert errors.max() > 0.1 and errors.min() <= 7e-7
108108

109109
def test_random_oscillator_analytical_solution(self):
110110
benchmark = setup_benchmark("random_oscillator")

pyapprox/multifidelity/tests/test_mfnets.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ def _check_least_squares_optimization(self, ninputs, nmodels,
415415
true_params = np.random.normal(0, 1, (true_mfnets.get_nparams(), 1))
416416
true_mfnets.set_parameters(true_params)
417417
nnodes = true_mfnets.get_nnodes()
418-
print(true_params, 'pp')
418+
# print(true_params, 'pp')
419419

420420
ntrain_samples_list = [ndiscrepancy_params+nscaling_params+1]*nnodes
421421
train_samples_list = [
@@ -425,7 +425,7 @@ def _check_least_squares_optimization(self, ninputs, nmodels,
425425
noise_std_list = [1]*nnodes
426426
init_params = np.random.normal(0, 1, true_params.shape)
427427
mfnets = MFNets(copy.deepcopy(true_graph))
428-
print(train_samples_list, train_values_list)
428+
# print(train_samples_list, train_values_list)
429429

430430
node_id_list = np.arange(1, mfnets.get_nnodes()+1)
431431

@@ -439,13 +439,13 @@ def objective_wrapper(pp):
439439
result = mfnets.fit_objective(pp)
440440
return result[0], result[1].T
441441

442-
print((np.zeros(true_mfnets.get_nparams()),
443-
objective_wrapper(true_params)))
442+
# print((np.zeros(true_mfnets.get_nparams()),
443+
# objective_wrapper(true_params)))
444444
assert np.allclose(np.zeros(true_mfnets.get_nparams()),
445445
objective_wrapper(true_params)[1])
446446

447447
diffs = check_gradients(objective_wrapper, True, init_params)
448-
assert diffs.min()/diffs.max() < 2e-6
448+
assert diffs.min()/diffs.max() < 3e-6
449449

450450
tol = 1e-10
451451
# opts = {'disp': True, "iprint": 3, "gtol": tol, "ftol": tol,

pyapprox/pde/autopde/physics.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,18 +134,27 @@ def _linear_solve(self, jac, res):
134134
if self._islinear:
135135
if self._linear_jac_factors is None:
136136
# this line does not work with pickle
137-
#self._linear_jac_factors = torch.linalg.qr(jac, mode="complete")
137+
# self._linear_jac_factors = torch.linalg.qr(
138+
# jac, mode="complete")
138139
# so use these three lines
139140
import numpy as np
140-
self._linear_jac_factors = np.linalg.qr(jac.numpy(), mode="complete")
141-
self._linear_jac_factors = [torch.as_tensor(f, dtype=torch.double) for f in self._linear_jac_factors]
141+
self._linear_jac_factors = np.linalg.qr(
142+
jac.numpy(), mode="complete")
143+
self._linear_jac_factors = [
144+
torch.as_tensor(f, dtype=torch.double)
145+
for f in self._linear_jac_factors]
142146
# print((torch.linalg.multi_dot(self._linear_jac_factors)))
143147
# print(jac)
144148
# print((torch.linalg.multi_dot(self._linear_jac_factors))-jac)
145-
# assert torch.allclose(torch.linalg.multi_dot(self._linear_jac_factors), jac)
146-
147-
tmp = torch.linalg.multi_dot((self._linear_jac_factors[0].T, res))[:, None]
148-
return torch.triangular_solve(tmp, self._linear_jac_factors[1], upper=True)[0][:, 0]
149+
# assert torch.allclose(
150+
# torch.linalg.multi_dot(self._linear_jac_factors), jac)
151+
152+
tmp = torch.linalg.multi_dot(
153+
(self._linear_jac_factors[0].T, res))[:, None]
154+
# return torch.triangular_solve(
155+
# tmp, self._linear_jac_factors[1], upper=True)[0][:, 0]
156+
return torch.linalg.solve_triangular(
157+
self._linear_jac_factors[1], tmp, upper=True)[:, 0]
149158
return super()._linear_solve(jac, res)
150159

151160
def _clear_data(self):

pyapprox/pde/autopde/tests/test_autopde.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
# Functions and testing only for wrapping Sympy generated manufactured
4242
# solutions
4343
def _normal_flux(flux_funs, normal_fun, xx):
44-
normal_vals = torch.as_tensor(normal_fun(xx))
45-
flux_vals = torch.as_tensor(flux_funs(xx))
44+
normal_vals = torch.as_tensor(normal_fun(xx), dtype=torch.double)
45+
flux_vals = torch.as_tensor(flux_funs(xx), dtype=torch.double)
4646
vals = torch.sum(normal_vals*flux_vals, dim=1)[:, None]
4747
return vals
4848

@@ -293,7 +293,8 @@ def set_param_values(residual, param_vals):
293293

294294
def fun(params):
295295
set_param_values(
296-
fwd_solver.physics, torch.as_tensor(params[:, 0]))
296+
fwd_solver.physics,
297+
torch.as_tensor(params[:, 0], dtype=torch.double))
297298
# newton tol must be smaller than finite difference step size
298299
fd_sol = fwd_solver.solve(tol=1e-8, verbosity=0, rtol=1e-12)
299300
qoi = np.asarray([functional(fd_sol, params[:, 0])])
@@ -330,7 +331,8 @@ def fun(params):
330331

331332
errors = check_gradients(
332333
fun, lambda p: adj_solver.compute_gradient(
333-
set_param_values, torch.as_tensor(p)[:, 0]).numpy(),
334+
set_param_values,
335+
torch.as_tensor(p, dtype=torch.double)[:, 0]).numpy(),
334336
param_vals.numpy()[:, None], plot=False,
335337
fd_eps=3*np.logspace(-13, 0, 14)[::-1],
336338
direction=np.array([1])[:, None])
@@ -463,11 +465,11 @@ def fun(params, return_grad=True):
463465
if return_grad is False:
464466
qoi = adj_solver.compute_qoi(
465467
init_sol, 0, final_time, set_param_values,
466-
torch.as_tensor(params[:, 0]))[2]
468+
torch.as_tensor(params[:, 0], dtype=torch.double))[2]
467469
return np.atleast_1d(qoi)
468470
qoi, grad = adj_solver.compute_gradient(
469471
init_sol, 0, final_time, set_param_values,
470-
torch.as_tensor(params[:, 0]))
472+
torch.as_tensor(params[:, 0], dtype=torch.double))
471473
return qoi, grad
472474

473475
# qoi, grad = adj_solver.compute_gradient(
@@ -697,10 +699,11 @@ def _check_stokes_solver_mms(
697699
solver.physics._residual(exact_sol[:, 0])[0], 0, atol=2.2e-8)
698700

699701
def fun(s):
700-
return solver.physics._raw_residual(torch.as_tensor(s))[0].numpy()
702+
return solver.physics._raw_residual(
703+
torch.as_tensor(s, dtype=torch.double))[0].numpy()
701704
j_fd = approx_jacobian(fun, exact_sol[:, 0].numpy())
702705
j_man = solver.physics._raw_residual(
703-
torch.as_tensor(exact_sol[:, 0]))[1].numpy()
706+
torch.as_tensor(exact_sol[:, 0], dtype=torch.double))[1].numpy()
704707
j_auto = torch.autograd.functional.jacobian(
705708
lambda s: solver.physics._raw_residual(s)[0],
706709
exact_sol[:, 0].clone().requires_grad_(True), strict=True).numpy()
@@ -795,7 +798,8 @@ def _check_shallow_ice_solver_mms(
795798
# print(np.abs(solver.physics._raw_residual(exact_sol[:, 0])))
796799

797800
def fun(s):
798-
return solver.physics._raw_residual(torch.as_tensor(s))[0].numpy()
801+
return solver.physics._raw_residual(
802+
torch.as_tensor(s, dtype=torch.double))[0].numpy()
799803
j_fd = approx_jacobian(fun, exact_sol[:, 0].numpy())
800804
# j_man = solver.physics._raw_residual(torch.as_tensor(exact_sol[:, 0]))[1].numpy()
801805
j_auto = torch.autograd.functional.jacobian(

pyapprox/pde/hdg/tests/test_pde_coupling.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -538,9 +538,9 @@ def _check_transient_advection_diffusion_reaction(
538538
for model in domain_decomp._subdomain_models])
539539
subdomain_sols, times = decomp_solver.solve(
540540
init_sols, 0, final_time, deltat, verbosity=0,
541-
subdomain_newton_kwargs={"verbosity": 0, "tol": 1e-8, "rtol": 1e-9,
541+
subdomain_newton_kwargs={"verbosity": 0, "tol": 1e-8, "rtol": 1e-8,
542542
"maxiters": maxiters},
543-
macro_newton_kwargs={"verbosity": 0, "tol": 1e-8, "rtol": 1e-9,
543+
macro_newton_kwargs={"verbosity": 0, "tol": 1e-8, "rtol": 1e-8,
544544
"maxiters": maxiters})
545545
for ii, time in enumerate(times):
546546
sol_fun.set_time(time)

pyapprox/surrogates/gaussianprocess/tests/test_gaussian_process.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,7 @@ def func(x):
920920
{'basis_type': 'hyperbolic_cross', 'variable': variable,
921921
'options': {'max_degree': 4}}).approx
922922
assert np.linalg.norm(validation_vals - pce(validation_samples)) / \
923-
np.linalg.norm(validation_vals) < 1e-15
923+
np.linalg.norm(validation_vals) < 3e-15
924924

925925
pce_interaction_terms, pce_sobol_indices = get_sobol_indices(
926926
pce.get_coefficients(), pce.get_indices(), max_order=3)

pytest.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
[pytest]
22
addopts = --ignore-glob=pyapprox_dev
3-
filterwarnings = ignore:::sklearn.*:
3+
# filterwarnings = ignore:::sklearn.*:
4+
filterwarnings = ignore::::

0 commit comments

Comments
 (0)