Ejemplo n.º 1
0
def test_full_execution(executable, tmpdir, comm):
    from pylada.process.iterator import IteratorProcess
    from pylada.process.tests.functional import Functional
    functional = Functional(executable, [50])
    program = IteratorProcess(functional, outdir=str(tmpdir))
    program.start(comm)
    program.wait()
    assert True
Ejemplo n.º 2
0
def test_fail_midway(executable, tmpdir, comm):
    from pytest import raises
    from pylada.process.iterator import IteratorProcess
    from pylada.process import Fail
    from pylada.process.tests.functional import Functional

    functional = Functional(executable, [50], fail='midway')
    program = IteratorProcess(functional, outdir=str(tmpdir))
    with raises(Fail):
        program.start(comm)
        program.wait()
Ejemplo n.º 3
0
def test_full_execution(executable, tmpdir, comm):
    from pylada.process.iterator import IteratorProcess
    functional = FakeFunctional(executable, [50])
    program = IteratorProcess(functional, outdir=str(tmpdir))
    program.start(comm)
    program.wait()
    assert True
Ejemplo n.º 4
0
def test_fail_midway(executable, tmpdir, comm):
    from pytest import raises
    from pylada.process.iterator import IteratorProcess
    from pylada.process import Fail

    functional = FakeFunctional(executable, [50], fail='midway')
    program = IteratorProcess(functional, outdir=str(tmpdir))
    with raises(Fail):
        program.start(comm)
        program.wait()
