graphot 0.0.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- graphot-0.0.2/.github/workflows/publish.yml +207 -0
- graphot-0.0.2/.gitignore +41 -0
- graphot-0.0.2/CMakeLists.txt +65 -0
- graphot-0.0.2/LICENSE +21 -0
- graphot-0.0.2/PKG-INFO +134 -0
- graphot-0.0.2/README.md +108 -0
- graphot-0.0.2/conanfile.py +19 -0
- graphot-0.0.2/cpp/graphot_core.cpp +1807 -0
- graphot-0.0.2/docs/api-reference.md +166 -0
- graphot-0.0.2/docs/debugging-and-diagnostics.md +93 -0
- graphot-0.0.2/docs/examples-guide.md +100 -0
- graphot-0.0.2/docs/getting-started.md +117 -0
- graphot-0.0.2/docs/graph-model.md +96 -0
- graphot-0.0.2/docs/index.md +26 -0
- graphot-0.0.2/docs/numerical-limitations.md +55 -0
- graphot-0.0.2/docs/solver-overview.md +73 -0
- graphot-0.0.2/examples/README.md +42 -0
- graphot-0.0.2/examples/_common.py +448 -0
- graphot-0.0.2/examples/cycle_neighbor_transport/run.py +98 -0
- graphot-0.0.2/examples/directed_reversible_transport/run.py +91 -0
- graphot-0.0.2/examples/large_grid_transport/run.py +209 -0
- graphot-0.0.2/examples/line_chain_transport/run.py +99 -0
- graphot-0.0.2/examples/two_node_benchmark/run.py +90 -0
- graphot-0.0.2/pyproject.toml +100 -0
- graphot-0.0.2/src/graphot/__init__.py +26 -0
- graphot-0.0.2/src/graphot/graph.py +362 -0
- graphot-0.0.2/src/graphot/means.py +295 -0
- graphot-0.0.2/src/graphot/solver.py +232 -0
- graphot-0.0.2/src/graphot/types.py +258 -0
- graphot-0.0.2/tests/smoke_solve.py +23 -0
- graphot-0.0.2/tests/test_examples_helpers.py +84 -0
- graphot-0.0.2/tests/test_graph.py +267 -0
- graphot-0.0.2/tests/test_graphot_import.py +9 -0
- graphot-0.0.2/tests/test_means.py +72 -0
- graphot-0.0.2/tests/test_solver.py +343 -0
- graphot-0.0.2/uv.lock +1494 -0
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- "v*"
|
|
7
|
+
workflow_dispatch:
|
|
8
|
+
inputs:
|
|
9
|
+
target:
|
|
10
|
+
description: "Package index to publish to"
|
|
11
|
+
required: true
|
|
12
|
+
default: testpypi
|
|
13
|
+
type: choice
|
|
14
|
+
options:
|
|
15
|
+
- testpypi
|
|
16
|
+
- pypi
|
|
17
|
+
skip_tests:
|
|
18
|
+
description: "Skip pytest in validate job (manual runs only)"
|
|
19
|
+
required: false
|
|
20
|
+
default: false
|
|
21
|
+
type: boolean
|
|
22
|
+
|
|
23
|
+
permissions:
|
|
24
|
+
contents: read
|
|
25
|
+
|
|
26
|
+
concurrency:
|
|
27
|
+
group: ${{ github.workflow }}-${{ github.ref }}
|
|
28
|
+
cancel-in-progress: true
|
|
29
|
+
|
|
30
|
+
jobs:
|
|
31
|
+
validate:
|
|
32
|
+
runs-on: ubuntu-latest
|
|
33
|
+
strategy:
|
|
34
|
+
fail-fast: false
|
|
35
|
+
matrix:
|
|
36
|
+
python-version: ["3.11", "3.12", "3.13"]
|
|
37
|
+
steps:
|
|
38
|
+
- name: Check out repository
|
|
39
|
+
uses: actions/checkout@v4
|
|
40
|
+
|
|
41
|
+
- name: Set up Python
|
|
42
|
+
uses: actions/setup-python@v5
|
|
43
|
+
with:
|
|
44
|
+
python-version: ${{ matrix.python-version }}
|
|
45
|
+
|
|
46
|
+
- name: Set up uv
|
|
47
|
+
uses: astral-sh/setup-uv@v5
|
|
48
|
+
with:
|
|
49
|
+
enable-cache: true
|
|
50
|
+
|
|
51
|
+
- name: Install dependencies
|
|
52
|
+
run: uv sync --group dev
|
|
53
|
+
|
|
54
|
+
- name: Lint
|
|
55
|
+
if: ${{ matrix.python-version == '3.13' }}
|
|
56
|
+
run: uv run ruff check .
|
|
57
|
+
|
|
58
|
+
- name: Test
|
|
59
|
+
if: ${{ github.event_name != 'workflow_dispatch' || inputs.skip_tests != true }}
|
|
60
|
+
run: uv run pytest -q
|
|
61
|
+
|
|
62
|
+
build_wheels:
|
|
63
|
+
needs: validate
|
|
64
|
+
runs-on: ${{ matrix.os }}
|
|
65
|
+
strategy:
|
|
66
|
+
fail-fast: false
|
|
67
|
+
matrix:
|
|
68
|
+
include:
|
|
69
|
+
- os: ubuntu-latest
|
|
70
|
+
artifact_name: wheels-linux
|
|
71
|
+
cibw_archs_linux: x86_64
|
|
72
|
+
cibw_archs_windows: auto
|
|
73
|
+
cibw_archs_macos: auto
|
|
74
|
+
- os: windows-latest
|
|
75
|
+
artifact_name: wheels-windows
|
|
76
|
+
cibw_archs_linux: auto
|
|
77
|
+
cibw_archs_windows: AMD64
|
|
78
|
+
cibw_archs_macos: auto
|
|
79
|
+
- os: macos-14
|
|
80
|
+
artifact_name: wheels-macos-arm64
|
|
81
|
+
cibw_archs_linux: auto
|
|
82
|
+
cibw_archs_windows: auto
|
|
83
|
+
cibw_archs_macos: arm64
|
|
84
|
+
steps:
|
|
85
|
+
- name: Check out repository
|
|
86
|
+
uses: actions/checkout@v4
|
|
87
|
+
|
|
88
|
+
- name: Set up Python
|
|
89
|
+
uses: actions/setup-python@v5
|
|
90
|
+
with:
|
|
91
|
+
python-version: "3.13"
|
|
92
|
+
|
|
93
|
+
- name: Set up uv
|
|
94
|
+
uses: astral-sh/setup-uv@v5
|
|
95
|
+
with:
|
|
96
|
+
enable-cache: true
|
|
97
|
+
|
|
98
|
+
- name: Verify tag matches package version
|
|
99
|
+
if: github.event_name == 'push'
|
|
100
|
+
shell: bash
|
|
101
|
+
run: |
|
|
102
|
+
python - <<'PY'
|
|
103
|
+
import tomllib
|
|
104
|
+
from pathlib import Path
|
|
105
|
+
|
|
106
|
+
tag = "${{ github.ref_name }}"
|
|
107
|
+
version = tomllib.loads(Path("pyproject.toml").read_text())["project"]["version"]
|
|
108
|
+
expected = f"v{version}"
|
|
109
|
+
if tag != expected:
|
|
110
|
+
raise SystemExit(
|
|
111
|
+
f"Tag/version mismatch: pushed tag {tag!r} does not match pyproject version {version!r}."
|
|
112
|
+
)
|
|
113
|
+
print(f"Tag/version check passed: {tag}")
|
|
114
|
+
PY
|
|
115
|
+
|
|
116
|
+
- name: Build wheels
|
|
117
|
+
uses: pypa/cibuildwheel@v2.21.3
|
|
118
|
+
env:
|
|
119
|
+
CIBW_BUILD_FRONTEND: "build[uv]"
|
|
120
|
+
CIBW_BUILD: "cp311-* cp312-* cp313-*"
|
|
121
|
+
CIBW_SKIP: "pp* *-musllinux*"
|
|
122
|
+
CIBW_MANYLINUX_X86_64_IMAGE: "manylinux_2_28"
|
|
123
|
+
CIBW_ARCHS_LINUX: ${{ matrix.cibw_archs_linux }}
|
|
124
|
+
CIBW_ARCHS_WINDOWS: ${{ matrix.cibw_archs_windows }}
|
|
125
|
+
CIBW_ARCHS_MACOS: ${{ matrix.cibw_archs_macos }}
|
|
126
|
+
CIBW_BUILD_VERBOSITY: "1"
|
|
127
|
+
CIBW_TEST_COMMAND: "python {project}/tests/smoke_solve.py"
|
|
128
|
+
|
|
129
|
+
- name: Validate wheel metadata
|
|
130
|
+
run: |
|
|
131
|
+
python -m pip install --upgrade pip twine
|
|
132
|
+
python -m twine check wheelhouse/*.whl
|
|
133
|
+
|
|
134
|
+
- name: Upload wheel artifacts
|
|
135
|
+
uses: actions/upload-artifact@v4
|
|
136
|
+
with:
|
|
137
|
+
name: ${{ matrix.artifact_name }}
|
|
138
|
+
path: wheelhouse/*.whl
|
|
139
|
+
if-no-files-found: error
|
|
140
|
+
|
|
141
|
+
build_sdist:
|
|
142
|
+
runs-on: ubuntu-latest
|
|
143
|
+
needs: validate
|
|
144
|
+
steps:
|
|
145
|
+
- name: Check out repository
|
|
146
|
+
uses: actions/checkout@v4
|
|
147
|
+
|
|
148
|
+
- name: Set up Python
|
|
149
|
+
uses: actions/setup-python@v5
|
|
150
|
+
with:
|
|
151
|
+
python-version: "3.13"
|
|
152
|
+
|
|
153
|
+
- name: Set up uv
|
|
154
|
+
uses: astral-sh/setup-uv@v5
|
|
155
|
+
with:
|
|
156
|
+
enable-cache: true
|
|
157
|
+
|
|
158
|
+
- name: Install dependencies
|
|
159
|
+
run: uv sync --group dev
|
|
160
|
+
|
|
161
|
+
- name: Build source distribution
|
|
162
|
+
run: uv build --sdist
|
|
163
|
+
|
|
164
|
+
- name: Validate source distribution
|
|
165
|
+
run: uv run python -m twine check dist/*.tar.gz
|
|
166
|
+
|
|
167
|
+
- name: Upload source distribution
|
|
168
|
+
uses: actions/upload-artifact@v4
|
|
169
|
+
with:
|
|
170
|
+
name: sdist
|
|
171
|
+
path: dist/*.tar.gz
|
|
172
|
+
if-no-files-found: error
|
|
173
|
+
|
|
174
|
+
publish:
|
|
175
|
+
runs-on: ubuntu-latest
|
|
176
|
+
needs:
|
|
177
|
+
- build_wheels
|
|
178
|
+
- build_sdist
|
|
179
|
+
permissions:
|
|
180
|
+
contents: read
|
|
181
|
+
id-token: write
|
|
182
|
+
steps:
|
|
183
|
+
- name: Download release artifacts
|
|
184
|
+
uses: actions/download-artifact@v4
|
|
185
|
+
with:
|
|
186
|
+
pattern: "*"
|
|
187
|
+
path: dist
|
|
188
|
+
merge-multiple: true
|
|
189
|
+
|
|
190
|
+
- name: Publish to TestPyPI
|
|
191
|
+
if: github.event_name == 'workflow_dispatch' && inputs.target == 'testpypi'
|
|
192
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
193
|
+
with:
|
|
194
|
+
repository-url: https://test.pypi.org/legacy/
|
|
195
|
+
packages-dir: dist
|
|
196
|
+
|
|
197
|
+
- name: Publish to PyPI (manual)
|
|
198
|
+
if: github.event_name == 'workflow_dispatch' && inputs.target == 'pypi'
|
|
199
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
200
|
+
with:
|
|
201
|
+
packages-dir: dist
|
|
202
|
+
|
|
203
|
+
- name: Publish to PyPI (tag)
|
|
204
|
+
if: github.event_name == 'push'
|
|
205
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
206
|
+
with:
|
|
207
|
+
packages-dir: dist
|
graphot-0.0.2/.gitignore
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# macOS
|
|
2
|
+
.DS_Store
|
|
3
|
+
|
|
4
|
+
# Python bytecode and caches
|
|
5
|
+
__pycache__/
|
|
6
|
+
*.py[cod]
|
|
7
|
+
|
|
8
|
+
# Test and lint caches
|
|
9
|
+
.pytest_cache/
|
|
10
|
+
.ruff_cache/
|
|
11
|
+
.mypy_cache/
|
|
12
|
+
|
|
13
|
+
# Virtual environments
|
|
14
|
+
.venv/
|
|
15
|
+
|
|
16
|
+
# Coverage artifacts
|
|
17
|
+
.coverage
|
|
18
|
+
.coverage.*
|
|
19
|
+
htmlcov/
|
|
20
|
+
|
|
21
|
+
# Build and packaging artifacts
|
|
22
|
+
build/
|
|
23
|
+
build-*/
|
|
24
|
+
dist/
|
|
25
|
+
*.egg-info/
|
|
26
|
+
.conan/
|
|
27
|
+
.conan2/
|
|
28
|
+
.cache/
|
|
29
|
+
src/graphot/_core*.so
|
|
30
|
+
src/graphot/_core*.pyd
|
|
31
|
+
|
|
32
|
+
# Notebook artifacts
|
|
33
|
+
.ipynb_checkpoints/
|
|
34
|
+
|
|
35
|
+
# Example-generated outputs
|
|
36
|
+
examples/output/
|
|
37
|
+
examples/*/output/
|
|
38
|
+
|
|
39
|
+
reference/
|
|
40
|
+
|
|
41
|
+
.vscode
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
cmake_minimum_required(VERSION 3.22)
|
|
2
|
+
|
|
3
|
+
project(graphot_core LANGUAGES CXX)
|
|
4
|
+
|
|
5
|
+
option(GRAPHOT_USE_CONAN "Install C++ dependencies via Conan during CMake configure" ON)
|
|
6
|
+
|
|
7
|
+
set(CMAKE_CXX_STANDARD 20)
|
|
8
|
+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
9
|
+
set(CMAKE_CXX_EXTENSIONS OFF)
|
|
10
|
+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
|
11
|
+
|
|
12
|
+
find_package(Python REQUIRED COMPONENTS Interpreter Development.Module)
|
|
13
|
+
|
|
14
|
+
if(GRAPHOT_USE_CONAN)
|
|
15
|
+
find_program(GRAPHOT_CONAN_EXECUTABLE conan)
|
|
16
|
+
if(NOT GRAPHOT_CONAN_EXECUTABLE)
|
|
17
|
+
message(FATAL_ERROR "GRAPHOT_USE_CONAN=ON but 'conan' was not found on PATH")
|
|
18
|
+
endif()
|
|
19
|
+
|
|
20
|
+
set(GRAPHOT_CONAN_HOME "${CMAKE_BINARY_DIR}/conan-home")
|
|
21
|
+
set(GRAPHOT_CONAN_OUTPUT "${CMAKE_BINARY_DIR}/conan")
|
|
22
|
+
set(GRAPHOT_BUILD_TYPE "${CMAKE_BUILD_TYPE}")
|
|
23
|
+
if(NOT GRAPHOT_BUILD_TYPE)
|
|
24
|
+
set(GRAPHOT_BUILD_TYPE "Release")
|
|
25
|
+
endif()
|
|
26
|
+
file(MAKE_DIRECTORY "${GRAPHOT_CONAN_HOME}")
|
|
27
|
+
file(MAKE_DIRECTORY "${GRAPHOT_CONAN_OUTPUT}")
|
|
28
|
+
|
|
29
|
+
if(NOT EXISTS "${GRAPHOT_CONAN_HOME}/profiles/default")
|
|
30
|
+
execute_process(
|
|
31
|
+
COMMAND "${CMAKE_COMMAND}" -E env "CONAN_HOME=${GRAPHOT_CONAN_HOME}" "${GRAPHOT_CONAN_EXECUTABLE}" profile detect --force
|
|
32
|
+
RESULT_VARIABLE graphot_conan_profile_result
|
|
33
|
+
COMMAND_ECHO STDOUT
|
|
34
|
+
)
|
|
35
|
+
if(NOT graphot_conan_profile_result EQUAL 0)
|
|
36
|
+
message(FATAL_ERROR "Conan profile detection failed with exit code ${graphot_conan_profile_result}")
|
|
37
|
+
endif()
|
|
38
|
+
endif()
|
|
39
|
+
|
|
40
|
+
if(NOT EXISTS "${GRAPHOT_CONAN_OUTPUT}/pybind11-config.cmake")
|
|
41
|
+
execute_process(
|
|
42
|
+
COMMAND "${CMAKE_COMMAND}" -E env "CONAN_HOME=${GRAPHOT_CONAN_HOME}" "${GRAPHOT_CONAN_EXECUTABLE}" install "${CMAKE_SOURCE_DIR}" -of "${GRAPHOT_CONAN_OUTPUT}" --build=missing -s "build_type=${GRAPHOT_BUILD_TYPE}"
|
|
43
|
+
RESULT_VARIABLE graphot_conan_result
|
|
44
|
+
COMMAND_ECHO STDOUT
|
|
45
|
+
)
|
|
46
|
+
if(NOT graphot_conan_result EQUAL 0)
|
|
47
|
+
message(FATAL_ERROR "Conan dependency resolution failed with exit code ${graphot_conan_result}")
|
|
48
|
+
endif()
|
|
49
|
+
endif()
|
|
50
|
+
|
|
51
|
+
list(PREPEND CMAKE_PREFIX_PATH "${GRAPHOT_CONAN_OUTPUT}")
|
|
52
|
+
endif()
|
|
53
|
+
|
|
54
|
+
find_package(pybind11 CONFIG REQUIRED)
|
|
55
|
+
|
|
56
|
+
pybind11_add_module(_core MODULE cpp/graphot_core.cpp)
|
|
57
|
+
target_compile_features(_core PRIVATE cxx_std_20)
|
|
58
|
+
target_compile_definitions(_core PRIVATE PYBIND11_DETAILED_ERROR_MESSAGES=1)
|
|
59
|
+
target_include_directories(_core PRIVATE "${CMAKE_SOURCE_DIR}/cpp")
|
|
60
|
+
|
|
61
|
+
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
|
|
62
|
+
target_compile_options(_core PRIVATE -O3 -Wall -Wextra -Wpedantic)
|
|
63
|
+
endif()
|
|
64
|
+
|
|
65
|
+
install(TARGETS _core LIBRARY DESTINATION graphot)
|
graphot-0.0.2/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 LvDAO
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
graphot-0.0.2/PKG-INFO
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: graphot
|
|
3
|
+
Version: 0.0.2
|
|
4
|
+
Summary: Graph optimal transport on sparse reversible graphs
|
|
5
|
+
Keywords: optimal transport,c++,numpy,scipy,graphs,wasserstein,numerical optimization
|
|
6
|
+
Author: LvDAO
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Intended Audience :: Science/Research
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
15
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
16
|
+
Project-URL: Homepage, https://github.com/LvDAO/Graph-Optimal-Transport
|
|
17
|
+
Project-URL: Repository, https://github.com/LvDAO/Graph-Optimal-Transport
|
|
18
|
+
Project-URL: Issues, https://github.com/LvDAO/Graph-Optimal-Transport/issues
|
|
19
|
+
Project-URL: Documentation, https://github.com/LvDAO/Graph-Optimal-Transport/tree/main/docs
|
|
20
|
+
Requires-Python: >=3.11
|
|
21
|
+
Requires-Dist: numpy>=2.1
|
|
22
|
+
Requires-Dist: scipy>=1.14
|
|
23
|
+
Provides-Extra: examples
|
|
24
|
+
Requires-Dist: matplotlib>=3.10; extra == "examples"
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
|
|
27
|
+
# graphot
|
|
28
|
+
|
|
29
|
+
`graphot` solves dynamic optimal transport on sparse reversible graphs.
|
|
30
|
+
|
|
31
|
+
Use it when you want:
|
|
32
|
+
- a transport path between two endpoint distributions on a graph,
|
|
33
|
+
- node densities over time,
|
|
34
|
+
- edge fluxes over time,
|
|
35
|
+
- a solver that runs from Python and returns NumPy arrays.
|
|
36
|
+
|
|
37
|
+
## Install
|
|
38
|
+
|
|
39
|
+
Install from PyPI:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pip install graphot
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
If you want to run the plotting examples:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
pip install "graphot[examples]"
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
If you are working from a local checkout instead, run `pip install .` or
|
|
52
|
+
`pip install ".[examples]"` from the repository root.
|
|
53
|
+
|
|
54
|
+
These docs use the public import path `graphot`:
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
from graphot import solve_ot
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Quick Start
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
import numpy as np
|
|
64
|
+
|
|
65
|
+
from graphot import (
|
|
66
|
+
GraphSpec,
|
|
67
|
+
LogMeanOps,
|
|
68
|
+
OTConfig,
|
|
69
|
+
OTProblem,
|
|
70
|
+
TimeDiscretization,
|
|
71
|
+
solve_ot,
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
graph = GraphSpec.from_undirected_weights(
|
|
75
|
+
num_nodes=2,
|
|
76
|
+
edge_u=[0],
|
|
77
|
+
edge_v=[1],
|
|
78
|
+
weight=[1.0],
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
mass_a = np.array([1.0, 0.0], dtype=np.float64)
|
|
82
|
+
mass_b = np.array([0.0, 1.0], dtype=np.float64)
|
|
83
|
+
|
|
84
|
+
rho_a = mass_a / graph.pi
|
|
85
|
+
rho_b = mass_b / graph.pi
|
|
86
|
+
|
|
87
|
+
problem = OTProblem(
|
|
88
|
+
graph=graph,
|
|
89
|
+
time=TimeDiscretization(num_steps=64),
|
|
90
|
+
rho_a=rho_a,
|
|
91
|
+
rho_b=rho_b,
|
|
92
|
+
mean_ops=LogMeanOps(),
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
solution = solve_ot(problem, OTConfig())
|
|
96
|
+
|
|
97
|
+
print("distance:", float(solution.distance))
|
|
98
|
+
print("converged:", solution.converged)
|
|
99
|
+
print("iterations:", solution.iterations_used)
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Three Things To Remember
|
|
103
|
+
|
|
104
|
+
- `graphot` expects endpoint densities with respect to `graph.pi`, not raw masses.
|
|
105
|
+
- Convert ordinary masses with `rho = mass / graph.pi`.
|
|
106
|
+
- Check `solution.converged` on harder problems before treating the result as final.
|
|
107
|
+
|
|
108
|
+
## What You Get Back
|
|
109
|
+
|
|
110
|
+
The most useful outputs are:
|
|
111
|
+
- `solution.distance`
|
|
112
|
+
- `solution.state.rho`
|
|
113
|
+
- `solution.state.m`
|
|
114
|
+
- `solution.diagnostics`
|
|
115
|
+
|
|
116
|
+
## Start Here
|
|
117
|
+
|
|
118
|
+
- [Getting Started](docs/getting-started.md)
|
|
119
|
+
- [Graph Model](docs/graph-model.md)
|
|
120
|
+
- [API Reference](docs/api-reference.md)
|
|
121
|
+
- [Examples Guide](docs/examples-guide.md)
|
|
122
|
+
- [Debugging and Diagnostics](docs/debugging-and-diagnostics.md)
|
|
123
|
+
- [Numerical Limitations](docs/numerical-limitations.md)
|
|
124
|
+
|
|
125
|
+
## Examples
|
|
126
|
+
|
|
127
|
+
The repository includes ready-to-run scripts for:
|
|
128
|
+
- two-node transport,
|
|
129
|
+
- cycle transport,
|
|
130
|
+
- line transport,
|
|
131
|
+
- directed reversible transport,
|
|
132
|
+
- large-grid transport.
|
|
133
|
+
|
|
134
|
+
See [examples/README.md](examples/README.md) for the example index.
|
graphot-0.0.2/README.md
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# graphot
|
|
2
|
+
|
|
3
|
+
`graphot` solves dynamic optimal transport on sparse reversible graphs.
|
|
4
|
+
|
|
5
|
+
Use it when you want:
|
|
6
|
+
- a transport path between two endpoint distributions on a graph,
|
|
7
|
+
- node densities over time,
|
|
8
|
+
- edge fluxes over time,
|
|
9
|
+
- a solver that runs from Python and returns NumPy arrays.
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
Install from PyPI:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pip install graphot
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
If you want to run the plotting examples:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pip install "graphot[examples]"
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
If you are working from a local checkout instead, run `pip install .` or
|
|
26
|
+
`pip install ".[examples]"` from the repository root.
|
|
27
|
+
|
|
28
|
+
These docs use the public import path `graphot`:
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
from graphot import solve_ot
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Quick Start
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
import numpy as np
|
|
38
|
+
|
|
39
|
+
from graphot import (
|
|
40
|
+
GraphSpec,
|
|
41
|
+
LogMeanOps,
|
|
42
|
+
OTConfig,
|
|
43
|
+
OTProblem,
|
|
44
|
+
TimeDiscretization,
|
|
45
|
+
solve_ot,
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
graph = GraphSpec.from_undirected_weights(
|
|
49
|
+
num_nodes=2,
|
|
50
|
+
edge_u=[0],
|
|
51
|
+
edge_v=[1],
|
|
52
|
+
weight=[1.0],
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
mass_a = np.array([1.0, 0.0], dtype=np.float64)
|
|
56
|
+
mass_b = np.array([0.0, 1.0], dtype=np.float64)
|
|
57
|
+
|
|
58
|
+
rho_a = mass_a / graph.pi
|
|
59
|
+
rho_b = mass_b / graph.pi
|
|
60
|
+
|
|
61
|
+
problem = OTProblem(
|
|
62
|
+
graph=graph,
|
|
63
|
+
time=TimeDiscretization(num_steps=64),
|
|
64
|
+
rho_a=rho_a,
|
|
65
|
+
rho_b=rho_b,
|
|
66
|
+
mean_ops=LogMeanOps(),
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
solution = solve_ot(problem, OTConfig())
|
|
70
|
+
|
|
71
|
+
print("distance:", float(solution.distance))
|
|
72
|
+
print("converged:", solution.converged)
|
|
73
|
+
print("iterations:", solution.iterations_used)
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Three Things To Remember
|
|
77
|
+
|
|
78
|
+
- `graphot` expects endpoint densities with respect to `graph.pi`, not raw masses.
|
|
79
|
+
- Convert ordinary masses with `rho = mass / graph.pi`.
|
|
80
|
+
- Check `solution.converged` on harder problems before treating the result as final.
|
|
81
|
+
|
|
82
|
+
## What You Get Back
|
|
83
|
+
|
|
84
|
+
The most useful outputs are:
|
|
85
|
+
- `solution.distance`
|
|
86
|
+
- `solution.state.rho`
|
|
87
|
+
- `solution.state.m`
|
|
88
|
+
- `solution.diagnostics`
|
|
89
|
+
|
|
90
|
+
## Start Here
|
|
91
|
+
|
|
92
|
+
- [Getting Started](docs/getting-started.md)
|
|
93
|
+
- [Graph Model](docs/graph-model.md)
|
|
94
|
+
- [API Reference](docs/api-reference.md)
|
|
95
|
+
- [Examples Guide](docs/examples-guide.md)
|
|
96
|
+
- [Debugging and Diagnostics](docs/debugging-and-diagnostics.md)
|
|
97
|
+
- [Numerical Limitations](docs/numerical-limitations.md)
|
|
98
|
+
|
|
99
|
+
## Examples
|
|
100
|
+
|
|
101
|
+
The repository includes ready-to-run scripts for:
|
|
102
|
+
- two-node transport,
|
|
103
|
+
- cycle transport,
|
|
104
|
+
- line transport,
|
|
105
|
+
- directed reversible transport,
|
|
106
|
+
- large-grid transport.
|
|
107
|
+
|
|
108
|
+
See [examples/README.md](examples/README.md) for the example index.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from conan import ConanFile
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class GraphOTConan(ConanFile):
|
|
7
|
+
name = "graphot-core"
|
|
8
|
+
version = "0.0.2"
|
|
9
|
+
package_type = "application"
|
|
10
|
+
|
|
11
|
+
settings = "os", "arch", "build_type"
|
|
12
|
+
generators = "CMakeDeps"
|
|
13
|
+
|
|
14
|
+
requires = (
|
|
15
|
+
"pybind11/2.13.6",
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
def configure(self) -> None:
|
|
19
|
+
self.options["pybind11/*"].shared = False
|