Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
LarvaTagger.jl
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nyx
LarvaTagger.jl
Commits
90383bb5
Commit
90383bb5
authored
2 years ago
by
François LAURENT
Browse files
Options
Downloads
Patches
Plain Diff
improved tests (still not cross-platform reproducible, though)
parent
14e19e1e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Pipeline
#102333
failed
2 years ago
Stage: test
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
test/deploy_and_test.sh
+90
-0
90 additions, 0 deletions
test/deploy_and_test.sh
test/predict_and_retrain.sh
+4
-1
4 additions, 1 deletion
test/predict_and_retrain.sh
test/scenarii.sh
+38
-25
38 additions, 25 deletions
test/scenarii.sh
with
132 additions
and
26 deletions
test/deploy_and_test.sh
0 → 100755
+
90
−
0
View file @
90383bb5
#!/usr/bin/env bash
# Standalone script
# on Maestro:
# SLURM_OPTS='-p dbc_pmo -q dbc -c 8' JULIA_THREADS=8 ./deploy_and_test.sh
if
[
-z
"
$(
which julia
)
"
]
;
then
echo
"
\`
julia
\`
not found"
exit
1
fi
if
[
-n
"
$1
"
]
&&
[
"
$1
"
=
"-f"
]
||
[
"
$1
"
=
"--force"
]
;
then
rm
-rf
LarvaTagger
elif
[
-d
LarvaTagger
]
;
then
echo
"
\`
$0
\`
needs to make a local LarvaTagger directory"
echo
"but this directory already exists."
echo
"Run
\`
$0
--force
\`
or pick another location."
exit
1
fi
if
[
-n
"
$LAUNCHER
"
]
;
then
launcher
=
"
$LAUNCHER
"
elif
[
-n
"
$(
which srun
)
"
]
;
then
launcher
=
"srun "
echo
"Slurm detected"
if
[
-z
"
$SLURM_OPTS
"
]
;
then
echo
"Options can be passed to
\`
srun
\`
with variable SLURM_OPTS"
else
launcher
=
"
$launcher$SLURM_OPTS
"
fi
fi
CURDIR
=
$(
pwd
)
mkdir
-p
LarvaTagger
&&
cd
$_
# shunit2 is for tests specifically
if
[
-z
"
$(
which shunit2
)
"
]
;
then
git clone
-c
advice.detachedHead
=
false
-b
v2.1.8 https://github.com/kward/shunit2
fi
# comment out the below line to build a development environment
CLONE_OPTS
=
" --depth 1 --no-tags --single-branch -b dev"
git clone
$CLONE_OPTS
https://gitlab.pasteur.fr/nyx/planarlarvae.jl PlanarLarvae
git clone
$CLONE_OPTS
https://gitlab.pasteur.fr/nyx/LarvaTagger.jl
ln
-s
$(
realpath
LarvaTagger.jl
)
LarvaTagger
git clone
$CLONE_OPTS
https://gitlab.pasteur.fr/nyx/TaggingBackends
git clone
$CLONE_OPTS
https://gitlab.pasteur.fr/nyx/MaggotUBA-adapter
ln
-s
$(
realpath
MaggotUBA-adapter
)
MaggotUBA
(
cd
TaggingBackends
&&
julia
--project
=
.
-e
'using Pkg; Pkg.develop(path="../PlanarLarvae"); Pkg.instantiate()'
)
(
cd
MaggotUBA
&&
poetry
install
-v
&&
poetry remove taggingbackends
&&
poetry add ../TaggingBackends
)
cd
LarvaTagger
||
exit
1
julia
--project
=
.
-e
'using Pkg; Pkg.develop(path="../PlanarLarvae"); Pkg.instantiate()'
# the remainder of this script is test-specific
if
[
-f
../../LarvaTagger_test_data.tgz
]
;
then
# To generate the test data, first run the tests with environment variable KEEP_MODEL_FILES=1
# copy the LarvaTagger/MaggotUBA/models/test_train_* directories into LarvaTagger/LarvaTagger.jl/test/data
# and build the archive from the LarvaTagger/LarvaTagger.jl directory.
# For example:
# KEEP_MODEL_FILES=1 ./deploy_and_test.sh
# cd LarvaTagger/LarvaTagger.jl
# rm -rf test/data/test_train_*
# cp -ra ../MaggotUBA/models/test_train_* test/data/
# tar zcvf LarvaTagger_test_data.tgz test/data/*
# mv LarvaTagger_test_data.tgz ../../
tar
zxvf ../../LarvaTagger_test_data.tgz
else
# Not recommended; reproducibility is not guarantee across hosts or architectures yet
wget
-O-
https://dl.pasteur.fr/fop/l3qruSQR/LarvaTagger_test_data.tgz |
tar
zxv
fi
if
[
"
$LOCAL_SCENARII
"
=
"1"
]
;
then
if
[
-f
"
$CURDIR
/scenarii.sh"
]
;
then
cp
"
$CURDIR
/scenarii.sh"
test
/
elif
[
-f
"
$CURDIR
/test/scenarii.sh"
]
;
then
cp
"
$CURDIR
/test/scenarii.sh"
test
/
else
echo
"Cannot find a local scenarii.sh file"
fi
fi
if
[
-z
"
$(
which shunit2
)
"
]
;
then
ln
-s
"
$CURDIR
/LarvaTagger/shunit2/shunit2"
test
/
fi
echo
"
${
launcher
}
test/scenarii.sh"
${
launcher
}
test
/scenarii.sh
This diff is collapsed.
Click to expand it.
test/predict_and_retrain.sh
+
4
−
1
View file @
90383bb5
#!/bin/bash
#!/usr/bin/env bash
# this script performs a few tests with the Docker image
# TODO: implement more use cases as in scenarii.sh
trap
'rm -rf "$TMPDIR"'
EXIT
...
...
This diff is collapsed.
Click to expand it.
test/scenarii.sh
+
38
−
25
View file @
90383bb5
#!/
bin/
bash
#!/
usr/bin/env
bash
if
[
-z
"
$(
which shunit2
)
"
]
;
then
echo
"shunit2 is required to run the tests"
exit
1
fi
# This script performs tests for the scripts/larvatagger-toolkit.jl command.
# See also the deploy_and_test.sh standalone script.
project_root
=
$(
dirname
"
$(
dirname
"
$(
realpath
"
${
BASH_SOURCE
[0]
}
"
)
"
)
"
)
if
[
-z
"
$(
which h5diff
)
"
]
;
then
echo
"h5diff (hdf5-tools) is required to run the tests"
if
[
-f
"
$project_root
/test/shunit2"
]
;
then
SHUNIT2
=
$(
realpath
"
$project_root
/test/shunit2"
)
elif
[
-z
"
$(
which shunit2
)
"
]
;
then
echo
"shUnit2 is required to run the tests (see https://github.com/kward/shunit2)"
exit
1
else
SHUNIT2
=
shunit2
fi
project_root
=
$(
dirname
"
$(
dirname
"
$(
realpath
"
${
BASH_SOURCE
[0]
}
"
)
"
)
"
)
# Since larva_dataset.hdf5 files cannot be compared because of absolute paths
# we no longer need `h5diff`
# if [ -z "$(which h5diff)" ]; then
# echo "h5diff (hdf5-tools) is required to run the tests"
# exit 1
# fi
if
[
-z
"
$JULIA_PROJECT
"
]
;
then
export
JULIA_PROJECT
=
$(
realpath
"
$project_root
/../TaggingBackends"
)
...
...
@@ -28,8 +38,6 @@ fi
larvataggerjl
=
"scripts/larvatagger-toolkit.jl"
# test data temporarily available at https://dl.pasteur.fr/fop/l3qruSQR/LarvaTagger_test_data.tgz
datadir
=
"test/data"
datapath
=
"
$project_root
/
$datadir
"
...
...
@@ -59,22 +67,26 @@ prepareTrainingData() {
}
testImportLabelFile
()
{
filename
=
result_imported.label
# run
cd
"
$project_root
"
echo
"
\"
$larvataggerjl
\"
import
\"
$datadir
/partial_predictions.label
\"
imported.label
--default-label=
\"
not back-up
\"
"
"
$larvataggerjl
"
import
"
$datadir
/partial_predictions.label"
result_imported.label
--default-label
=
"not back-up"
echo
"
\"
$larvataggerjl
\"
import
\"
$datadir
/partial_predictions.label
\"
$filename
--default-label=
\"
not back-up
\"
"
"
$larvataggerjl
"
import
"
$datadir
/partial_predictions.label"
$filename
--default-label
=
"not back-up"
# test
assert
Null
'\`import\` failed to reproduce the imported.label file'
"
$(
cmp
"
$datapath
/imported.label"
"
$datapath
/
result_imported.label
"
)
"
assert
True
'\`import\` failed to reproduce the imported.label file'
'
$(cmp "$datapath/imported.label" "$datapath/
$filename
")
'
# clean up
rm
-f
"
$datapath
/
result_imported.label
"
rm
-f
"
$datapath
/
$filename
"
}
testPredictDefault
()
{
tagger
=
"test_train_default
$tagger_suffix
"
tmpdir
=
$(
prepareTestData
$tagger
)
# restore the model
mkdir
-p
"
$maggotuba
/models"
rm
-rf
"
$maggotuba
/models/
$tagger
"
echo
"cp -ra
\"
$datapath
/
$tagger
\"
\"
$maggotuba
/models/
\"
"
cp
-ra
"
$datapath
/
$tagger
"
"
$maggotuba
/models/"
[
-f
"
$maggotuba
/models/
$tagger
/clf_config.json"
]
||
exit
1
# run
cd
"
$project_root
"
echo
"
\"
$larvataggerjl
\"
predict
\"
$maggotuba
\"
$tagger
\"
$tmpdir
/sample.spine
\"
"
...
...
@@ -84,7 +96,7 @@ testPredictDefault() {
predictions
=
"
$tmpdir
/
$filename
"
expected_labels
=
"
$datapath
/
$tagger
/
$filename
"
assertFalse
"
\`
predict
\`
failed to generate file
$filename
"
'[ -z "$predictions" ]'
assert
Null
"
\`
predict
\`
failed to reproduce file
$filename
"
"
$(
cmp
"
$expected_labels
"
"
$predictions
"
)
"
assert
True
"
\`
predict
\`
failed to reproduce file
$filename
"
'
$(cmp "$expected_labels" "$predictions")
'
}
testTrainDefault
()
{
...
...
@@ -127,12 +139,13 @@ postTrain() {
interim_dir
=
"
$maggotuba
/data/interim/
$tagger
"
# interim files
f
n
=
larva_dataset.hdf5
f
ilename
=
larva_dataset.hdf5
larva_dataset
=
"
$interim_dir
/
$(
cd
"
$interim_dir
"
;
ls
larva_dataset_
*
.hdf5
)
"
assertFalse
"
\`
train
\`
failed to generate file
$fn
"
'[ -z "$larva_dataset" ]'
assertNull
"
\`
train
\`
failed to reproduce file
$fn
"
"
$(
h5diff
"
$expected_tagger_dir
/
$fn
"
"
$larva_dataset
"
)
"
assertFalse
"
\`
train
\`
failed to generate file
$filename
"
'[ -z "$larva_dataset" ]'
# fails because of absolute paths
#assertTrue "\`train\` failed to reproduce file $filename" '$(h5diff "$expected_tagger_dir/$filename" "$larva_dataset")'
if
[
"
$KEEP_MODEL_FILES
"
=
"1"
]
;
then
cp
"
$larva_dataset
"
"
$tagger_dir
/
$f
n
"
cp
"
$larva_dataset
"
"
$tagger_dir
/
$f
ilename
"
fi
# test model files
...
...
@@ -148,17 +161,17 @@ postTrain() {
assertFalse
"
\`
train
\`
failed to generate file
$enc_config
"
'[ -z "$enc_config_path" ]'
assertFalse
"
\`
train
\`
failed to generate file
$clf_weights
"
'[ -z "$clf_weights_path" ]'
assertFalse
"
\`
train
\`
failed to generate file
$clf_config
"
'[ -z "$clf_config_path" ]'
assert
Null
"
\`
train
\`
failed to reproduce file
$enc_weights
"
"
$(
cmp
"
$expected_tagger_dir
/
$enc_weights
"
"
$enc_weights_path
"
)
"
assert
Null
"
\`
train
\`
failed to reproduce file
$enc_config
"
"
$(
cmp
"
$expected_tagger_dir
/
$enc_config
"
"
$enc_config_path
"
)
"
assert
Null
"
\`
train
\`
failed to reproduce file
$clf_weights
"
"
$(
cmp
"
$expected_tagger_dir
/
$clf_weights
"
"
$clf_weights_path
"
)
"
assert
Null
"
\`
train
\`
failed to reproduce file
$clf_config
"
"
$(
cmp
"
$expected_tagger_dir
/
$clf_config
"
"
$clf_config_path
"
)
"
assert
True
"
\`
train
\`
failed to reproduce file
$enc_weights
"
'
$(cmp "$expected_tagger_dir/$enc_weights" "$enc_weights_path")
'
assert
True
"
\`
train
\`
failed to reproduce file
$enc_config
"
'
$(cmp "$expected_tagger_dir/$enc_config" "$enc_config_path")
'
assert
True
"
\`
train
\`
failed to reproduce file
$clf_weights
"
'
$(cmp "$expected_tagger_dir/$clf_weights" "$clf_weights_path")
'
assert
True
"
\`
train
\`
failed to reproduce file
$clf_config
"
'
$(cmp "$expected_tagger_dir/$clf_config" "$clf_config_path")
'
# test the predictions
echo
"
\"
$larvataggerjl
\"
predict
\"
$maggotuba
\"
$tagger
\"
$tmpdir
/sample.spine
\"
"
"
$larvataggerjl
"
predict
"
$maggotuba
"
$tagger
"
$tmpdir
/sample.spine"
predictions
=
"
$tmpdir
/predicted.label"
expected_labels
=
"
$datapath
/
$tagger
/predicted.label"
assert
Null
"
\`
predict
\`
failed to reproduce file predicted.label"
"
$(
cmp
"
$expected_labels
"
"
$predictions
"
)
"
assert
True
"
\`
predict
\`
failed to reproduce file predicted.label"
'
$(cmp "$expected_labels" "$predictions")
'
# clean up
if
[
"
$KEEP_MODEL_FILES
"
=
"1"
]
;
then
...
...
@@ -169,4 +182,4 @@ postTrain() {
fi
}
.
shunit
2
.
$SHUNIT
2
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment