fplll / fpylll

A Python interface for https://github.com/fplll/fplll
GNU General Public License v2.0
122 stars 62 forks source link

Cannot open strategies file #133

Closed cavidan1 closed 5 years ago

cavidan1 commented 5 years ago

I am running Sage on a remote cluster within a Singularity container. I am trying make BKZ reductions on different dimensional lattices.

My code:

#!/usr/bin/env sage
import sys
from sage.all import *
for i in range(50,700,100):
       L = sage.crypto.gen_lattice(m=i, seed=1337, lattice=True)
       B = L.BKZ(block_size=80, proof=False)
       q=(B[0].norm()/(L.volume())^(1/i))^(1/i)
       t=timeit("B = L.BKZ(block_size=80, proof=False)",seconds="true",repeat=1)
       print(i,numerical_approx(q),t)

But it returns runtime error:

terminate called after throwing an instance of 'std::runtime_error' what(): Cannot open strategies file. Traceback (most recent call last): File "./bkz_1", line 8, in B = L.BKZ(block_size=80, proof=False) File "/usr/local/SageMath/local/lib/python2.7/site-packages/sage/modules/free_module_integer.py", line 462, in BKZ basis = [v for v in basis.BKZ(*args, **kwds) if v] File "sage/matrix/matrix_integer_dense.pyx", line 2985, in sage.matrix.matrix_integer_dense.Matrix_integer_dense.BKZ (build/cythonized/sage/matrix/matrix_integer_dense.c:24789) File "src/fpylll/fplll/bkz_param.pyx", line 216, in fpylll.fplll.bkz_param.load_strategies_json RuntimeError: Aborted

What should be done in this case? Thank you very much.

malb commented 5 years ago

What does

sage: from fpylll import BKZ
sage: BKZ.DEFAULT_STRATEGY

return? Is there a file at the location pointed to by that filename? If not, that's your issue and it seems you moved the installation after installing it.

cavidan1 commented 5 years ago

Sage package is in Singularity container. It works for LLL reduction but not for BKZ.

It returns

/usr/local/SageMath/local/share/fplll/strategieparse error - unpreprocessing_blpruning_parameteError: gptr == nullpointer.

Thanks.

malb commented 5 years ago

Okay, I have no idea what's going on there. It seems fpylll can't find the BKZ strategies file.

cavidan1 commented 5 years ago

I see. Thank you for your time.

gwolosh commented 5 years ago

Hello,

I am the sysadmin who installed this. This is installed in a Singularity container. The installation was NOT moved. Within the container the strategies directory and default.json exist.

Singularity sage-8.6_ubuntu-16.04.simg:/usr/local/SageMath/local/share/fplll/strategies> ls /usr/local/SageMath/local/share/fplll/strategies/default.json /usr/local/SageMath/local/share/fplll/strategies/default.json

Nevertheless the error reported by cavidan1 is persistant. Are there any environment variable that need to be set. I looke d but was unable to find.

malb commented 5 years ago

Nope. The deeper problem seems to be the parse error, no idea why that happens.

/usr/local/SageMath/local/share/fplll/strategieparse error - unpreprocessing_blpruning_parameteError: gptr == nullpointer.
gwolosh commented 5 years ago

So it finds the file but can't read it?

malb commented 5 years ago

Seems you're getting a NULL pointer somehow?

gwolosh commented 5 years ago

Any idea what I can do to trouble shoot this?

dimpase commented 2 years ago
sage: from fpylll import BKZ
sage: BKZ.DEFAULT_STRATEGY
b'default.json'

and then (a Sage doctest):

sage: from sage.modules.free_module_integer import IntegerLattice
sage: L = IntegerLattice(sage.crypto.gen_lattice(type='modular', m=10, seed=1337, dual=True))
sage: L.shortest_vector()
terminate called after throwing an instance of 'std::runtime_error'
  what():  Cannot open strategies file.
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
~/work/sage/local/var/lib/sage/venv-python3.9/lib/python3.9/site-packages/sage/misc/cachefunc.pyx in sage.misc.cachefunc.CachedMethodCaller.__call__ (build/cythonized/sage/misc/cachefunc.c:10347)()
   1942             try:
-> 1943                 return cache[k]
   1944             except TypeError:  # k is not hashable

KeyError: ((True, 'fplll'), ())
...
joerowell commented 2 years ago
sage: from fpylll import BKZ
sage: BKZ.DEFAULT_STRATEGY
b'default.json'

and then (a Sage doctest):

sage: from sage.modules.free_module_integer import IntegerLattice
sage: L = IntegerLattice(sage.crypto.gen_lattice(type='modular', m=10, seed=1337, dual=True))
sage: L.shortest_vector()
terminate called after throwing an instance of 'std::runtime_error'
  what():  Cannot open strategies file.
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
~/work/sage/local/var/lib/sage/venv-python3.9/lib/python3.9/site-packages/sage/misc/cachefunc.pyx in sage.misc.cachefunc.CachedMethodCaller.__call__ (build/cythonized/sage/misc/cachefunc.c:10347)()
   1942             try:
-> 1943                 return cache[k]
   1944             except TypeError:  # k is not hashable

KeyError: ((True, 'fplll'), ())
...

Could I get some more information on this? Is this the latest Sage version? How was this built?

I tried to fix a similar bug in #220 but it's possible that my local Sage is different from yours. If you could let me know I'll take a look tomorrow and get back to you.

dimpase commented 2 years ago

It's probably a Debian 11 bug - I'm using fplll that comes in Debian, and it appears they just don't install default.json anywhere. See https://packages.debian.org/bullseye/libfplll-dev

dimpase commented 2 years ago

more precisely, Debian 11 installs default.json in /usr/share/libfplll7/strategies/ - and apparently fpylll can't find it there.

joerowell commented 2 years ago

Thanks for the info! I'll try reproduce it tomorrow (and if possible get a patch done too).

On Fri, 4 Feb 2022, 23:10 Dima Pasechnik, @.***> wrote:

more precisely, Debian 11 installs default.json in /usr/share/libfplll7/strategies/ - and apparently fpylll can't find it there.

— Reply to this email directly, view it on GitHub https://github.com/fplll/fpylll/issues/133#issuecomment-1030420151, or unsubscribe https://github.com/notifications/unsubscribe-auth/AF7CASDODTGUMHYCC2DR4DTUZRMHTANCNFSM4HAJQW7A . You are receiving this because you commented.Message ID: @.***>

dimpase commented 2 years ago

If fplll wrote that location in fplll.pc, for pkg-config, it would be trivial to find from Python, or otherwise.

dimpase commented 2 years ago

What does

sage: from fpylll import BKZ
sage: BKZ.DEFAULT_STRATEGY

return? Is there a file at the location pointed to by that filename? If not, that's your issue and it seems you moved the installation after installing it.

see #221 - something is not right in fpylll.