Skip to content

Remove accidental print statements #1193

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

Merged
merged 1 commit into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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

Check warning on line 118 in pytensor/breakpoint.py

View check run for this annotation

Codecov / codecov/patch

pytensor/breakpoint.py#L111-L118

Added lines #L111 - L118 were not covered by tests

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 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

Check warning on line 99 in pytensor/compile/compiledir.py

View check run for this annotation

Codecov / codecov/patch

pytensor/compile/compiledir.py#L98-L99

Added lines #L98 - L99 were not covered by tests
if underline:
print(str(underline) * len_title)
print(str(underline) * len_title) # noqa: T201

Check warning on line 101 in pytensor/compile/compiledir.py

View check run for this annotation

Codecov / codecov/patch

pytensor/compile/compiledir.py#L101

Added line #L101 was not covered by tests


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

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

Check warning on line 162 in pytensor/compile/compiledir.py

View check run for this annotation

Codecov / codecov/patch

pytensor/compile/compiledir.py#L162

Added line #L162 was not covered by tests

print_title(f"List of {len(table)} compiled individual ops", underline="+")
print_title(
Expand All @@ -168,9 +168,9 @@
)
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

Check warning on line 171 in pytensor/compile/compiledir.py

View check run for this annotation

Codecov / codecov/patch

pytensor/compile/compiledir.py#L171

Added line #L171 was not covered by tests

print()
print() # noqa: T201

Check warning on line 173 in pytensor/compile/compiledir.py

View check run for this annotation

Codecov / codecov/patch

pytensor/compile/compiledir.py#L173

Added line #L173 was not covered by tests
print_title(
f"List of {len(table_multiple_ops)} compiled sets of ops", underline="+"
)
Expand All @@ -180,9 +180,9 @@
)
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

Check warning on line 183 in pytensor/compile/compiledir.py

View check run for this annotation

Codecov / codecov/patch

pytensor/compile/compiledir.py#L183

Added line #L183 was not covered by tests

print()
print() # noqa: T201

Check warning on line 185 in pytensor/compile/compiledir.py

View check run for this annotation

Codecov / codecov/patch

pytensor/compile/compiledir.py#L185

Added line #L185 was not covered by tests
print_title(
(
f"List of {len(table_op_class)} compiled Op classes and "
Expand All @@ -191,33 +191,33 @@
underline="+",
)
for op_class, nb in reversed(table_op_class.most_common()):
print(op_class, nb)
print(op_class, nb) # noqa: T201

Check warning on line 194 in pytensor/compile/compiledir.py

View check run for this annotation

Codecov / codecov/patch

pytensor/compile/compiledir.py#L194

Added line #L194 was not covered by tests

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

Check warning on line 199 in pytensor/compile/compiledir.py

View check run for this annotation

Codecov / codecov/patch

pytensor/compile/compiledir.py#L199

Added line #L199 was not covered by tests
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

Check warning on line 203 in pytensor/compile/compiledir.py

View check run for this annotation

Codecov / codecov/patch

pytensor/compile/compiledir.py#L203

Added line #L203 was not covered by tests
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

Check warning on line 209 in pytensor/compile/compiledir.py

View check run for this annotation

Codecov / codecov/patch

pytensor/compile/compiledir.py#L209

Added line #L209 was not covered by tests

nb_keys = sorted(nb_keys.items())
print()
print() # noqa: T201

Check warning on line 212 in pytensor/compile/compiledir.py

View check run for this annotation

Codecov / codecov/patch

pytensor/compile/compiledir.py#L212

Added line #L212 was not covered by tests
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

Check warning on line 220 in pytensor/compile/compiledir.py

View check run for this annotation

Codecov / codecov/patch

pytensor/compile/compiledir.py#L218-L220

Added lines #L218 - L220 were not covered by tests
f"Skipped {int(zeros_op)} files that contained 0 op "
"(are they always pytensor.scalar ops?)"
)
Expand All @@ -242,18 +242,18 @@
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

Check warning on line 246 in pytensor/compile/compiledir.py

View check run for this annotation

Codecov / codecov/patch

pytensor/compile/compiledir.py#L245-L246

Added lines #L245 - L246 were not covered by tests
for d in subdirs:
print(f" {d}")
print(f" {d}") # noqa: T201

Check warning on line 248 in pytensor/compile/compiledir.py

View check run for this annotation

Codecov / codecov/patch

pytensor/compile/compiledir.py#L248

Added line #L248 was not covered by tests
if not subdirs:
print(" (None)")
print(" (None)") # noqa: T201

Check warning on line 250 in pytensor/compile/compiledir.py

View check run for this annotation

Codecov / codecov/patch

pytensor/compile/compiledir.py#L250

Added line #L250 was not covered by tests

if others:
print()
print("Other files in base_compiledir:")
print() # noqa: T201
print("Other files in base_compiledir:") # noqa: T201

Check warning on line 254 in pytensor/compile/compiledir.py

View check run for this annotation

Codecov / codecov/patch

pytensor/compile/compiledir.py#L253-L254

Added lines #L253 - L254 were not covered by tests
for f in others:
print(f" {f}")
print(f" {f}") # noqa: T201

Check warning on line 256 in pytensor/compile/compiledir.py

View check run for this annotation

Codecov / codecov/patch

pytensor/compile/compiledir.py#L256

Added line #L256 was not covered by tests


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 printstuff(self):
for key in self.equiv:
print(key)
print(key) # noqa: T201

