7.1 Environment and task¶
All interaction with Optimizer API for Python proceeds through one of two entry points: the MOSEK tasks and, to a lesser degree the MOSEK environment .
The MOSEK task
Task provides a representation of one optimization problem. It is the main interface through which all optimization is performed. Many tasks can be created and disposed of in one process.
A typical scenario for working with a task is shown below:
with mosek.Task() as task: # Define and solve an optimization problem here # ...
If a task is created outside of a context that ensures automatic garbage collection then it can be disposed of manually using
The MOSEK environment
Env coordinates access to MOSEK from the current process. It provides various general functionalities, in particular those related to license management, linear algebra, parallel optimization and certain other auxiliary functions. All tasks are explicitly or implicitly attached to some environment. It is recommended to have at most one environment per process.
Creating an environment is optional and only recommended for those users who will require some of the features it provides. Most users will NOT need their own environment and can skip this object. In this case MOSEK will internally create a global environment transparently for the user. This environment will not be accessible for the user.
A typical scenario for working with MOSEK through an explicit environment is shown below:
with mosek.Env() as env: # Create one or more tasks with env.Task() as task: # Define and solve an optimization problem here # ...
If an environment is created outside of a context that ensures automatic garbage collection then it can be disposed of manually using