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

early and informative exception when passing a non-scalar func to solver.optimize #753

Open
joostvanzwieten opened this issue Dec 14, 2022 · 4 comments · May be fixed by #789
Open

early and informative exception when passing a non-scalar func to solver.optimize #753

joostvanzwieten opened this issue Dec 14, 2022 · 4 comments · May be fixed by #789

Comments

@joostvanzwieten
Copy link
Member

solver.optimize requires a scalar function. If provided with a function that has one dimension or more, than solver.optimize (or actually sparse.take) spits out an error message that is not very helpful to end users. Example:

from nutils import function, solver
solver.optimize('x', function.Argument('x', (1,))**2)

Traceback:

Traceback (most recent call last):
  File "solver.py", line 834, in optimize
    val, res, jac = _integrate_blocks(functional, residual, jacobian, arguments=lhs, mask=mask)
  File "nutils/solver.py", line 981, in _integrate_blocks
    res = [sparse.take(next(data), [m]) for m in mask]
  File "nutils/solver.py", line 981, in <listcomp>
    res = [sparse.take(next(data), [m]) for m in mask]
  File "nutils/sparse.py", line 290, in take
    assert axis == len(shape)
AssertionError

Let's raise an early (don't traverse into _integrate_blocks) and informative exception instead.

@Sbhat92
Copy link
Contributor

Sbhat92 commented Mar 28, 2023

I would like to work on this issue

@gertjanvanzwieten
Copy link
Contributor

@Sbhat92 that would be great!

@Sbhat92
Copy link
Contributor

Sbhat92 commented May 5, 2023

I'm having trouble understanding how to check the dimension (if it is greater than or equal to 1) or if is a scalar. Can you please direct me?

@gertjanvanzwieten
Copy link
Contributor

Sorry for not noticing your question here before! I'll reply in the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants