Skip to content

Commit da4ab08

Browse files
Drop cudf.Series default-arg change; namespace move alone is enough
With the dataset/batch helpers no longer re-exported from cuopt.routing, importing the package never touches utils / utils_wrapper, so it is GPU-free without the None-sentinel change to generate_dataset. Revert utils.py and utils_wrapper.pyx to keep the diff focused on the namespace move, and drop the utils-imports-without-a-gpu test. The test that importing cuopt.routing does not require a GPU is kept. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Ramakrishna Prabhu <ramakrishnap@nvidia.com>
1 parent be958c1 commit da4ab08

3 files changed

Lines changed: 9 additions & 48 deletions

File tree

python/cuopt/cuopt/routing/utils.py

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SPDX-FileCopyrightText: Copyright (c) 2021-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
1+
# SPDX-FileCopyrightText: Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

44
import glob
@@ -17,10 +17,10 @@
1717
def generate_dataset(
1818
locations=100,
1919
asymmetric=True,
20-
min_demand=None,
21-
max_demand=None,
22-
min_capacities=None,
23-
max_capacities=None,
20+
min_demand=cudf.Series(),
21+
max_demand=cudf.Series(),
22+
min_capacities=cudf.Series(),
23+
max_capacities=cudf.Series(),
2424
min_service_time=0,
2525
max_service_time=0,
2626
tw_tightness=0.0,
@@ -114,18 +114,6 @@ def generate_dataset(
114114
Time windows and multi dimension
115115
capacity for each vehicle.
116116
"""
117-
# Default to empty device series here rather than in the signature:
118-
# a cudf.Series() default is constructed at import time and needs a GPU,
119-
# which would make importing this module fail on a GPU-less host.
120-
if min_demand is None:
121-
min_demand = cudf.Series()
122-
if max_demand is None:
123-
max_demand = cudf.Series()
124-
if min_capacities is None:
125-
min_capacities = cudf.Series()
126-
if max_capacities is None:
127-
max_capacities = cudf.Series()
128-
129117
if (
130118
min_demand.shape[0] != max_demand.shape[0]
131119
or max_demand.shape[0] != min_capacities.shape[0]

python/cuopt/cuopt/routing/utils_wrapper.pyx

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SPDX-FileCopyrightText: Copyright (c) 2021-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
1+
# SPDX-FileCopyrightText: Copyright (c) 2021-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. # noqa
22
# SPDX-License-Identifier: Apache-2.0
33

44

@@ -35,27 +35,15 @@ class DatasetDistribution(IntEnum):
3535
RANDOM_CLUSTERED = dataset_distribution_t.RANDOM_CLUSTERED
3636

3737

38-
def generate_dataset(locations=100, asymmetric=True, min_demand=None,
39-
max_demand=None, min_capacities=None,
40-
max_capacities=None, min_service_time=0,
38+
def generate_dataset(locations=100, asymmetric=True, min_demand=cudf.Series(),
39+
max_demand=cudf.Series(), min_capacities=cudf.Series(),
40+
max_capacities=cudf.Series(), min_service_time=0,
4141
max_service_time=0, tw_tightness=0.0,
4242
drop_return_trips=0.0, shifts=1,
4343
n_vehicle_types=1, n_matrix_types=1,
4444
distribution=DatasetDistribution.CLUSTERED,
4545
center_box=None, seed=0):
4646

47-
# Default to empty device series here rather than in the signature:
48-
# a cudf.Series() default is constructed at import time and needs a GPU,
49-
# which would make importing this module fail on a GPU-less host.
50-
if min_demand is None:
51-
min_demand = cudf.Series()
52-
if max_demand is None:
53-
max_demand = cudf.Series()
54-
if min_capacities is None:
55-
min_capacities = cudf.Series()
56-
if max_capacities is None:
57-
max_capacities = cudf.Series()
58-
5947
cdef unique_ptr[handle_t] handle_ptr
6048
handle_ptr.reset(new handle_t())
6149
handle_ = handle_ptr.get()

python/cuopt/cuopt/tests/routing/test_gpu_free_import.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,3 @@ def test_routing_imports_without_a_gpu():
3131
"dm = r.DataModel(3, 2)\n"
3232
"dm.add_cost_matrix(np.eye(3, dtype=np.float32))\n"
3333
)
34-
35-
36-
def test_routing_utils_imports_without_a_gpu():
37-
"""cuopt.routing.utils must import on a GPU-less host too.
38-
39-
Its helpers build empty cudf.Series objects; doing so in a default argument
40-
would run at import time and fail with cudaErrorNoDevice where no GPU is
41-
visible. This guards that the construction stays in the function bodies, so
42-
tests importing utils can be collected without a GPU.
43-
"""
44-
_run_without_gpu(
45-
"from cuopt.routing import utils\n"
46-
"assert callable(utils.generate_dataset)\n"
47-
"assert callable(utils.add_vehicle_constraints)\n"
48-
)

0 commit comments

Comments
 (0)