Exemplo n.º 1
0
def test_help():
    exe = get_exe()

    help_text = 'Usage: qmca'

    command = sys.executable + ' {}'.format(exe)
    out, err, rc = execute(command)
    assert (help_text in out)

    command = sys.executable + ' {} -h'.format(exe)
    out, err, rc = execute(command)
    assert (help_text in out)
Exemplo n.º 2
0
def run(c, cxx, testsuite, fails, out, config='wasm'):
  """Compile all torture tests."""
  assert os.path.isfile(c), 'Cannot find C compiler at %s' % c
  assert os.path.isfile(cxx), 'Cannot find C++ compiler at %s' % cxx
  assert os.path.isdir(testsuite), 'Cannot find testsuite at %s' % testsuite
  # TODO(jfb) Also compile other C tests, as well as C++ tests under g++.dg.
  c_torture = os.path.join(testsuite, 'gcc.c-torture', 'execute')
  assert os.path.isdir(c_torture), ('Cannot find C torture tests at %s' %
                                    c_torture)
  assert os.path.isdir(out), 'Cannot find outdir %s' % out
  c_test_files = glob.glob(os.path.join(c_torture, '*c'))
  cflags = CFLAGS_COMMON + CFLAGS_EXTRA[config]
  suffix = '.s' if config == 'wasm' else '.js'

  result = testing.execute(
      tester=testing.Tester(
          command_ctor=c_compile,
          outname_ctor=Outname(suffix),
          outdir=out,
          extras={'c': c, 'cflags': cflags}),
      inputs=c_test_files,
      fails=fails)

  if config != 'binaryen':
    return result

  # Encode Binaryen's wast using sexpr-wasm (this means that v8's binary format
  # doesn't have to exactly match SM/Binaryen)
  testing.execute(
      tester=testing.Tester(
          command_ctor=sexpr,
          outname_ctor=Outname('.wasm', strip_suffix='.wast'),
          outdir=out,
          extras={'sexpr': os.path.join(
              os.path.dirname(os.path.dirname(c)), 'sexpr-wasm')}),
      inputs=[Outname('.wast')(out, f) for f in c_test_files],
      fails=None)

  # If emcc doesn't generate a foo.wasm binary, it assumes the browser will
  # consume the wast file and names the globals file accordingly. We manually
  # encode the wasm file, so rename <test>.wast.mappedGlobals to
  # <test>.wasm.mappedGlobals so the emscripten JS glue can find it.
  testing.execute(
      tester=testing.Tester(
          command_ctor=mv,
          outname_ctor=Outname('.wasm.mappedGlobals',
                               strip_suffix='.wast.mappedGlobals'),
          outdir=out,
          extras=None),
      inputs=[Outname('.wast.mappedGlobals')(out, f) for f in c_test_files],
      fails=None)
  return result
Exemplo n.º 3
0
def run(c, cxx, testsuite, fails, out, config='wasm'):
    """Compile all torture tests."""
    assert os.path.isfile(c), 'Cannot find C compiler at %s' % c
    assert os.path.isfile(cxx), 'Cannot find C++ compiler at %s' % cxx
    assert os.path.isdir(testsuite), 'Cannot find testsuite at %s' % testsuite
    # TODO(jfb) Also compile other C tests, as well as C++ tests under g++.dg.
    c_torture = os.path.join(testsuite, 'gcc.c-torture', 'execute')
    assert os.path.isdir(c_torture), ('Cannot find C torture tests at %s' %
                                      c_torture)
    assert os.path.isdir(out), 'Cannot find outdir %s' % out
    c_test_files = glob.glob(os.path.join(c_torture, '*c'))
    cflags = CFLAGS_COMMON + CFLAGS_EXTRA[config]
    suffix = '.s' if config == 'wasm' else '.js'

    result = testing.execute(tester=testing.Tester(
        command_ctor=c_compile,
        outname_ctor=Outname(suffix),
        outdir=out,
        extras={
            'c': c,
            'cflags': cflags
        }),
                             inputs=c_test_files,
                             fails=fails)

    return result
Exemplo n.º 4
0
def run(runner,
        files,
        fails,
        attributes,
        out,
        extra_args=[],
        exclude_files=[],
        wasmjs='',
        extra_files=[]):
    """Execute all files."""
    assert os.path.isfile(runner), 'Cannot find runner at %s' % runner
    if out:
        assert os.path.isdir(out), 'Cannot find outdir %s' % out
    executable_files = glob.glob(files)
    executable_files = [
        file for file in executable_files if file not in exclude_files
    ]
    assert len(executable_files), 'No files found by %s' % files
    return testing.execute(tester=testing.Tester(
        command_ctor=execute,
        outname_ctor=create_outname,
        outdir=out,
        extras={
            'runner': runner,
            'extra_files': extra_files if extra_files else [],
            'extra_args': extra_args
        }),
                           inputs=executable_files,
                           fails=fails,
                           attributes=attributes)
Exemplo n.º 5
0
def test_all_quantities():
    exe = get_exe()

    enter('vmc')

    command = sys.executable + " {} -e 5 --fp=16.8f *scalar*".format(exe)
    out, err, rc = execute(command)

    out_ref = '''
        vmc  series 0 
          LocalEnergy           =      -10.45972798 +/-       0.00380164 
          Variance              =        0.39708591 +/-       0.00971200 
          Kinetic               =       11.08225203 +/-       0.02281909 
          LocalPotential        =      -21.54198001 +/-       0.02390850 
          ElecElec              =       -2.73960796 +/-       0.00627045 
          LocalECP              =       -6.55900348 +/-       0.02845221 
          NonLocalECP           =        0.53229890 +/-       0.00924772 
          IonIon                =      -12.77566747 +/-       0.00000000 
          LocalEnergy_sq        =      109.80363374 +/-       0.07821849 
          MPC                   =       -2.47615080 +/-       0.00644218 
          BlockWeight           =      600.00000000 +/-       0.00000000 
          BlockCPU              =        0.03578981 +/-       0.00022222 
          AcceptRatio           =        0.76940789 +/-       0.00038843 
          Efficiency            =   122102.67468280 +/-       0.00000000 
          TotalTime             =        3.40003187 +/-       0.00000000 
          TotalSamples          =    57000.00000000 +/-       0.00000000 
          -------------------------------------------------------------- 
          CorrectedEnergy       =      -10.19627082 +/-       0.00469500 
        '''

    assert (text_eq(out, out_ref))

    leave()
