예제 #1
0
def get_lhs_generator(generator_name, args):
    """
    LHS enumeration generators. create a new one and add it here to include in API.
    If program is given an out_dir argument, will pickle and save the enumeration locally for later use.
    :param generator_name: name of custom generator
    :param args: program args
    :return: generator function , number of free coefficients
    """
    if generator_name == 'biased_monoms':
        if args.poly_deg <= 0 or len(
                args.coeff_lim
        ) != 2 or args.coeff_lim[0] <= 0 or args.coeff_lim[1] <= 0:
            print(
                "Degree and limits must be positive. Expecting two coefficient limits."
            )
            raise AttributeError
        return lhs_generators.create_biased_monoms(args.poly_deg,
                                                   args.coeff_lim[0],
                                                   args.coeff_lim[1])
    if generator_name == 'standard':
        if args.poly_deg <= 0 or not isinstance(args.coeff_lim,
                                                int) or args.coeff_lim <= 0:
            print(
                "Degree and limits must be positive. Expecting a single coefficient limit."
            )
            raise AttributeError
        return lhs_generators.create_standard_lhs(args.poly_deg,
                                                  args.coeff_lim,
                                                  args.out_dir,
                                                  do_print=(not args.no_print))
예제 #2
0
 def test_ESMA_api3(
         self):  # Test search using an existing enumeration configuration.
     print('Creating and saving a temporary generic LHS enumeration.')
     custom_enum = create_standard_lhs(poly_deg=1,
                                       coefficients_limit=2,
                                       do_print=False)
     path = './tmp'
     with open(path, 'wb') as file:
         pickle.dump(custom_enum, file)
     print('Calling using API:')
     cmd = 'ESMA, -mode, search, -constant, e, -cycle_range, 2, 2, -lhs, ./tmp, -no_print'
     cmd = cmd.split(', ')
     parser = main.init_parser()
     args = parser.parse_args(cmd)
     print('Searching using generic LHS')
     results = main.enumerate_over_signed_rcf_main(args)
     os.remove(path)
     print('Deleted temporary generic LHS enumeration from disk')
     self.assertEqual(len(results), 13)
     adjusted = [[res[0], res[1], list(res[3])] for res in results]
     self.assertIn([(e / (e - 1)), [1, -1], [1, 0, -2, 0, 1]], adjusted)
     self.assertIn([(e /
                     (-2 + e)), [1, 1], [1, 0, 0, -1, 0, 0, -1, 0, 0, 1]],
                   adjusted)
     print('Search results are as expected.')
 def test_ESMA_api2(self): # Test standard build configuration.
     cmd = 'ESMA -out_dir ./tmp -mode build -lhs standard -poly_deg 1 -coeff_lim 1 -no_print'
     cmd = cmd.split(' ')
     parser = main.init_parser()
     args = parser.parse_args(cmd)
     lhs = main.enumerate_over_signed_rcf_main(args)
     print('Creating enumeration not through API to compare:')
     self.assertEqual(lhs, create_standard_lhs(poly_deg=1, coefficients_limit=1, do_print=(not args.no_print)))
     print("Identical enumerations.")
     file_there = os.path.exists('./tmp')
     self.assertTrue(file_there)
     os.remove('./tmp')
     print('Successfuly removed output file')
예제 #4
0
 def test_create_and_use_generic_lhs(self):
     generic_lhs = create_standard_lhs(poly_deg=1,
                                       coefficients_limit=2,
                                       out_path=None)
     enumerator = SignedRcfEnumeration(sym_constant=e,
                                       cycle_len_range=[2, 2],
                                       custom_enum=generic_lhs,
                                       do_print=False)
     with mpmath.workdps(self.precision):
         results, duplicates = enumerator.find_hits()
         flatten = (lambda l: [item for sublist in l for item in sublist])
         recurring = flatten([duplicates[key] for key in duplicates.keys()])
         adjusted = [[res[0], res[1], list(res[3])]
                     for res in (results + recurring)]
         self.assertTrue([(e /
                           (e - 1)), [1, -1], [1, 0, -2, 0, 1]] in adjusted)