Exemplo n.º 1
0
def test_partition():
  random.seed(56565656)
  init_threads(-1,-1)
  slices = []
  for slice in xrange(7):
    # Grab half the sections of this slice
    sections = all_boards_sections(slice,8)
    random.shuffle(sections)
    slices.append(sections_t(slice,sections[:(len(sections)+1)//2]))
  for sections in descendent_sections([[4,4],[4,4],[4,5],[5,4]],35):
    if len(sections.sections):
      slices.append(sections)
  for sections in slices:
    for ranks in 1,2,3,5:
      for key in 0,1,17:
        with Log.scope('partition test: slice %d, ranks %d, key %d'%(sections.slice,ranks,key)):
          partition = random_partition_t(key,ranks,sections) if key else simple_partition_t(ranks,sections,False)
          partition_test(partition)
Exemplo n.º 2
0
def test_counts():
  init_threads(-1,-1)
  for slice in xrange(5):
    with Log.scope('counting slice %d'%slice):
      sections = sections_t(slice,all_boards_sections(slice,8))
      good_counts = meaningless_counts(all_boards(slice,1))
      good_nodes = sum(product(section_shape(s)) for s in sections.sections)
      for key in 0,1,17:
        with Log.scope('partition key %d'%key):
          partition = random_partition_t(key,1,sections) if key else simple_partition_t(1,sections,False)
          store = compacting_store_t(estimate_block_heap_size(partition,0))
          blocks = meaningless_block_store(partition,0,0,store)
          Log.write('blocks = %d, correct = %d'%(blocks.total_nodes,good_nodes))
          assert blocks.total_nodes==good_nodes
          bad_counts = sum_section_counts(sections.sections,blocks.section_counts)
          Log.write('bad counts  = %s\ngood counts = %s'%(bad_counts,good_counts))
          assert all(bad_counts==good_counts)
Exemplo n.º 3
0
def run(cmd):
    Log.write(cmd)
    if not nop:
        subprocess.check_call(cmd.split())
Exemplo n.º 4
0
        check(wdir)
        if extras:
            check(wdir, reader_test=slice - 1, high_test=slice - 2)
        if restart:
            tdir = wdir + '-restart-test'
            run('%s --restart %s/slice-%d.pentago --dir %s --test restart' %
                (base, wdir, slice - 1, tdir))
            rdir = wdir + '-restarted'
            run('%s --restart %s/slice-%d.pentago --dir %s' %
                (base, wdir, slice - 1, rdir))
            check(rdir)


def test_meaningless_simple(dir=None):
    meaningless_test(0, dir)


def test_meaningless_random(dir=None):
    meaningless_test(17, dir, restart=1, extras=1)


if __name__ == '__main__':
    Log.configure('test', False, False, 100)
    if '-n' in sys.argv:
        nop = True
    elif not os.path.exists('tmp'):
        os.mkdir('tmp')
    test_write('tmp')
    test_meaningless_simple('tmp')
    test_meaningless_random('tmp')
Exemplo n.º 5
0
    assert all(input==output)
    return compressed
  # Test a highly compressible sequence
  regular = arange(64//4*1873).view(uint64).reshape(-1,2,4)
  compressed = compress_check(regular)
  assert compressed[0]==1
  ratio = len(compressed)/regular.nbytes
  assert ratio < .314
  # Test various random (incompressible) sequences
  random.seed(18731)
  for n in 0,64,64*1873:
    bad = fromstring(random.bytes(n),dtype=uint64).reshape(-1,2,4)
    compressed = compress_check(bad)
    assert compressed[0]==0
    assert len(compressed)==bad.nbytes+1

def test_local_fast_compress():
  test_fast_compress(local=True)

def test_compacting_store():
  init_threads(-1,-1)
  compacting_store_test()
  
if __name__=='__main__':
  Log.configure('test',False,False,100)
  test_counts()
  test_partition()
  test_simple_partition()
  test_fast_compress()
  test_local_fast_compress()
Exemplo n.º 6
0
                                      and name not in positional),
                            type=converter(prop),
                            help=help(prop),
                            action=PropAction)

    # Add positional arguments
    for name in positional:
        prop = props.get(name)
        # NEEDS A CHECK HERE, AS SOME POSITIONALS FAIL (e.g. solar/layout)
        parser.add_argument(fix_name(name),
                            nargs='*' if type(prop()) == list else '?',
                            type=converter(prop),
                            action=PropAction)

    # Avoid jumbled output if we're inside a Log scope
    Log.flush()

    # Parse the input
    parser.parse_args()

    # Check for missing positional arguments
    for name in positional:
        prop = props.get(name)
        if prop.required and name not in props_set:
            parser.error('missing positional argument %s' % fix_name(name))

    # Verify that we're able to convert the current prop values back into a command line.
    # It's very annoying to go through a whole bunch of setup only to fine that a bug
    # presents one from saving work.
    command(props, drop_defaults=True)
    command(props, drop_defaults=False)
Exemplo n.º 7
0
            required=(prop.required and name not in positional),
            type=converter(prop),
            help=help(prop),
            action=PropAction
        )

    # Add positional arguments
    for name in positional:
        prop = props.get(name)
        # NEEDS A CHECK HERE, AS SOME POSITIONALS FAIL (e.g. solar/layout)
        parser.add_argument(
            fix_name(name), nargs="*" if type(prop()) == list else "?", type=converter(prop), action=PropAction
        )

    # Avoid jumbled output if we're inside a Log scope
    Log.flush()

    # Parse the input
    parser.parse_args()

    # Check for missing positional arguments
    for name in positional:
        prop = props.get(name)
        if prop.required and name not in props_set:
            parser.error("missing positional argument %s" % fix_name(name))

    # Verify that we're able to convert the current prop values back into a command line.
    # It's very annoying to go through a whole bunch of setup only to fine that a bug
    # presents one from saving work.
    command(props, drop_defaults=True)
    command(props, drop_defaults=False)
Exemplo n.º 8
0
def run(cmd):
    Log.write(cmd)
    if not nop:
        subprocess.check_call(cmd.split())
Exemplo n.º 9
0
        )
        run("%s --dir %s" % (base, wdir))
        check(wdir)
        if extras:
            check(wdir, reader_test=slice - 1, high_test=slice - 2)
        if restart:
            tdir = wdir + "-restart-test"
            run("%s --restart %s/slice-%d.pentago --dir %s --test restart" % (base, wdir, slice - 1, tdir))
            rdir = wdir + "-restarted"
            run("%s --restart %s/slice-%d.pentago --dir %s" % (base, wdir, slice - 1, rdir))
            check(rdir)


