Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ build/
__pycache__/
qoco_custom*/
src/bindings.cpp
dist/
dist/
myvenv
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ list(APPEND CMAKE_MESSAGE_INDENT " ")
include(FetchContent)
FetchContent_Declare(
qoco
GIT_REPOSITORY https://github.com/qoco-org/qoco.git
GIT_TAG 25ee8d63f1a96ffe96c5162089bd746b5947a282
#GIT_REPOSITORY https://github.com/qoco-org/qoco.git
# GIT_TAG 25ee8d63f1a96ffe96c5162089bd746b5947a282
GIT_REPOSITORY https://github.com/JonasBreuling/qoco.git
GIT_TAG main
)

list(POP_BACK CMAKE_MESSAGE_INDENT)
Expand Down
60 changes: 60 additions & 0 deletions examples/simple_socp1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import qoco
import numpy as np
from scipy import sparse


if __name__ == "__main__":
# Define problem data
P = sparse.diags([1, 2, 3, 4, 5, 6], 0, dtype=None)
P = P.tocsc()

c = np.array([1, 2, 3, 4, 5, 6], dtype=float)
G = -sparse.identity(6)
G = G.tocsc()
h = np.zeros(6)
A = sparse.csc_matrix([[1, 1, 0, 0, 0, 0], [0, 1, 2, 0, 0, 0]])
A = A.tocsc()
b = np.array([1, 2])

l = 3
n = 6
m = 6
p = 2
nsoc = 1
q = np.array([3], dtype=float)

# Create an QOCO object.
prob = qoco.QOCO()

# Setup workspace.
prob.setup(n, m, p, P, c, A, b, G, h, l, nsoc, q)

# Solve problem.
res = prob.solve()

opt_obj = 4.042
assert res.status == "QOCO_SOLVED"
assert abs(res.obj - opt_obj) <= 1e-4

# solve regularized KKT system with the existing LDL factorization
rhs = np.ones(prob.n + prob.m + prob.p)
sol = prob.solve_kkt(rhs)

# multiply original KKT matrix by some vector
product = prob.kkt_multiply(sol)
assert np.allclose(product, rhs, atol=1e-8)

# print("res.x:", res.x)
print("sol:", sol)
print("KKT @ sol:", product)
print("res:", res)

# possibly update settings
prob.update_settings(max_iters=1000, tol=1e-8)

# update vector data and solve KKT system again
# (None means that the corresponding data is not updated)
prob.update_vector_data(c=None, h=h + 1, b=None)
res = prob.solve()
print("res:", res)

Loading