How to use validate_field_names method in autotest

Best Python code snippet using autotest_python

test_cpp_regression.py

Source:test_cpp_regression.py Github

copy

Full Screen

1# GT4Py - GridTools4Py - GridTools for Python2#3# Copyright (c) 2014-2022, ETH Zurich4# All rights reserved.5#6# This file is part the GT4Py project and the GridTools framework.7# GT4Py is free software: you can redistribute it and/or modify it under8# the terms of the GNU General Public License as published by the9# Free Software Foundation, either version 3 of the License, or any later10# version. See the LICENSE.txt file at the top-level directory of this11# distribution for a copy of the license or check <https://www.gnu.org/licenses/>.12#13# SPDX-License-Identifier: GPL-3.0-or-later14import itertools15import os16import hypothesis as hyp17import hypothesis.strategies as hyp_st18import numpy as np19import pytest20import gt4py.backend as gt_backend21import gt4py.storage as gt_store22from gt4py.storage.utils import cpu_copy23from ..definitions import ALL_BACKENDS24from ..reference_cpp_regression import reference_module25from .utils import id_version # import fixture used by pytest26from .utils import generate_test_module27REGISTRY = list()28def register(cpp_regression_test):29 REGISTRY.append(cpp_regression_test)30 return cpp_regression_test31def get_reference(test_name, backend, domain, origins, shapes, masks=None):32 reference_data = reference_module.__dict__[test_name](*domain)33 res = {}34 for k, data in reference_data.items():35 if np.isscalar(data):36 res[k] = np.float_(data)37 else:38 try:39 field = gt_store.from_array(40 data,41 dtype=np.float_,42 aligned_index=origins[k],43 backend=backend.name,44 )45 except KeyError:46 field = gt_store.from_array(47 data,48 dtype=np.float_,49 aligned_index=origins[k[: -len("_reference")]],50 backend=backend.name,51 )52 res[k] = field53 return res54@register55@hyp.given(domain=hyp_st.tuples(*([hyp_st.integers(min_value=1, max_value=8)] * 3)))56def run_horizontal_diffusion(backend, id_version, domain):57 validate_field_names = ["out_field"]58 origins = {"in_field": (2, 2, 0), "out_field": (0, 0, 0), "coeff": (0, 0, 0)}59 shapes = {60 name: tuple(domain[i] + 2 * origin[i] for i in range(3)) for name, origin in origins.items()61 }62 name = "horizontal_diffusion"63 arg_fields = get_reference(name, backend, domain, origins, shapes)64 validate_fields = {65 name + "_reference": arg_fields.pop(name + "_reference") for name in validate_field_names66 }67 testmodule = generate_test_module(68 "horizontal_diffusion", backend, id_version=id_version, rebuild=False69 )70 testmodule.run(71 **arg_fields,72 _domain_=domain,73 _origin_=origins,74 exec_info=None,75 )76 for k in validate_field_names:77 np.testing.assert_allclose(78 cpu_copy(arg_fields[k]), cpu_copy(validate_fields[k + "_reference"])79 )80@register81@hyp.given(82 domain=hyp_st.tuples(83 *(84 [hyp_st.integers(min_value=1, max_value=32)] * 285 + [hyp_st.integers(min_value=2, max_value=32)]86 )87 )88)89def run_tridiagonal_solver(backend, id_version, domain):90 validate_field_names = ["out"]91 origins = {92 "inf": (0, 0, 0),93 "diag": (0, 0, 0),94 "sup": (0, 0, 0),95 "rhs": (0, 0, 0),96 "out": (0, 0, 0),97 }98 shapes = {99 name: tuple(domain[i] + 2 * origin[i] for i in range(3)) for name, origin in origins.items()100 }101 name = "tridiagonal_solver"102 arg_fields = get_reference(name, backend, domain, origins, shapes)103 validate_fields = {104 name + "_reference": arg_fields.pop(name + "_reference") for name in validate_field_names105 }106 testmodule = generate_test_module(107 "tridiagonal_solver", backend, id_version=id_version, rebuild=False108 )109 testmodule.run(110 **arg_fields,111 _domain_=domain,112 _origin_=origins,113 exec_info=None,114 )115 for k in validate_field_names:116 if hasattr(arg_fields[k], "synchronize"):117 arg_fields[k].device_to_host(force=True)118 np.testing.assert_allclose(119 cpu_copy(arg_fields[k]), cpu_copy(validate_fields[k + "_reference"])120 )121@register122@hyp.given(123 domain=hyp_st.tuples(124 *(125 [hyp_st.integers(min_value=1, max_value=32)] * 2126 + [hyp_st.integers(min_value=2, max_value=32)]127 )128 )129)130def run_vertical_advection_dycore(backend, id_version, domain):131 validate_field_names = ["utens_stage"]132 origins = {133 "utens_stage": (0, 0, 0),134 "u_stage": (0, 0, 0),135 "wcon": (0, 0, 0),136 "u_pos": (0, 0, 0),137 "utens": (0, 0, 0),138 }139 shapes = {140 "utens_stage": domain,141 "u_stage": domain,142 "wcon": tuple(d + 1 if i == 0 else d for i, d in enumerate(domain)),143 "u_pos": domain,144 "utens": domain,145 }146 name = "vertical_advection_dycore"147 arg_fields = get_reference(name, backend, domain, origins, shapes)148 validate_fields = {149 name + "_reference": arg_fields.pop(name + "_reference") for name in validate_field_names150 }151 testmodule = generate_test_module(152 "vertical_advection_dycore", backend, id_version=id_version, rebuild=False153 )154 testmodule.run(155 **arg_fields,156 _domain_=domain,157 _origin_=origins,158 # _origin_={159 # k: [oo[0] if isinstance(oo, tuple) else oo for oo in o] for k, o in origins.items()160 # },161 exec_info=None,162 )163 for k in validate_field_names:164 np.testing.assert_allclose(165 cpu_copy(arg_fields[k]), cpu_copy(validate_fields[k + "_reference"])166 )167@register168@hyp.given(169 domain=hyp_st.tuples(170 *(171 [hyp_st.integers(min_value=1, max_value=32)] * 2172 + [hyp_st.integers(min_value=16, max_value=32)]173 )174 )175)176def run_large_k_interval(backend, id_version, domain):177 """Test stencils with large static and potentially zero-length intervals."""178 validate_field_names = ["out_field"]179 origins = {"in_field": (0, 0, 0), "out_field": (0, 0, 0)}180 shapes = {181 name: tuple(domain[i] + 2 * origin[i] for i in range(3)) for name, origin in origins.items()182 }183 name = "large_k_interval"184 arg_fields = get_reference(name, backend, domain, origins, shapes)185 validate_fields = {186 name + "_reference": arg_fields.pop(name + "_reference") for name in validate_field_names187 }188 testmodule = generate_test_module(189 "large_k_interval", backend, id_version=id_version, rebuild=False190 )191 testmodule.run(192 **arg_fields,193 _domain_=domain,194 _origin_=origins,195 exec_info=None,196 )197 for k in validate_field_names:198 if hasattr(arg_fields[k], "synchronize"):199 arg_fields[k].device_to_host(force=True)200 np.testing.assert_allclose(201 cpu_copy(arg_fields[k]), cpu_copy(validate_fields[k + "_reference"])202 )203@pytest.mark.parametrize("backend", ALL_BACKENDS)204@pytest.mark.parametrize("function", REGISTRY)205def test_cpp_regression(backend, id_version, function):...

