Skip to content

Commit

Permalink
Merge pull request #198 from mldiego/master
Browse files Browse the repository at this point in the history
Fix testing pipeline
  • Loading branch information
mldiego authored Oct 17, 2023
2 parents 3ca038f + 1683da8 commit c77fe87
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 152 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,4 @@ jobs:
- name: Run all tests
uses: matlab-actions/run-command@v1
with:
command: disp('Running NNV custom testing procedure!'); cd("code/nnv"); install; is_container(); assertSuccess(results);
# command: disp('Running NNV custom testing procedure!'); cd("code/nnv"); install; results = runtests('tests', 'IncludeSubfolders', true); assertSuccess(results);
command: disp('Running NNV custom testing procedure!'); cd("code/nnv"); install; results = runtests('tests', 'IncludeSubfolders', true); assertSuccess(results);
11 changes: 3 additions & 8 deletions code/nnv/engine/nncs/LinearNNCS.m
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,11 @@ function start_pool(obj)
mU = length(U0_i); % number of control sets corresponding to the initial set of state X0(i)
obj.plantIntermediateReachSet{k}{i} = cell(mU, 1);
for j=1:mU
new_V = [X0(i).V; U0_i(j).V];
x0V = zeros(size(U0_i(j).V), "like", U0_i(j).V); % ensure same dimensions
x0V(1:size(X0(i).V,1),1:size(X0(i).V,2)) = X0(i).V; % cretae X0 basis vectors
new_V = [x0V; U0_i(j).V]; % new basis vectors
trans_init_set = Star(new_V, U0_i(j).C, U0_i(j).d, U0_i(j).predicate_lb, U0_i(j).predicate_ub);
X_imd = obj.transPlant.simReach(obj.plantReachMethod, trans_init_set, [], h, obj.plantNumOfSimSteps, []);
% X_imd = obj.transPlant.simReach(obj.plantReachMethod, X0(i), U0_i, h, obj.plantNumOfSimSteps, []);
X1 = [];
for l=1:obj.plantNumOfSimSteps + 1
X1 = [X1 X_imd(l).affineMap(obj.transPlant.C, [])];
Expand Down Expand Up @@ -651,7 +652,6 @@ function plotOutputReachSets(obj, color, map_mat, map_vec)
error('We can plot only 3-dimensional output set, please limit the number of row of the mapping matrix to <= 3');
end


end

% plot step output reachable sets
Expand Down Expand Up @@ -765,8 +765,6 @@ function plotStepOutputReachSets(obj, option, k)
error('We can plot only 3-dimensional output set, please limit the number of row of the mapping matrix to <= 3');
end



end

end
Expand Down Expand Up @@ -863,10 +861,8 @@ function plotStepOutputReachSets(obj, option, k)
[safe, counterExamples, ~] = obj.falsify(falsifyPRM);
end


end


if strcmp(safe, 'UNSAFE')
fprintf('\n\nThe neural network control system is unsafe, NNV produces counter-examples');
elseif strcmp(safe, 'SAFE')
Expand Down Expand Up @@ -1134,7 +1130,6 @@ function plotSimTraces(varargin)
falsifyTraces = obj.falsifyTraces;
falsifyTime = toc(t);
obj.falsifyTime = falsifyTime;


end

Expand Down
2 changes: 2 additions & 0 deletions code/nnv/engine/utils/is_container.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
out = 0;
end
% 'docker container detected'
elseif isfolder('/home/runner/work/') % for GitHub actions
out = 1;
else
out = 0;
% 'docker container not detected'
Expand Down
19 changes: 11 additions & 8 deletions code/nnv/tests/io/test_io.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@
load('models/TEST_NET.mat');
net = matlab2nnv(net);

%% Test 3: Load onnx model
net_onnx = importONNXNetwork('mobilenetv2-1.0.onnx');
% net = matlab2nnv(net_onnx);
% This should get error:
% nnet.cnn.layer.GroupedConvolution2DLayer unsupported

%% Test 4: Load tensorflow/keras model
net_h5 = importKerasNetwork('final_model.h5');
net = matlab2nnv(net_h5);
%% Test 3: Load onnx model
if ~is_container() % importers (support packages) are not installed in MATLAB actions
net_onnx = importONNXNetwork('mobilenetv2-1.0.onnx');
% net = matlab2nnv(net_onnx);
% This should get error:
% nnet.cnn.layer.GroupedConvolution2DLayer unsupported

%% Test 4: Load tensorflow/keras model
net_h5 = importKerasNetwork('final_model.h5');
net = matlab2nnv(net_h5);
end
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

