Example #1
0
 def all_descriptions():
     """ Returns descriptions for all objects defined here. """
     s = dict()
     items = chain(Stats.statistics.items())
     
     for k, v in items:
         s[k] = WithDescription(name=v.get_name(),
                                desc=v.get_desc(),
                                symbol=v.get_symbol())
         
     
     config = get_dp_config()
     
     for objspec in config.specs.values():
         if not objspec:
             logger.warning('No %s defined? Just wondering...' % 
                            objspec.name)
         for k, v in objspec.items():
             symbol, desc = symbol_desc_from_string(v['desc'])
             if desc is None:
                 logger.warning('No description entry %r.' % k)
             s[k] = WithDescription(name=k, desc=desc, symbol=symbol)
             # print k, s[k]
             
     s.update(Stats.misc_descriptions)            
     return s
Example #2
0
    def init(self):
        id_discdds = self.config.id_discdds

        dp_config = get_dp_config()

        dp_config.load(self.config.config_dir)
        self.discdds = dp_config.discdds.instance(id_discdds)

        plan = self.config.plan
        self.action = self.discdds.plan2action(plan)
Example #3
0
 def init(self):
     id_discdds = self.config.id_discdds
     
     dp_config = get_dp_config()
 
     dp_config.load(self.config.config_dir)
     self.discdds = dp_config.discdds.instance(id_discdds)
     
     plan = self.config.plan
     self.action = self.discdds.plan2action(plan)
 def init_diffeo(self, shape):
     id_symdiffeo = self.config.id_symdiffeo
     symdiffeo = get_dp_config().symdiffeos.instance(id_symdiffeo)
     label = 'tmp'
     original_cmd = [np.zeros(1)]
     self.info('creating diffeo_action')
     contracts.disable_all()
     self.diffeo_action = \
         diffeo_action_from_symdiffeo(symdiffeo, shape,
                                      label, original_cmd)
     self.info('..done')
Example #5
0
    def __init__(self, plan_time, plan_max_length, metric_goal):
        logger.info('initiating sampleplanner')
        print('pr: initiating sampleplanner')
        DiffeoPlanningAlgo.__init__(self)
        config = get_dp_config()

        self.metric_goal = config.distances.instance(metric_goal)
        self.plan_time = plan_time
        self.max_length = plan_max_length
        logger.info('done')
        print('pr: done')
Example #6
0
 def __init__(self, plan_time, plan_max_length, metric_goal):
     logger.info('initiating sampleplanner')
     print('pr: initiating sampleplanner')
     DiffeoPlanningAlgo.__init__(self)
     config = get_dp_config()
     
     self.metric_goal = config.distances.instance(metric_goal)
     self.plan_time = plan_time
     self.max_length = plan_max_length
     logger.info('done')
     print('pr: done')
Example #7
0
    def get_id_discdds2testcases(self, alltestcases):
        x = {}
        from diffeoplan import get_dp_config
        config = get_dp_config()
        if not alltestcases:
            testcases = config.testcases.expand_names(self.testcases)          
        else:
            testcases = expand_string(self.testcases, alltestcases)

        x[self.discdds] = testcases
        return x