def test_meaningless_simple(dir=None):
    meaningless_test(0, dir)


def test_meaningless_random(dir=None):
    meaningless_test(17, dir, restart=1, extras=1)


if __name__ == "__main__":
    Log.configure("test", False, False, 100)
    if "-n" in sys.argv:
        nop = True
    elif not os.path.exists("tmp"):
        os.mkdir("tmp")
    test_write("tmp")
    test_meaningless_simple("tmp")
    test_meaningless_random("tmp")
Exemplo n.º 10
0
def optimize_generator(x0,step0,tolerance,verbose=False):
  # Initialize simplex 
  d = len(x0)
  x = empty((d+1,d))
  x[:] = asarray(x0).reshape(1,d)
  for i in xrange(d):
    x[i+1,i] += step0
  f = empty(d+1)
  for i in xrange(d+1):
    f[i] = yield x[i],False
    if verbose:
      Log.write('nelder-mead: initialized f(%s) = %g'%(x[i],f[i]))

  # Control parameters
  alpha = 1.
  gamma = 2.
  rho = .5
  sigma = .5

  # Loop until convergence
  while 1:
    # Sort vertices in increasing order of f
    p = sorted(xrange(d+1),key=lambda i:f[i])
    f = f[p]
    x = x[p]

    if verbose:
      Log.write('nelder-mead: best  x = %s, f(x) = %g'%(x[0],f[0]))
      Log.write('nelder-mead: worst x = %s, f(x) = %g'%(x[-1],f[-1]))

    # Check if we're converged 
    diameter = max(magnitude(x[i]-x[j]) for i in xrange(d+1) for j in xrange(i+1,d+1))
    if verbose:
      Log.write('nelder-mead: diameter = %g'%diameter)
    if diameter <= tolerance:
      yield x[0],True
      return

    def replace(fn,xn):
      f[-1] = fn
      x[-1] = xn

    # Perform reflection
    xm = x[:d].mean(axis=0)
    xr = xm + alpha*(xm-x[-1])
    fr = yield xr,False
    if f[0] <= fr <= f[-2]: # Accept reflection
      if verbose:
        Log.write('nelder-mead: reflected')
      replace(fr,xr)
    elif fr <= f[0]: # other expansion
      xe = xm + gamma*(xm-x[-1])
      fe = yield xe,False
      if fe < fr:
        if verbose:
          Log.write('nelder-mead: expansion succeeded')
        replace(fe,xe)
      else:
        if verbose:
          Log.write('nelder-mead: expansion failed')
        replace(fr,xr)
    else: # other contraction
      xc = x[-1] + rho*(xm-x[-1])
      fc = yield xc,False
      if fc < f[-1]:
        if verbose:
          Log.write('nelder-mead: contracted')
        replace(fc,xc)
      else: # All else failed; perform reduction
        if verbose:
          Log.write('nelder-mead: reduced')
        for i in xrange(1,d+1):
          x[i] = x[0] + sigma*(x[i]-x[0])
          f[i] = yield x[i],False