def unixTime(): """Return the current time in seconds with high precision (unix version, use Manager.time() to stay platform independent).""" warnings.warn( "'pg.time' will be removed from the library in the first release following January, 2022. Use time.perf_counter instead", DeprecationWarning, stacklevel=2) return system_time()
def unixTime(): """Return the current time in seconds with high precision (unix version, use Manager.time() to stay platform independent).""" return system_time()
""" import sys if sys.version_info[0] < 3: from time import clock from time import time as system_time else: from time import perf_counter as clock from time import time as system_time START_TIME = None time = None def winTime(): """Return the current time in seconds with high precision (windows version, use Manager.time() to stay platform independent).""" return clock() - START_TIME #return systime.time() def unixTime(): """Return the current time in seconds with high precision (unix version, use Manager.time() to stay platform independent).""" return system_time() if sys.platform.startswith('win'): cstart = clock() ### Required to start the clock in windows START_TIME = system_time() - cstart time = winTime else: time = unixTime
#!/usr/bin/env python3 import os, sys, scipy import numpy as np from time import time as system_time from dicke_methods import coherent_spin_state from correlator_methods import compute_deriv_vals, dec_mat_drive, \ mat_zxy_to_pzm, vec_zxy_to_pzm start_time = system_time() if len(sys.argv[1:]) not in [3, 4]: print(f"usage: {sys.argv[0]} method lattice_depth lattice_size [rational]") exit() method = sys.argv[1] lattice_depth = sys.argv[2] lattice_size = int(sys.argv[3]) rational_correlators = (len(sys.argv[1:]) == 4) TAT, TNT = "TAT", "TNT" assert (method in [TAT, TNT]) data_dir = os.path.dirname(os.path.realpath(__file__)) + "/../data/" output_dir = data_dir + "trunc/" file_name = "_".join(sys.argv[1:]) + ".txt" lattice_dim = 2 confining_depth = 60 # recoil energies
def time(): return system_time()
def add_log(self, msg, user=None): self.projectlog_set.create(details=msg, user=user, timestamp=system_time())
def now(self): return int(system_time())
def process_result(self, result): self.logger.debug('trying result processing') mm = result[0] r = result[1] id = "" try: id = r['id'] except KeyError: id = (r['conid'],r['orderid']) self.logger.debug("had to recreate the id: %s", id) try: # get the orders and get them out of the pending list curmm, mmlist, paramap, waitinglist = self.pending_orders.pop(id) except KeyError: # order has been canceled self.logger.debug("Dropping connector %r order %r result" % id) return if r['error'] != 0: self.logger.debug('The result included an error') for o in waitinglist + [paramap]: if len(o["mmlist"]) > 0: if not self.aggregate_order(o): self.queue_order(o) else: o['error'] = r['error'] o['errortext'] = r['errortext'] if issubclass(type(o), InternalOrder): message = Message(None,None,'ERROR',None,None) self.put_in_mmmcq(self.plugins[o['moduleid']].msgq, o['moduleid'], message) self.logger.info("queue_message into msgq %s", self.plugins[o['moduleid']].msgq) elif issubclass(type(o), RemoteOrder): receiver = Node(o['senderip'], o['senderid']) sender = Node(o['receiverip'], o['receiverid']) o['errorcode'] = -1 msgtype = 'ERROR' payload = o outmsg = Message(sender,receiver,msgtype,payload) # queues response in dispatcher queue ev = Event("MESSAGE_OUT",outmsg) self.eventq.put(ev) else: self.replyq.put(Event('DELIVER', o)) if o['finished']: self.replyq.put(Event('FINISHED', o)) try: waitinglist.remove(o) except ValueError: pass else: self.logger.debug('Everything\'s fine, delivering results now') # cache results try: self.cache.store(copy.copy(r)) except KeyError: # result had no timestamp, must be from remote # create a current timestamp, should be accurate enough r['time'] = system_time() self.cache.store(copy.copy(r)) # deliver results for o in waitinglist + [paramap]: if o.istriggermatch(r[o.dataitem]): if issubclass(type(o), InternalOrder): message = Message(None,None,'RESULT',None,r) self.put_in_mmmcq(self.plugins[o['moduleid']].msgq, o['moduleid'], message) self.logger.info("queue_message into msgq %s", self.plugins[o['moduleid']].msgq) elif issubclass(type(o), RemoteOrder): self.logger.debug("It's the result for a remote order") receiver = Node(o['senderip'], o['senderid']) sender = Node(o['receiverip'], o['receiverid']) self.logger.debug("sender: %s", sender.ip) self.logger.debug("receiver: %s", receiver.ip) msgtype = 'RESULT' payload = self.fill_order(o, r) payload['error'] = r['error'] payload['errortext'] = r['errortext'] payload['time'] = r['time'] self.logger.debug("payload %s", o) outmsg = Message(sender,receiver,msgtype,payload,r[o['dataitem']]) # queues response in dispatcher queue ev = Event("MESSAGE_OUT",outmsg) self.eventq.put(ev) else: self.replyq.put(Event('DELIVER', self.fill_order(o, r))) if o['finished']: self.replyq.put(Event('FINISHED', o))
def log_progress(sequence, every=None, size=None, name='Items'): # https://github.com/kuk/log-progress from ipywidgets import IntProgress, HTML, VBox from IPython.display import display is_iterator = False if size is None: try: size = len(sequence) except TypeError: is_iterator = True if size is not None: if every is None: if size <= 200: every = 1 else: every = int(size / 200) # every 0.5% else: assert every is not None, 'sequence is iterator, set every' if is_iterator: progress = IntProgress(min=0, max=1, value=1) progress.bar_style = 'info' else: progress = IntProgress(min=0, max=size, value=0) label = HTML() box = VBox(children=[label, progress]) display(box) index = 0 full_init_time = system_time() elapsed_time = system_time() try: for index, record in enumerate(sequence, 1): if index == 1 or index % every == 0: if is_iterator: label.value = '{name}: {index} / ?'.format(name=name, index=index) else: time_per_case = (elapsed_time - full_init_time) / index rem_time = time_per_case * (size - index + 1) hours = floor(rem_time / 3600.0) minutes = floor((rem_time - hours * 3600.0) / 60.0) seconds = floor(rem_time - minutes * 60.0 - hours * 3600) rem_time = "{hours}:{minutes:02}:{seconds:02}".format( hours=hours, minutes=minutes, seconds=seconds) ela_time = elapsed_time - full_init_time hours = floor(ela_time / 3600.0) minutes = floor((ela_time - hours * 3600.0) / 60.0) seconds = floor(ela_time - minutes * 60.0 - hours * 3600) ela_time = "{hours}:{minutes:02}:{seconds:02}".format( hours=hours, minutes=minutes, seconds=seconds) progress.value = index label.value = u'{name}: {index} / {size} - Ela: {ela_time}\nRem: {rem_time}'.format( name=name, index=index, size=size, ela_time=ela_time, rem_time=rem_time) yield record elapsed_time = system_time() except: progress.bar_style = 'danger' raise else: ela_time = system_time() - full_init_time hours = floor(ela_time / 3600.0) minutes = floor((ela_time - hours * 3600.0) / 60.0) seconds = floor(ela_time - minutes * 60.0 - hours * 3600) ela_time = "{hours}:{minutes:02}:{seconds:02}".format(hours=hours, minutes=minutes, seconds=seconds) progress.bar_style = 'success' progress.value = index label.value = "{name}: {index}. Total time: {ela_time}".format( name=name, index=str(index or '?'), ela_time=ela_time)