Skip to content
Open
Show file tree
Hide file tree
Changes from 11 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
84 changes: 84 additions & 0 deletions python/cugraph-pyg/cugraph_pyg/_doctor_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION.
# SPDX-License-Identifier: Apache-2.0

"""
Smoke check for `rapids doctor` (RAPIDS CLI).

See: https://github.com/rapidsai/rapids-cli#check-plugins
"""


def cugraph_pyg_smoke_check(**kwargs):
"""
A quick check to ensure cugraph-pyg can be imported and its core
submodules are loadable.
"""
try:
import cugraph_pyg

# Ensure core submodules load (touches pylibwholegraph, torch-geometric, etc.)
import cugraph_pyg.data
import cugraph_pyg.tensor

except ImportError as e:
raise ImportError(
"cugraph-pyg or its dependencies could not be imported. "
"Tip: install with `pip install cugraph-pyg` or use a RAPIDS conda environment."
) from e

if not hasattr(cugraph_pyg, "__version__") or not cugraph_pyg.__version__:
raise AssertionError(
"cugraph-pyg smoke check failed: __version__ not found or empty"
)

from cugraph_pyg.utils.imports import import_optional, MissingModule

torch = import_optional("torch")

if isinstance(torch, MissingModule) or not torch.cuda.is_available():
import warnings

warnings.warn(
"PyTorch with CUDA support is required to use cuGraph-PyG. "
"Please install PyTorch from PyPI or Conda-Forge."
)
else:
import os
from cugraph_pyg.data import GraphStore

addr = os.environ.get("MASTER_ADDR", "")
port = os.environ.get("MASTER_PORT", "")
local_rank = os.environ.get("LOCAL_RANK", "")
world_size = os.environ.get("WORLD_SIZE", "")
local_world_size = os.environ.get("LOCAL_WORLD_SIZE", "")
rank = os.environ.get("RANK", "")
Copy link
Contributor

Choose a reason for hiding this comment

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

Env-var restoration sets empty string instead of deleting

os.environ.get("KEY", "") returns "" for both "not set" and "set to empty string", so the saved value cannot distinguish between those two states. After the finally block, variables that were originally absent end up set to "" in the environment — which is semantically different from not existing, and could still interfere with downstream distributed code.

Use None as the sentinel:

        addr = os.environ.get("MASTER_ADDR")
        port = os.environ.get("MASTER_PORT")
        local_rank = os.environ.get("LOCAL_RANK")
        world_size = os.environ.get("WORLD_SIZE")
        local_world_size = os.environ.get("LOCAL_WORLD_SIZE")
        rank = os.environ.get("RANK")

Then restore with:

        for key, val in [
            ("MASTER_ADDR", addr), ("MASTER_PORT", port),
            ("LOCAL_RANK", local_rank), ("WORLD_SIZE", world_size),
            ("LOCAL_WORLD_SIZE", local_world_size), ("RANK", rank),
        ]:
            if val is None:
                os.environ.pop(key, None)
            else:
                os.environ[key] = val


try:
os.environ["MASTER_ADDR"] = "localhost"
os.environ["MASTER_PORT"] = "29505"
os.environ["LOCAL_RANK"] = "0"
os.environ["WORLD_SIZE"] = "1"
os.environ["LOCAL_WORLD_SIZE"] = "1"
os.environ["RANK"] = "0"
torch.distributed.init_process_group("nccl")

graph_store = GraphStore()
graph_store.put_edge_index(
torch.tensor([[0, 1], [1, 2]]),
("person", "knows", "person"),
"coo",
False,
(3, 3),
)
edge_index = graph_store.get_edge_index(
("person", "knows", "person"), "coo"
)
assert edge_index.shape == torch.Size([2, 2])
finally:
os.environ["MASTER_ADDR"] = addr
os.environ["MASTER_PORT"] = port
os.environ["LOCAL_RANK"] = local_rank
os.environ["WORLD_SIZE"] = world_size
os.environ["LOCAL_WORLD_SIZE"] = local_world_size
os.environ["RANK"] = rank
torch.distributed.destroy_process_group()
Copy link
Contributor