Exemplo n.º 6
0
def test_multiple_directories():
    exe = get_exe()

    enter('multi')

    command = sys.executable + " {} -e 5 -q ev --fp=16.8f */*scalar*".format(
        exe)
    out, err, rc = execute(command)

    out_ref = '''
                  LocalEnergy                 Variance                   ratio 
dmc/dmc series 0 -10.48910618 +/- 0.00714379  0.45789123 +/- 0.04510618  0.0437 
dmc/dmc series 1 -10.53165002 +/- 0.00153762  0.38502189 +/- 0.00158532  0.0366 
dmc/dmc series 2 -10.53018917 +/- 0.00106340  0.38161141 +/- 0.00111391  0.0362 
dmc/dmc series 3 -10.52884336 +/- 0.00135513  0.38568155 +/- 0.00151082  0.0366 
 
opt/opt series 0 -10.44922550 +/- 0.00475437  0.60256216 +/- 0.01476264  0.0577 
opt/opt series 1 -10.45426389 +/- 0.00320561  0.40278743 +/- 0.01716415  0.0385 
opt/opt series 2 -10.45991696 +/- 0.00271802  0.39865602 +/- 0.00934316  0.0381 
opt/opt series 3 -10.45830307 +/- 0.00298106  0.38110459 +/- 0.00529809  0.0364 
opt/opt series 4 -10.46298481 +/- 0.00561322  0.38927957 +/- 0.01204068  0.0372 
opt/opt series 5 -10.46086055 +/- 0.00375811  0.39354343 +/- 0.00913372  0.0376 

vmc/vmc series 0 -10.45972798 +/- 0.00380164  0.39708591 +/- 0.00971200  0.0380
        '''

    assert (text_eq(out, out_ref))

    leave()
Exemplo n.º 7
0
def get_test_info():
    if len(test_info) == 0:
        import os

        tpath = testing.setup_unit_test_output_directory('qmca', 'test_qmca')

        exe = testing.executable_path('qmca')

        dirs = ['diamond_gamma', 'diamond_twist']

        for dir in dirs:
            qa_files_path = testing.unit_test_file_path(
                'qmcpack_analyzer', dir)
            command = 'rsync -a {} {}'.format(qa_files_path, tpath)
            out, err, rc = execute(command)
            assert (rc == 0)
            data_path = os.path.join(tpath, dir)
            assert (os.path.exists(data_path))
        #end for

        paths = dict(
            vmc='diamond_gamma/vmc',
            opt='diamond_gamma/opt',
            dmc='diamond_gamma/dmc',
            vmc_twist='diamond_twist/vmc',
            multi='diamond_gamma',
        )

        test_info['tpath'] = tpath
        test_info['exe'] = exe
        for name, path in paths.items():
            directories[name] = os.path.join(tpath, path)
Exemplo n.º 8
0
def test_examples():
    exe = get_exe()

    example_text = 'QMCA examples'

    command = sys.executable + ' {} -x'.format(exe)
    out, err, rc = execute(command)
    assert (example_text in out)
Exemplo n.º 9
0
def run(cc, cxx, testsuite, sysroot_dir, fails, exclusions, out, config, opt):
  """Compile all torture tests."""
  script_dir = os.path.dirname(os.path.abspath(__file__))
  pre_js = os.path.join(script_dir, 'em_pre.js')

  cflags_common = ['-DSTACK_SIZE=524288',
                   '-w', '-Wno-implicit-function-declaration', '-' + opt]
  cflags_c = ['--std=gnu89']
  cflags_cxx = []
  cflags_extra = {
      'clang': ['-c', '--sysroot=%s' % sysroot_dir],
      'emscripten': ['--pre-js', pre_js],
  }
  suffix = {
      'clang': '.o',
      'emscripten': '.js',
  }[config]

  assert os.path.isdir(out), 'Cannot find outdir %s' % out
  assert os.path.isfile(cc), 'Cannot find C compiler at %s' % cc
  assert os.path.isfile(cxx), 'Cannot find C++ compiler at %s' % cxx
  assert os.path.isdir(testsuite), 'Cannot find testsuite at %s' % testsuite

  # Currently we build the following parts of the gcc test suite:
  #  - testsuite/gcc.c-torture/execute/*.c
  #  - testsuite/g++.dg (all executable tests)
  # TODO(sbc) Also more parts of the test suite
  c_torture = os.path.join(testsuite, 'gcc.c-torture', 'execute')
  assert os.path.isdir(c_torture), ('Cannot find C tests at %s' % c_torture)
  test_files = glob.glob(os.path.join(c_torture, '*.c'))

  if config == 'clang':
    # Only build the C++ tests when linking with lld
    cxx_test_dir = os.path.join(testsuite, 'g++.dg')
    assert os.path.isdir(cxx_test_dir), ('Cannot find C++ tests at %s' %
                                         cxx_test_dir)
    test_files += find_runnable_tests(cxx_test_dir, '*.[Cc]')

  cflags = cflags_common + cflags_c + cflags_extra[config]
  cxxflags = cflags_common + cflags_cxx + cflags_extra[config]

  if test_filter:
    test_files = fnmatch.filter(test_files, test_filter)

  result = testing.execute(
      tester=testing.Tester(
          command_ctor=do_compile,
          outname_ctor=create_outname,
          outdir=out,
          extras={'cc': cc, 'cxx': cxx, 'cflags': cflags,
                  'cxxflags': cxxflags, 'suffix': suffix}),
      inputs=test_files,
      fails=fails,
      exclusions=exclusions,
      attributes=[config, opt])

  return result
Exemplo n.º 10
0
def test_redo():
    import os

    tpath = testing.setup_unit_test_output_directory('nxs_redo', 'test_redo')

    exe = testing.executable_path('nxs-redo')

    command = '{} {}'.format(exe, tpath)

    # empty directory
    assert (os.listdir(tpath) == [])

    out, err, rc = execute(command)

    assert ('no simulation directories found' in out)

    # directory w/ files, but not nexus simulation directory
    create_file('qmc.in.xml', tpath)

    out, err, rc = execute(command)

    assert ('no simulation directories found' in out)

    assert (set(os.listdir(tpath)) == set(['qmc.in.xml']))

    # nexus simulation directory
    create_path('sim_qmc', tpath)

    assert (set(os.listdir(tpath)) == set(['qmc.in.xml', 'sim_qmc']))

    out, err, rc = execute(command)

    assert (set(os.listdir(tpath)) == set(['attempt1']))

    # nexus simulation directory w/ prior attempt
    create_file('qmc.in.xml', tpath)
    create_path('sim_qmc', tpath)

    assert (set(os.listdir(tpath)) == set(
        ['attempt1', 'qmc.in.xml', 'sim_qmc']))

    out, err, rc = execute(command)

    assert (set(os.listdir(tpath)) == set(['attempt1', 'attempt2']))
Exemplo n.º 11
0
def run(linker, files, fails, out):
    """Link all files."""
    assert os.path.isfile(linker), 'Cannot find linker at %s' % linker
    assert os.path.isdir(out), 'Cannot find outdir %s' % out
    assembly_files = glob.glob(files)
    assert len(assembly_files), 'No files found by %s' % files
    return testing.execute(tester=testing.Tester(command_ctor=link,
                                                 outname_ctor=create_outname,
                                                 outdir=out,
                                                 extras={'linker': linker}),
                           inputs=assembly_files,
                           fails=fails)
Exemplo n.º 12
0
def run(assembler, files, fails, out):
    """Assemble all files."""
    assert os.path.isfile(assembler), "Cannot find assembler at %s" % assembler
    assert os.path.isdir(out), "Cannot find outdir %s" % out
    assembler_files = glob.glob(files)
    assert len(assembler_files), "No files found by %s" % files
    return testing.execute(
        tester=testing.Tester(
            command_ctor=assemble, outname_ctor=create_outname, outdir=out, extras={"assembler": assembler}
        ),
        inputs=assembler_files,
        fails=fails,
    )
def run(linker, files, fails, out):
  """Link all files."""
  assert os.path.isfile(linker), 'Cannot find linker at %s' % linker
  assert os.path.isdir(out), 'Cannot find outdir %s' % out
  assembly_files = glob.glob(files)
  assert len(assembly_files), 'No files found by %s' % files
  return testing.execute(
      tester=testing.Tester(
          command_ctor=link,
          outname_ctor=create_outname,
          outdir=out,
          extras={'linker': linker}),
      inputs=assembly_files,
      fails=fails)
Exemplo n.º 14
0
    def test_fit():
        import os

        tpath = testing.setup_unit_test_output_directory('qmc_fit', 'test_fit')

        exe = testing.executable_path('qmc-fit')

        qa_files_path = testing.unit_test_file_path('qmcpack_analyzer',
                                                    'diamond_gamma/dmc')
        command = 'rsync -a {} {}'.format(qa_files_path, tpath)
        out, err, rc = execute(command)
        assert (rc == 0)
        dmc_path = os.path.join(tpath, 'dmc')
        dmc_infile = os.path.join(dmc_path, 'dmc.in.xml')
        assert (os.path.exists(dmc_infile))

        command = "{} ts --noplot -e 10 -s 1 -t '0.02 0.01 0.005' {}/*scalar*".format(
            exe, dmc_path)

        out, err, rc = execute(command)

        out_ref = '''
            fit function  : linear
            fitted formula: (-10.5271 +/- 0.0021) + (-0.28 +/- 0.17)*t
            intercept     : -10.5271 +/- 0.0021  Ha
            '''

        def process_text(t):
            return t.replace('(', ' ( ').replace(')', ' ) ')

        #end def process_text

        out = process_text(out)
        out_ref = process_text(out_ref)

        assert (text_eq(out, out_ref, atol=1e-2, rtol=1e-2))
Exemplo n.º 15
0
def test_unit_conversion():
    exe = get_exe()

    enter('vmc')

    command = '{} -e 5 -q e -u eV --fp=16.8f *scalar*'.format(exe)
    out, err, rc = execute(command)

    out_ref = '''
        vmc  series 0  LocalEnergy  =  -284.62368087 +/- 0.10344802
        '''

    assert (text_eq(out, out_ref))

    leave()
Exemplo n.º 16
0
def test_weighted_twist_average():
    exe = get_exe()

    enter('vmc_twist')

    command = "{} -a -w '1 3 3 1' -e 5 -q ev --fp=16.8f *scalar*".format(exe)
    out, err, rc = execute(command)

    out_ref = '''
              LocalEnergy                 Variance                   ratio 
avg series 0 -11.44375840 +/- 0.00292164  0.44863011 +/- 0.00502859  0.0392 
        '''

    assert (text_eq(out, out_ref))

    leave()
Exemplo n.º 17
0
def test_twist_average():
    exe = get_exe()

    enter('vmc_twist')

    command = "{} -a -e 5 -q ev --fp=16.8f *scalar*".format(exe)
    out, err, rc = execute(command)

    out_ref = '''
              LocalEnergy                 Variance                   ratio 
avg series 0 -11.34367335 +/- 0.00257603  0.57340688 +/- 0.00442552  0.0505 
        '''

    assert (text_eq(out, out_ref))

    leave()
Exemplo n.º 18
0
def run(assembler, files, fails, attributes, out):
    """Assemble all files."""
    assert os.path.isfile(assembler), 'Cannot find assembler at %s' % assembler
    assert os.path.isdir(out), 'Cannot find outdir %s' % out
    assembler_files = glob.glob(files)
    if len(assembler_files) == 0:
        print 'No files found by %s' % files
        return 1
    return testing.execute(tester=testing.Tester(
        command_ctor=assemble,
        outname_ctor=create_outname,
        outdir=out,
        extras={'assembler': assembler}),
                           inputs=assembler_files,
                           fails=fails,
                           attributes=attributes)
