From cd5e00dd7a746236d856b349dc1f17667f5d9588 Mon Sep 17 00:00:00 2001 From: Bradley Dice Date: Tue, 17 Sep 2024 12:00:30 -0500 Subject: [PATCH 1/2] Update flake8 to 7.1.1. --- .pre-commit-config.yaml | 2 +- .../cugraph-dgl/python-script/ogbn_mag_benchmark.py | 4 ++-- python/cugraph-dgl/cugraph_dgl/nn/conv/base.py | 4 ++-- .../examples/graphsage/node-classification-dask.py | 4 +++- .../examples/graphsage/node-classification.py | 4 +++- .../examples/multi_trainer_MG_example/model.py | 2 +- .../examples/multi_trainer_MG_example/workflow_mnmg.py | 2 +- .../examples/multi_trainer_MG_example/workflow_snmg.py | 2 +- .../cugraph-pyg/cugraph_pyg/data/dask_graph_store.py | 2 +- python/cugraph-pyg/cugraph_pyg/examples/gcn_dist_sg.py | 2 +- python/cugraph-service/tests/test_e2e.py | 6 +++--- python/cugraph-service/tests/test_mg_e2e.py | 6 +++--- python/cugraph/cugraph/tests/generators/test_rmat.py | 4 +++- .../cugraph/cugraph/tests/generators/test_rmat_mg.py | 6 ++++-- .../cugraph/tests/sampling/test_bulk_sampler.py | 2 +- .../cugraph/cugraph/tests/structure/test_graph_mg.py | 4 ++-- python/cugraph/cugraph/tests/traversal/test_sssp.py | 4 ++-- python/cugraph/cugraph/traversal/sssp.py | 10 ++++++---- 18 files changed, 40 insertions(+), 30 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5b351478fa9..fafd6fd7b3a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -21,7 +21,7 @@ repos: files: ^(python/.*|benchmarks/.*)$ exclude: ^python/nx-cugraph/ - repo: https://github.com/PyCQA/flake8 - rev: 6.0.0 + rev: 7.1.1 hooks: - id: flake8 args: ["--config=.flake8"] diff --git a/benchmarks/cugraph-dgl/python-script/ogbn_mag_benchmark.py b/benchmarks/cugraph-dgl/python-script/ogbn_mag_benchmark.py index 539fe333b1e..55ff0043e30 100644 --- a/benchmarks/cugraph-dgl/python-script/ogbn_mag_benchmark.py +++ b/benchmarks/cugraph-dgl/python-script/ogbn_mag_benchmark.py @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2023, NVIDIA CORPORATION. +# Copyright (c) 2022-2024, NVIDIA CORPORATION. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -126,4 +126,4 @@ def sampling_func(g, seed_nodes, labels, train_loader): st = time.time() sampling_func(g, subset_split_idx["train"], labels, train_loader) et = time.time() - print(f"Sampling time taken = {et-st} s") + print(f"Sampling time taken = {et - st} s") diff --git a/python/cugraph-dgl/cugraph_dgl/nn/conv/base.py b/python/cugraph-dgl/cugraph_dgl/nn/conv/base.py index d2460f814c9..fcd5a26aee6 100644 --- a/python/cugraph-dgl/cugraph_dgl/nn/conv/base.py +++ b/python/cugraph-dgl/cugraph_dgl/nn/conv/base.py @@ -129,7 +129,7 @@ def __init__( if csrc_ids is not None: if csrc_ids.numel() != self._num_src_nodes + 1: raise RuntimeError( - f"Size mismatch for 'csrc_ids': expected ({size[0]+1},), " + f"Size mismatch for 'csrc_ids': expected ({size[0] + 1},), " f"but got {tuple(csrc_ids.size())}" ) csrc_ids = csrc_ids.contiguous() @@ -137,7 +137,7 @@ def __init__( if cdst_ids is not None: if cdst_ids.numel() != self._num_dst_nodes + 1: raise RuntimeError( - f"Size mismatch for 'cdst_ids': expected ({size[1]+1},), " + f"Size mismatch for 'cdst_ids': expected ({size[1] + 1},), " f"but got {tuple(cdst_ids.size())}" ) cdst_ids = cdst_ids.contiguous() diff --git a/python/cugraph-dgl/examples/graphsage/node-classification-dask.py b/python/cugraph-dgl/examples/graphsage/node-classification-dask.py index 992669e4284..0481f9566bc 100644 --- a/python/cugraph-dgl/examples/graphsage/node-classification-dask.py +++ b/python/cugraph-dgl/examples/graphsage/node-classification-dask.py @@ -205,7 +205,9 @@ def train(args, device, g, dataset, model): et = time.time() - print(f"Time taken for epoch {epoch} with batch_size {batch_size} = {et-st} s") + print( + f"Time taken for epoch {epoch} with batch_size {batch_size} = {et - st} s" + ) acc = evaluate(model, g, val_dataloader) print( "Epoch {:05d} | Loss {:.4f} | Accuracy {:.4f} ".format( diff --git a/python/cugraph-dgl/examples/graphsage/node-classification.py b/python/cugraph-dgl/examples/graphsage/node-classification.py index 2b8b687efab..56ac41c09b4 100644 --- a/python/cugraph-dgl/examples/graphsage/node-classification.py +++ b/python/cugraph-dgl/examples/graphsage/node-classification.py @@ -215,7 +215,9 @@ def train(args, device, g, dataset, model, directory): et = time.time() - print(f"Time taken for epoch {epoch} with batch_size {batch_size} = {et-st} s") + print( + f"Time taken for epoch {epoch} with batch_size {batch_size} = {et - st} s" + ) acc = evaluate(model, g, val_dataloader) print( "Epoch {:05d} | Loss {:.4f} | Accuracy {:.4f} ".format( diff --git a/python/cugraph-dgl/examples/multi_trainer_MG_example/model.py b/python/cugraph-dgl/examples/multi_trainer_MG_example/model.py index d3aad2ab309..3e0c0454905 100644 --- a/python/cugraph-dgl/examples/multi_trainer_MG_example/model.py +++ b/python/cugraph-dgl/examples/multi_trainer_MG_example/model.py @@ -134,7 +134,7 @@ def train_model(model, g, opt, train_dataloader, num_epochs, rank, val_nid): et = time.time() print( f"Total time taken for num_epochs {num_epochs} " - f"with batch_size {train_dataloader._batch_size} = {et-st} s on rank ={rank}" + f"with batch_size {train_dataloader._batch_size} = {et - st} s on rank ={rank}" ) if rank == 0: val_acc = layerwise_infer(g, val_nid, model, 1024 * 5, "cuda") diff --git a/python/cugraph-dgl/examples/multi_trainer_MG_example/workflow_mnmg.py b/python/cugraph-dgl/examples/multi_trainer_MG_example/workflow_mnmg.py index b1878b37d4e..11afe466014 100644 --- a/python/cugraph-dgl/examples/multi_trainer_MG_example/workflow_mnmg.py +++ b/python/cugraph-dgl/examples/multi_trainer_MG_example/workflow_mnmg.py @@ -234,7 +234,7 @@ def run_workflow( torch.distributed.barrier() total_et = time.time() print( - f"Total time taken on n_epochs {n_epochs} = {total_et-total_st} s", + f"Total time taken on n_epochs {n_epochs} = {total_et - total_st} s", f"measured by worker = {global_rank}", ) diff --git a/python/cugraph-dgl/examples/multi_trainer_MG_example/workflow_snmg.py b/python/cugraph-dgl/examples/multi_trainer_MG_example/workflow_snmg.py index da5c2b4d64e..001d7fb82dc 100644 --- a/python/cugraph-dgl/examples/multi_trainer_MG_example/workflow_snmg.py +++ b/python/cugraph-dgl/examples/multi_trainer_MG_example/workflow_snmg.py @@ -207,7 +207,7 @@ def run_workflow(rank, world_size, cugraph_id, dataset, temp_dir): torch.distributed.barrier() total_et = time.time() print( - f"Total time taken on n_epochs {n_epochs} = {total_et-total_st} s", + f"Total time taken on n_epochs {n_epochs} = {total_et - total_st} s", f"measured by worker = {rank}", ) diff --git a/python/cugraph-pyg/cugraph_pyg/data/dask_graph_store.py b/python/cugraph-pyg/cugraph_pyg/data/dask_graph_store.py index c805cd496c8..6195f3118a4 100644 --- a/python/cugraph-pyg/cugraph_pyg/data/dask_graph_store.py +++ b/python/cugraph-pyg/cugraph_pyg/data/dask_graph_store.py @@ -150,7 +150,7 @@ def is_set(self, key): if key not in self.__dataclass_fields__: raise KeyError(key) attr = getattr(self, key) - return type(attr) != _field_status or attr != _field_status.UNSET + return type(attr) is not _field_status or attr != _field_status.UNSET def is_fully_specified(self): """ diff --git a/python/cugraph-pyg/cugraph_pyg/examples/gcn_dist_sg.py b/python/cugraph-pyg/cugraph_pyg/examples/gcn_dist_sg.py index b299fc2a1a1..09d874bd87d 100644 --- a/python/cugraph-pyg/cugraph_pyg/examples/gcn_dist_sg.py +++ b/python/cugraph-pyg/cugraph_pyg/examples/gcn_dist_sg.py @@ -66,7 +66,7 @@ def train(epoch: int): torch.cuda.synchronize() print( f"Average Training Iteration Time (s/iter): \ - {(time.perf_counter() - start_avg_time)/(i-warmup_steps):.6f}" + {(time.perf_counter() - start_avg_time) / (i - warmup_steps):.6f}" ) diff --git a/python/cugraph-service/tests/test_e2e.py b/python/cugraph-service/tests/test_e2e.py index c9b3d24f20e..3079a2423c7 100644 --- a/python/cugraph-service/tests/test_e2e.py +++ b/python/cugraph-service/tests/test_e2e.py @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2023, NVIDIA CORPORATION. +# Copyright (c) 2022-2024, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -307,8 +307,8 @@ def test_load_call_unload_extension(client, extension1): assert len(results) == 2 assert len(results[0]) == 33 assert len(results[1]) == 21 - assert type(results[0][0]) == int - assert type(results[1][0]) == float + assert type(results[0][0]) is int + assert type(results[1][0]) is float assert results[0][0] == 9 assert results[1][0] == 9.0 diff --git a/python/cugraph-service/tests/test_mg_e2e.py b/python/cugraph-service/tests/test_mg_e2e.py index 39c1195151d..5526593aee0 100644 --- a/python/cugraph-service/tests/test_mg_e2e.py +++ b/python/cugraph-service/tests/test_mg_e2e.py @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2023, NVIDIA CORPORATION. +# Copyright (c) 2022-2024, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -413,8 +413,8 @@ def test_call_extension_result_on_device( assert len(results) == 2 assert len(results[0]) == array1_len assert len(results[1]) == array2_len - assert type(results[0][0]) == int - assert type(results[1][0]) == float + assert type(results[0][0]) is int + assert type(results[1][0]) is float assert results[0][0] == 9 assert results[1][0] == 9.0 else: diff --git a/python/cugraph/cugraph/tests/generators/test_rmat.py b/python/cugraph/cugraph/tests/generators/test_rmat.py index 1cee0461686..87cbe636fdc 100644 --- a/python/cugraph/cugraph/tests/generators/test_rmat.py +++ b/python/cugraph/cugraph/tests/generators/test_rmat.py @@ -27,7 +27,9 @@ _scale_values = [2, 4, 16] _scale_test_ids = [f"scale={x}" for x in _scale_values] _graph_types = [cugraph.Graph, None, int] -_graph_test_ids = [f"create_using={getattr(x,'__name__',str(x))}" for x in _graph_types] +_graph_test_ids = [ + f"create_using={getattr(x, '__name__', str(x))}" for x in _graph_types +] _clip_and_flip = [False, True] _clip_and_flip_test_ids = [f"clip_and_flip={x}" for x in _clip_and_flip] _scramble_vertex_ids = [False, True] diff --git a/python/cugraph/cugraph/tests/generators/test_rmat_mg.py b/python/cugraph/cugraph/tests/generators/test_rmat_mg.py index 0e1808d2f80..44a6b3a2fc1 100644 --- a/python/cugraph/cugraph/tests/generators/test_rmat_mg.py +++ b/python/cugraph/cugraph/tests/generators/test_rmat_mg.py @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2023, NVIDIA CORPORATION. +# Copyright (c) 2021-2024, NVIDIA CORPORATION. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -34,7 +34,9 @@ _scale_values = [2, 4, 16] _scale_test_ids = [f"scale={x}" for x in _scale_values] _graph_types = [cugraph.Graph, None, int] -_graph_test_ids = [f"create_using={getattr(x,'__name__',str(x))}" for x in _graph_types] +_graph_test_ids = [ + f"create_using={getattr(x, '__name__', str(x))}" for x in _graph_types +] def _call_rmat(scale, num_edges, create_using, mg=True): diff --git a/python/cugraph/cugraph/tests/sampling/test_bulk_sampler.py b/python/cugraph/cugraph/tests/sampling/test_bulk_sampler.py index 65bcce78771..3c5d6428001 100644 --- a/python/cugraph/cugraph/tests/sampling/test_bulk_sampler.py +++ b/python/cugraph/cugraph/tests/sampling/test_bulk_sampler.py @@ -119,7 +119,7 @@ def test_bulk_sampler_remainder(scratch_dir): assert b in recovered_samples["batch_id"].values_host.tolist() for x in range(0, 6, 2): - subdir = f"{x}-{x+1}" + subdir = f"{x}-{x + 1}" df = cudf.read_parquet(os.path.join(samples_path, f"batch={subdir}.parquet")) assert ((df.batch_id == x) | (df.batch_id == (x + 1))).all() diff --git a/python/cugraph/cugraph/tests/structure/test_graph_mg.py b/python/cugraph/cugraph/tests/structure/test_graph_mg.py index cba61731e9a..f2cc1583f93 100644 --- a/python/cugraph/cugraph/tests/structure/test_graph_mg.py +++ b/python/cugraph/cugraph/tests/structure/test_graph_mg.py @@ -303,7 +303,7 @@ def test_mg_graph_serializable(dask_client, input_combo): G = input_combo["MGGraph"] dask_client.publish_dataset(shared_g=G) shared_g = dask_client.get_dataset("shared_g") - assert type(shared_g) == type(G) + assert type(shared_g) is type(G) assert G.number_of_vertices() == shared_g.number_of_vertices() assert G.number_of_edges() == shared_g.number_of_edges() # cleanup @@ -314,7 +314,7 @@ def test_mg_graph_serializable(dask_client, input_combo): def test_mg_graph_copy(): G = cugraph.MultiGraph(directed=True) G_c = copy.deepcopy(G) - assert type(G) == type(G_c) + assert type(G) is type(G_c) @pytest.mark.mg diff --git a/python/cugraph/cugraph/tests/traversal/test_sssp.py b/python/cugraph/cugraph/tests/traversal/test_sssp.py index 58288e022e8..ceb6040275d 100644 --- a/python/cugraph/cugraph/tests/traversal/test_sssp.py +++ b/python/cugraph/cugraph/tests/traversal/test_sssp.py @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2023, NVIDIA CORPORATION. +# Copyright (c) 2019-2024, NVIDIA CORPORATION. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -486,7 +486,7 @@ def test_scipy_api_compat(): distances = cugraph.shortest_path( input_coo_matrix, source=0, return_predecessors=False ) - assert type(distances) != tuple + assert type(distances) is not tuple with pytest.raises(ValueError): cugraph.shortest_path(input_coo_matrix, source=0, unweighted=False) diff --git a/python/cugraph/cugraph/traversal/sssp.py b/python/cugraph/cugraph/traversal/sssp.py index 5ab97e60390..bb98b5a9a29 100644 --- a/python/cugraph/cugraph/traversal/sssp.py +++ b/python/cugraph/cugraph/traversal/sssp.py @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2023, NVIDIA CORPORATION. +# Copyright (c) 2019-2024, NVIDIA CORPORATION. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -36,7 +36,7 @@ def _ensure_args( # checks common to all input types if (method is not None) and (method != "auto"): raise ValueError("only 'auto' is currently accepted for method") - if (indices is not None) and (type(indices) == list): + if (indices is not None) and (type(indices) is list): raise ValueError("indices currently cannot be a list-like type") if (indices is not None) and (source is not None): raise TypeError("cannot specify both 'source' and 'indices'") @@ -70,9 +70,11 @@ def _ensure_args( # Check for non-Graph-type inputs else: - if (directed is not None) and (type(directed) != bool): + if (directed is not None) and (type(directed) is not bool): raise ValueError("'directed' must be a bool") - if (return_predecessors is not None) and (type(return_predecessors) != bool): + if (return_predecessors is not None) and ( + type(return_predecessors) is not bool + ): raise ValueError("'return_predecessors' must be a bool") if (unweighted is not None) and (unweighted is not True): raise ValueError("'unweighted' currently must be True if " "specified") From 22c9e4f1180415a4aaf4343b128d5098c743bd62 Mon Sep 17 00:00:00 2001 From: Bradley Dice Date: Tue, 17 Sep 2024 12:17:00 -0500 Subject: [PATCH 2/2] Bump flake8 in yesqa hook. --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fafd6fd7b3a..8ff284210b7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -34,7 +34,7 @@ repos: hooks: - id: yesqa additional_dependencies: - - flake8==6.0.0 + - flake8==7.1.1 - repo: https://github.com/pre-commit/mirrors-clang-format rev: v16.0.6 hooks: