2022-09-22 12:26:48 -07:00
|
|
|
# Copyright 2022 The JAX Authors.
|
2022-06-28 10:28:45 -07:00
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# https://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
2023-07-21 14:20:39 -04:00
|
|
|
|
|
|
|
from collections.abc import Sequence
|
2022-06-28 10:28:45 -07:00
|
|
|
import io
|
2022-07-21 20:21:38 -07:00
|
|
|
import re
|
2022-06-28 10:28:45 -07:00
|
|
|
import textwrap
|
2023-07-21 14:20:39 -04:00
|
|
|
from typing import IO
|
2022-06-28 10:28:45 -07:00
|
|
|
import unittest
|
|
|
|
|
|
|
|
from absl.testing import absltest
|
|
|
|
import jax
|
2022-07-21 20:21:38 -07:00
|
|
|
from jax.experimental import pjit
|
2022-06-28 10:28:45 -07:00
|
|
|
from jax._src import debugger
|
|
|
|
from jax._src import test_util as jtu
|
|
|
|
import jax.numpy as jnp
|
2022-07-21 20:21:38 -07:00
|
|
|
import numpy as np
|
2022-06-28 10:28:45 -07:00
|
|
|
|
2024-04-11 13:23:27 -07:00
|
|
|
jax.config.parse_flags_with_absl()
|
2025-01-08 06:37:02 -08:00
|
|
|
jtu.request_cpu_devices(2)
|
2022-06-28 10:28:45 -07:00
|
|
|
|
2023-06-23 15:11:37 -07:00
|
|
|
def make_fake_stdin_stdout(commands: Sequence[str]) -> tuple[IO[str], io.StringIO]:
|
2022-06-28 10:28:45 -07:00
|
|
|
fake_stdin = io.StringIO()
|
|
|
|
fake_stdin.truncate(0)
|
|
|
|
for command in commands:
|
|
|
|
fake_stdin.write(command + "\n")
|
|
|
|
fake_stdin.seek(0)
|
|
|
|
return fake_stdin, io.StringIO()
|
|
|
|
|
|
|
|
def _format_multiline(text):
|
|
|
|
return textwrap.dedent(text).lstrip()
|
|
|
|
|
2022-08-08 15:36:26 -07:00
|
|
|
foo = 2
|
|
|
|
|
2022-06-28 10:28:45 -07:00
|
|
|
class CliDebuggerTest(jtu.JaxTestCase):
|
|
|
|
|
2023-09-13 16:35:02 +01:00
|
|
|
def setUp(self):
|
|
|
|
super().setUp()
|
2023-09-27 12:10:06 -07:00
|
|
|
if not jtu.test_device_matches(["cpu", "gpu", "tpu"]):
|
2023-09-13 16:35:02 +01:00
|
|
|
self.skipTest(f"Host callback not supported on {jtu.device_under_test()}")
|
|
|
|
|
2022-06-28 10:28:45 -07:00
|
|
|
def test_debugger_eof(self):
|
|
|
|
stdin, stdout = make_fake_stdin_stdout([])
|
|
|
|
|
|
|
|
def f(x):
|
|
|
|
y = jnp.sin(x)
|
2022-07-29 12:00:26 -07:00
|
|
|
debugger.breakpoint(stdin=stdin, stdout=stdout, backend="cli")
|
2022-06-28 10:28:45 -07:00
|
|
|
return y
|
|
|
|
with self.assertRaises(SystemExit):
|
|
|
|
f(2.)
|
2022-07-06 20:52:08 -07:00
|
|
|
jax.effects_barrier()
|
2022-06-28 10:28:45 -07:00
|
|
|
|
|
|
|
def test_debugger_can_continue(self):
|
|
|
|
stdin, stdout = make_fake_stdin_stdout(["c"])
|
|
|
|
|
|
|
|
def f(x):
|
|
|
|
y = jnp.sin(x)
|
2022-07-29 12:00:26 -07:00
|
|
|
debugger.breakpoint(stdin=stdin, stdout=stdout, backend="cli")
|
2022-06-28 10:28:45 -07:00
|
|
|
return y
|
|
|
|
f(2.)
|
2022-07-06 20:52:08 -07:00
|
|
|
jax.effects_barrier()
|
2022-06-28 10:28:45 -07:00
|
|
|
expected = _format_multiline(r"""
|
2022-07-29 12:00:26 -07:00
|
|
|
Entering jdb:
|
|
|
|
(jdb) """)
|
2022-06-28 10:28:45 -07:00
|
|
|
self.assertEqual(stdout.getvalue(), expected)
|
|
|
|
|
|
|
|
def test_debugger_can_print_value(self):
|
|
|
|
stdin, stdout = make_fake_stdin_stdout(["p x", "c"])
|
|
|
|
|
|
|
|
def f(x):
|
|
|
|
y = jnp.sin(x)
|
2022-07-29 12:00:26 -07:00
|
|
|
debugger.breakpoint(stdin=stdin, stdout=stdout, backend="cli")
|
2022-06-28 10:28:45 -07:00
|
|
|
return y
|
2023-03-15 17:08:21 -07:00
|
|
|
expected = _format_multiline(r"""
|
2022-07-29 12:00:26 -07:00
|
|
|
Entering jdb:
|
2023-03-15 17:08:21 -07:00
|
|
|
(jdb) Array(2., dtype=float32)
|
2022-12-01 09:12:01 -08:00
|
|
|
(jdb) """)
|
2022-06-28 10:28:45 -07:00
|
|
|
f(jnp.array(2., jnp.float32))
|
2022-07-06 20:52:08 -07:00
|
|
|
jax.effects_barrier()
|
2022-06-28 10:28:45 -07:00
|
|
|
self.assertEqual(stdout.getvalue(), expected)
|
|
|
|
|
|
|
|
def test_debugger_can_print_value_in_jit(self):
|
|
|
|
stdin, stdout = make_fake_stdin_stdout(["p x", "c"])
|
|
|
|
|
|
|
|
@jax.jit
|
|
|
|
def f(x):
|
|
|
|
y = jnp.sin(x)
|
2022-07-29 12:00:26 -07:00
|
|
|
debugger.breakpoint(stdin=stdin, stdout=stdout, backend="cli")
|
2022-06-28 10:28:45 -07:00
|
|
|
return y
|
|
|
|
expected = _format_multiline(r"""
|
2022-07-29 12:00:26 -07:00
|
|
|
Entering jdb:
|
2024-04-19 13:56:28 -07:00
|
|
|
(jdb) Array(2., dtype=float32)
|
2022-07-29 12:00:26 -07:00
|
|
|
(jdb) """)
|
2022-06-28 10:28:45 -07:00
|
|
|
f(jnp.array(2., jnp.float32))
|
2022-07-06 20:52:08 -07:00
|
|
|
jax.effects_barrier()
|
2022-06-28 10:28:45 -07:00
|
|
|
self.assertEqual(stdout.getvalue(), expected)
|
|
|
|
|
|
|
|
def test_debugger_can_print_multiple_values(self):
|
|
|
|
stdin, stdout = make_fake_stdin_stdout(["p x, y", "c"])
|
|
|
|
|
|
|
|
@jax.jit
|
|
|
|
def f(x):
|
|
|
|
y = x + 1.
|
2022-07-29 12:00:26 -07:00
|
|
|
debugger.breakpoint(stdin=stdin, stdout=stdout, backend="cli")
|
2022-06-28 10:28:45 -07:00
|
|
|
return y
|
|
|
|
expected = _format_multiline(r"""
|
2022-07-29 12:00:26 -07:00
|
|
|
Entering jdb:
|
2024-04-19 13:56:28 -07:00
|
|
|
(jdb) (Array(2., dtype=float32), Array(3., dtype=float32))
|
2022-07-29 12:00:26 -07:00
|
|
|
(jdb) """)
|
2022-06-28 10:28:45 -07:00
|
|
|
f(jnp.array(2., jnp.float32))
|
2022-07-06 20:52:08 -07:00
|
|
|
jax.effects_barrier()
|
2022-06-28 10:28:45 -07:00
|
|
|
self.assertEqual(stdout.getvalue(), expected)
|
|
|
|
|
|
|
|
def test_debugger_can_print_context(self):
|
|
|
|
stdin, stdout = make_fake_stdin_stdout(["l", "c"])
|
|
|
|
|
|
|
|
@jax.jit
|
|
|
|
def f(x):
|
|
|
|
y = jnp.sin(x)
|
2022-07-29 12:00:26 -07:00
|
|
|
debugger.breakpoint(stdin=stdin, stdout=stdout, backend="cli")
|
2022-06-28 10:28:45 -07:00
|
|
|
return y
|
|
|
|
f(2.)
|
2022-07-06 20:52:08 -07:00
|
|
|
jax.effects_barrier()
|
2022-06-28 10:28:45 -07:00
|
|
|
expected = _format_multiline(r"""
|
2022-07-29 12:00:26 -07:00
|
|
|
Entering jdb:
|
|
|
|
\(jdb\) > .*debugger_test\.py\([0-9]+\)
|
2022-06-28 10:28:45 -07:00
|
|
|
@jax\.jit
|
|
|
|
def f\(x\):
|
|
|
|
y = jnp\.sin\(x\)
|
2022-07-29 12:00:26 -07:00
|
|
|
-> debugger\.breakpoint\(stdin=stdin, stdout=stdout, backend="cli"\)
|
2022-06-28 10:28:45 -07:00
|
|
|
return y
|
|
|
|
.*
|
2022-07-29 12:00:26 -07:00
|
|
|
\(jdb\) """)
|
2022-06-28 10:28:45 -07:00
|
|
|
self.assertRegex(stdout.getvalue(), expected)
|
|
|
|
|
|
|
|
def test_debugger_can_print_backtrace(self):
|
|
|
|
stdin, stdout = make_fake_stdin_stdout(["bt", "c"])
|
|
|
|
|
|
|
|
@jax.jit
|
|
|
|
def f(x):
|
|
|
|
y = jnp.sin(x)
|
2022-07-29 12:00:26 -07:00
|
|
|
debugger.breakpoint(stdin=stdin, stdout=stdout, backend="cli")
|
2022-06-28 10:28:45 -07:00
|
|
|
return y
|
|
|
|
expected = _format_multiline(r"""
|
2022-07-29 12:00:26 -07:00
|
|
|
Entering jdb:.*
|
|
|
|
\(jdb\) Traceback:.*
|
2022-06-28 10:28:45 -07:00
|
|
|
""")
|
|
|
|
f(2.)
|
2022-07-06 20:52:08 -07:00
|
|
|
jax.effects_barrier()
|
2022-06-28 10:28:45 -07:00
|
|
|
self.assertRegex(stdout.getvalue(), expected)
|
|
|
|
|
|
|
|
def test_debugger_can_work_with_multiple_stack_frames(self):
|
|
|
|
stdin, stdout = make_fake_stdin_stdout(["l", "u", "p x", "d", "c"])
|
|
|
|
|
|
|
|
def f(x):
|
|
|
|
y = jnp.sin(x)
|
2022-07-29 12:00:26 -07:00
|
|
|
debugger.breakpoint(stdin=stdin, stdout=stdout, backend="cli")
|
2022-06-28 10:28:45 -07:00
|
|
|
return y
|
|
|
|
|
|
|
|
@jax.jit
|
|
|
|
def g(x):
|
|
|
|
y = f(x)
|
|
|
|
return jnp.exp(y)
|
|
|
|
expected = _format_multiline(r"""
|
2022-07-29 12:00:26 -07:00
|
|
|
Entering jdb:
|
|
|
|
\(jdb\) > .*debugger_test\.py\([0-9]+\)
|
2022-06-28 10:28:45 -07:00
|
|
|
def f\(x\):
|
|
|
|
y = jnp\.sin\(x\)
|
2022-07-29 12:00:26 -07:00
|
|
|
-> debugger\.breakpoint\(stdin=stdin, stdout=stdout, backend="cli"\)
|
2022-06-28 10:28:45 -07:00
|
|
|
return y
|
|
|
|
.*
|
2022-07-29 12:00:26 -07:00
|
|
|
\(jdb\) > .*debugger_test\.py\([0-9]+\).*
|
2022-06-28 10:28:45 -07:00
|
|
|
@jax\.jit
|
|
|
|
def g\(x\):
|
|
|
|
-> y = f\(x\)
|
|
|
|
return jnp\.exp\(y\)
|
|
|
|
.*
|
2024-04-19 13:56:28 -07:00
|
|
|
\(jdb\) Array\(2\., dtype=float32\)
|
2022-07-29 12:00:26 -07:00
|
|
|
\(jdb\) > .*debugger_test\.py\([0-9]+\)
|
2022-06-28 10:28:45 -07:00
|
|
|
def f\(x\):
|
|
|
|
y = jnp\.sin\(x\)
|
2022-07-29 12:00:26 -07:00
|
|
|
-> debugger\.breakpoint\(stdin=stdin, stdout=stdout, backend="cli"\)
|
2022-06-28 10:28:45 -07:00
|
|
|
return y
|
|
|
|
.*
|
2022-07-29 12:00:26 -07:00
|
|
|
\(jdb\) """)
|
2022-06-28 10:28:45 -07:00
|
|
|
g(jnp.array(2., jnp.float32))
|
2022-07-06 20:52:08 -07:00
|
|
|
jax.effects_barrier()
|
2022-06-28 10:28:45 -07:00
|
|
|
self.assertRegex(stdout.getvalue(), expected)
|
|
|
|
|
|
|
|
def test_can_use_multiple_breakpoints(self):
|
|
|
|
stdin, stdout = make_fake_stdin_stdout(["p y", "c", "p y", "c"])
|
|
|
|
|
|
|
|
def f(x):
|
|
|
|
y = x + 1.
|
2022-07-29 12:00:26 -07:00
|
|
|
debugger.breakpoint(stdin=stdin, stdout=stdout, ordered=True,
|
|
|
|
backend="cli")
|
2022-06-28 10:28:45 -07:00
|
|
|
return y
|
|
|
|
|
|
|
|
@jax.jit
|
|
|
|
def g(x):
|
|
|
|
y = f(x) * 2.
|
2022-07-29 12:00:26 -07:00
|
|
|
debugger.breakpoint(stdin=stdin, stdout=stdout, ordered=True,
|
|
|
|
backend="cli")
|
2022-06-28 10:28:45 -07:00
|
|
|
return jnp.exp(y)
|
|
|
|
expected = _format_multiline(r"""
|
2022-07-29 12:00:26 -07:00
|
|
|
Entering jdb:
|
2024-04-19 13:56:28 -07:00
|
|
|
(jdb) Array(3., dtype=float32)
|
2022-07-29 12:00:26 -07:00
|
|
|
(jdb) Entering jdb:
|
2024-04-19 13:56:28 -07:00
|
|
|
(jdb) Array(6., dtype=float32)
|
2022-07-29 12:00:26 -07:00
|
|
|
(jdb) """)
|
2022-06-28 10:28:45 -07:00
|
|
|
g(jnp.array(2., jnp.float32))
|
|
|
|
jax.effects_barrier()
|
|
|
|
self.assertEqual(stdout.getvalue(), expected)
|
|
|
|
|
|
|
|
def test_debugger_works_with_vmap(self):
|
|
|
|
stdin, stdout = make_fake_stdin_stdout(["p y", "c", "p y", "c"])
|
2022-10-17 22:54:38 +00:00
|
|
|
|
2022-06-28 10:28:45 -07:00
|
|
|
def f(x):
|
|
|
|
y = x + 1.
|
2024-03-29 15:29:10 -07:00
|
|
|
debugger.breakpoint(stdin=stdin, stdout=stdout, ordered=True,
|
2022-07-29 12:00:26 -07:00
|
|
|
backend="cli")
|
2022-06-28 10:28:45 -07:00
|
|
|
return 2. * y
|
|
|
|
|
|
|
|
@jax.jit
|
|
|
|
@jax.vmap
|
|
|
|
def g(x):
|
|
|
|
y = f(x)
|
|
|
|
return jnp.exp(y)
|
|
|
|
expected = _format_multiline(r"""
|
2022-07-29 12:00:26 -07:00
|
|
|
Entering jdb:
|
2024-04-19 13:56:28 -07:00
|
|
|
(jdb) Array(1., dtype=float32)
|
2022-07-29 12:00:26 -07:00
|
|
|
(jdb) Entering jdb:
|
2024-04-19 13:56:28 -07:00
|
|
|
(jdb) Array(2., dtype=float32)
|
2022-07-29 12:00:26 -07:00
|
|
|
(jdb) """)
|
2022-06-28 10:28:45 -07:00
|
|
|
g(jnp.arange(2., dtype=jnp.float32))
|
2022-07-06 20:52:08 -07:00
|
|
|
jax.effects_barrier()
|
2022-06-28 10:28:45 -07:00
|
|
|
self.assertEqual(stdout.getvalue(), expected)
|
|
|
|
|
|
|
|
def test_debugger_works_with_pmap(self):
|
|
|
|
if jax.local_device_count() < 2:
|
|
|
|
raise unittest.SkipTest("Test requires >= 2 devices.")
|
2022-10-17 22:54:38 +00:00
|
|
|
|
2022-06-28 10:28:45 -07:00
|
|
|
stdin, stdout = make_fake_stdin_stdout(["p y", "c", "p y", "c"])
|
|
|
|
|
|
|
|
def f(x):
|
|
|
|
y = jnp.sin(x)
|
2022-07-29 12:00:26 -07:00
|
|
|
debugger.breakpoint(stdin=stdin, stdout=stdout, backend="cli")
|
2022-06-28 10:28:45 -07:00
|
|
|
return y
|
|
|
|
|
|
|
|
@jax.pmap
|
|
|
|
def g(x):
|
|
|
|
y = f(x)
|
|
|
|
return jnp.exp(y)
|
|
|
|
expected = _format_multiline(r"""
|
2022-07-29 12:00:26 -07:00
|
|
|
Entering jdb:
|
2024-04-19 13:56:28 -07:00
|
|
|
\(jdb\) Array\(.*, dtype=float32\)
|
2022-07-29 12:00:26 -07:00
|
|
|
\(jdb\) Entering jdb:
|
2024-04-19 13:56:28 -07:00
|
|
|
\(jdb\) Array\(.*, dtype=float32\)
|
2022-07-29 12:00:26 -07:00
|
|
|
\(jdb\) """)
|
2022-06-28 10:28:45 -07:00
|
|
|
g(jnp.arange(2., dtype=jnp.float32))
|
2022-06-30 23:09:50 -07:00
|
|
|
jax.effects_barrier()
|
2022-06-28 10:28:45 -07:00
|
|
|
self.assertRegex(stdout.getvalue(), expected)
|
|
|
|
|
2022-07-21 20:21:38 -07:00
|
|
|
def test_debugger_works_with_pjit(self):
|
|
|
|
if jax.default_backend() != "tpu":
|
|
|
|
raise unittest.SkipTest("`pjit` doesn't work with CustomCall.")
|
2022-10-17 22:54:38 +00:00
|
|
|
|
2022-07-21 20:21:38 -07:00
|
|
|
stdin, stdout = make_fake_stdin_stdout(["p y", "c"])
|
|
|
|
|
|
|
|
def f(x):
|
|
|
|
y = x + 1
|
2022-07-29 12:00:26 -07:00
|
|
|
debugger.breakpoint(stdin=stdin, stdout=stdout, backend="cli")
|
2022-07-21 20:21:38 -07:00
|
|
|
return y
|
|
|
|
|
|
|
|
def g(x):
|
|
|
|
y = f(x)
|
|
|
|
return jnp.exp(y)
|
2023-02-18 09:59:58 -08:00
|
|
|
g = pjit.pjit(
|
|
|
|
g,
|
|
|
|
in_shardings=jax.sharding.PartitionSpec("dev"),
|
|
|
|
out_shardings=jax.sharding.PartitionSpec("dev"),
|
|
|
|
)
|
2023-02-03 14:28:07 -08:00
|
|
|
with jax.sharding.Mesh(np.array(jax.devices()), ["dev"]):
|
2024-04-19 13:56:28 -07:00
|
|
|
arr = (1 + jnp.arange(8)).astype(np.int32)
|
2022-07-21 20:21:38 -07:00
|
|
|
expected = _format_multiline(r"""
|
2022-07-29 12:00:26 -07:00
|
|
|
Entering jdb:
|
|
|
|
\(jdb\) {}
|
|
|
|
\(jdb\) """.format(re.escape(repr(arr))))
|
2022-07-21 20:21:38 -07:00
|
|
|
g(jnp.arange(8, dtype=jnp.int32))
|
|
|
|
jax.effects_barrier()
|
|
|
|
self.assertRegex(stdout.getvalue(), expected)
|
|
|
|
|
2022-08-02 10:24:26 -07:00
|
|
|
def test_debugger_uses_local_before_global_scope(self):
|
|
|
|
stdin, stdout = make_fake_stdin_stdout(["p foo", "c"])
|
|
|
|
|
|
|
|
foo = "outer"
|
|
|
|
|
|
|
|
def f(x):
|
|
|
|
foo = "inner"
|
|
|
|
debugger.breakpoint(stdin=stdin, stdout=stdout, backend="cli")
|
|
|
|
del foo
|
|
|
|
return x
|
|
|
|
|
|
|
|
del foo
|
|
|
|
expected = _format_multiline(r"""
|
|
|
|
Entering jdb:
|
|
|
|
\(jdb\) 'inner'
|
|
|
|
\(jdb\) """)
|
|
|
|
f(2.)
|
|
|
|
jax.effects_barrier()
|
|
|
|
self.assertRegex(stdout.getvalue(), expected)
|
|
|
|
|
2022-08-08 15:36:26 -07:00
|
|
|
def test_debugger_accesses_globals(self):
|
|
|
|
stdin, stdout = make_fake_stdin_stdout(["p foo", "c"])
|
|
|
|
|
|
|
|
@jax.jit
|
|
|
|
def g():
|
|
|
|
debugger.breakpoint(stdin=stdin, stdout=stdout, backend="cli")
|
|
|
|
|
|
|
|
expected = _format_multiline(r"""
|
|
|
|
Entering jdb:
|
|
|
|
\(jdb\) \*\*\* NameError: name 'foo' is not defined
|
|
|
|
\(jdb\) """)
|
|
|
|
g()
|
|
|
|
jax.effects_barrier()
|
|
|
|
self.assertRegex(stdout.getvalue(), expected)
|
|
|
|
|
|
|
|
def test_can_limit_num_frames(self):
|
|
|
|
stdin, stdout = make_fake_stdin_stdout(["u", "p x", "c"])
|
|
|
|
|
|
|
|
def g():
|
|
|
|
debugger.breakpoint(stdin=stdin, stdout=stdout, backend="cli",
|
|
|
|
num_frames=2)
|
|
|
|
|
|
|
|
@jax.jit
|
|
|
|
def f():
|
|
|
|
x = 2
|
|
|
|
g()
|
|
|
|
return x
|
|
|
|
_ = f()
|
|
|
|
expected = _format_multiline(r"""
|
|
|
|
Entering jdb:
|
|
|
|
\(jdb\) .*
|
|
|
|
.*
|
|
|
|
.*
|
|
|
|
.*
|
|
|
|
.*
|
|
|
|
.*
|
|
|
|
.*
|
|
|
|
\(jdb\) 2
|
|
|
|
\(jdb\) """)
|
|
|
|
jax.effects_barrier()
|
|
|
|
self.assertRegex(stdout.getvalue(), expected)
|
|
|
|
|
|
|
|
stdin, stdout = make_fake_stdin_stdout(["u", "u", "c"])
|
|
|
|
|
|
|
|
def g2():
|
|
|
|
debugger.breakpoint(stdin=stdin, stdout=stdout, backend="cli",
|
|
|
|
num_frames=2)
|
|
|
|
|
|
|
|
@jax.jit
|
|
|
|
def f2():
|
|
|
|
x = 2
|
|
|
|
g2()
|
|
|
|
return x
|
|
|
|
|
|
|
|
expected = ".*At topmost frame.*"
|
|
|
|
_ = f2()
|
|
|
|
jax.effects_barrier()
|
|
|
|
self.assertRegex(stdout.getvalue(), expected)
|
|
|
|
|
2022-08-08 22:18:24 -07:00
|
|
|
def test_can_handle_dictionaries_with_unsortable_keys(self):
|
|
|
|
stdin, stdout = make_fake_stdin_stdout(["p x", "p weird_dict",
|
|
|
|
"p weirder_dict", "c"])
|
|
|
|
|
|
|
|
@jax.jit
|
|
|
|
def f():
|
|
|
|
weird_dict = {(lambda x: x): 2., (lambda x: x * 2): 3}
|
|
|
|
weirder_dict = {(lambda x: x): weird_dict}
|
|
|
|
x = 2.
|
|
|
|
debugger.breakpoint(stdin=stdin, stdout=stdout, backend="cli")
|
|
|
|
del weirder_dict
|
|
|
|
return x
|
|
|
|
expected = _format_multiline(r"""
|
|
|
|
Entering jdb:
|
|
|
|
\(jdb\) 2.0
|
|
|
|
\(jdb\) <cant_flatten>
|
|
|
|
\(jdb\) <cant_flatten>
|
|
|
|
\(jdb\) """)
|
|
|
|
_ = f()
|
|
|
|
jax.effects_barrier()
|
|
|
|
self.assertRegex(stdout.getvalue(), expected)
|
|
|
|
|
2022-06-28 10:28:45 -07:00
|
|
|
if __name__ == '__main__':
|
|
|
|
absltest.main(testLoader=jtu.JaxTestLoader())
|