gemseo / wrappers / matlab

engine module

Definition of the matlab engine singleton for workspace handling.

Overview

This module contains the __MatlabEngine class which enables to build the Matlab workspace. The Matlab workspace must be seen as the Matlab “area” where Matlab functions are executed as well as Matlab variables live. The engine is basically used when creating a MatlabDiscipline instance and therefore is not directly handled by the user. However, a __MatlabEngine instance can be used outside a MatlabDiscipline in order to directly call Matlab functions and/or accessing to some variables into the Matlab workspace.

Since __MatlabEngine is private, it cannot be used directly from the module. It is rather used through the function get_matlab_engine() which enables to create only one instance with respect to the workspace_name (i.e. the instance is unique if the workspace name is the same when calling several times the function). Following this, __MatlabEngine acts like a singleton.

Classes:

ParallelType(value)

Types of Matlab parallel execution.

Functions:

get_matlab_engine([workspace_name])

Return a new matlab engine.

class gemseo.wrappers.matlab.engine.ParallelType(value)[source]

Bases: enum.Enum

Types of Matlab parallel execution.

Attributes:

CLOUD

LOCAL

CLOUD = 'MATLAB Parallel Cloud'
LOCAL = 'local'
gemseo.wrappers.matlab.engine.get_matlab_engine(workspace_name='matlab')[source]

Return a new matlab engine.

LRU cache decorator enables to cache the instance if prescribed workspace_name is the same. Therefore, it acts like a singleton. This means that calling this function with the same workspace_name returns the same instance.

Parameters

workspace_name (str) –

The name of matlab workspace.

By default it is set to matlab.

Returns

A Matlab engine instance.

Return type

gemseo.wrappers.matlab.engine.__MatlabEngine

Examples

>>> eng1 = get_matlab_engine()
>>> eng2 = get_matlab_engine()
>>> # make sure that engines are the same
>>> eng1 is eng2