From e5ceaf09011ee8886eb86a3010c0d5fb9016e2ad Mon Sep 17 00:00:00 2001 From: Carlos Roig Date: Fri, 29 Nov 2024 12:09:36 +0100 Subject: [PATCH 1/3] Fixing numpy copy=false --- .../python_scripts/hrom_training_utility.py | 2 +- .../petrov_galerkin_training_utility.py | 2 +- .../RomApplication/python_scripts/rom_analysis.py | 2 +- .../RomApplication/python_scripts/rom_manager.py | 2 +- kratos/python_scripts/petsc_conversion_tools.py | 12 ++++++------ kratos/tests/test_numpy_export_dense_matrix.py | 4 ++-- kratos/tests/test_vectorized_interpolation.py | 2 +- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/applications/RomApplication/python_scripts/hrom_training_utility.py b/applications/RomApplication/python_scripts/hrom_training_utility.py index bd4870a6502a..e43961b65ddd 100644 --- a/applications/RomApplication/python_scripts/hrom_training_utility.py +++ b/applications/RomApplication/python_scripts/hrom_training_utility.py @@ -180,7 +180,7 @@ def AppendCurrentStepResiduals(self): err_msg = f"Projection strategy \'{self.projection_strategy}\' for HROM is not supported." raise Exception(err_msg) - np_res_mat = np.array(res_mat, copy=False) + np_res_mat = np.asarray(res_mat) self.time_step_residual_matrix_container.append(np_res_mat) def GetJacobianPhiMultiplication(self, computing_model_part): diff --git a/applications/RomApplication/python_scripts/petrov_galerkin_training_utility.py b/applications/RomApplication/python_scripts/petrov_galerkin_training_utility.py index 0cf528d1370c..6e0c907eb9d1 100644 --- a/applications/RomApplication/python_scripts/petrov_galerkin_training_utility.py +++ b/applications/RomApplication/python_scripts/petrov_galerkin_training_utility.py @@ -80,7 +80,7 @@ def AppendCurrentStepProjectedSystem(self): err_msg = "\'self.basis_strategy\' is not available. Select either 'jacobian' or 'residuals'." raise Exception(err_msg) - np_snapshots_matrix = np.array(snapshots_matrix, copy=False) + np_snapshots_matrix = np.asarray(snapshots_matrix) self.time_step_snapshots_matrix_container.append(np_snapshots_matrix) def GetJacobianPhiMultiplication(self, computing_model_part): diff --git a/applications/RomApplication/python_scripts/rom_analysis.py b/applications/RomApplication/python_scripts/rom_analysis.py index a78cc69d4a80..8afce059ab56 100644 --- a/applications/RomApplication/python_scripts/rom_analysis.py +++ b/applications/RomApplication/python_scripts/rom_analysis.py @@ -292,7 +292,7 @@ def ModifyInitialGeometry(self): print('Nodal variables: ', nodal_unknown_names) - s_default = np.array(s, copy=False) + s_default = np.asarray(s) print(s_default.shape) q, _ = nn_rom_interface.get_encode_function()(s_default) diff --git a/applications/RomApplication/python_scripts/rom_manager.py b/applications/RomApplication/python_scripts/rom_manager.py index d926a8191584..2ea4668e94d7 100644 --- a/applications/RomApplication/python_scripts/rom_manager.py +++ b/applications/RomApplication/python_scripts/rom_manager.py @@ -1008,7 +1008,7 @@ def Initialize(cls): def GetNonconvergedSolutions(cls): a,_ = cls._GetSolver()._GetSolutionStrategy().GetNonconvergedSolutions() - return np.array(a, copy=False) + return np.asarray(a) simulation.Initialize = types.MethodType(Initialize, simulation) simulation.GetNonconvergedSolutions = types.MethodType(GetNonconvergedSolutions, simulation) diff --git a/kratos/python_scripts/petsc_conversion_tools.py b/kratos/python_scripts/petsc_conversion_tools.py index 343de7d06012..03ebc36c7996 100644 --- a/kratos/python_scripts/petsc_conversion_tools.py +++ b/kratos/python_scripts/petsc_conversion_tools.py @@ -18,17 +18,17 @@ def __init__(self, A): #Kratos DistributedCsrMatrix N = A.GetColNumbering().Size() ##pointers to the kratos arrays of values - self.a = np.array(A.GetDiagonalBlock().value_data(), copy=False) - self.oa = np.array(A.GetOffDiagonalBlock().value_data(), copy=False) + self.a = np.asarray(A.GetDiagonalBlock().value_data()) + self.oa = np.asarray(A.GetOffDiagonalBlock().value_data()) if(type(m) == type(PETSc.IntType)): #we can avoid doing copies #indices of diagonal block - self.i = np.array(A.GetDiagonalBlock().index1_data(), copy=False) - self.j = np.array(A.GetDiagonalBlock().index2_data(), copy=False) + self.i = np.asarray(A.GetDiagonalBlock().index1_data()) + self.j = np.asarray(A.GetDiagonalBlock().index2_data()) #indices of offdiagonal block - self.oi = np.array(A.GetOffDiagonalBlock().index1_data(), copy=False) - self.oj = np.array(A.GetOffDiagonalIndex2DataInGlobalNumbering(), copy=False) + self.oi = np.asarray(A.GetOffDiagonalBlock().index1_data()) + self.oj = np.asarray(A.GetOffDiagonalIndex2DataInGlobalNumbering()) else: #WE NEED TO COPY INDICES! since the size of the IndexType is not compatible between Kratos and PETSc if(A.GetComm().Rank() == 0): diff --git a/kratos/tests/test_numpy_export_dense_matrix.py b/kratos/tests/test_numpy_export_dense_matrix.py index 8ff254f548ed..1e3012175f57 100644 --- a/kratos/tests/test_numpy_export_dense_matrix.py +++ b/kratos/tests/test_numpy_export_dense_matrix.py @@ -10,7 +10,7 @@ def test_numpy_export_dense_matrix_no_copying(self): KratosMatrix.fill(1.0) # Export it to numpy array (No copying is performed) - NumpyMatrix = np.array(KratosMatrix,copy=False) + NumpyMatrix = np.asarray(KratosMatrix) # Test correct creation for i in range(3): @@ -35,7 +35,7 @@ def test_numpy_export_complex_dense_matrix_no_copying(self): KratosMatrix.fill(1.0+1.0j) # Export it to numpy array (No copying is performed) - NumpyMatrix = np.array(KratosMatrix,copy=False) + NumpyMatrix = np.asarray(KratosMatrix) # Test correct creation for i in range(3): diff --git a/kratos/tests/test_vectorized_interpolation.py b/kratos/tests/test_vectorized_interpolation.py index c9f873987565..dec4a660201d 100644 --- a/kratos/tests/test_vectorized_interpolation.py +++ b/kratos/tests/test_vectorized_interpolation.py @@ -39,7 +39,7 @@ def testVectorizedInterpolation(self): #obtaining a copy of database onto numpy array, and reshaping it into matrices nnodes = len(self.mp.Nodes) - vdata = np.array(Kratos.VariableUtils().GetSolutionStepValuesVector(self.mp.Nodes, Kratos.VELOCITY, 0, 3),copy=False).reshape(nnodes,3) + vdata = np.asarray(Kratos.VariableUtils().GetSolutionStepValuesVector(self.mp.Nodes, Kratos.VELOCITY, 0, 3)).reshape(nnodes,3) coords = np.array(Kratos.VariableUtils().GetCurrentPositionsVector(self.mp.Nodes,3)).reshape(nnodes,3) ##coordinates to search for From 784cf7440e6b77f785b180e400463de310e61a71 Mon Sep 17 00:00:00 2001 From: Carlos Roig Date: Fri, 29 Nov 2024 16:05:06 +0100 Subject: [PATCH 2/3] Temporal fix until the rest of the libs upgrade to numpy==2 --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 21cd6dc63921..cacbb17ced32 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -271,7 +271,7 @@ jobs: - name: Installing dependencies shell: cmd run: | - pip install numpy + pip install numpy=1.26.4 pip install sympy pip install scipy pip install h5py @@ -483,7 +483,7 @@ jobs: - name: Installing dependencies shell: cmd run: | - pip install numpy + pip install numpy=1.26.4 pip install sympy pip install scipy From 6c1f603b7a2689bf26a9394bb30e4fd7d2300579 Mon Sep 17 00:00:00 2001 From: Carlos Roig Date: Fri, 29 Nov 2024 17:37:40 +0100 Subject: [PATCH 3/3] Changing *linux version, not win --- .github/workflows/ci.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cacbb17ced32..6e9f526db0a9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -60,7 +60,9 @@ jobs: - name: CI configuration shell: bash - run: python3 kratos/python_scripts/testing/ci_utilities.py + run: | + python3 kratos/python_scripts/testing/ci_utilities.py + python3 -m pip install --upgrade numpy==1.26.4 - name: Build shell: bash @@ -271,7 +273,7 @@ jobs: - name: Installing dependencies shell: cmd run: | - pip install numpy=1.26.4 + pip install numpy pip install sympy pip install scipy pip install h5py @@ -483,7 +485,7 @@ jobs: - name: Installing dependencies shell: cmd run: | - pip install numpy=1.26.4 + pip install numpy pip install sympy pip install scipy