Skip to content
New issue

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

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

Already on GitHub? # to your account

RfC: Enforce consistent formatting on CI #1957

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

romanc
Copy link
Contributor

@romanc romanc commented Feb 28, 2025

Description

Since there was no pushback on the discussion page1, let's go one step further and start discussing how this could look like in practice.

This PR contains two commits

  1. First commit is just to turn off all other CI while we iterate on the linting part. This will obviously be reverted.
  2. Second commit adds automated linting infrastructure.

To see the automated linting infrastructure in action, pull this branch, install the linting extras and run

pre-commit run --all-files

Most changes you'll see will be whitespace changes. If you don't like the formatting, yapf has a couple of knobs we could use for fine-tuning. And there's always the option to manually put guards in select places where auto-formatting isn't good enough.

Footnotes

  1. https://github.com/spcl/dace/discussions/1804

@romanc romanc force-pushed the romanc/linting branch 2 times, most recently from 1444d24 to 576fc1f Compare February 28, 2025 12:55
This PR is to support the discussion on enforcing consistent formatting
on the CI [1].

[1] spcl#1804
Copy link
Contributor Author

@romanc romanc left a comment

Choose a reason for hiding this comment

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

With this review, I want to highlight a couple places where we could end up putting manual guards to force a particular code layout.

Comment on lines 454 to 458
ind_entry, ind_exit = graph.add_map('indirection', {
'__i%d' % i: '%s:%s+1:%s' % (s, e, t)
for i, (s, e, t) in enumerate(mapped_rng)
},
debuginfo=pvisitor.current_lineinfo)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is an example where we might want to put manual guards around the old version.

Comment on lines 1467 to 1465
name, _ = sdfg.add_temp_transient(arr1.shape, restype, arr1.storage)
state.add_mapped_tasklet("_%s_" % opname, {'__i%d' % i: '0:%s' % s
for i, s in enumerate(arr1.shape)},
{'__in1': Memlet.simple(op1, ','.join(['__i%d' % i for i in range(len(arr1.shape))]))},
state.add_mapped_tasklet("_%s_" % opname, {
'__i%d' % i: '0:%s' % s
for i, s in enumerate(arr1.shape)
}, {'__in1': Memlet.simple(op1, ','.join(['__i%d' % i for i in range(len(arr1.shape))]))},
'__out = %s __in1' % opcode,
{'__out': Memlet.simple(name, ','.join(['__i%d' % i for i in range(len(arr1.shape))]))},
external_edges=True)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

From what I see: adding mapped tasklets works best if the first argument is already on a new line (at least in the current configuration of yapf)

Comment on lines 17 to 30
s[i, j, k] = (
0.5000 * r[2 * i, 2 * j, 2 * k] +
0.2500 * (r[2 * i - 1, 2 * j, 2 * k] + r[2 * i + 1, 2 * j, 2 * k] + r[2 * i, 2 * j - 1, 2 * k] +
r[2 * i, 2 * j + 1, 2 * k] + r[2 * i, 2 * j, 2 * k - 1] + r[2 * i, 2 * j, 2 * k + 1]) +
0.1250 * (r[2 * i - 1, 2 * j - 1, 2 * k] + r[2 * i - 1, 2 * j + 1, 2 * k] +
r[2 * i + 1, 2 * j - 1, 2 * k] + r[2 * i + 1, 2 * j + 1, 2 * k] +
r[2 * i - 1, 2 * j, 2 * k - 1] + r[2 * i - 1, 2 * j, 2 * k + 1] +
r[2 * i + 1, 2 * j, 2 * k - 1] + r[2 * i + 1, 2 * j, 2 * k + 1] +
r[2 * i, 2 * j - 1, 2 * k - 1] + r[2 * i, 2 * j - 1, 2 * k + 1] +
r[2 * i, 2 * j + 1, 2 * k - 1] + r[2 * i, 2 * j + 1, 2 * k + 1]) +
0.0625 * (r[2 * i - 1, 2 * j - 1, 2 * k - 1] + r[2 * i - 1, 2 * j - 1, 2 * k + 1] +
r[2 * i - 1, 2 * j + 1, 2 * k - 1] + r[2 * i - 1, 2 * j + 1, 2 * k + 1] +
r[2 * i + 1, 2 * j - 1, 2 * k - 1] + r[2 * i + 1, 2 * j - 1, 2 * k + 1] +
r[2 * i + 1, 2 * j + 1, 2 * k - 1] + r[2 * i + 1, 2 * j + 1, 2 * k + 1]))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one is a perfect example for manual guards

Comment on lines 66 to 68
assert [type(n)
for n in stree.preorder_traversal()][1:] == [tn.MapScope, tn.MapScope, tn.GeneralLoopScope,
tn.TaskletNode]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

that might also warrant a manual guard

Comment on lines 252 to 255
assert stree.as_string() == (f'{tn.INDENTATION}assign i = 0\n' +
f'{tn.INDENTATION}while (i < 10):\n' +
f'{2 * tn.INDENTATION}A[i] = tasklet()\n' +
f'{2 * tn.INDENTATION}assign i = (i + 1)')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

More candidates for "assert guards" in this file

@romanc romanc changed the title PoC: Enforce consistent formatting on CI RfC: Enforce consistent formatting on CI Feb 28, 2025
@tbennun
Copy link
Collaborator

tbennun commented Mar 2, 2025

@romanc I am ok with this PR. Let's discuss it on Thursday to finalize the decision.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants