Exemplo n.º 1
0
def test_dynbasisfns_dealloc(monkeypatch):
    ''' Check that the DynBasisFunctions.deallocate() method
    raises the expected InternalError if an unrecognised type of
    basis function is encountered. '''
    _, invoke_info = parse(os.path.join(BASE_PATH,
                                        "1.1.0_single_invoke_xyoz_qr.f90"),
                           api=API)
    psy = PSyFactory(API, distributed_memory=False).create(invoke_info)
    sched = psy.invokes.invoke_list[0].schedule
    call = sched.children[0].loop_body[0]
    assert isinstance(call, DynKern)
    dinf = DynBasisFunctions(psy.invokes.invoke_list[0])
    mod = ModuleGen(name="testmodule")
    # Supply an invalid type for one of the basis functions
    monkeypatch.setattr(dinf, "_basis_fns", [{'type': 'not-a-type'}])
    with pytest.raises(InternalError) as err:
        dinf.deallocate(mod)
    assert ("Unrecognised type of basis function: 'not-a-type'. Should be "
            "one of 'basis' or 'diff-basis'" in str(err.value))
Exemplo n.º 2
0
def test_dynbasisfunctions(monkeypatch):
    ''' Check that we raise internal errors as required. '''
    _, invoke_info = parse(os.path.join(BASE_PATH,
                                        "1.1.0_single_invoke_xyoz_qr.f90"),
                           api=API)
    psy = PSyFactory(API, distributed_memory=False).create(invoke_info)
    # Get hold of a DynBasisFunctions object
    evaluator = psy.invokes.invoke_list[0].evaluators

    # Test the error check in dynamo0p3.qr_basis_alloc_args() by passing in a
    # dictionary containing an invalid shape entry
    basis_dict = {"shape": "gh_wrong_shape"}
    from psyclone.dynamo0p3 import qr_basis_alloc_args
    with pytest.raises(InternalError) as excinfo:
        _ = qr_basis_alloc_args("size1", basis_dict)
    assert ("Unrecognised shape ('gh_wrong_shape') specified "
            in str(excinfo.value))

    # Monkey-patch it so that it doesn't have any quadrature args
    monkeypatch.setattr(evaluator, "_qr_vars", value=[])
    # Check that calling the various _initialise_... routines does nothing.
    # We pass parent=None so that if any of the routines get beyond the
    # initial check then they will fail.
    evaluator._initialise_xyz_qr(None)
    evaluator._initialise_xyoz_qr(None)
    evaluator._initialise_xoyoz_qr(None)
    evaluator._initialise_face_or_edge_qr(None, "face")
    evaluator._initialise_face_or_edge_qr(None, "edge")

    with pytest.raises(InternalError) as err:
        evaluator._initialise_face_or_edge_qr(None, "Face")
    assert ("qr_type argument must be either 'face' or 'edge' but got: "
            "'Face'" in str(err.value))

    # Check that the constructor raises an internal error if it encounters
    # a shape it doesn't recognise
    invoke = psy.invokes.invoke_list[0]
    sched = invoke.schedule
    call = sched.children[0].loop_body[0]
    assert isinstance(call, DynKern)
    monkeypatch.setattr(call, "_eval_shapes", ["not-a-shape"])
    with pytest.raises(InternalError) as err:
        _ = DynBasisFunctions(invoke)
    assert "Unrecognised evaluator shape: 'not-a-shape'" in str(err.value)
Exemplo n.º 3
0
def test_dynbasisfns_initialise(monkeypatch):
    ''' Check that the DynBasisFunctions.initialise() method
    raises the expected InternalErrors. '''
    _, invoke_info = parse(os.path.join(BASE_PATH,
                                        "1.1.0_single_invoke_xyoz_qr.f90"),
                           api=API)
    psy = PSyFactory(API, distributed_memory=False).create(invoke_info)
    dinf = DynBasisFunctions(psy.invokes.invoke_list[0])
    mod = ModuleGen(name="testmodule")
    # Break the shape of the first basis function
    dinf._basis_fns[0]["shape"] = "not-a-shape"
    with pytest.raises(InternalError) as err:
        dinf.initialise(mod)
    assert ("Unrecognised evaluator shape: 'not-a-shape'. Should be "
            "one of " in str(err.value))
    # Break the internal list of basis functions
    monkeypatch.setattr(dinf, "_basis_fns", [{'type': 'not-a-type'}])
    with pytest.raises(InternalError) as err:
        dinf.initialise(mod)
    assert ("Unrecognised type of basis function: 'not-a-type'. Should be "
            "either 'basis' or 'diff-basis'" in str(err.value))
Exemplo n.º 4
0
def test_dynbasisfns_compute(monkeypatch):
    ''' Check that the DynBasisFunctions._compute_basis_fns() method
    raises the expected InternalErrors if an unrecognised type or shape of
    basis function is encountered. '''
    _, invoke_info = parse(os.path.join(BASE_PATH,
                                        "1.1.0_single_invoke_xyoz_qr.f90"),
                           api=API)
    psy = PSyFactory(API, distributed_memory=False).create(invoke_info)
    dinf = DynBasisFunctions(psy.invokes.invoke_list[0])
    mod = ModuleGen(name="testmodule")
    # First supply an invalid shape for one of the basis functions
    dinf._basis_fns[0]["shape"] = "not-a-shape"
    with pytest.raises(InternalError) as err:
        dinf._compute_basis_fns(mod)
    assert ("Unrecognised shape 'not-a-shape' specified for basis function. "
            "Should be one of: ['gh_quadrature_xyoz', " in str(err.value))
    # Now supply an invalid type for one of the basis functions
    monkeypatch.setattr(dinf, "_basis_fns", [{'type': 'not-a-type'}])
    with pytest.raises(InternalError) as err:
        dinf._compute_basis_fns(mod)
    assert ("Unrecognised type of basis function: 'not-a-type'. Expected "
            "one of 'basis' or 'diff-basis'" in str(err.value))
Exemplo n.º 5
0
def test_dynbasisfns_setup(monkeypatch):
    ''' Check that DynInvokeBasisFns._setup_basis_fns_for_call() raises an
     internal error if an unrecognised evaluator shape is encountered or
    if it is passed something other than a Kernel object. '''
    _, invoke_info = parse(os.path.join(BASE_PATH,
                                        "1.1.0_single_invoke_xyoz_qr.f90"),
                           api=API)
    psy = PSyFactory(API, distributed_memory=False).create(invoke_info)
    sched = psy.invokes.invoke_list[0].schedule
    call = sched.children[0].loop_body[0]
    assert isinstance(call, DynKern)
    dinf = DynBasisFunctions(psy.invokes.invoke_list[0])
    # Now we've created a DynBasisFunctions object, monkeypatch the call
    # to have the wrong shape and try and call setup_basis_fns_for_call()
    monkeypatch.setattr(call, "_eval_shape", "not-a-shape")
    with pytest.raises(InternalError) as err:
        dinf._setup_basis_fns_for_call(call)
    assert "Unrecognised evaluator shape: 'not-a-shape'" in str(err)
    # Check that we get the expected error if the method is passed
    # something that is not a Kernel call
    with pytest.raises(InternalError) as err:
        dinf._setup_basis_fns_for_call("call")
    assert "Expected a DynKern object but got: " in str(err)