From d19dc500df6159351653a4e860c7936bc7d866dd Mon Sep 17 00:00:00 2001 From: Xavier Raynaud Date: Fri, 22 Nov 2024 14:09:51 +0100 Subject: [PATCH] added verbose in ServerManager and added an example --- Examples/Julia/runJuliaBridgeExample.m | 7 +++++++ .../JuliaBridge/JuliaInterface/ServerManager.m | 15 +++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 Examples/Julia/runJuliaBridgeExample.m diff --git a/Examples/Julia/runJuliaBridgeExample.m b/Examples/Julia/runJuliaBridgeExample.m new file mode 100644 index 00000000..9e126ca2 --- /dev/null +++ b/Examples/Julia/runJuliaBridgeExample.m @@ -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) diff --git a/Utilities/JuliaBridge/JuliaInterface/ServerManager.m b/Utilities/JuliaBridge/JuliaInterface/ServerManager.m index 873fe418..0e13fae0 100644 --- a/Utilities/JuliaBridge/JuliaInterface/ServerManager.m +++ b/Utilities/JuliaBridge/JuliaInterface/ServerManager.m @@ -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'})); @@ -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 @@ -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 @@ -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 @@ -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 @@ -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); @@ -367,7 +370,7 @@ 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 @@ -375,7 +378,7 @@ function restart(manager, varargin) pause(0.1); end - if manager.options.debug + if manager.options.debug | manager.options.versbose disp("Loading data from object") end