Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 45 additions & 5 deletions Utilities/ComputationalGraph/ComputationalGraphInteractiveTool.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,23 @@

plotOptions

interactiveOptions

end

methods

function cgti = ComputationalGraphInteractiveTool(cg, varargin)

opt = struct('markStatic', true);
opt = struct('markStatic', true, ...
'interactiveOptions', []);
opt = merge_options(opt, varargin{:});

interactiveOptions = setDefaultJsonStructField(opt.interactiveOptions, {'printStackSelectionAfterUpdate', 'position'}, 'before');
interactiveOptions = setDefaultJsonStructField(interactiveOptions, 'plotAfterUpdate', true);

cgti.interactiveOptions = interactiveOptions;

cgti.computationalGraph = cg;

nodenames = cg.nodenames;
Expand Down Expand Up @@ -935,6 +943,7 @@ function diff(cgti)

varnames = varnameset{2};

familyvarnames = {};
for ivar = 1 : numel(varnames)

varname = varnames{ivar};
Expand All @@ -946,12 +955,12 @@ function diff(cgti)

varnameinds = varnameinds(levels <= level);

varnames = union(varnames, cg.nodenames(varnameinds));
familyvarnames = union(familyvarnames, cg.nodenames(varnameinds));


end

selection = {'set', varnames};
selection = {'set', familyvarnames};
return

case 'diff'
Expand All @@ -977,6 +986,24 @@ function diff(cgti)
function printStack(cgti)

stack = cgti.stack;

doplot = getJsonStructField(cgti.interactiveOptions, {'plotAfterUpdate'}, false);

if doplot
cgti.plot();
end

position = getJsonStructField(cgti.interactiveOptions, {'printStackSelectionAfterUpdate', 'position'});

if isAssigned(position) && strcmp(position, 'before')

cgti.printHeader('Selection')
cgti.printStackSelection();
fprintf('\n');

end

cgti.printHeader('Selector stack');
for iselector = numel(stack) : -1 : 1
lines = cgti.setupSelectorPrint(stack{iselector});
nlines = numel(lines);
Expand All @@ -989,6 +1016,14 @@ function printStack(cgti)
fprintf('%s%s\n', start, lines{iline});
end
end

if isAssigned(position) && strcmp(position, 'after')

fprintf('\n');
cgti.printHeader('Stack selection result after parsing')
cgti.printStackSelection();

end

end

Expand Down Expand Up @@ -1273,8 +1308,13 @@ function printFunctionDocs(functionDocs, parfill, oneline)
end

function printHeader(headertxt, n)
% Minor utility function used in this class to print a header with a number
str = sprintf('\n%d %s', n, headertxt);
% Minor utility function used in this class to print a header. The optional argument n can be used to include a
% number at the beginning of the header (often needed).
if nargin < 2
str = sprintf('\n%s', headertxt);
else
str = sprintf('\n%d %s', n, headertxt);
end
fprintf('%s:\n', str);
fprintf('%s\n', repmat('-', length(str), 1));
end
Expand Down
118 changes: 109 additions & 9 deletions Utilities/Various/BatchProcessor.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
classdef BatchProcessor
classdef BatchProcessor < Selector

%{
Copyright 2021-2024 SINTEF Industry, Sustainable Energy Technology
Expand All @@ -21,12 +21,17 @@
%}

properties

paramnames

end

methods

function bp = BatchProcessor(varargin)

bp = bp@Selector();

bp.paramnames = {};
if nargin > 0
simlist = varargin{1};
Expand Down Expand Up @@ -246,7 +251,8 @@ function assertParam(bp, paramname)
assert(ismember(paramname, bp.paramnames), sprintf('parameter %s not registered', paramname));
end

function printSimList(bp, simlist, varargin)
function print(bp, simlist, varargin)

[T, singlevalued] = bp.setupTable(simlist);
if nargin > 2 && strcmp(varargin{1}, 'all')
paramnames = bp.paramnames;
Expand Down Expand Up @@ -283,7 +289,7 @@ function printSimList(bp, simlist, varargin)
if numel(paramnames) == 0
if numel(simlist) > 1
% we print all the parameters instead of empty table
printSimList(bp, simlist, 'all');
bp.print(simlist, 'all');
else
simlist{1}
end
Expand All @@ -292,7 +298,7 @@ function printSimList(bp, simlist, varargin)
end
end

function sortedsimlist = sortSimList(bp, simlist, varargin)
function sortedsimlist = sort(bp, simlist, varargin)
paramname = varargin{end};
rest = varargin(1 : end - 1);

Expand Down Expand Up @@ -351,10 +357,10 @@ function printSimList(bp, simlist, varargin)
[bp, simlist] = bp.mergeSimLists(simlist, simlist_to_merge);

end


function filteredsimlist = filterSimList(bp, simlist, varargin)

function filteredsimlist = filter(bp, simlist, varargin)
assert(mod(numel(varargin), 2) == 0, 'wrong number of argument')

filteredsimlist = {};
paramname = varargin{1};
filter = varargin{2};
Expand Down Expand Up @@ -394,8 +400,102 @@ function printSimList(bp, simlist, varargin)
if ~isempty(rest)
filteredsimlist = bp.filterSimList(filteredsimlist, rest{:});
end
end

end


%%%%%%%%%%%%
%% Selector class overloaded function
%%%%%%%%%%%%%%

function str = selectSelectorToString(slt, selectSelector)
% Returns the printed form of a 'select' selector

assert(strcmp(selectSelector{1}, 'select'), 'this is not a select type selector');
selector_type = selectSelector{2}{1};
selector_value = selectSelector{2}{2};

if isa(selector_value, 'function_handle')
selector_value = func2str(selector_value);
end

str = sprintf('%s : %s', selector_type, selector_value);

end

function printSelection(slt, givenset, selection)

if ~strcmp(selection{1}, 'set')
selection = slt.parseSelector(givenset, selection);
end

inds = selection{2};

simlist = givenset(inds);

printall = getStructField(slt.interactiveOptions, {'printSelection', 'all'}, true);

if printall
slt.print(simlist, 'all');
else
slt.print(simlist, 'all');
end

end

function found = find(slt, givenset, selector)

paramname = selector{1};
filter = selector{2};

found = [];

for ielt = 1 : numel(givenset)

elt = givenset{ielt};

paramnames = fieldnames(elt);

indparams = regexpSelect(paramnames, paramname);

for iindparams = 1 : numel(indparams)

indparam = indparams(iindparams);

paramval = elt.(paramnames{indparam});

take = false;

if (isempty(filter) | strcmp(filter, 'undefined'))
if isempty(paramval)
take = true;
end
elseif isa(filter, 'numeric') || isa(filter, 'logical')
if paramval == filter
take = true;
end
elseif isa(filter, 'char')
if strcmp(paramval, filter)
take = true;
end
elseif isa(filter, 'function_handle')
if filter(paramval)
take = true;
end
else
error('filter type not recognized');
end
if take == true
found(end + 1) = ielt;
end
end

end

found = unique(found);

end


end

methods(Static)
Expand Down
Loading