Skip to main content

WEmbed

This project contains the source code of WEmbed for calculating low dimensional weighted vertex embeddings. The library is written in C++ and includes Python bindings. Below is an example of a two-dimensional embedding calculated by WEmbed.

WEmbed embedding of the internet graph obtained from Boguñá, M., Papadopoulos, F. & Krioukov, D. Sustaining the Internet with hyperbolic mapping . Nat Commun 1, 62 (2010). https://doi.org/10.1038/ncomms1063

The network represents the connections between internet routers. Vertex size represents a weight, calculated by WEmbed, and colors indicate the country of the respective routers IP-Address. Note that WEmbed had no knowledge of the countries during the embedding process and still managed to assign vertices from the same countries similar spacial coordinates.

Installing the Python module

On most Linux systems we provide prebuild binaries, and you should be able to install WEmbed via pip. We recommend creating a new virtual environment before installing WEmbed.

python -m venv .venv
source .venv/bin/activate
pip install wembed

If your Linux system is not supported, or you are on Windows/Mac, pip will try to build WEmbed from source. In this case you have to make sure, that you install all necessary dependencies (see section further below).

Usage and file formats

Both the C++ example and the Python example show how to use the code. A minimal working example for the python bindings might look like this:

import wembed

graph = wembed.graphFromEdgeListFile("example.edg")
options = wembed.Options()
options.embeddingDimension = 4
embedder = wembed.createEmbedder(graph, options)

embedder.calculateEmbedding()

embedder.writeCoordinates("example.emb")
  • Start by creating a graph object. This can be done with a file (graphFromEdgeListFile) or a list of wembed.Edge objects (graphFromEdges). The graph is assumed to be undirected, connected and with consecutive vertex ids starting at zero. The file is expected to contain one line per edge. Each edge should only be given in one direction. The repository contains a small example graph file.

  • Create the embedder with createEmbedder from the graph object and an options object. You can modify the behavior of the embedder through this options object (e.g. changing the embedding dimension). You can calculate a single gradient descent step through calculateStep() or calculate until convergence with calculateEmbedding().

  • The final embedding can be written to file. It will contain one line per vertex. The first number of every line is the id of the vertex and the next d entries contain the coordinates for this vertex. The last entry represents the weight of the vertex.

Installing Dependencies

In order to compile WEmbed you need a C++20 compiler with OpenMP support and CMake 3.28 or newer. You can look at the flake.nix for more information. WEmbed also depends on a few smaller libraries, these get downloaded automatically by CMake via Fetchcontent (you do not have to worry about them).

By default, WEmbed uses the sprk tree as its spatial index, which needs a recent Rust toolchain (cargo 1.88 or newer). If you do not have Rust, configure with -DWEMBED_USE_SPRK=OFF: WEmbed then only contains a bundled KD-tree, which needs nothing but a C++ compiler. The KD-tree is never chosen silently, you have to select it explicitly (--index-type 0, or indexType = IndexKdTree in the options); it is also the only index for more than 16 embedding dimensions. Both indices report exactly the same repelling pairs, so the choice only affects the running time: expect the KD-tree to be a bit slower (x2.0) especially for datasets with few vertices or high dimensions.

Compiling with CMake

The project uses CMake as a build tool (see the root CMakeLists.txt for more details). In order to build the binaries clone this repository, and call CMake with the release preset. A release folder will be created, its bin and lib folders contain the executables and libraries.

git clone git@github.com:Vraier/wembed.git
cd wembed
cmake --preset release
cmake --build --preset release

This needs Ninja. Without it, cmake -B release -DCMAKE_BUILD_TYPE=Release followed by cmake --build release -j4 does the same.

The build can be adjusted with the following options (e.g. cmake --preset release -DWEMBED_USE_SPRK=OFF):

Option Default Description
WEMBED_USE_SPRK ON Use the sprk tree as spatial index (needs Rust). If OFF, only the bundled KD-tree is available.
WEMBED_BUILD_TOOLS ON Build the command line tools and unit tests. OFF by default if WEmbed is part of another project.
WEMBED_BUILD_PYTHON OFF Build the python module (needs the Python development headers). The presets turn this on.

Run the unit tests with ctest --preset release. See DEVELOPMENT.md for the other presets (debug with sanitizers, profiling) and for building wheels.

Using WEmbed in your C++ project

The C++ interface is the single header wembed.h and the CMake target wembed::wembed. With CMake's FetchContent, only the library is built, not the tools and tests:

include(FetchContent)
FetchContent_Declare(
    wembed
    GIT_REPOSITORY https://github.com/Vraier/wembed.git
    GIT_TAG        v0.2.0
)
FetchContent_MakeAvailable(wembed)

target_link_libraries(my_target PRIVATE wembed::wembed)

Project Structure

All C++ source files can be found in src, this includes the library and small example command line applications for C++. The python folder contains code for the python bindings and an example using these bindings. Unit tests using google test are found in tests.

Work in progress

Note that WEmbed is still quite experimental, expect major changes in the future. See TODOs for pending TODOs.

