From 0fb36f1e4cf774688dd2208f1564b32252ddbe0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ne=C4=8Dada?= Date: Thu, 7 Mar 2019 05:09:44 +0000 Subject: [PATCH] Group generation made deterministic. Former-commit-id: ee2f92e71427c11348e8fad8c8cee2dfa16fd3d8 --- qpms/qpms_c.pyx | 2 +- qpms/symmetries.py | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/qpms/qpms_c.pyx b/qpms/qpms_c.pyx index 2e10b9f..1a1b7cd 100644 --- a/qpms/qpms_c.pyx +++ b/qpms/qpms_c.pyx @@ -1185,7 +1185,7 @@ cdef class FinitePointGroup: '''Constructs a FinitePointGroup from PointGroupInfo''' # TODO maybe I might use a try..finally statement to avoid leaks # First, generate all basic data from info - permlist = list(info.permgroup.elements) + permlist = info.deterministic_elemlist() cdef int order = len(permlist) permindices = {perm: i for i, perm in enumerate(permlist)} # 'invert' permlist identity = info.permgroup.identity diff --git a/qpms/symmetries.py b/qpms/symmetries.py index 62eecd8..67fbb6f 100644 --- a/qpms/symmetries.py +++ b/qpms/symmetries.py @@ -29,6 +29,15 @@ def grouprep_try(tdict, src, im, srcgens, imgens, immultop = None, imcmp = None) raise ValueError("Homomorphism inconsistency detected") return +def group_dps_try(elemlist, elem, gens): + '''Deterministic group depth-first search''' + elemlist.append(elem) + for i in range(len(gens)): + newelem = elem * gens[i] + if newelem not in elemlist: + group_dps_try(elemlist, newelem, gens) + return + class SVWFPointGroupInfo: # only for point groups, coz in svwf_rep() I use I_tyty, not I_ptypty or something alike def __init__(self, name, @@ -59,6 +68,11 @@ class SVWFPointGroupInfo: # only for point groups, coz in svwf_rep() I use I_tyt permgroupgens, rep3d_gens, immultop = None, imcmp = (lambda x, y: x.isclose(y)) ) + + def deterministic_elemlist(self): + thelist = list() + group_dps_try(thelist, self.permgroup.identity, self.permgroupgens) + return thelist def svwf_rep(self, lMax, *rep_gen_func_args, **rep_gen_func_kwargs): ''' @@ -85,7 +99,7 @@ class SVWFPointGroupInfo: # only for point groups, coz in svwf_rep() I use I_tyt Generates a string with a chunk of C code with a definition of a qpms_finite_group_t instance. See also groups.h. ''' - permlist = list(self.permgroup.elements) # all elements ordered + permlist = self.deterministic_elemlist() order = len(permlist) permindices = {perm: i for i, perm in enumerate(permlist)} # 'invert' permlist identity = self.permgroup.identity