smf-solver 0.2.3__py3-none-win_amd64.whl

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.
smf_solver/__init__.py ADDED
@@ -0,0 +1,220 @@
1
+ """Python distribution helper for the smf sparse symmetric direct solver.
2
+
3
+ Provides library discovery, ctypes metadata inspection, and ready-to-use
4
+ option dictionaries for native IPOPT (linear_solver="smf"), cyipopt, and CasADi.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+
10
+ # start delvewheel patch
11
+ def _delvewheel_patch_1_13_4():
12
+ import ctypes
13
+ import os
14
+ import platform
15
+ import sys
16
+ libs_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, 'smf_solver.libs'))
17
+ is_conda_cpython = platform.python_implementation() == 'CPython' and (hasattr(ctypes.pythonapi, 'Anaconda_GetVersion') or 'packaged by conda-forge' in sys.version)
18
+ if sys.version_info[:2] >= (3, 8) and not is_conda_cpython or sys.version_info[:2] >= (3, 10):
19
+ if os.path.isdir(libs_dir):
20
+ os.add_dll_directory(libs_dir)
21
+ else:
22
+ load_order_filepath = os.path.join(libs_dir, '.load-order-smf_solver-0.2.3')
23
+ if os.path.isfile(load_order_filepath):
24
+ import ctypes.wintypes
25
+ with open(os.path.join(libs_dir, '.load-order-smf_solver-0.2.3'), encoding='utf-8') as file:
26
+ load_order = file.read().split()
27
+ kernel32 = ctypes.WinDLL('kernel32', use_last_error=True)
28
+ kernel32.LoadLibraryExW.restype = ctypes.wintypes.HMODULE
29
+ kernel32.LoadLibraryExW.argtypes = ctypes.wintypes.LPCWSTR, ctypes.wintypes.HANDLE, ctypes.wintypes.DWORD
30
+ for lib in load_order:
31
+ lib_path = os.path.join(os.path.join(libs_dir, lib))
32
+ if os.path.isfile(lib_path) and not kernel32.LoadLibraryExW(lib_path, None, 8):
33
+ raise OSError('Error loading {}; {}'.format(lib, ctypes.FormatError(ctypes.get_last_error())))
34
+
35
+
36
+ _delvewheel_patch_1_13_4()
37
+ del _delvewheel_patch_1_13_4
38
+ # end delvewheel patch
39
+
40
+ import ctypes
41
+ import os
42
+ import pathlib
43
+ import sys
44
+ from typing import Any, Dict, Optional
45
+
46
+ __all__ = [
47
+ "c_library_path",
48
+ "ma97_plugin_path",
49
+ "abi_version",
50
+ "version",
51
+ "blas_backend",
52
+ "ipopt_options",
53
+ "casadi_options",
54
+ ]
55
+
56
+
57
+ def _lib_names(stem: str) -> list[str]:
58
+ if sys.platform == "win32":
59
+ return [f"{stem}.dll", f"lib{stem}.dll"]
60
+ if sys.platform == "darwin":
61
+ return [f"lib{stem}.dylib", f"lib{stem}.1.dylib"]
62
+ return [f"lib{stem}.so", f"lib{stem}.so.1"]
63
+
64
+
65
+ def _search_dirs() -> list[pathlib.Path]:
66
+ dirs: list[pathlib.Path] = []
67
+ env_dir = os.environ.get("SMF_LIB_DIR")
68
+ if env_dir:
69
+ dirs.append(pathlib.Path(env_dir))
70
+ pkg_dir = pathlib.Path(__file__).resolve().parent
71
+ dirs.append(pkg_dir / "_libs")
72
+ # Conda / system prefix fallbacks
73
+ prefix = pathlib.Path(sys.prefix)
74
+ if sys.platform == "win32":
75
+ dirs.append(prefix / "Library" / "bin")
76
+ else:
77
+ dirs.append(prefix / "lib")
78
+ dirs.append(prefix / "lib64")
79
+ return dirs
80
+
81
+
82
+ def _find_library(stem: str, env_override: str) -> str:
83
+ explicit = os.environ.get(env_override)
84
+ if explicit:
85
+ return explicit
86
+ for d in _search_dirs():
87
+ for name in _lib_names(stem):
88
+ candidate = d / name
89
+ if candidate.is_file():
90
+ return str(candidate)
91
+ # Fall back to bare library name so dynamic linker search path can resolve it.
92
+ return _lib_names(stem)[0]
93
+
94
+
95
+ def c_library_path() -> str:
96
+ """Return the path to libsmf_c (versioned C ABI for native linear_solver=smf)."""
97
+ return _find_library("smf_c", "SMF_C_LIB")
98
+
99
+
100
+ def ma97_plugin_path() -> str:
101
+ """Return the path to libsmf_ma97 (drop-in HSL MA97 shim for stock IPOPT)."""
102
+ return _find_library("smf_ma97", "SMF_MA97_LIB")
103
+
104
+
105
+ _PRELOADED_LIBS: dict[str, ctypes.CDLL] = {}
106
+
107
+
108
+ def _load_dll_with_dir(path: str) -> ctypes.CDLL:
109
+ dir_name = os.path.dirname(path)
110
+ if (
111
+ sys.platform == "win32"
112
+ and dir_name
113
+ and hasattr(os, "add_dll_directory")
114
+ and os.path.isdir(dir_name)
115
+ ):
116
+ with os.add_dll_directory(os.path.abspath(dir_name)):
117
+ return ctypes.CDLL(path)
118
+ return ctypes.CDLL(path)
119
+
120
+
121
+ def _preload_windows_plugin(path: str) -> None:
122
+ """Preload a bundled Windows DLL via ctypes so downstream LoadLibraryA calls
123
+ (e.g. IPOPT's hsllib loader) find dependencies bundled by delvewheel."""
124
+ if sys.platform != "win32" or path in _PRELOADED_LIBS or not os.path.isfile(path):
125
+ return
126
+ _PRELOADED_LIBS[path] = _load_dll_with_dir(path)
127
+
128
+
129
+ def _load_c_lib() -> ctypes.CDLL:
130
+ path = c_library_path()
131
+ lib = _load_dll_with_dir(path)
132
+ lib.smf_c_abi_version.restype = ctypes.c_int
133
+ lib.smf_c_abi_version.argtypes = []
134
+ lib.smf_version.restype = ctypes.c_char_p
135
+ lib.smf_version.argtypes = []
136
+ lib.smf_blas_backend.restype = ctypes.c_char_p
137
+ lib.smf_blas_backend.argtypes = []
138
+ return lib
139
+
140
+
141
+ def abi_version() -> int:
142
+ """Return SMF_C_ABI_VERSION exported by libsmf_c."""
143
+ return int(_load_c_lib().smf_c_abi_version())
144
+
145
+
146
+ def version() -> str:
147
+ """Return the smf version string exported by libsmf_c."""
148
+ return _load_c_lib().smf_version().decode("utf-8")
149
+
150
+
151
+ def blas_backend() -> str:
152
+ """Return the BLAS backend string (e.g. 'openblas', 'mkl') of libsmf_c."""
153
+ return _load_c_lib().smf_blas_backend().decode("utf-8")
154
+
155
+
156
+ def ipopt_options(
157
+ *,
158
+ native: bool = True,
159
+ num_threads: int = 0,
160
+ scaling: str = "auto",
161
+ ordering: str = "auto",
162
+ deterministic: bool = False,
163
+ pass_lib_path: bool = True,
164
+ ) -> Dict[str, Any]:
165
+ """Build an IPOPT / cyipopt options dict configured for smf.
166
+
167
+ Args:
168
+ native: True for IPOPT built with native linear_solver=smf; False for
169
+ stock IPOPT wheels (uses linear_solver='ma97' + hsllib=libsmf_ma97).
170
+ num_threads: 0 for auto (SMF_NUM_THREADS / OMP_NUM_THREADS / P-cores).
171
+ scaling: 'auto', 'dynamic', 'none', 'matching', or 'equilibration'.
172
+ ordering: 'auto', 'amd', 'metis', or 'matching'.
173
+ deterministic: True for bitwise-reproducible parallel solves.
174
+ pass_lib_path: When native=True, include 'smflib' pointing to libsmf_c
175
+ (set False if IPOPT is compile-time linked with IPOPT_HAS_SMF).
176
+ """
177
+ if native:
178
+ opts: Dict[str, Any] = {
179
+ "linear_solver": "smf",
180
+ "smf_num_threads": int(num_threads),
181
+ "smf_scaling": scaling,
182
+ "smf_ordering": ordering,
183
+ "smf_deterministic": "yes" if deterministic else "no",
184
+ }
185
+ if pass_lib_path:
186
+ c_path = c_library_path()
187
+ _preload_windows_plugin(c_path)
188
+ opts["smflib"] = c_path
189
+ return opts
190
+
191
+ ma97_path = ma97_plugin_path()
192
+ _preload_windows_plugin(ma97_path)
193
+ return {
194
+ "linear_solver": "ma97",
195
+ "hsllib": ma97_path,
196
+ }
197
+
198
+
199
+ def casadi_options(
200
+ *,
201
+ native: bool = True,
202
+ num_threads: int = 0,
203
+ scaling: str = "auto",
204
+ ordering: str = "auto",
205
+ deterministic: bool = False,
206
+ pass_lib_path: bool = True,
207
+ extra_ipopt: Optional[Dict[str, Any]] = None,
208
+ ) -> Dict[str, Any]:
209
+ """Build a CasADi nlpsol('...', 'ipopt', nlp, opts) dictionary for smf."""
210
+ ipopt_opts = ipopt_options(
211
+ native=native,
212
+ num_threads=num_threads,
213
+ scaling=scaling,
214
+ ordering=ordering,
215
+ deterministic=deterministic,
216
+ pass_lib_path=pass_lib_path,
217
+ )
218
+ if extra_ipopt:
219
+ ipopt_opts.update(extra_ipopt)
220
+ return {"ipopt": ipopt_opts}
Binary file
Binary file
@@ -0,0 +1,18 @@
1
+
2
+ Copyright & License Notice
3
+ ---------------------------
4
+
5
+ Copyright 1995-2013, Regents of the University of Minnesota
6
+
7
+ Licensed under the Apache License, Version 2.0 (the "License");
8
+ you may not use this file except in compliance with the License.
9
+ You may obtain a copy of the License at
10
+
11
+ http://www.apache.org/licenses/LICENSE-2.0
12
+
13
+ Unless required by applicable law or agreed to in writing, software
14
+ distributed under the License is distributed on an "AS IS" BASIS,
15
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
16
+ implied. See the License for the specific language governing
17
+ permissions and limitations under the License.
18
+
@@ -0,0 +1,202 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "{}"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright {yyyy} {name of copyright owner}
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
202
+
@@ -0,0 +1,137 @@
1
+ # Vendored third-party code
2
+
3
+ smf builds METIS from these sources by default (`SMF_VENDORED_METIS=ON`) as one
4
+ static library, `smf_metis` (`CMakeLists.txt` here; upstream's CMake is not used).
5
+ `-DSMF_VENDORED_METIS=OFF` links an external METIS through `find_package(METIS)`
6
+ instead, whose calls smf then serialises with a process-wide mutex.
7
+
8
+ ## Why vendored
9
+
10
+ The conda-forge `metis` 5.2.1 package on Windows (MSVC) is built with GKlib's
11
+ `__thread` defined to nothing: upstream's CMake thread-local-storage check
12
+ (`GKlibSystem.cmake`, `conf/gkbuild.cmake`) runs `try_compile` without the
13
+ `-D__thread=__declspec(thread)` it then adds, fails, and appends `-D__thread=`,
14
+ which MSVC applies last. GKlib's per-call state (the `gkmcore` memory core,
15
+ the `gk_jbufs` error jump buffers) becomes process-global, and two concurrent
16
+ METIS calls abort or corrupt the heap ("Could not find pointer ... in mcore").
17
+ Built here with real thread-local storage, 16 threads x 200 concurrent
18
+ `METIS_NodeND` / `METIS_ComputeVertexSeparator` calls give results bitwise
19
+ equal to the serial ones (`ParallelNd.RawConcurrentMetisIsSafe`), and the
20
+ serial orderings are bitwise those of the conda-forge DLL
21
+ (`ParallelNd.VendoredMetisMatchesCondaOrdering`).
22
+
23
+ ## Sources
24
+
25
+ | dir | upstream | version | tarball | SHA-256 of the tarball |
26
+ |---|---|---|---|---|
27
+ | `metis/` | https://github.com/KarypisLab/METIS | tag `v5.2.1` | https://github.com/KarypisLab/METIS/archive/v5.2.1.tar.gz | `1a4665b2cd07edc2f734e30d7460afb19c1217c2547c2ac7bf6e1848d50aff7a` |
28
+ | `gklib/` | https://github.com/KarypisLab/GKlib | commit `8bd6bad750b2b0d90800c632cf18e8ee93ad72d7` | https://github.com/KarypisLab/GKlib/archive/8bd6bad750b2b0d90800c632cf18e8ee93ad72d7.tar.gz | `e1d59de12336731e6dde8465f05de7b907fae5d72c921cffcde217a89eaab654` |
29
+
30
+ These are the versions and tarballs conda-forge's `metis` 5.2.1 recipe builds
31
+ (its MSVC DLL links GKlib statically). Copied: `metis/include/metis.h`,
32
+ `metis/libmetis/*.{c,h}`, `gklib/*.{c,h}`, `gklib/win32/adapt.{c,h}` and the
33
+ licence files; upstream's programs, tests, graphs, manuals and build files are
34
+ left out. The unmodified copy is the upstream tarballs (SHA-256 above), minus
35
+ the files in the table below.
36
+
37
+ Removed from that copy since, so that nothing under LGPL is built or shipped
38
+ (see patches 4 and 5):
39
+
40
+ | file | what it was | why it can go |
41
+ |---|---|---|
42
+ | `gklib/getopt.c` | glibc's getopt (LGPL-2.1) | used only by GKlib's command-line programs |
43
+ | `gklib/gk_getopt.h` | declarations for `getopt.c` | nothing else uses them |
44
+ | `gklib/gkregex.c`, `gklib/gkregex.h` | glibc's regex (LGPL-2.1), built on MSVC under `USE_GKREGEX` | its only caller, `gk_strstr_replace()`, is removed and never called by METIS |
45
+ | `gklib/gk_mksort.h` (content) | GKlib's sort macro, adapted from glibc's qsort (LGPL-2.1) | replaced by smf's own implementation (patch 4) |
46
+
47
+ ## Licences
48
+
49
+ smf itself is MIT. The vendored code is linked statically into smf's
50
+ libraries (`smf_metis`, `libsmf`, `libsmf_ma97`); `install` copies these
51
+ notices to `share/doc/smf/third_party`.
52
+
53
+ - **Apache License 2.0** (`LICENSE-Apache-2.0.txt`), all of it except the
54
+ headers below:
55
+ - METIS: Copyright 1995-2013, Regents of the University of Minnesota (`metis/LICENSE`).
56
+ - GKlib: Copyright 1995-2018, Regents of the University of Minnesota (`gklib/LICENSE.txt`).
57
+ - `gklib/gk_mksort.h` is smf's own code (patch 4), Apache-2.0 as well.
58
+ - Each file smf changed says so where it changed (`smf patch N` comments),
59
+ as section 4(b) asks.
60
+ - **BSD-style**, notices in the files: `gklib/gk_ms_stdint.h`,
61
+ `gklib/gk_ms_inttypes.h` (Alexander Chemeris; MSVC headers) and the
62
+ MT19937-64 generator in `gklib/random.c` (Matsumoto and Nishimura; only with
63
+ `USE_GKRAND`, which smf does not define).
64
+
65
+ Nothing under the LGPL or GPL is left in this directory.
66
+
67
+ ## smf's patches
68
+
69
+ Five, all in `patches/smf-metis.patch`: `git diff -B -D` against the
70
+ unmodified copy, paths from the repository root. Deleted and rewritten files
71
+ appear without their old content, so no LGPL text is in the patch either; to
72
+ redo it on fresh sources, delete the files in the table above, then apply the
73
+ remaining hunks (for example `git apply --exclude` the deleted paths).
74
+
75
+ 1. **`metis/include/metis.h`: index and real widths.** `IDXTYPEWIDTH 32` and
76
+ `REALTYPEWIDTH 32` defined, as conda-forge's
77
+ `0004-uncomment-width-variables.patch` does (smf asserts
78
+ `sizeof(idx_t) == sizeof(smf::Int)`); plus `SMF_VENDORED_METIS_H`, which
79
+ `ordering_metis.cpp` checks so that a thread-safe build cannot pick up
80
+ another `metis.h`.
81
+ 2. **`gklib/random.c`: thread-local `rand()`.** Without `USE_GKRAND`, GKlib's
82
+ random numbers come from the C runtime's `rand()`, whose state is per
83
+ thread with MSVC but one process-wide stream with glibc: concurrent METIS
84
+ calls on Linux would interleave it and give run-dependent orderings.
85
+ `gk_randinit` / `gk_randint32` / `gk_randint64` now use a `__thread` copy of
86
+ MSVC's generator (state 1 until seeded, `state = state * 214013 + 2531011`,
87
+ returns `(state >> 16) & 0x7fff`). Windows orderings stay bit-identical,
88
+ and every platform gets the same per-thread sequence. (`gk_macros.h`'s
89
+ `RandomInRange` still calls `rand()`; nothing METIS calls uses it.)
90
+ 3. **`gklib/error.c`: no process-wide signal handlers.** Every METIS API call
91
+ brackets its work with `gk_sigtrap()` / `gk_siguntrap()`, which installed
92
+ and restored `SIGABRT` / `SIGTERM` handlers with `signal()`. Handlers are
93
+ process-wide: concurrent calls race on them and can leave GKlib's handler
94
+ installed, or drop the host's, after every call has returned. Now
95
+ `gk_sigtrap` / `gk_siguntrap` only push and pop the thread's jump-buffer
96
+ level, and `gk_errexit()` jumps straight to that buffer when a METIS call is
97
+ active on the thread (METIS then returns its error code, as before, in
98
+ every API function that sets a trap; see the gaps below).
99
+
100
+ 4. **`gklib/gk_mksort.h`: smf's own `GK_MKQSORT`.** The original macro was
101
+ adapted from glibc's qsort (LGPL-2.1). smf's replacement is written from a
102
+ description of that algorithm, not from its code: median-of-three
103
+ quicksort with an explicit stack, the smaller side first, ranges of at
104
+ most 9 elements (the original's threshold of 8) left for one final
105
+ insertion-sort pass that starts with the minimum of the first 9 elements
106
+ moved to the front. METIS sorts key-value pairs by key only, so equal-key
107
+ order feeds the orderings; the replacement gives the original's element
108
+ order exactly. Checked against the original on 38,928 random arrays with
109
+ many duplicate keys (ascending and descending, int and float keys, n up
110
+ to 200,000) before the original was removed; the gtest
111
+ `ParallelNd.GkSortPinnedOrder` pins its outputs.
112
+ 5. **No regex, no getopt.** `gk_strstr_replace()` (`string.c`, the only
113
+ regex user; METIS never calls it) and its prototype are removed, `GKlib.h`
114
+ no longer includes a regex header or `gk_getopt.h`, and `getopt.c`,
115
+ `gk_getopt.h`, `gkregex.c` and `gkregex.h` are deleted (table above).
116
+
117
+ Known gaps, unchanged from upstream and not reached by smf in normal use:
118
+ `METIS_ComputeVertexSeparator` sets no trap (`libmetis/parmetis.c`), so an
119
+ out-of-memory error inside it raises `SIGABRT` and ends the process, as it
120
+ did with conda-forge's DLL; `METIS_PartMeshNodal/Dual` (`meshpart.c`, unused
121
+ by smf) call `raise(SIGERR)` directly, which now terminates instead of being
122
+ caught.
123
+
124
+ ## Build flags (`CMakeLists.txt`)
125
+
126
+ - MSVC: `WIN32 MSC _CRT_SECURE_NO_DEPRECATE __thread=__declspec(thread)`,
127
+ upstream's set with real TLS and without `USE_GKREGEX` (patch 5).
128
+ clang-cl also gets `/FIio.h`: GKlib calls `read()` / `write()` without a
129
+ declaration, which Clang rejects in C99.
130
+ - GCC / Clang: `LINUX _FILE_OFFSET_BITS=64`, `HAVE_EXECINFO_H` /
131
+ `HAVE_GETLINE` when present, `-std=c99 -fno-strict-aliasing`; native
132
+ `__thread`. Symbols get hidden visibility, and `libsmf_ma97` links with
133
+ `--exclude-libs,ALL`, so a process that also loads a system `libmetis` keeps
134
+ the two copies apart.
135
+ - Always `NDEBUG NDEBUG2` (no METIS/GKlib assertions), warnings off, and none
136
+ of smf's own flags (`/arch:AVX2`, `-march=native`, ...): the compiler's
137
+ defaults for the build type, like the conda-forge build.
@@ -0,0 +1,18 @@
1
+
2
+ Copyright & License Notice
3
+ ---------------------------
4
+
5
+ Copyright 1995-2018, Regents of the University of Minnesota
6
+
7
+ Licensed under the Apache License, Version 2.0 (the "License");
8
+ you may not use this file except in compliance with the License.
9
+ You may obtain a copy of the License at
10
+
11
+ http://www.apache.org/licenses/LICENSE-2.0
12
+
13
+ Unless required by applicable law or agreed to in writing, software
14
+ distributed under the License is distributed on an "AS IS" BASIS,
15
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
16
+ implied. See the License for the specific language governing
17
+ permissions and limitations under the License.
18
+
@@ -0,0 +1,2 @@
1
+ Version: 1.13.4
2
+ Arguments: ['C:\\Users\\runneradmin\\micromamba\\envs\\smfwhl\\Scripts\\delvewheel', 'repair', '--analyze-existing', '--add-path', 'C:\\Users\\runneradmin\\micromamba\\envs\\smfwhl\\Library\\bin', '-w', 'dist', 'wheelhouse_raw\\smf_solver-0.2.3-py3-none-win_amd64.whl']
@@ -0,0 +1,81 @@
1
+ Metadata-Version: 2.2
2
+ Name: smf-solver
3
+ Version: 0.2.3
4
+ Summary: Sparse symmetric multifrontal direct linear solver (libsmf_c + libsmf_ma97) for IPOPT, cyipopt, and CasADi
5
+ Keywords: sparse,linear-solver,multifrontal,cholesky,ldlt,ipopt,casadi,cyipopt,optimization
6
+ License: MIT AND Apache-2.0
7
+ Classifier: Intended Audience :: Science/Research
8
+ Classifier: License :: OSI Approved :: MIT License
9
+ Classifier: Operating System :: POSIX :: Linux
10
+ Classifier: Operating System :: MacOS
11
+ Classifier: Operating System :: Microsoft :: Windows
12
+ Classifier: Programming Language :: C++
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
15
+ Project-URL: Homepage, https://github.com/danlil240/smf-solver
16
+ Project-URL: Repository, https://github.com/danlil240/smf-solver
17
+ Project-URL: Issues, https://github.com/danlil240/smf-solver/issues
18
+ Requires-Python: >=3.9
19
+ Description-Content-Type: text/markdown
20
+
21
+ # `smf-solver`
22
+
23
+ Prebuilt Python wheels for [smf](https://github.com/danlil240/smf-solver), a C++20 sparse symmetric multifrontal direct linear solver (Cholesky / LDLᵀ with exact inertia) designed for interior-point optimizers such as IPOPT, CasADi, and cyipopt.
24
+
25
+ Each wheel bundles self-contained `libsmf_c` (versioned C ABI for native `linear_solver="smf"`) and `libsmf_ma97` (drop-in MA97 plugin for stock IPOPT/CasADi/cyipopt wheels), licensed under MIT / Apache-2.0.
26
+
27
+ ## Installation
28
+
29
+ ```bash
30
+ pip install smf-solver
31
+ ```
32
+
33
+ ## Usage with `CasADi`
34
+
35
+ With stock PyPI `casadi` wheels (uses `libsmf_ma97` via IPOPT's `hsllib` loader — no HSL license required):
36
+
37
+ ```python
38
+ import casadi as ca
39
+ import smf_solver
40
+
41
+ opts = smf_solver.casadi_options(native=False)
42
+ solver = ca.nlpsol("solver", "ipopt", nlp, opts)
43
+ ```
44
+
45
+ With an IPOPT build that includes native `linear_solver="smf"`:
46
+
47
+ ```python
48
+ opts = smf_solver.casadi_options(native=True, num_threads=0)
49
+ solver = ca.nlpsol("solver", "ipopt", nlp, opts)
50
+ ```
51
+
52
+ ## Usage with `cyipopt`
53
+
54
+ ```python
55
+ import cyipopt
56
+ import smf_solver
57
+
58
+ nlp = cyipopt.Problem(...)
59
+
60
+ # Stock PyPI cyipopt / IPOPT:
61
+ for k, v in smf_solver.ipopt_options(native=False).items():
62
+ nlp.add_option(k, v)
63
+
64
+ # IPOPT built with native linear_solver="smf":
65
+ for k, v in smf_solver.ipopt_options(native=True, num_threads=0).items():
66
+ nlp.add_option(k, v)
67
+ ```
68
+
69
+ Set `SMF_NUM_THREADS` (or `OMP_NUM_THREADS`) to control thread count, and `SMF_PLUGIN_STATS=1` to confirm `smf` is serving factorizations.
70
+
71
+ ## Building from source
72
+
73
+ ```bash
74
+ pip install ./packaging/python
75
+ ```
76
+
77
+ For portable Linux x86_64 wheels, pass `-DSMF_MARCH=x86-64-v3`:
78
+
79
+ ```bash
80
+ CMAKE_ARGS="-DSMF_MARCH=x86-64-v3" pip wheel ./packaging/python -w dist/
81
+ ```
@@ -0,0 +1,20 @@
1
+ smf_solver/__init__.py,sha256=eOcLqiLL8JxdHfPhs8-Wh3b3y2yvAx3ewvn412iDK_4,7608
2
+ smf_solver/_libs/smf_c.dll,sha256=o_EJpf1pqKMwjbz7zCP02TZpsZ5TkaVWgvqoBH58y_Y,958464
3
+ smf_solver/_libs/smf_ma97.dll,sha256=Ug4Z4Xem7Om44zckKvnUDGNzpZjzBwMHPKwTbzmij_E,1003520
4
+ smf_solver/_licenses/doc/smf/third_party/LICENSE,sha256=CuSskEnsGwXCmi7vVC3J_WdPCdRaZavrclf7SGK18fg,659
5
+ smf_solver/_licenses/doc/smf/third_party/LICENSE-Apache-2.0.txt,sha256=oH6RhcyocMVWpE1bTf8r6lFuAGjs95hP2caBiDm_12E,11527
6
+ smf_solver/_licenses/doc/smf/third_party/README.md,sha256=ONjzfpyoQmw49xkY6-a5uAoa536PdAjVDIU5QR8EJCM,8410
7
+ smf_solver/_licenses/doc/smf/third_party/gklib/LICENSE.txt,sha256=t6LI5Jqxd0bi6aLrZww6GQ3LVSX33mBvwx5ns7S1xr0,659
8
+ smf_solver-0.2.3.dist-info/DELVEWHEEL,sha256=pZuAIQD8z5SHHsvSkfnQGUUe0V2WpSvQ7qddrVUKDqA,286
9
+ smf_solver-0.2.3.dist-info/METADATA,sha256=WW6o_5zw0nV_MGCy2XvlucPksNoarVJMXvNqOZ5FeMk,2661
10
+ smf_solver-0.2.3.dist-info/RECORD,,
11
+ smf_solver-0.2.3.dist-info/WHEEL,sha256=MavvTN48CE-QbhQ_kyQzVg79Yjk576_oKsIlJsE4vMI,102
12
+ smf_solver.libs/.load-order-smf_solver-0.2.3,sha256=Vx3uHDNCIUSe8zX2UT4EUxpbvAlT53Bbegjqjl5-r6g,380
13
+ smf_solver.libs/amd-8be1447e5208db353852ebd80414b580.dll,sha256=9W0mGOpQD5o0-k28flM4RVq6uy-pqnhGXeb5ZMjPJ9A,59392
14
+ smf_solver.libs/libomp-55bfd1471b80573c2c230b74fc18cebc.dll,sha256=ZfUic6jG0_PLlcHN97aBTcmqOaiUsTPs5WuWzoO4rbE,674816
15
+ smf_solver.libs/msvcp140-64a912c050508080334edfecf86c430a.dll,sha256=hDPPx478fl4MBr3Z-oJus8lcyCGGkjs4Xp4BpE95rK4,631808
16
+ smf_solver.libs/openblas-0911bb8c12cb0ee9fbc499f396d2a713.dll,sha256=koGJmMDXoDI2Y4KAVCbH0fV5IXlwuSdAbIsrs-bjby4,28357632
17
+ smf_solver.libs/suitesparseconfig-d1e8636e247235b3e16521fdd1c31ff3.dll,sha256=VV8NLtutBae1fEC0418mQFoRHNcYGbVi65qGNp6gS64,14848
18
+ smf_solver.libs/vcomp140-294397f642d824a97de354aa625f993a.dll,sha256=KUOX9kLYJKl941SqYl-ZOpfzTXKeyhveVtWol65XSIg,213864
19
+ smf_solver.libs/vcruntime140-eb1ee979bf02324712346e5bdbfc59c7.dll,sha256=6x7peb8CMkcSNG5b2_xZx4U4i8UNGMwmiKrksHNJFaA,176488
20
+ smf_solver.libs/vcruntime140_1-d17c65eaa89c8c850ca90b0048d58fe9.dll,sha256=0RbkkbyxMAu6EI6jaLYUkHDbkUEh-K9GPZQ6a0j0ZyI,30208
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: scikit-build-core 1.1.2
3
+ Root-Is-Purelib: false
4
+ Tag: py3-none-win_amd64
5
+
@@ -0,0 +1,8 @@
1
+ vcruntime140-eb1ee979bf02324712346e5bdbfc59c7.dll
2
+ vcruntime140_1-d17c65eaa89c8c850ca90b0048d58fe9.dll
3
+ openblas-0911bb8c12cb0ee9fbc499f396d2a713.dll
4
+ amd-8be1447e5208db353852ebd80414b580.dll
5
+ vcomp140-294397f642d824a97de354aa625f993a.dll
6
+ msvcp140-64a912c050508080334edfecf86c430a.dll
7
+ libomp-55bfd1471b80573c2c230b74fc18cebc.dll
8
+ suitesparseconfig-d1e8636e247235b3e16521fdd1c31ff3.dll