Exemplo n.º 19
0
def run(c, cxx, testsuite, sysroot_dir, fails, out, config):
  """Compile all torture tests."""
  cflags_common = ['--std=gnu89', '-DSTACK_SIZE=1044480',
                   '-w', '-Wno-implicit-function-declaration']
  cflags_extra = {
      'wasm-s': ['--target=wasm32-unknown-unknown', '-S', '-O2',
                 '--sysroot=%s' % sysroot_dir],
      'wasm-o': ['--target=wasm32-unknown-unknown-wasm', '-c', '-O2',
                 '--sysroot=%s' % sysroot_dir],
      # Binaryen's native-wasm method uses the JS engine's native support for
      # wasm rather than interpreting the wasm with wasm.js.
      'binaryen-native': ['-s', 'WASM=1', '-s',
                          'BINARYEN_METHOD="native-wasm"'],
      # The interpret-binary method runs the wasm in an asmjs-compiled
      # wasm-shell
      'binaryen-interpret': ['-s', 'WASM=1', '-s',
                             'BINARYEN_METHOD="interpret-binary"'],
  }
  suffix = {
      'wasm-o': '.o',
      'wasm-s': '.s',
      'binaryen-native': '.js',
      'binaryen-inputs': '.js',
  }[config]

  assert os.path.isfile(c), 'Cannot find C compiler at %s' % c
  assert os.path.isfile(cxx), 'Cannot find C++ compiler at %s' % cxx
  assert os.path.isdir(testsuite), 'Cannot find testsuite at %s' % testsuite
  # TODO(jfb) Also compile other C tests, as well as C++ tests under g++.dg.
  c_torture = os.path.join(testsuite, 'gcc.c-torture', 'execute')
  assert os.path.isdir(c_torture), ('Cannot find C torture tests at %s' %
                                    c_torture)
  assert os.path.isdir(out), 'Cannot find outdir %s' % out
  c_test_files = glob.glob(os.path.join(c_torture, '*c'))
  cflags = cflags_common + cflags_extra[config]

  result = testing.execute(
      tester=testing.Tester(
          command_ctor=c_compile,
          outname_ctor=Outname(suffix),
          outdir=out,
          extras={'c': c, 'cflags': cflags}),
      inputs=c_test_files,
      fails=fails,
      attributes=[config])

  return result
Exemplo n.º 20
0
def test_join():
    exe = get_exe()

    enter('dmc')

    command = "{} -e 5 -j '1 3' -q ev --fp=16.8f *scalar*".format(exe)
    out, err, rc = execute(command)

    out_ref = '''
               LocalEnergy                 Variance                   ratio 
dmc  series 0 -10.48910618 +/- 0.00714379  0.45789123 +/- 0.04510618  0.0437 
dmc  series 1 -10.53022752 +/- 0.00073527  0.38410495 +/- 0.00082972  0.0365 
        '''

    assert (text_eq(out, out_ref))

    leave()
Exemplo n.º 21
0
def run(linker, files, fails, attributes, out, args):
    """Link all files."""
    assert os.path.isfile(linker), 'Cannot find linker at %s' % linker
    assert os.path.isdir(out), 'Cannot find outdir %s' % out
    input_files = glob.glob(files)
    assert len(input_files), 'No files found by %s' % files
    if not args:
        args = []
    return testing.execute(tester=testing.Tester(command_ctor=link,
                                                 outname_ctor=create_outname,
                                                 outdir=out,
                                                 extras={
                                                     'linker': linker,
                                                     'args': args
                                                 }),
                           inputs=input_files,
                           fails=fails,
                           attributes=attributes)
Exemplo n.º 22
0
def test_selected_quantities():
    exe = get_exe()

    enter('vmc')

    command = "{} -e 5 -q 'e k p' --fp=16.8f *scalar*".format(exe)
    out, err, rc = execute(command)

    out_ref = '''
        vmc  series 0 
          LocalEnergy           =      -10.45972798 +/-       0.00380164 
          Kinetic               =       11.08225203 +/-       0.02281909 
          LocalPotential        =      -21.54198001 +/-       0.02390850 
        '''

    assert (text_eq(out, out_ref))

    leave()
Exemplo n.º 23
0
def test_multiple_equilibration():
    exe = get_exe()

    enter('dmc')

    command = "{} -e '5 10 15 20' -q ev --fp=16.8f *scalar*".format(exe)
    out, err, rc = execute(command)

    out_ref = '''
              LocalEnergy                 Variance                   ratio 
dmc series 0 -10.48910618 +/- 0.00714379  0.45789123 +/- 0.04510618  0.0437 
dmc series 1 -10.53167630 +/- 0.00163992  0.38531028 +/- 0.00162825  0.0366 
dmc series 2 -10.53061971 +/- 0.00123791  0.38172188 +/- 0.00124608  0.0362 
dmc series 3 -10.52807733 +/- 0.00122687  0.38565052 +/- 0.00196074  0.0366 
        '''

    assert (text_eq(out, out_ref))

    leave()
Exemplo n.º 24
0
def run(runner, files, fails, out, wasmjs='', extra_files=[]):
    """Execute all files."""
    assert os.path.isfile(runner), 'Cannot find runner at %s' % runner
    if out:
        assert os.path.isdir(out), 'Cannot find outdir %s' % out
    if wasmjs:
        assert os.path.isfile(wasmjs), 'Cannot find wasm.js %s' % wasmjs
    executable_files = glob.glob(files)
    assert len(executable_files), 'No files found by %s' % files
    return testing.execute(tester=testing.Tester(
        command_ctor=execute,
        outname_ctor=create_outname,
        outdir=out,
        extras={
            'runner': runner,
            'wasmjs': wasmjs,
            'extra_files': extra_files if extra_files else []
        }),
                           inputs=executable_files,
                           fails=fails)
Exemplo n.º 25
0
def run(runner, files, fails, out, wasmjs='', extra_files=[]):
  """Execute all files."""
  assert os.path.isfile(runner), 'Cannot find runner at %s' % runner
  if out:
    assert os.path.isdir(out), 'Cannot find outdir %s' % out
  if wasmjs:
    assert os.path.isfile(wasmjs), 'Cannot find wasm.js %s' % wasmjs
  executable_files = glob.glob(files)
  assert len(executable_files), 'No files found by %s' % files
  return testing.execute(
      tester=testing.Tester(
          command_ctor=execute,
          outname_ctor=create_outname,
          outdir=out,
          extras={
              'runner': runner,
              'wasmjs': wasmjs,
              'extra_files': extra_files if extra_files else []
          }),
      inputs=executable_files,
      fails=fails)
Exemplo n.º 26
0
def test_energy_variance():
    exe = get_exe()

    enter('opt')

    command = sys.executable + " {} -e 5 -q ev --fp=16.8f *scalar*".format(exe)
    out, err, rc = execute(command)

    out_ref = '''
              LocalEnergy                 Variance                   ratio 
opt series 0 -10.44922550 +/- 0.00475437  0.60256216 +/- 0.01476264  0.0577 
opt series 1 -10.45426389 +/- 0.00320561  0.40278743 +/- 0.01716415  0.0385 
opt series 2 -10.45991696 +/- 0.00271802  0.39865602 +/- 0.00934316  0.0381 
opt series 3 -10.45830307 +/- 0.00298106  0.38110459 +/- 0.00529809  0.0364 
opt series 4 -10.46298481 +/- 0.00561322  0.38927957 +/- 0.01204068  0.0372 
opt series 5 -10.46086055 +/- 0.00375811  0.39354343 +/- 0.00913372  0.0376 
        '''

    assert (text_eq(out, out_ref))

    leave()
Exemplo n.º 27
0
def run(c, cxx, testsuite, sysroot_dir, fails, out, config='wasm'):
  """Compile all torture tests."""
  cflags_common = ['--std=gnu89', '-DSTACK_SIZE=1044480',
                   '-w', '-Wno-implicit-function-declaration']
  cflags_extra = {
      'wasm': ['--target=wasm32-unknown-unknown', '-S', '-O2',
               '--sysroot=%s' % sysroot_dir],
      # Binaryen's native-wasm method uses the JS engine's native support for
      # wasm rather than interpreting the wasm with wasm.js.
      'binaryen-native': ['-s', 'BINARYEN=1', '-s',
                          'BINARYEN_METHOD="native-wasm"'],
      # The interpret-binary method runs the wasm in an asmjs-compiled
      # wasm-shell
      'binaryen-interpret': ['-s', 'BINARYEN=1', '-s',
                             'BINARYEN_METHOD="interpret-binary"'],
  }

  assert os.path.isfile(c), 'Cannot find C compiler at %s' % c
  assert os.path.isfile(cxx), 'Cannot find C++ compiler at %s' % cxx
  assert os.path.isdir(testsuite), 'Cannot find testsuite at %s' % testsuite
  # TODO(jfb) Also compile other C tests, as well as C++ tests under g++.dg.
  c_torture = os.path.join(testsuite, 'gcc.c-torture', 'execute')
  assert os.path.isdir(c_torture), ('Cannot find C torture tests at %s' %
                                    c_torture)
  assert os.path.isdir(out), 'Cannot find outdir %s' % out
  c_test_files = glob.glob(os.path.join(c_torture, '*c'))
  cflags = cflags_common + cflags_extra[config]
  suffix = '.s' if config == 'wasm' else '.js'

  result = testing.execute(
      tester=testing.Tester(
          command_ctor=c_compile,
          outname_ctor=Outname(suffix),
          outdir=out,
          extras={'c': c, 'cflags': cflags}),
      inputs=c_test_files,
      fails=fails)

  return result
Exemplo n.º 28
0
def run(c, cxx, testsuite, sysroot_dir, fails, out, config, opt):
    """Compile all torture tests."""
    cflags_common = [
        '--std=gnu89', '-DSTACK_SIZE=524288', '-w',
        '-Wno-implicit-function-declaration', '-' + opt
    ]
    cflags_extra = [
        '--target=wasm32-unknown-wavix', '-c',
        '--sysroot=%s' % sysroot_dir
    ]
    suffix = '.o'

    assert os.path.isfile(c), 'Cannot find C compiler at %s' % c
    assert os.path.isfile(cxx), 'Cannot find C++ compiler at %s' % cxx
    assert os.path.isdir(testsuite), 'Cannot find testsuite at %s' % testsuite
    # TODO(jfb) Also compile other C tests, as well as C++ tests under g++.dg.
    c_torture = os.path.join(testsuite, 'gcc.c-torture', 'execute')
    assert os.path.isdir(c_torture), ('Cannot find C torture tests at %s' %
                                      c_torture)
    assert os.path.isdir(out), 'Cannot find outdir %s' % out
    c_test_files = glob.glob(os.path.join(c_torture, '*c'))
    cflags = cflags_common + cflags_extra

    result = testing.execute(tester=testing.Tester(command_ctor=c_compile,
                                                   outname_ctor=create_outname,
                                                   outdir=out,
                                                   extras={
                                                       'c': c,
                                                       'cflags': cflags,
                                                       'suffix': suffix
                                                   }),
                             inputs=c_test_files,
                             fails=fails,
                             attributes=[config, opt])

    return result
def run(c, cxx, testsuite, fails, out, config='wasm'):
  """Compile all torture tests."""
  assert os.path.isfile(c), 'Cannot find C compiler at %s' % c
  assert os.path.isfile(cxx), 'Cannot find C++ compiler at %s' % cxx
  assert os.path.isdir(testsuite), 'Cannot find testsuite at %s' % testsuite
  # TODO(jfb) Also compile other C tests, as well as C++ tests under g++.dg.
  c_torture = os.path.join(testsuite, 'gcc.c-torture', 'execute')
  assert os.path.isdir(c_torture), ('Cannot find C torture tests at %s' %
                                    c_torture)
  assert os.path.isdir(out), 'Cannot find outdir %s' % out
  c_test_files = glob.glob(os.path.join(c_torture, '*c'))
  cflags = CFLAGS_COMMON + CFLAGS_EXTRA[config]
  suffix = '.s' if config == 'wasm' else '.js'

  result = testing.execute(
      tester=testing.Tester(
          command_ctor=c_compile,
          outname_ctor=Outname(suffix),
          outdir=out,
          extras={'c': c, 'cflags': cflags}),
      inputs=c_test_files,
      fails=fails)

  return result
Exemplo n.º 30
0
    def test_radial_density():
        import os

        tpath = testing.setup_unit_test_output_directory(
            'qdens_radial', 'test_radial_density')

        exe = testing.executable_path('qdens-radial')

        qr_vmc_files_path = testing.unit_test_file_path(
            'qdens_radial', 'diamond_twist/vmc')
        command = 'rsync -a {} {}'.format(qr_vmc_files_path, tpath)
        out, err, rc = execute(command)
        assert (rc == 0)
        vmc_path = os.path.join(tpath, 'vmc')
        vmc_infile = os.path.join(vmc_path, 'vmc.g000.twistnum_0.in.xml')
        assert (os.path.exists(vmc_infile))
        vmc_infile = os.path.join(vmc_path, 'vmc.g001.twistnum_1.in.xml')
        assert (os.path.exists(vmc_infile))
        vmc_infile = os.path.join(vmc_path, 'vmc.g002.twistnum_2.in.xml')
        assert (os.path.exists(vmc_infile))
        vmc_infile = os.path.join(vmc_path, 'vmc.g003.twistnum_3.in.xml')
        assert (os.path.exists(vmc_infile))

        files_bef = '''
        vmc.avg.s000.SpinDensity_u+d+err.xsf  vmc.avg.s000.SpinDensity_u+d-err.xsf
        vmc.avg.s000.SpinDensity_u+d.xsf      vmc.g000.twistnum_0.in.xml
        vmc.g000.s000.scalar.dat              vmc.g001.s000.scalar.dat
        vmc.g000.twistnum_0.in.g000.qmc       vmc.g001.twistnum_1.in.g001.qmc
        vmc.g001.twistnum_1.in.xml            vmc.g002.twistnum_2.in.xml
        vmc.g002.s000.scalar.dat              vmc.g003.s000.scalar.dat
        vmc.g002.twistnum_2.in.g002.qmc       vmc.g003.twistnum_3.in.g003.qmc
        vmc.g003.twistnum_3.in.xml            vmc.out
        vmc.in                                vmc.info.xml
        '''.split()

        qr_dmc_files_path = testing.unit_test_file_path(
            'qdens_radial', 'diamond_twist/dmc')
        command = 'rsync -a {} {}'.format(qr_dmc_files_path, tpath)
        out, err, rc = execute(command)
        assert (rc == 0)
        dmc_path = os.path.join(tpath, 'dmc')
        dmc_infile = os.path.join(dmc_path, 'dmc.g000.twistnum_0.in.xml')
        assert (os.path.exists(dmc_infile))
        dmc_infile = os.path.join(dmc_path, 'dmc.g001.twistnum_1.in.xml')
        assert (os.path.exists(dmc_infile))
        dmc_infile = os.path.join(dmc_path, 'dmc.g002.twistnum_2.in.xml')
        assert (os.path.exists(dmc_infile))
        dmc_infile = os.path.join(dmc_path, 'dmc.g003.twistnum_3.in.xml')
        assert (os.path.exists(dmc_infile))

        files_bef = '''
        dmc.avg.s001.SpinDensity_u+d+err.xsf  dmc.avg.s001.SpinDensity_u+d-err.xsf
        dmc.avg.s001.SpinDensity_u+d.xsf      dmc.g001.s001.scalar.dat                               
        dmc.g000.s000.scalar.dat              dmc.g000.s001.scalar.dat
        dmc.g000.twistnum_0.in.g000.qmc       dmc.g001.twistnum_1.in.g001.qmc
        dmc.g000.twistnum_0.in.xml            dmc.g001.twistnum_1.in.xml     
        dmc.g001.s000.scalar.dat              dmc.g002.s000.scalar.dat       
        dmc.g002.s001.scalar.dat              dmc.g003.s001.scalar.dat       
        dmc.g002.twistnum_2.in.g002.qmc       dmc.g003.twistnum_3.in.g003.qmc
        dmc.g002.twistnum_2.in.xml            dmc.g003.twistnum_3.in.xml
        dmc.g003.s000.scalar.dat              dmc.in
        dmc.out
        '''.split()

        assert (check_value_eq(set(os.listdir(dmc_path)), set(files_bef)))

        # VMC non-cumulative
        command = '{0} -s C -r 0.6 {1}/vmc.avg.s000.SpinDensity_u+d.xsf'.format(
            exe, vmc_path)
        out, err, rc = execute(command)

        # Assert that return code is 0
        assert (rc == 0)

        # Assert that output is consistent with reference
        out_ref = '''
Norm:   tot             = 8.00000003

Non-Cumulative Value of C Species at Cutoff 0.6 is: 4.773264912162242
'''
        assert (text_eq(out, out_ref))

        # VMC cumulative
        command = '{0} -s C -r 0.6 -c {1}/vmc.avg.s000.SpinDensity_u+d.xsf'.format(
            exe, vmc_path)
        out, err, rc = execute(command)

        # Assert that return code is 0
        assert (rc == 0)

        # Assert that output is consistent with reference
        out_ref = '''
Norm:   tot             = 8.00000003

Cumulative Value of C Species at Cutoff 0.6 is: 1.0684248641866259
'''

        # DMC extrapolated non-cumulative
        command = '{0} -s C -r 0.6 --vmc={1}/vmc.avg.s000.SpinDensity_u+d.xsf {2}/dmc.avg.s001.SpinDensity_u+d.xsf'.format(
            exe, vmc_path, dmc_path)
        out, err, rc = execute(command)

        # Assert that return code is 0
        assert (rc == 0)

        # Assert that output is consistent with reference
        out_ref = '''
Extrapolating from VMC and DMC densities...

Norm:   tot             = 7.999999969999998

Non-Cumulative Value of C Species at Cutoff 0.6 is: 4.910093964664309
'''
        assert (text_eq(out, out_ref))

        # DMC extrapolated cumulative
        command = '{0} -s C -r 0.6 -c --vmc={1}/vmc.avg.s000.SpinDensity_u+d.xsf {2}/dmc.avg.s001.SpinDensity_u+d.xsf'.format(
            exe, vmc_path, dmc_path)
        out, err, rc = execute(command)

        # Assert that return code is 0
        assert (rc == 0)

        # Assert that output is consistent with reference
        out_ref = '''
Extrapolating from VMC and DMC densities...

Norm:   tot             = 7.999999969999998

Cumulative Value of C Species at Cutoff 0.6 is: 1.1078267486386275
'''
        assert (text_eq(out, out_ref))

        # DMC extrapolated cumulative with error bar
        command = '{0} -s C -r 0.6 -c -n 3 --seed=0 --vmc={1}/vmc.avg.s000.SpinDensity_u+d.xsf --vmcerr={1}/vmc.avg.s000.SpinDensity_u+d+err.xsf --dmcerr={2}/dmc.avg.s001.SpinDensity_u+d+err.xsf {2}/dmc.avg.s001.SpinDensity_u+d.xsf'.format(
            exe, vmc_path, dmc_path)
        out, err, rc = execute(command)

        # Assert that return code is 0
        assert (rc == 0)

        # Assert that output is consistent with reference
        out_ref = '''
Extrapolating from VMC and DMC densities...
Resampling to obtain error bar (NOTE: This can be slow)...
Will compute 3 samples...
sample: 0
sample: 1
sample: 2

Norm:   tot             = 7.999999969999998

Cumulative Value of C Species at Cutoff 0.6 is: 1.1078267486386275+/-0.0016066467833404942
'''
        assert (text_eq(out, out_ref))
Exemplo n.º 31
0
    def test_density():
        import os

        tpath = testing.setup_unit_test_output_directory('qdens','test_density')

        exe = testing.executable_path('qdens')

        qa_files_path = testing.unit_test_file_path('qmcpack_analyzer','diamond_gamma/dmc')
        command = 'rsync -a {} {}'.format(qa_files_path,tpath)
        out,err,rc = execute(command)
        assert(rc==0)
        dmc_path = os.path.join(tpath,'dmc')
        dmc_infile = os.path.join(dmc_path,'dmc.in.xml')
        assert(os.path.exists(dmc_infile))

        files_bef = '''
    dmc.err     dmc.s000.scalar.dat  dmc.s001.stat.h5     dmc.s003.scalar.dat
    dmc.in.xml  dmc.s000.stat.h5     dmc.s002.scalar.dat  dmc.s003.stat.h5
    dmc.out     dmc.s001.scalar.dat  dmc.s002.stat.h5
        '''.split()

        assert(check_value_eq(set(os.listdir(dmc_path)),set(files_bef)))

        command = '{0} -v -e 4 -f xsf -i {1}/dmc.in.xml {1}/*stat.h5'.format(exe,dmc_path)

        out,err,rc = execute(command)

        files_aft = '''
            dmc.err                           dmc.s001.stat.h5
            dmc.in.xml                        dmc.s002.scalar.dat
            dmc.out                           dmc.s002.SpinDensity_d-err.xsf
            dmc.s000.scalar.dat               dmc.s002.SpinDensity_d+err.xsf
            dmc.s000.SpinDensity_d-err.xsf    dmc.s002.SpinDensity_d.xsf
            dmc.s000.SpinDensity_d+err.xsf    dmc.s002.SpinDensity_u-d-err.xsf
            dmc.s000.SpinDensity_d.xsf        dmc.s002.SpinDensity_u-d+err.xsf
            dmc.s000.SpinDensity_u-d-err.xsf  dmc.s002.SpinDensity_u+d-err.xsf
            dmc.s000.SpinDensity_u-d+err.xsf  dmc.s002.SpinDensity_u+d+err.xsf
            dmc.s000.SpinDensity_u+d-err.xsf  dmc.s002.SpinDensity_u-d.xsf
            dmc.s000.SpinDensity_u+d+err.xsf  dmc.s002.SpinDensity_u+d.xsf
            dmc.s000.SpinDensity_u-d.xsf      dmc.s002.SpinDensity_u-err.xsf
            dmc.s000.SpinDensity_u+d.xsf      dmc.s002.SpinDensity_u+err.xsf
            dmc.s000.SpinDensity_u-err.xsf    dmc.s002.SpinDensity_u.xsf
            dmc.s000.SpinDensity_u+err.xsf    dmc.s002.stat.h5
            dmc.s000.SpinDensity_u.xsf        dmc.s003.scalar.dat
            dmc.s000.stat.h5                  dmc.s003.SpinDensity_d-err.xsf
            dmc.s001.scalar.dat               dmc.s003.SpinDensity_d+err.xsf
            dmc.s001.SpinDensity_d-err.xsf    dmc.s003.SpinDensity_d.xsf
            dmc.s001.SpinDensity_d+err.xsf    dmc.s003.SpinDensity_u-d-err.xsf
            dmc.s001.SpinDensity_d.xsf        dmc.s003.SpinDensity_u-d+err.xsf
            dmc.s001.SpinDensity_u-d-err.xsf  dmc.s003.SpinDensity_u+d-err.xsf
            dmc.s001.SpinDensity_u-d+err.xsf  dmc.s003.SpinDensity_u+d+err.xsf
            dmc.s001.SpinDensity_u+d-err.xsf  dmc.s003.SpinDensity_u-d.xsf
            dmc.s001.SpinDensity_u+d+err.xsf  dmc.s003.SpinDensity_u+d.xsf
            dmc.s001.SpinDensity_u-d.xsf      dmc.s003.SpinDensity_u-err.xsf
            dmc.s001.SpinDensity_u+d.xsf      dmc.s003.SpinDensity_u+err.xsf
            dmc.s001.SpinDensity_u-err.xsf    dmc.s003.SpinDensity_u.xsf
            dmc.s001.SpinDensity_u+err.xsf    dmc.s003.stat.h5
            dmc.s001.SpinDensity_u.xsf
            '''.split()

        assert(check_value_eq(set(os.listdir(dmc_path)),set(files_aft),verbose=True))

        tot_file = os.path.join(dmc_path,'dmc.s003.SpinDensity_u+d.xsf')
        pol_file = os.path.join(dmc_path,'dmc.s003.SpinDensity_u-d.xsf')

        tot = open(tot_file,'r').read()
        pol = open(pol_file,'r').read()

        tot_ref = '''
             CRYSTAL
             PRIMVEC 
                 1.78500000   1.78500000   0.00000000
                -0.00000000   1.78500000   1.78500000
                 1.78500000  -0.00000000   1.78500000
             PRIMCOORD 
               2 1
                 6   0.00000000   0.00000000   0.00000000
                 6   0.89250000   0.89250000   0.89250000
             BEGIN_BLOCK_DATAGRID_3D
               density
               BEGIN_DATAGRID_3D_density
                 4 4 4
                 0.59500000   0.59500000   0.59500000
                 1.78500000   1.78500000   0.00000000
                -0.00000000   1.78500000   1.78500000
                 1.78500000  -0.00000000   1.78500000
                   0.73126076   0.62407496   0.51676366   0.73126076
                   0.62575089   0.19225114   0.18686389   0.62575089
                   0.51847569   0.18457799   0.42203355   0.51847569
                   0.73126076   0.62407496   0.51676366   0.73126076
                   0.62659840   0.19325900   0.18422995   0.62659840
                   0.19219866   0.04873728   0.13184395   0.19219866
                   0.18474638   0.13013188   0.10227670   0.18474638
                   0.62659840   0.19325900   0.18422995   0.62659840
                   0.51793019   0.18615766   0.41806405   0.51793019
                   0.18425005   0.13092538   0.10088238   0.18425005
                   0.41967003   0.10133434   0.14471118   0.41967003
                   0.51793019   0.18615766   0.41806405   0.51793019
                   0.73126076   0.62407496   0.51676366   0.73126076
                   0.62575089   0.19225114   0.18686389   0.62575089
                   0.51847569   0.18457799   0.42203355   0.51847569
                   0.73126076   0.62407496   0.51676366   0.73126076
               END_DATAGRID_3D_density
             END_BLOCK_DATAGRID_3D
            '''

        pol_ref = '''
             CRYSTAL
             PRIMVEC 
                 1.78500000   1.78500000   0.00000000
                -0.00000000   1.78500000   1.78500000
                 1.78500000  -0.00000000   1.78500000
             PRIMCOORD 
               2 1
                 6   0.00000000   0.00000000   0.00000000
                 6   0.89250000   0.89250000   0.89250000
             BEGIN_BLOCK_DATAGRID_3D
               density
               BEGIN_DATAGRID_3D_density
                 4 4 4
                 0.59500000   0.59500000   0.59500000
                 1.78500000   1.78500000   0.00000000
                -0.00000000   1.78500000   1.78500000
                 1.78500000  -0.00000000   1.78500000
                   0.00106753   0.00015792  -0.00122859   0.00106753
                  -0.00003402   0.00018762  -0.00051347  -0.00003402
                   0.00154254   0.00067654   0.00073434   0.00154254
                   0.00106753   0.00015792  -0.00122859   0.00106753
                   0.00263956   0.00079744  -0.00118289   0.00263956
                  -0.00039348  -0.00026396  -0.00069392  -0.00039348
                   0.00087929   0.00000719   0.00113934   0.00087929
                   0.00263956   0.00079744  -0.00118289   0.00263956
                  -0.00013655  -0.00041508  -0.00235212  -0.00013655
                   0.00003805  -0.00025962  -0.00133495   0.00003805
                   0.00040692   0.00051699  -0.00198263   0.00040692
                  -0.00013655  -0.00041508  -0.00235212  -0.00013655
                   0.00106753   0.00015792  -0.00122859   0.00106753
                  -0.00003402   0.00018762  -0.00051347  -0.00003402
                   0.00154254   0.00067654   0.00073434   0.00154254
                   0.00106753   0.00015792  -0.00122859   0.00106753
               END_DATAGRID_3D_density
             END_BLOCK_DATAGRID_3D
            '''

        assert(text_eq(tot,tot_ref,atol=1e-7))
        assert(text_eq(pol,pol_ref,atol=1e-7))
Exemplo n.º 32
0
def test_sim():
    import os
    from nexus_base import nexus_core
    from test_simulation_module import get_sim

    tpath = testing.setup_unit_test_output_directory('nxs_sim','test_sim',divert=True)

    nexus_core.runs    = ''
    nexus_core.results = ''
    
    exe = testing.executable_path('nxs-sim')

    sim = get_sim()

    sim.create_directories()

    sim.save_image()

    simp_path = os.path.join(tpath,sim.imlocdir,'sim.p')
    assert(os.path.isfile(simp_path))


    # initial simulation state
    command = sys.executable+' {} show {}'.format(exe,simp_path)

    out,err,rc = execute(command)

    out_ref = '''
        {}
        setup        0
        sent_files   0
        submitted    0
        finished     0
        failed       0
        got_output   0
        analyzed     0
        '''.format(simp_path)

    assert(text_eq(out,out_ref))


    # final simulation state
    command = sys.executable+' {} complete {}'.format(exe,simp_path)
    out,err,rc = execute(command)

    command = sys.executable+' {} show {}'.format(exe,simp_path)
    out,err,rc = execute(command)

    out_ref = '''
        {}
        setup        1
        sent_files   1
        submitted    1
        finished     1
        failed       0
        got_output   1
        analyzed     1
        '''.format(simp_path)

    assert(text_eq(out,out_ref))


    # intermediate simulation state 1
    command = sys.executable+' {} reset {}'.format(exe,simp_path)
    out,err,rc = execute(command)

    command = sys.executable+' {} set setup sent_files submitted {}'.format(exe,simp_path)
    out,err,rc = execute(command)

    command = sys.executable+' {} show {}'.format(exe,simp_path)
    out,err,rc = execute(command)

    out_ref = '''
        {}
        setup        1
        sent_files   1
        submitted    1
        finished     0
        failed       0
        got_output   0
        analyzed     0
        '''.format(simp_path)


    # intermediate simulation state 2
    command = sys.executable+' {} complete {}'.format(exe,simp_path)
    out,err,rc = execute(command)

    command = sys.executable+' {} unset got_output analyzed {}'.format(exe,simp_path)
    out,err,rc = execute(command)

    command = sys.executable+' {} show {}'.format(exe,simp_path)
    out,err,rc = execute(command)

    out_ref = '''
        {}
        setup        1
        sent_files   1
        submitted    1
        finished     1
        failed       0
        got_output   0
        analyzed     0
        '''.format(simp_path)

    assert(text_eq(out,out_ref))

    clear_all_sims()
    restore_nexus()