From 82fac8cc941c8120bc772f88d383d881729c6425 Mon Sep 17 00:00:00 2001 From: Matt Smith Date: Thu, 22 Jun 2023 14:21:41 -0600 Subject: [PATCH 1/2] Fix issues with `==` in tests and update to work with numpy 1.25 (#917) * fix comparisons and disable == * fix issue after numpy 1.25 update * remove more == --- mirgecom/eos.py | 4 ++-- mirgecom/filter.py | 4 ++-- mirgecom/fluid.py | 5 +++-- mirgecom/gas_model.py | 2 +- mirgecom/transport.py | 2 +- test/test_av.py | 4 ++-- test/test_bc.py | 18 +++++++++--------- test/test_navierstokes.py | 2 +- test/test_symbolic.py | 13 ++++++++++--- 9 files changed, 31 insertions(+), 23 deletions(-) diff --git a/mirgecom/eos.py b/mirgecom/eos.py index 032b89721..5fdc7a1dc 100644 --- a/mirgecom/eos.py +++ b/mirgecom/eos.py @@ -65,7 +65,7 @@ class MixtureEOSNeededError(Exception): @dataclass_array_container -@dataclass(frozen=True) +@dataclass(frozen=True, eq=False) class GasDependentVars: """State-dependent quantities for :class:`GasEOS`. @@ -89,7 +89,7 @@ class GasDependentVars: @dataclass_array_container -@dataclass(frozen=True) +@dataclass(frozen=True, eq=False) class MixtureDependentVars(GasDependentVars): """Mixture state-dependent quantities for :class:`MixtureEOS`. diff --git a/mirgecom/filter.py b/mirgecom/filter.py index 3219688c6..9a4aa5959 100644 --- a/mirgecom/filter.py +++ b/mirgecom/filter.py @@ -87,9 +87,9 @@ def get_element_spectrum_from_modal_representation(actx, vol_discr, modal_fields Array with the element modes accumulated into the corresponding "modes" for the polynomial basis functions for each field. """ - modal_spectra = np.stack( + modal_spectra = np.stack([ actx.to_numpy(ary)[0] - for ary in modal_fields) + for ary in modal_fields]) numfields, numelem, nummodes = modal_spectra.shape diff --git a/mirgecom/fluid.py b/mirgecom/fluid.py index 9d9de8ef4..1609f03fc 100644 --- a/mirgecom/fluid.py +++ b/mirgecom/fluid.py @@ -52,9 +52,10 @@ bcast_container_types=(DOFArray, np.ndarray), matmul=True, _cls_has_array_context_attr=True, - rel_comparison=True) + eq_comparison=False, + rel_comparison=False) @dataclass_array_container -@dataclass(frozen=True) +@dataclass(frozen=True, eq=False) class ConservedVars: r"""Store and resolve quantities according to the fluid conservation equations. diff --git a/mirgecom/gas_model.py b/mirgecom/gas_model.py index 7ae828067..9424dedcc 100644 --- a/mirgecom/gas_model.py +++ b/mirgecom/gas_model.py @@ -94,7 +94,7 @@ class GasModel: @dataclass_array_container -@dataclass(frozen=True) +@dataclass(frozen=True, eq=False) class FluidState: r"""Gas model-consistent fluid state. diff --git a/mirgecom/transport.py b/mirgecom/transport.py index 0208b4e5f..4f6e5bf6f 100644 --- a/mirgecom/transport.py +++ b/mirgecom/transport.py @@ -63,7 +63,7 @@ class TransportModelError(Exception): @dataclass_array_container -@dataclass(frozen=True) +@dataclass(frozen=True, eq=False) class GasTransportVars: """State-dependent quantities for :class:`TransportModel`. diff --git a/test/test_av.py b/test/test_av.py index b6d1ce285..9bacad867 100644 --- a/test/test_av.py +++ b/test/test_av.py @@ -454,10 +454,10 @@ def _boundary_state_func(dcoll, dd_bdry, gas_model, state_minus, **kwargs): bnd_flux_resid = (prescribed_boundary_av_flux - exp_av_flux) print(f"{bnd_flux_resid=}") - assert bnd_flux_resid == 0 + assert actx.np.equal(bnd_flux_resid, 0) # Solid wall boundaries are expected to have 0 AV flux wall_bnd_flux = \ adiabatic_noslip.av_flux(dcoll, BTAG_ALL, av_diffusion) print(f"adiabatic_noslip: {wall_bnd_flux=}") - assert wall_bnd_flux == 0 + assert actx.np.equal(wall_bnd_flux, 0) diff --git a/test/test_bc.py b/test/test_bc.py index 2e36ecb0c..d786745d9 100644 --- a/test/test_bc.py +++ b/test/test_bc.py @@ -291,7 +291,7 @@ def gradient_flux_interior(int_tpair): grad_t_minus=grad_t_minus) print(f"{v_flux_bc=}") - assert ff_bndry_state.cv == exp_ff_cv + assert actx.np.equal(ff_bndry_state.cv, exp_ff_cv) assert actx.np.all(temperature_bc == ff_temp) for idim in range(dim): assert actx.np.all(ff_bndry_state.momentum_density[idim] @@ -387,7 +387,7 @@ def test_outflow_boundary(actx_factory, dim, flux_func): print(f"{exp_flowbnd_cv=}") - assert flowbnd_bndry_state.cv == exp_flowbnd_cv + assert actx.np.equal(flowbnd_bndry_state.cv, exp_flowbnd_cv) assert actx.np.all(flowbnd_bndry_temperature == flowbnd_press_bc) assert actx.np.all(flowbnd_bndry_pressure == flowbnd_press_bc) @@ -421,7 +421,7 @@ def test_outflow_boundary(actx_factory, dim, flux_func): exp_flowbnd_cv = make_conserved(dim=dim, mass=bnd_dens, momentum=bnd_mom, energy=bnd_ener) - assert flowbnd_bndry_state.cv == exp_flowbnd_cv + assert actx.np.equal(flowbnd_bndry_state.cv, exp_flowbnd_cv) @pytest.mark.parametrize("dim", [1, 2, 3]) @@ -585,7 +585,7 @@ def gradient_flux_interior(int_tpair): grad_t_minus=grad_t_minus) print(f"{v_flux_bc=}") - assert wall_state.cv == expected_noslip_cv + assert actx.np.equal(wall_state.cv, expected_noslip_cv) assert actx.np.all(temperature_bc == expected_wall_temperature) for idim in range(dim): assert actx.np.all(wall_state.momentum_density[idim] @@ -762,8 +762,8 @@ def gradient_flux_interior(int_tpair): grad_t_minus=grad_t_minus) print(f"{v_flux_bc=}") - assert adv_wall_state.cv == expected_adv_wall_cv - assert diff_wall_state.cv == expected_diff_wall_cv + assert actx.np.equal(adv_wall_state.cv, expected_adv_wall_cv) + assert actx.np.equal(diff_wall_state.cv, expected_diff_wall_cv) assert actx.np.all(temperature_bc == expected_wall_temperature) for idim in range(dim): assert actx.np.all(adv_wall_state.momentum_density[idim] @@ -956,8 +956,8 @@ def gradient_flux_interior(int_tpair): temperature_bc = wall.temperature_bc( dcoll, dd_bdry=BTAG_ALL, state_minus=state_minus) - assert adv_wall_state.cv == expected_adv_wall_cv - assert diff_wall_state.cv == expected_diff_wall_cv + assert actx.np.equal(adv_wall_state.cv, expected_adv_wall_cv) + assert actx.np.equal(diff_wall_state.cv, expected_diff_wall_cv) assert actx.np.all(temperature_bc == expected_temp_boundary) for idim in range(dim): @@ -1342,4 +1342,4 @@ def scalar_flux_interior(int_tpair): bc_soln = \ domain_boundary._boundary_state_pair(dcoll, BTAG_ALL, gas_model, state_minus=state_minus).ext.cv - assert bc_soln == expected_boundary_solution + assert actx.np.equal(bc_soln, expected_boundary_solution) diff --git a/test/test_navierstokes.py b/test/test_navierstokes.py index 3f9522cf8..e739b3c73 100644 --- a/test/test_navierstokes.py +++ b/test/test_navierstokes.py @@ -615,7 +615,7 @@ def test_exact_mms(actx_factory, order, dim, manufactured_soln, mu): tol = 1e-15 if mu == 0: - assert sym_ns_source == sym_euler_source + assert actx.np.equal(sym_ns_source, sym_euler_source) sym_source = sym_euler_source else: sym_source = sym_ns_source diff --git a/test/test_symbolic.py b/test/test_symbolic.py index 4979197aa..b40818e4c 100644 --- a/test/test_symbolic.py +++ b/test/test_symbolic.py @@ -131,16 +131,23 @@ def _array_container_deriv_pair(): _obj_array_deriv_pair(), _array_container_deriv_pair(), ]) -def test_symbolic_diff(sym_f, expected_sym_df): +def test_symbolic_diff(actx_factory, sym_f, expected_sym_df): """ Compute the symbolic derivative of an expression and compare it to an expected result. """ + actx = actx_factory() + sym_df = sym.diff(pmbl.var("x"))(sym_f) - if isinstance(sym_f, np.ndarray): + + from pymbolic.primitives import Expression + if isinstance(sym_f, Expression): + assert sym_df == expected_sym_df + elif isinstance(sym_f, np.ndarray): assert (sym_df == expected_sym_df).all() else: - assert sym_df == expected_sym_df + # Array container + assert actx.np.equal(sym_df, expected_sym_df) def test_symbolic_div(): From 11472b4718fad04d3799168c5b621052c946e2e4 Mon Sep 17 00:00:00 2001 From: Matthias Diener Date: Thu, 22 Jun 2023 17:26:03 -0500 Subject: [PATCH 2/2] Update deprecated zeros_like usage (#916) --- mirgecom/eos.py | 4 ++-- mirgecom/gas_model.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/mirgecom/eos.py b/mirgecom/eos.py index 5fdc7a1dc..1ea9a111d 100644 --- a/mirgecom/eos.py +++ b/mirgecom/eos.py @@ -187,7 +187,7 @@ def dependent_vars( temperature = self.temperature(cv, temperature_seed) # MJA, it doesn't appear that we can have a None field embedded inside DV, # make a dummy smoothness in this case - zeros = cv.array_context.zeros_like(cv.mass) + zeros = cv.array_context.np.zeros_like(cv.mass) if smoothness_mu is None: smoothness_mu = zeros if smoothness_kappa is None: @@ -265,7 +265,7 @@ def dependent_vars( temperature = self.temperature(cv, temperature_seed) # MJA, it doesn't appear that we can have a None field embedded inside DV, # make a dummy smoothness in this case - zeros = cv.array_context.zeros_like(cv.mass) + zeros = cv.array_context.np.zeros_like(cv.mass) if smoothness_mu is None: smoothness_mu = zeros if smoothness_kappa is None: diff --git a/mirgecom/gas_model.py b/mirgecom/gas_model.py index 9424dedcc..132bf5476 100644 --- a/mirgecom/gas_model.py +++ b/mirgecom/gas_model.py @@ -318,11 +318,11 @@ def make_fluid_state(cv, gas_model, temperature_seed=None, dd=limiter_dd) # FIXME work-around for now - smoothness_mu = (actx.zeros_like(pressure) if smoothness_mu + smoothness_mu = (actx.np.zeros_like(pressure) if smoothness_mu is None else smoothness_mu) - smoothness_kappa = (actx.zeros_like(pressure) if smoothness_kappa + smoothness_kappa = (actx.np.zeros_like(pressure) if smoothness_kappa is None else smoothness_kappa) - smoothness_beta = (actx.zeros_like(pressure) if smoothness_beta + smoothness_beta = (actx.np.zeros_like(pressure) if smoothness_beta is None else smoothness_beta) dv = GasDependentVars(