Skip to content

Commit 319af54

Browse files
committed
Format
1 parent 38224e8 commit 319af54

File tree

6 files changed

+93
-35
lines changed

6 files changed

+93
-35
lines changed

include/pyoptinterface/knitro_model.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ struct CallbackEvaluator
228228
x[i] = req_x[indexVars[i]];
229229
}
230230
fun.sparse_jac_rev(x, jac_, jac_pattern_, jac_coloring_, jac_work_);
231-
auto& jac = jac_.val();
231+
auto &jac = jac_.val();
232232
for (size_t i = 0; i < jac_.nnz(); i++)
233233
{
234234
res_jac[i] = jac[i];
@@ -253,7 +253,7 @@ struct CallbackEvaluator
253253
}
254254
}
255255
fun.sparse_hes(x, w, hess_, hess_pattern_, hess_coloring_, hess_work_);
256-
auto& hess = hess_.val();
256+
auto &hess = hess_.val();
257257
for (size_t i = 0; i < hess_.nnz(); i++)
258258
{
259259
res_hess[i] = hess[i];
@@ -265,8 +265,8 @@ struct CallbackEvaluator
265265
CallbackPattern pattern;
266266
pattern.indexCons = indexCons;
267267

268-
auto& jac_rows = jac_pattern_.row();
269-
auto& jac_cols = jac_pattern_.col();
268+
auto &jac_rows = jac_pattern_.row();
269+
auto &jac_cols = jac_pattern_.col();
270270
if (indexCons.empty())
271271
{
272272
for (size_t k = 0; k < jac_pattern_.nnz(); k++)
@@ -283,8 +283,8 @@ struct CallbackEvaluator
283283
}
284284
}
285285

286-
auto& hess_rows = hess_pattern_symm_.row();
287-
auto& hess_cols = hess_pattern_symm_.col();
286+
auto &hess_rows = hess_pattern_symm_.row();
287+
auto &hess_cols = hess_pattern_symm_.col();
288288
for (size_t k = 0; k < hess_pattern_symm_.nnz(); k++)
289289
{
290290
pattern.hessIndexVars1.push_back(indexVars[hess_rows[k]]);

lib/cppad_interface_ext.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ NB_MODULE(cppad_interface_ext, m)
183183
.def_ro("hessian", &CppADAutodiffGraph::hessian_graph);
184184

185185
m.def("cppad_trace_graph_constraints", cppad_trace_graph_constraints);
186-
m.def("cppad_trace_graph_objective", cppad_trace_graph_objective, nb::arg("graph"), nb::arg("aggregate") = true);
186+
m.def("cppad_trace_graph_objective", cppad_trace_graph_objective, nb::arg("graph"),
187+
nb::arg("aggregate") = true);
187188
m.def("cppad_autodiff", &cppad_autodiff);
188189
}

lib/knitro_model.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1031,7 +1031,6 @@ void KNITROModel::_init()
10311031
m_kc = std::unique_ptr<KN_context, KNITROFreeProblemT>(kc);
10321032
}
10331033

1034-
10351034
KNINT KNITROModel::_variable_index(const VariableIndex &variable) const
10361035
{
10371036
return _get_index(variable);

lib/knitro_model_ext.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ NB_MODULE(knitro_model_ext, m)
2828
nb::class_<KNITROModel>(m, "RawModel")
2929
.def(nb::init<>())
3030
.def(nb::init<const KNITROEnv &>())
31-
.def("init", nb::overload_cast<>(&KNITROModel::init))
32-
.def("init", nb::overload_cast<const KNITROEnv &>(&KNITROModel::init))
33-
// clang-format off
31+
.def("init", nb::overload_cast<>(&KNITROModel::init))
32+
.def("init", nb::overload_cast<const KNITROEnv &>(&KNITROModel::init))
33+
// clang-format off
3434
BIND_F(close)
3535
BIND_F(get_infinity)
3636
BIND_F(get_number_iterations)
@@ -161,8 +161,8 @@ NB_MODULE(knitro_model_ext, m)
161161
nb::arg("expr"), nb::arg("sense") = ObjectiveSense::Minimize)
162162
.def("_add_single_nl_objective", &KNITROModel::add_single_nl_objective, nb::arg("graph"),
163163
nb::arg("result"))
164-
.def("set_objective_coefficient", &KNITROModel::set_objective_coefficient, nb::arg("variable"),
165-
nb::arg("coefficient"))
164+
.def("set_objective_coefficient", &KNITROModel::set_objective_coefficient,
165+
nb::arg("variable"), nb::arg("coefficient"))
166166