Ejemplo n.º 5
0
def test(nbprocs, ppn, executable):
  from os import getcwd
  print 'IN DIRECTORY', getcwd()
  from pylada.process.mpi import create_global_comm
  from pylada.process.iterator import IteratorProcess
  from functional import Functional
  import pylada

  print 'CREATING GLOBAL COMM'
  pylada.default_comm['ppn'] = ppn
  pylada.default_comm['n'] = nbprocs
  create_global_comm(nbprocs)

  print 'CREATING FUNCTIONALS AND PROCESSES'
  lfunc = Functional(executable, range(ppn*10, ppn*10+8))
  long = IteratorProcess(lfunc, outdir='long')

  sfunc = Functional(executable, [10])
  short0 = IteratorProcess(sfunc, outdir='short0')
  short1 = IteratorProcess(sfunc, outdir='short1') 
  
  print 'CREATING COMMUNICATORS'
  long_comm = pylada.default_comm.lend(3*(nbprocs//4))
  assert len(long_comm.machines) == 2
  short_comm0 = pylada.default_comm.lend(pylada.default_comm['n']//2)
  assert len(short_comm0.machines) == 1
  short_comm1 = pylada.default_comm.lend('all')
  assert len(short_comm1.machines) == 1

  print 'STARTING LONG PROCESS'
  long.start(long_comm)
  assert not long.poll()
  print 'STARTING SHORT PROCESSES'
  short0.start(short_comm0)
  short1.start(short_comm1)
  print 'TESTING PROCESS OVERLAP'
  assert not long.poll()
  print 'TESTED PROCESS OVERLAP'
  short0.wait()
  print 'FIRST SHORT PROCESS FINISHED'
  assert not long.poll()
  print 'TESTED PROCESS OVERLAP'
  short1.wait()
  print 'SECOND SHORT PROCESS FINISHED'
  assert not long.poll()
  print 'TESTED PROCESS OVERLAP'
  long.wait()
  print 'LONG PROCESS FINISHED'

  assert lfunc.Extract('long').success
  assert sfunc.Extract('short0').success
  assert sfunc.Extract('short1').success
  print 'END'
Ejemplo n.º 6
0
def test(executable):
    """ Tests IteratorProcess. Includes failure modes.  """
    from tempfile import mkdtemp
    from shutil import rmtree
    from numpy import all, arange, abs, array
    from pylada.process.iterator import IteratorProcess
    from pylada.process import Fail, NotStarted
    from pylada import default_comm
    from functional import Functional
    comm = default_comm.copy()
    dir = mkdtemp()
    try:
        functional = Functional(executable, range(8))
        program = IteratorProcess(functional, outdir=dir)
        # program not started. should fail.
        try:
            program.poll()
        except NotStarted:
            pass
        else:
            raise Exception()
        try:
            program.wait()
        except NotStarted:
            pass
        else:
            raise Exception()

        # now starting for real.
        program.start(comm)
        while not program.poll():
            continue
        extract = functional.Extract(dir)
        assert extract.success
        assert all(arange(8) - extract.order == 0)
        assert all(abs(extract.pi - array([0.0, 3.2, 3.162353, 3.150849,
                                           3.146801, 3.144926, 3.143907, 3.143293]))\
                    < 1e-5 )
        assert all(abs(extract.error - array([3.141593, 0.05840735, 0.02076029, 0.009256556,
                                              0.005207865, 0.00333321, 0.002314774, 0.001700664]))\
                    < 1e-5 )
        assert all(n['n'] == comm['n'] for n in extract.comm)
        # restart
        assert program.poll()
        program.start(comm)
        assert program.process is None
        assert program.poll()
        # true restart
        program = IteratorProcess(functional, outdir=dir)
        program.start(comm)
        assert program.process is None
        assert program.poll()
        extract = functional.Extract(dir)
        assert extract.success
        assert all(arange(8) - extract.order == 0)
        assert all(abs(extract.pi - array([0.0, 3.2, 3.162353, 3.150849,
                                           3.146801, 3.144926, 3.143907, 3.143293]))\
                    < 1e-5 )
        assert all(abs(extract.error - array([3.141593, 0.05840735, 0.02076029, 0.009256556,
                                              0.005207865, 0.00333321, 0.002314774, 0.001700664]))\
                    < 1e-5 )
    finally:
        try:
            rmtree(dir)
        except:
            pass

    try:
        functional = Functional(executable, [666])
        program = IteratorProcess(functional, outdir=dir)
        program.start(comm)
        program.wait()
    except Fail:
        pass
    else:
        raise Exception
    finally:
        try:
            rmtree(dir)
        except:
            pass
    try:
        functional = Functional(executable, [667])
        program = IteratorProcess(functional, outdir=dir)
        program.start(comm)
        program.wait()
    finally:
        try:
            rmtree(dir)
        except:
            pass
Ejemplo n.º 7
0
def test_iterator(executable, tmpdir, comm):
    """Tests IteratorProcess.

    Includes failure modes.
    """
    from pytest import raises
    from numpy import all, arange, abs, array
    from pylada.process.iterator import IteratorProcess
    from pylada.process import Fail, NotStarted
    from pylada.process.tests.functional import Functional

    functional = Functional(executable, list(range(8)))
    program = IteratorProcess(functional, outdir=str(tmpdir))
    # program not started. should fail.
    with raises(NotStarted):
        program.poll()

    with raises(NotStarted):
        program.wait()

    # now starting for real.
    program.start(comm)
    while not program.poll():
        continue
    extract = functional.Extract(str(tmpdir))
    assert extract.success
    assert all(arange(8) - extract.order == 0)
    expected = [
        0.0, 3.2, 3.162353, 3.150849, 3.146801, 3.144926, 3.143907, 3.143293
    ]
    assert all(abs(extract.pi - array(expected)) < 1e-5)
    expected = [
        3.141593, 0.05840735, 0.02076029, 0.009256556, 0.005207865, 0.00333321,
        0.002314774, 0.001700664
    ]
    assert all(abs(extract.error - array(expected)) < 1e-5)
    assert all(n['n'] == comm['n'] for n in extract.comm)
    # restart
    assert program.poll()
    program.start(comm)
    assert program.process is None
    assert program.poll()
    # true restart
    program = IteratorProcess(functional, outdir=str(tmpdir))
    program.start(comm)
    assert program.process is None
    assert program.poll()
    extract = functional.Extract(str(tmpdir))
    assert extract.success
    assert all(arange(8) - extract.order == 0)
    expected = [
        0.0, 3.2, 3.162353, 3.150849, 3.146801, 3.144926, 3.143907, 3.143293
    ]
    assert all(abs(extract.pi - array(expected)) < 1e-5)
    expected = [
        3.141593, 0.05840735, 0.02076029, 0.009256556, 0.005207865, 0.00333321,
        0.002314774, 0.001700664
    ]
    assert all(abs(extract.error - array(expected)) < 1e-5)
Ejemplo n.º 8
0
def test(executable):
  """ Tests IteratorProcess. Includes failure modes.  """
  from tempfile import mkdtemp
  from shutil import rmtree
  from numpy import all, arange, abs, array
  from pylada.process.iterator import IteratorProcess
  from pylada.process import Fail, NotStarted
  from pylada import default_comm
  from functional import Functional
  comm = default_comm.copy()
  dir = mkdtemp()
  try: 
    functional = Functional(executable, range(8))
    program = IteratorProcess(functional, outdir=dir)
    # program not started. should fail.
    try: program.poll()
    except NotStarted: pass
    else: raise Exception()
    try: program.wait()
    except NotStarted: pass
    else: raise Exception()

    # now starting for real.
    program.start(comm)
    while not program.poll():  continue
    extract = functional.Extract(dir)
    assert extract.success
    assert all(arange(8) - extract.order == 0)
    assert all(abs(extract.pi - array([0.0, 3.2, 3.162353, 3.150849,
                                       3.146801, 3.144926, 3.143907, 3.143293]))\
                < 1e-5 )
    assert all(abs(extract.error - array([3.141593, 0.05840735, 0.02076029, 0.009256556,
                                          0.005207865, 0.00333321, 0.002314774, 0.001700664]))\
                < 1e-5 )
    assert all(n['n'] == comm['n'] for n in extract.comm)
    # restart
    assert program.poll()
    program.start(comm)
    assert program.process is None
    assert program.poll()
    # true restart
    program = IteratorProcess(functional, outdir=dir)
    program.start(comm)
    assert program.process is None
    assert program.poll()
    extract = functional.Extract(dir)
    assert extract.success
    assert all(arange(8) - extract.order == 0)
    assert all(abs(extract.pi - array([0.0, 3.2, 3.162353, 3.150849,
                                       3.146801, 3.144926, 3.143907, 3.143293]))\
                < 1e-5 )
    assert all(abs(extract.error - array([3.141593, 0.05840735, 0.02076029, 0.009256556,
                                          0.005207865, 0.00333321, 0.002314774, 0.001700664]))\
                < 1e-5 )
  finally:
    try: rmtree(dir)
    except: pass

  try: 
    functional = Functional(executable, [666])
    program = IteratorProcess(functional, outdir=dir)
    program.start(comm)
    program.wait()
  except Fail: pass
  else: raise Exception
  finally:
    try: rmtree(dir)
    except: pass
  try: 
    functional = Functional(executable, [667])
    program = IteratorProcess(functional, outdir=dir)
    program.start(comm)
    program.wait()
  finally:
    try: rmtree(dir)
    except: pass
Ejemplo n.º 9
0
def test(nbprocs, ppn, executable):
  from os import getcwd
  print 'IN DIRECTORY', getcwd()
  from pylada.process.mpi import create_global_comm
  from pylada.process.iterator import IteratorProcess
  from functional import Functional
  import pylada

  print 'CREATING GLOBAL COMM'
  pylada.default_comm['ppn'] = ppn
  pylada.default_comm['n'] = nbprocs
  create_global_comm(nbprocs)

  print 'CREATING FUNCTIONALS AND PROCESSES'
  lfunc = Functional(executable, range(ppn*10, ppn*10+8))
  long = IteratorProcess(lfunc, outdir='long')

  sfunc = Functional(executable, [10])
  short0 = IteratorProcess(sfunc, outdir='short0')
  short1 = IteratorProcess(sfunc, outdir='short1') 
  
  print 'CREATING COMMUNICATORS'
  long_comm = pylada.default_comm.lend(3*(nbprocs//4))
  assert len(long_comm.machines) == 2
  short_comm0 = pylada.default_comm.lend(pylada.default_comm['n']//2)
  assert len(short_comm0.machines) == 1
  short_comm1 = pylada.default_comm.lend('all')
  assert len(short_comm1.machines) == 1

  print 'STARTING LONG PROCESS'
  long.start(long_comm)
  assert not long.poll()
  print 'STARTING SHORT PROCESSES'
  short0.start(short_comm0)
  short1.start(short_comm1)
  print 'TESTING PROCESS OVERLAP'
  assert not long.poll()
  print 'TESTED PROCESS OVERLAP'
  short0.wait()
  print 'FIRST SHORT PROCESS FINISHED'
  assert not long.poll()
  print 'TESTED PROCESS OVERLAP'
  short1.wait()
  print 'SECOND SHORT PROCESS FINISHED'
  assert not long.poll()
  print 'TESTED PROCESS OVERLAP'
  long.wait()
  print 'LONG PROCESS FINISHED'

  assert lfunc.Extract('long').success
  assert sfunc.Extract('short0').success
  assert sfunc.Extract('short1').success
  print 'END'