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

Unexpected behaviour: elt(T) doesn't raise out-of range error #416

Open
tanlin2013 opened this issue Dec 20, 2022 · 5 comments
Open

Unexpected behaviour: elt(T) doesn't raise out-of range error #416

tanlin2013 opened this issue Dec 20, 2022 · 5 comments

Comments

@tanlin2013
Copy link

Hi there,

I accidentally realized when I access the element of tensor, and when I ask the index that is supposed to be out-of-range, elt() can still return a value, rather then just throwing an error. Though it appears like it always returns zero.

Personally I think it will be better to just throw an error, so even users are doing something wrongly, at least they got a notice?

best,
taolin

@mtfishman
Copy link
Member

Does it throw an error if you run in debug mode?

@emstoudenmire
Copy link
Contributor

I had the same question – more information on compiling and running in debug mode here:
http://itensor.org/docs.cgi?vers=cppv3&page=formulas/debug_mode

@tanlin2013
Copy link
Author

tanlin2013 commented Dec 21, 2022

Hi, so I gave a try in debug mode, and looks like it's still working fine?? 🤔

Here is one simple example, a 2 by 2 random tensor, and I ask for T(10, 10), which obviously is nonsense

auto i = Index(2);
auto j = Index(2);
auto T = randomITensor(i, j);
std::cout << "Here is the output: " << elt(T, 10, 10) << std::endl;

and still, I got a zero with no error messages.

Here is what gbd returned to me

root@2d7b272ef1f7:/home/tests# gdb -ex 'run' ./build/test.exe             
GNU gdb (Debian 10.1-1.7) 10.1.90.20210103-git
Copyright (C) 2021 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./build/test.exe...
Starting program: /home/tests/build/test.exe 
warning: Error disabling address space randomization: Operation not permitted
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
warning: File "/usr/local/lib64/libstdc++.so.6.0.30-gdb.py" auto-loading has been declined by your `auto-load safe-path' set to "$debugdir:$datadir/auto-load".
To enable execution of this file add
        add-auto-load-safe-path /usr/local/lib64/libstdc++.so.6.0.30-gdb.py
--Type <RET> for more, q to quit, c to continue without paging--c
line to your configuration file "/root/.gdbinit".
To completely disable this security protection add
        set auto-load safe-path /
line to your configuration file "/root/.gdbinit".
For more information about this security protection see the
"Auto-loading safe path" section in the GDB manual.  E.g., run from the shell:
        info "(gdb)Auto-loading safe path"
[New Thread 0x7fd605e56700 (LWP 135)]
[New Thread 0x7fd605655700 (LWP 136)]
[New Thread 0x7fd5fce54700 (LWP 137)]
Here is the output: 0
===============================================================================
test cases: 1 | 1 passed
assertions: - none -

[Thread 0x7fd605655700 (LWP 136) exited]
[Thread 0x7fd5fce54700 (LWP 137) exited]
[Thread 0x7fd605e56700 (LWP 135) exited]
[Inferior 1 (process 131) exited normally]

p.s. I ran this in Catch2 test case, but that shouldn’t be a problem I think.

@tanlin2013
Copy link
Author

tanlin2013 commented Dec 22, 2022

Hi there,

I did a more detailed check, and I think this is actually kind of overflow issue?

It seems like elt(T) can return either zero or infinity to me (yes, not just zero).

#include <catch2/catch_all.hpp>
#include <catch2/catch_test_macros.hpp>
#include "itensor/all.h"
using namespace itensor;

TEST_CASE("Test behaviour of elt(T) func", "[TestFuncElt]") {
  auto i = Index(2);
  auto j = Index(2);
  auto T = randomITensor(i, j);
  for (int k = 3; k < 20; ++k) {
    // always gives zero or infinity for out-of-range index?
    CHECK(((elt(T, k, k) < std::numeric_limits<float>::min()) ||
           (elt(T, k, k) > std::numeric_limits<float>::max())));
  }
}

outputs:

root@2d7b272ef1f7:/home/tests# ./build/test.exe [TestFuncElt]
Filters: [TestFuncElt]
===============================================================================
All tests passed (17 assertions in 1 test case)

Outputs are about the same in the debug mode, with just some information about the threads. No errors.

@tanlin2013
Copy link
Author

Hi, I guess this is forgotten after the new year 😆

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

3 participants