Beispiel #1
0
    def _main_loop(self):
        """
        Handle method calls from the queue und call the provided
        update method.
        """
        while self._running:
            try:
                # Handle incoming calls from the queue ...
                max_calls = 50
                while max_calls > 0:  # ... till a max is reached ...
                    call, result, args, kwargs = self._q.get_nowait()
                    max_calls -= 1
                    result.put(call(*args, **kwargs))
            except Empty:
                # ... or until nothing's left
                pass

            # Run the update function from the encapsulated object
            # setting a maximum on calls above assures the update
            # function won't starve
            try:
                self._u()
            except Exception as e:
                eprint(self, e)

            # Yield thread time
            yield_thread()
Beispiel #2
0
    def run(self):
        """This is what the main server thread runs."""
        while True:
            try:
                # accept and receive socket message
                s, addr = self.ss.accept()
                self.server_started = True
                msg = recv(s)

                # verify message information
                if not self.verify_message(msg):
                    eprint(self.name, 'Error processing ' + str(msg) + '.')
                    s.close()
                    continue

                msg_head, *msg_args = msg

                # respond to received message
                if msg_head in Constants.OPEN_SOCKET:
                    Thread(target=self.respond[msg_head],
                           args=(s, msg_args)).start()
                else:
                    Thread(target=self.respond[msg_head],
                           args=(msg_args, )).start()
            except Exception:
                traceback.print_exc()
    def test_00_benchmark(self, max_time=30):
        cls = self.__class__

        cmd = [
            "client", "--enclave-name", self.enclave_name, "backup",
            "--request-count",
            str(self.request_count)
        ]
        backup_count = 0
        start_time = time.time()
        elapsed_time = 0
        while elapsed_time < max_time:
            kbupctls = []
            for frontend in self.frontends:
                self.client.log.write("CMD: " + " ".join(cmd) + "\n")
                self.client.log.flush()
                kbupctls.append(frontend.kbupctl_async(*cmd))
            for kbupctl in kbupctls:
                kbupctl_res = kbupctl.wait()
                if kbupctl_res != 0:
                    eprint()
                    eprint("TEST '%s' FAILED, returned %d" %
                           (" ".join(cmd), kbupctl_res))
                    raise Exception("Test failed")
            elapsed_time = time.time() - start_time
            backup_count += self.request_count * len(self.frontends)
            gprint("performed %7d backups in %6.03fs (%4d/s)" %
                   (backup_count, elapsed_time, backup_count / elapsed_time))
        cls.backup_count += backup_count
        gprint()
Beispiel #4
0
    def input_callback(self, event):
        """
        Handles a Midi event from the DAW
        """
        message, deltatime = event

        status_byte = message[0]
        if status_byte == SONG_START:
            self.clock.start()
        elif status_byte == SONG_CONTINUE:
            self.clock.unpause()
        elif status_byte == SONG_STOP:
            self.clock.stop()
        elif status_byte == TIMING_CLOCK:
            self.clock.tick()

        else:  # TODO: Filter for Note events
            try:
                channel, cc, value = message
                ID = ccc2ID(channel, cc)

                worth_reporting = False
                try:
                    if value != self.last_sent_values[ID]:
                        worth_reporting = True
                except KeyError:
                    pass

                if worth_reporting:
                    self.received(channel, cc, value)
            except Exception as e:
                eprint(self, e)
Beispiel #5
0
    def start_server(self, ss):
        while True:
            try:
                # accept and receive socket message
                s, addr = ss.accept()
                msg = recv(s)

                # verify message information
                if not self.verify_message(msg):
                    eprint(self.name, 'Error processing message.')
                    continue

                msg_head, *msg_args = msg

                # respond to received message
                if msg_head in Constants.OPEN_SOCKET:
                    if not self.respond[msg_head](s, msg_args):
                        break
                else:
                    if not self.respond[msg_head](msg_args):
                        break
                if msg_head == Constants.SHUFFLE:
                    break
            except ConnectionAbortedError:
                print()
                ss.close()
                break
            except Exception:
                traceback.print_exc()
        ss.close()
        self.listening = False
Beispiel #6
0
    def handle_ehlo(self, command):
        # Verify hostname
        try:
            peer_ip, peer_port = self.request.getpeername()

            _, _, valid_ips = socket.gethostbyname_ex(command[1])
            if peer_ip not in valid_ips:
                eprint("Warning: %s does not resolve to %s" %
                       (command[1], peer_ip))
        except socket.error:
            eprint("Warning: unable to resolve peer name", command[1])

        # Construct EHLO messages
        ehlo_mesg = [
            (socket.gethostname(), None),
            ("SIZE", 10 * (1 << 30)),  # 10MB should be enough for everyone
        ]

        for entry, last in lookahead(ehlo_mesg):
            if last:
                msg = "250 "
            else:
                msg = "250-"

            key, value = entry

            msg += str(key)
            if value is not None:
                msg += " " + str(value)

            self.write_output(msg)
def createdir():
    '''Create the cache directory if it doesn't exist'''
    try:
        os.makedirs(CACHE_DIR, exist_ok=False)
        eprint(f"Created cache directory at '{CACHE_DIR}'.")
    except FileExistsError:
        eprint(f"Using existing cache directory at '{CACHE_DIR}'.")
Beispiel #8
0
 def create_decoder(self):
     z_est = {}
     self.d_cost = []  # to store the denoising cost of all layers
     for l in range(self.L, -1, -1):
         eprint(
             "Layer ", l, ": ",
             self.layer_sizes[l +
                              1] if l + 1 < len(self.layer_sizes) else None,
             " -> ", self.layer_sizes[l], ", denoising cost: ",
             self.denoising_cost[l])
         z, z_c = self.clean['unlabeled']['z'][l], self.corr['unlabeled'][
             'z'][l]
         m, v = self.clean['unlabeled']['m'].get(
             l, 0), self.clean['unlabeled']['v'].get(l, 1 - 1e-10)
         if l == self.L:
             u = self.unlabeled(self.y_c)
         else:
             u = tf.matmul(z_est[l + 1], self.weights['V'][l])
         u = self.batch_normalization(u)
         z_est[l] = self.g_gauss(z_c, u, self.layer_sizes[l])
         z_est_bn = (z_est[l] - m) / v
         # append the cost of this layer to d_cost
         self.d_cost.append(
             (tf.reduce_mean(tf.reduce_sum(tf.square(z_est_bn - z), 1)) /
              self.layer_sizes[l]) * self.denoising_cost[l])
Beispiel #9
0
def main():
    parser = argparse.ArgumentParser(description="linearize a set of files")
    parser.add_argument('--prelude', default=".")
    parser.add_argument('--hardfail', default=False,
                        const=True, action='store_const')
    parser.add_argument('-v', '--verbose', action='count', default=0)
    parser.add_argument('--skip-nochange-tac', default=False, const=True,
                        action='store_const',
                        dest='skip_nochange_tac')
    parser.add_argument("--progress",
                        action='store_const', const=True, default=False)
    parser.add_argument("--linearizer-timeout",
                        type=int, default=(60 * 60 * 2))
    parser.add_argument('filenames', nargs="+", help="proof file name (*.v)")
    arg_values = parser.parse_args()

    coqargs = ["sertop", "--implicit"]

    for filename in arg_values.filenames:
        if arg_values.verbose:
            eprint("Linearizing {}".format(filename))
        local_filename = arg_values.prelude + "/" + filename
        original_commands = serapi_instance.load_commands_preserve(
            arg_values, 0, arg_values.prelude + "/" + filename)
        try:
            fresh_commands = preprocess_file_commands(
                arg_values, 0, original_commands,
                coqargs, arg_values.prelude,
                local_filename, filename, False)
            serapi_instance.save_lin(fresh_commands, local_filename)
        except CoqAnomaly:
            serapi_instance.save_lin(original_commands, local_filename)
Beispiel #10
0
    def handle_data(self, command):
        if self.mail_from is None:
            self.write_output(503, "No MAIL command")
            return
        elif not self.recipients:
            self.write_output(503, "No recipients specified")
            return

        self.write_output(354, "Go ahead, send message")
        message = ""

        prev = None
        crlf = "\r\n"
        for line in self.rfile:
            line = line.decode("ascii")

            if prev == crlf and line == "." + crlf:
                break
            elif prev is not None:
                message += prev
            prev = line

        self.send_ok()
        params = (self.mail_from, "' and '".join(self.recipients), message)
        eprint("Recieved message from '%s' to '%s':\n%s" % params)

        self.reset_state()
Beispiel #11
0
    def load_ladder_weights(self, arch, trainable=False):
        sess = tf.Session()
        shapes = list(zip(self.layer_sizes[:-1], self.layer_sizes[1:]))
        self.weights = {'W_raw': [self.wi(s, "W", trainable=trainable) \
                                  for (i, s) in enumerate(shapes)], \
                        'beta': [self.bi(0.0, self.layer_sizes[l + 1], \
                                'beta', trainable=trainable) for l in range(self.L)]}

        saver = tf.train.Saver()
        if arch == 'ladder':
            fm = 'weight_checkpoints'
        else:
            fm = 'baseline_checkpoints'
        ckpt = tf.train.get_checkpoint_state(fm)
        if ckpt and ckpt.model_checkpoint_path:
            #set_trace()
            #checkpoint_path = '{}/model.ckpt-9900'.format(fm)
            #checkpoint_path = '{}/weights.ckpt-2'.format(fm)
            checkpoint_path = ckpt.model_checkpoint_path
            saver.restore(sess, checkpoint_path)
            epoch_n = int(checkpoint_path.split('-')[1])
            eprint("Restored Epoch ", epoch_n)
        eprint("Restored weights from file {}".format(fm))

        self.weights['W'] = [self.true_divide(w, s, scope="transfer_weights") \
                             for (w, s) in zip(self.weights['W_raw'], shapes)]
 def run_one(self, remaining: int, package_name: str, pkg_path: str):
     start_time = time.time()
     try:
         eprint(f'Timing {package_name}. {remaining} remaining...')
         output_path = f'{pkg_path}/experiment.out'
         with open(output_path, 'wt') as out:
             exit_code = subprocess.Popen(solve_command(
                 self.mode_configuration),
                                          cwd=pkg_path,
                                          stdout=out,
                                          stderr=out).wait(self.timeout)
         duration = time.time() - start_time
         if exit_code == 0:
             print(f'{package_name},{duration}', flush=True)
             return
         else:
             print(f'{package_name},', flush=True)
         eprint(f'{package_name} failed with exit code {exit_code}')
     except subprocess.TimeoutExpired:
         print(f'{package_name},', flush=True)
         eprint(f'{package_name} failed with timeout')
     except KeyboardInterrupt as e:
         eprint(f'{package_name} failed with keyboard interrupt')
         raise e
     except BaseException as e:
         eprint(f'{package_name} failed with exception {e}')
Beispiel #13
0
 def main_loop(self):
     while True:
         try:
             self.update()
         except Exception as e:
             eprint(e)
         yield_thread()
Beispiel #14
0
    def post_message(self, msg_args):
        """Posts message to board and increment message id."""
        client_msg, addresses, sender_addr = msg_args

        # verify that there is either one address with 0 reputation or all addresses
        # have 1 reputation, and that the addresses have never been used before.
        if len(addresses) > 1:
            for addr in addresses:
                if self.blockchain.get_reputation(addr) != 1:
                    eprint(self.name,
                           'All wallets should have had >0 reputation.')
                    return
                if addr in self.used_wallets:
                    eprint(self.name,
                           '{} has already been used in a post'.format(addr))

        self.used_wallets.update(addresses)

        self.reps[tuple(sender_addr)] = 0
        self.msg_id_to_addr[self.msg_id] = tuple(sender_addr)

        # post message to board and increment message id
        self.board.append([
            self.msg_id, {
                Constants.MSG: client_msg,
                Constants.REP: addresses,
                Constants.FB: Constants.INIT_FEEDBACK
            }
        ])

        self.msg_id += 1
Beispiel #15
0
 def map_modconfig_target(attr_desc, target):
     try:
         ID = next(type_IDs[attr_desc.type])
         temp_view.map_this(ID, target)
     except StopIteration:
         eprint(
             "Not enough universal controls available to make %s available in Config View"
             % target)
Beispiel #16
0
 def convertPotionToCheese(self, potion, quantity):
     settings = {
         'potion': potion,
         'num_potions': quantity,
         'recipe_index': 0
     }
     api_usePotion(self.request_cookies, {**self.request_body, **settings})
     eprint('Bristle Woods Rift', f'Converted {quantity} {potion}')
Beispiel #17
0
 def remove_listener(self, q):
     """
     Removes a queue from the listener qs
     """
     try:
         self.listener_qs.remove(q)
     except KeyError:
         eprint("(Exception): Tried to remove Queue that wasn't registered:", q)
    def create_compute_graph(self):
        self.inputs = tf.placeholder(tf.float32,
                                     shape=(None, self.layer_sizes[0]))
        self.labels = tf.placeholder(tf.int64)
        self.o_labels = tf.one_hot(self.labels, 10)
        self.training = tf.placeholder(tf.bool)

        # Shapes of linear layers.
        shapes = list(zip(self.layer_sizes[:-1], self.layer_sizes[1:]))

        self.weights = {'W_raw': [self.wi(s, "W", scope="transfer_weights") \
                              for s in shapes],  # Encoder weights
                   # batch normalization parameter to shift the normalized value
                   'beta': [self.bi(0.0, self.layer_sizes[l+1], "beta", scope="transfer_weights") \
                            for l in range(self.L)],
                   # batch normalization parameter to scale the normalized value
                   'gamma': [self.bi(1.0, self.layer_sizes[l+1], "beta") for l in range(self.L)]}

        self.weights['W'] = [self.true_divide(w, s, scope="transfer_weights") \
                             for (w, s) in zip(self.weights['W_raw'], shapes)]

        net = {}
        net['fc0'] = self.inputs

        for l in range(1, self.L + 1):
            prev = 'fc{}'.format(l - 1)
            curr = 'fc{}'.format(l)

            net[curr] = tf.matmul(net[prev], self.weights['W'][l - 1])
            if l == self.L:
                net[curr] = tf.nn.softmax(self.weights['gamma'][l - 1] * \
                    (net[curr] + self.weights['beta'][l - 1]))
            else:
                net[curr] = tf.nn.relu(net[curr] + self.weights['beta'][l - 1])

        net['output'] = net['fc{}'.format(self.L)]
        net['predicted'] = tf.cast(tf.argmax( \
                    net['output'], axis=-1), tf.int64)

        eprint(
            "Total number of variables used ",
            np.sum([
                v.get_shape().num_elements() for v in tf.trainable_variables()
            ]))

        self.loss = tf.reduce_mean(
            tf.nn.softmax_cross_entropy_with_logits(logits=net['output'],
                                                    labels=self.o_labels))
        reg_loss = tf.reduce_sum(
            tf.get_collection(tf.GraphKeys.REGULARIZATION_LOSSES))
        self.loss = self.loss + 1e-6 * reg_loss
        bounds = [5000, 10000]
        values = [1e-3, 1e-4, 1e-5]
        step_op = tf.Variable(0, name='step', trainable=False)
        lr_op = tf.train.piecewise_constant(step_op, bounds, values)
        self.minimizer = tf.train.AdamOptimizer(lr_op).minimize(self.loss)
        self.correct = tf.equal(net['predicted'], self.labels)
        self.accuracy = tf.reduce_mean(tf.cast(self.correct, tf.float32))
Beispiel #19
0
 def setNormalTrap(self):
     # if self.getCurrentTrinket() != 'Rift Spooky Charm':
     #     eprint('Valour Rift', f'Changing trinket to Rift Spooky Charm')
     #     self.setTrap({'trinket': "rift_spooky_trinket"})
     if self.getCurrentTrinket() != 'Rift Ultimate Lucky Power Charm':
         eprint('Valour Rift', f'Changing trinket to RULPC')
         self.setTrap({'trinket': "rift_ultimate_luck_power_trinket"})
         self.setTrap({'base': "upgraded_denture_base"})
         self.setCandle('yellow')
Beispiel #20
0
 def from_dict(self, d):
     super().from_dict(d)
     try:
         self.flex = self.parent.targets[d["flex"]]
     except KeyError:
         eprint(
             "Flex target %s for %s not yet instantiated. Defering until first trigger"
         )
         self.deferred = d["flex"]
Beispiel #21
0
    def chamberSetup(self, setup):
        if setup['quantumQuarts'] and not self.getItemIsActiveStatus('rift_quantum_quartz_stat_item'):
            self.toggleQuantumQuarts()
        if not setup['quantumQuarts'] and self.getItemIsActiveStatus('rift_quantum_quartz_stat_item'):
            self.toggleQuantumQuarts()

        self.setTrap({'bait': setup['bait']})
        self.setTrap({'trinket': setup['trinket']})
        eprint('Bristle Woods Rift', f'Changed Setup')
Beispiel #22
0
 def remove_target(self, target):
     """
     Stop modifying the provided target.
     """
     self.target(target, 0.0)
     try:
         target.remove_modifier(self)
     except AttributeError as e:
         eprint(e)
Beispiel #23
0
    def determineChamberToEnter(self):
        """
        This method determines the chamber to enter, the priorities are:
        1. Enter Security Chamber to disable alarm
        2. Enter Guard Barracks if the alarm was triggered
        3. Hidden Treasury for gold
        4. Then Lucky tower for loot
        5. Acolyte Chamber if conditions are met
        6. Timewarp chamber if conditions are met
        7. runic chamber if all else fails
        8. ancient chamber if oh well....
        9. Gear works, seriously?

        returns the name of the chamber
        """

        portals = self.getCurrentPortals()

        # Condition 1 (TODO)
        # if 'security_chamber' in chambers:
        #     return 'security_chamber'

        # Condition 2 (TODO)
        # if self.getStatusEffects()['un'] == 'active':
        #     return 'guard_barracks'

        # Condition 3
        if 'lucky_tower' in portals:
            return 'lucky_tower'

        # Condition 4
        if 'hidden_treasury' in portals:
            return 'hidden_treasury'

        # Condition 5
        if self.getItemsCount(
                'rift_hourglass_sand_stat_item') > 65 and self.getItemsCount(
                    'runic_string_cheese'
                ) > 65 and 'acolyte_chamber' in portals:
            return 'acolyte_chamber'

        # Condition 6
        if 'timewarp_chamber' in portals and self.getItemsCount(
                'rift_hourglass_sand_stat_item') < 70:
            return 'timewarp_chamber'

        # Condition 7
        if 'magic_chamber' in portals:
            return 'magic_chamber'

        # # Condition 8 (TODO)
        # if 'ancient_chamber' in portals:
        #     return 'ancient_chamber'
        eprint('Bristle Woods Rift', f'No Suitable portal')

        return None
Beispiel #24
0
    def set_control(self, ID, value, from_input=False, inform_listeners=False, force=False):
        """
        Try to set the value of a control. Depending on the flags the value is reported back to:
        - the hardware (self.input port)
        - to any listener (self.listener_qs)

        from_input: The input came in through the midi port callback
                    -> If the value set is the one we expect, don't
                       report back to the input port
        inform_listeners:  Whether to inform listeners about the value
                    @Robustness: Only works with one listener right now
                                 Gotta add some exclude functionality
        force: Assures the value we try to set the control to is actually assumed,
               circumventing any logic the control might implement. This is necessary
               for actions like recalling previous values and bringing the control back
               into that state.

        Default assumption: We call this from the outside, which means we only really
        want to set the control value on the hardware and not get the set value reported
        back to us, which might result in an endless loop of messages. Hence the defaults
        from_input=False, inform_listeners=False. Any CC messages from the hardware should
        come through the input_callback method which automatically sets the correct flags.
        """
        try:
            control = self.controls[ID]
        except KeyError:
            eprint("Control with ID %s not found" % ID)
            return None

        # The Control might implement some further logic which can result in a different
        # value being set than what we are trying to set here (think min/max-values or
        # ignoring button presses to simulate toggle behaviour).
        real_value = control.set_value(value, force=force)

        #        iprint(ID == 873, self, value, real_value)
        # Therefore we get the real_value reported back from the control which we can
        # then reflect on the input device. If None was returned, the control wants us
        # to ignore it
        if real_value is None:
            return None

        # Otherwise, depending on where the control change came from inform the hardware
        # device or possible listeners

        # If the cc didn't come from the hardware, or if it did but the real_value is
        # different that what we tried to set the virtual control to, send that cc to
        # the input. The cc method checks whether the control is on the active page.
        if not from_input or real_value != value:
            self.cc(ID, real_value)

        # If it came from the input device or the value we tried to set is different
        # than what the virutal control assumed, issue the cc to all listeners
        if inform_listeners and (from_input or real_value != value):
            self.control_changed(ID, real_value)

        return real_value
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--experiments', type=str)
    parser.add_argument('--duration', default=12, type=int)
    args = parser.parse_args()
    eprint(args)
    if not args.experiments:
        print("0 Experiments passed in!")
        sys.exit(1)
    runner = ExperimentRunner(args.experiments.split(), duration=args.duration)
