Skip to content

Commit

Permalink
Fix tests to avoid warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
joserapa98 committed May 9, 2024
1 parent 2f0221b commit 98634a4
Showing 1 changed file with 87 additions and 74 deletions.
161 changes: 87 additions & 74 deletions tests/models/test_mps.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,18 +649,19 @@ def test_all_algorithms_diff_in_dim_bond_dim(self):
def test_all_algorithms_marginalize(self):
for n_features in [1, 2, 3, 4, 10]:
for boundary in ['obc', 'pbc']:
example = torch.randn(1, n_features // 2, 5) # batch x n_features x feature_dim
data = torch.randn(100, n_features // 2, 5)

if example.numel() == 0:
example = None
data = None

in_features = torch.randint(low=0,
high=n_features,
size=(n_features // 2,)).tolist()
in_features = list(set(in_features))

# batch x n_features x feature_dim
example = torch.randn(1, len(in_features), 5)
data = torch.randn(100, len(in_features), 5)

if example.numel() == 0:
example = None
data = None

mps = tk.models.MPS(n_features=n_features,
phys_dim=5,
bond_dim=2,
Expand Down Expand Up @@ -715,18 +716,19 @@ def test_all_algorithms_marginalize(self):
def test_all_algorithms_marginalize_with_list_matrices(self):
for n_features in [1, 2, 3, 4, 10]:
for boundary in ['obc', 'pbc']:
example = torch.randn(1, n_features // 2, 5) # batch x n_features x feature_dim
data = torch.randn(100, n_features // 2, 5)

if example.numel() == 0:
example = None
data = None

in_features = torch.randint(low=0,
high=n_features,
size=(n_features // 2,)).tolist()
in_features = list(set(in_features))

# batch x n_features x feature_dim
example = torch.randn(1, len(in_features), 5)
data = torch.randn(100, len(in_features), 5)

if example.numel() == 0:
example = None
data = None

mps = tk.models.MPS(n_features=n_features,
phys_dim=5,
bond_dim=2,
Expand Down Expand Up @@ -786,17 +788,19 @@ def test_all_algorithms_marginalize_with_list_matrices(self):
def test_all_algorithms_marginalize_with_matrix(self):
for n_features in [1, 2, 3, 4, 10]:
for boundary in ['obc', 'pbc']:
example = torch.randn(1, n_features // 2, 5) # batch x n_features x feature_dim
data = torch.randn(100, n_features // 2, 5)
in_features = torch.randint(low=0,
high=n_features,
size=(n_features // 2,)).tolist()
in_features = list(set(in_features))

# batch x n_features x feature_dim
example = torch.randn(1, len(in_features), 5)
data = torch.randn(100, len(in_features), 5)

if example.numel() == 0:
example = None
data = None

in_features = torch.randint(low=0, high=n_features,
size=(n_features // 2,)).tolist()
in_features = list(set(in_features))

mps = tk.models.MPS(n_features=n_features,
phys_dim=5,
bond_dim=2,
Expand Down Expand Up @@ -856,18 +860,19 @@ def test_all_algorithms_marginalize_with_matrix_cuda(self):
device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')
for n_features in [1, 2, 3, 4, 10]:
for boundary in ['obc', 'pbc']:
in_features = torch.randint(low=0,
high=n_features,
size=(n_features // 2,)).tolist()
in_features = list(set(in_features))

# batch x n_features x feature_dim
example = torch.randn(1, n_features // 2, 5, device=device)
data = torch.randn(100, n_features // 2, 5, device=device)
example = torch.randn(1, len(in_features), 5, device=device)
data = torch.randn(100, len(in_features), 5, device=device)

if example.numel() == 0:
example = None
data = None

in_features = torch.randint(low=0, high=n_features,
size=(n_features // 2,)).tolist()
in_features = list(set(in_features))

mps = tk.models.MPS(n_features=n_features,
phys_dim=5,
bond_dim=2,
Expand Down Expand Up @@ -928,18 +933,19 @@ def test_all_algorithms_marginalize_with_mpo(self):
for n_features in [1, 2, 3, 4, 10]:
for mps_boundary in ['obc', 'pbc']:
for mpo_boundary in ['obc', 'pbc']:
in_features = torch.randint(low=0,
high=n_features,
size=(n_features // 2,)).tolist()
in_features = list(set(in_features))

# batch x n_features x feature_dim
example = torch.randn(1, n_features // 2, 5)
data = torch.randn(100, n_features // 2, 5)
example = torch.randn(1, len(in_features), 5)
data = torch.randn(100, len(in_features), 5)

if example.numel() == 0:
example = None
data = None

in_features = torch.randint(low=0, high=n_features,
size=(n_features // 2,)).tolist()
in_features = list(set(in_features))

mps = tk.models.MPS(n_features=n_features,
phys_dim=5,
bond_dim=2,
Expand Down Expand Up @@ -1011,17 +1017,18 @@ def test_all_algorithms_marginalize_with_mpo_cuda(self):
for n_features in [1, 2, 3, 4, 10]:
for mps_boundary in ['obc', 'pbc']:
for mpo_boundary in ['obc', 'pbc']:
# batch x n_features x feature_dim
example = torch.randn(1, n_features // 2, 5, device=device)
data = torch.randn(100, n_features // 2, 5, device=device)

if example.numel() == 0:
example = None
data = None

in_features = torch.randint(low=0, high=n_features,
size=(n_features // 2,)).tolist()
in_features = list(set(in_features))
in_features = torch.randint(low=0,
high=n_features,
size=(n_features // 2,)).tolist()
in_features = list(set(in_features))

# batch x n_features x feature_dim
example = torch.randn(1, len(in_features), 5, device=device)
data = torch.randn(100, len(in_features), 5, device=device)

if example.numel() == 0:
example = None
data = None

mps = tk.models.MPS(n_features=n_features,
phys_dim=5,
Expand Down Expand Up @@ -1099,18 +1106,19 @@ def test_all_algorithms_marginalize_with_mpo_cuda(self):
def test_all_algorithms_no_marginalize(self):
for n_features in [1, 2, 3, 4, 10]:
for boundary in ['obc', 'pbc']:
example = torch.randn(1, n_features // 2, 5) # batch x n_features x feature_dim
data = torch.randn(100, n_features // 2, 5)

if example.numel() == 0:
example = None
data = None

in_features = torch.randint(low=0,
high=n_features,
size=(n_features // 2,)).tolist()
in_features = list(set(in_features))

# batch x n_features x feature_dim
example = torch.randn(1, len(in_features), 5)
data = torch.randn(100, len(in_features), 5)

if example.numel() == 0:
example = None
data = None

mps = tk.models.MPS(n_features=n_features,
phys_dim=5,
bond_dim=2,
Expand Down Expand Up @@ -1163,17 +1171,19 @@ def test_all_algorithms_no_marginalize(self):

def test_norm(self):
for n_features in [1, 2, 3, 4, 10]:
for boundary in ['obc', 'pbc']:
example = torch.randn(1, n_features // 2, 5) # batch x n_features x feature_dim
if example.numel() == 0:
example = None

for boundary in ['obc', 'pbc']:
in_features = torch.randint(low=0,
high=n_features,
size=(n_features // 2,)).tolist()
in_features = list(set(in_features))
in_features.sort()

# batch x n_features x feature_dim
example = torch.randn(1, len(in_features), 5)

if example.numel() == 0:
example = None

mps = tk.models.MPS(n_features=n_features,
phys_dim=5,
bond_dim=2,
Expand Down Expand Up @@ -1790,18 +1800,19 @@ def test_all_algorithms(self):

def test_all_algorithms_marginalize(self):
for n_features in [1, 2, 3, 4, 10]:
example = torch.randn(1, n_features // 2, 5) # batch x n_features x feature_dim
data = torch.randn(100, n_features // 2, 5)

if example.numel() == 0:
example = None
data = None

in_features = torch.randint(low=0,
high=n_features,
size=(n_features // 2,)).tolist()
in_features = list(set(in_features))

# batch x n_features x feature_dim
example = torch.randn(1, len(in_features), 5)
data = torch.randn(100, len(in_features), 5)

if example.numel() == 0:
example = None
data = None

mps = tk.models.UMPS(n_features=n_features,
phys_dim=5,
bond_dim=2,
Expand Down Expand Up @@ -1845,18 +1856,19 @@ def test_all_algorithms_marginalize(self):

def test_all_algorithms_no_marginalize(self):
for n_features in [1, 2, 3, 4, 10]:
example = torch.randn(1, n_features // 2, 5) # batch x n_features x feature_dim
data = torch.randn(100, n_features // 2, 5)

if example.numel() == 0:
example = None
data = None

in_features = torch.randint(low=0,
high=n_features,
size=(n_features // 2,)).tolist()
in_features = list(set(in_features))

# batch x n_features x feature_dim
example = torch.randn(1, len(in_features), 5)
data = torch.randn(100, len(in_features), 5)

if example.numel() == 0:
example = None
data = None

mps = tk.models.UMPS(n_features=n_features,
phys_dim=5,
bond_dim=2,
Expand Down Expand Up @@ -1899,17 +1911,18 @@ def test_all_algorithms_no_marginalize(self):

def test_norm(self):
for n_features in [1, 2, 3, 4, 10]:
# batch x n_features x feature_dim
example = torch.randn(1, n_features // 2, 5)
if example.numel() == 0:
example = None

in_features = torch.randint(low=0,
high=n_features,
size=(n_features // 2,)).tolist()
in_features = list(set(in_features))
in_features.sort()

# batch x n_features x feature_dim
example = torch.randn(1, len(in_features), 5)

if example.numel() == 0:
example = None

mps = tk.models.UMPS(n_features=n_features,
phys_dim=5,
bond_dim=2,
Expand Down

0 comments on commit 98634a4

Please sign in to comment.