Skip to content

Commit 83a1457

Browse files
committed
Precent torch 2.3.0 being installed because it causes a segfault
The segfault arises in pde/autopde/mesh.py. See comment in code for more details
1 parent 93a1e7e commit 83a1457

File tree

7 files changed

+35
-22
lines changed

7 files changed

+35
-22
lines changed

pyapprox/analysis/active_subspace.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ def sort_2d_vertices_by_polar_angle(vertices):
436436
# sort by polar angle
437437
sorted_vertices = np.array(
438438
sorted(vertices.T,
439-
key=lambda p: np.math.atan2(p[1]-cent[1], p[0]-cent[0]))).T
439+
key=lambda p: np.atan2(p[1]-cent[1], p[0]-cent[0]))).T
440440
return sorted_vertices
441441

442442

pyapprox/analysis/tests/test_active_subspace.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def test_moments_of_active_subspace(self):
202202
(3*a**4+3*b**4+10*b**2*c**2+3*c**4+10*a**2*(b**2+c**2))/15.])
203203
moments = moments[sorted_idx]
204204
# ignore dummy values until I compute them analytically
205-
II = np.where(true_moments != np.Inf)[0]
205+
II = np.where(true_moments != np.inf)[0]
206206
assert np.allclose(moments[II], true_moments[II])
207207

208208
def test_moments_of_active_subspace_II(self):

pyapprox/benchmarks/pde_benchmarks.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,6 @@ def _setup_advection_diffusion_benchmark(
319319
kle_mean_field=0.):
320320
variable = IndependentMarginalsVariable([stats.norm(0, 1)]*nvars)
321321
orders = np.asarray(orders, dtype=int)
322-
323322
domain_bounds = [0, 1, 0, 1]
324323
mesh = CartesianProductCollocationMesh(domain_bounds, orders)
325324
# bndry_conds = [

pyapprox/pde/autopde/mesh.py

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55

66
from pyapprox.util.utilities import cartesian_product, outer_product
77
from pyapprox.surrogates.orthopoly.quadrature import gauss_jacobi_pts_wts_1D
8-
from pyapprox.variables.transforms import _map_hypercube_samples
98
from pyapprox.surrogates.interp.barycentric_interpolation import (
10-
compute_barycentric_weights_1d, barycentric_interpolation_1d
11-
)
9+
compute_barycentric_weights_1d, barycentric_interpolation_1d)
1210
from pyapprox.util.visualization import plt, get_meshgrid_samples
1311
from pyapprox.pde.autopde.mesh_transforms import ScaleAndTranslationTransform
1412

@@ -23,16 +21,16 @@ def full_fun_axis_1(fill_val, xx, oned=True):
2321

2422
def chebyshev_derivative_matrix(order):
2523
if order == 0:
26-
pts = np.array([1], float)
27-
derivative_matrix = np.array([0], float)
24+
pts = np.array([1], dtype=float)
25+
derivative_matrix = np.array([0], dtype=float)
2826
else:
2927
# this is reverse order used by matlab cheb function
3028
pts = -np.cos(np.linspace(0., np.pi, order+1))
31-
scalars = np.ones((order+1), float)
29+
scalars = np.ones((order+1), dtype=float)
3230
scalars[0] = 2.
3331
scalars[order] = 2.
3432
scalars[1:order+1:2] *= -1
35-
derivative_matrix = np.empty((order+1, order+1), float)
33+
derivative_matrix = np.empty((order+1, order+1), dtype=float)
3634
for ii in range(order+1):
3735
row_sum = 0.
3836
for jj in range(order+1):
@@ -114,7 +112,7 @@ def fourier_basis(order, samples):
114112
npts = (order+1)
115113
h = 2*np.pi/npts
116114
pts = h*np.arange(1, npts+1)
117-
II = np.where(samples==2*np.pi)[0]
115+
II = np.where(samples == 2*np.pi)[0]
118116
samples[II] = 0
119117
xx = samples[:, None]-pts[None, :]
120118
vals = np.sin(np.pi*xx/h)/(2*np.pi/h*np.tan(xx/2))
@@ -223,7 +221,7 @@ def kronecker_product_2d(matrix1, matrix2):
223221
assert matrix1.ndim == 2
224222
block_num_rows = matrix1.shape[0]
225223
matrix_num_rows = block_num_rows**2
226-
matrix = np.empty((matrix_num_rows, matrix_num_rows), float)
224+
matrix = np.empty((matrix_num_rows, matrix_num_rows), dtype=float)
227225