167167
// clang-format off
168168
BIND_F(get_obj_value)
@@ -237,9 +237,9 @@ NB_MODULE(knitro_model_ext, m)
237237
BIND_F(empty)
238238
// clang-format on
239239

240-
// clang-format off
240+
// clang-format off
241241
BIND_F(get_solve_status)
242-
// clang-format on
242+
// clang-format on
243243
;
244244

245245
#undef BIND_F

src/pyoptinterface/_src/knitro.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ class Env(RawEnv):
263263
"""
264264
KNITRO license manager environment.
265265
"""
266+
266267
@property
267268
def is_empty(self):
268269
return self.empty()

tests/test_knitro.py

Lines changed: 77 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from pyoptinterface import knitro
55
import pyoptinterface as poi
66

7-
87
pytestmark = pytest.mark.skipif(
98
not knitro.is_library_loaded(), reason="KNITRO library is not loaded"
109
)
@@ -166,6 +165,7 @@ def test_model_init_with_empty_env_after_start():
166165
env.start()
167166
assert knitro.Model(env=env) is not None
168167

168+
169169
def test_model_dirty():
170170
"""Test the dirty method."""
171171
model = knitro.Model()
@@ -256,20 +256,63 @@ def test_number_of_constraints():
256256
def test_supports_attribute_methods():
257257
"""Test supports_*_attribute() static methods."""
258258
assert knitro.Model.supports_variable_attribute(poi.VariableAttribute.Value) is True
259-
assert knitro.Model.supports_variable_attribute(poi.VariableAttribute.LowerBound) is True
260-
assert knitro.Model.supports_variable_attribute(poi.VariableAttribute.LowerBound, setable=True) is True
261-
assert knitro.Model.supports_variable_attribute(poi.VariableAttribute.Value, setable=True) is False
262-
263-
assert knitro.Model.supports_constraint_attribute(poi.ConstraintAttribute.Primal) is True
264-
assert knitro.Model.supports_constraint_attribute(poi.ConstraintAttribute.Name) is True
265-
assert knitro.Model.supports_constraint_attribute(poi.ConstraintAttribute.Name, setable=True) is True
266-
267-
assert knitro.Model.supports_model_attribute(poi.ModelAttribute.ObjectiveValue) is True
259+
assert (
260+
knitro.Model.supports_variable_attribute(poi.VariableAttribute.LowerBound)
261+
is True
262+
)
263+
assert (
264+
knitro.Model.supports_variable_attribute(
265+
poi.VariableAttribute.LowerBound, setable=True
266+
)
267+
is True
268+
)
269+
assert (
270+
knitro.Model.supports_variable_attribute(
271+
poi.VariableAttribute.Value, setable=True
272+
)
273+
is False
274+
)
275+
276+
assert (
277+
knitro.Model.supports_constraint_attribute(poi.ConstraintAttribute.Primal)
278+
is True
279+
)
280+
assert (
281+
knitro.Model.supports_constraint_attribute(poi.ConstraintAttribute.Name) is True
282+
)
283+
assert (
284+
knitro.Model.supports_constraint_attribute(
285+
poi.ConstraintAttribute.Name, setable=True
286+
)
287+
is True
288+
)
289+
290+
assert (
291+
knitro.Model.supports_model_attribute(poi.ModelAttribute.ObjectiveValue) is True
292+
)
268293
assert knitro.Model.supports_model_attribute(poi.ModelAttribute.SolverName) is True
269-
assert knitro.Model.supports_model_attribute(poi.ModelAttribute.Silent, setable=True) is True
270-
assert knitro.Model.supports_model_attribute(poi.ModelAttribute.ObjectiveValue, setable=True) is False
271-
assert knitro.Model.supports_model_attribute(poi.ModelAttribute.NumberOfThreads, setable=True) is True
272-
assert knitro.Model.supports_model_attribute(poi.ModelAttribute.TimeLimitSec, setable=True) is True
294+
assert (
295+
knitro.Model.supports_model_attribute(poi.ModelAttribute.Silent, setable=True)
296+
is True
297+
)
298+
assert (
299+
knitro.Model.supports_model_attribute(
300+
poi.ModelAttribute.ObjectiveValue, setable=True
301+
)
302+
is False
303+
)
304+
assert (
305+
knitro.Model.supports_model_attribute(
306+
poi.ModelAttribute.NumberOfThreads, setable=True
307+
)
308+
is True
309+
)
310+
assert (
311+
knitro.Model.supports_model_attribute(
312+
poi.ModelAttribute.TimeLimitSec, setable=True
313+
)
314+
is True
315+
)
273316

