TuringQ / deepquantum

DeepQuantum for quantum computing
https://deepquantum.turingq.com/
Apache License 2.0
31 stars 7 forks source link

UserWarning for `torch.repeat_interleave` #24

Closed Hugh-888 closed 1 month ago

Hugh-888 commented 1 month ago

Problem

UserWarning for torch.repeat_interleave

Code:

def test_(ts, idx):
    return torch.repeat_interleave(ts, idx)
a = torch.tensor([0,4,6,9])
b1 = torch.tensor([0,2,1,1])
b2 = torch.tensor([0,1,2,1])
torch.vmap(test_, in_dims=(None, 0))(a, torch.stack([b1, b2]))

image

Possible solution

sansiro77 commented 1 month ago

warnings.filterwarnings('ignore')是global的,用下面代码实现local的效果

import warnings

def my_function():
    with warnings.catch_warnings():
        warnings.filterwarnings('ignore')
        # Your code here
        # The 'ignore' filter only applies within this context

# Outside the function, the original warning settings are still in effect