You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To understand the causes of massive test failures,
PyTorch tensors (on the low level) are strictly-typed and does not support dynamic casting. For example, one can not add a Double tensor with a Float tensor without explicitly casting one to the other's type.
PyTorch supports globally setting the default type of tensors via torch.set_default_dtype(...), which will be used for all tensors subsequently created, until the current process exits. If no calls to torch.set_default_dtype are made, PyTorch will work out default tensor type using some unknown strategies.
When python evaluates a script (for import or any other purposes), it runs everything in that module verbatim. In other words, Python is not intelligently only evaluate bar when a user executes from foo import bar. Instead, it runs (evaluates) the entire filefoo.py and registers foo.bar to the current namespace.
[To be confirmed] When pytest is executed with no arguments, it searches for all files matching the test_*.py pattern, executes them one at a time (in the same process), registers all target functions beginning with test in all files, and runs all registered targets. Note that in this manner, if default types are specified multiple times in different .py files, only the last call takes effect.
In our case, default tensor types are different among test files. Therefore, running any individual test files yields no error (which is the common workflow when using an IDE like PyCharm) while running all tests together in a single process results in failure (which is the case for our travis-ci build config).
Behavior
To verify our theory, consider the following ways of runnings tests
Scenario A: Running all test files together using
pytest tests/test_*.py
# or, without arguments
pytest
causes some test cases to fail because of Float vs Double type mismatch
Scenario B: Running each test file one at a time using
forfilein tests/test_*.py;do
pytest $filedone
yields no error (except for the technical debt in test_pde_spherical.py)
Solution
Modify the following line in .travis.yml
- pytest --cov-report term --cov=neurodiffeq/
to do pytest one file at a time.
I'm not familiar with Travis config's syntax, but probably something like
Causes of Test Failure
To understand the causes of massive test failures,
PyTorch tensors (on the low level) are strictly-typed and does not support dynamic casting. For example, one can not add a
Double
tensor with aFloat
tensor without explicitly casting one to the other's type.PyTorch supports globally setting the default type of tensors via
torch.set_default_dtype(...)
, which will be used for all tensors subsequently created, until the current process exits. If no calls totorch.set_default_dtype
are made, PyTorch will work out default tensor type using some unknown strategies.When python evaluates a script (for import or any other purposes), it runs everything in that module verbatim. In other words, Python is not intelligently only evaluate
bar
when a user executesfrom foo import bar
. Instead, it runs (evaluates) the entire filefoo.py
and registersfoo.bar
to the current namespace.[To be confirmed] When
pytest
is executed with no arguments, it searches for all files matching thetest_*.py
pattern, executes them one at a time (in the same process), registers all target functions beginning withtest
in all files, and runs all registered targets. Note that in this manner, if default types are specified multiple times in different.py
files, only the last call takes effect.In our case, default tensor types are different among test files. Therefore, running any individual test files yields no error (which is the common workflow when using an IDE like PyCharm) while running all tests together in a single process results in failure (which is the case for our travis-ci build config).
Behavior
To verify our theory, consider the following ways of runnings tests
causes some test cases to fail because of
Float
vsDouble
type mismatchyields no error (except for the technical debt in
test_pde_spherical.py
)Solution
Modify the following line in
.travis.yml
- pytest --cov-report term --cov=neurodiffeq/
to do
pytest
one file at a time.I'm not familiar with Travis config's syntax, but probably something like
Is there a more elegant way of doing this?
The text was updated successfully, but these errors were encountered: