Skip to content

Commit

Permalink
Remove accidental print statements
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardoV94 committed Feb 5, 2025
1 parent 4ac1e63 commit 17748b7
Show file tree
Hide file tree
Showing 33 changed files with 161 additions and 168 deletions.
11 changes: 9 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ exclude = ["doc/", "pytensor/_version.py"]
docstring-code-format = true

[tool.ruff.lint]
select = ["B905", "C", "E", "F", "I", "UP", "W", "RUF", "PERF", "PTH", "ISC"]
select = ["B905", "C", "E", "F", "I", "UP", "W", "RUF", "PERF", "PTH", "ISC", "T20"]
ignore = ["C408", "C901", "E501", "E741", "RUF012", "PERF203", "ISC001"]
unfixable = [
# zip-strict: the auto-fix adds `strict=False` but we might want `strict=True` instead
Expand All @@ -144,7 +144,12 @@ lines-after-imports = 2
# TODO: Get rid of these:
"**/__init__.py" = ["F401", "E402", "F403"]
"pytensor/tensor/linalg.py" = ["F403"]
"pytensor/link/c/cmodule.py" = ["PTH"]
"pytensor/link/c/cmodule.py" = ["PTH", "T201"]
"pytensor/misc/elemwise_time_test.py" = ["T201"]
"pytensor/misc/elemwise_openmp_speedup.py" = ["T201"]
"pytensor/misc/check_duplicate_key.py" = ["T201"]
"pytensor/misc/check_blas.py" = ["T201"]
"pytensor/bin/pytensor_cache.py" = ["T201"]
# For the tests we skip because `pytest.importorskip` is used:
"tests/link/jax/test_scalar.py" = ["E402"]
"tests/link/jax/test_tensor_basic.py" = ["E402"]
Expand All @@ -158,6 +163,8 @@ lines-after-imports = 2
"tests/sparse/test_sp2.py" = ["E402"]
"tests/sparse/test_utils.py" = ["E402"]
"tests/sparse/sandbox/test_sp.py" = ["E402", "F401"]
"tests/compile/test_monitormode.py" = ["T201"]
"scripts/run_mypy.py" = ["T201"]


[tool.mypy]
Expand Down
16 changes: 8 additions & 8 deletions pytensor/breakpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,14 @@ def perform(self, node, inputs, output_storage):
f"'{self.name}' could not be casted to NumPy arrays"
)

print("\n")
print("-------------------------------------------------")
print(f"Conditional breakpoint '{self.name}' activated\n")
print("The monitored variables are stored, in order,")
print("in the list variable 'monitored' as NumPy arrays.\n")
print("Their contents can be altered and, when execution")
print("resumes, the updated values will be used.")
print("-------------------------------------------------")
print("\n") # noqa: T201
print("-------------------------------------------------") # noqa: T201
print(f"Conditional breakpoint '{self.name}' activated\n") # noqa: T201
print("The monitored variables are stored, in order,") # noqa: T201
print("in the list variable 'monitored' as NumPy arrays.\n") # noqa: T201
print("Their contents can be altered and, when execution") # noqa: T201
print("resumes, the updated values will be used.") # noqa: T201
print("-------------------------------------------------") # noqa: T201

try:
import pudb
Expand Down
46 changes: 23 additions & 23 deletions pytensor/compile/compiledir.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ def cleanup():
def print_title(title, overline="", underline=""):
len_title = len(title)
if overline:
print(str(overline) * len_title)
print(title)
print(str(overline) * len_title) # noqa: T201
print(title) # noqa: T201
if underline:
print(str(underline) * len_title)
print(str(underline) * len_title) # noqa: T201


def print_compiledir_content():
Expand Down Expand Up @@ -159,7 +159,7 @@ def print_compiledir_content():
_logger.error(f"Could not read key file '{filename}'.")

print_title(f"PyTensor cache: {compiledir}", overline="=", underline="=")
print()
print() # noqa: T201

print_title(f"List of {len(table)} compiled individual ops", underline="+")
print_title(
Expand All @@ -168,9 +168,9 @@ def print_compiledir_content():
)
table = sorted(table, key=lambda t: str(t[1]))
for dir, op, types, compile_time in table:
print(dir, f"{compile_time:.3f}s", op, types)
print(dir, f"{compile_time:.3f}s", op, types) # noqa: T201

print()
print() # noqa: T201
print_title(
f"List of {len(table_multiple_ops)} compiled sets of ops", underline="+"
)
Expand All @@ -180,9 +180,9 @@ def print_compiledir_content():
)
table_multiple_ops = sorted(table_multiple_ops, key=lambda t: (t[1], t[2]))
for dir, ops_to_str, types_to_str, compile_time in table_multiple_ops:
print(dir, f"{compile_time:.3f}s", ops_to_str, types_to_str)
print(dir, f"{compile_time:.3f}s", ops_to_str, types_to_str) # noqa: T201

print()
print() # noqa: T201
print_title(
(
f"List of {len(table_op_class)} compiled Op classes and "
Expand All @@ -191,33 +191,33 @@ def print_compiledir_content():
underline="+",
)
for op_class, nb in reversed(table_op_class.most_common()):
print(op_class, nb)
print(op_class, nb) # noqa: T201

if big_key_files:
big_key_files = sorted(big_key_files, key=lambda t: str(t[1]))
big_total_size = sum(sz for _, sz, _ in big_key_files)
print(
print( # noqa: T201
f"There are directories with key files bigger than {int(max_key_file_size)} bytes "
"(they probably contain big tensor constants)"
)
print(
print( # noqa: T201
f"They use {int(big_total_size)} bytes out of {int(total_key_sizes)} (total size "
"used by all key files)"
)

for dir, size, ops in big_key_files:
print(dir, size, ops)
print(dir, size, ops) # noqa: T201

nb_keys = sorted(nb_keys.items())
print()
print() # noqa: T201
print_title("Number of keys for a compiled module", underline="+")
print_title(
"number of keys/number of modules with that number of keys", underline="-"
)
for n_k, n_m in nb_keys:
print(n_k, n_m)
print()
print(
print(n_k, n_m) # noqa: T201
print() # noqa: T201
print( # noqa: T201
f"Skipped {int(zeros_op)} files that contained 0 op "
"(are they always pytensor.scalar ops?)"
)
Expand All @@ -242,18 +242,18 @@ def basecompiledir_ls():
subdirs = sorted(subdirs)
others = sorted(others)

print(f"Base compile dir is {config.base_compiledir}")
print("Sub-directories (possible compile caches):")
print(f"Base compile dir is {config.base_compiledir}") # noqa: T201
print("Sub-directories (possible compile caches):") # noqa: T201
for d in subdirs:
print(f" {d}")
print(f" {d}") # noqa: T201
if not subdirs:
print(" (None)")
print(" (None)") # noqa: T201

if others:
print()
print("Other files in base_compiledir:")
print() # noqa: T201
print("Other files in base_compiledir:") # noqa: T201
for f in others:
print(f" {f}")
print(f" {f}") # noqa: T201


def basecompiledir_purge():
Expand Down
8 changes: 4 additions & 4 deletions pytensor/compile/debugmode.py
Original file line number Diff line number Diff line change
Expand Up @@ -1315,9 +1315,9 @@ def on_change_input(self, fgraph, node, i, r, new_r, reason=None):

def printstuff(self):
for key in self.equiv:
print(key)
print(key) # noqa: T201
for e in self.equiv[key]:
print(" ", e)
print(" ", e) # noqa: T201


# List of default version of make thunk.
Expand Down Expand Up @@ -1569,7 +1569,7 @@ def f():
#####
for r, s in storage_map.items():
if s[0] is not None:
print(r, s)
print(r, s) # noqa: T201
assert s[0] is None

# try:
Expand Down Expand Up @@ -2079,7 +2079,7 @@ def __init__(
raise StochasticOrder(infolog.getvalue())
else:
if self.verbose:
print(
print( # noqa: T201
"OPTCHECK: optimization",
i,
"of",
Expand Down
2 changes: 1 addition & 1 deletion pytensor/compile/mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def __init__(self, header):
def apply(self, fgraph):
import pytensor.printing

print("PrintCurrentFunctionGraph:", self.header)
print("PrintCurrentFunctionGraph:", self.header) # noqa: T201
pytensor.printing.debugprint(fgraph.outputs)


Expand Down
6 changes: 3 additions & 3 deletions pytensor/compile/monitormode.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ def detect_nan(fgraph, i, node, fn):
not isinstance(output[0], np.random.RandomState | np.random.Generator)
and np.isnan(output[0]).any()
):
print("*** NaN detected ***")
print("*** NaN detected ***") # noqa: T201
debugprint(node)
print(f"Inputs : {[input[0] for input in fn.inputs]}")
print(f"Outputs: {[output[0] for output in fn.outputs]}")
print(f"Inputs : {[input[0] for input in fn.inputs]}") # noqa: T201
print(f"Outputs: {[output[0] for output in fn.outputs]}") # noqa: T201
break
2 changes: 1 addition & 1 deletion pytensor/compile/nanguardmode.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def do_check_on(value, nd, var=None):
if config.NanGuardMode__action == "raise":
raise AssertionError(msg)
elif config.NanGuardMode__action == "pdb":
print(msg)
print(msg) # noqa: T201
import pdb

pdb.set_trace()
Expand Down
4 changes: 2 additions & 2 deletions pytensor/compile/profiling.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def _atexit_print_fn():
to_sum.append(ps)
else:
# TODO print the name if there is one!
print("Skipping empty Profile")
print("Skipping empty Profile") # noqa: T201
if len(to_sum) > 1:
# Make a global profile
cum = copy.copy(to_sum[0])
Expand Down Expand Up @@ -125,7 +125,7 @@ def _atexit_print_fn():
assert len(merge) == len(cum.rewriter_profile[1])
cum.rewriter_profile = (cum.rewriter_profile[0], merge)
except Exception as e:
print(e)
print(e) # noqa: T201
cum.rewriter_profile = None
else:
cum.rewriter_profile = None
Expand Down
22 changes: 11 additions & 11 deletions pytensor/graph/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ def validate_(self, fgraph):
if verbose:
r = uf.f_locals.get("r", "")
reason = uf_info.function
print(f"validate failed on node {r}.\n Reason: {reason}, {e}")
print(f"validate failed on node {r}.\n Reason: {reason}, {e}") # noqa: T201
raise
t1 = time.perf_counter()
if fgraph.profile:
Expand Down Expand Up @@ -603,13 +603,13 @@ def replace_all_validate(
except Exception as e:
fgraph.revert(chk)
if verbose:
print(
print( # noqa: T201
f"rewriting: validate failed on node {r}.\n Reason: {reason}, {e}"
)
raise

if verbose:
print(
print( # noqa: T201
f"rewriting: rewrite {reason} replaces {r} of {r.owner} with {new_r} of {new_r.owner}"
)

Expand Down Expand Up @@ -692,11 +692,11 @@ def on_import(self, fgraph, node, reason):
except TypeError: # node.op is unhashable
return
except Exception as e:
print("OFFENDING node", type(node), type(node.op), file=sys.stderr)
print("OFFENDING node", type(node), type(node.op), file=sys.stderr) # noqa: T201
try:
print("OFFENDING node hash", hash(node.op), file=sys.stderr)
print("OFFENDING node hash", hash(node.op), file=sys.stderr) # noqa: T201
except Exception:
print("OFFENDING node not hashable", file=sys.stderr)
print("OFFENDING node not hashable", file=sys.stderr) # noqa: T201
raise e

def on_prune(self, fgraph, node, reason):
Expand Down Expand Up @@ -725,27 +725,27 @@ def __init__(self, active=True):

def on_attach(self, fgraph):
if self.active:
print("-- attaching to: ", fgraph)
print("-- attaching to: ", fgraph) # noqa: T201

def on_detach(self, fgraph):
"""
Should remove any dynamically added functionality
that it installed into the function_graph
"""
if self.active:
print("-- detaching from: ", fgraph)
print("-- detaching from: ", fgraph) # noqa: T201

def on_import(self, fgraph, node, reason):
if self.active:
print(f"-- importing: {node}, reason: {reason}")
print(f"-- importing: {node}, reason: {reason}") # noqa: T201

def on_prune(self, fgraph, node, reason):
if self.active:
print(f"-- pruning: {node}, reason: {reason}")
print(f"-- pruning: {node}, reason: {reason}") # noqa: T201

def on_change_input(self, fgraph, node, i, r, new_r, reason=None):
if self.active:
print(f"-- changing ({node}.inputs[{i}]) from {r} to {new_r}")
print(f"-- changing ({node}.inputs[{i}]) from {r} to {new_r}") # noqa: T201


class PreserveVariableAttributes(Feature):
Expand Down
2 changes: 1 addition & 1 deletion pytensor/graph/fg.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ def replace(
if verbose is None:
verbose = config.optimizer_verbose
if verbose:
print(
print( # noqa: T201
f"rewriting: rewrite {reason} replaces {var} of {var.owner} with {new_var} of {new_var.owner}"
)

Expand Down
Loading

0 comments on commit 17748b7

Please sign in to comment.