11"""Runs RAT from the MATLAB API."""
22
3+ import json
34import tempfile
45import warnings
56from pathlib import Path
1415cd('{rat_path}');
1516addPaths;
1617cd(cur_dir);
17-
18+
1819project = jsonToProject('{project}');
1920controls = jsonToControls('{control}');
21+ if any(strcmpi(controls.procedure, {{procedures.DE.value, procedures.Simplex.value}}))
22+ disp("hello")
23+ useLivePlot(1);
24+ end
2025for i=1:project.customFile.rowCount
2126 addpath(project.customFile.varTable{{i, 5}});
2227end
2328[project, results] = RAT(project, controls);
2429
2530projectToJson(project, '{project}');
2631resultsToJson(results, '{result}');
32+ close all
2733end
2834"""
2935
3036
31- def run_matlab_directly (project , controls , matlab_rat_path ):
37+ def run_matlab_directly (project , controls , matlab_rat_path , stdout = None , stderr = None ):
3238 """Run User provided MATLAB RAT for the given project and controls inputs.
3339
3440 Parameters
3541 ----------
36- project : RAT.Project
37- The project model, which defines the physical system under study.
38- controls : RAT.Controls
39- The controls model, which defines algorithmic properties.
42+ project : RAT.Project or dict
43+ The project model (or equivalent json dict) , which defines the physical system under study.
44+ controls : RAT.Controls or dict
45+ The controls model (or equivalent json dict) , which defines algorithmic properties.
4046 matlab_rat_path : str
4147 The path to MATLAB RAT folder.
48+ stdout : io.TextIOBase, optional
49+ Text stream for MATLAB console output
50+ stderr : io.TextIOBase, optional
51+ Text stream for MATLAB console error output
4252 """
4353 if MatlabWrapper .loader is None :
4454 raise ImportError (MatlabWrapper .loader_error_message ) from None
@@ -56,13 +66,16 @@ def run_matlab_directly(project, controls, matlab_rat_path):
5666 RUNNER .format (project = project_file , control = control_file , result = result_file , rat_path = matlab_rat_path )
5767 )
5868
69+ controls .save (control_file ) if not isinstance (controls , dict ) else control_file .write_text (json .dumps (controls ))
70+
5971 with warnings .catch_warnings (): # Avoid warning about relative paths
6072 warnings .simplefilter ("ignore" )
61- project .save (project_file )
62- controls .save (control_file )
73+ project .save (project_file ) if not isinstance (project , dict ) else project_file .write_text (
74+ json .dumps (project )
75+ )
6376
6477 engine .addpath (tmp , nargout = 0 )
65- engine .executeRAT (nargout = 0 )
78+ engine .executeRAT (nargout = 0 , stdout = stdout , stderr = stderr )
6679 engine .rmpath (tmp , nargout = 0 )
6780
6881 project = Project .load (project_file )
0 commit comments