Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
NIFTy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Monitor
Service Desk
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
ift
NIFTy
Commits
31426c60
Commit
31426c60
authored
5 years ago
by
Philipp Arras
Browse files
Options
Downloads
Patches
Plain Diff
Fixup untested code in KL
parent
91f9c9ff
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!453
Fix mpi kl
Pipeline
#73448
failed
5 years ago
Stage: build_docker
Stage: test
Stage: demo_runs
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
nifty6/minimization/metric_gaussian_kl.py
+1
-1
1 addition, 1 deletion
nifty6/minimization/metric_gaussian_kl.py
test/test_mpi/test_kl.py
+10
-5
10 additions, 5 deletions
test/test_mpi/test_kl.py
with
11 additions
and
6 deletions
nifty6/minimization/metric_gaussian_kl.py
+
1
−
1
View file @
31426c60
...
@@ -50,7 +50,7 @@ def _allreduce_sum_field(comm, fld):
...
@@ -50,7 +50,7 @@ def _allreduce_sum_field(comm, fld):
if
comm
is
None
:
if
comm
is
None
:
return
fld
return
fld
if
isinstance
(
fld
,
Field
):
if
isinstance
(
fld
,
Field
):
return
Field
(
fld
.
domain
,
_np_allreduce_sum
(
fld
.
val
))
return
Field
(
fld
.
domain
,
_np_allreduce_sum
(
comm
,
fld
.
val
))
res
=
tuple
(
res
=
tuple
(
Field
(
f
.
domain
,
_np_allreduce_sum
(
comm
,
f
.
val
))
Field
(
f
.
domain
,
_np_allreduce_sum
(
comm
,
f
.
val
))
for
f
in
fld
.
values
())
for
f
in
fld
.
values
())
...
...
This diff is collapsed.
Click to expand it.
test/test_mpi/test_kl.py
+
10
−
5
View file @
31426c60
...
@@ -40,6 +40,8 @@ pms = pytest.mark.skipif
...
@@ -40,6 +40,8 @@ pms = pytest.mark.skipif
@pmp
(
'
mode
'
,
(
0
,
1
))
@pmp
(
'
mode
'
,
(
0
,
1
))
@pmp
(
'
mf
'
,
(
False
,
True
))
@pmp
(
'
mf
'
,
(
False
,
True
))
def
test_kl
(
constants
,
point_estimates
,
mirror_samples
,
mode
,
mf
):
def
test_kl
(
constants
,
point_estimates
,
mirror_samples
,
mode
,
mf
):
if
not
mf
and
(
len
(
point_estimates
)
!=
0
or
len
(
constants
)
!=
0
):
return
dom
=
ift
.
RGSpace
((
12
,),
(
2.12
))
dom
=
ift
.
RGSpace
((
12
,),
(
2.12
))
op
=
ift
.
HarmonicSmoothingOperator
(
dom
,
3
)
op
=
ift
.
HarmonicSmoothingOperator
(
dom
,
3
)
if
mf
:
if
mf
:
...
@@ -67,10 +69,18 @@ def test_kl(constants, point_estimates, mirror_samples, mode, mf):
...
@@ -67,10 +69,18 @@ def test_kl(constants, point_estimates, mirror_samples, mode, mf):
locsamp
=
samples
[
slc
]
locsamp
=
samples
[
slc
]
kl1
=
ift
.
MetricGaussianKL
(
**
args
,
comm
=
comm
,
_local_samples
=
locsamp
)
kl1
=
ift
.
MetricGaussianKL
(
**
args
,
comm
=
comm
,
_local_samples
=
locsamp
)
# Test number of samples
expected_nsamps
=
2
*
nsamps
if
mirror_samples
else
nsamps
assert_
(
len
(
tuple
(
kl0
.
samples
))
==
expected_nsamps
)
assert_
(
len
(
tuple
(
kl1
.
samples
))
==
expected_nsamps
)
# Test value
# Test value
assert_allclose
(
kl0
.
value
,
kl1
.
value
)
assert_allclose
(
kl0
.
value
,
kl1
.
value
)
# Test gradient
# Test gradient
if
not
mf
:
ift
.
extra
.
assert_allclose
(
kl0
.
gradient
,
kl1
.
gradient
,
0
,
1e-14
)
return
for
kk
in
h
.
domain
.
keys
():
for
kk
in
h
.
domain
.
keys
():
res0
=
kl0
.
gradient
[
kk
].
val
res0
=
kl0
.
gradient
[
kk
].
val
if
kk
in
constants
:
if
kk
in
constants
:
...
@@ -78,11 +88,6 @@ def test_kl(constants, point_estimates, mirror_samples, mode, mf):
...
@@ -78,11 +88,6 @@ def test_kl(constants, point_estimates, mirror_samples, mode, mf):
res1
=
kl1
.
gradient
[
kk
].
val
res1
=
kl1
.
gradient
[
kk
].
val
assert_allclose
(
res0
,
res1
)
assert_allclose
(
res0
,
res1
)
# Test number of samples
expected_nsamps
=
2
*
nsamps
if
mirror_samples
else
nsamps
assert_
(
len
(
tuple
(
kl0
.
samples
))
==
expected_nsamps
)
assert_
(
len
(
tuple
(
kl1
.
samples
))
==
expected_nsamps
)
# Test point_estimates (after drawing samples)
# Test point_estimates (after drawing samples)
for
kk
in
point_estimates
:
for
kk
in
point_estimates
:
for
ss
in
kl0
.
samples
:
for
ss
in
kl0
.
samples
:
...
...
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