Skip to content

Commit

Permalink
added verbose in ServerManager and added an example
Browse files Browse the repository at this point in the history
  • Loading branch information
xavierr committed Nov 22, 2024
1 parent 4366d3d commit d19dc50
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
7 changes: 7 additions & 0 deletions Examples/Julia/runJuliaBridgeExample.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
jsonfilename = fullfile(battmoDir(), 'Examples', 'JsonDataFiles', 'p2d_40.json');
jsonstruct = parseBattmoJson(jsonfilename);

% The server should be start only once.
man = ServerManager();

output = man.runBatteryJson(jsonstruct)
15 changes: 9 additions & 6 deletions Utilities/JuliaBridge/JuliaInterface/ServerManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
addParameter(p , 'cwd' , serverFolder, @ischar);
addParameter(p , 'port' , 3000 , @(x) validateattributes(x, {'numeric'}, {'scalar', 'integer', 'positive'}));
addParameter(p , 'shared' , true , @(x) validateattributes(x, {'logical'}, {'scalar'}));
addParameter(p , 'verbose' , true , @(x) validateattributes(x, {'logical'}, {'scalar'}));
addParameter(p , 'print_stack' , true , @(x) validateattributes(x, {'logical'}, {'scalar'}));
addParameter(p , 'async' , true , @(x) validateattributes(x, {'logical'}, {'scalar'}));
addParameter(p , 'gc' , true , @(x) validateattributes(x, {'logical'}, {'scalar'}));
Expand Down Expand Up @@ -173,7 +174,7 @@ function load(manager, varargin)
' -load ' , ...
loadingDataFilename];

if manager.options.debug
if manager.options.debug | manager.options.verbose
fprintf("Loading data into Julia \n")
end

Expand All @@ -193,7 +194,7 @@ function load(manager, varargin)
' -run ' , ...
outputFileName];

if manager.options.debug
if manager.options.debug | manager.options.verbose
fprintf("Calling run battery \n")
end

Expand Down Expand Up @@ -287,7 +288,7 @@ function startup(manager)
% ', async=' , ...
% jl_bool(manager.options.async) , ...

if manager.options.debug
if manager.options.debug | manager.options.verbose
fprintf("Starting Julia server \n")
end

Expand All @@ -314,7 +315,7 @@ function shutdown(manager)
[st, result] = system(cmd);
assert(st == 0, "System call failed: \n %s \nSystem call returned:\n %s\n", cmd, result);

if manager.options.debug
if manager.options.debug | manager.options.verbose
fprintf("Shutting down server \n");
end

Expand All @@ -335,6 +336,8 @@ function restart(manager, varargin)

if manager.options.debug
fprintf("Call to julia: %s \n", cmd);
elseif manager.options.verbose
fprintf("Call to julia (It will take time the first time due to just in time compilation)\n");
end

[st, result] = system(cmd);
Expand Down Expand Up @@ -367,15 +370,15 @@ function restart(manager, varargin)
function result = collect_results(manager, f, index)
% Collect results from a Futures object at given indices

if manager.options.debug
if manager.options.debug | manager.options.verbose
disp("Waiting for futures object to finish...")
end

while isprop(f, 'State') && f.State == "running"
pause(0.1);
end

if manager.options.debug
if manager.options.debug | manager.options.versbose
disp("Loading data from object")
end

Expand Down

0 comments on commit d19dc50

Please sign in to comment.