Commit 7130009c authored by Philipp Arras's avatar Philipp Arras
Browse files

Speed up jacobian tests

parent d6f6bbde
Pipeline #75149 passed with stages
in 10 minutes and 30 seconds
......@@ -11,11 +11,10 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Copyright(C) 2013-2019 Max-Planck-Society
# Copyright(C) 2013-2020 Max-Planck-Society
#
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik.
import numpy as np
import pytest
import nifty6 as ift
......@@ -24,17 +23,18 @@ from ..common import list2fixture, setup_function, teardown_function
pmp = pytest.mark.parametrize
space = list2fixture([
ift.GLSpace(15),
ift.RGSpace(64, distances=.789),
ift.RGSpace([32, 32], distances=.789)
ift.GLSpace(5),
ift.RGSpace(3, distances=.789),
ift.RGSpace([4, 4], distances=.789)
])
_h_RG_spaces = [
ift.RGSpace(7, distances=0.2, harmonic=True),
ift.RGSpace((12, 46), distances=(.2, .3), harmonic=True)
ift.RGSpace((3, 4), distances=(.2, .3), harmonic=True)
]
_h_spaces = _h_RG_spaces + [ift.LMSpace(17)]
space1 = space
seed = list2fixture([4, 78, 23])
seed = list2fixture([4, 78])
ntries = 10
def testBasics(space, seed):
......@@ -42,7 +42,7 @@ def testBasics(space, seed):
s = ift.from_random('normal', space)
var = ift.Linearization.make_var(s)
model = ift.ScalingOperator(var.target, 6.)
ift.extra.check_jacobian_consistency(model, var.val)
ift.extra.check_jacobian_consistency(model, var.val, ntries=ntries)
@pmp('type1', ['Variable', 'Constant'])
......@@ -56,36 +56,36 @@ def testBinary(type1, type2, space, seed):
select_s2 = ift.ducktape(None, dom2, "s2")
model = select_s1*select_s2
pos = ift.from_random("normal", dom)
ift.extra.check_jacobian_consistency(model, pos, ntries=20)
ift.extra.check_jacobian_consistency(model, pos, ntries=ntries)
model = select_s1 + select_s2
pos = ift.from_random("normal", dom)
ift.extra.check_jacobian_consistency(model, pos, ntries=20)
ift.extra.check_jacobian_consistency(model, pos, ntries=ntries)
model = select_s1.scale(3.)
pos = ift.from_random("normal", dom1)
ift.extra.check_jacobian_consistency(model, pos, ntries=20)
ift.extra.check_jacobian_consistency(model, pos, ntries=ntries)
model = ift.ScalingOperator(space, 2.456)(select_s1*select_s2)
pos = ift.from_random("normal", dom)
ift.extra.check_jacobian_consistency(model, pos, ntries=20)
ift.extra.check_jacobian_consistency(model, pos, ntries=ntries)
model = (2.456*(select_s1*select_s2)).ptw("sigmoid")
pos = ift.from_random("normal", dom)
ift.extra.check_jacobian_consistency(model, pos, ntries=20)
ift.extra.check_jacobian_consistency(model, pos, ntries=ntries)
pos = ift.from_random("normal", dom)
model = ift.OuterProduct(pos['s1'], ift.makeDomain(space))
ift.extra.check_jacobian_consistency(model, pos['s2'], ntries=20)
ift.extra.check_jacobian_consistency(model, pos['s2'], ntries=ntries)
model = select_s1**2
pos = ift.from_random("normal", dom1)
ift.extra.check_jacobian_consistency(model, pos, ntries=20)
ift.extra.check_jacobian_consistency(model, pos, ntries=ntries)
model = select_s1.clip(-1, 1)
pos = ift.from_random("normal", dom1)
ift.extra.check_jacobian_consistency(model, pos, ntries=20)
ift.extra.check_jacobian_consistency(model, pos, ntries=ntries)
f = ift.from_random("normal", space)
model = select_s1.clip(f-0.1, f+1.)
pos = ift.from_random("normal", dom1)
ift.extra.check_jacobian_consistency(model, pos, ntries=20)
ift.extra.check_jacobian_consistency(model, pos, ntries=ntries)
if isinstance(space, ift.RGSpace):
model = ift.FFTOperator(space)(select_s1*select_s2)
pos = ift.from_random("normal", dom)
ift.extra.check_jacobian_consistency(model, pos, ntries=20)
ift.extra.check_jacobian_consistency(model, pos, ntries=ntries)
def testSpecialDistributionOps(space, seed):
......@@ -105,31 +105,27 @@ def testAdder(space, seed, neg):
f = ift.from_random('normal', space)
f1 = ift.from_random('normal', space)
op = ift.Adder(f1, neg)
ift.extra.check_jacobian_consistency(op, f)
ift.extra.check_jacobian_consistency(op, f, ntries=ntries)
op = ift.Adder(f1.val.ravel()[0], neg=neg, domain=space)
ift.extra.check_jacobian_consistency(op, f)
ift.extra.check_jacobian_consistency(op, f, ntries=ntries)
@pmp('target', [ift.RGSpace(64, distances=.789, harmonic=True),
ift.RGSpace([32, 32], distances=.789, harmonic=True),
ift.RGSpace([32, 32, 8], distances=.789, harmonic=True)])
ift.RGSpace([10, 10], distances=.789, harmonic=True)])
@pmp('causal', [True, False])
@pmp('minimum_phase', [True, False])
def testDynamicModel(target, causal, minimum_phase, seed):
with ift.random.Context(seed):
dct = {
'target': target,
'harmonic_padding': None,
'sm_s0': 3.,
'sm_x0': 1.,
'key': 'f',
'causal': causal,
'minimum_phase': minimum_phase
}
dct = {'target': target,
'harmonic_padding': None,
'sm_s0': 3.,
'sm_x0': 1.,
'key': 'f',
'causal': causal,
'minimum_phase': minimum_phase}
model, _ = ift.dynamic_operator(**dct)
pos = ift.from_random('normal', model.domain)
# FIXME I dont know why smaller tol fails for 3D example
ift.extra.check_jacobian_consistency(model, pos, tol=1e-5, ntries=20)
ift.extra.check_jacobian_consistency(model, pos, tol=1e-7, ntries=ntries)
if len(target.shape) > 1:
dct = {
'target': target,
......@@ -148,9 +144,7 @@ def testDynamicModel(target, causal, minimum_phase, seed):
dct['quant'] = 5
model, _ = ift.dynamic_lightcone_operator(**dct)
pos = ift.from_random('normal', model.domain)
# FIXME I dont know why smaller tol fails for 3D example
ift.extra.check_jacobian_consistency(
model, pos, tol=1e-5, ntries=20)
ift.extra.check_jacobian_consistency(model, pos, tol=1e-7, ntries=ntries)
@pmp('h_space', _h_spaces)
......@@ -160,11 +154,10 @@ def testDynamicModel(target, causal, minimum_phase, seed):
def testNormalization(h_space, specialbinbounds, logarithmic, nbin):
if not specialbinbounds and (not logarithmic or nbin is not None):
return
binbounds = None
if specialbinbounds:
binbounds = ift.PowerSpace.useful_binbounds(h_space, logarithmic, nbin)
else:
binbounds = None
dom = ift.PowerSpace(h_space, binbounds)
op = ift.library.correlated_fields._Normalization(dom)
pos = 0.1*ift.from_random('normal', op.domain)
ift.extra.check_jacobian_consistency(op, pos)
ift.extra.check_jacobian_consistency(op, pos, ntries=10)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment