Skip to content

alchemiops.py: Flag as unavailable on non-NVIDIA torch builds - #603

Open
yantar92 wants to merge 1 commit into
TorchSim:mainfrom
yantar92:fix/alchemiops-available-rocm
Open

alchemiops.py: Flag as unavailable on non-NVIDIA torch builds#603
yantar92 wants to merge 1 commit into
TorchSim:mainfrom
yantar92:fix/alchemiops-available-rocm

Conversation

@yantar92

@yantar92 yantar92 commented Aug 31, 2026

Copy link
Copy Markdown

Summary

On ROCm builds, nvalchemiops correctly imports but does not work during runtime, yielding

File "<...>/lib/python3.12/site-packages/torch_sim/neighbors/init.py", line 86, in torchsim_nl
return alchemiops_nl_n2(
^^^^^^^^^^^^^^^^^
File "<...>/lib/python3.12/site-packages/torch_sim/neighbors/alchemiops.py", line 62, in alchemiops_nl_n2
res = _batch_naive_neighbor_list(
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<...>/lib/python3.12/site-packages/nvalchemiops/torch/neighbors/batch_naive.py", line 1513, in batch_naive_neighbor_list
compute_naive_num_shifts(cell, cutoff, pbc)
File "<...>/lib/python3.12/site-packages/nvalchemiops/torch/neighbors/neighbor_utils.py", line 326, in compute_naive_num_shifts
wp_device = wp.device_from_torch(device)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<...>/lib/python3.12/site-packages/warp/_src/torch.py", line 39, in device_from_torch
return warp._src.context.runtime.cuda_devices[torch_device.index]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^
IndexError: list index out of range

Checklist

Before a pull request can be merged, the following items must be checked:

  • Doc strings have been added in the Google docstring format, but not in _import_nvalchemiops_batch_neighbors, which I did not touch.
  • Run ruff on your code. (no new failures)
  • Tests have been added for any new functionality or bug fixes.

@CompRhys

Copy link
Copy Markdown
Member

Thanks for the contribution, I totally understand the issue but I am not sure this is the right fix because on CPU achemiops should be the default so the check needs to check if there is a non-cuda accelerator not just if there is not a cuda accelerator.

* torch_sim/neighbors/alchemiops.py (_import_nvalchemiops_batch_neighbors):
Check that we are really using NVIDIA's drivers when checking if
nvalchemiops can be used with GPU.  For CPU-only, nvalchemiops should
work.
* tests/test_neighbors.py (test_alchemiops_import_guard_non_nvidia_builds):
New test.

On ROCm builds, nvalchemiops correctly imports but does not work
during runtime, yielding

  File "<...>/lib/python3.12/site-packages/torch_sim/neighbors/__init__.py", line 86, in torchsim_nl
    return alchemiops_nl_n2(
           ^^^^^^^^^^^^^^^^^
  File "<...>/lib/python3.12/site-packages/torch_sim/neighbors/alchemiops.py", line 62, in alchemiops_nl_n2
    res = _batch_naive_neighbor_list(
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<...>/lib/python3.12/site-packages/nvalchemiops/torch/neighbors/batch_naive.py", line 1513, in batch_naive_neighbor_list
    compute_naive_num_shifts(cell, cutoff, pbc)
  File "<...>/lib/python3.12/site-packages/nvalchemiops/torch/neighbors/neighbor_utils.py", line 326, in compute_naive_num_shifts
    wp_device = wp.device_from_torch(device)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<...>/lib/python3.12/site-packages/warp/_src/torch.py", line 39, in device_from_torch
    return warp._src.context.runtime.cuda_devices[torch_device.index]
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^
IndexError: list index out of range
@yantar92
yantar92 force-pushed the fix/alchemiops-available-rocm branch from 157e3cc to 6d81a4b Compare August 31, 2026 09:57
@yantar92

Copy link
Copy Markdown
Author

Oops. Did not realize that alchemiops works on CPUs. I have updated the commit.

@lil-lon

lil-lon commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Btw, if you want to detect ROCm, you can use torch.version.hip variable.

@yantar92

Copy link
Copy Markdown
Author

Btw, if you want to detect ROCm, you can use torch.version.hip variable.

I have considered it, but AFAIU alchemiops will fail on any GPU that is not CUDA.

@CompRhys

CompRhys commented Sep 1, 2026

Copy link
Copy Markdown
Member

I think that perhaps it's hard to do in logic for everyone's preferences so perhaps set 'TS_USE_ALCHEMIOPS=false' and skip on that is most direct approach and easy to document. If not set default to true.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants