micropurc 0.1.0__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.
Files changed (185) hide show
  1. micropurc-0.1.0/.clang-format +7 -0
  2. micropurc-0.1.0/.editorconfig +24 -0
  3. micropurc-0.1.0/.gitignore +63 -0
  4. micropurc-0.1.0/.pre-commit-config.yaml +51 -0
  5. micropurc-0.1.0/CHANGELOG.md +24 -0
  6. micropurc-0.1.0/CITATION.cff +40 -0
  7. micropurc-0.1.0/CMakeLists.txt +165 -0
  8. micropurc-0.1.0/LICENSE +21 -0
  9. micropurc-0.1.0/LICENSES/EIGEN_LICENSE.txt +378 -0
  10. micropurc-0.1.0/LICENSES/LDL_LICENSE.txt +21 -0
  11. micropurc-0.1.0/LICENSES/NANOBIND_LICENSE.txt +31 -0
  12. micropurc-0.1.0/LICENSES/PIQP_LICENSE.txt +29 -0
  13. micropurc-0.1.0/LICENSES/ROBIN_MAP_LICENSE.txt +26 -0
  14. micropurc-0.1.0/Makefile +39 -0
  15. micropurc-0.1.0/PKG-INFO +128 -0
  16. micropurc-0.1.0/README.md +84 -0
  17. micropurc-0.1.0/docs/Makefile +17 -0
  18. micropurc-0.1.0/docs/_static/custom.css +13 -0
  19. micropurc-0.1.0/docs/api/config.rst +5 -0
  20. micropurc-0.1.0/docs/api/core.rst +38 -0
  21. micropurc-0.1.0/docs/api/demands.rst +5 -0
  22. micropurc-0.1.0/docs/api/forward.rst +14 -0
  23. micropurc-0.1.0/docs/api/index.rst +14 -0
  24. micropurc-0.1.0/docs/api/network.rst +5 -0
  25. micropurc-0.1.0/docs/api/reporting.rst +20 -0
  26. micropurc-0.1.0/docs/api/simulation.rst +14 -0
  27. micropurc-0.1.0/docs/api/spec.rst +23 -0
  28. micropurc-0.1.0/docs/conf.py +75 -0
  29. micropurc-0.1.0/docs/examples/data/siouxfalls_net.csv +77 -0
  30. micropurc-0.1.0/docs/examples/data/siouxfalls_trips.csv +529 -0
  31. micropurc-0.1.0/docs/examples/index.rst +14 -0
  32. micropurc-0.1.0/docs/examples/model_spec.rst +78 -0
  33. micropurc-0.1.0/docs/examples/pipeline.py +138 -0
  34. micropurc-0.1.0/docs/examples/pipeline.rst +187 -0
  35. micropurc-0.1.0/docs/examples/reporting.rst +91 -0
  36. micropurc-0.1.0/docs/examples/simulation.rst +39 -0
  37. micropurc-0.1.0/docs/getting_started.rst +75 -0
  38. micropurc-0.1.0/docs/index.rst +37 -0
  39. micropurc-0.1.0/docs/requirements.txt +11 -0
  40. micropurc-0.1.0/extern/piqp/piqp/common.hpp +63 -0
  41. micropurc-0.1.0/extern/piqp/piqp/dense/data.hpp +95 -0
  42. micropurc-0.1.0/extern/piqp/piqp/dense/data.tpp +200 -0
  43. micropurc-0.1.0/extern/piqp/piqp/dense/kkt.hpp +91 -0
  44. micropurc-0.1.0/extern/piqp/piqp/dense/kkt.tpp +166 -0
  45. micropurc-0.1.0/extern/piqp/piqp/dense/ldlt_no_pivot.hpp +498 -0
  46. micropurc-0.1.0/extern/piqp/piqp/dense/model.hpp +79 -0
  47. micropurc-0.1.0/extern/piqp/piqp/dense/preconditioner.hpp +319 -0
  48. micropurc-0.1.0/extern/piqp/piqp/dense/preconditioner.tpp +276 -0
  49. micropurc-0.1.0/extern/piqp/piqp/fwd.hpp +68 -0
  50. micropurc-0.1.0/extern/piqp/piqp/kkt_fwd.hpp +41 -0
  51. micropurc-0.1.0/extern/piqp/piqp/kkt_solver_base.hpp +48 -0
  52. micropurc-0.1.0/extern/piqp/piqp/kkt_system.hpp +124 -0
  53. micropurc-0.1.0/extern/piqp/piqp/kkt_system.tpp +539 -0
  54. micropurc-0.1.0/extern/piqp/piqp/piqp.hpp +15 -0
  55. micropurc-0.1.0/extern/piqp/piqp/results.hpp +100 -0
  56. micropurc-0.1.0/extern/piqp/piqp/settings.hpp +129 -0
  57. micropurc-0.1.0/extern/piqp/piqp/solver.hpp +242 -0
  58. micropurc-0.1.0/extern/piqp/piqp/solver.tpp +1696 -0
  59. micropurc-0.1.0/extern/piqp/piqp/sparse/LDL_License.txt +21 -0
  60. micropurc-0.1.0/extern/piqp/piqp/sparse/blocksparse/block_info.hpp +29 -0
  61. micropurc-0.1.0/extern/piqp/piqp/sparse/blocksparse/block_kkt.hpp +133 -0
  62. micropurc-0.1.0/extern/piqp/piqp/sparse/blocksparse/block_mat.hpp +149 -0
  63. micropurc-0.1.0/extern/piqp/piqp/sparse/blocksparse/block_vec.hpp +159 -0
  64. micropurc-0.1.0/extern/piqp/piqp/sparse/data.hpp +98 -0
  65. micropurc-0.1.0/extern/piqp/piqp/sparse/data.tpp +201 -0
  66. micropurc-0.1.0/extern/piqp/piqp/sparse/kkt.hpp +106 -0
  67. micropurc-0.1.0/extern/piqp/piqp/sparse/kkt.tpp +223 -0
  68. micropurc-0.1.0/extern/piqp/piqp/sparse/kkt_all_eliminated.hpp +230 -0
  69. micropurc-0.1.0/extern/piqp/piqp/sparse/kkt_eq_eliminated.hpp +252 -0
  70. micropurc-0.1.0/extern/piqp/piqp/sparse/kkt_full.hpp +258 -0
  71. micropurc-0.1.0/extern/piqp/piqp/sparse/kkt_ineq_eliminated.hpp +253 -0
  72. micropurc-0.1.0/extern/piqp/piqp/sparse/ldlt.hpp +77 -0
  73. micropurc-0.1.0/extern/piqp/piqp/sparse/ldlt.tpp +209 -0
  74. micropurc-0.1.0/extern/piqp/piqp/sparse/model.hpp +86 -0
  75. micropurc-0.1.0/extern/piqp/piqp/sparse/multistage_kkt.hpp +193 -0
  76. micropurc-0.1.0/extern/piqp/piqp/sparse/multistage_kkt.tpp +1815 -0
  77. micropurc-0.1.0/extern/piqp/piqp/sparse/ordering.hpp +131 -0
  78. micropurc-0.1.0/extern/piqp/piqp/sparse/preconditioner.hpp +319 -0
  79. micropurc-0.1.0/extern/piqp/piqp/sparse/preconditioner.tpp +298 -0
  80. micropurc-0.1.0/extern/piqp/piqp/sparse/utils.hpp +205 -0
  81. micropurc-0.1.0/extern/piqp/piqp/timer.hpp +39 -0
  82. micropurc-0.1.0/extern/piqp/piqp/typedefs.hpp +97 -0
  83. micropurc-0.1.0/extern/piqp/piqp/utils/blasfeo_mat.hpp +126 -0
  84. micropurc-0.1.0/extern/piqp/piqp/utils/blasfeo_vec.hpp +125 -0
  85. micropurc-0.1.0/extern/piqp/piqp/utils/blasfeo_wrapper.hpp +124 -0
  86. micropurc-0.1.0/extern/piqp/piqp/utils/eigen_matio.hpp +497 -0
  87. micropurc-0.1.0/extern/piqp/piqp/utils/filesystem.hpp +32 -0
  88. micropurc-0.1.0/extern/piqp/piqp/utils/ghc_filesystem.hpp +6083 -0
  89. micropurc-0.1.0/extern/piqp/piqp/utils/io_utils.hpp +98 -0
  90. micropurc-0.1.0/extern/piqp/piqp/utils/optional.hpp +52 -0
  91. micropurc-0.1.0/extern/piqp/piqp/utils/random_utils.hpp +292 -0
  92. micropurc-0.1.0/extern/piqp/piqp/utils/smoothing.hpp +37 -0
  93. micropurc-0.1.0/extern/piqp/piqp/utils/tl_optional.hpp +2062 -0
  94. micropurc-0.1.0/extern/piqp/piqp/utils/tracy.hpp +27 -0
  95. micropurc-0.1.0/extern/piqp/piqp/variables.hpp +115 -0
  96. micropurc-0.1.0/pyproject.toml +176 -0
  97. micropurc-0.1.0/scripts/__init__.py +0 -0
  98. micropurc-0.1.0/scripts/check_build_artifacts.py +61 -0
  99. micropurc-0.1.0/scripts/ci/upstream_python_support.py +84 -0
  100. micropurc-0.1.0/scripts/dev_setup.sh +31 -0
  101. micropurc-0.1.0/scripts/paper/__init__.py +12 -0
  102. micropurc-0.1.0/scripts/paper/common.py +66 -0
  103. micropurc-0.1.0/scripts/paper/nb01/__init__.py +0 -0
  104. micropurc-0.1.0/scripts/paper/nb01/s1_recovery.py +109 -0
  105. micropurc-0.1.0/scripts/paper/nb01/s2_initball.py +63 -0
  106. micropurc-0.1.0/scripts/paper/nb01/s3_margin.py +96 -0
  107. micropurc-0.1.0/scripts/paper/nb01/s4_switching.py +113 -0
  108. micropurc-0.1.0/scripts/paper/nb01/s5_nonconv.py +94 -0
  109. micropurc-0.1.0/scripts/paper/nb01/setup.py +156 -0
  110. micropurc-0.1.0/scripts/paper/nb02/__init__.py +0 -0
  111. micropurc-0.1.0/scripts/paper/nb02/s1_sweep_N.py +71 -0
  112. micropurc-0.1.0/scripts/paper/nb02/s2_sweep_L.py +118 -0
  113. micropurc-0.1.0/scripts/paper/nb02/s3_sweep_K.py +56 -0
  114. micropurc-0.1.0/scripts/paper/nb02/s4_cores.py +83 -0
  115. micropurc-0.1.0/scripts/paper/nb02/s5_figure.py +128 -0
  116. micropurc-0.1.0/scripts/paper/nb02/s7_paper_panels.py +67 -0
  117. micropurc-0.1.0/scripts/paper/nb02/setup.py +271 -0
  118. micropurc-0.1.0/scripts/paper/nb03/__init__.py +0 -0
  119. micropurc-0.1.0/scripts/paper/nb03/s1_finite_sample.py +93 -0
  120. micropurc-0.1.0/scripts/paper/nb03/s2_init_robust.py +134 -0
  121. micropurc-0.1.0/scripts/paper/nb03/s3_efficiency.py +51 -0
  122. micropurc-0.1.0/scripts/paper/nb03/s4_recovery_cdf.py +102 -0
  123. micropurc-0.1.0/scripts/paper/nb03/setup.py +337 -0
  124. micropurc-0.1.0/scripts/paper/nb04/__init__.py +0 -0
  125. micropurc-0.1.0/scripts/paper/nb04/s1_config_sweeps.py +68 -0
  126. micropurc-0.1.0/scripts/paper/nb04/s2_qp_tol.py +55 -0
  127. micropurc-0.1.0/scripts/paper/nb04/s3_hardstart.py +65 -0
  128. micropurc-0.1.0/scripts/paper/nb04/s4_figure.py +62 -0
  129. micropurc-0.1.0/scripts/paper/nb04/setup.py +178 -0
  130. micropurc-0.1.0/scripts/paper/nb06/__init__.py +0 -0
  131. micropurc-0.1.0/scripts/paper/nb06/s1_repeated_trips.py +163 -0
  132. micropurc-0.1.0/scripts/paper/nb06/setup.py +155 -0
  133. micropurc-0.1.0/scripts/paper/run_all.py +73 -0
  134. micropurc-0.1.0/src/micropurc/__init__.py +157 -0
  135. micropurc-0.1.0/src/micropurc/_native/activeset.cpp +252 -0
  136. micropurc-0.1.0/src/micropurc/_native/activeset.hpp +29 -0
  137. micropurc-0.1.0/src/micropurc/_native/bindings.cpp +2215 -0
  138. micropurc-0.1.0/src/micropurc/_native/common.hpp +171 -0
  139. micropurc-0.1.0/src/micropurc/_native/route_sampler.cpp +172 -0
  140. micropurc-0.1.0/src/micropurc/_native/route_sampler.hpp +41 -0
  141. micropurc-0.1.0/src/micropurc/_native/schur.cpp +236 -0
  142. micropurc-0.1.0/src/micropurc/_native/schur.hpp +35 -0
  143. micropurc-0.1.0/src/micropurc/config.py +270 -0
  144. micropurc-0.1.0/src/micropurc/core/__init__.py +18 -0
  145. micropurc-0.1.0/src/micropurc/core/activeset.py +228 -0
  146. micropurc-0.1.0/src/micropurc/core/covariance.py +109 -0
  147. micropurc-0.1.0/src/micropurc/core/diagnostics.py +1099 -0
  148. micropurc-0.1.0/src/micropurc/core/estimator.py +669 -0
  149. micropurc-0.1.0/src/micropurc/core/lazy_design.py +95 -0
  150. micropurc-0.1.0/src/micropurc/core/projection.py +85 -0
  151. micropurc-0.1.0/src/micropurc/demands.py +137 -0
  152. micropurc-0.1.0/src/micropurc/forward/__init__.py +11 -0
  153. micropurc-0.1.0/src/micropurc/forward/base.py +75 -0
  154. micropurc-0.1.0/src/micropurc/forward/piqp_solver.py +178 -0
  155. micropurc-0.1.0/src/micropurc/network.py +293 -0
  156. micropurc-0.1.0/src/micropurc/reporting/__init__.py +37 -0
  157. micropurc-0.1.0/src/micropurc/reporting/html.py +352 -0
  158. micropurc-0.1.0/src/micropurc/reporting/loader.py +401 -0
  159. micropurc-0.1.0/src/micropurc/reporting/metrics.py +271 -0
  160. micropurc-0.1.0/src/micropurc/reporting/runlog.py +476 -0
  161. micropurc-0.1.0/src/micropurc/simulation/__init__.py +12 -0
  162. micropurc-0.1.0/src/micropurc/simulation/dgp.py +615 -0
  163. micropurc-0.1.0/src/micropurc/simulation/route_sampler.py +277 -0
  164. micropurc-0.1.0/src/micropurc/spec/__init__.py +27 -0
  165. micropurc-0.1.0/src/micropurc/spec/compile.py +293 -0
  166. micropurc-0.1.0/src/micropurc/spec/dsl.py +182 -0
  167. micropurc-0.1.0/src/micropurc/spec/schema.py +173 -0
  168. micropurc-0.1.0/tests/__init__.py +0 -0
  169. micropurc-0.1.0/tests/data/EMA_net.csv +259 -0
  170. micropurc-0.1.0/tests/data/EMA_trips.csv +1114 -0
  171. micropurc-0.1.0/tests/data/SiouxFalls_net.csv +77 -0
  172. micropurc-0.1.0/tests/data/SiouxFalls_trips.csv +529 -0
  173. micropurc-0.1.0/tests/test_activeset_comparison.py +228 -0
  174. micropurc-0.1.0/tests/test_covariance.py +176 -0
  175. micropurc-0.1.0/tests/test_cts.py +162 -0
  176. micropurc-0.1.0/tests/test_estimator_orchestration.py +411 -0
  177. micropurc-0.1.0/tests/test_metrics.py +123 -0
  178. micropurc-0.1.0/tests/test_native.py +116 -0
  179. micropurc-0.1.0/tests/test_projection.py +450 -0
  180. micropurc-0.1.0/tests/test_projection_stress.py +637 -0
  181. micropurc-0.1.0/tests/test_recovery.py +735 -0
  182. micropurc-0.1.0/tests/test_reporting.py +181 -0
  183. micropurc-0.1.0/tests/test_route_sampler_native.py +196 -0
  184. micropurc-0.1.0/tests/test_scaling_instrumentation.py +131 -0
  185. micropurc-0.1.0/tests/test_spec.py +319 -0
