Ejemplo n.º 1
0
def main():
    parser = argparse.ArgumentParser(description=None)
    parser.add_argument('-v', '--verbose', action='count', dest='verbosity', default=0, help='Set verbosity.')
    parser.add_argument('-l', '--listen-address', default='0.0.0.0:5899', help='Address to listen on')
    parser.add_argument('-s', '--vnc-address', default='127.0.0.1:5900', help='Address of the VNC server to run on.')
    parser.add_argument('-d', '--logfile-dir', default=None, help='Base directory to write logs for each connection')
    args = parser.parse_args()

    if args.verbosity == 0:
        logger.setLevel(logging.INFO)
    elif args.verbosity >= 1:
        logger.setLevel(logging.DEBUG)

    factory = protocol.ServerFactory()
    factory.protocol = vnc_proxy_server.VNCProxyServer
    factory.vnc_address = 'tcp:{}'.format(args.vnc_address)
    factory.logfile_dir = args.logfile_dir
    factory.recorder_id = utils.random_alphanumeric().lower()

    host, port = args.listen_address.split(':')
    port = int(port)

    logger.info('Listening on %s:%s', host, port)
    reactor.listenTCP(port, factory, interface=host)
    reactor.run()
    return 0
Ejemplo n.º 2
0
    def __init__(self,
                 env,
                 recording_dir=None,
                 recording_policy=None,
                 recording_notes=None):
        super(Recording, self).__init__(env)
        self._log_n = None
        self._episode_ids = None
        self._step_ids = None
        self._episode_id_counter = 0
        self._env_semantics_autoreset = env.metadata.get(
            'semantics.autoreset', False)
        self._env_semantics_async = env.metadata.get('semantics.async', False)
        self._async_write = self._env_semantics_async

        self._recording_dir = recording_dir
        if self._recording_dir is not None:
            if recording_policy == 'never' or recording_policy is False:
                self._recording_policy = lambda episode_id: False
            elif recording_policy == 'always' or recording_policy is True:
                self._recording_policy = lambda episode_id: True
            elif recording_policy == 'capped_cubic' or recording_policy is None:
                self._recording_policy = lambda episode_id: (
                    int(round(episode_id**(1. / 3)))**3 == episode_id
                ) if episode_id < 1000 else episode_id % 1000 < 2
            else:
                self._recording_policy = recording_policy
        else:
            self._recording_policy = lambda episode_id: False
        logger.info(
            'Running Recording wrapper with recording_dir=%s policy=%s. To change this, pass recording_dir="..." to env.configure.',
            self._recording_dir, recording_policy)

        self._recording_notes = {
            'env_id': env.spec.id,
            'env_metadata': env.metadata,
            'env_spec_tags': env.spec.tags,
            'env_semantics_async': self._env_semantics_async,
            'env_semantics_autoreset': self._env_semantics_autoreset,
        }
        if recording_notes is not None:
            self._recording_notes.update(recording_notes)

        if self._recording_dir is not None:
            os.makedirs(self._recording_dir, exist_ok=True)

        self._instance_id = random_alphanumeric(6)
Ejemplo n.º 3
0
    def _configure(self,
                   recording_dir=None,
                   recording_policy=None,
                   recording_notes={},
                   **kwargs):
        """
Configure the wrapper. To make it record, configure the env with
env.configure(recording_dir='/path/to/results', recording_policy='capped_cubic')
  recording_dir:
    It will create files 'universe.recording.*.{jsonl|bin}' in that directory
  recording_policy:
    'capped_cubic' will record a subset of episodes (those that are a perfect cube: 0, 1, 8, 27, 64, 125, 216, 343, 512, 729, 1000, and every multiple of 1000 thereafter).
    'always' records all
    'never' records none

"""
        self._recording_dir = recording_dir
        if self._recording_dir is not None:
            if recording_policy == 'never' or recording_policy is False:
                self._recording_policy = lambda episode_id: False
            elif recording_policy == 'always' or recording_policy is True:
                self._recording_policy = lambda episode_id: True
            elif recording_policy == 'capped_cubic' or recording_policy is None:
                self._recording_policy = lambda episode_id: (
                    int(round(episode_id**(1. / 3)))**3 == episode_id
                ) if episode_id < 1000 else episode_id % 1000 < 2
            else:
                self._recording_policy = recording_policy
        else:
            self._recording_policy = lambda episode_id: False
        logger.info(
            'Running Recording wrapper with recording_dir=%s policy=%s. To change this, pass recording_dir="..." to env.configure.',
            self._recording_dir, recording_policy)

        self._recording_notes = recording_notes

        super(Recording, self)._configure(**kwargs)
        if self._recording_dir is not None:
            os.makedirs(self._recording_dir, exist_ok=True)
        self._episode_ids = [self._get_episode_id() for i in range(self.n)]
        self._step_ids = [0] * self.n

        self._instance_id = random_alphanumeric(6)
Ejemplo n.º 4
0
    def _configure(self, recording_dir=None, recording_policy=None, recording_notes={}, **kwargs):
        """
Configure the wrapper. To make it record, configure the env with
env.configure(recording_dir='/path/to/results', recording_policy='capped_cubic')
  recording_dir:
    It will create files 'universe.recording.*.{jsonl|bin}' in that directory
  recording_policy:
    'capped_cubic' will record a subset of episodes (those that are a perfect cube: 0, 1, 8, 27, 64, 125, 216, 343, 512, 729, 1000, and every multiple of 1000 thereafter).
    'always' records all
    'never' records none

"""
        self._recording_dir = recording_dir
        if self._recording_dir is not None:
            if recording_policy == 'never' or recording_policy is False:
                self._recording_policy = lambda episode_id: False
            elif recording_policy == 'always' or recording_policy is True:
                self._recording_policy = lambda episode_id: True
            elif recording_policy == 'capped_cubic' or recording_policy is None:
                self._recording_policy = lambda episode_id: (int(round(episode_id ** (1. / 3))) ** 3 == episode_id) if episode_id < 1000 else episode_id % 1000 < 2
            else:
                self._recording_policy = recording_policy
        else:
            self._recording_policy = lambda episode_id: False
        logger.info('Running Recording wrapper with recording_dir=%s policy=%s. To change this, pass recording_dir="..." to env.configure.', self._recording_dir, recording_policy)

        self._recording_notes = recording_notes

        super(Recording, self)._configure(**kwargs)
        if self._recording_dir is not None:
            os.makedirs(self._recording_dir, exist_ok=True)
        self._episode_ids = [self._get_episode_id() for i in range(self.n)]
        self._step_ids = [0] * self.n


        self._instance_id = random_alphanumeric(6)