Example #8
0
 def init_diffeo(self, shape):
     id_symdiffeo = self.config.id_symdiffeo
     symdiffeo = get_dp_config().symdiffeos.instance(id_symdiffeo)
     label = 'tmp'
     original_cmd = [np.zeros(1)]
     self.info('creating diffeo_action')
     contracts.disable_all()
     self.diffeo_action = \
         diffeo_action_from_symdiffeo(symdiffeo, shape,
                                      label, original_cmd)
     self.info('..done')
 def init(self):
     contracts.disable_all()
     id_discdds = self.config.id_discdds
     
     dp_config = get_dp_config()
 
     dp_config.load(self.config.config_dir)
     self.discdds = dp_config.discdds.instance(id_discdds)
     
     N = self.config.nsteps
     m = make_matrix(nsteps=N, mult=self.config.mult)
     
     cmd_to_action = {'a': 3, 'b': 2, 'c': 1, 'd': 0}
     cmd_inv = {'a': 'c', 'b': 'd'}
     
     mult = self.config.mult
     sequence = {0: 0, 1: 1 * mult, 2: 2 * mult, 3: 3 * mult}
     
     @contract(ins='tuple(int,str)', returns='list[int]')
     def normalize_instruction(ins):
         num, cmd = ins
         if num < 0:
             cmd = cmd_inv[cmd]
             num = -num 
         assert num >= 0
         k = cmd_to_action[cmd]
         n = sequence[num]
         return [k] * n
     
     @contract(splan='list[P](tuple(int,str))', returns='list(int)')
     def normalize_splan(splan):
         plan = []
         for ins in splan:
             plan.extend(normalize_instruction(ins))
         return plan
     
     M = 2 * N + 1
     self.actions = []
     for i, j in itertools.product(range(M), range(M)):
         m[i][j] = normalize_splan(m[i][j])
         action = self.discdds.plan2action(m[i][j])
         self.actions.append(action)
     
     self.info('shape: %s' % str(self.discdds.get_shape()))
     self.M = M
Example #10
0
    def init(self):
        contracts.disable_all()
        id_discdds = self.config.id_discdds

        dp_config = get_dp_config()

        dp_config.load(self.config.config_dir)
        self.discdds = dp_config.discdds.instance(id_discdds)

        N = self.config.nsteps
        m = make_matrix(nsteps=N, mult=self.config.mult)

        cmd_to_action = {'a': 3, 'b': 2, 'c': 1, 'd': 0}
        cmd_inv = {'a': 'c', 'b': 'd'}

        mult = self.config.mult
        sequence = {0: 0, 1: 1 * mult, 2: 2 * mult, 3: 3 * mult}

        @contract(ins='tuple(int,str)', returns='list[int]')
        def normalize_instruction(ins):
            num, cmd = ins
            if num < 0:
                cmd = cmd_inv[cmd]
                num = -num
            assert num >= 0
            k = cmd_to_action[cmd]
            n = sequence[num]
            return [k] * n

        @contract(splan='list[P](tuple(int,str))', returns='list(int)')
        def normalize_splan(splan):
            plan = []
            for ins in splan:
                plan.extend(normalize_instruction(ins))
            return plan

        M = 2 * N + 1
        self.actions = []
        for i, j in itertools.product(range(M), range(M)):
            m[i][j] = normalize_splan(m[i][j])
            action = self.discdds.plan2action(m[i][j])
            self.actions.append(action)

        self.info('shape: %s' % str(self.discdds.get_shape()))
        self.M = M
Example #11
0
    def go(self):
        options = self.get_options()
        allofthem = options.type == '*'
        config = get_dp_config()

        if options.type == 'distances' or options.type == True:
            print('Distances:')
            print(config.distances.summary_string_id_desc_patterns())

        if options.type == 'algos' or allofthem:
            print('Algorithms:')
            print(config.algos.summary_string_id_desc_patterns())

        if options.type == 'batches' or allofthem:
            print('Batch experiments:')
            print(config.batches.summary_string_id_desc_patterns())

        if options.type == 'testcases' or allofthem:
            if options.verbose:
                print('Test cases:')
                print(config.testcases.summary_string_id_desc_patterns())
            else:
                n = len(config.testcases)
                print('There are %d testcases; use -v to show them' % n)