274317

275318
def test_model_attribute_solver_info():
@@ -334,11 +377,21 @@ def test_set_model_attribute_objective_sense():
334377
model = knitro.Model()
335378
model.add_variable(lb=0.0, ub=10.0)
336379

337-
model.set_model_attribute(poi.ModelAttribute.ObjectiveSense, poi.ObjectiveSense.Maximize)
338-
assert model.get_model_attribute(poi.ModelAttribute.ObjectiveSense) == poi.ObjectiveSense.Maximize
380+
model.set_model_attribute(
381+
poi.ModelAttribute.ObjectiveSense, poi.ObjectiveSense.Maximize
382+
)
383+
assert (
384+
model.get_model_attribute(poi.ModelAttribute.ObjectiveSense)
385+
== poi.ObjectiveSense.Maximize
386+
)
339387

340-
model.set_model_attribute(poi.ModelAttribute.ObjectiveSense, poi.ObjectiveSense.Minimize)
341-
assert model.get_model_attribute(poi.ModelAttribute.ObjectiveSense) == poi.ObjectiveSense.Minimize
388+
model.set_model_attribute(
389+
poi.ModelAttribute.ObjectiveSense, poi.ObjectiveSense.Minimize
390+
)
391+
assert (
392+
model.get_model_attribute(poi.ModelAttribute.ObjectiveSense)
393+
== poi.ObjectiveSense.Minimize
394+
)
342395

343396

344397
def test_set_model_attribute_silent():
@@ -434,7 +487,9 @@ def test_variable_attribute_domain():
434487
model = knitro.Model()
435488
x = model.add_variable(lb=0.0, ub=10.0)
436489

437-
model.set_variable_attribute(x, poi.VariableAttribute.Domain, poi.VariableDomain.Integer)
490+
model.set_variable_attribute(
491+
x, poi.VariableAttribute.Domain, poi.VariableDomain.Integer
492+
)
438493

439494
model.set_objective(x, poi.ObjectiveSense.Minimize)
440495
model.add_linear_constraint(x, poi.ConstraintSense.GreaterEqual, 2.5)
@@ -448,7 +503,9 @@ def test_constraint_attribute_name():
448503
model = knitro.Model()
449504
x = model.add_variable(lb=0.0, ub=10.0)
450505

451-
con = model.add_linear_constraint(x, poi.ConstraintSense.LessEqual, 5.0, name="my_con")
506+
con = model.add_linear_constraint(
507+
x, poi.ConstraintSense.LessEqual, 5.0, name="my_con"
508+
)
452509

453510
name = model.get_constraint_attribute(con, poi.ConstraintAttribute.Name)
454511
assert name == "my_con"

0 commit comments

Comments
 (0)