Skip to content

Commit

Permalink
Merge pull request #51 from cvxgrp/ms/clarabel-update-logic
Browse files Browse the repository at this point in the history
Adjusted Clarabel update logic
  • Loading branch information
maxschaller authored May 8, 2024
2 parents e1e2f0d + 54d657a commit bac4c2e
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 6 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]
os: [ ubuntu-latest, macos-13, windows-latest ]

steps:
- name: Checkout repository and submodules
Expand Down Expand Up @@ -62,9 +62,9 @@ jobs:
- name: Test with pytest (macOS)
if: runner.os == 'macOS'
run: |
sudo conda install pytest
pip install pytest
cd tests
$CONDA/bin/pytest
python -m pytest
- name: Test with pytest (Windows)
if: runner.os == 'Windows'
Expand Down
24 changes: 22 additions & 2 deletions cvxpygen/solvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -923,22 +923,42 @@ def __init__(self, data, p_prob, enable_settings):
P_p = f'(cpg_int[]){{{{ {", ".join(["0"]*(n_var+1))} }}}}'
P_i = '0'
P_x = '0'
update_after_init = ['A', 'q', 'b']
else:
extra_condition = '!{prefix}solver'
P_p = '{prefix}Canon_Params_conditioning.P->p'
P_i = '{prefix}Canon_Params_conditioning.P->i'
P_x = '{prefix}Canon_Params_conditioning.P->x'
update_after_init = ['P', 'A', 'q', 'b']

self.parameter_update_structure = {
'init': ParameterUpdateLogic(
update_pending_logic=UpdatePendingLogic([], extra_condition=extra_condition, functions_if_false=[]),
update_pending_logic=UpdatePendingLogic([], extra_condition=extra_condition, functions_if_false=update_after_init),
function_call= \
f'{{prefix}}cpg_copy_all();\n'
f' clarabel_CscMatrix_init(&{{prefix}}P, {canon_constants["n"]}, {canon_constants["n"]}, {P_p}, {P_i}, {P_x});\n'
f' clarabel_CscMatrix_init(&{{prefix}}A, {canon_constants["m"]}, {canon_constants["n"]}, {{prefix}}Canon_Params_conditioning.A->p, {{prefix}}Canon_Params_conditioning.A->i, {{prefix}}Canon_Params_conditioning.A->x);\n' \
f' {{prefix}}settings = clarabel_DefaultSettings_default()'
)
),
'A': ParameterUpdateLogic(
update_pending_logic = UpdatePendingLogic(['A']),
function_call = f'{{prefix}}cpg_copy_A();\n clarabel_CscMatrix_init(&{{prefix}}A, {canon_constants["m"]}, {canon_constants["n"]}, {{prefix}}Canon_Params_conditioning.A->p, {{prefix}}Canon_Params_conditioning.A->i, {{prefix}}Canon_Params_conditioning.A->x)'
),
'q': ParameterUpdateLogic(
update_pending_logic = UpdatePendingLogic(['q']),
function_call = f'{{prefix}}cpg_copy_q()'
),
'b': ParameterUpdateLogic(
update_pending_logic = UpdatePendingLogic(['b']),
function_call = f'{{prefix}}cpg_copy_b()'
),
}

if indices_obj is not None:
self.parameter_update_structure['P'] = ParameterUpdateLogic(
update_pending_logic = UpdatePendingLogic(['P']),
function_call = f'{{prefix}}cpg_copy_P();\n clarabel_CscMatrix_init(&{{prefix}}P, {canon_constants["n"]}, {canon_constants["n"]}, {P_p}, {P_i}, {P_x})'
)

self.solve_function_call = \
f'{{prefix}}solver = clarabel_DefaultSolver_new(&{{prefix}}P, {{prefix}}Canon_Params_conditioning.q, &{{prefix}}A, {{prefix}}Canon_Params_conditioning.b, {canon_constants["n_cone_types"]}, {{prefix}}cones, &{{prefix}}settings);\n' \
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

MAJOR = 0
MINOR = 3
MICRO = 4
MICRO = 5
VERSION = '%d.%d.%d' % (MAJOR, MINOR, MICRO)


Expand Down
1 change: 1 addition & 0 deletions tests/test_E2E_LP.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,4 @@ def test(name, solver, style, seed):

def test_clarabel():
test('network', 'CLARABEL', 'loops', 0)
test('network', 'CLARABEL', 'loops', 1)
1 change: 1 addition & 0 deletions tests/test_E2E_QP.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,4 @@ def test_OSQP_verbose():

def test_clarabel():
test('actuator', 'CLARABEL', 'loops', 0)
test('actuator', 'CLARABEL', 'loops', 1)
1 change: 1 addition & 0 deletions tests/test_E2E_SOCP.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,4 @@ def test(name, solver, style, seed):

def test_clarabel():
test('ADP', 'CLARABEL', 'loops', 0)
test('ADP', 'CLARABEL', 'loops', 1)

0 comments on commit bac4c2e

Please sign in to comment.