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), a list of wembed.Edge objects (graphFromEdges) or offset and neighbor arrays in CSR form (graphFromNeighborhoods). 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.3.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.3.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.3.0
File Size Uploaded Provenance Actions
wembed-0.3.0.tar.gz 1.4 MB Without provenance Details for wembed-0.3.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for wembed 0.3.0
File Actions
wembed-0.3.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.3.0-cp314-cp314-manylinux_2_28_x86_64.whl
wembed-0.3.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.3.0-cp313-cp313-manylinux_2_28_x86_64.whl
wembed-0.3.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.3.0-cp312-cp312-manylinux_2_28_x86_64.whl
wembed-0.3.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.3.0-cp311-cp311-manylinux_2_28_x86_64.whl
wembed-0.3.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.3.0-cp310-cp310-manylinux_2_28_x86_64.whl
wembed-0.3.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.3.0-cp39-cp39-manylinux_2_28_x86_64.whl

Total release size: 7.8 MB

Release files / wembed-0.3.0.tar.gz

Download URL wembed-0.3.0.tar.gz
Size 1.4 MB
Tags Source
SHA-256 checksum
How to use checksums
c2c6b2d5a69d30f12e469d8f5c03d0840efc0a37c2e870af9f1543653ad974a9
BLAKE2b-256 checksum
How to use checksums
2400b1b86885759b675e2883fe69a868eae1e36f565fccb792a2c32215c7f480
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.3.0-cp314-cp314-manylinux_2_28_x86_64.whl

Download URL wembed-0.3.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
c45d42af31f3f13dbce73b70d127b90c22cf08ab7151ac2214431292fe6a87b7
BLAKE2b-256 checksum
How to use checksums
a9990ff53871e55596d670ec9f4f8ab574e06f45bc13cb063b7249dd375f7332
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.3.0-cp313-cp313-manylinux_2_28_x86_64.whl

Download URL wembed-0.3.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
24206729065df7a1b64678d28926a29a18f06bffa8e33f1c8a339e7f4607c0c1
BLAKE2b-256 checksum
How to use checksums
61262bc38924e23dab5ecc2797b1f6ff98eeb21b1e95c21a52a11aeaf5806173
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.3.0-cp312-cp312-manylinux_2_28_x86_64.whl

Download URL wembed-0.3.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
07f235e003b4f0028978593d03be578ca2a418579e8f9bb9adfb96c550542662
BLAKE2b-256 checksum
How to use checksums
fcfcd4443dbbad260898154daf70c02d85192ed7d1dc474328038e939c956667
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.3.0-cp311-cp311-manylinux_2_28_x86_64.whl

Download URL wembed-0.3.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
82a9754475fab4e56bd5661e54cbf9e9f1537290e4fe941289ff6fef07a40f5f
BLAKE2b-256 checksum
How to use checksums
85498f146f21604fb6238e88ec685d92cb7ab95b2c2e7b3e2836c6ccc83d4929
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.3.0-cp310-cp310-manylinux_2_28_x86_64.whl

Download URL wembed-0.3.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
f23a82a9fd52fcb501b378012bc2be25beac870958aab904c3448abd050242a4
BLAKE2b-256 checksum
How to use checksums
1ac88b27de221ee1fcfa98a2a92402daf7a73b179a2ff23c24c2cc93dddcbdb2
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.3.0-cp39-cp39-manylinux_2_28_x86_64.whl

Download URL wembed-0.3.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
ca37cf68cf0a069eee507e9b5231849c37d798ff7ff12f32357269993b988854
BLAKE2b-256 checksum
How to use checksums
f504bcbed18e7d6de63d6b615b1980c1176eee66a78d1d4e3422c2fac62fe936
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.3.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