Skip to content

Commit

Permalink
Merge pull request #85 from pymc-devs/fix-84
Browse files Browse the repository at this point in the history
Stop importing test suite from __init__
  • Loading branch information
brandonwillard committed Oct 7, 2020
2 parents 295ea57 + 21a993e commit 1d3454f
Show file tree
Hide file tree
Showing 14 changed files with 78 additions and 117 deletions.
4 changes: 2 additions & 2 deletions doc/tutorial/debug_faq.txt
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ Breakpoint during Theano function execution
-------------------------------------------

You can set a breakpoint during the execution of a Theano function with
:class:`PdbBreakpoint <tests.breakpoint.PdbBreakpoint>`.
:class:`PdbBreakpoint <tests.breakpoint.PdbBreakpoint>` automatically
:class:`PdbBreakpoint <theano.breakpoint.PdbBreakpoint>`.
:class:`PdbBreakpoint <theano.breakpoint.PdbBreakpoint>` automatically
detects available debuggers and uses the first available in the following order:
`pudb`, `ipdb`, or `pdb`.
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[flake8]
ignore=E501,E123,E133,FI12,FI14,FI15,FI50,FI51,FI53,W503,W504,E203,C901,E231,E741
per-file-ignores =
theano/sparse/sandbox/truedot.py:F401
theano/sparse/sandbox/sp2.py:F401
tests/sparse/test_basic.py:E402
tests/sparse/test_opt.py:E402
Expand Down
2 changes: 1 addition & 1 deletion tests/gpuarray/test_basic_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

from tests import unittest_tools as utt
from tests.gpuarray.config import mode_with_gpu, mode_without_gpu, test_ctx_name
from tests.theano.tensor.test_basic import (
from tests.tensor.test_basic import (
rand,
safe_make_node,
TestAlloc,
Expand Down
4 changes: 2 additions & 2 deletions tests/gpuarray/test_gemmcorr.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@

from tests import unittest_tools as utt
from tests.gpuarray.config import mode_with_gpu, mode_without_gpu, ref_cast
from tests.theano.tensor.nnet.test_abstract_conv import (
from tests.tensor.nnet.test_abstract_conv import (
TestGroupedConvNoOptim,
TestUnsharedConv,
)
from tests.tensor.nnet.theano.test_abstract_conv import (
from tests.tensor.nnet.test_abstract_conv import (
TestAsymmetricPadding,
TestCausalConv,
)
Expand Down
2 changes: 1 addition & 1 deletion tests/gpuarray/test_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from theano import tensor
from theano.gof.opt import check_stack_trace
from theano.tensor.nnet import abstract_conv
from theano.breakpoint import PdbBreakpoint
from theano.gpuarray import basic_ops
from theano.gpuarray.type import GpuArrayType, gpuarray_shared_constructor, get_context
from theano.gpuarray.basic_ops import (
Expand All @@ -34,7 +35,6 @@

from tests import unittest_tools as utt, test_ifelse
from tests.tensor import test_basic
from tests.breakpoint import PdbBreakpoint
from tests.gpuarray.config import mode_with_gpu, mode_without_gpu, test_ctx_name


Expand Down
2 changes: 1 addition & 1 deletion tests/gpuarray/test_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from tests.gpuarray.test_basic_ops import rand_gpuarray

# Disabled for now
# from tests.theano.tensor.test_sharedvar import makeSharedTester
# from tests.tensor.test_sharedvar import makeSharedTester


def test_deep_copy():
Expand Down
3 changes: 2 additions & 1 deletion tests/test_breakpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import theano
import theano.tensor as T

from theano.breakpoint import PdbBreakpoint

from tests import unittest_tools as utt
from tests.breakpoint import PdbBreakpoint


class TestPdbBreakpoint(utt.InferShapeTester):
Expand Down
67 changes: 1 addition & 66 deletions tests/unittest_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
from copy import copy, deepcopy

from six import integer_types
from six.moves import StringIO

from theano import config
from theano.compile.debugmode import str_diagnostic


_logger = logging.getLogger("tests.unittest_tools")
Expand Down Expand Up @@ -282,71 +282,6 @@ def _compile_and_check(
assert np.all(out.shape == shape), (out.shape, shape)


def str_diagnostic(expected, value, rtol, atol):
"""Return a pretty multiline string representating the cause
of the exception"""
sio = StringIO()

try:
ssio = StringIO()
print(" : shape, dtype, strides, min, max, n_inf, n_nan:", file=ssio)
print(" Expected :", end=" ", file=ssio)
print(expected.shape, end=" ", file=ssio)
print(expected.dtype, end=" ", file=ssio)
print(expected.strides, end=" ", file=ssio)
print(expected.min(), end=" ", file=ssio)
print(expected.max(), end=" ", file=ssio)
print(np.isinf(expected).sum(), end=" ", file=ssio)
print(np.isnan(expected).sum(), end=" ", file=ssio)
# only if all succeeds to we add anything to sio
print(ssio.getvalue(), file=sio)
except Exception:
pass
try:
ssio = StringIO()
print(" Value :", end=" ", file=ssio)
print(value.shape, end=" ", file=ssio)
print(value.dtype, end=" ", file=ssio)
print(value.strides, end=" ", file=ssio)
print(value.min(), end=" ", file=ssio)
print(value.max(), end=" ", file=ssio)
print(np.isinf(value).sum(), end=" ", file=ssio)
print(np.isnan(value).sum(), end=" ", file=ssio)
# only if all succeeds to we add anything to sio
print(ssio.getvalue(), file=sio)
except Exception:
pass

print(" expected :", expected, file=sio)
print(" value :", value, file=sio)

try:
ov = np.asarray(expected)
nv = np.asarray(value)
ssio = StringIO()
absdiff = np.absolute(nv - ov)
print(" Max Abs Diff: ", np.max(absdiff), file=ssio)
print(" Mean Abs Diff: ", np.mean(absdiff), file=ssio)
print(" Median Abs Diff: ", np.median(absdiff), file=ssio)
print(" Std Abs Diff: ", np.std(absdiff), file=ssio)
reldiff = np.absolute(nv - ov) / np.absolute(ov)
print(" Max Rel Diff: ", np.max(reldiff), file=ssio)
print(" Mean Rel Diff: ", np.mean(reldiff), file=ssio)
print(" Median Rel Diff: ", np.median(reldiff), file=ssio)
print(" Std Rel Diff: ", np.std(reldiff), file=ssio)
# only if all succeeds to we add anything to sio
print(ssio.getvalue(), file=sio)
except Exception:
pass
atol_, rtol_ = T.basic._get_atol_rtol(expected, value)
if rtol is not None:
rtol_ = rtol
if atol is not None:
atol_ = atol
print(" rtol, atol:", rtol_, atol_, file=sio)
return sio.getvalue()


class WrongValue(Exception):
def __init__(self, expected_val, val, rtol, atol):
Exception.__init__(self) # to be compatible with python2.4
Expand Down
4 changes: 0 additions & 4 deletions theano/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,6 @@ def disable_log_handler(logger=theano_logger, handler=logging_default_handler):

from theano.gradient import Rop, Lop, grad, subgraph_grad

# This need to be before the init of GPU, as it add config variable
# needed during that phase.
import tests

if (
config.device.startswith("cuda")
or config.device.startswith("opencl")
Expand Down
2 changes: 1 addition & 1 deletion tests/breakpoint.py → theano/breakpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class PdbBreakpoint(Op):
import theano
import theano.tensor as T
from tests.breakpoint import PdbBreakpoint
from theano.breakpoint import PdbBreakpoint
input = T.fvector()
target = T.fvector()
Expand Down
70 changes: 66 additions & 4 deletions theano/compile/debugmode.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,7 @@ def str_diagnostic(self):
print(" thunk1 :", self.thunk1, file=sio)
print(" thunk2 :", self.thunk2, file=sio)

# Don't import it at the top of the file to prevent circular import.
import tests.unittest_tools as utt

print(utt.str_diagnostic(self.val1, self.val2, None, None), file=sio)
print(str_diagnostic(self.val1, self.val2, None, None), file=sio)
ret = sio.getvalue()
return ret

Expand Down Expand Up @@ -382,6 +379,71 @@ def __str__(self):
########################


def str_diagnostic(expected, value, rtol, atol):
"""Return a pretty multiline string representating the cause
of the exception"""
sio = StringIO()

try:
ssio = StringIO()
print(" : shape, dtype, strides, min, max, n_inf, n_nan:", file=ssio)
print(" Expected :", end=" ", file=ssio)
print(expected.shape, end=" ", file=ssio)
print(expected.dtype, end=" ", file=ssio)
print(expected.strides, end=" ", file=ssio)
print(expected.min(), end=" ", file=ssio)
print(expected.max(), end=" ", file=ssio)
print(np.isinf(expected).sum(), end=" ", file=ssio)
print(np.isnan(expected).sum(), end=" ", file=ssio)
# only if all succeeds to we add anything to sio
print(ssio.getvalue(), file=sio)
except Exception:
pass
try:
ssio = StringIO()
print(" Value :", end=" ", file=ssio)
print(value.shape, end=" ", file=ssio)
print(value.dtype, end=" ", file=ssio)
print(value.strides, end=" ", file=ssio)
print(value.min(), end=" ", file=ssio)
print(value.max(), end=" ", file=ssio)
print(np.isinf(value).sum(), end=" ", file=ssio)
print(np.isnan(value).sum(), end=" ", file=ssio)
# only if all succeeds to we add anything to sio
print(ssio.getvalue(), file=sio)
except Exception:
pass

print(" expected :", expected, file=sio)
print(" value :", value, file=sio)

try:
ov = np.asarray(expected)
nv = np.asarray(value)
ssio = StringIO()
absdiff = np.absolute(nv - ov)
print(" Max Abs Diff: ", np.max(absdiff), file=ssio)
print(" Mean Abs Diff: ", np.mean(absdiff), file=ssio)
print(" Median Abs Diff: ", np.median(absdiff), file=ssio)
print(" Std Abs Diff: ", np.std(absdiff), file=ssio)
reldiff = np.absolute(nv - ov) / np.absolute(ov)
print(" Max Rel Diff: ", np.max(reldiff), file=ssio)
print(" Mean Rel Diff: ", np.mean(reldiff), file=ssio)
print(" Median Rel Diff: ", np.median(reldiff), file=ssio)
print(" Std Rel Diff: ", np.std(reldiff), file=ssio)
# only if all succeeds to we add anything to sio
print(ssio.getvalue(), file=sio)
except Exception:
pass
atol_, rtol_ = theano.tensor.basic._get_atol_rtol(expected, value)
if rtol is not None:
rtol_ = rtol
if atol is not None:
atol_ = atol
print(" rtol, atol:", rtol_, atol_, file=sio)
return sio.getvalue()


def char_from_number(number):
"""
Converts number to string by rendering it in base 26 using
Expand Down
2 changes: 1 addition & 1 deletion theano/gpuarray/opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
import theano.tensor.slinalg as slinalg
from collections import Counter

from tests.breakpoint import PdbBreakpoint
from theano.breakpoint import PdbBreakpoint

from .type import (
GpuArrayType,
Expand Down
9 changes: 0 additions & 9 deletions theano/sandbox/cuda/__init__.py

This file was deleted.

23 changes: 0 additions & 23 deletions theano/sparse/sandbox/truedot.py

This file was deleted.

0 comments on commit 1d3454f

Please sign in to comment.