Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

negative axis 1 index #573

Closed
NAThompson opened this issue May 23, 2024 · 0 comments
Closed

negative axis 1 index #573

NAThompson opened this issue May 23, 2024 · 0 comments

Comments

@NAThompson
Copy link
Contributor

NAThompson commented May 23, 2024

Code to reproduce:

#!/usr/bin/env python3
from math import pi as π
import random
import numpy as np
from smt.surrogate_models import RMTB, RMTC


dimension = 2

def generate_sine_surface_data(samples=20):
    training_points = np.full(shape=(samples, dimension), fill_value=np.nan)
    training_values = np.full(shape=samples, fill_value=np.nan)

    for i in range(samples):
        x = np.random.uniform(-1, 1, dimension)
        training_points[i, :] = x
        v = 1
        for j in range(dimension):
            v *= np.sin(π*x[j])
        training_values[i] = v
    return training_points, training_values


def rmtb_surrogate_model(training_points, training_values):
    limits = np.full(shape=(dimension, 2), fill_value=np.nan)
    limits[0, 0] = -1
    limits[0, 1] = 1

    model = RMTB(
        xlimits=limits,
    )
    model.set_training_values(training_points, training_values)
    model.train()
    return model


if __name__ == "__main__":
    training_points, training_values = generate_sine_surface_data()
    rmtb = rmtb_surrogate_model(training_points, training_values)

Error:

___________________________________________________________________________
   
                                   RMTB
___________________________________________________________________________
   
 Problem size
   
      # training points.        : 20
   
___________________________________________________________________________
   
 Training
   
   Training ...
      Pre-computing matrices ...
         Computing dof2coeff ...
         Computing dof2coeff - done. Time (sec):  0.0000010
         Initializing Hessian ...
         Initializing Hessian - done. Time (sec):  0.0001552
         Computing energy terms ...
Traceback (most recent call last):
  File "~/smt/./rmtb_negative_axis.py", line 39, in <module>
    rmtb = rmtb_surrogate_model(training_points, training_values)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/smt/./rmtb_negative_axis.py", line 33, in rmtb_surrogate_model
    model.train()
  File "~/smt/smt/surrogate_models/surrogate_model.py", line 275, in train
    self._train()
  File "~/smt/smt/surrogate_models/rmts.py", line 443, in _train
    self._new_train()
  File "~/smt/smt/surrogate_models/rmts.py", line 406, in _new_train
    self._compute_energy_terms() * self.options["energy_weight"]
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/smt/smt/surrogate_models/rmts.py", line 209, in _compute_energy_terms
    mtx = self._compute_jac(kx + 1, kx + 1, x)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/smt/smt/surrogate_models/rmts.py", line 142, in _compute_jac
    full_jac = scipy.sparse.csc_matrix(
               ^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/smt/venv_smt/lib/python3.12/site-packages/scipy/sparse/_compressed.py", line 55, in __init__
    coo = self._coo_container(arg1, shape=shape, dtype=dtype)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/smt/venv_smt/lib/python3.12/site-packages/scipy/sparse/_coo.py", line 99, in __init__
    self._check()
  File "~/smt/venv_smt/lib/python3.12/site-packages/scipy/sparse/_coo.py", line 208, in _check
    raise ValueError(f'negative axis {i} index: {idx.min()}')
ValueError: negative axis 1 index: -1

Additional information:

$ pip show scipy
Name: scipy
Version: 1.13.1
$ python3 -V
Python 3.12.3
$ uname -a
Darwin  23.4.0 Darwin Kernel Version 23.4.0: Fri Mar 15 00:12:49 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T6020 arm64

Reproduces on scipy==1.12 as well, albeit with a different error message.

NAThompson added a commit to NAThompson/smt that referenced this issue May 24, 2024
In Issue SMTorg#573, I observed that `scipy`s compressed sparse column matrix
was throwing an exception about specification of negative indices. I
traced this issue to the column specification in the C++ implementation
of RMTB.

I could not figure out what precisely was going wrong. However, by
simply replacing all negative column indices with zeros, I found that
the unit tests pass. This is in no way a permanent solution, but given
the lack of shared understanding of this code, it is preferable to it
being fully nonfunctional.
NAThompson added a commit to NAThompson/smt that referenced this issue May 24, 2024
In Issue SMTorg#573, I observed that `scipy`s compressed sparse column matrix
was throwing an exception about specification of negative indices. I
traced this issue to the column specification in the C++ implementation
of RMTB.

I could not figure out what precisely was going wrong. However, by
simply replacing all negative column indices with zeros, I found that
the unit tests pass. This is in no way a permanent solution, but given
the lack of shared understanding of this code, it is preferable to it
being fully nonfunctional.

While we're at it, replace all internal `int`s by `long` in order to
support larger model sizes, similar to the diff made in RMTC.
NAThompson added a commit to NAThompson/smt that referenced this issue May 24, 2024
In Issue SMTorg#573, I observed that `scipy`s compressed sparse column matrix
was throwing an exception about specification of negative indices. I
traced this issue to the column specification in the C++ implementation
of RMTB.

I could not figure out what precisely was going wrong. However, by
simply replacing all negative column indices with zeros, I found that
the unit tests pass. This is in no way a permanent solution, but given
the lack of shared understanding of this code, it is preferable to it
being fully nonfunctional.

While we're at it, replace all internal `int`s by `long` in order to
support larger model sizes, similar to the diff made in RMTC.
relf pushed a commit that referenced this issue May 27, 2024
In Issue #573, I observed that `scipy`s compressed sparse column matrix
was throwing an exception about specification of negative indices. I
traced this issue to the column specification in the C++ implementation
of RMTB.

I could not figure out what precisely was going wrong. However, by
simply replacing all negative column indices with zeros, I found that
the unit tests pass. This is in no way a permanent solution, but given
the lack of shared understanding of this code, it is preferable to it
being fully nonfunctional.

While we're at it, replace all internal `int`s by `long` in order to
support larger model sizes, similar to the diff made in RMTC.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant