Beispiel #1
0
    def addTransaction(self):
        num = 0
        while True:
            delay = getTransactionDelay(self.params["transactionMu"],
                                        self.params["transactionSigma"])
            yield self.env.timeout(delay)

            value = np.random.randint(self.params["txLow"],
                                      self.params["txHigh"])
            reward = value * self.params["rewardPercentage"]

            transaction = Transaction("T%d" % num, self.env.now, value, reward)
            self.data["numTransactions"] += 1
            if self.params["verbose"] == "vv":
                print("%7.4f" % self.env.now + " : " +
                      "%s added with reward %.2f" %
                      (transaction.identifier, transaction.reward))
            """Broadcast transactions to all neighbours"""
            transactionNeighbours = list(
                np.random.choice(list(self.nodes.keys()),
                                 size=len(self.nodes) // 2))
            broadcast(
                self.env,
                transaction,
                "Transaction",
                "TempID",
                transactionNeighbours,
                self.params,
                nodes=self.nodes,
            )
            num += 1
Beispiel #2
0
def writeToNetwork(content, broadcast_destination):
    message = messages.shoutbox_message()
    message.set(content)
    casting = broadcast.broadcast()
    casting.setDestination(broadcast_destination)
    casting.set(message.get_message())
    casting.send()
def writeToNetwork(content, broadcast_destination):
    message = messages.shoutbox_message()
    message.set(content)
    casting = broadcast.broadcast()
    casting.setDestination(broadcast_destination)
    casting.set(message.get_message())
    casting.send()
Beispiel #4
0
def build_actual_tx(unspent, root_hash):
    print "Building...", root_hash.encode("hex")
    fee = 10000
    optimal_outputs = obelisk.select_outputs(unspent, fee)
    tx = obelisk.Transaction()
    for output in optimal_outputs.points:
        add_input(tx, output.point)
    add_return_output(tx, root_hash)
    change = optimal_outputs.change
    add_output(tx, address, change)
    key = obelisk.EllipticCurveKey()
    key.set_secret(secret)
    for i, output in enumerate(optimal_outputs.points):
        obelisk.sign_transaction_input(tx, i, key)
    broadcast.broadcast(tx)
    tx_hash = hash_transaction(tx)
    return tx_hash
Beispiel #5
0
def build_actual_tx(unspent, root_hash):
    print "Building...", root_hash.encode("hex")
    fee = 10000
    optimal_outputs = obelisk.select_outputs(unspent, fee)
    tx = obelisk.Transaction()
    for output in optimal_outputs.points:
        add_input(tx, output.point)
    add_return_output(tx, root_hash)
    change = optimal_outputs.change
    add_output(tx, address, change)
    key = obelisk.EllipticCurveKey()
    key.set_secret(secret)
    for i, output in enumerate(optimal_outputs.points):
        obelisk.sign_transaction_input(tx, i, key)
    broadcast.broadcast(tx)
    tx_hash = hash_transaction(tx)
    return tx_hash
 def putTransaction(self, transaction, sourceLocation):
     """Add received transaction to the transaction pool and broadcast further"""
     destLocation = self.nodes[self.identifier].location
     delay = getTransmissionDelay(sourceLocation, destLocation)
     yield self.env.timeout(delay)
     if (
         not self.transactionQueue.isPresent(transaction)
         and transaction not in self.prevTransactions
     ):
         self.transactionQueue.insert(transaction)
         broadcast(
             self.env,
             transaction,
             "Transaction",
             self.identifier,
             self.neighbourList,
             self.params,
             nodes=self.nodes,
         )
         if self.params["verbose"] == "vv":
             print(
                 "%7.4f : %s accepted by %s"
                 % (self.env.now, transaction.identifier, self.identifier)
             )
Beispiel #7
0
    def __init__(self, suite, db, stop_point, config, pyro, log, run_mode, proc_pool):
        self.pyro = pyro
        self.run_mode = run_mode
        self.log = log
        self.qconfig = config.cfg['scheduling']['queues']
        self.stop_point = stop_point
        self.reconfiguring = False
        self.db = db

        self.custom_runahead_limit = config.get_custom_runahead_limit()
        self.max_future_offset = None
        self._prev_runahead_base_point = None
        self.max_num_active_cycle_points = (
            config.get_max_num_active_cycle_points())
        self._prev_runahead_base_point = None
        self._prev_runahead_sequence_points = None

        self.config = config

        self.pool = {}
        self.proc_pool = proc_pool
        self.runahead_pool = {}
        self.myq = {}
        self.queues = {}
        self.assign_queues()

        self.pool_list = []
        self.rhpool_list = []
        self.pool_changed = []
        self.rhpool_changed = []

        self.held_future_tasks = []

        self.wireless = broadcast(config.get_linearized_ancestors())
        self.pyro.connect(self.wireless, 'broadcast_receiver')

        self.broker = broker()

        self.orphans = []
        self.task_name_list = config.get_task_name_list()
Beispiel #8
0
    def __init__(self, path):
        self.path = path
        self.broadcast = broadcast.broadcast()
        if not os.path.exists(path):
            self.execute__(lambda db: db.execute("""
CREATE TABLE podcasts(
  id integer primary key not null,
  name text not null,
  path text,
  original_name text,
  original text not null,
  created_at integer not null,
  object blob not null);"""))
        self.q = Queue(3)
        def f():
            while True:
                try:
                    f = self.q.get(block=True)
                    logging.info("transaction pop")
                    f()
                except Exception, e:
                    logging.error(e)
                    logging.error(traceback.format_exc())
Beispiel #9
0
    def run(self):
        self.target(self.generate())


# Example use:
if __name__ == "__main__":
    from follow import follow
    from apachelog import apache_log
    from broadcast import broadcast

    def find_404(log):
        r404 = (r for r in log if r["status"] == 404)
        for r in r404:
            print(r["status"], r["datetime"], r["request"])

    def bytes_transferred(log):
        total = 0
        for r in log:
            total = r["bytes"]
            print("Total bytes", total)

    c1 = ConsumerThread(find_404)
    c1.start()
    c2 = ConsumerThread(bytes_transferred)
    c2.start()

    lines = follow(open("run/foo/access-log"))  # Foolow a log
    log = apache_log(lines)  # Turn into records
    broadcast(log, [c1, c2])  # Broadcast to consumers
Beispiel #10
0
def water_mp2_script(scfwfn, mints):
  nirrep   = scfwfn.nirrep()
  nsopi    = tuple(scfwfn.nsopi()   [h] for h in range(nirrep))
  nalphpi  = tuple(scfwfn.nalphapi()[h] for h in range(nirrep))
  nbetapi  = tuple(scfwfn.nbetapi() [h] for h in range(nirrep))
  af = AxisFactory("C2v", "U", nsopi, nalphpi, nbetapi)
  
  U = Array((af.sy_ao, af.c1_ao))
  smtrzr = mints.petite_list().sotoao()
  for h in range(nirrep):
    for i in range(af.nao_pi[h]):
      for j in range(af.nao):
        U[0,0][0,0][h,0][i,j] = smtrzr.get(h, i, j)
        U[0,0][1,1][h,0][i,j] = smtrzr.get(h, i, j)

  Ca = scfwfn.Ca()
  Cb = scfwfn.Cb()

  C = Array((af.sy_ao, af.sy_mo))
  for h in range(nirrep):
    for mu in range(af.nao_pi[h]):
      for i in range(af.nocc_alph_pi[h]):
        C[0,0][0,0][h,h][mu,i] = Ca.get(h, mu, i)
      for a in range(af.nvir_alph_pi[h]):
        C[0,1][0,0][h,h][mu,a] = Ca.get(h, mu, af.nocc_alph_pi[h] + a)
      for i in range(af.nocc_beta_pi[h]):
        C[0,0][1,1][h,h][mu,i] = Cb.get(h, mu, i)
      for a in range(af.nvir_beta_pi[h]):
        C[0,1][1,1][h,h][mu,a] = Cb.get(h, mu, af.nocc_beta_pi[h] + a)

  epsilon_a = scfwfn.epsilon_a()
  epsilon_b = scfwfn.epsilon_b()
  e = Array(af.sy_mo, array=None, diagonal=True)
  for h in range(nirrep):
    for i in range(af.nocc_alph_pi[h]):
      e[0][0][h][i] = epsilon_a.get(h, i)
    for a in range(af.nvir_alph_pi[h]):                       
      e[1][0][h][a] = epsilon_a.get(h, af.nocc_alph_pi[h] + a)
    for i in range(af.nocc_beta_pi[h]):                       
      e[0][1][h][i] = epsilon_b.get(h, i)
    for a in range(af.nvir_beta_pi[h]):                       
      e[1][1][h][a] = epsilon_b.get(h, af.nocc_beta_pi[h] + a)

  import numpy as np
  import broadcast as bd

  bcast_axes = (af.sy_mo[0], af.sy_mo[0], af.sy_mo[1], af.sy_mo[1])
  tmp = bd.broadcast(e[0], bcast_axes, axis_keys=(0,))
  D = 1./( bd.broadcast(e[0], bcast_axes, axis_keys=(0,)) + bd.broadcast(e[0], bcast_axes, axis_keys=(1,)) \
         - bd.broadcast(e[1], bcast_axes, axis_keys=(2,)) - bd.broadcast(e[1], bcast_axes, axis_keys=(3,)))



  G = np.empty((1,1,1,1), dtype=np.ndarray)
  G[0,0,0,0] = np.array(mints.ao_eri())
  g_c1_ao = Array((af.c1_ao, af.c1_ao, af.c1_ao, af.c1_ao))
  for w1,w2,w3,w4 in g_c1_ao[0,0,0,0].iter_keytups():
    if w1==w2 and w3==w4:
      g_c1_ao[0,0,0,0][w1,w2,w3,w4] = Array((af.c1_ao[0][w1], af.c1_ao[0][w2], af.c1_ao[0][w3], af.c1_ao[0][w4]), array=G)

  import contract as ct
  g_sy_ao = ct.eindot('pqrs', (g_c1_ao,'PQRS'), (U,'pP'), (U,'qQ'), (U,'rR'), (U,'sS'))
  g       = ct.eindot('pqrs', (g_sy_ao,'PQRS'), (C,'Pp'), (C,'Qq'), (C,'Rr'), (C,'Ss'))

  g = g.transpose((0,2,1,3)) - g.transpose((0,2,3,1)) # phys. antisymmetrized
  t = g[0,0,1,1] * D

  E0 = 0.0
  for i in range(50):
    I = ct.eindot('ijab', (g[0,1,1,0], 'kbcj'), (t,'ikac'))
    t = g[0,0,1,1] + 1./2 * ct.eindot('ijab', (g[1,1,1,1],'abcd'), (t,'ijcd')) \
                   + 1./2 * ct.eindot('ijab', (g[0,0,0,0],'klij'), (t,'klab'))
    t = D * (t + I.transpose((0,1,2,3)) - I.transpose((1,0,2,3)) - I.transpose((0,1,3,2)) + I.transpose((1,0,3,2)) )

    E = ct.eindot('', (g[0,0,1,1],'ijab'), (t,'ijab'))[()][()]
    E /= 4
    print('{:<3d} {:17.10f} {:17.10f}'.format(i, E, E-E0))
    if(abs(E-E0) < 1e-9): break
    E0 = E
Beispiel #11
0
  def has_data_at(self, keytup): return not self.array[keytup] is None and not 0 in self.array[keytup].shape

  def __getitem__(self, *args): return self.array[args[0]]
  def __setitem__(self, *args):        self.array[args[0]] = args[1]

  def __mod__ (self, other): return tensordot(self, other)
  def __rmod__(self, other): return tensordot(other, self)

  def transform(self, transformer):
    array = np.empty(self.multiaxis.shape, self.multiaxis.dtype)
    for keytup in self.iter_keytups():
      array[keytup] = transformer(self.array, keytup)
    return array

  def transpose(self, axis_keys = None):
    return Array(self.multiaxis.transpose(axis_keys), self.transform(lambda arr, kt: arr[kt].transpose(axis_keys)).transpose(axis_keys))
  T = property(transpose, None)


if __name__ == "__main__":
  import axis as ax
  import broadcast as bd
  a = ax.IrrepAxis("C2v", (4,0,1,2), np.ndarray)
  A = Array((a,), None, diagonal=True)
  B = bd.broadcast(A, (a,a), axis_keys=(0,))
  print B.multiaxis
  B += 1
  for blk in B:
    print blk
Beispiel #12
0
    def blockGenerator(self, params):
        """Block generator"""
        while True:
            try:
                delay = getBlockDelay(self.params["blockMu"], self.params["blockSigma"])
                yield self.env.timeout(delay)

                transactionCount = int(params["blockCapacity"])
                transactionList = self.transactionPool.getTransaction(transactionCount)
                l = []
                for transaction in transactionList:
                    transaction.miningTime = self.env.now
                    """Simulating Tx validation time"""
                    self.env.timeout(0.1)
                    l.append(transaction.identifier)
                b = Block("B" + str(self.currentBlockID), transactionList, params)

                """Collection of data"""
                """If block has been mined earlier, inrease count of fork"""
                if b.identifier in [
                    id[: id.index("_")] for id in self.data["blockProp"].keys()
                ]:
                    self.data["numForks"] += 1

                print(
                    "%7.4f" % self.env.now
                    + " : %s proposing %s with transaction list count %d with transactions %s ..."
                    % (self.identifier, b.identifier, len(l), l[:3])
                )

                if bool(self.params["verbose"]):
                    print(
                        "%7.4f" % self.env.now
                        + " : %s" % self.identifier
                        + " generated Block %s" % b.identifier
                    )
                self.blockchain.append(b)
                if bool(self.params["verbose"]):
                    self.displayChain()

                """Mark the block creation time"""
                if b.hash not in self.data["blockProp"].keys():
                    self.data["blockProp"][b.hash] = [self.env.now, self.env.now]

                """Broadcast block to all neighbours"""
                broadcast(
                    self.env,
                    b,
                    "Block",
                    self.identifier,
                    self.neighbourList,
                    self.params,
                    pipes=self.pipes,
                    nodes=self.nodes,
                )

                """Remove transactions from local pool"""
                self.transactionPool.popTransaction(transactionCount)
                self.currentBlockID += 1

            except simpy.Interrupt:
                if bool(self.params["verbose"]):
                    print(
                        "%7.4f" % self.env.now
                        + " : "
                        + "%s" % self.identifier
                        + " interrupted. To mine block %s" % (self.currentBlockID + 1)
                        + " now"
                    )
                self.currentBlockID += 1
Beispiel #13
0
    def setUp(self):
        def f(*xs,**ys):
            self.called = (xs,ys)

        self.broadcast = broadcast.broadcast()
        self.broadcast += f
Beispiel #14
0
from broadcast import broadcast
import time
while True:
    broadcast()
    time.sleep(1)
'''
run python broadcast.py
then in a seperate terminal run this file.
'''
Beispiel #15
0
def message_callback_handler():
    message = request.values.get('Body', None)
    from_number = request.values.get('From', None)
    status = broadcast(from_number, message)
    return status
Beispiel #16
0
            item = self.in_queue.get()
            yield item

    def run(self):
        self.target(self.generate())


if __name__ == '__main__':
    from python_tail_f import follow
    from nginx_log import nginx_log

    def find_404(log):
        for r in (r for r in log if r['status'] == 404):
            print('[{}] [{}] {}'.format(r['status'], r['datetime'],
                                        r['request']))

    def bytes_transferred(log):
        total = 0
        for r in log:
            total += r['bytes']
            print('Total bytes: {}'.format(total))

    c1 = ConsumerThread(find_404)
    c1.start()
    c2 = ConsumerThread(bytes_transferred)
    c2.start()

    lines = follow('/var/log/nginx/3d.access.log')
    log = nginx_log(lines)
    broadcast(log, [c1, c2])
Beispiel #17
0
def broadcast_handler():
    request_body = request.get_json()
    message = request_body['message']
    status = broadcast(message)
    return status
Beispiel #18
0
from follow import follow
from apachelog import apache_log


class NetConsumer(object):
    def __init__(self, addr):
        self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.s.connect(addr)

    def send(self, item):
        pitem = pickle.dumps(item)
        self.s.sendall(pitem)

    def close(self):
        self.s.close()


# A class that sends 404 requests to another host
class Stat404(NetConsumer):
    def send(self, item):
        if item["status"] == 404:
            super().send(item)


if __name__ == "__main__":
    stat404 = Stat404(("127.0.0.1", 15000))

    lines = follow(open("run/foo/access-log"))
    log = apache_log(lines)
    broadcast(log, [stat404])
Beispiel #19
0
    def __init__(self, addr):
        self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.s.connect(addr)

    def send(self, item):
        pitem = pickle.dumps(item)
        self.s.sendall(pitem)

    def close(self):
        self.s.close()


class Stat404(NetConsumer):
    def send(self, item):
        if item['status'] == 404:
            NetConsumer.send(self, item)


class LogConsumer(NetConsumer):
    def send(self, item):
        NetConsumer.send(self, item)


if __name__ == '__main__':
    lines = follow(open('www/access-log'))
    log = apache_log(lines)

    stat404 = Stat404(('', 15000))
    log_c = LogConsumer(('', 15001))
    broadcast(log, [stat404, log_c])
Beispiel #20
0
our_router.bind((local_host, int(router_direct[router_id])))

#Start router protocol loop
#Time counters
i = 1
j = 1
k = 1
link_packet = build_packet(router_id, cost_direct)
time_start = time.time()

while True:
    # Send out heartbeat every 0.05 seconds
    if((time.time() - time_start) / (k*HEARTBEAT_UPDATE_INTERVAL) >= 1):
        heartbeat()
        k += 1

    #Send link packet every second
    if((time.time() - time_start) // (i*UPDATE_INTERVAL) == 1):
        link_packet = build_packet(router_id, cost_direct)
        broadcast(link_packet)
        i += 1

    #Update routes every 30 seconds
    if ((time.time() - time_start) // (ROUTE_UPDATE_INTERVAL*j) == 1):
        output_summary(unpack(packets_received))
        packets_received = []
        already_sent = []
        j+= 1

    packets_received = receive_and_forward(packets_received)
Beispiel #21
0
from recvcount import consumer
from tail import follow
from parser import apache_log
from broadcast import broadcast


@consumer
def find_404():
    while True:
        r = yield
        if r['status'] == 404:
            print(r['status'], r['datetime'], r['request'])


@consumer
def bytes_transferred():
    total = 0
    while True:
        r = yield
        total += r['bytes']
        print('Total bytes', total)


if __name__ == '__main__':
    lines = follow(open('www/access-log'))
    log = apache_log(lines)

    broadcast(log, [find_404(), bytes_transferred()])