Open mikeonly opened 1 year ago
Hey, thanks for using TorchPhysics and your detailed problem description. Sampling in these kinds of domains is supported. Strangely, your code runs on my machine without any problems.
How did you install TorchPhysics? With pip install torchphysics
or directly from GitHub? Another possible problem could be some mismatch in PyTorch versions.
With pip install torchphysics
it should work. Which you can check, for example, on Google Colab by running the following (one has to install the library first, which takes around 2-3 minutes):
!pip install torchaudio==0.13.0
!pip install torchphysics
import torchphysics as tp
X = tp.spaces.R2("x")
R = tp.domains.Parallelogram(X, [0, 0], [3, 0], [0, 3])
A = tp.domains.Parallelogram(X, [1, 1], [2, 1], [2, 2])
O = R - A
sampler = tp.samplers.RandomUniformSampler(O, n_points=100)
pts = sampler.sample_points()
print(pts)
And if you run this cell:
sampler = tp.samplers.RandomUniformSampler(O, n_points=2000)
fig = tp.utils.scatter(X, sampler)
The sampling appears to work correctly.
Thanks for the fast reply. It can be indeed due to a mismatch of PyTorch versions.
My PyTorch version is 2.0.1, and I installed torchphysics from GitHub with pip install .
. I see now that it when I try with pip install torchphysics
, there is a requirement for pytorch<2.0.0
. However, I do not see this requirement here in setup.cfg
in the main branch.
It works in the colab as you've suggested, with the following crucial ouput:
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
torchdata 0.6.1 requires torch==2.0.1, but you have torch 1.13.0 which is incompatible.
torchtext 0.15.2 requires torch==2.0.1, but you have torch 1.13.0 which is incompatible.
torchvision 0.15.2+cu118 requires torch==2.0.1, but you have torch 1.13.0 which is incompatible.
Successfully installed torch-1.13.0 torchaudio-0.13.0
Why do you specify torchaudio==0.13.0
? It is not a direct dependency for torchphysics
, and it indeed pulls down an older version of torch, 1.13.1. Now, when I try it without fixing a torch version (and also specifying torch, not torchaudio),
!pip install torch
!pip install torchphysics
it also hits that requirement torch<2.0.0,>=1.7.1 (from torchphysics)
and fails even in colab with a cryptic dependency issue, what is seems. Running
!pip install torch
!pip install torchphysics
import torchphysics as tp
X = tp.spaces.R2("x")
R = tp.domains.Parallelogram(X, [0, 0], [3, 0], [0, 3])
A = tp.domains.Parallelogram(X, [1, 1], [2, 1], [2, 2])
O = R - A
sampler = tp.samplers.RandomUniformSampler(O, n_points=100)
pts = sampler.sample_points()
print(pts)
in colab gives this full output (make sure that colab doesn't have older version torch preinstalled from your previous commands, i.e. have a clean runtime)
```
Requirement already satisfied: torch in /usr/local/lib/python3.10/dist-packages (2.0.1+cu118)
Requirement already satisfied: filelock in /usr/local/lib/python3.10/dist-packages (from torch) (3.12.2)
Requirement already satisfied: typing-extensions in /usr/local/lib/python3.10/dist-packages (from torch) (4.6.3)
Requirement already satisfied: sympy in /usr/local/lib/python3.10/dist-packages (from torch) (1.11.1)
Requirement already satisfied: networkx in /usr/local/lib/python3.10/dist-packages (from torch) (3.1)
Requirement already satisfied: jinja2 in /usr/local/lib/python3.10/dist-packages (from torch) (3.1.2)
Requirement already satisfied: triton==2.0.0 in /usr/local/lib/python3.10/dist-packages (from torch) (2.0.0)
Requirement already satisfied: cmake in /usr/local/lib/python3.10/dist-packages (from triton==2.0.0->torch) (3.25.2)
Requirement already satisfied: lit in /usr/local/lib/python3.10/dist-packages (from triton==2.0.0->torch) (16.0.6)
Requirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib/python3.10/dist-packages (from jinja2->torch) (2.1.3)
Requirement already satisfied: mpmath>=0.19 in /usr/local/lib/python3.10/dist-packages (from sympy->torch) (1.3.0)
Collecting torchphysics
Downloading torchphysics-1.0.0-py2.py3-none-any.whl (124 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 124.2/124.2 kB 8.5 MB/s eta 0:00:00
Collecting torch<2.0.0,>=1.7.1 (from torchphysics)
Downloading torch-1.13.1-cp310-cp310-manylinux1_x86_64.whl (887.5 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 887.5/887.5 MB 1.8 MB/s eta 0:00:00
Collecting pytorch-lightning<2.0.0,>=1.3.4 (from torchphysics)
Downloading pytorch_lightning-1.9.5-py3-none-any.whl (829 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 829.5/829.5 kB 59.1 MB/s eta 0:00:00
Requirement already satisfied: numpy>=1.20.2 in /usr/local/lib/python3.10/dist-packages (from torchphysics) (1.22.4)
Requirement already satisfied: matplotlib>=3.0.0 in /usr/local/lib/python3.10/dist-packages (from torchphysics) (3.7.1)
Requirement already satisfied: scipy>=1.6.3 in /usr/local/lib/python3.10/dist-packages (from torchphysics) (1.10.1)
Requirement already satisfied: contourpy>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib>=3.0.0->torchphysics) (1.1.0)
Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.10/dist-packages (from matplotlib>=3.0.0->torchphysics) (0.11.0)
Requirement already satisfied: fonttools>=4.22.0 in /usr/local/lib/python3.10/dist-packages (from matplotlib>=3.0.0->torchphysics) (4.40.0)
Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib>=3.0.0->torchphysics) (1.4.4)
Requirement already satisfied: packaging>=20.0 in /usr/local/lib/python3.10/dist-packages (from matplotlib>=3.0.0->torchphysics) (23.1)
Requirement already satisfied: pillow>=6.2.0 in /usr/local/lib/python3.10/dist-packages (from matplotlib>=3.0.0->torchphysics) (8.4.0)
Requirement already satisfied: pyparsing>=2.3.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib>=3.0.0->torchphysics) (3.1.0)
Requirement already satisfied: python-dateutil>=2.7 in /usr/local/lib/python3.10/dist-packages (from matplotlib>=3.0.0->torchphysics) (2.8.2)
Requirement already satisfied: tqdm>=4.57.0 in /usr/local/lib/python3.10/dist-packages (from pytorch-lightning<2.0.0,>=1.3.4->torchphysics) (4.65.0)
Requirement already satisfied: PyYAML>=5.4 in /usr/local/lib/python3.10/dist-packages (from pytorch-lightning<2.0.0,>=1.3.4->torchphysics) (6.0)
Requirement already satisfied: fsspec[http]>2021.06.0 in /usr/local/lib/python3.10/dist-packages (from pytorch-lightning<2.0.0,>=1.3.4->torchphysics) (2023.6.0)
Collecting torchmetrics>=0.7.0 (from pytorch-lightning<2.0.0,>=1.3.4->torchphysics)
Downloading torchmetrics-1.0.0-py3-none-any.whl (728 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 728.8/728.8 kB 59.5 MB/s eta 0:00:00
Requirement already satisfied: typing-extensions>=4.0.0 in /usr/local/lib/python3.10/dist-packages (from pytorch-lightning<2.0.0,>=1.3.4->torchphysics) (4.6.3)
Collecting lightning-utilities>=0.6.0.post0 (from pytorch-lightning<2.0.0,>=1.3.4->torchphysics)
Downloading lightning_utilities-0.9.0-py3-none-any.whl (23 kB)
Collecting nvidia-cuda-runtime-cu11==11.7.99 (from torch<2.0.0,>=1.7.1->torchphysics)
Downloading nvidia_cuda_runtime_cu11-11.7.99-py3-none-manylinux1_x86_64.whl (849 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 849.3/849.3 kB 58.3 MB/s eta 0:00:00
Collecting nvidia-cudnn-cu11==8.5.0.96 (from torch<2.0.0,>=1.7.1->torchphysics)
Downloading nvidia_cudnn_cu11-8.5.0.96-2-py3-none-manylinux1_x86_64.whl (557.1 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 557.1/557.1 MB 2.9 MB/s eta 0:00:00
Collecting nvidia-cublas-cu11==11.10.3.66 (from torch<2.0.0,>=1.7.1->torchphysics)
Downloading nvidia_cublas_cu11-11.10.3.66-py3-none-manylinux1_x86_64.whl (317.1 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 317.1/317.1 MB 2.6 MB/s eta 0:00:00
Collecting nvidia-cuda-nvrtc-cu11==11.7.99 (from torch<2.0.0,>=1.7.1->torchphysics)
Downloading nvidia_cuda_nvrtc_cu11-11.7.99-2-py3-none-manylinux1_x86_64.whl (21.0 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 21.0/21.0 MB 73.6 MB/s eta 0:00:00
Requirement already satisfied: setuptools in /usr/local/lib/python3.10/dist-packages (from nvidia-cublas-cu11==11.10.3.66->torch<2.0.0,>=1.7.1->torchphysics) (67.7.2)
Requirement already satisfied: wheel in /usr/local/lib/python3.10/dist-packages (from nvidia-cublas-cu11==11.10.3.66->torch<2.0.0,>=1.7.1->torchphysics) (0.40.0)
Requirement already satisfied: requests in /usr/local/lib/python3.10/dist-packages (from fsspec[http]>2021.06.0->pytorch-lightning<2.0.0,>=1.3.4->torchphysics) (2.27.1)
Requirement already satisfied: aiohttp!=4.0.0a0,!=4.0.0a1 in /usr/local/lib/python3.10/dist-packages (from fsspec[http]>2021.06.0->pytorch-lightning<2.0.0,>=1.3.4->torchphysics) (3.8.4)
Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.10/dist-packages (from python-dateutil>=2.7->matplotlib>=3.0.0->torchphysics) (1.16.0)
Requirement already satisfied: attrs>=17.3.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp!=4.0.0a0,!=4.0.0a1->fsspec[http]>2021.06.0->pytorch-lightning<2.0.0,>=1.3.4->torchphysics) (23.1.0)
Requirement already satisfied: charset-normalizer<4.0,>=2.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp!=4.0.0a0,!=4.0.0a1->fsspec[http]>2021.06.0->pytorch-lightning<2.0.0,>=1.3.4->torchphysics) (2.0.12)
Requirement already satisfied: multidict<7.0,>=4.5 in /usr/local/lib/python3.10/dist-packages (from aiohttp!=4.0.0a0,!=4.0.0a1->fsspec[http]>2021.06.0->pytorch-lightning<2.0.0,>=1.3.4->torchphysics) (6.0.4)
Requirement already satisfied: async-timeout<5.0,>=4.0.0a3 in /usr/local/lib/python3.10/dist-packages (from aiohttp!=4.0.0a0,!=4.0.0a1->fsspec[http]>2021.06.0->pytorch-lightning<2.0.0,>=1.3.4->torchphysics) (4.0.2)
Requirement already satisfied: yarl<2.0,>=1.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp!=4.0.0a0,!=4.0.0a1->fsspec[http]>2021.06.0->pytorch-lightning<2.0.0,>=1.3.4->torchphysics) (1.9.2)
Requirement already satisfied: frozenlist>=1.1.1 in /usr/local/lib/python3.10/dist-packages (from aiohttp!=4.0.0a0,!=4.0.0a1->fsspec[http]>2021.06.0->pytorch-lightning<2.0.0,>=1.3.4->torchphysics) (1.3.3)
Requirement already satisfied: aiosignal>=1.1.2 in /usr/local/lib/python3.10/dist-packages (from aiohttp!=4.0.0a0,!=4.0.0a1->fsspec[http]>2021.06.0->pytorch-lightning<2.0.0,>=1.3.4->torchphysics) (1.3.1)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests->fsspec[http]>2021.06.0->pytorch-lightning<2.0.0,>=1.3.4->torchphysics) (1.26.16)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/dist-packages (from requests->fsspec[http]>2021.06.0->pytorch-lightning<2.0.0,>=1.3.4->torchphysics) (2023.5.7)
Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests->fsspec[http]>2021.06.0->pytorch-lightning<2.0.0,>=1.3.4->torchphysics) (3.4)
Installing collected packages: nvidia-cuda-runtime-cu11, nvidia-cuda-nvrtc-cu11, nvidia-cublas-cu11, lightning-utilities, nvidia-cudnn-cu11, torch, torchmetrics, pytorch-lightning, torchphysics
Attempting uninstall: torch
Found existing installation: torch 2.0.1+cu118
Uninstalling torch-2.0.1+cu118:
Successfully uninstalled torch-2.0.1+cu118
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
torchaudio 2.0.2+cu118 requires torch==2.0.1, but you have torch 1.13.1 which is incompatible.
torchdata 0.6.1 requires torch==2.0.1, but you have torch 1.13.1 which is incompatible.
torchtext 0.15.2 requires torch==2.0.1, but you have torch 1.13.1 which is incompatible.
torchvision 0.15.2+cu118 requires torch==2.0.1, but you have torch 1.13.1 which is incompatible.
Successfully installed lightning-utilities-0.9.0 nvidia-cublas-cu11-11.10.3.66 nvidia-cuda-nvrtc-cu11-11.7.99 nvidia-cuda-runtime-cu11-11.7.99 nvidia-cudnn-cu11-8.5.0.96 pytorch-lightning-1.9.5 torch-1.13.1 torchmetrics-1.0.0 torchphysics-1.0.0
/usr/local/lib/python3.10/dist-packages/torchvision/io/image.py:13: UserWarning: Failed to load image Python extension: '/usr/local/lib/python3.10/dist-packages/torchvision/image.so: undefined symbol: _ZN3c104cuda20CUDACachingAllocator9allocatorE'If you don't plan on using image functionality from `torchvision.io`, you can ignore this warning. Otherwise, there might be something wrong with your environment. Did you have `libjpeg` or `libpng` installed before building `torchvision` from source?
warn(
---------------------------------------------------------------------------
OSError Traceback (most recent call last)
I prefer to use the latest torch, at least because I rely on torchvision transformations. Perhaps it would help me to understand what exactly _repeat_params
does in that context, so that I can figure out if it can be done in the newer version of torch?
We are mainly developing the library in our fork of TorchPhysics, so the version on the boschresearch page is not always up-to-date. Since we don't have access to merge the code here. I'm sorry for this inconvenience. Because of this, the setup.cfg
is missing some information and is still from before PyTorch version 2.0 existed.
Regarding Google Colab: By default, the newest version of PyTorch and the subpackages are installed. But TorchPhysics may not yet be (or rather is not) compatible with the version >=2.0.0 (both of PyTorch and PyTroch-Lightning). Generally, pip install TorchPhysics
will install the correct PyTorch version, but not update the subpackages. This is why you get the warning/error on Google Colab (but since we don't use the packages, this does not matter). But one has to downgrade torchaudio
manually, or else one gets the second error because some variables/parameters change internally.
I am not sure if _repeat_params
is the only thing that breaks in newer versions (something like the way we transpose tensors may also not work anymore). The method _repeat_params
only does something in the case of moving domains (e.g. time-dependent boundaries). In your case, it should always return just 1 and something breaks mostlikely in the empty point creation.
I think updating TorchPhysics to run with versions 2.0.0 and newer will take some effort and time. We may focus on this in the next weeks, but until then, I recommend sticking with PyTorch version < 2.0 (if possible).
Thanks for the nice library! I was writing a similar code to solve my inverse problem with PINNs when I stumbled upon your project, and decided to try using it, since it has nice sampling, domain creation, and conditions logic. However, I encounter a problem in a simple situation when I try to obtain points from a 2d domain which is a
CutDomain
:This gives the assertion error in
__torch_function__
:assert len(spaces) > 0
, asserted here.Expected behavior:
Have 100 points from domain
O
, which is a subtraction ofA
fromR
.Observed behavior:
sample_points()
call runssample_domain_uniform()
and inside_random_points_inside()
when there should be a check of what points belong to the region, there is a eventually a linetorch.repeat_interleave(params, n, dim=0)
, which fails forparams = Points.empty()
I would try to fix this issue myself, but I cannot understand the point of the function
_repeat_params
, and of the assertion. Perhaps you can help clarifying the issue of what the code tries to check and why? Then I'd be able to write up a working version of the code for the case of 2d regions.Also, I stumbled somewhere that it might be not supported to sample from domains like that? Is that so?