Skip to content

Numpy v2 compatability errors #20

Description

@srimanachanta

When running tests, the following errors occur due to the codebase not properly support Numpy V2.

 │ ======================================================================
 │ ERROR: test_algorithms_002_MEStatic_gpc (test_algorithms.TestPygpcMethods.test_algorithms_002_MEStatic_gpc)
 │ Algorithm: MEStatic
 │ ----------------------------------------------------------------------
 │ TypeError: only 0-dimensional arrays can be converted to Python scalars
 │ The above exception was the direct cause of the following exception:
 │ Traceback (most recent call last):
 │   File "$SRC_DIR/tests/test_algorithms.py", line 383, in test_algorithms_002_MEStatic_gpc
 │     session, coeffs, results = session.run()
 │                                ^^^^^^^^^^^^^
 │ cuda Time create_gpc_matrix:  0.08231496810913086
 │   File "$PREFIX/lib/python3.12/site-packages/pygpc/Session.py", line 119, in run
 │     gpc, coeffs, results = self.algorithm.run()
 │ cuda Time get_approximation:  0.010493040084838867
 │ done!
 │                            ^^^^^^^^^^^^^^^^^^^^
 │ test_utils_004_gradient_estimation_methods
 │ done!
 │ done!
 │   File "$PREFIX/lib/python3.12/site-packages/pygpc/Algorithm.py", line 1089, in run
 │     res_new = com.run(model=self.problem.model,
 │               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 │   File "$PREFIX/lib/python3.12/site-packages/pygpc/Computation.py", line 363, in run
 │     res = Worker.run(obj=worker_objs, matlab_engine=self.matlab_engine)
 │           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 │   File "$PREFIX/lib/python3.12/site-packages/pygpc/Worker.py", line 57, in run
 │     out = obj.simulate(process_id, matlab_engine)
 │           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 │   File "$PREFIX/lib/python3.12/site-packages/pygpc/testfunctions/testfunctions.py", line 2010, in simulate
 │     y_out[i, 0] = np.array([y[-1]])
 │     ~~~~~^^^^^^
 │ ValueError: setting an array element with a sequence.
 │ ======================================================================
 │ ERROR: test_algorithms_002_MEStatic_gpc_NaN (test_algorithms.TestPygpcMethods.test_algorithms_002_MEStatic_gpc_NaN)
 │ Algorithm: MEStatic
 │ ----------------------------------------------------------------------
 │ TypeError: only 0-dimensional arrays can be converted to Python scalars
 │ The above exception was the direct cause of the following exception:
 │ Traceback (most recent call last):
 │   File "$SRC_DIR/tests/test_algorithms.py", line 485, in test_algorithms_002_MEStatic_gpc_NaN
 │     session, coeffs, results = session.run()
 │                                ^^^^^^^^^^^^^
 │   File "$PREFIX/lib/python3.12/site-packages/pygpc/Session.py", line 119, in run
 │     gpc, coeffs, results = self.algorithm.run()
 │                            ^^^^^^^^^^^^^^^^^^^^
 │   File "$PREFIX/lib/python3.12/site-packages/pygpc/Algorithm.py", line 1089, in run
 │     res_new = com.run(model=self.problem.model,
 │               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 │   File "$PREFIX/lib/python3.12/site-packages/pygpc/Computation.py", line 363, in run
 │     res = Worker.run(obj=worker_objs, matlab_engine=self.matlab_engine)
 │           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 │   File "$PREFIX/lib/python3.12/site-packages/pygpc/Worker.py", line 57, in run
 │     out = obj.simulate(process_id, matlab_engine)
 │           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 │   File "$PREFIX/lib/python3.12/site-packages/pygpc/testfunctions/testfunctions.py", line 2090, in simulate
 │     y_out[i, 0] = np.array([y[-1]])
 │     ~~~~~^^^^^^
 │ ValueError: setting an array element with a sequence.
 │ ======================================================================
 │ ERROR: test_algorithms_004_MEStaticProjection_gpc (test_algorithms.TestPygpcMethods.test_algorithms_004_MEStaticProjection_gpc)
 │ Algorithm: MEStaticProjection
 │ ----------------------------------------------------------------------
 │ TypeError: only 0-dimensional arrays can be converted to Python scalars
 │ The above exception was the direct cause of the following exception:
 │ Traceback (most recent call last):
 │   File "$SRC_DIR/tests/test_algorithms.py", line 737, in test_algorithms_004_MEStaticProjection_gpc
 │     pygpc.get_sensitivities_hdf5(fn_gpc=options["fn_results"],
 │   File "$PREFIX/lib/python3.12/site-packages/pygpc/postprocessing.py", line 315, in get_sensitivities_hdf5
 │     sobol[jj, i] = sobol_qoi[s]
 │     ~~~~~^^^^^^^
 │ ValueError: setting an array element with a sequence.
 │ ======================================================================
 │ ERROR: test_algorithms_004_MEStaticProjection_gpc_NaN (test_algorithms.TestPygpcMethods.test_algorithms_004_MEStaticProjection_gpc_NaN)
 │ Algorithm: MEStaticProjection
 │ ----------------------------------------------------------------------
 │ Traceback (most recent call last):
 │   File "$SRC_DIR/tests/test_algorithms.py", line 823, in test_algorithms_004_MEStaticProjection_gpc_NaN
 │     session, coeffs, results = session.run()
 │                                ^^^^^^^^^^^^^
 │   File "$PREFIX/lib/python3.12/site-packages/pygpc/Session.py", line 119, in run
 │     gpc, coeffs, results = self.algorithm.run()
 │                            ^^^^^^^^^^^^^^^^^^^^
 │   File "$PREFIX/lib/python3.12/site-packages/pygpc/Algorithm.py", line 2320, in run
 │     eps = megpc[i_qoi].validate(coeffs=coeffs[i_qoi], results=res, gradient_results=grad_res_3D_passed)
 │           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 │   File "$PREFIX/lib/python3.12/site-packages/pygpc/MEGPC.py", line 400, in validate
 │     error_loocv = self.loocv(results=results,
 │                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^
 │   File "$PREFIX/lib/python3.12/site-packages/pygpc/MEGPC.py", line 281, in loocv
 │     domain_idx = int(self.classifier.predict(self.grid.coords_norm[loocv_point_idx[i]][np.newaxis, :]))
 │                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 │ TypeError: only 0-dimensional arrays can be converted to Python scalars
 │ ======================================================================
 │ ERROR: test_algorithms_011_MEStatic_IO_gpc (test_algorithms.TestPygpcMethods.test_algorithms_011_MEStatic_IO_gpc)
 │ Algorithm: MEStatic_IO
 │ ----------------------------------------------------------------------
 │ Traceback (most recent call last):
 │   File "$SRC_DIR/tests/test_algorithms.py", line 1772, in test_algorithms_011_MEStatic_IO_gpc
 │     session, coeffs, results = session.run()
 │                                ^^^^^^^^^^^^^
 │   File "$PREFIX/lib/python3.12/site-packages/pygpc/Session.py", line 119, in run
 │     gpc, coeffs, results = self.algorithm.run()
 │                            ^^^^^^^^^^^^^^^^^^^^
 │   File "$PREFIX/lib/python3.12/site-packages/pygpc/Algorithm.py", line 1510, in run
 │     eps = megpc[i_qoi].validate(coeffs=coeffs[i_qoi], results=res)
 │           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 │   File "$PREFIX/lib/python3.12/site-packages/pygpc/MEGPC.py", line 400, in validate
 │     error_loocv = self.loocv(results=results,
 │                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^
 │   File "$PREFIX/lib/python3.12/site-packages/pygpc/MEGPC.py", line 281, in loocv
 │     domain_idx = int(self.classifier.predict(self.grid.coords_norm[loocv_point_idx[i]][np.newaxis, :]))
 │                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 │ TypeError: only 0-dimensional arrays can be converted to Python scalars
 │ ======================================================================
 │ ERROR: test_grids_002_random_grid (test_grids.TestPygpcMethods.test_grids_002_random_grid)
 │ Testing Grids [Random]
 │ ----------------------------------------------------------------------
 │ TypeError: only 0-dimensional arrays can be converted to Python scalars
 │ The above exception was the direct cause of the following exception:
 │ Traceback (most recent call last):
 │   File "$SRC_DIR/tests/test_grids.py", line 152, in test_grids_002_random_grid
 │     grid = pygpc.Random(parameters_random=problem_2.parameters_random,
 │            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 │   File "$PREFIX/lib/python3.12/site-packages/pygpc/Grid.py", line 1439, in __init__
 │     self.coords_norm[i_grid, i_p] = np.random.normal(loc=0,
 │     ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
 │ ValueError: setting an array element with a sequence.
 │ ======================================================================
 │ ERROR: test_grids_004_L1_grid (test_grids.TestPygpcMethods.test_grids_004_L1_grid)
 │ Testing Grids [L1]
 │ ----------------------------------------------------------------------
 │ TypeError: only 0-dimensional arrays can be converted to Python scalars
 │ The above exception was the direct cause of the following exception:
 │ Traceback (most recent call last):
 │   File "$SRC_DIR/tests/test_grids.py", line 519, in test_grids_004_L1_grid
 │     grid = pygpc.L1(parameters_random=problem_2.parameters_random,
 │            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 │   File "$PREFIX/lib/python3.12/site-packages/pygpc/Grid.py", line 2680, in __init__
 │     self.coords_norm = self.get_optimal_mu_greedy()
 │                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 │   File "$PREFIX/lib/python3.12/site-packages/pygpc/Grid.py", line 2705, in get_optimal_mu_greedy
 │     random_pool = Random(parameters_random=self.parameters_random,
 │                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 │   File "$PREFIX/lib/python3.12/site-packages/pygpc/Grid.py", line 1439, in __init__
 │     self.coords_norm[i_grid, i_p] = np.random.normal(loc=0,
 │     ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
 │ ValueError: setting an array element with a sequence.
 │ ======================================================================
 │ ERROR: test_grids_005_FIM_grid (test_grids.TestPygpcMethods.test_grids_005_FIM_grid)
 │ Testing Grids [FIM]
 │ ----------------------------------------------------------------------
 │ TypeError: only 0-dimensional arrays can be converted to Python scalars
 │ The above exception was the direct cause of the following exception:
 │ Traceback (most recent call last):
 │   File "$SRC_DIR/tests/test_grids.py", line 701, in test_grids_005_FIM_grid
 │     grid = pygpc.FIM(parameters_random=problem_2.parameters_random,
 │            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 │   File "$PREFIX/lib/python3.12/site-packages/pygpc/Grid.py", line 3018, in __init__
 │     self.coords_norm = self.add_fim_optiomal_grid_points(parameters_random=parameters_random,
 │                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 │   File "$PREFIX/lib/python3.12/site-packages/pygpc/Grid.py", line 3066, in add_fim_optiomal_grid_points
 │     grid_pool = Random(parameters_random=parameters_random,
 │                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 │   File "$PREFIX/lib/python3.12/site-packages/pygpc/Grid.py", line 1439, in __init__
 │     self.coords_norm[i_grid, i_p] = np.random.normal(loc=0,
 │     ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
 │ ValueError: setting an array element with a sequence.
 │ ======================================================================
 │ ERROR: test_grids_007_GP_grid (test_grids.TestPygpcMethods.test_grids_007_GP_grid)
 │ Testing Grids [GP]
 │ ----------------------------------------------------------------------
 │ TypeError: only 0-dimensional arrays can be converted to Python scalars
 │ The above exception was the direct cause of the following exception:
 │ Traceback (most recent call last):
 │   File "$SRC_DIR/tests/test_grids.py", line 958, in test_grids_007_GP_grid
 │     grid = pygpc.Random(parameters_random=problem_2.parameters_random,
 │            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 │   File "$PREFIX/lib/python3.12/site-packages/pygpc/Grid.py", line 1439, in __init__
 │     self.coords_norm[i_grid, i_p] = np.random.normal(loc=0,
 │     ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
 │ ValueError: setting an array element with a sequence.
 │ ======================================================================
 │ ERROR: test_postprocessing_001_random_vars_postprocessing (test_postprocessing.TestPygpcMethods.test_postprocessing_001_random_vars_postprocessing)
 │ Algorithm: Static
 │ ----------------------------------------------------------------------
 │ TypeError: only 0-dimensional arrays can be converted to Python scalars
 │ The above exception was the direct cause of the following exception:
 │ Traceback (most recent call last):
 │   File "$SRC_DIR/tests/test_postprocessing.py", line 126, in test_postprocessing_001_random_vars_postprocessing
 │     grid = pygpc.Random(parameters_random=problem.parameters_random,
 │            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 │   File "$PREFIX/lib/python3.12/site-packages/pygpc/Grid.py", line 1450, in __init__
 │     self.coords_norm[i_grid, i_p] = np.random.gamma(
 │     ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
 │ ValueError: setting an array element with a sequence.
 │ ======================================================================
 │ ERROR: test_utils_001_testfunctions (test_utils.TestPygpcMethods.test_utils_001_testfunctions)
 │ Testing testfunctions (multi-threading and inherited parallelization)
 │ ----------------------------------------------------------------------
 │ TypeError: only 0-dimensional arrays can be converted to Python scalars
 │ The above exception was the direct cause of the following exception:
 │ Traceback (most recent call last):
 │   File "$SRC_DIR/tests/test_utils.py", line 145, in test_utils_001_testfunctions
 │     grid = pygpc.Random(
 │            ^^^^^^^^^^^^^
 │   File "$PREFIX/lib/python3.12/site-packages/pygpc/Grid.py", line 1439, in __init__
 │     self.coords_norm[i_grid, i_p] = np.random.normal(loc=0,
 │     ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
 │ ValueError: setting an array element with a sequence.
 │ ----------------------------------------------------------------------
 │ Ran 38 tests in 238.685s
 │ FAILED (errors=11)
 │ × error Script failed with status 1
 │ × error 
 │ × error Script execution failed.
 │ × error 
 │ × error   Work directory: /home/srimanachanta/Developer/recipe-testdir/output/test/test_pygpcoDw0YF/test_run_env/etc/conda/test-files/pygpc/1
 │ × error   Prefix: /home/srimanachanta/Developer/recipe-testdir/output/test/test_pygpcoDw0YF/test_run_env
 │ × error   Build prefix: None
 │ × error 
 │ × error To run the script manually, use the following command:
 │ × error 
 │ × error   cd "/home/srimanachanta/Developer/recipe-testdir/output/test/test_pygpcoDw0YF/test_run_env/etc/conda/test-files/pygpc/1" && ./conda_build.sh
 │ × error 
 │ × error To run commands interactively in the build environment:
 │ × error 
 │ × error   cd "/home/srimanachanta/Developer/recipe-testdir/output/test/test_pygpcoDw0YF/test_run_env/etc/conda/test-files/pygpc/1" && source build_env.sh
 │
 ╰─────────────────── (took 4 minutes)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions