def anderson(hop=-1., dist='uniform', loc=0., scale=1., shape=(10, ), bcond='p'): """Define 1-band simple-cubic tight binding system with site-diagonal disorder and constant isotropic next-neighbor hopping, using a continuous probability distribution. Return supercell object (instance of :class:`tb.sc.SuperCell`) and parameter set (instance of :class:`bundle.Bundle`).""" # created 2013-07-07, modified 2013-07-12 # former tb._anderson (developed 2011-09-15 - 2012-11-28) # former tb._Anderson from 2011-03-29 # former anderson.py from 21/01/2010-03/09/2010 dim = len(shape) scell = sc.SuperCell(dim=dim) dist = sc.dist.select(dist) scell.add_scnn(pot=dist(loc, scale), hop=hop, bcond=bcond, shape=shape) pset = bundle.Bundle(dist=dist, dim=dim, loc=loc, scale=scale, shape=shape, hop=hop, pot=loc) return scell, pset
def andisp(hop=-1., dist='uniform', loc=0., scale=1., shape=(10, ), bcond='p', coup=1., mix=.1, mom=1.): """Define Anderson-Ising model with polarized impurity spins (spin-up).""" # created 2013-07-12, modified 2014-01-27 # former tb._andis (developed 2012-09-10 - 2012-11-19) # former tb._Andis (developed 2012-06-15 - 2012-06-19) mix = misc.get_ratio(mix) dim = len(shape) scell = sc.SuperCell(dim=dim) dist = sc.dist.select(dist) scell.add_andisp(pot=dist(loc, scale), hop=hop, bcond=bcond, shape=shape, coup=coup, mix=mix, mom=mom) pset = bundle.Bundle(dist=dist, dim=dim, loc=loc, scale=scale, shape=shape, mix=mix, coup=coup, mom=mom, hop=hop, pot=loc) return scell, pset
def decode(message): bytes = list(message) bytes = map(ord, bytes) version = bytes[0] if (version != VERSION): raise Exception("Version mismatch, decoding failed") len = 1 #there's probably a smarter way to do this #my python-fu is weak (flags, block_length, len) = __decode_assist(len,bytes) (dest_sch_offset, dest_ssp_off, len) = __decode_assist(len,bytes) (source_sch_offset, source_ssp_off, len) = __decode_assist( len,bytes) (reply_sch_offset, reply_ssp_off, len) = __decode_assist( len,bytes) (cust_sch_offset, cust_ssp_off, len) = __decode_assist( len,bytes) (creation_ts, creation_ts_sq_no, len) = __decode_assist( len,bytes) (lifetime, dict_len, len) = __decode_assist(len,bytes) #should test if fragment, then see a fragment offset. #Skipping as we say no fragments at this point #build the bundle b = bundle.Bundle() b.creation_secs = creation_ts b.creation_seqno = creation_ts_sq_no b.expiration = lifetime b.dest = __get_decoded_address(bytes[len:], dest_sch_offset, dest_ssp_off) b.source = __get_decoded_address(bytes[len:], source_sch_offset, source_ssp_off) b.replyto = __get_decoded_address(bytes[len:], reply_sch_offset, reply_ssp_off) b.custodian = __get_decoded_address(bytes[len:], cust_sch_offset, cust_ssp_off) for flag in (BUNDLE_IS_FRAGMENT, BUNDLE_IS_ADMIN, BUNDLE_DO_NOT_FRAGMENT, BUNDLE_CUSTODY_XFER_REQUESTED, BUNDLE_SINGLETON_DESTINATION, BUNDLE_ACK_BY_APP, BUNDLE_UNUSED): b.bundle_flags += (flags & flag) for flag in (STATUS_RECEIVED, STATUS_CUSTODY_ACCEPTED, STATUS_FORWARDED, STATUS_DELIVERED, STATUS_DELETED, STATUS_ACKED_BY_APP, STATUS_UNUSED2): b.srr_flags += (flags & flag) b.priority = flags & (COS_BULK | COS_NORMAL | COS_EXPEDITED) #ok, primary bundle done. Onto bundle block! len += dict_len block_type = bytes[len] #we'll ignore the flags for now... (block_proc_cntl_flags, block_len, len) = __decode_assist(len+1, bytes) return (b, block_len, array_into_string(bytes[len:]))
def convert_to_bundle(json_file: pathlib.PosixPath) -> bundle.Bundle: """Loads content of file to create Bundle object. Args: json_file: Set containing JSON files that need to be read Returns: Bundle object """ with open(json_file) as f: data = json.loads(f.read()) return bundle.Bundle(json_file, data)
def decode(message): bytes = list(message) bytes = map(ord, bytes) version = bytes[0] if (version != VERSION): raise Exception("Version mismatch, decoding failed") i = 1 #there's probably a smarter way to do this #my python-fu is weak (flags, block_length, i) = __decode_assist(i, bytes) (dest_sch_offset, dest_ssp_off, i) = __decode_assist(i, bytes) (source_sch_offset, source_ssp_off, i) = __decode_assist(i, bytes) (reply_sch_offset, reply_ssp_off, i) = __decode_assist(i, bytes) (cust_sch_offset, cust_ssp_off, i) = __decode_assist(i, bytes) (creation_ts, creation_ts_sq_no, i) = __decode_assist(i, bytes) (lifetime, dict_len, i) = __decode_assist(i, bytes) #should test if fragment, then see a fragment offset. #Skipping as we say no fragments at this point #build the bundle b = bundle.Bundle() b.creation_secs = creation_ts b.creation_seqno = creation_ts_sq_no b.expiration = lifetime (b.dest, b.source, b.replyto, b.custodian) = decode_eids( bytes[i:i + dict_len], ((dest_sch_offset, dest_ssp_off), (source_sch_offset, source_ssp_off), (reply_sch_offset, reply_ssp_off), (cust_sch_offset, cust_ssp_off))) for flag in (BUNDLE_IS_FRAGMENT, BUNDLE_IS_ADMIN, BUNDLE_DO_NOT_FRAGMENT, BUNDLE_CUSTODY_XFER_REQUESTED, BUNDLE_SINGLETON_DESTINATION, BUNDLE_ACK_BY_APP, BUNDLE_UNUSED): b.bundle_flags += (flags & flag) for flag in (STATUS_RECEIVED, STATUS_CUSTODY_ACCEPTED, STATUS_FORWARDED, STATUS_DELIVERED, STATUS_DELETED, STATUS_ACKED_BY_APP, STATUS_UNUSED2): b.srr_flags += (flags & flag) b.priority = flags & (COS_BULK | COS_NORMAL | COS_EXPEDITED) # Skip the dictionary i += dict_len #ok, primary bundle done. Decode other blocks. b.blocks = decode_blocks(bytes[i:]) # Return if b.blocks.has_key(PAYLOAD_BLOCK): return (b, len(b.blocks[PAYLOAD_BLOCK][0]["payload"]), b.blocks[PAYLOAD_BLOCK][0]["payload"]) else: return (b, 0, "")
def spheres(mix=.1, range=1., coup=1., mom=1., shell=1, bcond='p', shape=(10, ), sconc=None, iconc=None, iconcin=None, iconcout=None, space=.1, rad=1., timeout='30s'): """Define dilute Heisenberg model with sphere-like inhomogeneities.""" # created 2013-07-12, modified 2013-07-18 # former tb._Spheres (developed 2012-03-14 - 2012-09-06) # former tb._Heis (developed 2012-03-14 - 2012-09-06) dim = len(shape) scell = sc.SuperCell(dim=dim) scell.add_spheres(range=range, coup=coup, mom=mom, bcond=bcond, shape=shape, shell=shell, sconc=sconc, iconc=iconc, iconcin=iconcin, space=space, iconcout=iconcout, rad=rad, timeout=timeout) pset = bundle.Bundle(dim=dim, range=range, coup=coup, mom=mom, bcond=bcond, shape=shape, shell=shell, sconc=sconc, iconc=iconc, iconcin=iconcin, space=space, iconcout=iconcout, rad=rad, timeout=timeout) return scell, pset
def __init__(self, x=[], y=[], dtype=None, attrs={}): """Initialize the continuous function object.""" # 2012-06-27 - 2012-06-28 # store data, force numpy arrays self.x = scipy.array(x, dtype=dtype).flatten() self.y = scipy.array(y, dtype=dtype).flatten() # check dimensions if len(self.x.shape) != 1 or len(self.y.shape) != 1 \ or self.x.shape[0] != self.y.shape[0]: raise ValueError('bad data shape') # sort data self.sort() # initialize attribute structure self.attrs = bundle.Bundle(**attrs)
def __init__(self): self._options = {} #Add menu classes self._optionLookup = {} #Add/order your menu option here self._options = [ addSubproject.AddSubproject(), bundle.Bundle(), bundle.Unbundle(), branches.Branches(), status.Status(), stash.Stash(), checkout.Checkout(), push.Push(), pull.Pull(), commit.Commit(), publish.Publish(), clone.Clone(), config.Config(), grapeConfig.WriteConfig(), foreach.ForEach(), merge.Merge(), mergeDevelop.MergeDevelop(), mergeRemote.MergeRemote(), deleteBranch.DeleteBranch(), newWorkingTree.NewWorkingTree(), resolveConflicts.ResolveConflicts(), review.Review(), test.Test(), updateLocal.UpdateLocal(), updateSubproject.UpdateSubproject(), hooks.InstallHooks(), hooks.RunHook(), updateView.UpdateView(), version.Version(), walkthrough.Walkthrough(), quit.Quit() ] #Add/order the menu sections here self._sections = [ 'Getting Started', 'Code Reviews', 'Workspace', 'Merge', 'Gitflow Tasks', 'Hooks', 'Patches', 'Project Management', 'Other' ]
def pack_dir(base_dir): rootfs = pack_fs(base_dir + '/root', '/', -1, False) + pack_fs( base_dir + '/cwd', '', -1, False) exe = os.readlink(base_dir + '/exe') data = [] for i in os.listdir(base_dir): if i.count('-') == 3: data.append(tuple(map(int, i.split('-'))) + (i, )) assert len(set(i[0] for i in data)) == len(data) data.sort() tests = [] for _, tl, ml, fszlim, dir in data: fs = pack_fs(base_dir + '/' + dir + '/root', '/', fszlim, not tests) + pack_fs( base_dir + '/' + dir + '/cwd', '', fszlim, not tests) input_txt = os.readlink(base_dir + '/' + dir + '/input') output_txt = os.readlink(base_dir + '/' + dir + '/output') tests.append(bundle.Test(tl, ml, input_txt, output_txt, fs)) return bundle.Bundle(rootfs, exe, tests)
def heis(mix=.1, range=1., coup=1., mom=1., shell=1, bcond='p', shape=(10, )): """Define homogeneous dilute Heisenberg model.""" # created 2013-07-12, modified 2013-07-18 # former tb._Heis (developed 2012-03-14 - 2012-09-06) mix = misc.get_ratio(mix) dim = len(shape) scell = sc.SuperCell(dim=dim) scell.add_heis(range=range, coup=coup, mix=mix, mom=mom, bcond=bcond, shape=shape, shell=shell) pset = bundle.Bundle(dim=dim, shape=shape, mix=mix, coup=coup, mom=mom, shell=shell, range=range) return scell, pset
def get_window(self, first, n): assert len(self.tracks) == len(self.xs) assert len(self.Rs) == len(self.ts) # Get a vector of measurements for this track + window track_ids = [] window = [] window_pts = [] for track,pt in zip(self.tracks, self.xs): msm_vec = -np.ones((n, 2)) observed = 0 for cam_id,msm in zip(track.camera_ids, track.measurements): if cam_id >= first and cam_id < first+n: msm_vec[ cam_id-first ] = msm observed += 1 if observed >= 2: window.append(msm_vec) window_pts.append(pt) # TODO: deal with missing data # Count observations per camera window = np.asarray(window) obs_mask = np.all(window != (-1,-1), axis=2) obs_per_cam = obs_mask.sum(axis=0) # Check for cameras with too few observations deg_cams = np.nonzero(obs_per_cam < 3)[0] assert len(deg_cams) == 0, 'Some cameras had too few observations: '+str(obs_per_cam) # Construct a bundle instance b = bundle.Bundle(n, len(window)) b.K = self.K b.msm = np.transpose(window, (1,0,2)) # swap first two dimensions b.Rs = [ self.Rs[i] for i in range(first, first+n) ] b.ts = [ self.ts[i] for i in range(first, first+n) ] b.pts = window_pts return b
def andheis(hop=-1., dist='uniform', loc=0., scale=1., shape=(10, ), bcond='p', coup=1., mix=.1, mom=1.): """Define Anderson-Heisenberg model with isotropic random impurity spins (conforming to the SU(2) group).""" # created 2013-07-12, modified 2014-01-27 # former tb._andheisi (developed 2013-06-27 - 2013-06-27) # based on tb._andheis (2012-09-10 - 2012-12-17) # based on tb._andis from 2012-09-10 mix = misc.get_ratio(mix) dim = len(shape) scell = sc.SuperCell(dim=dim) dist = sc.dist.select(dist) scell.add_andheis(pot=dist(loc, scale), hop=hop, bcond=bcond, shape=shape, coup=coup, mix=mix, mom=mom) pset = bundle.Bundle(dist=dist, dim=dim, loc=loc, scale=scale, shape=shape, mix=mix, coup=coup, mom=mom, hop=hop, pot=loc) return scell, pset
def setUp(self): super().setUp() content = test_util.read_file('bundle') self.each_bundle = bundle.Bundle('anything', content)