Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sample_points() error when sampling from a composite domain #29

Open
mikeonly opened this issue Jul 7, 2023 · 3 comments
Open

sample_points() error when sampling from a composite domain #29

mikeonly opened this issue Jul 7, 2023 · 3 comments

Comments

@mikeonly
Copy link

mikeonly commented Jul 7, 2023

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:

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()

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 of A from R.

Observed behavior:

sample_points() call runs sample_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 line torch.repeat_interleave(params, n, dim=0), which fails for params = 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?

@TomF98
Copy link
Contributor

TomF98 commented Jul 7, 2023

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.

@mikeonly
Copy link
Author

mikeonly commented Jul 8, 2023

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)

Full output

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)
<ipython-input-1-caf5c51d3521> in <cell line: 4>()
      2 get_ipython().system('pip install torchphysics')
      3 
----> 4 import torchphysics as tp
      5 
      6 X = tp.spaces.R2("x")

30 frames
/usr/local/lib/python3.10/dist-packages/torchphysics/__init__.py in <module>
      1 import sys
      2 from .problem import spaces
----> 3 from .problem import domains
      4 from .problem import samplers
      5 from .problem import conditions

/usr/local/lib/python3.10/dist-packages/torchphysics/problem/domains/__init__.py in <module>
     22 
     23 # 0D-domains:
---> 24 from .domain0D.point import Point
     25 # 1D-domains:
     26 from .domain1D.interval import Interval

/usr/local/lib/python3.10/dist-packages/torchphysics/problem/domains/domain0D/__init__.py in <module>
----> 1 from .point import Point

/usr/local/lib/python3.10/dist-packages/torchphysics/problem/domains/domain0D/point.py in <module>
      1 import torch
      2 
----> 3 from ..domain import Domain
      4 from ...spaces import Points
      5 

/usr/local/lib/python3.10/dist-packages/torchphysics/problem/domains/domain.py in <module>
      2 import torch
      3 
----> 4 from ...utils.user_fun import DomainUserFunction, UserFunction
      5 from ..spaces.points import Points
      6 

/usr/local/lib/python3.10/dist-packages/torchphysics/utils/__init__.py in <module>
     25 from .evaluation import compute_min_and_max
     26 
---> 27 from .callbacks import (WeightSaveCallback, PlotterCallback, TrainerStateCheckpoint)

/usr/local/lib/python3.10/dist-packages/torchphysics/utils/callbacks.py in <module>
      1 import torch
      2 
----> 3 from pytorch_lightning.callbacks import Callback
      4 
      5 from .plotting.plot_functions import plot

/usr/local/lib/python3.10/dist-packages/pytorch_lightning/__init__.py in <module>
     33 
     34 from lightning_fabric.utilities.seed import seed_everything  # noqa: E402
---> 35 from pytorch_lightning.callbacks import Callback  # noqa: E402
     36 from pytorch_lightning.core import LightningDataModule, LightningModule  # noqa: E402
     37 from pytorch_lightning.trainer import Trainer  # noqa: E402

/usr/local/lib/python3.10/dist-packages/pytorch_lightning/callbacks/__init__.py in <module>
     12 # See the License for the specific language governing permissions and
     13 # limitations under the License.
---> 14 from pytorch_lightning.callbacks.batch_size_finder import BatchSizeFinder
     15 from pytorch_lightning.callbacks.callback import Callback
     16 from pytorch_lightning.callbacks.checkpoint import Checkpoint

/usr/local/lib/python3.10/dist-packages/pytorch_lightning/callbacks/batch_size_finder.py in <module>
     22 
     23 import pytorch_lightning as pl
---> 24 from pytorch_lightning.callbacks.callback import Callback
     25 from pytorch_lightning.tuner.batch_size_scaling import scale_batch_size
     26 from pytorch_lightning.utilities.exceptions import _TunerExitException, MisconfigurationException

/usr/local/lib/python3.10/dist-packages/pytorch_lightning/callbacks/callback.py in <module>
     23 
     24 import pytorch_lightning as pl
---> 25 from pytorch_lightning.utilities.types import STEP_OUTPUT
     26 
     27 

/usr/local/lib/python3.10/dist-packages/pytorch_lightning/utilities/__init__.py in <module>
     21 from pytorch_lightning.utilities.enums import GradClipAlgorithmType  # noqa: F401
     22 from pytorch_lightning.utilities.grads import grad_norm  # noqa: F401
