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

Feature/ot singlet compatibility [MEDIUM] #144

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/gpt/core/coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def mat_backward(dst, src):

def coordinate_mask(field, mask):
assert isinstance(mask, numpy.ndarray)
assert field.otype.data_otype() == gpt.ot_singlet
assert field.otype.is_singlet

x = gpt.coordinates(field)
field[x] = mask.astype(field.grid.precision.complex_dtype).reshape((len(mask), 1))
Expand Down
4 changes: 2 additions & 2 deletions lib/gpt/core/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def __mul__(self, l):
if uf & gpt.factor_unary.BIT_CONJ != 0:
lhs = lhs.conj()
res = gpt.tensor(np.tensordot(lhs, l.array, axes=mt[1]), mt[0]())
if res.otype == gpt.ot_singlet:
if res.otype.is_singlet:
res = complex(res.array)
return res
assert 0
Expand Down Expand Up @@ -247,7 +247,7 @@ def get_otype_from_expression(e):
bare_otype = None
for coef, term in e.val:
if len(term) == 0:
t_otype = gpt.ot_singlet
t_otype = gpt.ot_singlet()
else:
t_otype = None
t_adj = False
Expand Down
4 changes: 2 additions & 2 deletions lib/gpt/core/lattice.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ def __itruediv__(self, expr):
return self

def __lt__(self, other):
assert self.otype.data_otype() == gpt.ot_singlet
assert other.otype.data_otype() == gpt.ot_singlet
assert self.otype.is_singlet
assert other.otype.is_singlet
res = gpt.lattice(self)
params = {"operator": "<"}
cgpt.binary(res.v_obj[0], self.v_obj[0], other.v_obj[0], params)
Expand Down
2 changes: 1 addition & 1 deletion lib/gpt/core/object_type/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def gpt_object(first, ot):
###
# Container objects without (lie) group structure
def singlet(grid):
return gpt_object(grid, ot_singlet)
return gpt_object(grid, ot_singlet())


def matrix_color(grid, ndim):
Expand Down
1 change: 1 addition & 0 deletions lib/gpt/core/object_type/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class ot_base:

# list of object types to which I can convert and converter function
ctab = {}
is_singlet = False

# safe cast of data_alias
def data_otype(self):
Expand Down
10 changes: 5 additions & 5 deletions lib/gpt/core/object_type/complex_additive_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ class ot_complex_additive_group(ot_singlet):

def __init__(self):
self.__name__ = "ot_complex_additive_group"
self.data_alias = lambda: ot_singlet
self.data_alias = lambda: ot_singlet()
self.rmtab = {
"ot_singlet": (lambda: ot_singlet, None),
"ot_singlet": (lambda: ot_singlet(), None),
}
self.mtab = {
self.__name__: (lambda: self, None),
"ot_singlet": (lambda: ot_singlet, None),
"ot_singlet": (lambda: ot_singlet(), None),
}

# this is always multiplicative identity, not neutral element of group
Expand Down Expand Up @@ -87,7 +87,7 @@ def __init__(self, n):
}
self.otab = {self.__name__: (lambda: ot_matrix_complex_additive_group(n), [])}
self.itab = {
self.__name__: (lambda: ot_singlet, (0, 0)),
self.__name__: (lambda: ot_singlet(), (0, 0)),
}
self.cache = {}

Expand Down Expand Up @@ -119,7 +119,7 @@ def coordinates(self, l, c=None):
assert l.otype.__name__ == self.__name__
if c is None:
r = [None] * self.shape[0] * 2
a = gpt.separate_indices(l, (0, lambda: ot_singlet), self.cache)
a = gpt.separate_indices(l, (0, lambda: ot_singlet()), self.cache)
for i in a:
r[i[0]] = gpt.component.real(a[i])
r[i[0] + self.shape[0]] = gpt.component.imag(a[i])
Expand Down
23 changes: 12 additions & 11 deletions lib/gpt/core/object_type/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,14 @@ class ot_singlet(ot_base):
colortrace = (None, None, None)
v_otype = ["ot_singlet"]
mtab = {
"ot_singlet": (lambda: ot_singlet, None),
"ot_singlet": (lambda: ot_singlet(), None),
}
is_singlet = True

def data_otype(self=None):
return ot_singlet
def data_otype(self):
return ot_singlet()

def identity():
def identity(self):
return 1.0


Expand All @@ -84,7 +85,7 @@ def __init__(self, ndim):
self.shape = (ndim, ndim)
self.transposed = (1, 0)
self.spintrace = (None, None, None) # do nothing
self.colortrace = (0, 1, lambda: ot_singlet)
self.colortrace = (0, 1, lambda: ot_singlet())
self.v_otype = ["ot_mcolor%d" % ndim] # cgpt data types
self.mtab = {
self.__name__: (lambda: self, (1, 0)),
Expand Down Expand Up @@ -115,7 +116,7 @@ def __init__(self, ndim):
}
self.otab = {self.__name__: (lambda: ot_matrix_color(ndim), [])}
self.itab = {
self.__name__: (lambda: ot_singlet, (0, 0)),
self.__name__: (lambda: ot_singlet(), (0, 0)),
}

def compose(self, a, b):
Expand All @@ -133,7 +134,7 @@ def __init__(self, ndim):
self.nfloats = 2 * ndim * ndim
self.shape = (ndim, ndim)
self.transposed = (1, 0)
self.spintrace = (0, 1, lambda: ot_singlet)
self.spintrace = (0, 1, lambda: ot_singlet())
self.colortrace = (None, None, None) # do nothing
self.v_otype = ["ot_mspin%d" % ndim]
self.mtab = {
Expand Down Expand Up @@ -197,7 +198,7 @@ def __init__(self, ndim):
"ot_singlet": (lambda: self, None),
}
self.otab = {self.__name__: (lambda: ot_matrix_spin(ndim), [])}
self.itab = {self.__name__: (lambda: ot_singlet, (0, 0))}
self.itab = {self.__name__: (lambda: ot_singlet(), (0, 0))}

