Simple Lattice/Graph Library
Project description
lattice
Simple Lattice/Graph Library
Main functions
- Access to information of lattice structure (sites, bonds, etc)
- Construct lattice from unitcell, span vector of supercell, and boundary conditions
- Construct lattice by adding sites and bonds one by one
- Reading and writing ALPS Lattice XML file
Prerequisites
For Rust
- Rust toolchain (
rustc,cargo)
For Python
- Python (>= 3.9)
- Rust toolchain (
rustc,cargo) - maturin
- NumPy
For C++
- C++-17 compiler
- CMake (>= 3.14)
- Eigen3
- Rust toolchain (
rustc,cargo) for auto-buildingrust/lattice-ffi
Note: C++ build may invoke cargo automatically to build rust/lattice-ffi when the shared library is missing.
Rust workspace
The repository is being extended with a Rust core under rust/ as the shared implementation base for future Python and Julia bindings.
C++ XML compatibility bridge (default)
Rust-backed XML implementation is now the default C++ XML backend.
When building C++ targets, CMake automatically builds rust/lattice-ffi with cargo if the required shared library is missing.
Rust targets are managed in the workspace under rust/:
lattice-core: core model + XML parser/writerlattice-ffi: C ABI layer for C++ compatibilitylattice-python: PyO3/maturin Python bindings
Build, test, and sample run
Rust
Build and run Rust tests:
cargo build
cargo test
The Python extension crate is a workspace member, but it is not a default member because PyO3 extension modules should be linked by maturin. Build it with the Python instructions below.
Python
Create a virtual environment and install the Python extension in editable mode:
python3 -m venv .venv
.venv/bin/python -m pip install maturin numpy
.venv/bin/python -m maturin develop
From PyPI, the distribution name is lattice-graph-core and the import name is
lattice:
python -m pip install lattice-graph-core
Run the Python tests:
.venv/bin/python -m unittest discover -s python/tests
See docs/pypi.md for release-build and PyPI upload steps.
Minimal Python example:
import lattice
graph = lattice.Graph.simple(2, 4)
print(graph.num_sites)
print(graph.coordinates().shape)
Run Rust samples:
cargo run -p lattice-core --example construct1
cargo run -p lattice-core --example construct2
cargo run -p lattice-core --example construct3
cargo run -p lattice-core --example construct4
cargo run -p lattice-core --example construct_xml
cargo run -p lattice-core --example ising
C++ (default)
Configure and build:
cmake -S . -B build
cmake --build build
Run C++ tests:
Enable tests at configure time, then run ctest:
cmake -S . -B build -DLATTICE_BUILD_TESTS=ON
cmake --build build
ctest --test-dir build --output-on-failure
Run C++ samples:
./build/example/construct1
./build/example/construct2
./build/example/construct3
./build/example/construct4
./build/example/construct_xml
./build/example/ising
Workaround for MacOSX26.sdk
Use CMake presets to pin the SDK to MacOSX15.4.sdk:
cmake --preset macos-sdk154
cmake --build --preset macos-sdk154
ctest --preset macos-sdk154
Using Installed Package
Install into a prefix:
cmake --install build-sdk154 --prefix /path/to/prefix
CMake find_package(lattice)
Set CMAKE_PREFIX_PATH to the install prefix and use find_package:
cmake_minimum_required(VERSION 3.14)
project(lattice_consumer CXX)
find_package(lattice REQUIRED)
add_executable(app main.cpp)
target_link_libraries(app PRIVATE lattice::lattice)
Configure example:
cmake -S . -B build -DCMAKE_PREFIX_PATH=/path/to/prefix
cmake --build build
pkg-config
Set PKG_CONFIG_PATH and query compile/link flags:
export PKG_CONFIG_PATH=/path/to/prefix/lib/pkgconfig:$PKG_CONFIG_PATH
pkg-config --cflags --libs lattice
Compile example:
c++ -std=c++17 main.cpp $(pkg-config --cflags --libs lattice) -o app
Classes/types
-
lattice::basis
Helper class that contains the shape, i.e. the set of basis vectors, of the unit cell.
-
lattice::unitcell
Helper class that contains the structure, i.e. sites and bonds, of the unit cell.
-
lattice::graph
This class contains the structure of the whole lattice structure. It provides various information of sites (vertices) and bonds (edges) via the following member functions:
member functions description std::size_t dimension() const; dimension of the lattice std::size_t num_sites() const; total number of sites std::size_t site_type(std::size_t s) const; type of site s const coordinate_t& coordinate(std::size_t s) const; coordinate of site s std::size_t num_neighbors(std::size_t s) const; number of neighboring sites of site s std::size_t neighbor(std::size_t s, std::size_t k) const; k-th neighbor site of site s std::size_t neighbor_bond(std::size_t s, std::size_t k) const; bond connecting site s and its k-th neighbor site std::size_t num_bonds() const; total number of bonds int bond_type(std::size_t b) const; type of bond s std::size_t source(std::size_t b) const; start point (site) of bond b std::size_t target(std::size_t b) const; end point (site) of bond b
How to construct lattices
Rust
-
periodic chain lattice of 16 sites
-
simplest interface
use lattice_core::Graph; let graph = Graph::simple(1, 16);
-
most generic interface
use lattice_core::{Basis, BasisMatrix, Boundary, CoordinateVector, ExtentVector, Graph, OffsetVector, Unitcell}; let basis = Basis::new(BasisMatrix::from_row_slice(1, 1, &[1.0])); let mut unitcell = Unitcell::new(1); unitcell.add_site(CoordinateVector::from_element(1, 0.0), 0); unitcell.add_bond(0, 0, OffsetVector::from_element(1, 1), 0); let extent = ExtentVector::from_element(1, 16); let boundary = vec![Boundary::Periodic; 1]; let graph = Graph::from_basis_unitcell_extent(&basis, &unitcell, &extent, &boundary);
-
-
periodic square lattice of 4 x 4 sites
-
simplest interface
use lattice_core::Graph; let graph = Graph::simple(2, 4);
-
most generic interface
use lattice_core::{Basis, BasisMatrix, Boundary, CoordinateVector, ExtentVector, Graph, OffsetVector, Unitcell}; let basis = Basis::new(BasisMatrix::from_row_slice(2, 2, &[1.0, 0.0, 0.0, 1.0])); let mut unitcell = Unitcell::new(2); unitcell.add_site(CoordinateVector::from_vec(vec![0.0, 0.0]), 0); unitcell.add_bond(0, 0, OffsetVector::from_vec(vec![1, 0]), 0); unitcell.add_bond(0, 0, OffsetVector::from_vec(vec![0, 1]), 0); let extent = ExtentVector::from_vec(vec![4, 4]); let boundary = vec![Boundary::Periodic; 2]; let graph = Graph::from_basis_unitcell_extent(&basis, &unitcell, &extent, &boundary);
-
reading basis and unitcell from XML file
use lattice_core::{read_basis_from_file, read_unitcell_from_file, Boundary, ExtentVector, Graph}; let file = "cxx/example/lattices.xml"; let basis = read_basis_from_file(file, "square lattice")?; let cell = read_unitcell_from_file(file, "simple2d")?; let extent = ExtentVector::from_vec(vec![4, 4]); let boundary = vec![Boundary::Periodic; 2]; let graph = Graph::from_basis_unitcell_extent(&basis, &cell, &extent, &boundary);
-
-
fully connected lattice of 10 sites
use lattice_core::Graph; let graph = Graph::fully_connected(10);
C++
-
periodic chain lattice of 16 sites
-
simplest interface
lattice::graph lat = lattice::graph::simple(1, 16);
-
most generic interface
lattice::basis_t bs(1, 1); bs << 1; // 1x1 matrix lattice::basis basis(bs); lattice::unitcell unitcell(1); unitcell.add_site(lattice::coordinate(0), 0); unitcell.add_bond(0, 0, lattice::offset(1), 0); lattice::span_t span(1, 1); span << 16; // 1x1 matrix std::vector<lattice::boundary_t> boundary(1, lattice::boundary_t::periodic); lattice::graph lat(basis, unitcell, span, boundary);
-
-
periodic square lattice of 4 x 4 sites
-
simplest interface
lattice::graph lat = lattice::graph::simple(2, 4);
-
most generic interface
lattice::basis_t bs(2, 2); bs << 1, 0, 0, 1; // 2x2 matrix lattice::basis basis(bs); lattice::unitcell unitcell(2); unitcell.add_site(lattice::coordinate(0, 0), 0); unitcell.add_bond(0, 0, lattice::offset(1, 0), 0); unitcell.add_bond(0, 0, lattice::offset(0, 1), 0); lattice::span_t span(2, 2); span << 4, 0, 0, 4; // 2x2 matrix std::vector<lattice::boundary_t> boundary(2, lattice::boundary_t::periodic); lattice::graph lat(basis, unitcell, span, boundary);
-
reading basis and unitcell from XML file
std::string file = "lattices.xml"; lattice::basis bs; read_xml_file(file, "square lattice", bs); lattice::unitcell cell; read_xml_file(file, "simple2d", cell); lattice::graph lat(bs, cell, lattice::extent(4, 4)); ```
-
-
fully connected lattice of 10 sites
lattice::graph lat = lattice::graph::fully_connected(10);
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lattice_graph_core-0.1.0.tar.gz.
File metadata
- Download URL: lattice_graph_core-0.1.0.tar.gz
- Upload date:
- Size: 27.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1e14efe9390bb560abc8aacb97e8dc50e70ad4237aaaaf9b8b0a0a1bafd2c1c2
|
|
| MD5 |
e64c30319666ae6491858d59f52a95bf
|
|
| BLAKE2b-256 |
8a65ad4c667d7a6e1cfdf180f3a1d25ec7967e8f2a0b587f1bf3a5e5d8298c5b
|
Provenance
The following attestation bundles were made for lattice_graph_core-0.1.0.tar.gz:
Publisher:
python-publish.yml on todo-group/lattice
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lattice_graph_core-0.1.0.tar.gz -
Subject digest:
1e14efe9390bb560abc8aacb97e8dc50e70ad4237aaaaf9b8b0a0a1bafd2c1c2 - Sigstore transparency entry: 1629350621
- Sigstore integration time:
-
Permalink:
todo-group/lattice@f0cf6f8045aba16946e7eb8851c9572365a3d352 -
Branch / Tag:
refs/tags/0.2 - Owner: https://github.com/todo-group
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@f0cf6f8045aba16946e7eb8851c9572365a3d352 -
Trigger Event:
release
-
Statement type:
File details
Details for the file lattice_graph_core-0.1.0-cp311-cp311-win_amd64.whl.
File metadata
- Download URL: lattice_graph_core-0.1.0-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 290.1 kB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d2ce193f72021b4a61610d68dc0173b757f56e2713387e791ebd64e7d565995f
|
|
| MD5 |
d48bc3651a60c23fc90e378d5cad40c1
|
|
| BLAKE2b-256 |
baa17c133601c4cb1d44d2341164c3c72384a14b26b4dadbe02e909ccb90b874
|
Provenance
The following attestation bundles were made for lattice_graph_core-0.1.0-cp311-cp311-win_amd64.whl:
Publisher:
python-publish.yml on todo-group/lattice
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lattice_graph_core-0.1.0-cp311-cp311-win_amd64.whl -
Subject digest:
d2ce193f72021b4a61610d68dc0173b757f56e2713387e791ebd64e7d565995f - Sigstore transparency entry: 1629350669
- Sigstore integration time:
-
Permalink:
todo-group/lattice@f0cf6f8045aba16946e7eb8851c9572365a3d352 -
Branch / Tag:
refs/tags/0.2 - Owner: https://github.com/todo-group
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@f0cf6f8045aba16946e7eb8851c9572365a3d352 -
Trigger Event:
release
-
Statement type:
File details
Details for the file lattice_graph_core-0.1.0-cp311-cp311-macosx_11_0_arm64.whl.
File metadata
- Download URL: lattice_graph_core-0.1.0-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 394.4 kB
- Tags: CPython 3.11, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
103f8af7f5c776d0f2c9f55803348e07637abfa0d798fa62a7ef3be43e0d245f
|
|
| MD5 |
6b368848ca579e65d4685816a53f320e
|
|
| BLAKE2b-256 |
0a43c73924829dec3bdd97b8e7a21abdc514facd4d792ebcdf9d58533b6488ff
|
Provenance
The following attestation bundles were made for lattice_graph_core-0.1.0-cp311-cp311-macosx_11_0_arm64.whl:
Publisher:
python-publish.yml on todo-group/lattice
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lattice_graph_core-0.1.0-cp311-cp311-macosx_11_0_arm64.whl -
Subject digest:
103f8af7f5c776d0f2c9f55803348e07637abfa0d798fa62a7ef3be43e0d245f - Sigstore transparency entry: 1629350657
- Sigstore integration time:
-
Permalink:
todo-group/lattice@f0cf6f8045aba16946e7eb8851c9572365a3d352 -
Branch / Tag:
refs/tags/0.2 - Owner: https://github.com/todo-group
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@f0cf6f8045aba16946e7eb8851c9572365a3d352 -
Trigger Event:
release
-
Statement type:
File details
Details for the file lattice_graph_core-0.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: lattice_graph_core-0.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 437.7 kB
- Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
835093ea15b1463397d834ed585b1e46a75daddfc00a2e9716422046635c356b
|
|
| MD5 |
8efeb07d01aae791ecf5f26ef1c59e52
|
|
| BLAKE2b-256 |
020ad0197a8cba42ffc3596ff3dc553dbfdcfb939357c9abe8de10c866234ae6
|
Provenance
The following attestation bundles were made for lattice_graph_core-0.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
python-publish.yml on todo-group/lattice
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lattice_graph_core-0.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
835093ea15b1463397d834ed585b1e46a75daddfc00a2e9716422046635c356b - Sigstore transparency entry: 1629350646
- Sigstore integration time:
-
Permalink:
todo-group/lattice@f0cf6f8045aba16946e7eb8851c9572365a3d352 -
Branch / Tag:
refs/tags/0.2 - Owner: https://github.com/todo-group
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@f0cf6f8045aba16946e7eb8851c9572365a3d352 -
Trigger Event:
release
-
Statement type: