Skip to content

Commit b122cc2

Browse files
authored
Merge pull request #21 from cvxgrp/results_dict
Results dict
2 parents 6461b72 + 8335334 commit b122cc2

File tree

4 files changed

+29
-6
lines changed

4 files changed

+29
-6
lines changed

diffcp/__init__.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
__version__ = "1.0.4"
1+
__version__ = "1.0.7"
22

3-
from diffcp.cone_program import solve_and_derivative, solve_and_derivative_batch, SolverError
3+
from diffcp.cone_program import solve_and_derivative, \
4+
solve_and_derivative_batch, \
5+
solve_and_derivative_internal, SolverError
46
from diffcp.cones import ZERO, POS, SOC, PSD, EXP
57
from diffcp import utils

diffcp/cone_program.py

+21-2
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,18 @@ def solve_and_derivative(A, b, c, cone_dict, warm_start=None, mode='lsqr', **kwa
203203
Raises:
204204
SolverError: if the cone program is infeasible or unbounded.
205205
"""
206+
result = solve_and_derivative_internal(
207+
A, b, c, cone_dict, warm_start=warm_start, mode=mode, **kwargs)
208+
x = result["x"]
209+
y = result["y"]
210+
s = result["s"]
211+
D = result["D"]
212+
DT = result["DT"]
213+
return x, y, s, D, DT
214+
215+
216+
def solve_and_derivative_internal(A, b, c, cone_dict, warm_start=None,
217+
mode='lsqr', raise_on_error=True, **kwargs):
206218
if mode not in ["dense", "lsqr"]:
207219
raise ValueError("Unsupported mode {}; the supported modes are "
208220
"'dense' and 'lsqr'".format(mode))
@@ -225,7 +237,12 @@ def solve_and_derivative(A, b, c, cone_dict, warm_start=None, mode='lsqr', **kwa
225237
if status == "Solved/Inaccurate":
226238
warnings.warn("Solved/Inaccurate.")
227239
elif status != "Solved":
228-
raise SolverError("Solver scs returned status %s" % status)
240+
if raise_on_error:
241+
raise SolverError("Solver scs returned status %s" % status)
242+
else:
243+
result["D"] = None
244+
result["DT"] = None
245+
return result
229246

230247
x = result["x"]
231248
y = result["y"]
@@ -315,4 +332,6 @@ def adjoint_derivative(dx, dy, ds, **kwargs):
315332

316333
return dA, db, dc
317334

318-
return x, y, s, derivative, adjoint_derivative
335+
result["D"] = derivative
336+
result["DT"] = adjoint_derivative
337+
return result

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def get_openmp_flag():
5757

5858
setup(
5959
name='diffcp',
60-
version="1.0.6",
60+
version="1.0.7",
6161
author="Akshay Agrawal, Shane Barratt, Stephen Boyd, Enzo Busseti, Walaa Moursi",
6262
long_description=long_description,
6363
long_description_content_type="text/markdown",

tests.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import unittest
22

3-
import cvxpy as cp
43
import numpy as np
54
from scipy import sparse
65
from scipy.sparse import linalg as splinalg
@@ -80,6 +79,7 @@ def test_proj_pos(self):
8079
p, cone_lib._proj(x, cone_lib.POS, dual=True))
8180

8281
def test_proj_soc(self):
82+
import cvxpy as cp
8383
np.random.seed(0)
8484
n = 100
8585
for _ in range(15):
@@ -96,6 +96,7 @@ def test_proj_soc(self):
9696
p, cone_lib._proj(x, cone_lib.SOC, dual=True))
9797

9898
def test_proj_psd(self):
99+
import cvxpy as cp
99100
np.random.seed(0)
100101
n = 10
101102
for _ in range(15):
@@ -113,6 +114,7 @@ def test_proj_psd(self):
113114
cone_lib._proj(x_vec, cone_lib.PSD, dual=True), n))
114115

115116
def test_proj_exp(self):
117+
import cvxpy as cp
116118
np.random.seed(0)
117119
for _ in range(15):
118120
x = np.random.randn(9)

0 commit comments

Comments
 (0)