Skip to content

Commit 515a7d2

Browse files
committed
WIP
1 parent a680727 commit 515a7d2

5 files changed

Lines changed: 59 additions & 4 deletions

File tree

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ FetchContent_Declare(
2929
list(POP_BACK CMAKE_MESSAGE_INDENT)
3030
FetchContent_MakeAvailable(qoco)
3131

32+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/bindings.cpp.in
33+
${CMAKE_CURRENT_SOURCE_DIR}/src/bindings.cpp)
3234
pybind11_add_module(qoco_ext src/bindings.cpp)
3335
target_include_directories(qoco_ext INTERFACE ${qoco_SOURCE_DIR}/include)
3436

backends/cuda/pyproject.toml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[build-system]
2+
requires = ["scikit-build-core", "pybind11"]
3+
build-backend = "scikit_build_core.build"
4+
5+
[project]
6+
name = "qoco"
7+
version = "0.2.0"
8+
description = "QOCO: Quadratic Objective Conic Optimizer"
9+
readme = "README.md"
10+
requires-python = ">=3.8"
11+
authors = [{ name = "Govind M. Chari", email = "govindchari1@gmail.com" }]
12+
dependencies = ["jinja2", "numpy>=1.7", "qdldl", "scipy>=0.13.2", "setuptools"]
13+
14+
[tool.scikit-build]
15+
install.components = ["python"]
16+
wheel.install-dir = "qoco"
17+
18+
[tool.scikit-build.cmake.define]
19+
QOCO_ALGEBRA_BACKEND = "cuda"
20+
QOCO_EXT_MODULE_NAME = "qoco_cuda"
21+
22+
[project.urls]
23+
Homepage = "https://github.com/qoco-org/qoco"
24+
Issues = "https://github.com/qoco-org/qoco/issues"

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ install.components = ["python"]
1616
wheel.install-dir = "qoco"
1717

1818
[tool.scikit-build.cmake.define]
19-
QOCO_ALGEBRA_BACKEND = "cuda"
19+
QOCO_ALGEBRA_BACKEND = "builtin"
20+
QOCO_EXT_MODULE_NAME = "qoco_ext"
2021

2122
[project.urls]
2223
Homepage = "https://github.com/qoco-org/qoco"

src/bindings.cpp renamed to src/bindings.cpp.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ QOCOInt PyQOCOSolver::update_settings(const QOCOSettings &new_settings)
241241
return qoco_update_settings(this->_solver, &new_settings);
242242
}
243243

244-
PYBIND11_MODULE(qoco_ext, m)
244+
PYBIND11_MODULE(@QOCO_EXT_MODULE_NAME@, m)
245245
{
246246
// Enums.
247247
py::enum_<qoco_solve_status>(m, "qoco_solve_status", py::module_local())

src/qoco/interface.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,32 @@
55
import numpy as np
66
from scipy import sparse
77
from types import SimpleNamespace
8-
import time
8+
9+
ALGEBRAS = (
10+
"cuda",
11+
"builtin",
12+
)
13+
14+
ALGEBRA_MODULES = {
15+
"cuda": "qoco_cuda",
16+
"builtin": "qoco.qoco_ext",
17+
}
18+
19+
20+
def algebra_available(algebra):
21+
assert algebra in ALGEBRAS, f"Unknown algebra {algebra}"
22+
module = ALGEBRA_MODULES[algebra]
23+
24+
try:
25+
importlib.import_module(module)
26+
except ImportError:
27+
return False
28+
else:
29+
return True
30+
31+
32+
def algebras_available():
33+
return [algebra for algebra in ALGEBRAS if algebra_available(algebra)]
934

1035

1136
class QOCO:
@@ -41,7 +66,10 @@ def __init__(self, *args, **kwargs):
4166
"QOCO_MAX_ITER",
4267
]
4368

44-
self.ext = importlib.import_module("qoco.qoco_ext")
69+
self.algebra = kwargs.pop("algebra") if "algebra" in kwargs else "builtin"
70+
if not algebra_available(self.algebra):
71+
raise RuntimeError(f"Algebra {self.algebra} not available")
72+
self.ext = importlib.import_module(ALGEBRA_MODULES[self.algebra])
4573
self._solver = None
4674

4775
def update_settings(self, **kwargs):

0 commit comments

Comments
 (0)