Choose a reason for hiding this comment

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

destroy_process_group called even if init_process_group failed

If torch.distributed.init_process_group("nccl") raises (e.g., NCCL not found, GPU not reachable), the finally block unconditionally calls torch.distributed.destroy_process_group(). PyTorch will raise RuntimeError: Default process group has not been initialized from inside the finally, which suppresses the original exception and makes diagnosis much harder.

Guard the destroy call:

        initialized = False
        try:
            torch.distributed.init_process_group("nccl")
            initialized = True
            # ... rest of the check ...
        finally:
            # restore env vars ...
            if initialized:
                torch.distributed.destroy_process_group()

3 changes: 3 additions & 0 deletions python/cugraph-pyg/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ dependencies = [
"torch-geometric>=2.5,<2.8",
] # This list was generated by `rapids-dependency-file-generator`. To make changes, edit ../../dependencies.yaml and run `rapids-dependency-file-generator`.

[project.entry-points."rapids_doctor_check"]
cugraph_pyg_smoke_check = "cugraph_pyg._doctor_check:cugraph_pyg_smoke_check"

[project.urls]
Homepage = "https://github.com/rapidsai/cugraph-gnn"
Documentation = "https://docs.rapids.ai/api/cugraph/stable/"
Expand Down
41 changes: 41 additions & 0 deletions python/pylibwholegraph/pylibwholegraph/_doctor_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION.
# SPDX-License-Identifier: Apache-2.0

"""
Smoke check for `rapids doctor` (RAPIDS CLI).

See: https://github.com/rapidsai/rapids-cli#check-plugins
"""


def pylibwholegraph_smoke_check(**kwargs):
"""
A quick check to ensure pylibwholegraph can be imported and the
native library loads correctly.
"""
try:
import pylibwholegraph
except ImportError as e:
raise ImportError(
"pylibwholegraph or its dependencies could not be imported. "
"Tip: install with `pip install pylibwholegraph` or use a RAPIDS conda environment."
) from e

if not hasattr(pylibwholegraph, "__version__") or not pylibwholegraph.__version__:
raise AssertionError(
"pylibwholegraph smoke check failed: __version__ not found or empty"
)

try:
import torch

assert torch.cuda.is_available()

except ImportError:
Copy link
Contributor

Choose a reason for hiding this comment

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

AssertionError not caught when CUDA is unavailable

When torch is installed but CUDA is not available, import torch succeeds, then assert torch.cuda.is_available() raises AssertionError. The except ImportError clause does not catch AssertionError, so the exception propagates unhandled to the caller — causing the check to hard-fail instead of emitting the intended warning.

Suggested change
try:
import torch
assert torch.cuda.is_available()
except ImportError:
try:
import torch
if not torch.cuda.is_available():
raise ImportError("torch.cuda is not available")
except (ImportError, AssertionError):

Or more directly: replace the assert with an explicit if/raise ImportError so the single except ImportError handles both the missing-package and no-CUDA cases.

import warnings

warnings.warn(
"PyTorch with CUDA or its dependencies could not be imported. "
"PyTorch is required to use pylibwholegraph. "
"Please install PyTorch from PyPI or Conda-Forge."
)
2 changes: 2 additions & 0 deletions python/pylibwholegraph/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ dependencies = [
"numpy>=1.23,<3.0",
] # This list was generated by `rapids-dependency-file-generator`. To make changes, edit ../../dependencies.yaml and run `rapids-dependency-file-generator`.

[project.entry-points."rapids_doctor_check"]
pylibwholegraph_smoke_check = "pylibwholegraph._doctor_check:pylibwholegraph_smoke_check"

[project.optional-dependencies]
test = [
Expand Down
Loading