Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined names in lax_numpy_test.py #204

Open
cclauss opened this issue Jan 7, 2020 · 0 comments
Open

Undefined names in lax_numpy_test.py #204

cclauss opened this issue Jan 7, 2020 · 0 comments

Comments

@cclauss
Copy link
Contributor

@cclauss cclauss commented Jan 7, 2020

Description

flake8 testing of https://github.com/google/trax on Python 3.8.0

$ flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics

./trax/tf_numpy/jax_tests/lax_numpy_test.py:588:12: F821 undefined name 'FLAGS'
    if not FLAGS.jax_enable_x64 and any(
           ^
./trax/tf_numpy/jax_tests/lax_numpy_test.py:740:17: F821 undefined name 'dtypes'
    tol_spec = {dtypes.bfloat16: 3e-1, onp.float16: 0.15}
                ^
./trax/tf_numpy/jax_tests/lax_numpy_test.py:1574:13: F821 undefined name 'dtypes'
    dtype = dtypes.canonicalize_dtype(dtype)
            ^
./trax/tf_numpy/jax_tests/lax_numpy_test.py:1618:13: F821 undefined name 'api'
    csame = api.jit(same)
            ^
./trax/tf_numpy/jax_tests/lax_numpy_test.py:1651:11: F821 undefined name 'api'
    fun = api.jit(fun)
          ^
./trax/tf_numpy/jax_tests/lax_numpy_test.py:1663:11: F821 undefined name 'api'
    fun = api.jit(fun)
          ^
./trax/tf_numpy/jax_tests/lax_numpy_test.py:1671:6: F821 undefined name 'api'
    @api.jit
     ^
./trax/tf_numpy/jax_tests/lax_numpy_test.py:1691:42: F821 undefined name 'api'
    self.assertRaises(TypeError, lambda: api.jit(g)(x, y))
                                         ^
./trax/tf_numpy/jax_tests/lax_numpy_test.py:1692:42: F821 undefined name 'api'
    self.assertRaises(TypeError, lambda: api.jit(f)(x, y))
                                         ^
./trax/tf_numpy/jax_tests/lax_numpy_test.py:1697:6: F821 undefined name 'api'
    @api.jit
     ^
./trax/tf_numpy/jax_tests/lax_numpy_test.py:1705:6: F821 undefined name 'api'
    @api.jit
     ^
./trax/tf_numpy/jax_tests/lax_numpy_test.py:1723:12: F821 undefined name 'api'
    cfoo = api.jit(foo)
           ^
./trax/tf_numpy/jax_tests/lax_numpy_test.py:1820:9: F821 undefined name 'lax'
    x = lax.add(lnp.eye(3, dtype=lnp.float_), 0.)
        ^
./trax/tf_numpy/jax_tests/lax_numpy_test.py:2006:23: F821 undefined name 'dtypes'
    dtype = onp.dtype(dtypes.canonicalize_dtype(dtype)).type
                      ^
./trax/tf_numpy/jax_tests/lax_numpy_test.py:2191:14: F821 undefined name 'api'
    result = api.grad(test_fail)(x)
             ^
./trax/tf_numpy/jax_tests/lax_numpy_test.py:2220:39: F821 undefined name 'api'
    self.assertAllClose(onp.int64(7), api.jit(lambda x: x)(onp.longlong(7)),
                                      ^
./trax/tf_numpy/jax_tests/lax_numpy_test.py:2249:50: F821 undefined name 'lax'
    self.assertTrue(type(lnp.arange(77)) == type(lax.iota(onp.int32, 77)))
                                                 ^
./trax/tf_numpy/jax_tests/lax_numpy_test.py:2255:26: F821 undefined name 'lax'
                    type(lax.iota(onp.int32, 77)))
                         ^
./trax/tf_numpy/jax_tests/lax_numpy_test.py:2274:9: F821 undefined name 'api'
    f = api.grad(lambda x: lnp.sum(lnp.tanh(x)))
        ^
./trax/tf_numpy/jax_tests/lax_numpy_test.py:2284:11: F821 undefined name 'jax'
      y = jax.ops.index_add(onp.ones(10,), [2, 4, 5], u)
          ^
./trax/tf_numpy/jax_tests/lax_numpy_test.py:2287:14: F821 undefined name 'lax'
      return lax.tie_in(y, 7.)
             ^
./trax/tf_numpy/jax_tests/lax_numpy_test.py:2289:40: F821 undefined name 'api'
    self.assertAllClose(onp.zeros(3,), api.grad(f)(onp.ones(3,)),
                                       ^
./trax/tf_numpy/jax_tests/lax_numpy_test.py:2295:9: F821 undefined name 'api'
    f = api.grad(lambda x: lnp.sum(1 / (1 + lnp.exp(-x))))
        ^
./trax/tf_numpy/jax_tests/lax_numpy_test.py:2311:23: F821 undefined name 'dtypes'
    dtype = onp.dtype(dtypes.canonicalize_dtype(dtype)).type
                      ^
./trax/tf_numpy/jax_tests/lax_numpy_test.py:2333:14: F821 undefined name 'api'
    @partial(api.jit, static_argnums=(1,))
             ^
./trax/tf_numpy/jax_tests/lax_numpy_test.py:2520:13: F821 undefined name 'FLAGS'
        not FLAGS.jax_enable_x64):
            ^
./trax/tf_numpy/jax_tests/lax_numpy_test.py:2604:19: F821 undefined name 'FLAGS'
      prev_flag = FLAGS.jax_numpy_rank_promotion
                  ^
./trax/tf_numpy/jax_tests/lax_numpy_test.py:2605:7: F821 undefined name 'FLAGS'
      FLAGS.jax_numpy_rank_promotion = "allow"
      ^
./trax/tf_numpy/jax_tests/lax_numpy_test.py:2608:7: F821 undefined name 'FLAGS'
      FLAGS.jax_numpy_rank_promotion = prev_flag
      ^
./trax/tf_numpy/jax_tests/lax_numpy_test.py:2611:19: F821 undefined name 'FLAGS'
      prev_flag = FLAGS.jax_numpy_rank_promotion
                  ^
./trax/tf_numpy/jax_tests/lax_numpy_test.py:2612:7: F821 undefined name 'FLAGS'
      FLAGS.jax_numpy_rank_promotion = "raise"
      ^
./trax/tf_numpy/jax_tests/lax_numpy_test.py:2615:7: F821 undefined name 'FLAGS'
      FLAGS.jax_numpy_rank_promotion = prev_flag
      ^
./trax/tf_numpy/jax_tests/lax_numpy_test.py:2618:19: F821 undefined name 'FLAGS'
      prev_flag = FLAGS.jax_numpy_rank_promotion
                  ^
./trax/tf_numpy/jax_tests/lax_numpy_test.py:2619:7: F821 undefined name 'FLAGS'
      FLAGS.jax_numpy_rank_promotion = "warn"
      ^
./trax/tf_numpy/jax_tests/lax_numpy_test.py:2633:7: F821 undefined name 'FLAGS'
      FLAGS.jax_numpy_rank_promotion = prev_flag
      ^
./trax/tf_numpy/jax_tests/lax_numpy_test.py:2638:6: F821 undefined name 'api'
    @api.jit
     ^
./trax/tf_numpy/jax_tests/lax_numpy_test.py:2643:6: F821 undefined name 'api'
    @api.jit
     ^
./trax/tf_numpy/jax_tests/lax_numpy_test.py:2656:15: F821 undefined name 'jax'
      y = y + jax.grad(lambda z: lnp.sum(lnp.maximum(z, 0.)))(x)
              ^
./trax/tf_numpy/jax_tests/lax_numpy_test.py:2659:19: F821 undefined name 'lax'
    f = lambda y: lax.fori_loop(0, 5, body, (y, y))
                  ^
./trax/tf_numpy/jax_tests/lax_numpy_test.py:2660:15: F821 undefined name 'linear_util'
    wrapped = linear_util.wrap_init(f)
              ^
./trax/tf_numpy/jax_tests/lax_numpy_test.py:2661:10: F821 undefined name 'partial_eval'
    pv = partial_eval.PartialVal(
         ^
./trax/tf_numpy/jax_tests/lax_numpy_test.py:2662:8: F821 undefined name 'jax'
      (jax.ShapedArray((3, 4), onp.float32), jax.core.unit))
       ^
./trax/tf_numpy/jax_tests/lax_numpy_test.py:2662:46: F821 undefined name 'jax'
      (jax.ShapedArray((3, 4), onp.float32), jax.core.unit))
                                             ^
./trax/tf_numpy/jax_tests/lax_numpy_test.py:2663:20: F821 undefined name 'partial_eval'
    _, _, consts = partial_eval.trace_to_jaxpr(wrapped, [pv])
                   ^
./trax/tf_numpy/jax_tests/lax_numpy_test.py:2709:15: F821 undefined name 'lax'
    HIGHEST = lax.Precision.HIGHEST
              ^
./trax/tf_numpy/jax_tests/lax_numpy_test.py:2786:20: F821 undefined name 'dtypes'
  return lnp.finfo(dtypes.canonicalize_dtype(dtype)).bits
                   ^
./trax/tf_numpy/jax_tests/lax_numpy_test.py:2803:5: F821 undefined name 'check_grads'
    check_grads(op, args, order, ["fwd", "rev"], tol, tol)
    ^
./trax/tf_numpy/jax_tests/lax_numpy_test.py:2813:5: F821 undefined name 'check_grads'
    check_grads(op, (special_value,), order, ["fwd", "rev"],
    ^
./trax/tf_numpy/jax_tests/lax_numpy_test.py:2825:5: F821 undefined name 'check_grads'
    check_grads(f, (1.,), order=1)
    ^
49    F821 undefined name 'FLAGS'
49

https://flake8.pycqa.org/en/latest/user/error-codes.html

On the flake8 test selection, this PR does not focus on "style violations" (the majority of flake8 error codes that psf/black can autocorrect). Instead these tests are focus on runtime safety and correctness:

  • E9 tests are about Python syntax errors usually raised because flake8 can not build an Abstract Syntax Tree (AST). Often these issues are a sign of unused code or code that has not been ported to Python 3. These would be compile-time errors in a compiled language but in a dynamic language like Python they result in the script halting/crashing on the user.
  • F63 tests are usually about the confusion between identity and equality in Python. Use ==/!= to compare str, bytes, and int literals is the classic case. These are areas where a == b is True but a is b is False (or vice versa). Python >= 3.8 will raise SyntaxWarnings on these instances.
  • F7 tests logic errors and syntax errors in type hints
  • F82 tests are almost always undefined names which are usually a sign of a typo, missing imports, or code that has not been ported to Python 3. These also would be compile-time errors in a compiled language but in Python a NameError is raised which will halt/crash the script on the user.

Environment information

OS: <your answer here>

$ pip freeze | grep tensor
# your output here

$ pip freeze | grep jax
# your output here

$ python -V
# your output here

For bugs: reproduction and error logs

# Steps to reproduce:
...

flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics

# Error logs:
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.