Example #12
0
    def go(self):
        options = self.get_options()
        allofthem = options.type == "*"
        config = get_dp_config()

        if options.type == "distances" or options.type == True:
            print("Distances:")
            print(config.distances.summary_string_id_desc_patterns())

        if options.type == "algos" or allofthem:
            print("Algorithms:")
            print(config.algos.summary_string_id_desc_patterns())

        if options.type == "batches" or allofthem:
            print("Batch experiments:")
            print(config.batches.summary_string_id_desc_patterns())

        if options.type == "testcases" or allofthem:
            if options.verbose:
                print("Test cases:")
                print(config.testcases.summary_string_id_desc_patterns())
            else:
                n = len(config.testcases)
                print("There are %d testcases; use -v to show them" % n)
Example #13
0
 def __init__(self, plans_generator, reduce_tolerance, distance):
     self.reduce_tolerance = reduce_tolerance
     self.plans_generator = instantiate_spec(plans_generator)
     _, self.distance = get_dp_config().distances.instance_smarter(distance)
Example #14
0
def create_bench_jobs(context, batch, alltestcases):
    '''
    
    :param context: 
    :param batch: 
    :param alltestcases: list of testcases that are going to be autogenerated.
    '''
    config = get_dp_config()
    algos = config.algos.expand_names(batch.algorithms)
#     if not alltestcases:
#         testcases = config.testcases.expand_names(batch.testcases)          
#     else:
#         testcases = expand_string(batch.testcases, alltestcases)

    # dict(id_algo, id_tc, id_discdds, plan_length) => PlanningResults
    allplanning = StoreResults()
    
    # dict(id_algo, id_tc, id_discdds, plan_length) => resultstats
    allruns = StoreResults() 
    
    # dict(id_algo, id_tc) => DiffeoPlanningAlgorithm
    algoinit = StoreResults()
    
    config = get_dp_config()
    
    # Let's instantiate all test cases and sort them by discdds
    # so that we do only one initialization per algorithms

    # id -> {dds -> [tc]}    
    id_discdds2testcases = defaultdict(lambda: {})
#     alltc = {}  # id -> Promise TestCase

    id2t = batch.get_id_discdds2testcases(alltestcases)
    for idd, idd_tcs in id2t.items():
        for tcc in idd_tcs:
            tc = context.comp(instantiate_testcase, tcc)
            # alltc[tcc]
            id_discdds2testcases[idd][tcc] = tc
            
    # Load discdds before, they might be automatically generated
    # as well so we want the generation to happen only once.
    discdds = {}  # id -> Promise DiffeoSystem
    for id_discdds in id_discdds2testcases: 
        discdds[id_discdds] = context.comp(instantiate_discdds, id_discdds)
        
    # for each algorithm
    for id_algo in algos:
        config.algos[id_algo]  # check it is in the configuration
            
        # for each dynamics
        for id_discdds, dds in discdds.items():
            job_id = 'init-%s-%s' % (id_algo, id_discdds)
            
            # initialize the algorithm for that dynamics
            algo = context.comp(init_algorithm, id_algo, id_discdds,
                                discdds[id_discdds], job_id=job_id)
            algoinit[dict(id_algo=id_algo, id_discdds=id_discdds)] = algo
            
            # for each test case in that dynamics
            for id_tc, tc in id_discdds2testcases[id_discdds].items():
                # run the planning
                job_id = 'plan-%s-%s' % (id_algo, id_tc)
                result = context.comp(run_planning, id_algo,
                              id_tc, tc, algo, job_id=job_id)
                
                # compute statistics
                result_stats = context.comp(run_planning_stats, result,
                                    dds, tc,
                                    job_id=job_id + '-stats') 
    
                attrs = dict(id_algo=id_algo, id_tc=id_tc,
                             id_discdds=id_discdds)
                warnings.warn('this was an important attribute to have...')
                # true_plan_length=len(tc.true_plan))
                allruns[attrs] = result_stats
                allplanning[attrs] = result
    
    jobs_report_algo_init(context, algoinit)
    jobs_report_tc(context, id_discdds2testcases)
    jobs_report_dds(context, discdds)

    allstats = StoreResults()
    for key, run in allruns.items():
        allstats[key] = context.comp(results2stats_dict, run,
                             job_id=comp_stage_job_id(run, 'statsdict'))

    jobs_tables(context, allstats)
    jobs_visualization(context, allruns)
Example #15
0
def create_bench_jobs(context, batch, alltestcases):
    '''
    
    :param context: 
    :param batch: 
    :param alltestcases: list of testcases that are going to be autogenerated.
    '''
    config = get_dp_config()
    algos = config.algos.expand_names(batch.algorithms)
    #     if not alltestcases:
    #         testcases = config.testcases.expand_names(batch.testcases)
    #     else:
    #         testcases = expand_string(batch.testcases, alltestcases)

    # dict(id_algo, id_tc, id_discdds, plan_length) => PlanningResults
    allplanning = StoreResults()

    # dict(id_algo, id_tc, id_discdds, plan_length) => resultstats
    allruns = StoreResults()

    # dict(id_algo, id_tc) => DiffeoPlanningAlgorithm
    algoinit = StoreResults()

    config = get_dp_config()

    # Let's instantiate all test cases and sort them by discdds
    # so that we do only one initialization per algorithms

    # id -> {dds -> [tc]}
    id_discdds2testcases = defaultdict(lambda: {})
    #     alltc = {}  # id -> Promise TestCase

    id2t = batch.get_id_discdds2testcases(alltestcases)
    for idd, idd_tcs in id2t.items():
        for tcc in idd_tcs:
            tc = context.comp(instantiate_testcase, tcc)
            # alltc[tcc]
            id_discdds2testcases[idd][tcc] = tc

    # Load discdds before, they might be automatically generated
    # as well so we want the generation to happen only once.
    discdds = {}  # id -> Promise DiffeoSystem
    for id_discdds in id_discdds2testcases:
        discdds[id_discdds] = context.comp(instantiate_discdds, id_discdds)

    # for each algorithm
    for id_algo in algos:
        config.algos[id_algo]  # check it is in the configuration

        # for each dynamics
        for id_discdds, dds in discdds.items():
            job_id = 'init-%s-%s' % (id_algo, id_discdds)

            # initialize the algorithm for that dynamics
            algo = context.comp(init_algorithm,
                                id_algo,
                                id_discdds,
                                discdds[id_discdds],
                                job_id=job_id)
            algoinit[dict(id_algo=id_algo, id_discdds=id_discdds)] = algo

            # for each test case in that dynamics
            for id_tc, tc in id_discdds2testcases[id_discdds].items():
                # run the planning
                job_id = 'plan-%s-%s' % (id_algo, id_tc)
                result = context.comp(run_planning,
                                      id_algo,
                                      id_tc,
                                      tc,
                                      algo,
                                      job_id=job_id)

                # compute statistics
                result_stats = context.comp(run_planning_stats,
                                            result,
                                            dds,
                                            tc,
                                            job_id=job_id + '-stats')

                attrs = dict(id_algo=id_algo,
                             id_tc=id_tc,
                             id_discdds=id_discdds)
                warnings.warn('this was an important attribute to have...')
                # true_plan_length=len(tc.true_plan))
                allruns[attrs] = result_stats
                allplanning[attrs] = result

    jobs_report_algo_init(context, algoinit)
    jobs_report_tc(context, id_discdds2testcases)
    jobs_report_dds(context, discdds)

    allstats = StoreResults()
    for key, run in allruns.items():
        allstats[key] = context.comp(results2stats_dict,
                                     run,
                                     job_id=comp_stage_job_id(
                                         run, 'statsdict'))

    jobs_tables(context, allstats)
    jobs_visualization(context, allruns)
Example #16
0
 def __init__(self, plans_generator, reduce_tolerance, distance):
     self.reduce_tolerance = reduce_tolerance
     self.plans_generator = instantiate_spec(plans_generator)
     _, self.distance = get_dp_config().distances.instance_smarter(distance)