def compose(self, a, b):
return a + b
Expand Down Expand Up @@ -269,7 +270,7 @@ def __init__(self, spin_ndim, color_ndim):
),
}
self.itab = {
self.__name__: (lambda: ot_singlet, ([0, 1], [0, 1])),
self.__name__: (lambda: ot_singlet(), ([0, 1], [0, 1])),
}
self.mtab = {
"ot_singlet": (lambda: self, None),
Expand Down Expand Up @@ -346,7 +347,7 @@ def __init__(self, n):
"ot_singlet": (lambda: self, None),
}
self.itab = {
self.__name__: (lambda: ot_singlet, (0, 0)),
self.__name__: (lambda: ot_singlet(), (0, 0)),
}


Expand All @@ -367,7 +368,7 @@ def __init__(self, n):
self.shape = (n, n)
self.transposed = (1, 0)
self.spintrace = (None, None, None)
self.colortrace = (0, 1, lambda: ot_singlet)
self.colortrace = (0, 1, lambda: ot_singlet())
self.vector_type = ot_vector_singlet(n)
self.mtab = {
self.__name__: (lambda: self, (1, 0)),
Expand Down
10 changes: 5 additions & 5 deletions lib/gpt/core/object_type/real_additive_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ class ot_real_additive_group(ot_singlet):

def __init__(self):
self.__name__ = "ot_real_additive_group"
self.data_alias = lambda: ot_singlet
self.data_alias = lambda: ot_singlet()
self.rmtab = {
"ot_singlet": (lambda: ot_singlet, None),
"ot_singlet": (lambda: ot_singlet(), None),
}
self.mtab = {
self.__name__: (lambda: self, None),
"ot_singlet": (lambda: ot_singlet, None),
"ot_singlet": (lambda: ot_singlet(), None),
}

# this is always multiplicative identity, not neutral element of group
Expand Down Expand Up @@ -87,7 +87,7 @@ def __init__(self, n):
}
self.otab = {self.__name__: (lambda: ot_matrix_real_additive_group(n), [])}
self.itab = {
self.__name__: (lambda: ot_singlet, (0, 0)),
self.__name__: (lambda: ot_singlet(), (0, 0)),
}
self.cache = {}

Expand All @@ -114,7 +114,7 @@ def coordinates(self, l, c=None):
assert l.otype.__name__ == self.__name__
if c is None:
r = [None] * self.shape[0]
a = gpt.separate_indices(l, (0, lambda: ot_singlet), self.cache)
a = gpt.separate_indices(l, (0, lambda: ot_singlet()), self.cache)
for i in a:
r[i[0]] = a[i]
return r
Expand Down
6 changes: 3 additions & 3 deletions lib/gpt/core/object_type/u_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ def identity(self):

def __init__(self, name):
self.__name__ = name
self.data_alias = lambda: ot_singlet
self.data_alias = lambda: ot_singlet()
self.rmtab = {
"ot_singlet": (lambda: ot_singlet, None),
"ot_singlet": (lambda: ot_singlet(), None),
}
self.mtab = {
self.__name__: (lambda: self, None),
"ot_singlet": (lambda: ot_singlet, None),
"ot_singlet": (lambda: ot_singlet(), None),
}


Expand Down
4 changes: 2 additions & 2 deletions lib/gpt/core/tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def adj(self):
return tensor(np.transpose(self.array.conj(), self.otype.transposed), self.otype)

def reduced(self):
if self.otype.data_otype() == gpt.ot_singlet:
if self.otype.is_singlet:
return complex(self.array)
return self

Expand All @@ -92,7 +92,7 @@ def trace(self, t):
if ct[0] is not None:
res = tensor(np.trace(res.array, offset=0, axis1=ct[0], axis2=ct[1]), ct[2]())

if res.otype == gpt.ot_singlet:
if res.otype.is_singlet:
res = complex(res.array)
return res

Expand Down
2 changes: 1 addition & 1 deletion lib/gpt/core/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def to_num(x):

# tensor
def value_to_tensor(val, otype):
if otype.data_otype() == gpt.ot_singlet:
if otype.is_singlet:
# this is not ideal, can we do a subclass of complex that preserves otype info?
return complex(val)
return gpt.tensor(val, otype)
Expand Down
2 changes: 1 addition & 1 deletion lib/gpt/create/sparse_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def coordinates(src, position, spacing):


def zn(src, position, spacing, rng, n):
singlet = gpt.lattice(src.grid, gpt.ot_singlet)
singlet = gpt.lattice(src.grid, gpt.ot_singlet())
singlet.checkerboard(src.checkerboard())
pos = coordinates(src, position, spacing)
singlet_full = gpt.lattice(singlet)
Expand Down
2 changes: 1 addition & 1 deletion lib/gpt/ml/layer/nearest_neighbor.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@


class nearest_neighbor(cshift):
def __init__(self, grid, ot_input=g.ot_singlet, ot_weights=g.ot_singlet, activation=sigmoid):
def __init__(self, grid, ot_input=g.ot_singlet(), ot_weights=g.ot_singlet(), activation=sigmoid):
nd = grid.nd
super().__init__(
grid,
Expand Down
Loading