Skip to content

Commit

Permalink
1.2.16
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdecyphir committed Mar 28, 2018
1 parent f5e8017 commit 42a9118
Show file tree
Hide file tree
Showing 26 changed files with 280 additions and 190 deletions.
16 changes: 12 additions & 4 deletions @STL_Formula/STL_EvalThom.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,12 @@
% all subsequent computations

global BreachGlobOpt;
BreachGlobOpt.GlobVarsDeclare = ['global ', sprintf('%s ',P.ParamList{:})]; % contains parameters and IC values (can remove IC if phi is optimized)
eval(BreachGlobOpt.GlobVarsDeclare); % These values may be used in generic_predicate and GetValues
if ~isempty(P.ParamList)
BreachGlobOpt.GlobVarsDeclare = ['global ', sprintf('%s ',P.ParamList{:})]; % contains parameters and IC values (can remove IC if phi is optimized)
eval(BreachGlobOpt.GlobVarsDeclare); % These values may be used in generic_predicate and GetValues
else
BreachGlobOpt.GlobVarsDeclare = ''; % contains parameters and IC values (can remove IC if phi is optimized)
end

ii=1;
eval_str = [P.ParamList;num2cell(1:numel(P.ParamList))];
Expand Down Expand Up @@ -94,7 +98,11 @@
if(numel(t)==1) % we handle singular times
val__{ii} = val(1);
else
val__{ii} = interp1(time_values, val, t);
if isfield(BreachGlobOpt, 'disable_robust_linear_interpolation')&&BreachGlobOpt.disable_robust_linear_interpolation
val__{ii} = interp1(time_values, val, t, 'previous');
else
val__{ii} = interp1(time_values, val, t);
end
end
catch % if val is empty
val__{ii} = NaN(1,numel(t));
Expand Down Expand Up @@ -269,7 +277,7 @@

% first time instant
ind_ti = find(traj.time>=interval(1),1);
if isempty(ind_ti)
if isempty(ind_ti)
time_values = [traj.time(1,end) traj.time(1,end)+1];
return
end
Expand Down
10 changes: 7 additions & 3 deletions @STL_Formula/private/generic_predicate.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@
global BreachGlobOpt;
eval(BreachGlobOpt.GlobVarsDeclare);

dt__ = traj.time(1,2)-traj.time(1,1);
if numel(traj.time)==1
dt__ = 1; % not sure this makes sense, will see
else
dt__ = traj.time(1,2)-traj.time(1,1);
end
Sys = params.Sys;
P =params.P;

Expand Down Expand Up @@ -59,8 +63,8 @@
fn_ = params.fn;

% don't like that... But not so trivial to remove
traj.time = [-1e99 traj.time 1e99]; % NM: when fixing that, don't forget to change
traj.X = [traj.X(:,1) traj.X traj.X(:,end)]; % GetTrajSensi.
traj.time = [-1e99 traj.time 1e99];
traj.X = [traj.X(:,1) traj.X traj.X(:,end)];

