Skip to content

Commit

Permalink
two more simple tests for the matrix action and the resampler
Browse files Browse the repository at this point in the history
  • Loading branch information
gray95 committed Oct 17, 2024
1 parent f85606d commit 0d20b21
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
7 changes: 7 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import os
import sys
PROJECT_PATH = os.getcwd()
SOURCE_PATH = os.path.join(
PROJECT_PATH,"src"
)
sys.path.append(SOURCE_PATH)
25 changes: 25 additions & 0 deletions tests/test_matrix_action.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from action.matrix_action import MatrixAction
from torch import zeros, rand
import torch
### Test 1: set fields to zero should return zero action (wit non-zero coeffs)
### Test 2: set coeffs to zero should return zero action (with non-zero fields)

def test_scalar_matrix_zero_field():
action_dict = dict(beta=1)
# generate zero-valued fields
cfgs = zeros(100,10,10) # 0 axis is the batch axis ie number of cfgs
result = MatrixAction(**action_dict)
S = result.action(cfgs)
for i in range(100):
assert S[i] == 0

def test_scalar_matrix_zero_beta():
action_dict = dict(beta=0)
# generate zero-valued fields
cfgs = rand(100,10,10) # 0 axis is the batch axis ie number of cfgs
result = MatrixAction(**action_dict)
S = result.action(cfgs)
for i in range(100):
assert S[i] == 0


14 changes: 14 additions & 0 deletions tests/test_resampler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

from numpy import ones, mean
from random import randint

from lib.stats.resampler import Resampler

# all this does is check that if you resample from a set of identical numbers the mean and std of the sample and resample will be exactly equal.

def test_resampler():
resampler = Resampler()
sample = randint(1,100)*ones((30))
sample_mean = mean(sample)
resample_mean, resample_std = resampler.eval(sample)
assert (sample_mean == resample_mean) & (resample_std == 0)
3 changes: 2 additions & 1 deletion tests/test_scalarphi4action.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from normflow.action import ScalarPhi4Action
from torch import zeros, rand
from action.scalar_action import ScalarPhi4Action
#from ..action.scalar_action import ScalarPhi4Action

### Test 1: set fields to zero should return zero action (wit non-zero coeffs)
### Test 2: set coeffs to zero should return zero action (with non-zero fields)
Expand Down

0 comments on commit 0d20b21

Please sign in to comment.