-
Notifications
You must be signed in to change notification settings - Fork 3
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
Flatnav python bindings #14
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
aae779b
making progress on python bindings
blaise-muhirwa 6004a2c
all bindings for l2 & ip work
blaise-muhirwa 15a20c8
testing index
blaise-muhirwa f9aebaf
add python tests
blaise-muhirwa d9923e6
clean up
blaise-muhirwa 4ce61bd
Update README
blaise-muhirwa ebc5902
update readme
blaise-muhirwa bfcbf97
support apple darwin
blaise-muhirwa 8c5631c
remove requirements.txt and run_anns.sh
blaise-muhirwa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,51 +70,13 @@ correct distance is computed. | |
The most straightforward way to include a new dataset for this evaluation is to put it into either the ANN-Benchmarks (NPY) format or to put it into the Big ANN-Benchmarks format. The NPY format requires a float32 2-D Numpy array for the train and test sets and an integer array for the ground truth. The Big ANN-Benchmarks format uses the following binary representation. For the train and test data, there is a 4-byte little-endian unsigned integer number of points followed by a 4-byte little-endian unsigned integer number of dimensions. This is followed by a flat list of `num_points * num_dimensions` values, where each value is a 32-bit float or an 8-bit integer (depending on the dataset type). The ground truth files consist of a 32-bit integer number of queries, followed by a 32-bit integer number of ground truth results for each query. This is followed by a flat list of ground truth results. | ||
|
||
|
||
## Python Binding Instructions | ||
We also provide python bindings for a subset of index types. This is very much a work in progress - the default build may or may not work with a given Pyton configuration. While we've successfully built the bindings on Windows, Linux and MacOS, this will still probably require some customization of the build system. To begin with, follow these instructions: | ||
## Python Binding Instructions | ||
We also provide python bindings for a subset of index types. We've successfully built the bindings on Linux and MacOS, and if there is interest, | ||
we can also support Windows. To generate the python bindings you will need a stable installation of [poetry](https://python-poetry.org/). | ||
|
||
1. `$ cd python_bindings` | ||
2. `$ make python-bindings` | ||
3. `$ export PYTHONPATH=$(pwd)/build:$PYTHONPATH` | ||
4. `$ python3 python_bindings/test.py` | ||
Then, follow instructions [here](/flatnav_python/README.md) on how to build the library. There are also examples for how to use the library | ||
to build an index and run queries on top of it [here](/flatnav_python/test_index.py). | ||
|
||
You are likely to encounter compilation issues depending on your Python configuration. See below for notes and instructions on how to get this working. | ||
|
||
### Note on python bindings: | ||
The python bindings require pybind11 to compile. This can be installed with `pip3 install pybind11`. The command `python3 -m pybind11 --includes` which is included in the Makefile gets the correct include flags for the `pybind11/pybind11.h` header file, as well as the include flags for the `Python.h` header file. On most Linux platforms, the paths in the Makefile should point to the correct include directories for this to work (for the system Python). If the `Python.h` file is not located at the specified include paths (e.g. for a non-system Python installation), then another include path may need to be added (specified by the PYTHON_INC_FLAGS variable in the Makefile). The headers may also need to be installed with `$ sudo apt-get install python3-dev`. | ||
|
||
If you encounter the following error: | ||
|
||
`ld: can't open output file for writing: ../build/flatnav.so, errno=2 for architecture x86_64` | ||
|
||
The reason is likely that you forgot to make the build directory. Run `mkdir build` in the top-level flatnav directory and re-build the Python bindings. | ||
|
||
### Special Instructions for MacOS | ||
|
||
On MacOS, the default installation directory (`/usr/lib`) is where the global, system Python libraries are located, but this is often not where we want to perform the installation. If the user has installed their own (non-system) version of Python via Homebrew or a similar tool, the actual Python libraries will be located somewhere else. This will result in many errors similar to the following: | ||
|
||
``` | ||
Undefined symbols for architecture x86_64: | ||
"_PyBaseObject_Type... | ||
``` | ||
|
||
This happens because homebrew does not install into the global installation directory, and we need to explicitly link the libpython object files on MacOS. To fix it, you will need the location of `libpython*.dylib` (where `*` stands in for the Python version). To find them, run | ||
|
||
`sudo find / -iname "libpython*"` | ||
|
||
And pick the one corresponding to the version of Python you use. Once you've located the library, add the following to the Makefile: | ||
|
||
`PYTHON_LINK_FLAGS := -L /path/to/directory/containing/dylib/ -lpythonX.Y` | ||
|
||
For example, on an Intel MacBook, I installed Python 3.9 using Homebrew and found: | ||
|
||
`/usr/local/Cellar/[email protected]/3.9.4/Frameworks/Python.framework/Versions/3.9/lib/libpython3.9.dylib` | ||
|
||
This means that my link flags are: | ||
|
||
`PYTHON_LINK_FLAGS := -L /usr/local/Cellar/[email protected]/3.9.4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/config-3.9-darwin/ -lpython3.9` | ||
|
||
If you installed Python in some other place (or if you use the system Python on MacOS), you will probably have a different, non-standard location for `libpython.dylib`. Note that building python bindings on M1 Macs is a work-in-progress, given the switch from x86 to arm64. | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Passing these here directly so that there is no confusion when someone has both GCC and clang.