Full Screen

Full Screen

function_applier.py

Source:function_applier.py Github

copy

Full Screen

...11 :param field_name_to_func: a dict of mappings, where values are12 functions of the form: x -> y.13 """14 try:15 validate_field_names(list(field_name_to_func.keys()))16 except Exception as e:17 raise e18 for f in field_name_to_func.values():19 if not callable(f):20 raise ValueError("Please provide all valid callable functions.")21 super(FunctionApplier, self).__init__(**kwargs)22 self.field_name_to_func = field_name_to_func23 def _transform(self, data_chunk):24 """25 :param data_chunk: self-explanatory.26 :return data_chunk: same as input but with modified values.27 """28 for field_name, func in self.field_name_to_func.items():29 data_chunk[field_name] = func(data_chunk[field_name])...

Full Screen

Full Screen

field_selector.py

Source:field_selector.py Github

copy

Full Screen

...11 fields that should be selected from data-chunks.12 Other fields are discarded.13 """14 try:15 validate_field_names(fnames)16 except Exception as e:17 raise e18 super(FieldSelector, self).__init__(**kwargs)19 self.fnames = listify(fnames)20 def _transform(self, data_chunk):21 fn_set = set(self.fnames)22 for fn in fn_set:23 if fn not in data_chunk:24 raise ValueError(25 "The data-chunk does not have the `%s` field." % fn)26 fnames_to_del = [fn for fn in data_chunk if fn not in fn_set]27 for fn in fnames_to_del:28 del data_chunk[fn]29 return data_chunk

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful