Skip to content

Commit d0f3d1b

Browse files
committed
Fix CI on windows and some format
1 parent a427e7a commit d0f3d1b

File tree

9 files changed

+43
-34
lines changed

9 files changed

+43
-34
lines changed

include/pyoptinterface/core.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ enum class ConstraintType
274274
COPT_ExpCone,
275275
COPT_NL,
276276
IPOPT_NL,
277-
Xpress_Nlp
277+
Xpress_Nlp
278278
};
279279

280280
enum class SOSType

include/pyoptinterface/nlexpr.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ enum class BinaryOperator
5555
GreaterThan,
5656

5757
// Compatibility issue where some solvers only accepts two-arg multiplication
58-
Add2,
58+
Add2,
5959
Mul2
6060
};
6161

include/pyoptinterface/xpress_model.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,8 @@ using Callback = std::function<void(Model *, CB_CONTEXT)>; // Callback opaque co
365365
// Xpress to mutex callbacks invocations, so concurrent callback execution isn't an issue.
366366
enum class XPRESS_MODEL_MODE
367367
{
368-
MAIN, // Owns XPRSprob; holds global callback state
369-
CALLBACK, // Non-owning wrapper around Xpress's callback problem clone
368+
MAIN, // Owns XPRSprob; holds global callback state
369+
CALLBACK_, // Non-owning wrapper around Xpress's callback problem clone
370370
};
371371

372372
// Simple conditional struct that define the ret_code field only if it is not void

lib/xpress_model.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
#include <mutex>
99
#include <stack>
1010
#include <stdexcept>
11+
#ifndef _WIN32
1112
#include <unistd.h>
13+
#endif
1214

1315
namespace xpress
1416
{
@@ -356,7 +358,7 @@ XPRSprob Model::_toggle_model_mode(XPRSprob model)
356358
{
357359
if (m_mode == XPRESS_MODEL_MODE::MAIN)
358360
{
359-
m_mode = XPRESS_MODEL_MODE::CALLBACK;
361+
m_mode = XPRESS_MODEL_MODE::CALLBACK_;
360362
}
361363
else
362364
{
@@ -381,7 +383,7 @@ catch (std::exception e)
381383
void Model::close()
382384
{
383385
// In CALLBACK mode we cannot destroy the problem, we release the unique_ptr instead
384-
if (m_mode == XPRESS_MODEL_MODE::CALLBACK)
386+
if (m_mode == XPRESS_MODEL_MODE::CALLBACK_)
385387
{
386388
[[maybe_unused]] auto _ = m_model.release();
387389
}
@@ -557,7 +559,7 @@ std::string Model::pprint_variable(VariableIndex variable)
557559

558560
std::string Model::_get_entity_name(int etype, int eidx)
559561
{
560-
_check_expected_mode(XPRESS_MODEL_MODE::MAIN);
562+
_check_expected_mode(XPRESS_MODEL_MODE::MAIN);
561563
_ensure_postsolved();
562564

563565
int req_size = {};
@@ -2168,12 +2170,12 @@ void Model::_ensure_postsolved()
21682170

21692171
void Model::_check_expected_mode(XPRESS_MODEL_MODE mode)
21702172
{
2171-
if (mode == XPRESS_MODEL_MODE::MAIN && m_mode == XPRESS_MODEL_MODE::CALLBACK)
2173+
if (mode == XPRESS_MODEL_MODE::MAIN && m_mode == XPRESS_MODEL_MODE::CALLBACK_)
21722174
{
21732175
throw std::runtime_error("Cannot call this function from within a callback. "
21742176
"This operation is only available on the main model.");
21752177
}
2176-
if (mode == XPRESS_MODEL_MODE::CALLBACK && m_mode == XPRESS_MODEL_MODE::MAIN)
2178+
if (mode == XPRESS_MODEL_MODE::CALLBACK_ && m_mode == XPRESS_MODEL_MODE::MAIN)
21772179
{
21782180
throw std::runtime_error("This function can only be called from within a callback. "
21792181
"It is not available on the main model.");
@@ -2182,14 +2184,14 @@ void Model::_check_expected_mode(XPRESS_MODEL_MODE mode)
21822184

21832185
xpress_cbs_data Model::cb_get_arguments()
21842186
{
2185-
_check_expected_mode(XPRESS_MODEL_MODE::CALLBACK);
2187+
_check_expected_mode(XPRESS_MODEL_MODE::CALLBACK_);
21862188
return cb_args;
21872189
}
21882190

21892191
// NOTE: XPRSgetcallbacksolution return a context dependent solution
21902192
double Model::_cb_get_context_solution(VariableIndex variable)
21912193
{
2192-
_check_expected_mode(XPRESS_MODEL_MODE::CALLBACK);
2194+
_check_expected_mode(XPRESS_MODEL_MODE::CALLBACK_);
21932195
// Xpress already caches solutions internally
21942196
int p_available = 0;
21952197
int colidx = _checked_variable_index(variable);
@@ -2207,7 +2209,7 @@ double Model::_cb_get_context_solution(VariableIndex variable)
22072209
// otherwise falls back to the current incumbent solution.
22082210
double Model::cb_get_solution(VariableIndex variable)
22092211
{
2210-
_check_expected_mode(XPRESS_MODEL_MODE::CALLBACK);
2212+
_check_expected_mode(XPRESS_MODEL_MODE::CALLBACK_);
22112213
if (cb_where == CB_CONTEXT::intsol || cb_where == CB_CONTEXT::preintsol)
22122214
{
22132215
// Context provides a candidate integer solution - return it directly
@@ -2223,7 +2225,7 @@ double Model::cb_get_solution(VariableIndex variable)
22232225
// chgbranchobject, nodelpsolved, optnode). It throws in other contexts.
22242226
double Model::cb_get_relaxation(VariableIndex variable)
22252227
{
2226-
_check_expected_mode(XPRESS_MODEL_MODE::CALLBACK);
2228+
_check_expected_mode(XPRESS_MODEL_MODE::CALLBACK_);
22272229
if (cb_where != CB_CONTEXT::bariteration && cb_where != CB_CONTEXT::cutround &&
22282230
cb_where != CB_CONTEXT::chgbranchobject && cb_where != CB_CONTEXT::nodelpsolved &&
22292231
cb_where != CB_CONTEXT::optnode)
@@ -2240,13 +2242,13 @@ double Model::cb_get_incumbent(VariableIndex variable)
22402242

22412243
void Model::cb_set_solution(VariableIndex variable, double value)
22422244
{
2243-
_check_expected_mode(XPRESS_MODEL_MODE::CALLBACK);
2245+
_check_expected_mode(XPRESS_MODEL_MODE::CALLBACK_);
22442246
cb_sol_cache.emplace_back(_checked_variable_index(variable), value);
22452247
}
22462248

22472249
void Model::cb_submit_solution()
22482250
{
2249-
_check_expected_mode(XPRESS_MODEL_MODE::CALLBACK);
2251+
_check_expected_mode(XPRESS_MODEL_MODE::CALLBACK_);
22502252

22512253
auto &sol = cb_sol_cache;
22522254
if (sol.empty())
@@ -2276,7 +2278,7 @@ void Model::cb_submit_solution()
22762278

22772279
void Model::cb_exit()
22782280
{
2279-
_check_expected_mode(XPRESS_MODEL_MODE::CALLBACK);
2281+
_check_expected_mode(XPRESS_MODEL_MODE::CALLBACK_);
22802282
_check(XPRSinterrupt(m_model.get(), POI_XPRS_STOP_USER));
22812283
}
22822284

@@ -2326,7 +2328,7 @@ void Model::_cb_add_cut(const ScalarAffineFunction &function, ConstraintSense se
23262328
void Model::cb_add_lazy_constraint(const ScalarAffineFunction &function, ConstraintSense sense,
23272329
CoeffT rhs)
23282330
{
2329-
_check_expected_mode(XPRESS_MODEL_MODE::CALLBACK);
2331+
_check_expected_mode(XPRESS_MODEL_MODE::CALLBACK_);
23302332
if (cb_where != CB_CONTEXT::nodelpsolved && cb_where != CB_CONTEXT::optnode &&
23312333
cb_where != CB_CONTEXT::preintsol && cb_where != CB_CONTEXT::prenode)
23322334
{
@@ -2431,7 +2433,7 @@ struct Model::CbWrap
24312433

24322434
try
24332435
{
2434-
model->_check_expected_mode(XPRESS_MODEL_MODE::CALLBACK);
2436+
model->_check_expected_mode(XPRESS_MODEL_MODE::CALLBACK_);
24352437
model->cb_sol_cache.clear();
24362438
model->cb_where = static_cast<CB_CONTEXT>(Where);
24372439
model->cb_args = &cb_args;

src/pyoptinterface/_src/xpress.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ def get_primalstatus(model):
217217
status = model.get_lp_status()
218218
if status == XPRS.LPSTATUS.OPTIMAL:
219219
return ResultStatusCode.FEASIBLE_POINT
220-
return ResultStatusCode.NO_SOLUTION
220+
return ResultStatusCode.NO_SOLUTION
221221

222222
elif opt_type == XPRS.OPTIMIZETYPE.MIP:
223223
status = model.get_mip_status()
@@ -617,9 +617,7 @@ def add_nl_constraint(self, expr, *args, **kwargs):
617617
graph = ExpressionGraphContext.current_graph()
618618
expr = convert_to_expressionhandle(graph, expr)
619619
if not isinstance(expr, ExpressionHandle):
620-
raise ValueError(
621-
"Expression should be convertible to ExpressionHandle"
622-
)
620+
raise ValueError("Expression should be convertible to ExpressionHandle")
623621

624622
con = self._add_single_nl_constraint(graph, expr, *args, **kwargs)
625623
return con
@@ -628,9 +626,7 @@ def add_nl_objective(self, expr):
628626
graph = ExpressionGraphContext.current_graph()
629627
expr = convert_to_expressionhandle(graph, expr)
630628
if not isinstance(expr, ExpressionHandle):
631-
raise ValueError(
632-
"Expression should be convertible to ExpressionHandle"
633-
)
629+
raise ValueError("Expression should be convertible to ExpressionHandle")
634630
self._add_single_nl_objective(graph, expr)
635631

636632
def set_callback(self, cb, where):

tests/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def nlp_model_ctor(request):
4444
if highs.is_library_loaded():
4545
model_interface_dict["highs"] = highs.Model
4646

47+
4748
@pytest.fixture(params=model_interface_dict.keys())
4849
def model_interface(request):
4950
name = request.param

tests/simple_cb.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import pyoptinterface as poi from pyoptinterface import gurobi, xpress
1+
import pyoptinterface as poi
2+
from pyoptinterface import gurobi, xpress
23

34
GRB = gurobi.GRB
45
XPRS = xpress.XPRS
56

7+
68
def simple_cb(f):
79
model = f()
810

@@ -16,7 +18,9 @@ def simple_cb(f):
1618
model.set_objective(obj, poi.ObjectiveSense.Minimize)
1719

1820
conexpr = x + y
19-
model.add_linear_constraint(conexpr, poi.ConstraintSense.GreaterEqual, 10.0, name="con1")
21+
model.add_linear_constraint(
22+
conexpr, poi.ConstraintSense.GreaterEqual, 10.0, name="con1"
23+
)
2024

2125
def cb(model, where):
2226
runtime = 0.0
@@ -29,14 +33,19 @@ def cb(model, where):
2933
print(f"Runtime: {runtime}, Coldel: {coldel}, Rowdel: {rowdel}")
3034
if isinstance(model, xpress.Model) and where == XPRS.CB_CONTEXT.PRESOLVE:
3135
runtime = model.get_raw_attribute_dbl_by_id(XPRS.TIME)
32-
coldel = model.get_raw_attribute_int_by_id(XPRS.ORIGINALCOLS) - model.get_raw_attribute_int_by_id(XPRS.COLS)
33-
rowdel = model.get_raw_attribute_int_by_id(XPRS.ORIGINALROWS) - model.get_raw_attribute_int_by_id(XPRS.ROWS)
34-
print(f"CB[AFTER-PRESOLVE] >> Runtime: {runtime}, Coldel: {coldel}, Rowdel: {rowdel}")
36+
coldel = model.get_raw_attribute_int_by_id(
37+
XPRS.ORIGINALCOLS
38+
) - model.get_raw_attribute_int_by_id(XPRS.COLS)
39+
rowdel = model.get_raw_attribute_int_by_id(
40+
XPRS.ORIGINALROWS
41+
) - model.get_raw_attribute_int_by_id(XPRS.ROWS)
42+
print(
43+
f"CB[AFTER-PRESOLVE] >> Runtime: {runtime}, Coldel: {coldel}, Rowdel: {rowdel}"
44+
)
3545
if isinstance(model, xpress.Model) and where == XPRS.CB_CONTEXT.MESSAGE:
3646
args = model.cb_get_arguments()
3747
print(f"CB[MESSAGE-{args.msgtype}] >> {args.msg}")
3848

39-
4049
if isinstance(model, gurobi.Model):
4150
model.set_callback(cb)
4251
elif isinstance(model, xpress.Model):

tests/test_close.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
envs.append(mosek.Env)
1616
models.append(mosek.Model)
1717

18+
1819
def test_close():
1920
for env, model in zip(envs, models):
2021
env_instance = env()

tests/test_nlp_expression.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ def test_nlp_expressiontree(model_interface):
2626

2727
x_value = model.get_value(x)
2828
y_value = model.get_value(y)
29-
30-
# Note: with a feasibility tolerance defaulted to 1e-6 + the
29+
30+
# Note: with a feasibility tolerance defaulted to 1e-6 + the
3131
# effect of the internal solver scaling, x and y can assume
3232
# values relatively far away from the expected ones.
33-
# E.g.: x = 1.0005, y = 0.49975
33+
# E.g.: x = 1.0005, y = 0.49975
3434
assert x_value == approx(1.0, rel=1e-2)
3535
assert y_value == approx(0.5, rel=1e-2)
3636

0 commit comments

Comments
 (0)