Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pycalibration
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Model registry
Analyze
Contributor 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
calibration
pycalibration
Commits
a4f8cba7
Commit
a4f8cba7
authored
1 year ago
by
Thomas Kluyver
Browse files
Options
Downloads
Patches
Plain Diff
Format test code
parent
3741c366
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!933
[Tests] clearer comparison of HDF5 files
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_reference_runs/test_pre_deployment.py
+51
-38
51 additions, 38 deletions
tests/test_reference_runs/test_pre_deployment.py
with
51 additions
and
38 deletions
tests/test_reference_runs/test_pre_deployment.py
+
51
−
38
View file @
a4f8cba7
import
hashlib
import
io
import
io
import
logging
import
logging
import
multiprocessing
import
multiprocessing
import
pathlib
import
pathlib
import
tempfile
import
time
import
time
from
contextlib
import
redirect_stdout
from
contextlib
import
redirect_stdout
from
dataclasses
import
dataclass
from
dataclasses
import
dataclass
...
@@ -46,19 +44,23 @@ class ComparisonResult:
...
@@ -46,19 +44,23 @@ class ComparisonResult:
for
ds
in
self
.
changed_dsets
:
for
ds
in
self
.
changed_dsets
:
print
(
f
"
~ CHANGED:
{
ds
}
"
)
print
(
f
"
~ CHANGED:
{
ds
}
"
)
def
gather_dsets
(
f
:
h5py
.
File
):
def
gather_dsets
(
f
:
h5py
.
File
):
res
=
set
()
res
=
set
()
def
visitor
(
name
,
obj
):
def
visitor
(
name
,
obj
):
if
isinstance
(
obj
,
h5py
.
Dataset
):
if
isinstance
(
obj
,
h5py
.
Dataset
):
res
.
add
(
name
)
res
.
add
(
name
)
f
.
visititems
(
visitor
)
f
.
visititems
(
visitor
)
return
res
return
res
def
validate_file
(
def
validate_file
(
ref_folder
:
pathlib
.
PosixPath
,
ref_folder
:
pathlib
.
PosixPath
,
out_folder
:
pathlib
.
PosixPath
,
out_folder
:
pathlib
.
PosixPath
,
exclude_dsets
:
set
,
exclude_dsets
:
set
,
test_file
:
str
test_file
:
str
,
)
->
ComparisonResult
:
)
->
ComparisonResult
:
res
=
ComparisonResult
(
test_file
,
[],
[],
[])
res
=
ComparisonResult
(
test_file
,
[],
[],
[])
ref_file
=
ref_folder
/
test_file
ref_file
=
ref_folder
/
test_file
...
@@ -77,7 +79,7 @@ def validate_file(
...
@@ -77,7 +79,7 @@ def validate_file(
eq
=
np
.
array_equal
(
ref_arr
,
out_arr
,
equal_nan
=
True
)
eq
=
np
.
array_equal
(
ref_arr
,
out_arr
,
equal_nan
=
True
)
else
:
else
:
# Both single values
# Both single values
eq
=
(
ref_arr
==
out_arr
)
eq
=
ref_arr
==
out_arr
if
not
eq
:
if
not
eq
:
changed
.
append
(
dsname
)
changed
.
append
(
dsname
)
...
@@ -85,9 +87,10 @@ def validate_file(
...
@@ -85,9 +87,10 @@ def validate_file(
test_file
,
test_file
,
new_dsets
=
sorted
(
out_dsets
-
ref_dsets
),
new_dsets
=
sorted
(
out_dsets
-
ref_dsets
),
missing_dsets
=
sorted
(
ref_dsets
-
out_dsets
),
missing_dsets
=
sorted
(
ref_dsets
-
out_dsets
),
changed_dsets
=
changed
changed_dsets
=
changed
,
)
)
def
parse_config
(
cmd
:
List
[
str
],
config
:
Dict
[
str
,
Any
],
out_folder
:
str
)
->
List
[
str
]:
def
parse_config
(
cmd
:
List
[
str
],
config
:
Dict
[
str
,
Any
],
out_folder
:
str
)
->
List
[
str
]:
"""
Convert a dictionary to a list of arguments.
"""
Convert a dictionary to a list of arguments.
...
@@ -177,11 +180,7 @@ def validate_hdf5_files(
...
@@ -177,11 +180,7 @@ def validate_hdf5_files(
assert
ok
,
"
HDF5 files changed - see details above
"
assert
ok
,
"
HDF5 files changed - see details above
"
def
slurm_watcher
(
test_key
:
str
,
std_out
:
str
):
def
slurm_watcher
(
test_key
:
str
,
std_out
:
str
):
"""
"""
Watch for submitted slurm jobs and wait for them to finish.
Watch for submitted slurm jobs and wait for them to finish.
After they finish apply first test and check
After they finish apply first test and check
...
@@ -208,19 +207,25 @@ def slurm_watcher(
...
@@ -208,19 +207,25 @@ def slurm_watcher(
res
=
run
(
cmd
,
stdout
=
PIPE
)
res
=
run
(
cmd
,
stdout
=
PIPE
)
states
=
res
.
stdout
.
decode
().
split
(
"
\n
"
)[
2
:
-
1
]
states
=
res
.
stdout
.
decode
().
split
(
"
\n
"
)[
2
:
-
1
]
if
not
any
(
s
.
strip
()
in
[
if
not
any
(
"
COMPLETING
"
,
s
.
strip
()
"
RUNNING
"
,
in
[
"
CONFIGURING
"
,
"
COMPLETING
"
,
"
PENDING
"
,
"
RUNNING
"
,
]
for
s
in
states
):
"
CONFIGURING
"
,
"
PENDING
"
,
]
for
s
in
states
):
slurm_watcher
=
False
slurm_watcher
=
False
else
:
else
:
time
.
sleep
(
2
)
time
.
sleep
(
2
)
# 1st check that all jobs were COMPLETED without errors.
# 1st check that all jobs were COMPLETED without errors.
states
=
res
.
stdout
.
decode
().
split
(
"
\n
"
)[
2
:
-
1
]
states
=
res
.
stdout
.
decode
().
split
(
"
\n
"
)[
2
:
-
1
]
assert
all
(
s
.
strip
()
==
"
COMPLETED
"
for
s
in
states
),
f
"
{
test_key
}
failure, calibration jobs were not completed.
{
jobids
}
:
{
states
}
"
# noqa
assert
all
(
s
.
strip
()
==
"
COMPLETED
"
for
s
in
states
),
f
"
{
test_key
}
failure, calibration jobs were not completed.
{
jobids
}
:
{
states
}
"
# noqa
LOGGER
.
info
(
f
"
{
test_key
}
'
s jobs were COMPLETED
"
)
LOGGER
.
info
(
f
"
{
test_key
}
'
s jobs were COMPLETED
"
)
...
@@ -230,11 +235,8 @@ def slurm_watcher(
...
@@ -230,11 +235,8 @@ def slurm_watcher(
list
(
automated_test_config
.
items
()),
list
(
automated_test_config
.
items
()),
ids
=
list
(
automated_test_config
.
keys
()),
ids
=
list
(
automated_test_config
.
keys
()),
)
)
def
test_xfel_calibrate
(
def
test_xfel_calibrate
(
test_key
:
str
,
val_dict
:
dict
,
release_test_config
:
Tuple
):
test_key
:
str
,
val_dict
:
dict
,
"""
Test xfel calibrate detectors and calibrations written
release_test_config
:
Tuple
[
bool
,
bool
,
bool
,
bool
]
):
"""
Test xfel calibrate detectors and calibrations written
in the given callab_test YAML file.
in the given callab_test YAML file.
Args:
Args:
test_key : Key for the xfel-calibrate test.
test_key : Key for the xfel-calibrate test.
...
@@ -244,9 +246,14 @@ def test_xfel_calibrate(
...
@@ -244,9 +246,14 @@ def test_xfel_calibrate(
"""
"""
(
(
detectors
,
calibration
,
picked_test
,
detectors
,
skip_numerical_validation
,
only_validate
,
calibration
,
use_slurm
,
reference_dir_base
,
out_dir_base
,
picked_test
,
skip_numerical_validation
,
only_validate
,
use_slurm
,
reference_dir_base
,
out_dir_base
,
)
=
release_test_config
)
=
release_test_config
cal_type
=
val_dict
[
"
cal_type
"
]
cal_type
=
val_dict
[
"
cal_type
"
]
...
@@ -254,10 +261,9 @@ def test_xfel_calibrate(
...
@@ -254,10 +261,9 @@ def test_xfel_calibrate(
if
not
picked_test
:
if
not
picked_test
:
# Skip non-selected detectors
# Skip non-selected detectors
if
(
if
detectors
!=
[
"
all
"
]
and
det_type
.
lower
()
not
in
[
detectors
!=
[
"
all
"
]
and
d
.
lower
()
for
d
in
detectors
det_type
.
lower
()
not
in
[
d
.
lower
()
for
d
in
detectors
]
]:
):
pytest
.
skip
()
pytest
.
skip
()
# Skip non-selected calibration
# Skip non-selected calibration
...
@@ -271,14 +277,16 @@ def test_xfel_calibrate(
...
@@ -271,14 +277,16 @@ def test_xfel_calibrate(
cal_conf
=
val_dict
[
"
config
"
]
cal_conf
=
val_dict
[
"
config
"
]
out_folder
=
pathlib
.
Path
(
cal_conf
[
"
out-folder
"
].
format
(
out_folder
=
pathlib
.
Path
(
out_dir_base
,
cal_conf
[
"
karabo-id
"
],
test_key
))
cal_conf
[
"
out-folder
"
].
format
(
out_dir_base
,
cal_conf
[
"
karabo-id
"
],
test_key
)
reference_folder
=
pathlib
.
Path
(
val_dict
[
"
reference-folder
"
].
format
(
)
reference_dir_base
,
cal_conf
[
"
karabo-id
"
],
test_key
))
reference_folder
=
pathlib
.
Path
(
val_dict
[
"
reference-folder
"
].
format
(
reference_dir_base
,
cal_conf
[
"
karabo-id
"
],
test_key
)
)
report_name
=
(
report_name
=
out_folder
/
f
"
{
test_key
}
_
{
datetime
.
now
().
strftime
(
'
%y%m%d_%H%M%S
'
)
}
"
out_folder
/
f
"
{
test_key
}
_
{
datetime
.
now
().
strftime
(
'
%y%m%d_%H%M%S
'
)
}
"
)
cal_conf
[
"
report-to
"
]
=
str
(
report_name
)
cal_conf
[
"
report-to
"
]
=
str
(
report_name
)
...
@@ -290,13 +298,18 @@ def test_xfel_calibrate(
...
@@ -290,13 +298,18 @@ def test_xfel_calibrate(
out_folder
,
out_folder
,
reference_folder
,
reference_folder
,
cal_type
,
cal_type
,
)
)
return
return
if
not
use_slurm
:
# e.g. for Gitlab CI.
if
not
use_slurm
:
# e.g. for Gitlab CI.
cmd
+=
[
"
--no-cluster-job
"
]
cmd
+=
[
"
--no-cluster-job
"
]
cmd
+=
[
"
--slurm-name
"
,
test_key
,
"
--cal-db-interface
"
,
"
tcp://max-exfl-cal001:8015#8045
"
]
cmd
+=
[
"
--slurm-name
"
,
test_key
,
"
--cal-db-interface
"
,
"
tcp://max-exfl-cal001:8015#8045
"
,
]
f
=
io
.
StringIO
()
f
=
io
.
StringIO
()
LOGGER
.
info
(
f
"
Submitting CL:
{
cmd
}
"
)
LOGGER
.
info
(
f
"
Submitting CL:
{
cmd
}
"
)
with
redirect_stdout
(
f
):
with
redirect_stdout
(
f
):
...
...
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