if isfield(traj,'XS')
traj.XS = [traj.XS(:,1) traj.XS traj.XS(:,end)];
Expand Down
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
# Release 1.2.16
## Users
- printStatus now prints error message obtained during failed Simulink
simulation
- New SimInModelsDataFolder option, default to false (i.e., by
default, Breach won't change folder for simulalink simulations
- Changed default max_obj_eval to 100 and max_time to inf in BreachProblem

## Bugfixes
- GetBrSet_Logged, _False, _True methods now works as expected in
serial and parallel (BreachTEMA Issue #33)
- DiskCaching matfiles writable option should improve stability
- Fixed interpolation bug in STL_EvalThom (Issue #62)
- Fixed bug in BreachTraceSystem with useless legacy Xf field
- ModelsData folders properly created at initialization if not
existant (BreachTEMA Issue #30)

## Developpers
- log_traces field for BreachProblem now consistent with serial and
parallel (BreachTEMA Issue #31)
- StoreTracesOnDisk true by default for DiskCaching (BreachTEMA Issue #21)

# Release 1.2.15

## Users
Expand Down
2 changes: 1 addition & 1 deletion Contents.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Breach Toolbox v1.0-beta1
% Breach Toolbox
%
% Files
% InitBreach - Initializes Breach, in particular adding paths to Breach directories
Expand Down
95 changes: 46 additions & 49 deletions Core/Algos/@BreachProblem/BreachProblem.m
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@
properties
display = 'on'
freq_update = 10
use_parallel =0
max_time = 60
use_parallel = 0
max_time = inf
time_start = tic
time_spent = 0
nb_obj_eval = 0
max_obj_eval = inf
max_obj_eval = 100
end

%% Static Methods
Expand Down Expand Up @@ -466,9 +466,10 @@ function SetupParallel(this, varargin)
this.BrSys.use_parallel = 0;
this.BrSys.Sys.Parallel=0;

% Disable serial logging mechanism and enable DiskCaching
this.log_traces = 0;
this.SetupDiskCaching();
% Enable DiskCaching
if this.log_traces
this.SetupDiskCaching();
end
end

function StopParallel(this)
Expand Down Expand Up @@ -546,7 +547,6 @@ function SetupDiskCaching(this, varargin)
end

%% Misc methods

function x = CheckinDomain(this,x)
for ip = 1:numel(this.params)
x(ip) = this.domains(ip).checkin(x(ip));
Expand All @@ -556,11 +556,10 @@ function SetupDiskCaching(this, varargin)
function LogX(this, x, fval)
% LogX logs values tried by the optimizer

x = this.CheckinDomain(x);
this.X_log = [this.X_log x];
this.obj_log = [this.obj_log fval];

if (this.log_traces)
if (this.log_traces)&&~(this.use_parallel);
if isempty(this.BrSet_Logged)
this.BrSet_Logged = this.BrSys.copy();
else
Expand Down Expand Up @@ -609,7 +608,7 @@ function DispResultMsg(this)

function [BrOut, Berr, BbadU] = GetBrSet_Logged(this)
% GetBrSet_Logged gets BreachSet object containing parameters and traces computed during optimization
if this.log_traces
if this.log_traces&&~this.use_parallel % when this is true, BrSet_Logged is already a BreachSet with traces
BrOut = this.BrSet_Logged;
else
BrOut = this.BrSys.copy();
Expand All @@ -619,45 +618,23 @@ function DispResultMsg(this)
BrOut.Sim();
end
end
BrOut.Sys.Verbose=1;
Berr =[];
BbadU = [];
[idx_ok, idx_sim_error, idx_invalid_input, st_status] = BrOut.GetTraceStatus();

if ~isempty(idx_sim_error)||~isempty(idx_invalid_input)
[Bok, Berr, BbadU] = FilterTraceStatus(BrOut);
BrOut= Bok;
this.disp_msg(['Warning: ' st_status],1);
end

if ~isempty(idx_ok)
BrOut.CheckSpec(this.Spec);
end
[BrOut, Berr, BbadU] = this.ExportBrSet(BrOut);

end

function BrBest = GetBrSet_Best(this)
BrBest = this.BrSet_Best;
if isempty(BrBest)
BrBest = this.BrSys.copy();
BrBest.SetParam(this.params, this.x_best, 'spec');
BrBest.Sim();
end
BrBest.Sys.Verbose=1;
if BrBest.hasTraj()
BrBest.CheckSpec(this.Spec);
end
end

function SetupLogFolder(this, fname)
if nargin<2
this.BrSys.SetupLogFolder();
else
this.BrSys.SetupLogFolder(fname);
end
this.log_traces= false;

BrBest = this.ExportBrSet(BrBest);

end

function display_status_header(this)
fprintf( '#calls (max:%5d) time spent (max: %g) best obj\n',...
this.max_obj_eval, this.max_time);
Expand All @@ -670,11 +647,6 @@ function display_status(this,fval)
fval = this.obj_log(end); % bof bof
end

% if this.nb_obj_eval==1
% this.display_status_header();
% rfprintf_reset();
% end

st__= sprintf(' %5d %7.1f %+5.5e %+5.5e\n', ...
this.nb_obj_eval, this.time_spent, this.obj_best, fval);
switch this.display
Expand All @@ -686,6 +658,35 @@ function display_status(this,fval)
end
end

function new = copy(this)
% copy operator for BreachSet, works with R2010b or newer.
objByteArray = getByteStreamFromArray(this);
new = getArrayFromByteStream(objByteArray);
end

end

methods (Access=protected)

function [BrOut, Berr, BbadU] = ExportBrSet(this,BrOut)
% ExportBrSet prepares a BreachSet such as best, logged, etc to be
% returned
BrOut.Sys.Verbose=1;
Berr =[];
BbadU = [];
[idx_ok, idx_sim_error, idx_invalid_input, st_status] = BrOut.GetTraceStatus();

if ~isempty(idx_sim_error)||~isempty(idx_invalid_input)
[Bok, Berr, BbadU] = FilterTraceStatus(BrOut);
BrOut= Bok;
this.disp_msg(['Warning: ' st_status],1);
end

if ~isempty(idx_ok)&&BrOut.hasTraj();
BrOut.CheckSpec(this.Spec);
end
end

function [cmp, cmpSet, cmpSys, cmpBest, cmpLogged] = compare(this, other)
% FIXME broken as per changes in BreachStatus
cmp = BreachStatus();
Expand Down Expand Up @@ -715,11 +716,7 @@ function display_status(this,fval)
end
end

function new = copy(this)
% copy operator for BreachSet, works with R2010b or newer.
objByteArray = getByteStreamFromArray(this);
new = getArrayFromByteStream(objByteArray);
end


end

end
2 changes: 1 addition & 1 deletion Core/Algos/BreachCEGIS.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function solve(this)
this.falsif_pb.BrSet.SetParam(this.synth_pb.params, this.synth_pb.x_best, true);
this.falsif_pb.ResetObjective();
this.falsif_pb.solve();
BrFalse = this.falsif_pb.BrSet_False;
BrFalse = this.falsif_pb.GetBrSet_False();
if isempty(BrFalse)
return
end
Expand Down
21 changes: 10 additions & 11 deletions Core/Algos/FalsificationProblem.m
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,16 @@ function ResetObjective(this)

% Logging
function LogX(this, x, fval)

% LogX log variable parameter value tested by optimizers

% Logging default stuff
this.LogX@BreachProblem(x, fval);

% Logging falsifying parameters found
[~, i_false] = find(fval<0);
if ~isempty(i_false)
this.X_false = [this.X_false x(:,i_false)];
if (this.log_traces)
if (this.log_traces)&&~this.use_parallel
if isempty(this.BrSet_False)
this.BrSet_False = this.BrSys.copy();
else
Expand All @@ -97,14 +98,13 @@ function LogX(this, x, fval)
end

function b = stopping(this)
b = (this.time_spent >= this.max_time) ||...
(this.nb_obj_eval>= this.max_obj_eval) ||...
(this.StopAtFalse&&this.obj_best<0);
b = this.stopping@BreachProblem();
b= b||(this.StopAtFalse&&this.obj_best<0);
end

function BrFalse = GetBrSet_False(this)
function [BrFalse, BrFalse_Err, BrFalse_badU] = GetBrSet_False(this)
BrFalse = [];
if this.log_traces
if this.log_traces&&~this.use_parallel
BrFalse = this.BrSet_False;
else
[~, i_false] = find(this.obj_log<0);
Expand All @@ -115,10 +115,9 @@ function LogX(this, x, fval)
BrFalse.Sim();
end
end
BrFalse.Sys.Verbose=1;
if isempty(BrFalse.InputGenerator.Specs)&&BrFalse.hasTraj() % TODO: change this when dealing with Input requirements/constraints
BrFalse.CheckSpec(this.Spec);
end

[BrFalse, BrFalse_Err, BrFalse_badU] = this.ExportBrSet(BrFalse);

end
end

Expand Down
44 changes: 26 additions & 18 deletions Core/Algos/MaxSatProblem.m
Original file line number Diff line number Diff line change
Expand Up @@ -64,35 +64,43 @@ function LogX(this, x, fval)
this.LogX@BreachProblem(x, fval);

% Logging satisfying parameters and traces
if fval < 0
this.X_True = [this.X_True x];
if isempty(this.BrSet_True)
this.BrSet_True = this.BrSys.copy();
else
this.BrSet_True.Concat(this.BrSys);
end

if this.StopAtTrue == true
this.stopping = true;
[~, i_true] = find(fval>0);
if ~isempty(i_true)
this.X_true = [this.X_true x(:,i_true)];
if (this.log_traces)&&~this.use_parallel
if isempty(this.BrSet_True)
this.BrSet_True = this.BrSys.copy();
else
this.BrSet_True.Concat(this.BrSys);
end
end
end

end

function BrTrue = GetBrSet_True(this)
if this.log_traces
BrTrue = this.BrSet_False;
function b = stopping(this)
b = this.stopping@BreachProblem();
b= b||(this.StopAtTrue&&this.obj_best>0);
end

function [BrTrue, BrTrue_Err, BrTrue_badU] = GetBrSet_True(this)
BrTrue = [];
if this.log_traces&&~this.use_parallel
BrTrue = this.BrSet_True;
else
[~, i_true] = find(this.obj_log>=0);
if ~isempty(i_true)
[~, i_false] = find(this.obj_log<0);
if ~isempty(i_false)
BrTrue = this.BrSys.copy();
BrTrue.SetParam(this.params, this.X_log(:, i_true));
if ~isempty(this.BrSys.log_folder)
BrTrue.SetParam(this.params, this.X_log(:, i_false));
if this.BrSys.UseDiskCaching
BrTrue.Sim();
end
end

[BrTrue, BrTrue_Err, BrTrue_badU] = this.ExportBrSet(BrTrue);

end


end


Expand Down
Loading

0 comments on commit 42a9118

Please sign in to comment.