Skip to content

misc: General reductions in lines of code - #3031

Open
EdCaunt wants to merge 9 commits into
mainfrom
golf
Open

EdCaunt wants to merge 9 commits into
mainfrom
golf

Conversation

@EdCaunt

@EdCaunt EdCaunt commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

No description provided.

if isinstance(p, type) \
and issubclass(p, sympy.Symbol) \
and any(isinstance(i, p) for i in self.free_symbols):
if (isinstance(p, type) and issubclass(p, sympy.Symbol) and

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Todo: revert

last = [ecls(lhs, rhs, implicit_dims=implicit_dims)]

return temps + last
return temps + [ecls(lhs, rhs, implicit_dims=implicit_dims)]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Todo: revert


class LinearInterpolator(WeightedInterpolator):
class TabulatedInterpolator(WeightedInterpolator):
"""Shared plumbing for schemes whose weights are tabulated on the host."""

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Todo: adjust docstring

@codecov

codecov Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 78.18930% with 53 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.93%. Comparing base (760a476) to head (e2105ac).

Files with missing lines Patch % Lines
devito/types/sparse.py 53.84% 18 Missing ⚠️
devito/finite_differences/differentiable.py 75.86% 6 Missing and 1 partial ⚠️
devito/operator/operator.py 76.66% 6 Missing and 1 partial ⚠️
devito/types/grid.py 69.56% 5 Missing and 2 partials ⚠️
devito/types/dense.py 75.00% 4 Missing and 2 partials ⚠️
devito/tools/data_structures.py 71.42% 4 Missing ⚠️
devito/types/dimension.py 90.90% 3 Missing ⚠️
devito/types/basic.py 95.83% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3031      +/-   ##
==========================================
+ Coverage   83.89%   83.93%   +0.03%     
==========================================
  Files         258      258              
  Lines       55605    55450     -155     
  Branches     4765     4744      -21     
==========================================
- Hits        46652    46544     -108     
+ Misses       8135     8093      -42     
+ Partials      818      813       -5     
Flag Coverage Δ
pytest-gpu-aomp-amdgpuX 68.72% <60.90%> (+0.07%) ⬆️
pytest-gpu-gcc- 78.59% <77.77%> (+0.03%) ⬆️
pytest-gpu-icx- 78.53% <77.77%> (+0.04%) ⬆️
pytest-gpu-nvc-nvidiaX 69.24% <62.13%> (+0.07%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

"due to excessive register pressure in one of the Operator "
"kernels. Try supplying a smaller `par-tile` value."
)
"kernels. Try supplying a smaller `par-tile` value.")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Todo: revert

"prevents the use of `tbc-tile` in realistic scenarios, but it "
"will be removed in future versions."
)
"will be removed in future versions.")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Todo: revert

'linearize': False,
'place-transfers': False
}
rcompile_registry = {'avoid_denormals': False, 'linearize': False,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Todo: revert

byproduct = byproduct0.filter(key)

return irs, byproduct
return irs, byproduct0.filter(key)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Todo: revert


return {'platform': self.platform.name,
'compiler': compiler,
return {'platform': self.platform.name, 'compiler': compiler,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Todo: revert

"""
key0 = lambda f: (f.is_TimeFunction and
f.save is not None and
key0 = lambda f: (f.is_TimeFunction and f.save is not None and

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Todo: revert

self.nbytes_consumed_arrays,
self.nbytes_consumed_memmapped
)
mem_locations = (self.nbytes_consumed_functions, self.nbytes_consumed_arrays,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Todo: revert

@JDBetteridge JDBetteridge left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I hate it.

But in all seriousness, what's the point? It looks like we reduce the number of lines of code in the whole codebase by ~600 at the expense of:

  • Readability “Programs must be written for people to read, and only incidentally for machines to execute.” Harold Abelson, Structure and Interpretation of Computer Programs
  • Automatic merge and rebase functionality
  • Spaghetti code, I'm thinking specifically of early/multiple returns "A single return statement at the end of a function creates a single, known point which is passed through at the termination of function execution.
    The single-return structure is easier to change. If there is more to do after a
    search, just add the statement(s) between the for loop and the return." C STYLE GUIDE, 1994, National Aeronautics and Space Administration (NASA)

The metric should not be the number of lines we remove. The goal of reducing the number of lines of code in a codebase should be eliminating redundant classes and functions by refining the abstractions and generally making the structure more elegant.

'Real',
'Weights',
'Conj', 'DiffDerivative', 'Differentiable', 'EvalDerivative', 'Imag',
'IndexDerivative', 'IndexDerivativeProperty', 'LocalSum', 'Real', 'Weights',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No

fd_args = []
for f in self._args_diff:
try:
with suppress(AttributeError):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

and issubclass(p, sympy.Symbol) \
and any(isinstance(i, p) for i in self.free_symbols):
if (isinstance(p, type) and issubclass(p, sympy.Symbol) and
any(isinstance(i, p) for i in self.free_symbols)):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is less readable

prio = getattr(expr, '_fd_priority', 0)
return max([prio] + [deep_priority(i)
for i in getattr(expr, '_args_diff', ())])
return max([prio] + [deep_priority(i) for i in getattr(expr, '_args_diff', ())])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@FabioLuporini doesn't like getattr, if you're going to touch lines of code you should probably fix them too

other = self.func(*other)._eval_at(highest_priority(self))
return self.func(other, *derivs)
other = self.func(*other)._eval_at(highest_priority(self))
return self.func(other, *derivs)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I despise multiple returns and consider them the definition of spaghetti code. I'd much rather you consolidate and return once

Comment thread devito/types/basic.py
"""Number of points in the domain region."""
return DimensionTuple(*self.shape, getters=self.dimensions)

def _make_sizes(self, pairs):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a free function and used in at least one other place to justify its existance

Comment thread devito/types/basic.py
for a, b in zip(row_indices, col_indices, strict=True)
]
vec = [mat[a]*other_mat[b]
for a, b in zip(row_indices, col_indices, strict=True)]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No

Comment thread devito/types/basic.py
cls = self.function._indexed_cls
except AttributeError:
cls = Indexed
cls = getattr(self.function, '_indexed_cls', Indexed)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@FabioLuporini he's doing it again...

Comment thread devito/types/basic.py
"all dimensions are covered"
)
raise ValueError(f"Cannot translate {self} with mapper {mapper} since not "
"all dimensions are covered")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No description provided.

Comment thread devito/types/dense.py
for i, j in zip(self._decomposition, self._size_inhalo.left, strict=True)]
right = [max(i.loc_abs_max+j-i.glb_max, 0) if i and not i.loc_empty else 0
for i, j in zip(self._decomposition, self._size_inhalo.right,
strict=True)]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make this bit less readable!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm stopping here, I can't read anymore

@JDBetteridge

Copy link
Copy Markdown
Contributor

Also, if you have time to feed this into a prompt, you probably have time to help me a bit more with my other PRs

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants