Skip to content

Commit

Permalink
[MAINT] try not indexing dependencies for a speed up (#1129)
Browse files Browse the repository at this point in the history
* try not indexing dependencies for a speed up

* fix

* speed up layout indexing during tests

* fix concatenation

* separate slow tests

* fewer subjects in bms

* update flags coverage

* fix octave bug
  • Loading branch information
Remi-Gau authored Aug 19, 2023
1 parent 96969da commit 4f94935
Show file tree
Hide file tree
Showing 43 changed files with 434 additions and 54 deletions.
23 changes: 20 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,27 @@ jobs:
os: [ubuntu-latest, macos-latest]
matlab: [R2022b]
include:
# only run bms on ubuntu because of datalad setup
- test_type: system
os: ubuntu-latest
matlab: R2022b
script: bms
- test_type: unit
os: ubuntu-latest
matlab: R2022b
mode: fast
- test_type: unit
os: macos-latest
matlab: R2022b
mode: fast
- test_type: unit
os: ubuntu-latest
matlab: R2022b
mode: slow
- test_type: unit
os: macos-latest
matlab: R2022b
mode: slow
fail-fast: false

runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -124,18 +135,24 @@ jobs:
with:
release: ${{ matrix.matlab }}

- name: Run unit tests MATLAB
if: matrix.test_type == 'unit'
- name: Run fast unit tests MATLAB
if: matrix.test_type == 'unit' && matrix.mode == 'fast'
uses: matlab-actions/[email protected]
with:
command: cd(fullfile(getenv('GITHUB_WORKSPACE'), '.github', 'workflows')); run tests_matlab;

- name: Run slow unit tests MATLAB
if: matrix.test_type == 'unit' && matrix.mode == 'slow'
uses: matlab-actions/[email protected]
with:
command: cd(fullfile(getenv('GITHUB_WORKSPACE'), '.github', 'workflows')); global SLOW; SLOW=true; run tests_matlab;

- name: Code coverage matlab
if: matrix.test_type == 'unit'
uses: codecov/codecov-action@v3
with:
file: coverage.xml
flags: ${{ matrix.os }}_matlab-${{ matrix.matlab }}
flags: ${{ matrix.os }}_matlab-${{ matrix.matlab }}_${{ matrix.mode }}
name: codecov-matlab
fail_ci_if_error: false
# token: ${{ secrets.CODECOV_TOKEN }} # not required but might help API rate limits
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/tests_octave.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ function tests_octave()

cd(fullfile(fileparts(mfilename('fullpath')), '..', '..'));

bidspm('action', 'dev');

success = bidspm('action', 'run_tests');

toc;
Expand Down
17 changes: 14 additions & 3 deletions .github/workflows/tests_octave.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ jobs:
script: [moae, facerep, fmriprep]
include:
- test_type: unit
mode: fast
- test_type: unit
mode: slow
fail-fast: false

steps:
Expand Down Expand Up @@ -125,21 +128,29 @@ jobs:
make -C spm12/src PLATFORM=octave install
octave $OCTFLAGS --eval "addpath(fullfile(pwd, 'spm12')); savepath();"
- name: Run unit tests Octave
if: matrix.test_type == 'unit'
- name: Run fast unit tests Octave
if: matrix.test_type == 'unit' && matrix.mode == 'fast'
run: |
octave $OCTFLAGS --eval "addpath(fullfile(pwd, 'tests', 'utils')); savepath();"
octave $OCTFLAGS --eval "bidspm(); cd demos/MoAE; download_moae_ds(true);"
cd .github/workflows
octave $OCTFLAGS --eval "tests_octave;"
- name: Run fast unit tests Octave
if: matrix.test_type == 'unit' && matrix.mode == 'slow'
run: |
octave $OCTFLAGS --eval "addpath(fullfile(pwd, 'tests', 'utils')); savepath();"
octave $OCTFLAGS --eval "bidspm(); cd demos/MoAE; download_moae_ds(true);"
cd .github/workflows
octave $OCTFLAGS --eval " global SLOW; SLOW=true; tests_octave;"
- name: Code coverage
if: matrix.test_type == 'unit'
uses: codecov/codecov-action@v3
with:
file: coverage.xml
flags: octave
name: codecov-octave
name: codecov-octave_${{ matrix.mode }}
fail_ci_if_error: false
# token: ${{ secrets.CODECOV_TOKEN }} # not required but might help API rate limits

Expand Down
17 changes: 14 additions & 3 deletions .github/workflows/tests_windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ jobs:
- test_type: unit
os: windows-latest
matlab: R2022b
mode: fast
- test_type: unit
os: windows-latest
matlab: R2022b
mode: slow
fail-fast: false

runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -109,18 +114,24 @@ jobs:
with:
release: ${{ matrix.matlab }}

- name: Run unit tests MATLAB
if: matrix.test_type == 'unit'
- name: Run fast unit tests MATLAB
if: matrix.test_type == 'unit' && matrix.mode == 'fast'
uses: matlab-actions/[email protected]
with:
command: cd(fullfile(getenv('GITHUB_WORKSPACE'), '.github', 'workflows')); run tests_matlab;

- name: Run slow unit tests MATLAB
if: matrix.test_type == 'unit' && matrix.mode == 'slow'
uses: matlab-actions/[email protected]
with:
command: cd(fullfile(getenv('GITHUB_WORKSPACE'), '.github', 'workflows')); global SLOW; SLOW=true; run tests_matlab;

- name: Code coverage matlab
if: matrix.test_type == 'unit'
uses: codecov/codecov-action@v3
with:
file: coverage.xml
flags: ${{ matrix.os }}_matlab-${{ matrix.matlab }}
flags: ${{ matrix.os }}_matlab-${{ matrix.matlab }}_${{ matrix.mode }}
name: codecov-matlab
fail_ci_if_error: false
# token: ${{ secrets.CODECOV_TOKEN }} # not required but might help API rate limits
Expand Down
8 changes: 6 additions & 2 deletions bidspm.m
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,13 @@ function uninitBidspm()

spm('defaults', 'fMRI');

subfolder = '';

folderToCover = fullfile(pwd, 'src');

subfolder = '';
if usingSlowTestMode()
fprintf(1, 'Running in slow tests only.\n');
subfolder = 'tests_slow';
end
testFolder = fullfile(pwd, 'tests', subfolder);

returnCode = moxunit_runtests(testFolder, ...
Expand Down
3 changes: 1 addition & 2 deletions demos/bayes/ds000114_run.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
FWHM = 8;

% set to false to not re run the smoothing
SMOOTH = false;
SMOOTH = true;

% set to false to not re run the model specification
FIRST_LEVEL = true;
Expand All @@ -30,7 +30,6 @@
participant_label = {'[0-9]*'}; %#ok<*NASGU>
if TESTING
participant_label = {'^0[12]$'};
participant_label = {'[0-9]*'};
end

%% Smooth
Expand Down
16 changes: 13 additions & 3 deletions src/IO/getData.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
%
% [BIDS, opt] = getData(opt, bidsDir)
%
% :type opt: structure
% :type opt: structure
% :param opt: Options chosen for the analysis.
% See checkOptions.
%
Expand All @@ -27,6 +27,7 @@

addRequired(args, 'opt', @isstruct);
addRequired(args, 'bidsDir', isFolder);
addOptional(args, 'index_dependencies', true, @islogical);

try
parse(args, varargin{:});
Expand All @@ -44,6 +45,11 @@
opt = args.Results.opt;
bidsDir = args.Results.bidsDir;

index_dependencies = args.Results.index_dependencies;
if strcmp(opt.pipeline.type, 'stats')
index_dependencies = false;
end

if isfield(opt, 'taskName')
msg = sprintf('FOR TASK(s): %s', strjoin(opt.taskName, ' '));
logger('INFO', msg, 'options', opt, 'filename', mfilename());
Expand All @@ -59,16 +65,20 @@
BIDS = bids.layout(bidsDir, ...
'use_schema', opt.useBidsSchema, ...
'verbose', opt.verbosity > 1, ...
'filter', layout_filter);
'filter', layout_filter, ...
'index_dependencies', index_dependencies);

if strcmp(opt.pipeline.type, 'stats') && ~opt.pipeline.isBms
if exist(fullfile(opt.dir.raw, 'layout.mat'), 'file') == 2
msg = sprintf('Loading BIDS raw layout from:\n\t%s', ...
bids.internal.format_path(fullfile(opt.dir.raw, 'layout.mat')));
logger('INFO', msg, 'options', opt, 'filename', mfilename());
tmp = load(fullfile(opt.dir.raw, 'layout.mat'), 'BIDS');

if isempty(fieldnames(tmp))
BIDS.raw = bids.layout(opt.dir.raw, 'filter', layout_filter);
BIDS.raw = bids.layout(opt.dir.raw, ...
'filter', layout_filter, ...
'index_dependencies', index_dependencies);
else
BIDS.raw = tmp.BIDS;
end
Expand Down
1 change: 1 addition & 0 deletions src/bids/initBids.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ function initBids(varargin)
BIDS = bids.layout(opt.dir.output, ...
'use_schema', false, ...
'index_derivatives', false, ...
'index_dependencies', false, ...
'tolerant', true, ...
'verbose', opt.verbosity > 0);

Expand Down
10 changes: 6 additions & 4 deletions src/bids_model/addConfoundsToDesignMatrix.m
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,16 @@
toClean = cellfun(@(x) isempty(x), designMatrix);
designMatrix(toClean) = [];

numeric = cellfun(@(x) isnumeric(x), designMatrix);
tmp = unique(designMatrix(~numeric));
if size(tmp, 1) > 1
tmp = tmp';
if isempty(designMatrix)
return
end
if size(designMatrix, 1) > 1
designMatrix = designMatrix';
end

numeric = cellfun(@(x) isnumeric(x), designMatrix);
tmp = unique(designMatrix(~numeric));

designMatrix = cat(2, tmp, designMatrix(numeric));
end

Expand Down
4 changes: 3 additions & 1 deletion src/workflows/stats/bidsResults.m
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,9 @@
if ismember(lower(node.Level), {'run', 'session', 'subject'})

if isempty(BIDS)
BIDS = bids.layout(opt.dir.preproc, 'use_schema', false, ...
BIDS = bids.layout(opt.dir.preproc, ...
'use_schema', false, ...
'index_dependencies', false, ...
'filter', struct('sub', {opt.subjects}));
end

Expand Down
4 changes: 3 additions & 1 deletion tests/tests_QA/test_computeDesignEfficiency.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ function test_computeDesignEfficiency_vislocalizer()

opt = setOptions('vismotion', '01');

BIDS = bids.layout(opt.dir.input);
BIDS = bids.layout(opt.dir.input, ...
'use_schema', false, ...
'index_dependencies', false);

metadata = bids.query(BIDS, 'metadata', ...
'sub', opt.subjects, ...
Expand Down
4 changes: 3 additions & 1 deletion tests/tests_bids/test_getAnatFilename.m
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ function test_getAnatFilename_no_session()
subLabel = '01';
opt = setOptions('MoAE-preproc');

BIDS = bids.layout(opt.dir.input);
BIDS = bids.layout(opt.dir.input, ...
'use_schema', false, ...
'index_dependencies', false);

[anatImage, anatDataDir] = getAnatFilename(BIDS, opt, subLabel);

Expand Down
4 changes: 3 additions & 1 deletion tests/tests_bids/unit_tests/test_getInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ function test_getInfo_no_session_no_run()
opt = setOptions('MoAE-preproc', subLabel);
opt.dir.input = opt.dir.preproc;

BIDS = bids.layout(opt.dir.input);
BIDS = bids.layout(opt.dir.input, ...
'use_schema', false, ...
'index_dependencies', false);

sessions = getInfo(BIDS, subLabel, opt, 'sessions');
assertEqual(sessions, {''});
Expand Down
6 changes: 4 additions & 2 deletions tests/tests_cli/test_bidspm_smooth.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ function test_smooth()

BIDS = bids.layout(fullfile(outputPath, 'derivatives', 'bidspm-preproc'), ...
'verbose', false, ...
'use_schema', false);
'use_schema', false, ...
'index_dependencies', false);

assertEqual(numel(bids.query(BIDS, 'data', 'desc', 'smth6')), 2);

Expand Down Expand Up @@ -65,7 +66,8 @@ function test_smooth_anat_only()

BIDS = bids.layout(fullfile(outputPath, 'derivatives', 'bidspm-preproc'), ...
'verbose', false, ...
'use_schema', false);
'use_schema', false, ...
'index_dependencies', false);

assertEqual(numel(bids.query(BIDS, 'data', 'desc', 'smth6')), 2);

Expand Down
11 changes: 11 additions & 0 deletions tests/tests_slow/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Slow tests folders

Move files in this folder if they are too slow.

Add the following at the beginning of each test.

```matlab
if ~usingSlowTestMode()
moxunit_throw_test_skipped_exception('slow test only');
end
```
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

function test_bidsGenerateT1map_basic()

if ~usingSlowTestMode()
moxunit_throw_test_skipped_exception('slow test only');
end

opt = setOptions('vismotion');

matlabbatch = bidsGenerateT1map(opt);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

function test_bidsRealignReslice_basic()

if ~usingSlowTestMode()
moxunit_throw_test_skipped_exception('slow test only');
end

opt = setOptions('vislocalizer', '');

opt.funcVoxelDims = [2 2 2];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

function test_bidsRealignUnwarp_basic()

if ~usingSlowTestMode()
moxunit_throw_test_skipped_exception('slow test only');
end

opt = setOptions('vislocalizer', '');
opt.bidsFilterFile.bold.part = 'mag';
opt.funcVoxelDims = [2 2 2];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

function test_bidsRemoveDummies_basic()

if ~usingSlowTestMode()
moxunit_throw_test_skipped_exception('slow test only');
end

if bids.internal.is_octave()
tmpDir = fullfile(tempname);
else
Expand Down
Loading

0 comments on commit 4f94935

Please sign in to comment.