---> 23 from pytorch_lightning.utilities.imports import (  # noqa: F401
     24     _HIVEMIND_AVAILABLE,
     25     _OMEGACONF_AVAILABLE,

/usr/local/lib/python3.10/dist-packages/pytorch_lightning/utilities/imports.py in <module>
     26 _TORCH_GREATER_EQUAL_2_0 = compare_version("torch", operator.ge, "2.0.0")
     27 _TORCHMETRICS_GREATER_EQUAL_0_9_1 = RequirementCache("torchmetrics>=0.9.1")
---> 28 _TORCHMETRICS_GREATER_EQUAL_0_11 = compare_version("torchmetrics", operator.ge, "0.11.0")  # using new API with task
     29 
     30 _ONNX_AVAILABLE = package_available("onnx")

/usr/local/lib/python3.10/dist-packages/lightning_utilities/core/imports.py in compare_version(package, op, version, use_base_version)
     71     """
     72     try:
---> 73         pkg = importlib.import_module(package)
     74     except (ImportError, pkg_resources.DistributionNotFound):
     75         return False

/usr/lib/python3.10/importlib/__init__.py in import_module(name, package)
    124                 break
    125             level += 1
--> 126     return _bootstrap._gcd_import(name[level:], package, level)
    127 
    128 

/usr/local/lib/python3.10/dist-packages/torchmetrics/__init__.py in <module>
     12 _PROJECT_ROOT = os.path.dirname(_PACKAGE_ROOT)
     13 
---> 14 from torchmetrics import functional  # noqa: E402
     15 from torchmetrics.aggregation import (  # noqa: E402
     16     CatMetric,

/usr/local/lib/python3.10/dist-packages/torchmetrics/functional/__init__.py in <module>
     12 # See the License for the specific language governing permissions and
     13 # limitations under the License.
---> 14 from torchmetrics.functional.audio._deprecated import _permutation_invariant_training as permutation_invariant_training
     15 from torchmetrics.functional.audio._deprecated import _pit_permutate as pit_permutate
     16 from torchmetrics.functional.audio._deprecated import (

/usr/local/lib/python3.10/dist-packages/torchmetrics/functional/audio/__init__.py in <module>
     12 # See the License for the specific language governing permissions and
     13 # limitations under the License.
---> 14 from torchmetrics.functional.audio.pit import permutation_invariant_training, pit_permutate
     15 from torchmetrics.functional.audio.sdr import scale_invariant_signal_distortion_ratio, signal_distortion_ratio
     16 from torchmetrics.functional.audio.snr import (

/usr/local/lib/python3.10/dist-packages/torchmetrics/functional/audio/pit.py in <module>
     21 from typing_extensions import Literal
     22 
---> 23 from torchmetrics.utilities import rank_zero_warn
     24 from torchmetrics.utilities.imports import _SCIPY_AVAILABLE
     25 

/usr/local/lib/python3.10/dist-packages/torchmetrics/utilities/__init__.py in <module>
     12 # See the License for the specific language governing permissions and
     13 # limitations under the License.
---> 14 from torchmetrics.utilities.checks import check_forward_full_state_property
     15 from torchmetrics.utilities.data import apply_to_collection
     16 from torchmetrics.utilities.distributed import class_reduce, reduce

/usr/local/lib/python3.10/dist-packages/torchmetrics/utilities/checks.py in <module>
     23 from torch import Tensor
     24 
---> 25 from torchmetrics.metric import Metric
     26 from torchmetrics.utilities.data import select_topk, to_onehot
     27 from torchmetrics.utilities.enums import DataType

/usr/local/lib/python3.10/dist-packages/torchmetrics/metric.py in <module>
     28 from torch.nn import Module
     29 
---> 30 from torchmetrics.utilities.data import (
     31     _flatten,
     32     _squeeze_if_scalar,

/usr/local/lib/python3.10/dist-packages/torchmetrics/utilities/data.py in <module>
     20 
     21 from torchmetrics.utilities.exceptions import TorchMetricsUserWarning
---> 22 from torchmetrics.utilities.imports import _TORCH_GREATER_EQUAL_1_12, _XLA_AVAILABLE
     23 from torchmetrics.utilities.prints import rank_zero_warn
     24 

/usr/local/lib/python3.10/dist-packages/torchmetrics/utilities/imports.py in <module>
     46 _GAMMATONE_AVAILABEL: bool = package_available("gammatone")
     47 _TORCHAUDIO_AVAILABEL: bool = package_available("torchaudio")
---> 48 _TORCHAUDIO_GREATER_EQUAL_0_10: Optional[bool] = compare_version("torchaudio", operator.ge, "0.10.0")
     49 _SACREBLEU_AVAILABLE: bool = package_available("sacrebleu")
     50 _REGEX_AVAILABLE: bool = package_available("regex")

/usr/local/lib/python3.10/dist-packages/lightning_utilities/core/imports.py in compare_version(package, op, version, use_base_version)
     71     """
     72     try:
---> 73         pkg = importlib.import_module(package)
     74     except (ImportError, pkg_resources.DistributionNotFound):
     75         return False

/usr/lib/python3.10/importlib/__init__.py in import_module(name, package)
    124                 break
    125             level += 1
--> 126     return _bootstrap._gcd_import(name[level:], package, level)
    127 
    128 

/usr/local/lib/python3.10/dist-packages/torchaudio/__init__.py in <module>
----> 1 from torchaudio import (  # noqa: F401
      2     _extension,
      3     compliance,
      4     datasets,
      5     functional,

/usr/local/lib/python3.10/dist-packages/torchaudio/_extension/__init__.py in <module>
     41 _IS_KALDI_AVAILABLE = False
     42 if _IS_TORCHAUDIO_EXT_AVAILABLE:
---> 43     _load_lib("libtorchaudio")
     44 
     45     import torchaudio.lib._torchaudio  # noqa

/usr/local/lib/python3.10/dist-packages/torchaudio/_extension/utils.py in _load_lib(lib)
     59     if not path.exists():
     60         return False
---> 61     torch.ops.load_library(path)
     62     torch.classes.load_library(path)
     63     return True

/usr/local/lib/python3.10/dist-packages/torch/_ops.py in load_library(self, path)
    571             # static (global) initialization code in order to register custom
    572             # operators with the JIT.
--> 573             ctypes.CDLL(path)
    574         self.loaded_libraries.add(path)
    575 

/usr/lib/python3.10/ctypes/__init__.py in __init__(self, name, mode, handle, use_errno, use_last_error, winmode)
    372 
    373         if handle is None:
--> 374             self._handle = _dlopen(self._name, mode)
    375         else:
    376             self._handle = handle

OSError: /usr/local/lib/python3.10/dist-packages/torchaudio/lib/libtorchaudio.so: undefined symbol: _ZNK3c107SymBool10guard_boolEPKcl

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?

@TomF98
Copy link
Contributor

TomF98 commented Jul 8, 2023

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).

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

No branches or pull requests

2 participants