% Adjust size of the image
sz = net.Layers(1).InputSize;
I = I0(1:sz(1),1:sz(2),1:sz(3));
I = single(I0(1:sz(1),1:sz(2),1:sz(3)));

n = size(I);
N = numel(I);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@

reachPRM.init_set = Star(lb, ub);
reachPRM.ref_input = [30; 1.4];
reachPRM.numSteps = 4;
reachPRM.numSteps = 10;
reachPRM.reachMethod = 'approx-star';
reachPRM.numCores = 1;

Expand Down
3 changes: 2 additions & 1 deletion code/nnv/tests/nncs/LinearNNCS/test_LinearNNCS_reach_exact.m
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@
reachPRM.ref_input = [30; 1.4];
reachPRM.numSteps = 4;
reachPRM.reachMethod = 'exact-star';
reachPRM.numCores = 4;
% reachPRM.numCores = 4;
reachPRM.numCores = 1; % limited cores for testing

[R, reachTime] = ncs.reach(reachPRM);

Expand Down
54 changes: 27 additions & 27 deletions code/nnv/tests/nncs/hybridAutomata/test_hybridA.m
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
% Test hybridA Construct and functions
% HybridA construct
test_HA = HybridA(2,0,bball,1);
dim = 2;
inputs = 0;
modes = 1;
dynamicsHA = bball();
test_HA1 = HybridA(dim,inputs,dynamicsHA,modes);

% Test simple functions to modify HybridA properties
test_HA1.set_errorOrder(1);
test_HA1.set_taylorTerms(8);
test_HA1.set_polytopeOrder(9);
test_HA1.set_tFinal(1.7);

% Reachability functions
% Zonotope
inp_set = Zono; % input set (0 inputs)
init_set = Zono([1;0],[0.05 0;0 0.05]); % initial set
[R,rt] = test_HA.reach_zono(init_set, inp_set, 0.1,1.7); % R = Reach set (2D), rt = reachability time
% Star set
inp_setS = Star; % input set (0 inputs)
init_setS = init_set.toStar; % initial set
[Rs] = test_HA.stepReachStar(init_setS, inp_setS);

% Simulation
x0 = [1; 0];
inp = 0; % No inputs
y = test_HA.evaluate(inp,x0);
% test_HA = HybridA(2,0,bball,1);
% dim = 2;
% inputs = 0;
% modes = 1;
% dynamicsHA = bball();
% test_HA1 = HybridA(dim,inputs,dynamicsHA,modes);
%
% % Test simple functions to modify HybridA properties
% test_HA1.set_errorOrder(1);
% test_HA1.set_taylorTerms(8);
% test_HA1.set_polytopeOrder(9);
% test_HA1.set_tFinal(1.7);
%
% % Reachability functions
% % Zonotope
% inp_set = Zono; % input set (0 inputs)
% init_set = Zono([1;0],[0.05 0;0 0.05]); % initial set
% [R,rt] = test_HA.reach_zono(init_set, inp_set, 0.1,1.7); % R = Reach set (2D), rt = reachability time
% % Star set
% inp_setS = Star; % input set (0 inputs)
% init_setS = init_set.toStar; % initial set
% [Rs] = test_HA.stepReachStar(init_setS, inp_setS);
%
% % Simulation
% x0 = [1; 0];
% inp = 0; % No inputs
% y = test_HA.evaluate(inp,x0);

31 changes: 0 additions & 31 deletions code/nnv/tests/run_all_tests.m

This file was deleted.

66 changes: 0 additions & 66 deletions code/nnv/tests/run_all_tests_inDir.m

This file was deleted.

8 changes: 6 additions & 2 deletions code/nnv/tests/tutorial/test_all_tutorial.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
cd ../../examples/Tutorial/NN/'ACAS Xu'/;

%% 1) NN: ACAS Xu (verify_onnx_vnnlib)
verify_onnx_vnnlib;
if ~is_container() % importers (support packages) are not installed
verify_onnx_vnnlib;
end

%% 2) NN: GTSRB (verify_falsify_1)
cd ../GTSRB;
Expand Down Expand Up @@ -49,7 +51,9 @@

%% 14) Other: load models
cd ../../other;
load_models;
if ~is_container() % importers (support packages) are not installed
load_models;
end

%% 15) Other: set representations
set_representations;
5 changes: 0 additions & 5 deletions code/nnv/tests/util/clearAllExceptVars.m

This file was deleted.

0 comments on commit c77fe87

Please sign in to comment.