Beispiel #26
0
 def getNextAvailableTournmanetID(self):
     tournaments = self.getSpecialTournaments()
     for tournament in tournaments:
         if tournament['name'][
                 -33:] == "Snow Golem Celebration Tournament" and tournament[
                     'can_join']:
             eprint(
                 "Tournament",
                 f"{self.name}: Joining tournament {tournament['name']}")
             return tournament['tournament_id']
Beispiel #27
0
 def switch_to_lfo(self, index):
     """
     Switch the the LFO at the provided index in the Modifiers self.lfos list.
     Doesn't complain if the index is out of range.
     :param index: Index of the LFO to switch to
     """
     try:
         self._lfo = self.lfos[index]
     except IndexError:
         eprint("No LFO in slot", index)
Beispiel #28
0
 def configure(self, conf):
     """
     Configures the control based on the dictionary
     """
     for attribute, value in conf.items():
         try:
             setattr(self, attribute, value)
         except AttributeError:
             eprint(
                 "Control of type %s does not have configurable attribute %s!"
                 % (type(self), attribute))
Beispiel #29
0
def modify_scene(scene,
                 integrator,
                 sampler,
                 sample_count,
                 cropwindow="",
                 test=False):
    if "pixelsamples" in sampler:
        eprint(
            colored(
                "Given sampler should not contain 'pixelsamples'. This is the job of the application.",
                'red'))
        eprint(colored("Sampler input: " + sampler, 'yellow'))
        sys.exit(1)
        return False

    films = re_film.findall(scene)
    if test:
        if len(films) != 1:
            eprint("Should be exactly 1 match for a Film")
            return False

        integrators = re_integrator.findall(scene)
        if len(integrators) != 1:
            eprint("Should be exactly 1 match for an Integrator")
            return False

        sampler_info = re_sampler.findall(scene)
        if len(sampler_info) != 1:
            eprint("Should be exactly 1 match for a Sampler")
            return False

    if " " not in integrator and not integrator.startswith(
            '"') and not integrator.endswith('"'):
        integrator = '"' + integrator + '"'

    if " " not in sampler and not sampler.startswith(
            '"') and not sampler.endswith('"'):
        sampler = '"' + sampler + '"'

    if cropwindow != "":
        cropwindow = ' "float cropwindow" [ ' + " ".join(cropwindow) + ' ]'

    scene = re_integrator.sub("Integrator " + integrator, scene)
    scene = re_sampler.sub(
        "Sampler {} \"integer pixelsamples\" [{}]".format(
            sampler, sample_count), scene)
    scene = re_film.sub(
        'Film "image" "string filename" "___p144out.exr" "integer xresolution" [400] "integer yresolution" [400]'
        + cropwindow, scene)

    with open('_lastscene.pbrt', 'w') as this:
        this.write(scene)

    return scene
Beispiel #30
0
 def _save_all_dynamic_images(self):
     for (filename, label) in zip(self.videos, self.labels):
         if os.path.exists(filename + '.npy'):
             util.eprint("DI for {} already exists".format(filename))
             continue
         video = util.video_to_frames(filename)
         if video is None:
             continue
         dynamic_image_rep = self.dig.get_dynamic_image(video)
         util.serialize(dynamic_image_rep, filename, dynamic=True)
         util.eprint("Serialized DI for {}".format(filename))