228226
# loop through blocks
229227
start_col = 0
@@ -440,16 +438,33 @@ def _form_derivative_matrices(self):
440438
compute_barycentric_weights_1d(xx) for xx in canonical_mesh_pts_1d]
441439

442440
if self.nphys_vars == 1:
443-
canonical_deriv_mats = [canonical_deriv_mats_1d[0]]
441+
canonical_deriv_mats = [
442+
torch.as_tensor(
443+
canonical_deriv_mats_1d[0], dtype=torch.double)]
444444
else:
445445
# assumes that 2d-mesh_pts varies in x1 faster than x2,
446446
# e.g. points are
447447
# [[x11,x21],[x12,x21],[x13,x12],[x11,x22],[x12,x22],...]
448+
449+
# The following fails with PyTorch 2.3.0
450+
# I thought it may have been caused by converting numpy to tensor
451+
# but this code suggests it is not that explicitly.
452+
# What is confusing is this works in ipython as standalone code
453+
# For now setting setup to only use pytorch<=2.2
454+
# mat1 = torch.eye(31, dtype=torch.double)
455+
# mat2 = torch.ones((31, 31), dtype=torch.double)
456+
# C = torch.kron(mat1, mat2)
457+
# print("A", C.shape)
448458
canonical_deriv_mats = [
449-
np.kron(np.eye(self._orders[1]+1), canonical_deriv_mats_1d[0]),
450-
np.kron(canonical_deriv_mats_1d[1], np.eye(self._orders[0]+1))]
451-
canonical_deriv_mats = [torch.as_tensor(mat, dtype=torch.double)
452-
for mat in canonical_deriv_mats]
459+
torch.kron(
460+
torch.eye(self._orders[1]+1, dtype=torch.double),
461+
torch.as_tensor(canonical_deriv_mats_1d[0],
462+
dtype=torch.double)),
463+
torch.kron(
464+
torch.as_tensor(canonical_deriv_mats_1d[1],
465+
dtype=torch.double),
466+
torch.eye(self._orders[0]+1, dtype=torch.double))]
467+
453468
canonical_mesh_pts = cartesian_product(canonical_mesh_pts_1d)
454469

455470
return (canonical_mesh_pts_1d, canonical_deriv_mats_1d,

pyapprox/surrogates/interp/barycentric_interpolation.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
from pyapprox.util.utilities import cartesian_product
66
from pyapprox.util.pya_numba import njit
77
from pyapprox.util.sys_utilities import trace_error_with_msg
8-
from pyapprox.util.visualization import (
9-
get_meshgrid_function_data, create_3d_axis, mpl, plot_surface)
108

119

1210
def compute_barycentric_weights_1d(samples, interval_length=None,
@@ -101,7 +99,8 @@ def barycentric_interpolation_1d(abscissa, weights, vals, eval_samples):
10199
with warnings.catch_warnings():
102100
# avoid division by zero warning
103101
warnings.simplefilter("ignore")
104-
return _barycentric_interpolation_1d(abscissa, weights, vals, eval_samples)
102+
return _barycentric_interpolation_1d(
103+
abscissa, weights, vals, eval_samples)
105104

106105

107106
def barycentric_lagrange_interpolation_precompute(

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ dependencies = [
3232
'scipy >= 1.0.0',
3333
'Cython',
3434
'sympy',
35-
'torch',
35+
'torch<=2.2.0',
3636
'scikit-learn',
3737
'coverage>=6.4',
3838
'pytest-cov',

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def no_cythonize(extensions, **_ignore):
5656
'scipy >= 1.0.0',
5757
'Cython',
5858
'sympy',
59-
'torch',
59+
'torch<=2.2.0',
6060
'scikit-learn',
6161
'coverage>=6.4',
6262
'pytest-cov',

0 commit comments

Comments
 (0)