Skip to content

Commit

Permalink
Linting changes from pre-commit & yapf
Browse files Browse the repository at this point in the history
  • Loading branch information
romanc committed Feb 28, 2025
1 parent b3914a9 commit 576fc1f
Show file tree
Hide file tree
Showing 579 changed files with 5,318 additions and 4,971 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
@@ -1 +1 @@
BasedOnStyle: Google
BasedOnStyle: Google
4 changes: 2 additions & 2 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ exclude_lines =
if False:
if __name__ == .__main__.:
pass

omit =
# Omit files that cannot be tested
dace/jupyter.py

# Omit deprecated files
dace/frontend/tensorflow/__init__.py
dace/frontend/tensorflow/tensorflow.py
Expand Down
4 changes: 1 addition & 3 deletions .github/citation_format_authors.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Parse the authors file and print for CITATION.cff
"""
with open("AUTHORS", "r") as f:
content = f.readlines()
content = f.readlines()

for i, l in enumerate(content[4:]):
if l == "\n":
Expand All @@ -18,5 +18,3 @@
last_names = ' '.join(names[1:])
text = f"- family-names: {last_names}\n given-names: {first_name}"
print(text)


2 changes: 1 addition & 1 deletion .github/workflows/hardware_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ jobs:
# Due to an internal bug in the Xilinx tools, where the current datetime is passed as an integer
# and overflowed in the year 2022, run the RTL FPGA tests pretending like it's January 1st 2021.
faketime -f "@2021-01-01 00:00:00" pytest -n auto --tb=short -m "rtl_hardware"
killall -9 xsim xsimk || true
killall -9 xsim xsimk || true
6 changes: 3 additions & 3 deletions .github/workflows/heterogeneous-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
run: |
papi_avail
- name: Run parallel pytest
- name: Run parallel pytest
run: |
source ~/.venv/bin/activate # activate venv
export DACE_cache=unique
Expand All @@ -55,7 +55,7 @@ jobs:
source ~/.venv/bin/activate # activate venv
./tests/mpi_test.sh
- name: Test MPI with pytest
run: |
export NOSTATUSBAR=1
Expand All @@ -64,7 +64,7 @@ jobs:
export DACE_cache=unique
source ~/.venv/bin/activate # activate venv
mpirun -n 2 coverage run --source=dace --parallel-mode -m pytest -x --with-mpi --tb=short -m "mpi"
- name: Test ScaLAPACK PBLAS with pytest
run: |
export NOSTATUSBAR=1
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/pyFV3-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
submodules: 'recursive'
path: 'pyFV3'
- uses: actions/checkout@v4
with:
with:
path: 'dace'
submodules: 'recursive'
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -46,9 +46,9 @@ jobs:
sudo apt-get install -y libopenmpi-dev libboost-all-dev
gcc --version
# Because Github doesn't allow us to do a git checkout in code
# we use a trick to checkout DaCe first (not using the external submodule)
# we use a trick to checkout DaCe first (not using the external submodule)
# install the full suite via requirements_dev, then re-install the correct DaCe
- name: Install Python packages
- name: Install Python packages
run: |
python -m pip install --upgrade pip wheel setuptools
pip install -e ./pyFV3[develop]
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,3 @@ python -m build --sdist

# Upload to PyPI
twine upload dist/*

3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,3 @@ _build/

# Ignoring the test junk
_all_tests/



2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
url = https://github.com/spcl/dace-webclient.git
[submodule "dace/external/rtllib"]
path = dace/external/rtllib
url = https://github.com/carljohnsen/rtllib.git
url = https://github.com/carljohnsen/rtllib.git
2 changes: 1 addition & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This is the official list of DaCe authors (individuals or organizations) for
# This is the official list of DaCe authors (individuals or organizations) for
# copyright purposes.

ETH Zurich
Expand Down
4 changes: 2 additions & 2 deletions CITATION.cff
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cff-version: 1.2.0
title: "DaCe - Data Centric Parallel Programming"
message: "Please cite as"
message: "Please cite as"
# this can be parsed from the AUTHORS file using .github/citation_format_authors.py
authors:
- family-names: Ben-Nun
Expand Down Expand Up @@ -64,7 +64,7 @@ preferred-citation:
year: "2019"
type: conference-paper
collection-title: "Proceedings of the International Conference for High Performance Computing, Networking, Storage and Analysis"
conference:
conference:
name: "SC '19"
authors:
- family-names: Ben-Nun
Expand Down
5 changes: 2 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ development and the code review process.

We follow the [Google Python Style Guide](https://google.github.io/styleguide/pyguide.html), with a few notable exceptions:

* **"Power Features"**: We like Python power features. We use them both externally (to make the Python/Numpy frontend easy to use) and internally. Use of any Python power feature that increases productivity is allowed.
* **"Power Features"**: We like Python power features. We use them both externally (to make the Python/Numpy frontend easy to use) and internally. Use of any Python power feature that increases productivity is allowed.
* **Note on compatibility**: DaCe currently supports Python versions 3.6 and above, please make sure that the feature is supported in those versions, and if not ([dataclasses](https://docs.python.org/3/library/dataclasses.html) for example), please make sure to add a backwards-compatibility dependency. [Example](https://github.com/spcl/dace/blob/205d7c911a74e507d2fcbcc4b6cb5819b026648a/setup.py#L71)
* **Type Hints**: New functions must include proper Python [typing information](https://docs.python.org/3/library/typing.html), in order to support type checking and smoother development.
* **Importing classes and functions directly**: This is disallowed, with the exception of directly importing the following main graph components (which are heavily reused throughout the framework): `SDFG, SDFGState, Memlet, InterstateEdge`.
Expand Down Expand Up @@ -63,7 +63,7 @@ to install the `git` hooks for this repository.

## Tests

We use [pytest](https://www.pytest.org/) for our testing infrastructure. All tests under the `tests/` folder
We use [pytest](https://www.pytest.org/) for our testing infrastructure. All tests under the `tests/` folder
(and any subfolders within) are automatically read and run. The files must be under the right subfolder
based on the component being tested (e.g., `tests/sdfg/` for IR-related tests), and must have the right
suffix: either `*_test.py` or `*_cudatest.py`. See [pytest.ini](https://github.com/spcl/dace/blob/main/pytest.ini)
Expand Down Expand Up @@ -105,4 +105,3 @@ Use Python docstrings for function/class/file documentation. Since we use [Sphin

File documentation is mostly one or a few sentences documenting the purpose and elements
in a file. If your file contains more than one class/function, which share a general theme that should be documented, include a docstring for the Python file containing a general explanation (and ideally an example of the topic). [Example](dace/codegen/control_flow.py)

27 changes: 13 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,24 @@
_Decoupling domain science from performance optimization._

DaCe is a [fast](https://nbviewer.org/github/spcl/dace/blob/main/tutorials/benchmarking.ipynb) parallel programming
framework that takes code in Python/NumPy and other programming languages, and maps it to high-performance
**CPU, GPU, and FPGA** programs, which can be optimized to achieve state-of-the-art. Internally, DaCe
uses the Stateful DataFlow multiGraph (SDFG) *data-centric intermediate
representation*: A transformable, interactive representation of code based on
framework that takes code in Python/NumPy and other programming languages, and maps it to high-performance
**CPU, GPU, and FPGA** programs, which can be optimized to achieve state-of-the-art. Internally, DaCe
uses the Stateful DataFlow multiGraph (SDFG) *data-centric intermediate
representation*: A transformable, interactive representation of code based on
data movement.
Since the input code and the SDFG are separate, it is possible to optimize a
program without changing its source, so that it stays readable. On the other
hand, transformations are customizable and user-extensible, so they can be written
Since the input code and the SDFG are separate, it is possible to optimize a
program without changing its source, so that it stays readable. On the other
hand, transformations are customizable and user-extensible, so they can be written
once and reused in many applications.
With data-centric parallel programming, we enable **direct knowledge transfer**
With data-centric parallel programming, we enable **direct knowledge transfer**
of performance optimization, regardless of the application or the target processor.

DaCe generates high-performance programs for:
* Multi-core CPUs (tested on Intel, IBM POWER9, and ARM with SVE)
* NVIDIA GPUs and AMD GPUs (with HIP)
* Xilinx and Intel FPGAs

DaCe can be written inline in Python and transformed in the command-line/Jupyter
DaCe can be written inline in Python and transformed in the command-line/Jupyter
Notebooks or SDFGs can be interactively modified using our [Visual Studio Code extension](https://marketplace.visualstudio.com/items?itemName=phschaad.sdfv).

## [For more information, see the documentation](https://spcldace.readthedocs.io/en/latest/)
Expand All @@ -53,10 +53,10 @@ def myprogram(a):
return np.sum(a)
```

Calling `myprogram` with any NumPy array or GPU array (e.g., PyTorch, Numba, CuPy) will
generate data-centric code, compile, and run it. From here on out, you can
_optimize_ (interactively or automatically), _instrument_, and _distribute_
your code. The code creates a shared library (DLL/SO file) that can readily
Calling `myprogram` with any NumPy array or GPU array (e.g., PyTorch, Numba, CuPy) will
generate data-centric code, compile, and run it. From here on out, you can
_optimize_ (interactively or automatically), _instrument_, and _distribute_
your code. The code creates a shared library (DLL/SO file) that can readily
be used in any C ABI compatible language (C/C++, FORTRAN, etc.).

For more information on how to use DaCe, see the [samples](samples) or tutorials below:
Expand Down Expand Up @@ -93,4 +93,3 @@ DaCe is an open-source project. We are happy to accept Pull Requests with your c
License
-------
DaCe is published under the New BSD license, see [LICENSE](LICENSE).

1 change: 1 addition & 0 deletions dace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
# Hack that enables using @dace as a decorator
# See https://stackoverflow.com/a/48100440/6489142
class DaceModule(sys.modules[__name__].__class__):

def __call__(self, *args, **kwargs):
return function(*args, **kwargs)

Expand Down
15 changes: 9 additions & 6 deletions dace/builtin_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ def profile(
def _make_filter_function(filter: Optional[Union[str, Callable[[Any], bool]]],
with_attr: bool = True) -> Callable[[Any], bool]:
"""
Internal helper that makes a filtering function.
Internal helper that makes a filtering function.
* If nothing is given, the filter always returns True.
* If a string is given, performs wildcard matching.
* If a callable is given, use predicate directly.
:param filter: The filter to use.
:param with_attr: If True, uses the ``name`` attribute for testing strings.
Expand Down Expand Up @@ -121,7 +121,7 @@ def instrument(itype: 'InstrumentationType',
.. code-block:: python
with dace.instrument(dace.InstrumentationType.GPU_Events,
with dace.instrument(dace.InstrumentationType.GPU_Events,
filter='*add??') as profiler:
some_program(...)
# ...
Expand All @@ -148,6 +148,7 @@ def instrument(itype: 'InstrumentationType',
filter_func = _make_filter_function(filter)

class Instrumenter:

def __init__(self):
self.reports: List[InstrumentationReport] = []

Expand Down Expand Up @@ -212,15 +213,15 @@ def sample(a: dace.float64, b: dace.float64):
with dace.instrument_data(dace.DataInstrumentationType.Save, filter='a??'):
result_ab = sample(a, b)
# Optionally, get the serialized data containers
dreport = sdfg.get_instrumented_data()
assert dreport.keys() == {'arr'} # dreport['arr'] is now the internal ``arr``
# Reload latest instrumented data (can be customized if ``restore_from`` is given)
with dace.instrument_data(dace.DataInstrumentationType.Restore, filter='a??'):
result_cd = sample(c, d) # where ``c, d`` are different from ``a, b``
assert numpy.allclose(result_ab, result_cd)
Expand All @@ -243,6 +244,7 @@ def sample(a: dace.float64, b: dace.float64):
filter_func = _make_filter_function(filter, with_attr=False)

class DataInstrumenter:

@contextmanager
def __call__(self, sdfg: 'SDFG'):
for n, _ in sdfg.all_nodes_recursive():
Expand All @@ -269,6 +271,7 @@ def __call__(self, sdfg: 'SDFG'):
if ditype == DataInstrumentationType.Restore:
# Restore data into compiled SDFG
class DataRestoreHook:

@contextmanager
def __call__(self, csdfg: 'CompiledSDFG', args: Tuple[Any, ...]):
# Restore data from requested data report
Expand Down
1 change: 1 addition & 0 deletions dace/cli/fcdc.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import shutil
from dace.frontend.fortran import fortran_parser


def main():
# Command line options parser
parser = argparse.ArgumentParser(description='Fortran to SDFG command-line transpiler.')
Expand Down
11 changes: 3 additions & 8 deletions dace/cli/sdfg_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from dace.sdfg.state import ControlFlowBlock
import dace.serialize


DiffableT = Union[ControlFlowBlock, nd.Node, MultiConnectorEdge[mlt.Memlet], Edge[InterstateEdge]]
DiffSetsT = Tuple[Set[str], Set[str], Set[str]]

Expand Down Expand Up @@ -69,7 +68,7 @@ def _print_diff(sdfg_A: dace.SDFG, sdfg_B: dace.SDFG, diff_sets: DiffSetsT) -> N
print('SDFGs are identical')


def _sdfg_diff(sdfg_A: dace.SDFG, sdfg_B: dace.SDFG, eq_strategy = Union[Literal['hash', '==']]) -> DiffSetsT:
def _sdfg_diff(sdfg_A: dace.SDFG, sdfg_B: dace.SDFG, eq_strategy=Union[Literal['hash', '==']]) -> DiffSetsT:
all_id_elements_A: Dict[str, DiffableT] = dict()
all_id_elements_B: Dict[str, DiffableT] = dict()

Expand Down Expand Up @@ -151,17 +150,13 @@ def main():
action='store_true',
help="If set, visualize the difference graphically",
default=False)
parser.add_argument('-o',
'--output',
dest='output',
help="The output filename to generate",
type=str)
parser.add_argument('-o', '--output', dest='output', help="The output filename to generate", type=str)
parser.add_argument('-H',
'--hash',
dest='hash',
action='store_true',
help="If set, use the hash of JSON serialized properties for change checks instead of " +
"Python's dictionary equivalence checks. This makes changes order sensitive.",
"Python's dictionary equivalence checks. This makes changes order sensitive.",
default=False)

args = parser.parse_args()
Expand Down
12 changes: 5 additions & 7 deletions dace/cli/sdfv.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@


def partialclass(cls, *args, **kwds):

class NewCls(cls):
__init__ = functools.partialmethod(cls.__init__, *args, **kwds)

Expand All @@ -37,11 +38,8 @@ def view(sdfg: dace.SDFG, filename: Optional[Union[str, int]] = None, verbose: b
"""
# If vscode is open, try to open it inside vscode
if filename is None:
if (
'VSCODE_IPC_HOOK' in os.environ
or 'VSCODE_IPC_HOOK_CLI' in os.environ
or 'VSCODE_GIT_IPC_HANDLE' in os.environ
):
if ('VSCODE_IPC_HOOK' in os.environ or 'VSCODE_IPC_HOOK_CLI' in os.environ
or 'VSCODE_GIT_IPC_HANDLE' in os.environ):
suffix = '.sdfgz' if compress else '.sdfg'
fd, filename = tempfile.mkstemp(suffix=suffix)
sdfg.save(filename, compress=compress)
Expand Down Expand Up @@ -82,7 +80,7 @@ def view(sdfg: dace.SDFG, filename: Optional[Union[str, int]] = None, verbose: b
with open(html_filename, "w") as f:
f.write(html)

if(verbose):
if (verbose):
print("File saved at %s" % html_filename)

if fd is not None:
Expand All @@ -95,7 +93,7 @@ def view(sdfg: dace.SDFG, filename: Optional[Union[str, int]] = None, verbose: b
# start the web server
handler = partialclass(http.server.SimpleHTTPRequestHandler, directory=dirname)
httpd = http.server.HTTPServer(('localhost', filename), handler)
if(verbose):
if (verbose):
print(f"Serving at localhost:{filename}, press enter to stop...")

# start the server in a different thread
Expand Down
2 changes: 1 addition & 1 deletion dace/codegen/Xilinx_IP.tcl.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ set_part ${DACE_XILINX_PART_NAME}
create_clock -period ${DACE_XILINX_INTERNAL_TARGET_CLOCK}MHz -name default
csynth_design
export_design -format ip_catalog
quit
quit
7 changes: 4 additions & 3 deletions dace/codegen/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,10 @@ def generate_code(sdfg: SDFG, validate=True) -> List[CodeObject]:
targets = {'cpu': default_target(frame, sdfg)}

# Instantiate the rest of the targets
targets.update(
{v['name']: k(frame, sdfg)
for k, v in TargetCodeGenerator.extensions().items() if v['name'] not in targets})
targets.update({
v['name']: k(frame, sdfg)
for k, v in TargetCodeGenerator.extensions().items() if v['name'] not in targets
})

# Query all code generation targets and instrumentation providers in SDFG
_get_codegen_targets(sdfg, frame)
Expand Down
3 changes: 2 additions & 1 deletion dace/codegen/codeobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class CodeObject(object):
value_type=str,
desc="Additional compiler argument "
"variables to add to template")
linkable = Property(dtype=bool, desc='Should this file participate in ' 'overall linkage?')
linkable = Property(dtype=bool, desc='Should this file participate in '
'overall linkage?')
environments = SetProperty(str,
desc="Environments required by CMake to build and run this code node.",
default=set())
Expand Down
Loading

0 comments on commit 576fc1f

Please sign in to comment.