Check warning on line 1318 in pytensor/compile/debugmode.py

View check run for this annotation

Codecov / codecov/patch

pytensor/compile/debugmode.py#L1318

Added line #L1318 was not covered by tests
for e in self.equiv[key]:
print(" ", e)
print(" ", e) # noqa: T201

Check warning on line 1320 in pytensor/compile/debugmode.py

View check run for this annotation

Codecov / codecov/patch

pytensor/compile/debugmode.py#L1320

Added line #L1320 was not covered by tests


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

Check warning on line 1572 in pytensor/compile/debugmode.py

View check run for this annotation

Codecov / codecov/patch

pytensor/compile/debugmode.py#L1572

Added line #L1572 was not covered by tests
assert s[0] is None

# try:
Expand Down Expand Up @@ -2079,7 +2079,7 @@
raise StochasticOrder(infolog.getvalue())
else:
if self.verbose:
print(
print( # noqa: T201

Check warning on line 2082 in pytensor/compile/debugmode.py

View check run for this annotation

Codecov / codecov/patch

pytensor/compile/debugmode.py#L2082

Added line #L2082 was not covered by tests
"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 apply(self, fgraph):
import pytensor.printing

print("PrintCurrentFunctionGraph:", self.header)
print("PrintCurrentFunctionGraph:", self.header) # noqa: T201

Check warning on line 181 in pytensor/compile/mode.py

View check run for this annotation

Codecov / codecov/patch

pytensor/compile/mode.py#L181

Added line #L181 was not covered by tests
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 @@
not isinstance(output[0], np.random.RandomState | np.random.Generator)
and np.isnan(output[0]).any()
):
print("*** NaN detected ***")
print("*** NaN detected ***") # noqa: T201

Check warning on line 111 in pytensor/compile/monitormode.py

View check run for this annotation

Codecov / codecov/patch

pytensor/compile/monitormode.py#L111

Added line #L111 was not covered by tests
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

Check warning on line 114 in pytensor/compile/monitormode.py

View check run for this annotation

Codecov / codecov/patch

pytensor/compile/monitormode.py#L113-L114

Added lines #L113 - L114 were not covered by tests
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 @@
if config.NanGuardMode__action == "raise":
raise AssertionError(msg)
elif config.NanGuardMode__action == "pdb":
print(msg)
print(msg) # noqa: T201

Check warning on line 239 in pytensor/compile/nanguardmode.py

View check run for this annotation

Codecov / codecov/patch

pytensor/compile/nanguardmode.py#L239

Added line #L239 was not covered by tests
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 @@
to_sum.append(ps)
else:
# TODO print the name if there is one!
print("Skipping empty Profile")
print("Skipping empty Profile") # noqa: T201

Check warning on line 85 in pytensor/compile/profiling.py

View check run for this annotation

Codecov / codecov/patch

pytensor/compile/profiling.py#L85

Added line #L85 was not covered by tests
if len(to_sum) > 1:
# Make a global profile
cum = copy.copy(to_sum[0])
Expand Down Expand Up @@ -125,7 +125,7 @@
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

Check warning on line 128 in pytensor/compile/profiling.py

View check run for this annotation

Codecov / codecov/patch

pytensor/compile/profiling.py#L128

Added line #L128 was not covered by tests
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 @@
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

Check warning on line 494 in pytensor/graph/features.py

View check run for this annotation

Codecov / codecov/patch

pytensor/graph/features.py#L494

Added line #L494 was not covered by tests
raise
t1 = time.perf_counter()
if fgraph.profile:
Expand Down Expand Up @@ -603,13 +603,13 @@
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 @@
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

Check warning on line 695 in pytensor/graph/features.py

View check run for this annotation

Codecov / codecov/patch

pytensor/graph/features.py#L695

Added line #L695 was not covered by tests
try:
print("OFFENDING node hash", hash(node.op), file=sys.stderr)
print("OFFENDING node hash", hash(node.op), file=sys.stderr) # noqa: T201

Check warning on line 697 in pytensor/graph/features.py

View check run for this annotation

Codecov / codecov/patch

pytensor/graph/features.py#L697

Added line #L697 was not covered by tests
except Exception:
print("OFFENDING node not hashable", file=sys.stderr)
print("OFFENDING node not hashable", file=sys.stderr) # noqa: T201

Check warning on line 699 in pytensor/graph/features.py

View check run for this annotation

Codecov / codecov/patch

pytensor/graph/features.py#L699

Added line #L699 was not covered by tests
raise e

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

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

Check warning on line 728 in pytensor/graph/features.py

View check run for this annotation

Codecov / codecov/patch

pytensor/graph/features.py#L728

Added line #L728 was not covered by tests

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

Check warning on line 736 in pytensor/graph/features.py

View check run for this annotation

Codecov / codecov/patch

pytensor/graph/features.py#L736

Added line #L736 was not covered by tests

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

Check warning on line 740 in pytensor/graph/features.py

View check run for this annotation

Codecov / codecov/patch

pytensor/graph/features.py#L740

Added line #L740 was not covered by tests

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

Check warning on line 744 in pytensor/graph/features.py

View check run for this annotation

Codecov / codecov/patch

pytensor/graph/features.py#L744

Added line #L744 was not covered by tests

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

Check warning on line 748 in pytensor/graph/features.py

View check run for this annotation

Codecov / codecov/patch

pytensor/graph/features.py#L748

Added line #L748 was not covered by tests


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