Metadata

Release files for wembed 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for wembed 0.2.0
File Size Uploaded Provenance Actions
wembed-0.2.0.tar.gz 1.4 MB Without provenance Details for wembed-0.2.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for wembed 0.2.0
File Actions
wembed-0.2.0-cp314-cp314-manylinux_2_28_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.28+ x86-64 Details for wembed-0.2.0-cp314-cp314-manylinux_2_28_x86_64.whl
wembed-0.2.0-cp313-cp313-manylinux_2_28_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.28+ x86-64 Details for wembed-0.2.0-cp313-cp313-manylinux_2_28_x86_64.whl
wembed-0.2.0-cp312-cp312-manylinux_2_28_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.28+ x86-64 Details for wembed-0.2.0-cp312-cp312-manylinux_2_28_x86_64.whl
wembed-0.2.0-cp311-cp311-manylinux_2_28_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.28+ x86-64 Details for wembed-0.2.0-cp311-cp311-manylinux_2_28_x86_64.whl
wembed-0.2.0-cp310-cp310-manylinux_2_28_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.28+ x86-64 Details for wembed-0.2.0-cp310-cp310-manylinux_2_28_x86_64.whl
wembed-0.2.0-cp39-cp39-manylinux_2_28_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.28+ x86-64 Details for wembed-0.2.0-cp39-cp39-manylinux_2_28_x86_64.whl

Total release size: 7.7 MB

Release files / wembed-0.2.0.tar.gz

Download URL wembed-0.2.0.tar.gz
Size 1.4 MB
Tags Source
SHA-256 checksum
How to use checksums
34268b869d62cfb0cc3f6bea203533e61338f08e798d68478e4ec1484469d5ec
BLAKE2b-256 checksum
How to use checksums
d237817a1d2638f0f9ead157f4c4e6dfcad4fbac6f4e3beba40aad9143dc5761
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / wembed-0.2.0-cp314-cp314-manylinux_2_28_x86_64.whl

Download URL wembed-0.2.0-cp314-cp314-manylinux_2_28_x86_64.whl
Size 1.1 MB
Tags CPython 3.14 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
07c78048033d3a5a3c22d0f622fc611807b22621e82fec9d67393b72cb1929d7
BLAKE2b-256 checksum
How to use checksums
51226478cb7ecaf1297b9a08022a997c1577d670fc0577eee9504af58eca4b89
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / wembed-0.2.0-cp313-cp313-manylinux_2_28_x86_64.whl

Download URL wembed-0.2.0-cp313-cp313-manylinux_2_28_x86_64.whl
Size 1.1 MB
Tags CPython 3.13 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
8921a2e03085f2cfbd2111d663bdc29e0e621ef666e54ecd6d0aa0e0dcd17219
BLAKE2b-256 checksum
How to use checksums
5d5664b112ae45ddcc1aace9229c43340a9341ad52b3b13872d3f8337b1f0764
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / wembed-0.2.0-cp312-cp312-manylinux_2_28_x86_64.whl

Download URL wembed-0.2.0-cp312-cp312-manylinux_2_28_x86_64.whl
Size 1.1 MB
Tags CPython 3.12 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
c35ca03f8eb5b09e95a403a540b60b897e66ded8ccda3b49b24716e1ae02ac0c
BLAKE2b-256 checksum
How to use checksums
89818dcea3673d1e5e60b09510407ab7aa696cb792498107b848181c5562f785
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / wembed-0.2.0-cp311-cp311-manylinux_2_28_x86_64.whl

Download URL wembed-0.2.0-cp311-cp311-manylinux_2_28_x86_64.whl
Size 1.1 MB
Tags CPython 3.11 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
8430b6ac0565dfa8d7ff4d0adb54624090396d1cf6bb98ce0c11e023e32fa1cf
BLAKE2b-256 checksum
How to use checksums
1813ccce1e05f84319f0dc0244a550158eaee57f04203779723db85b61ad6fcd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / wembed-0.2.0-cp310-cp310-manylinux_2_28_x86_64.whl

Download URL wembed-0.2.0-cp310-cp310-manylinux_2_28_x86_64.whl
Size 1.1 MB
Tags CPython 3.10 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
6b6943425c76684641e6fc6e8f12029fa9e25da15c6324e1de53c7ba33ab4a1a
BLAKE2b-256 checksum
How to use checksums
04aebaf0fc7a7b7c3d3ff3a23a03a28191c2145c64070d4ea5dae1586daa64e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / wembed-0.2.0-cp39-cp39-manylinux_2_28_x86_64.whl

Download URL wembed-0.2.0-cp39-cp39-manylinux_2_28_x86_64.whl
Size 1.1 MB
Tags CPython 3.9 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
cf3d347816a4ed3c107cf2d229f7be8c620aef8a610fe17caaaed0e4700aa686
BLAKE2b-256 checksum
How to use checksums
96d907d8ae2735cfaa3a308584efda6f73ebdd26fba3efb8727320f5e29f785f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Security for wembed 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page