@@ -0,0 +1,7 @@
1
+ BasedOnStyle: Google
2
+ IndentWidth: 4
3
+ ColumnLimit: 100
4
+ PointerAlignment: Right
5
+ DerivePointerAlignment: false
6
+ AllowShortFunctionsOnASingleLine: Inline
7
+ AllowShortIfStatementsOnASingleLine: WithoutElse
@@ -0,0 +1,24 @@
1
+ root = true
2
+
3
+ [*]
4
+ charset = utf-8
5
+ end_of_line = lf
6
+ insert_final_newline = true
7
+ trim_trailing_whitespace = true
8
+ indent_style = space
9
+
10
+ [*.py]
11
+ indent_size = 4
12
+ max_line_length = 100
13
+
14
+ [*.{cpp,hpp,h,cu,cuh}]
15
+ indent_size = 4
16
+
17
+ [*.{yml,yaml,toml}]
18
+ indent_size = 2
19
+
20
+ [*.md]
21
+ trim_trailing_whitespace = false
22
+
23
+ [Makefile]
24
+ indent_style = tab
@@ -0,0 +1,63 @@
1
+ # OS
2
+ .DS_Store
3
+
4
+ # IDE
5
+ .idea/
6
+
7
+ # Logs
8
+ log/
9
+ *.log
10
+
11
+ # Local configs
12
+ config.toml
13
+ configs/
14
+
15
+ # Paper-work experiments (not part of the publishable package)
16
+ experiments/
17
+
18
+ # Generated outputs
19
+ outputs*/
20
+ run.sh
21
+ run_job.sh
22
+ run_job.template.sh
23
+
24
+ # Python
25
+ __pycache__/
26
+ *.pyc
27
+
28
+ # Reference files
29
+ ref/
30
+
31
+ # Build artifacts
32
+ build/
33
+ *.so
34
+ *.egg-info/
35
+
36
+ # Empirical pipeline
37
+ empirical/
38
+ summary_stats.py
39
+ save_filtered_obs_csv.py
40
+
41
+ # Sphinx documentation build output
42
+ docs/_build/
43
+
44
+ # Generated experiment results (regenerable via scripts/paper/run_all.py)
45
+ results/
46
+
47
+ # Consolidated local archive (retired scripts, results, legacy oracle)
48
+ _archive/
49
+
50
+ # Doc-example run archives (generated by pipeline.py)
51
+ docs/examples/runs/
52
+
53
+ # --- Data-file backstops ----------------------------------------------------
54
+ # The rules above protect directory NAMES only. These protect by extension, so a
55
+ # stray data file anywhere in the tree cannot be tracked by accident. Name-based
56
+ # patterns are kept in .git/info/exclude instead, which is never published.
57
+ *.pkl
58
+ *.pt
59
+ *.npy
60
+
61
+ # Internal write-ups (not for publication)
62
+ docs/qa/
63
+ docs/prediction_metrics/
@@ -0,0 +1,51 @@
1
+ # Never touch vendored code, the read-only legacy oracle, or the reference
2
+ # paper sources. (configs/ and experiments/ are gitignored.)
3
+ exclude: '^(extern/|micropurc_sim/|ref/|\.vscode/)'
4
+
5
+ repos:
6
+ - repo: https://github.com/astral-sh/ruff-pre-commit
7
+ rev: v0.14.13
8
+ hooks:
9
+ - id: ruff
10
+ args: ["--fix"]
11
+ - id: ruff-format
12
+
13
+ - repo: https://github.com/pycqa/pydocstyle
14
+ rev: 6.3.0
15
+ hooks:
16
+ - id: pydocstyle
17
+ additional_dependencies: [toml]
18
+ files: '^src/micropurc/.*\.py$'
19
+
20
+ - repo: https://github.com/terrencepreilly/darglint
21
+ rev: v1.8.1
22
+ hooks:
23
+ - id: darglint
24
+ args: ["--docstring-style", "google", "--strictness", "long"]
25
+ files: '^src/micropurc/.*\.py$'
26
+ # forward/base.py declares a Protocol with `...` stub bodies, which
27
+ # darglint misreads as excess-return (DAR202).
28
+ exclude: '^src/micropurc/forward/base\.py$'
29
+
30
+ - repo: https://github.com/pre-commit/mirrors-clang-format
31
+ rev: v19.1.7
32
+ hooks:
33
+ - id: clang-format
34
+ files: '^src/micropurc/_native/.*\.(cpp|hpp|h|cu|cuh)$'
35
+
36
+ - repo: https://github.com/pre-commit/pre-commit-hooks
37
+ rev: v5.0.0
38
+ hooks:
39
+ - id: end-of-file-fixer
40
+ - id: trailing-whitespace
41
+ - id: check-yaml
42
+ - id: check-added-large-files
43
+ args: ["--maxkb=1024"]
44
+
45
+ - repo: local
46
+ hooks:
47
+ - id: check-build-artifacts
48
+ name: Check for committed build artifacts
49
+ entry: python scripts/check_build_artifacts.py
50
+ language: system
51
+ pass_filenames: false
@@ -0,0 +1,24 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to
7
+ [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
8
+
9
+ ## [0.1.0] - 2026-08-09
10
+
11
+ ### Added
12
+
13
+ - First public release.
14
+ - Trip-level PURC estimator: a nested fixed-point solver with a non-monotone
15
+ line search.
16
+ - Forward route-choice solver built on [PIQP](https://github.com/PREDICT-EPFL/piqp),
17
+ behind a `ForwardSolver` protocol for additional backends.
18
+ - Simulation tooling: a data-generating process and route samplers for
19
+ producing synthetic trip datasets at known parameters.
20
+ - Lazy design evaluation in C++ for memory-efficient handling of large
21
+ networks and specifications.
22
+ - Sandwich and cluster-robust covariance estimators.
23
+ - Structured run reporting with frozen configuration, diagnostics, and
24
+ reproducibility metadata.
@@ -0,0 +1,40 @@
1
+ cff-version: 1.2.0
2
+ message: "If you use this software, please cite both the software and the accompanying article."
3
+ type: software
4
+ title: "micropurc"
5
+ version: 0.1.0
6
+ date-released: '2026-08-09'
7
+ license: MIT
8
+ repository-code: "https://github.com/andyYaoR/micropurc"
9
+ authors:
10
+ - family-names: "Fosgerau"
11
+ given-names: "Mogens"
12
+ affiliation: "University of Copenhagen"
13
+ - family-names: "Nielsen"
14
+ given-names: "Nikolaj"
15
+ affiliation: "University of Copenhagen"
16
+ - family-names: "Rasmussen"
17
+ given-names: "Thomas"
18
+ affiliation: "Technical University of Denmark"
19
+ - family-names: "Yao"
20
+ given-names: "Rui"
21
+ affiliation: "Technion — Israel Institute of Technology"
22
+ email: "rui.yao@technion.ac.il"
23
+ preferred-citation:
24
+ type: article
25
+ title: "Estimating the perturbed utility route choice model with trip-level data"
26
+ year: 2026
27
+ authors:
28
+ - family-names: "Fosgerau"
29
+ given-names: "Mogens"
30
+ affiliation: "University of Copenhagen"
31
+ - family-names: "Nielsen"
32
+ given-names: "Nikolaj"
33
+ affiliation: "University of Copenhagen"
34
+ - family-names: "Rasmussen"
35
+ given-names: "Thomas"
36
+ affiliation: "Technical University of Denmark"
37
+ - family-names: "Yao"
38
+ given-names: "Rui"
39
+ affiliation: "Technion — Israel Institute of Technology"
40
+ email: "rui.yao@technion.ac.il"
@@ -0,0 +1,165 @@
1
+ cmake_minimum_required(VERSION 3.18)
2
+ project(micropurc_native LANGUAGES CXX)
3
+
4
+ set(CMAKE_CXX_STANDARD 17)
5
+ set(CMAKE_CXX_STANDARD_REQUIRED ON)
6
+ set(CMAKE_CXX_EXTENSIONS OFF)
7
+
8
+ # ── Python + nanobind ────────────────────────────────────────────────
9
+ find_package(Python 3.10 COMPONENTS Interpreter Development.Module REQUIRED)
10
+
11
+ if(NOT nanobind_DIR)
12
+ execute_process(
13
+ COMMAND "${Python_EXECUTABLE}" -m nanobind --cmake_dir
14
+ OUTPUT_STRIP_TRAILING_WHITESPACE
15
+ OUTPUT_VARIABLE _NB_CMAKE_DIR
16
+ RESULT_VARIABLE _NB_RESULT)
17
+ if(_NB_RESULT EQUAL 0 AND _NB_CMAKE_DIR)
18
+ list(APPEND CMAKE_PREFIX_PATH "${_NB_CMAKE_DIR}")
19
+ endif()
20
+ endif()
21
+ find_package(nanobind CONFIG REQUIRED)
22
+
23
+ # ── Eigen + PIQP (header-only) ─────────────────────────────────────
24
+ # conda-forge installs Eigen's CMake config and headers under the environment
25
+ # prefix on Unix, but under <prefix>/Library on Windows. Seed CMAKE_PREFIX_PATH
26
+ # with both (from CONDA_PREFIX, which the build front-end reliably inherits) so
27
+ # find_package(Eigen3) resolves even when scikit-build-core's PEP 517 build
28
+ # isolation does not forward a CMAKE_PREFIX_PATH set in the parent shell into
29
+ # the configure subprocess.
30
+ foreach(_conda_root "$ENV{CONDA_PREFIX}" "$ENV{CONDA_PREFIX}/Library"
31
+ "$ENV{LIBRARY_PREFIX}" "$ENV{PREFIX}")
32
+ if(_conda_root AND IS_DIRECTORY "${_conda_root}")
33
+ list(APPEND CMAKE_PREFIX_PATH "${_conda_root}")
34
+ endif()
35
+ endforeach()
36
+
37
+ # Do not pass an explicit version here. conda-forge now ships Eigen 5.x, whose
38
+ # Eigen3ConfigVersion.cmake rejects a `find_package(Eigen3 3.3)` request as
39
+ # version-incompatible (major-version mismatch) and reports NOTFOUND even when
40
+ # the config is on CMAKE_PREFIX_PATH — silently sending the build to the
41
+ # fallback below (which used to be Unix-only, hence the Windows failure). The
42
+ # code only needs a reasonably modern Eigen, which any conda-forge build
43
+ # satisfies, so we omit the version and let compilation fail loudly otherwise.
44
+ find_package(Eigen3 QUIET)
45
+ if(NOT Eigen3_FOUND)
46
+ # Header-only fallback: probe the conda layouts directly on both Unix
47
+ # (<prefix>/include/eigen3) and Windows (<prefix>/Library/include/eigen3).
48
+ find_path(EIGEN3_INCLUDE_DIR NAMES Eigen/Dense
49
+ HINTS "$ENV{CONDA_PREFIX}" "$ENV{CONDA_PREFIX}/Library"
50
+ "$ENV{LIBRARY_PREFIX}" "$ENV{PREFIX}"
51
+ PATH_SUFFIXES include/eigen3 include
52
+ PATHS "/usr/local" "/usr")
53
+ if(EIGEN3_INCLUDE_DIR)
54
+ message(STATUS "Found Eigen3 headers at ${EIGEN3_INCLUDE_DIR}")
55
+ else()
56
+ # Last resort, for clean CI runners with no conda or system Eigen (e.g.
57
+ # cibuildwheel's manylinux containers and the GitHub macOS/Windows
58
+ # runners): fetch a pinned Eigen release from the official GitLab mirror.
59
+ # Eigen is header-only, so we only populate the sources and point the
60
+ # include path at them -- Eigen's own CMake project (docs, tests, install
61
+ # rules) is never configured, so nothing of Eigen's leaks into our build
62
+ # or install (wheel) stage. The direct-argument FetchContent_Populate
63
+ # form is used deliberately: it works on CMake 3.18 (our minimum) and,
64
+ # unlike the single-argument form, is not deprecated by CMP0169 on
65
+ # CMake >= 3.30.
66
+ message(STATUS
67
+ "Eigen3 not found via find_package or header probe; "
68
+ "fetching Eigen 3.4.0 sources (header-only) with FetchContent")
69
+ include(FetchContent)
70
+ FetchContent_Populate(eigen
71
+ GIT_REPOSITORY https://gitlab.com/libeigen/eigen.git
72
+ GIT_TAG 3.4.0
73
+ GIT_SHALLOW TRUE)
74
+ set(EIGEN3_INCLUDE_DIR "${eigen_SOURCE_DIR}" CACHE PATH
75
+ "Eigen3 headers (fetched by FetchContent)" FORCE)
76
+ message(STATUS "Using fetched Eigen3 headers at ${EIGEN3_INCLUDE_DIR}")
77
+ endif()
78
+ endif()
79
+
80
+ # PIQP header-only library (vendored in extern/piqp/).
81
+ set(PIQP_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/extern/piqp")
82
+
83
+ # ── Build the extension ─────────────────────────────────────────────
84
+ # Threading via std::thread (no OpenMP — avoids dual-runtime conflicts
85
+ # with torch/numpy libomp on macOS).
86
+ nanobind_add_module(_native
87
+ src/micropurc/_native/bindings.cpp
88
+ src/micropurc/_native/activeset.cpp
89
+ src/micropurc/_native/schur.cpp
90
+ src/micropurc/_native/route_sampler.cpp)
91
+
92
+ # std::thread needs pthreads on Linux. On MinGW the pthread symbols come from
93
+ # winpthread, which we link *statically* in the MINGW block below so the .pyd
94
+ # carries no libwinpthread-1.dll dependency; using Threads::Threads there would
95
+ # re-introduce a dynamic winpthread reference, so it is skipped on MinGW.
96
+ find_package(Threads REQUIRED)
97
+ if(NOT MINGW)
98
+ target_link_libraries(_native PRIVATE Threads::Threads)
99
+ endif()
100
+
101
+ # Eigen + PIQP headers.
102
+ if(Eigen3_FOUND)
103
+ target_link_libraries(_native PRIVATE Eigen3::Eigen)
104
+ else()
105
+ target_include_directories(_native PRIVATE ${EIGEN3_INCLUDE_DIR})
106
+ endif()
107
+ target_include_directories(_native PRIVATE ${PIQP_INCLUDE_DIR})
108
+ target_compile_definitions(_native PRIVATE HAVE_PIQP)
109
+
110
+ # ── BLAS/LAPACK (for large matrix operations) ──────────────────────
111
+ if(APPLE)
112
+ target_link_libraries(_native PRIVATE "-framework Accelerate")
113
+ target_compile_definitions(_native PRIVATE HAVE_LAPACK)
114
+ else()
115
+ find_package(LAPACK QUIET)
116
+ find_package(BLAS QUIET)
117
+ if(LAPACK_FOUND AND BLAS_FOUND)
118
+ target_link_libraries(_native PRIVATE ${LAPACK_LIBRARIES} ${BLAS_LIBRARIES})
119
+ target_compile_definitions(_native PRIVATE HAVE_LAPACK)
120
+ endif()
121
+ endif()
122
+
123
+ # ── Self-contained runtime on Windows/MinGW ─────────────────────────
124
+ # Built with MinGW-w64 (e.g. Strawberry Perl's GCC), the .pyd otherwise
125
+ # depends on libgcc_s_seh-1.dll, libstdc++-6.dll, and libwinpthread-1.dll
126
+ # (the last pulled in by std::thread). Since Python 3.8 the extension loader
127
+ # ignores PATH for a .pyd's own dependencies -- only the module's directory,
128
+ # the system directories, and os.add_dll_directory() are searched -- so adding
129
+ # the toolchain's bin to PATH does not resolve them. Statically link the GCC
130
+ # runtime and winpthread so the module has no external MinGW DLL dependencies.
131
+ # Surgical by design: BLAS/LAPACK and system DLLs stay dynamic.
132
+ if(MINGW)
133
+ target_link_options(_native PRIVATE
134
+ -static-libgcc -static-libstdc++
135
+ -Wl,-Bstatic -lwinpthread -Wl,-Bdynamic)
136
+ endif()
137
+
138
+ # Optimisation flags.
139
+ # MICROPURC_NATIVE_ARCH defaults to OFF because binaries built with
140
+ # -march=native are tied to the build machine's CPU: a wheel compiled on a
141
+ # modern CI runner would crash with SIGILL (illegal instruction) on older
142
+ # user CPUs. Source builders compiling for their own machine can opt in with
143
+ # -DMICROPURC_NATIVE_ARCH=ON; distributable wheels must leave it off.
144
+ option(MICROPURC_NATIVE_ARCH
145
+ "Optimize for the build machine's CPU (never enable for distributable wheels)"
146
+ OFF)
147
+ if(NOT MSVC)
148
+ target_compile_options(_native PRIVATE -O3 -funroll-loops)
149
+ if(MICROPURC_NATIVE_ARCH)
150
+ include(CheckCXXCompilerFlag)
151
+ check_cxx_compiler_flag("-march=native" HAS_MARCH_NATIVE)
152
+ if(HAS_MARCH_NATIVE)
153
+ target_compile_options(_native PRIVATE -march=native)
154
+ endif()
155
+ endif()
156
+ else()
157
+ # No explicit MSVC optimisation flags needed: the wheel build configures
158
+ # with cmake.build-type = Release (pyproject.toml), and CMake's default
159
+ # CMAKE_CXX_FLAGS_RELEASE for MSVC already contains /O2 /Ob2 /DNDEBUG
160
+ # (see Modules/Platform/Windows-MSVC.cmake). Adding /O2 here again would
161
+ # be redundant and risk duplicate-flag warnings.
162
+ endif()
163
+
164
+ # Install into the micropurc package directory.
165
+ install(TARGETS _native DESTINATION micropurc)
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Mogens Fosgerau, Nikolaj Nielsen, Thomas Rasmussen, Rui Yao
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.