Debian Codegraph @

/

debian fpylll 0.6.4-1.1debian python3-fpylll debian python-fpylll-doc python fpylll 0.6.4 cdebianinimakemakefilepythonshelltomlyaml 65 files · 864 symbols
View dependency graph

Depends on

README (full)

fpylll

A Python wrapper for fplll_.

:target: https://github.com/fplll/fpylll/actions?query=workflow%3ATests

:target: https://badge.fury.io/py/fpylll

:target: http://fpylll.readthedocs.io/en/latest/?badge=latest

 >>> from fpylll import *

 >>> A = IntegerMatrix(50, 50)
 >>> A.randomize("ntrulike", bits=50, q=127)
 >>> A[0].norm()
 3564748886669202.5

 >>> M = GSO.Mat(A)
 >>> M.update_gso()
 >>> M.get_mu(1,0)
 0.815748944429783

 >>> L = LLL.Reduction(M)
 >>> L()
 >>> M.get_mu(1,0)
 0.41812865497076024
 >>> A[0].norm()
 24.06241883103193

The basic BKZ algorithm can be implemented in about 60 pretty readable lines of Python code (cf. simple_bkz.py_). For a quick tour of the library, you can check out the tutorial_.

How to cite

 @unpublished{fpylll,
     author = {The {FPLLL} development team},
     title = {{fpylll}, a {Python} wrapper for the {fplll} lattice reduction library, {Version}: 0.6.4},
     year = 2025,
     note = {Available at \url{https://github.com/fplll/fpylll}},
     url = {https://github.com/fplll/fpylll}
 }

Requirements

fpylll relies on the following C/C++ libraries:

  • GMP_ or MPIR_ for arbitrary precision integer arithmetic.

  • MPFR_ for arbitrary precision floating point arithmetic.

  • QD_ for double double and quad double arithmetic (optional).

  • fplll_ for pretty much everything.

fpylll also relies on

  • Cython_ for linking Python and C/C++.

  • cysignals_ for signal handling such as interrupting C++ code.

  • py.test_ for testing Python.

  • flake8_ for linting.

We also suggest

  • virtualenv_ to build and install fpylll in

  • IPython_ for interacting with Python

  • Numpy_ for numerical computations (e.g. with Gram-Schmidt values)

Online

fpylll ships with Sage. Thus, it is available via SageMathCell_ and CoCalc_ (select a Jupyter notebook with a Sage kernel).

Getting Started

Note: fpylll is also available via PyPI_ and Conda-Forge_ for Conda_. In what follows, we explain manual installation.

We recommend virtualenv_ for isolating Python build environments and virtualenvwrapper_ to manage virtual environments. We indicate active virtualenvs by the prefix (fpylll).

Automatic install

1. Run bootstrap.sh

$ ./bootstrap.sh $ source ./activate

Manual install

1. Create a new virtualenv and activate it:

$ virtualenv env $ ln -s ./env/bin/activate ./ $ source ./activate

2. Install the required libraries - GMP_ or MPIR_ and MPFR_ - if not available already. You may also want to install QD_.

3. Install fplll:

$ (fpylll) ./install-dependencies.sh $VIRTUAL_ENV

Some OSX users report that they required export CXXFLAGS="-stdlib=libc++ -mmacosx-version-min=10.7" and export CXX=clang++ (after installing a recent clang with brew_) since the default GCC installed by Apple does not have full C++11 support.

4. Then, execute:

$ (fpylll) pip install -r requirements.txt

to install the required Python packages (see above).

5. If you are so inclined, run:

$ (fpylll) pip install -r suggestions.txt

to install suggested Python packages as well (optional).

6. Build the Python extension:

$ (fpylll) export PKG_CONFIG_PATH="$VIRTUAL_ENV/lib/pkgconfig:$PKG_CONFIG_PATH" $ (fpylll) python setup.py build $ (fpylll) pip install .

7. To run fpylll, you will need to:

$ (fpylll) export LD_LIBRARY_PATH="$VIRTUAL_ENV/lib"

so that Python can find fplll and friends.

Note that you can also patch activate to set LD_LIBRRY_PATH. For this, add:

### LD_LIBRARY_HACK _OLD_LD_LIBRARY_PATH="$LD_LIBRARY_PATH" LD_LIBRARY_PATH="$VIRTUAL_ENV/lib:$LD_LIBRARY_PATH" export LD_LIBRARY_PATH ### END_LD_LIBRARY_HACK

### PKG_CONFIG_HACK _OLD_PKG_CONFIG_PATH="$PKG_CONFIG_PATH" PKG_CONFIG_PATH="$VIRTUAL_ENV/lib/pkgconfig:$PKG_CONFIG_PATH" export PKG_CONFIG_PATH ### END_PKG_CONFIG_HACK

towards the end and:

### LD_LIBRARY_HACK if ! [ -z ${_OLD_LD_LIBRARY_PATH+x} ] ; then LD_LIBRARY_PATH="$_OLD_LD_LIBRARY_PATH" export LD_LIBRARY_PATH unset _OLD_LD_LIBRARY_PATH fi ### END_LD_LIBRARY_HACK

### PKG_CONFIG_HACK if ! [ -z ${_OLD_PKG_CONFIG_PATH+x} ] ; then PKG_CONFIG_PATH="$_OLD_PKG_CONFIG_PATH" export PKG_CONFIG_PATH unset _OLD_PKG_CONFIG_PATH fi ### END_PKG_CONFIG_HACK

in the deactivate function in the activate script.

Running fpylll

1. To (re)activate the virtual environment, simply run:

$ source ./activate

2. Start Python:

$ (fpylll) ipython

Manual update of fpylll and fplll inside Sagemath 9.0+

The instructions are very similar to the manual ones above.

1. Activate the sage-sh virtualenv:

$ sage -sh

2. Install the required libraries - GMP_ or MPIR_ and MPFR_ - if not available already. You may also want to install QD_.

3. Install fplll:

$ (sage-sh) ./install-dependencies.sh $SAGE_LOCAL

Some OSX users report that they required export CXXFLAGS="-stdlib=libc++ -mmacosx-version-min=10.7" and export CXX=clang++ (after installing a recent clang with brew_) since the default GCC installed by Apple does not have full C++11 support.

4. Then, execute:

$ (sage-sh) pip3 install -r requirements.txt

to install the required Python packages (see above).

5. If you are so inclined, run:

$ (sage-sh) pip3 install -r suggestions.txt

to install suggested Python packages as well (optional).

6. Build the Python extension:

$ (sage-sh) export PKG_CONFIG_PATH="$SAGE_LOCAL/lib/pkgconfig:$PKG_CONFIG_PATH" $ (sage-sh) python3 setup.py build $ (sage-sh) pip3 install . $ (sage-sh) exit

7. Verify the upgrade went well:

$ sage sage: import fpylll sage: print(fpylll._version_)

The output should match the value of `__version_` in src/fpylll/__init__.py_.

Multicore Support

fpylll supports parallelisation on multiple cores. For all C++ support to drop the GIL is enabled, allowing the use of threads to parallelise. Fplll is thread safe as long as each thread works on a separate object such as IntegerMatrix or MatGSO. Also, fpylll does not actually drop the GIL in all calls to C++ functions yet. In many scenarios using multiprocessing, which sidesteps the GIL and thread safety issues by using processes instead of threads, will be the better choice.

The example below calls LLL.reduction on 128 matrices of dimension 30 on four worker processes.

 from fpylll import IntegerMatrix, LLL
 from multiprocessing import Pool

 d, workers, tasks = 30, 4, 128

 def run_it(p, f, A, prefix=""):
     """Print status during parallel execution."""
     import sys
     r = []
     for i, retval in enumerate(p.imap_unordered(f, A, 1)):
         r.append(retval)
         sys.stderr.write('\r{0} done: {1:.2%}'.format(prefix, float(i)/len(A)))
         sys.stderr.flush()
     sys.stderr.write('\r{0} done {1:.2%}\n'.format(prefix, float(i+1)/len(A)))
     return r

 A = [IntegerMatrix.random(d, "uniform", bits=30) for _ in range(tasks)]
 A = run_it(Pool(workers), LLL.reduction, A)

To test threading simply replace the line from multiprocessing import Pool with from multiprocessing.pool import ThreadPool as Pool. For calling BKZ.reduction this way, which expects a second parameter with options, using functools.partial is a good choice.

Contributing

fpylll welcomes contributions, cf. the list of open issues. To contribute, clone this repository, commit your code on a separate branch and send a pull request. Please write tests for your code. You can run them by calling::

$ (fpylll) PY_IGNORE_IMPORTMISMATCH=1 py.test

from the top-level directory which runs all tests in tests/test_*.py. We run flake8 on every commit automatically, In particular, we run::

$ (fpylll) flake8 --max-line-length=120 --max-complexity=16 --ignore=E22,E241 src

Note that fpylll supports Python 3. In particular, tests are run using Python 3.10, 3.11 and 3.12. See .tests.yml for details on automated testing.

Attribution & License

fpylll is maintained by Martin Albrecht.

The following people have contributed to fpylll

  • Eamonn Postlethwaite

  • E M Bray

  • Fernando Virdia

  • Guillaume Bonnoron

  • Jeroen Demeyer

  • Jérôme Benoit

  • Konstantinos Draziotis

  • Leo Ducas

  • Martin Albrecht

  • Michael Walter

  • Omer Katz

We copied a decent bit of code over from Sage, mostly from it's fpLLL interface.

fpylll is licensed under the GPLv2+.

This project was supported through the European Union PROMETHEUS project (Horizon 2020 Research and Innovation Program, grant 780701), EPSRC grant EP/P009417/1 and EPSRC grant EP/S020330/1.

dir .github/
dir debian/
dir docs/
dir src/
dir tests/
file .gitignore
file Dockerfile
file LICENSE
file MANIFEST.in
file README.rst
file bootstrap.sh
file install-dependencies.sh
file pyproject.toml
file pytest.ini
file readthedocs-conda.yml
file readthedocs.yml
file requirements.txt
file setup.py
file suggestions.txt