@@ -313,6 +313,62 @@ def test_conic_duals(self):
313313 results .Solution .constraint ['x11' ]['Dual' ][i ], check [i ], 5
314314 )
315315
316+ def test_solver_parameters (self ):
317+ import mosek
318+
319+ solver = pyo .SolverFactory ('mosek_direct' )
320+ model = self ._test_model ()
321+ solver .solve (
322+ model ,
323+ options = {
324+ 'dparam.optimizer_max_time' : 1.0 ,
325+ 'iparam.intpnt_solve_form' : mosek .solveform .dual ,
326+ 'mosek.iparam.intpnt_max_iterations' : 10 ,
327+ 'MSK_DPAR_INTPNT_CO_TOL_REL_GAP' : '1.0e-7' ,
328+ 'MSK_IPAR_PRESOLVE_USE' : '0' ,
329+ 'sparam.param_comment_sign' : '##' ,
330+ },
331+ )
332+ # Check if iparams were set correctly
333+ self .assertEqual (
334+ solver ._solver_model .getintparam (mosek .iparam .intpnt_solve_form ),
335+ mosek .solveform .dual ,
336+ )
337+ self .assertEqual (
338+ solver ._solver_model .getintparam (mosek .iparam .intpnt_max_iterations ), 10
339+ )
340+ self .assertEqual (
341+ solver ._solver_model .getintparam (mosek .iparam .presolve_use ),
342+ mosek .presolvemode .off ,
343+ )
344+ # Check if dparams were set correctly
345+ self .assertEqual (
346+ solver ._solver_model .getdouparam (mosek .dparam .optimizer_max_time ), 1.0
347+ )
348+ self .assertEqual (
349+ solver ._solver_model .getdouparam (mosek .dparam .intpnt_co_tol_rel_gap ), 1.0e-7
350+ )
351+ # Check if sparam is set correctly
352+ self .assertEqual (
353+ solver ._solver_model .getstrparam (mosek .sparam .param_comment_sign )[1 ], '##'
354+ )
355+ # Check for TypeErrors
356+ with self .assertRaises (TypeError ) as typeCheck :
357+ solver .solve (model , options = {'mosek.dparam.intpnt_co_tol_rel_gap' : '1.4' })
358+ with self .assertRaises (TypeError ) as typeCheck :
359+ solver .solve (model , options = {'iparam.log' : 1.2 })
360+ # Check for AttributeError
361+ with self .assertRaises (AttributeError ) as assertCheck :
362+ solver .solve (model , options = {'wrong.name' : '1' })
363+ with self .assertRaises (AttributeError ) as typeCheck :
364+ solver .solve (model , options = {'mosek.iparam.log' : 'mosek.wrong.input' })
365+ # Check for wrong parameter name (but valid MOSEK attribute)
366+ with self .assertRaises (ValueError ) as typeCheck :
367+ solver .solve (model , options = {'mosek.mark.up' : 'wrong.val' })
368+ # Check for parameter names with wrong length
369+ with self .assertRaises (AssertionError ) as typeCheck :
370+ solver .solve (model , options = {'mosek.iparam.log.level' : 10 })
371+
316372
317373if __name__ == "__main__" :
318374 unittest .main ()
0 commit comments