From 3870fd92386ff4d38adfac9750e6f35f2cf36349 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Keck <Jean-Baptiste.Keck@imag.fr> Date: Mon, 2 Nov 2020 16:27:39 +0100 Subject: [PATCH] demove hysop.deps --- ci/scripts/test.sh | 2 +- hysop/__init__.py.in | 4 -- hysop/backend/device/autotunable_kernel.py | 2 +- hysop/backend/device/codegen/base/codegen.py | 2 +- .../device/codegen/base/kernel_codegen.py | 2 +- .../backend/device/codegen/base/variables.py | 7 +- .../device/codegen/functions/apply_stencil.py | 2 +- .../device/codegen/functions/complex.py | 4 +- .../codegen/functions/directional_remesh.py | 7 +- .../device/codegen/functions/polynomial.py | 3 +- .../codegen/functions/stretching_rhs.py | 2 +- .../device/codegen/kernels/custom_symbolic.py | 4 +- .../codegen/kernels/directional_advection.py | 7 +- .../codegen/kernels/directional_remesh.py | 8 +-- .../codegen/kernels/directional_stretching.py | 4 +- .../tests/test_codegen_directional_remesh.py | 2 +- .../kernels/tests/test_codegen_transpose.py | 4 +- .../device/codegen/kernels/transpose.py | 4 +- .../backend/device/codegen/structs/indices.py | 2 +- .../device/codegen/structs/mesh_info.py | 2 +- .../symbolic/functions/apply_stencil.py | 8 +-- .../functions/custom_symbolic_function.py | 2 +- hysop/backend/device/codegen/symbolic/map.py | 3 +- .../device/codegen/unions/float_int.py | 19 +++-- hysop/backend/device/kernel_autotuner.py | 9 ++- .../autotunable_kernels/custom_symbolic.py | 2 +- .../opencl/autotunable_kernels/remesh_dir.py | 3 +- hysop/backend/device/opencl/clpeak.py | 5 +- .../backend/device/opencl/opencl_allocator.py | 4 +- .../device/opencl/opencl_array_backend.py | 12 ++-- .../opencl/opencl_autotunable_kernel.py | 4 +- .../opencl/opencl_copy_kernel_launchers.py | 2 +- hysop/backend/device/opencl/opencl_device.py | 3 +- hysop/backend/device/opencl/opencl_env.py | 4 +- hysop/backend/device/opencl/opencl_kernel.py | 3 +- .../device/opencl/opencl_kernel_launcher.py | 4 +- .../backend/device/opencl/opencl_operator.py | 4 +- hysop/backend/device/opencl/opencl_tools.py | 3 +- hysop/backend/device/opencl/opencl_types.py | 6 +- .../device/opencl/operator/analytic.py | 2 +- hysop/backend/device/opencl/operator/curl.py | 14 ++-- .../device/opencl/operator/derivative.py | 11 ++- .../operator/directional/advection_dir.py | 9 ++- .../opencl_directional_operator.py | 11 +-- .../operator/directional/stretching_dir.py | 62 ++++++++-------- .../device/opencl/operator/enstrophy.py | 7 +- .../device/opencl/operator/external_force.py | 11 ++- .../device/opencl/operator/integrate.py | 4 -- .../opencl/operator/memory_reordering.py | 8 ++- .../backend/device/opencl/operator/poisson.py | 14 ++-- .../device/opencl/operator/poisson_curl.py | 3 + .../device/opencl/operator/transpose.py | 4 -- hysop/backend/hardware/hwinfo.py | 6 +- hysop/backend/hardware/machine.py | 4 +- hysop/backend/hardware/pci.py | 3 +- hysop/backend/host/host_allocator.py | 4 +- hysop/backend/host/host_array.py | 3 +- hysop/backend/host/host_array_backend.py | 5 +- hysop/backend/host/host_buffer.py | 14 ++-- .../host/python/operator/convergence.py | 4 ++ hysop/backend/host/python/operator/custom.py | 9 +++ .../host/python/operator/derivative.py | 16 ++--- .../operator/directional/advection_dir.py | 2 +- .../backend/host/python/operator/enstrophy.py | 5 ++ .../backend/host/python/operator/integrate.py | 4 ++ .../host/python/operator/memory_reordering.py | 8 ++- hysop/backend/host/python/operator/min_max.py | 8 ++- .../python/operator/vorticity_absorption.py | 9 +-- hysop/constants.py.in | 4 +- hysop/core/arrays/array_backend.py | 5 +- hysop/core/graph/allocator.py | 4 +- hysop/core/graph/computational_graph.py | 6 +- hysop/core/graph/computational_node.py | 2 +- hysop/core/graph/graph_builder.py | 4 +- hysop/core/memory/buffer.py | 4 +- hysop/core/memory/memory_request.py | 3 +- hysop/core/memory/mempool.py | 6 +- hysop/core/memory/tests/test_buffer.py | 3 +- hysop/core/memory/tests/test_mempool.py | 3 +- hysop/core/mpi/redistribute.py | 2 + hysop/deps.py | 39 ---------- hysop/domain/box.py | 7 +- hysop/domain/domain.py | 4 +- hysop/fields/cartesian_discrete_field.py | 4 +- hysop/fields/discrete_field.py | 3 +- hysop/fields/field_requirements.py | 12 ++-- hysop/fields/ghost_exchangers.py | 6 +- hysop/fields/tests/test_cartesian.py | 4 +- hysop/mesh/cartesian_mesh.py | 2 +- hysop/numerics/odesolvers/runge_kutta.py | 2 +- hysop/numerics/remesh/kernel_generator.py | 11 ++- hysop/numerics/remesh/remesh.py | 3 +- hysop/numerics/stencil/stencil.py | 7 +- hysop/numerics/stencil/stencil_generator.py | 13 +++- hysop/numerics/tests/bench_fft.py | 8 +-- hysop/numerics/tests/test_fft.py | 5 +- hysop/operator/adapt_timestep.py | 62 +++++++++++++++- hysop/operator/advection.py | 20 +++++- hysop/operator/analytic.py | 9 +++ hysop/operator/base/convergence.py | 6 ++ .../operator/base/custom_symbolic_operator.py | 4 +- hysop/operator/base/derivative.py | 3 +- hysop/operator/base/enstrophy.py | 7 ++ hysop/operator/base/external_force.py | 12 ++++ hysop/operator/base/integrate.py | 8 +++ hysop/operator/base/memory_reordering.py | 10 +++ hysop/operator/base/min_max.py | 72 +++++++++++-------- hysop/operator/base/redistribute_operator.py | 6 ++ hysop/operator/base/spatial_filtering.py | 4 +- hysop/operator/base/stretching_dir.py | 4 +- hysop/operator/convergence.py | 9 ++- hysop/operator/curl.py | 21 ++++-- hysop/operator/custom.py | 6 ++ hysop/operator/custom_symbolic.py | 25 ++++--- hysop/operator/diffusion.py | 12 ++++ hysop/operator/directional/diffusion_dir.py | 3 +- .../directional/stretching_diffusion_dir.py | 10 ++- hysop/operator/directional/stretching_dir.py | 2 +- hysop/operator/directional/symbolic_dir.py | 15 ++++ hysop/operator/dummy.py | 6 ++ hysop/operator/enstrophy.py | 14 +++- hysop/operator/external_force.py | 15 ++++ hysop/operator/flowrate_correction.py | 13 ++++ hysop/operator/gradient.py | 4 +- hysop/operator/hdf_io.py | 16 +++-- hysop/operator/integrate.py | 67 ++++++++++++++++- hysop/operator/kinetic_energy.py | 49 ++++++++----- hysop/operator/mean_field.py | 7 +- hysop/operator/memory_reordering.py | 12 ++++ hysop/operator/min_max.py | 71 +++++++++--------- hysop/operator/parameter_plotter.py | 12 ++++ hysop/operator/penalization.py | 17 +++++ hysop/operator/poisson.py | 10 ++- hysop/operator/poisson_curl.py | 17 +++-- hysop/operator/redistribute.py | 65 ++++++++--------- hysop/operator/solenoidal_projection.py | 36 ++++++---- hysop/operator/spatial_filtering.py | 22 ++++++ hysop/operator/tests/test_absorption.py | 4 +- hysop/operator/tests/test_analytic.py | 4 +- .../operator/tests/test_bilevel_advection.py | 3 +- hysop/operator/tests/test_custom_symbolic.py | 5 +- .../tests/test_directional_advection.py | 5 +- .../tests/test_directional_diffusion.py | 5 +- .../tests/test_directional_stretching.py | 6 +- hysop/operator/tests/test_fd_derivative.py | 4 +- hysop/operator/tests/test_penalization.py | 2 +- hysop/operator/tests/test_poisson.py | 7 +- hysop/operator/tests/test_poisson_curl.py | 4 +- .../operator/tests/test_restriction_filter.py | 3 + hysop/operator/tests/test_scales_advection.py | 3 +- .../tests/test_solenoidal_projection.py | 5 +- hysop/operator/tests/test_spectral_curl.py | 7 +- .../tests/test_spectral_derivative.py | 5 +- hysop/operator/tests/test_transpose.py | 4 +- .../tests/test_velocity_correction.py | 11 +-- hysop/operator/vorticity_absorption.py | 18 ++++- hysop/operators.py | 14 ++-- hysop/parameters/buffer_parameter.py | 26 +++---- hysop/parameters/scalar_parameter.py | 2 +- hysop/parameters/tensor_parameter.py | 5 +- hysop/problem.py | 1 - hysop/simulation.py | 3 +- hysop/symbolic/array.py | 1 - hysop/symbolic/base.py | 2 +- hysop/symbolic/directional.py | 5 +- hysop/symbolic/field.py | 3 +- hysop/symbolic/func.py | 3 +- hysop/symbolic/misc.py | 12 ++-- hysop/symbolic/parameter.py | 2 +- hysop/symbolic/relational.py | 26 +++---- hysop/tools/cache.py | 2 +- hysop/tools/contexts.py | 5 +- hysop/tools/decorators.py | 4 +- hysop/tools/handle.py | 11 ++- hysop/tools/hash.py | 4 +- hysop/tools/misc.py | 4 +- hysop/tools/mpi_utils.py | 2 +- hysop/tools/numerics.py | 5 +- hysop/tools/numpywrappers.py | 2 +- hysop/tools/sympy_utils.py | 8 ++- hysop/tools/transposition_states.py | 2 +- hysop/tools/types.py | 2 +- hysop/tools/units.py | 2 +- hysop/tools/warning.py | 4 +- hysop/topology/cartesian_descriptor.py | 3 +- hysop/topology/cartesian_topology.py | 3 +- hysop_examples/examples/analytic/analytic.py | 6 +- .../particles_above_salt_symmetrized.py | 2 +- .../examples/shear_layer/shear_layer.py | 1 - 189 files changed, 1120 insertions(+), 559 deletions(-) delete mode 100644 hysop/deps.py diff --git a/ci/scripts/test.sh b/ci/scripts/test.sh index df3cb5b42..01bec6954 100755 --- a/ci/scripts/test.sh +++ b/ci/scripts/test.sh @@ -136,7 +136,7 @@ if [ "$RUN_TESTS" = true ]; then #hysop_test "operator/tests/test_poisson.py" #hysop_test "operator/tests/test_solenoidal_projection.py" #hysop_test "operator/tests/test_poisson_curl.py" - ${HYSOP_DIR}/fields/tests/test_cartesian.sh + #${HYSOP_DIR}/fields/tests/test_cartesian.sh ${HYSOP_DIR}/core/tests/test_checkpoint.sh fi diff --git a/hysop/__init__.py.in b/hysop/__init__.py.in index 997c1b758..45a998546 100644 --- a/hysop/__init__.py.in +++ b/hysop/__init__.py.in @@ -4,7 +4,6 @@ on hybrid architectures (MPI-GPU) """ import psutil, signal, traceback, threading, sys, os, warnings from functools import wraps -from hysop.deps import __builtin__, print_function # Register debug signals (SIGUSR1(10)=print the main stack, SIGUSR2(12)=print the stack of all threads) def dumpstack(signal, frame): @@ -97,9 +96,6 @@ else: host_rank, shm_rank = 0, 0 # define printing functions -def print(*args, **kargs): - """Wrap print function (because of python 3)""" - __builtin__.print(*args, **kargs) def vprint(*args, **kargs): """prints only if __VERBOSE__ has been set""" if __VERBOSE__: diff --git a/hysop/backend/device/autotunable_kernel.py b/hysop/backend/device/autotunable_kernel.py index 155126ca5..280185486 100644 --- a/hysop/backend/device/autotunable_kernel.py +++ b/hysop/backend/device/autotunable_kernel.py @@ -1,6 +1,6 @@ +import functools, itertools as it from abc import ABCMeta, abstractmethod -from hysop.deps import it, functools from hysop.tools.types import check_instance, first_not_None from hysop.tools.numpywrappers import npw from hysop.tools.misc import next_pow2, upper_pow2 diff --git a/hysop/backend/device/codegen/base/codegen.py b/hysop/backend/device/codegen/base/codegen.py index cc92c7d72..d3c227832 100644 --- a/hysop/backend/device/codegen/base/codegen.py +++ b/hysop/backend/device/codegen/base/codegen.py @@ -1,8 +1,8 @@ +import itertools as it, sys, os, string, tempfile, operator from contextlib import contextmanager from subprocess import call from hysop.tools.types import check_instance -from hysop.deps import it, sys, os, string, tempfile, operator from hysop.backend.device.opencl import cl from hysop.backend.device.codegen.base.utils import WriteOnceDict, VarDict from hysop.backend.device.codegen.base.variables import CodegenVariable diff --git a/hysop/backend/device/codegen/base/kernel_codegen.py b/hysop/backend/device/codegen/base/kernel_codegen.py index 9518e40d3..45d8b29c7 100644 --- a/hysop/backend/device/codegen/base/kernel_codegen.py +++ b/hysop/backend/device/codegen/base/kernel_codegen.py @@ -1,5 +1,5 @@ from contextlib import contextmanager -from hysop.deps import np +import numpy as np from hysop.tools.types import check_instance from hysop.constants import Backend diff --git a/hysop/backend/device/codegen/base/variables.py b/hysop/backend/device/codegen/base/variables.py index a46430f0d..19abfce87 100644 --- a/hysop/backend/device/codegen/base/variables.py +++ b/hysop/backend/device/codegen/base/variables.py @@ -1,5 +1,6 @@ +import re, copy +import numpy as np -from hysop.deps import np, re, copy from hysop.tools.types import to_list, check_instance, first_not_None import hysop.backend.device.opencl.opencl_types @@ -864,8 +865,8 @@ class CodegenVectorClBuiltin(CodegenVector): raise TypeError(msg) def declare(self, codegen=None, init=None, **kargs): - init = init or self.init - if isinstance(init,int): + init = first_not_None(init, self.init) + if isinstance(init, int): init = ','.join([self.typegen.dump(init) for _ in range(self.dim)]) init = '({})({})'.format(self.ctype,init) elif init.__class__ in [list,tuple,np.ndarray]: diff --git a/hysop/backend/device/codegen/functions/apply_stencil.py b/hysop/backend/device/codegen/functions/apply_stencil.py index 54e8f1e5f..614d1363f 100644 --- a/hysop/backend/device/codegen/functions/apply_stencil.py +++ b/hysop/backend/device/codegen/functions/apply_stencil.py @@ -1,5 +1,5 @@ +import sympy as sm -from hysop.deps import sm from hysop.tools.types import check_instance, first_not_None from hysop.backend.device.codegen.base.opencl_codegen import OpenClCodeGenerator from hysop.backend.device.codegen.base.function_codegen import OpenClFunctionCodeGenerator diff --git a/hysop/backend/device/codegen/functions/complex.py b/hysop/backend/device/codegen/functions/complex.py index 3f2e68faf..1225b48e3 100644 --- a/hysop/backend/device/codegen/functions/complex.py +++ b/hysop/backend/device/codegen/functions/complex.py @@ -1,5 +1,7 @@ from abc import ABCMeta, abstractmethod -from hysop.deps import sm, np +import sympy as sm +import numpy as np + from hysop.tools.types import check_instance from hysop.backend.device.codegen.base.opencl_codegen import OpenClCodeGenerator from hysop.backend.device.codegen.base.function_codegen import OpenClFunctionCodeGenerator diff --git a/hysop/backend/device/codegen/functions/directional_remesh.py b/hysop/backend/device/codegen/functions/directional_remesh.py index b234bee71..4e249a725 100644 --- a/hysop/backend/device/codegen/functions/directional_remesh.py +++ b/hysop/backend/device/codegen/functions/directional_remesh.py @@ -1,4 +1,7 @@ -from hysop.deps import sm, np, contextlib +import contextlib +import numpy as np +import sympy as sm + from hysop.tools.types import check_instance, first_not_None from hysop.backend.device.opencl.opencl_types import OpenClTypeGen @@ -30,7 +33,7 @@ class DirectionalRemeshFunction(OpenClFunctionCodeGenerator): check_instance(sboundary, tuple, values=BoundaryCondition) check_instance(remesh_kernel, (RemeshKernel, Kernel)) - assert remesh_kernel.n % 2 == 0 or remesh_kernel.n == 1 + assert (remesh_kernel.n % 2 == 0) or (remesh_kernel.n == 1) assert remesh_kernel.n > 0 use_short_circuit = first_not_None(use_short_circuit, typegen.use_short_circuit_ops) diff --git a/hysop/backend/device/codegen/functions/polynomial.py b/hysop/backend/device/codegen/functions/polynomial.py index c5b08ad38..0501e67e3 100644 --- a/hysop/backend/device/codegen/functions/polynomial.py +++ b/hysop/backend/device/codegen/functions/polynomial.py @@ -1,5 +1,6 @@ +import numpy as np +import sympy as sm -from hysop.deps import sm, np from hysop.tools.types import check_instance from hysop.backend.device.codegen.base.opencl_codegen import OpenClCodeGenerator from hysop.backend.device.codegen.base.function_codegen import OpenClFunctionCodeGenerator diff --git a/hysop/backend/device/codegen/functions/stretching_rhs.py b/hysop/backend/device/codegen/functions/stretching_rhs.py index 17d6d6a94..4ddd12faf 100644 --- a/hysop/backend/device/codegen/functions/stretching_rhs.py +++ b/hysop/backend/device/codegen/functions/stretching_rhs.py @@ -1,5 +1,5 @@ +import sympy as sm -from hysop.deps import sm from hysop.tools.types import check_instance from hysop.backend.device.codegen.base.opencl_codegen import OpenClCodeGenerator from hysop.backend.device.codegen.base.function_codegen import OpenClFunctionCodeGenerator diff --git a/hysop/backend/device/codegen/kernels/custom_symbolic.py b/hysop/backend/device/codegen/kernels/custom_symbolic.py index 47eb23757..a7d6aa0b8 100644 --- a/hysop/backend/device/codegen/kernels/custom_symbolic.py +++ b/hysop/backend/device/codegen/kernels/custom_symbolic.py @@ -1,10 +1,10 @@ -import contextlib +import contextlib, math, operator, hashlib from contextlib import contextmanager +import sympy as sm from abc import ABCMeta, abstractmethod from hysop import __VERBOSE__, __KERNEL_DEBUG__ -from hysop.deps import sm, math, operator, hashlib from hysop.core.arrays.all import OpenClArray from hysop.tools.contexts import nested from hysop.constants import DirectionLabels, BoundaryCondition, Backend, Precision, \ diff --git a/hysop/backend/device/codegen/kernels/directional_advection.py b/hysop/backend/device/codegen/kernels/directional_advection.py index 85a941c1f..218d4b008 100644 --- a/hysop/backend/device/codegen/kernels/directional_advection.py +++ b/hysop/backend/device/codegen/kernels/directional_advection.py @@ -1,7 +1,7 @@ -import contextlib +import contextlib, math, operator, hashlib from contextlib import contextmanager +import numpy as np -from hysop.deps import math, operator, hashlib from hysop.constants import DirectionLabels from hysop import __VERBOSE__, __KERNEL_DEBUG__ @@ -11,7 +11,6 @@ from hysop.tools.misc import Utils, upper_pow2_or_3 from hysop.tools.types import check_instance, first_not_None from hysop.tools.contexts import nested -from hysop.deps import np from hysop.constants import BoundaryCondition, Backend from hysop.core.arrays.all import OpenClArray @@ -80,7 +79,7 @@ class DirectionalAdvectionKernelGenerator(KernelCodeGenerator): msg='Bilevel support with multiple particles at a time has not been implemented yet.' raise NotImplementedError(msg) - known_vars = known_vars or dict() + known_vars = first_not_None(known_vars, {}) use_short_circuit = first_not_None(use_short_circuit, typegen.use_short_circuit_ops) diff --git a/hysop/backend/device/codegen/kernels/directional_remesh.py b/hysop/backend/device/codegen/kernels/directional_remesh.py index 90f6108a5..0027087b8 100644 --- a/hysop/backend/device/codegen/kernels/directional_remesh.py +++ b/hysop/backend/device/codegen/kernels/directional_remesh.py @@ -1,8 +1,8 @@ -import contextlib +import contextlib, math, operator, hashlib from contextlib import contextmanager +import numpy as np from hysop import __VERBOSE__, __KERNEL_DEBUG__ -from hysop.deps import np, math, operator, hashlib from hysop.tools.misc import Utils, upper_pow2_or_3 from hysop.tools.types import check_instance, first_not_None @@ -154,7 +154,7 @@ class DirectionalRemeshKernelGenerator(KernelCodeGenerator): if tuning_mode: unroll_loops = False - group_scalars = group_scalars or tuple(1 for _ in range(nscalars)) + group_scalars = first_not_None(group_scalars, tuple(1 for _ in range(nscalars))) check_instance(group_scalars, tuple, values=int) assert sum(group_scalars) == nscalars nfields = len(group_scalars) @@ -168,7 +168,7 @@ class DirectionalRemeshKernelGenerator(KernelCodeGenerator): msg = 'Local periodic boundary have been deprecated, use BoundaryCondition.NONE instead.' raise RuntimeError(msg) - known_vars = known_vars or dict() + known_vars = first_not_None(known_vars, {}) local_size_known = ('local_size' in known_vars) itype = 'int' diff --git a/hysop/backend/device/codegen/kernels/directional_stretching.py b/hysop/backend/device/codegen/kernels/directional_stretching.py index 54e6c730b..6c64a8817 100644 --- a/hysop/backend/device/codegen/kernels/directional_stretching.py +++ b/hysop/backend/device/codegen/kernels/directional_stretching.py @@ -1,5 +1,5 @@ - -from hysop.deps import np, operator, hashlib, contextlib +import operator, hashlib, contextlib +import numpy as np from hysop import __VERBOSE__, __KERNEL_DEBUG__ diff --git a/hysop/backend/device/codegen/kernels/tests/test_codegen_directional_remesh.py b/hysop/backend/device/codegen/kernels/tests/test_codegen_directional_remesh.py index 5bdf6abee..069ea02aa 100644 --- a/hysop/backend/device/codegen/kernels/tests/test_codegen_directional_remesh.py +++ b/hysop/backend/device/codegen/kernels/tests/test_codegen_directional_remesh.py @@ -1,6 +1,6 @@ +import copy, math from hysop import __ENABLE_LONG_TESTS__ -from hysop.deps import copy, math from hysop.testsenv import __HAS_OPENCL_BACKEND__, iter_clenv, opencl_failed, TestCartesianField from hysop.constants import BoundaryCondition, Precision diff --git a/hysop/backend/device/codegen/kernels/tests/test_codegen_transpose.py b/hysop/backend/device/codegen/kernels/tests/test_codegen_transpose.py index f9de9412f..152c89cad 100644 --- a/hysop/backend/device/codegen/kernels/tests/test_codegen_transpose.py +++ b/hysop/backend/device/codegen/kernels/tests/test_codegen_transpose.py @@ -1,8 +1,8 @@ - import copy, math, sys, os, tempfile +import itertools as it +import numpy as np from hysop import __ENABLE_LONG_TESTS__ -from hysop.deps import np, it from hysop.tools.misc import upper_pow2_or_3, prod from hysop.tools.types import check_instance from hysop.tools.numerics import is_integer diff --git a/hysop/backend/device/codegen/kernels/transpose.py b/hysop/backend/device/codegen/kernels/transpose.py index 7f399b71b..62b6b5277 100644 --- a/hysop/backend/device/codegen/kernels/transpose.py +++ b/hysop/backend/device/codegen/kernels/transpose.py @@ -1,5 +1,7 @@ from contextlib import contextmanager -from hysop.deps import np, operator +import operator +import numpy as np + from hysop.tools.contexts import nested from hysop.tools.misc import upper_pow2_or_3, prod from hysop.tools.decorators import static_vars diff --git a/hysop/backend/device/codegen/structs/indices.py b/hysop/backend/device/codegen/structs/indices.py index 1e1f44310..c1c3a54c8 100644 --- a/hysop/backend/device/codegen/structs/indices.py +++ b/hysop/backend/device/codegen/structs/indices.py @@ -1,5 +1,5 @@ +import numpy as np -from hysop.deps import np from hysop.tools.types import check_instance, first_not_None from hysop.tools.misc import upper_pow2_or_3 from hysop.backend.device.codegen.base.enum_codegen import EnumCodeGenerator diff --git a/hysop/backend/device/codegen/structs/mesh_info.py b/hysop/backend/device/codegen/structs/mesh_info.py index 2b30b6b7b..eab6cfd53 100644 --- a/hysop/backend/device/codegen/structs/mesh_info.py +++ b/hysop/backend/device/codegen/structs/mesh_info.py @@ -1,5 +1,5 @@ +import numpy as np -from hysop.deps import np from hysop.tools.types import check_instance, first_not_None from hysop.tools.misc import upper_pow2_or_3 from hysop.backend.device.codegen.base.enum_codegen import EnumCodeGenerator diff --git a/hysop/backend/device/codegen/symbolic/functions/apply_stencil.py b/hysop/backend/device/codegen/symbolic/functions/apply_stencil.py index 6291d7fcb..2ae48f967 100644 --- a/hysop/backend/device/codegen/symbolic/functions/apply_stencil.py +++ b/hysop/backend/device/codegen/symbolic/functions/apply_stencil.py @@ -1,5 +1,5 @@ +import sympy as sm -from hysop.deps import sm from hysop.tools.numpywrappers import npw from hysop.tools.types import check_instance, first_not_None @@ -18,9 +18,9 @@ from hysop.backend.device.codegen.symbolic.relational import OpenClMul, OpenClAd class CustomApplyStencilFunction(CustomSymbolicFunction): def __init__(self, csc, name, expr, target_ctype=None, **kwds): check_instance(expr, ApplyStencil) - super(CustomApplyStencilFunction, self).__init__(csc=csc, name=name, + super(CustomApplyStencilFunction, self).__init__(csc=csc, name=name, expr=expr, target_ctype=target_ctype, **kwds) - + def parse_expr(self, csc, name, expr, args, reqs): if isinstance(expr, ApplyStencil): stencil = expr.stencil @@ -29,7 +29,7 @@ class CustomApplyStencilFunction(CustomSymbolicFunction): def fn_call(i, fn_kwds): _fn_kwds = fn_kwds.copy() _fn_kwds['offset'] = '{}+{}'.format(fn_kwds['offset'], csc.typegen.dump(int(i))) - return FunctionCall(fn.ctype, fn, _fn_kwds) + return FunctionCall(fn.ctype, fn, _fn_kwds) factor = self.parse_expr(csc, name, stencil.factor, args, reqs) pexprs = () for (i, coeff) in stencil.iteritems(include_factor=False): diff --git a/hysop/backend/device/codegen/symbolic/functions/custom_symbolic_function.py b/hysop/backend/device/codegen/symbolic/functions/custom_symbolic_function.py index 437ae5fdc..77bc17ca3 100644 --- a/hysop/backend/device/codegen/symbolic/functions/custom_symbolic_function.py +++ b/hysop/backend/device/codegen/symbolic/functions/custom_symbolic_function.py @@ -1,5 +1,5 @@ +import sympy as sm -from hysop.deps import sm from hysop.tools.numpywrappers import npw from hysop.tools.types import check_instance, first_not_None from hysop.tools.numerics import is_fp, is_signed, is_unsigned, get_dtype, is_complex diff --git a/hysop/backend/device/codegen/symbolic/map.py b/hysop/backend/device/codegen/symbolic/map.py index bd0ba726c..111ec8392 100644 --- a/hysop/backend/device/codegen/symbolic/map.py +++ b/hysop/backend/device/codegen/symbolic/map.py @@ -1,4 +1,5 @@ -from hysop.deps import sm +import sympy as sm + from hysop.tools.types import check_instance from hysop.backend.device.codegen.symbolic.expr import TypedI from hysop.backend.device.codegen.symbolic.cast import OpenClCastUtils diff --git a/hysop/backend/device/codegen/unions/float_int.py b/hysop/backend/device/codegen/unions/float_int.py index 643d85f6e..dca99bf53 100644 --- a/hysop/backend/device/codegen/unions/float_int.py +++ b/hysop/backend/device/codegen/unions/float_int.py @@ -1,6 +1,5 @@ +import numpy as np - -from hysop.deps import np from hysop.tools.types import check_instance from hysop.backend.device.codegen.base.union_codegen import UnionCodeGenerator from hysop.backend.device.opencl.opencl_types import OpenClTypeGen @@ -10,18 +9,18 @@ class FloatIntegerUnion(UnionCodeGenerator): name,dtype,comments = self.build_dtype(typegen, ftype) - super(FloatIntegerUnion,self).__init__(name=name, - dtype=dtype, + super(FloatIntegerUnion,self).__init__(name=name, + dtype=dtype, typegen=typegen, - typedef=typedef, + typedef=typedef, comments=comments) - + @staticmethod def build_dtype(typegen, ftype): tg = typegen name = 'float_int' - + dtype = [] if ftype == 'half': name+='16' @@ -42,7 +41,7 @@ class FloatIntegerUnion(UnionCodeGenerator): msg='Unknown ftype \'{}\', only half, float and double are supported.' msg=msg.format(ftype) raise ValueError(msg) - + comments = [ 'Access value as a signed integer', 'Access value as a unsigned integer', @@ -57,12 +56,12 @@ if __name__ == '__main__': from hysop.backend.device.codegen.base.test import _test_typegen tg = _test_typegen() - + u1 = FloatIntegerUnion('double', tg) u2 = FloatIntegerUnion('float', tg, 'custom32') cg = OpenClCodeGenerator('test_generator',tg) - cg.declare_cl_extension('cl_khr_fp64') + cg.declare_cl_extension('cl_khr_fp64') cg.require('u1',u1) cg.require('u2',u2) diff --git a/hysop/backend/device/kernel_autotuner.py b/hysop/backend/device/kernel_autotuner.py index 12dd091a1..6ec3ce632 100644 --- a/hysop/backend/device/kernel_autotuner.py +++ b/hysop/backend/device/kernel_autotuner.py @@ -1,7 +1,12 @@ -import copy +import copy, os, hashlib, gzip, sys, warnings +import itertools as it +try: + import cPickle as pickle +except: + import pickle + from abc import ABCMeta, abstractmethod from hysop import __KERNEL_DEBUG__ -from hysop.deps import pickle, os, it, hashlib, gzip, sys, warnings from hysop.tools.units import time2str from hysop.tools.contexts import Timer from hysop.tools.types import check_instance diff --git a/hysop/backend/device/opencl/autotunable_kernels/custom_symbolic.py b/hysop/backend/device/opencl/autotunable_kernels/custom_symbolic.py index 562084234..dcb5daa29 100644 --- a/hysop/backend/device/opencl/autotunable_kernels/custom_symbolic.py +++ b/hysop/backend/device/opencl/autotunable_kernels/custom_symbolic.py @@ -1,5 +1,5 @@ +import warnings -from hysop.deps import warnings from hysop.tools.numpywrappers import npw from hysop.tools.types import check_instance from hysop.tools.numerics import is_complex diff --git a/hysop/backend/device/opencl/autotunable_kernels/remesh_dir.py b/hysop/backend/device/opencl/autotunable_kernels/remesh_dir.py index d334e6e5c..fa6230c9d 100644 --- a/hysop/backend/device/opencl/autotunable_kernels/remesh_dir.py +++ b/hysop/backend/device/opencl/autotunable_kernels/remesh_dir.py @@ -1,4 +1,5 @@ -from hysop.deps import warnings +import warnings + from hysop.tools.numpywrappers import npw from hysop.tools.types import check_instance from hysop.tools.misc import upper_pow2_or_3 diff --git a/hysop/backend/device/opencl/clpeak.py b/hysop/backend/device/opencl/clpeak.py index c1504b8c2..836d72b4e 100644 --- a/hysop/backend/device/opencl/clpeak.py +++ b/hysop/backend/device/opencl/clpeak.py @@ -1,9 +1,12 @@ +try: + import cPickle as pickle +except: + import pickle import tempfile, re, os, warnings, gzip, portalocker import subprocess32 as subprocess from xml.dom import minidom from hysop import vprint -from hysop.deps import pickle from hysop.tools.decorators import requires_cmd from hysop.tools.types import check_instance, first_not_None from hysop.tools.units import bdw2str, flops2str, iops2str diff --git a/hysop/backend/device/opencl/opencl_allocator.py b/hysop/backend/device/opencl/opencl_allocator.py index ec3a7c958..696258758 100644 --- a/hysop/backend/device/opencl/opencl_allocator.py +++ b/hysop/backend/device/opencl/opencl_allocator.py @@ -1,6 +1,6 @@ - from abc import ABCMeta, abstractmethod -from hysop.deps import np +import numpy as np + from hysop.backend.device.opencl import cl, cl_api from hysop.core.memory.allocator import AllocatorBase from hysop.backend.device.opencl.opencl_buffer import OpenClBuffer diff --git a/hysop/backend/device/opencl/opencl_array_backend.py b/hysop/backend/device/opencl/opencl_array_backend.py index fb232e2f2..f69a94776 100644 --- a/hysop/backend/device/opencl/opencl_array_backend.py +++ b/hysop/backend/device/opencl/opencl_array_backend.py @@ -1,7 +1,7 @@ +import os, re, warnings +import numpy as np -import warnings from hysop import __KERNEL_DEBUG__ -from hysop.deps import re, np, os from hysop.tools.types import check_instance, to_tuple from hysop.tools.misc import prod from hysop.tools.numerics import is_complex, get_dtype, float_to_complex_dtype, \ @@ -237,7 +237,7 @@ class _GenericScanKernel(object): index_dtype = np.int32, **kargs): - input_fetch_exprs = input_fetch_exprs or list() + input_fetch_exprs = first_not_None(input_fetch_exprs, []) self.kernel = clScan.GenericScanKernel(ctx=context, dtype=dtype, index_dtype=index_dtype, @@ -863,9 +863,9 @@ class OpenClArrayBackend(ArrayBackend): """ from hysop.core.arrays.all import OpenClArray - extra_kargs = extra_kargs or tuple() - kernel_build_kwargs = kernel_build_kwargs or dict() - kernel_call_kwargs = kernel_call_kwargs or dict() + extra_kargs = first_not_None(extra_kargs, ()) + kernel_build_kwargs = first_not_None(kernel_build_kwargs, {}) + kernel_call_kwargs = first_not_None(kernel_call_kwargs, {}) self._check_argtype('elementwise', 'ikargs', ikargs, tuple) self._check_argtype('elementwise', 'okargs', okargs, tuple) diff --git a/hysop/backend/device/opencl/opencl_autotunable_kernel.py b/hysop/backend/device/opencl/opencl_autotunable_kernel.py index 6f5e2e6f6..7f73c0766 100644 --- a/hysop/backend/device/opencl/opencl_autotunable_kernel.py +++ b/hysop/backend/device/opencl/opencl_autotunable_kernel.py @@ -1,7 +1,7 @@ -import subprocess, sys +import os, subprocess, sys from abc import ABCMeta, abstractmethod + from hysop import __KERNEL_DEBUG__, vprint -from hysop.deps import os from hysop.constants import Backend from hysop.tools.numpywrappers import npw from hysop.tools.types import check_instance, first_not_None, to_tuple, to_list diff --git a/hysop/backend/device/opencl/opencl_copy_kernel_launchers.py b/hysop/backend/device/opencl/opencl_copy_kernel_launchers.py index eb43816d9..6b6193157 100644 --- a/hysop/backend/device/opencl/opencl_copy_kernel_launchers.py +++ b/hysop/backend/device/opencl/opencl_copy_kernel_launchers.py @@ -1,6 +1,6 @@ +import numpy as np from hysop import vprint, dprint, __KERNEL_DEBUG__, __TRACE_KERNELS__ -from hysop.deps import np from hysop.constants import Backend from hysop.tools.decorators import debug from hysop.tools.types import check_instance, first_not_None, to_list diff --git a/hysop/backend/device/opencl/opencl_device.py b/hysop/backend/device/opencl/opencl_device.py index c38686647..e655427ea 100644 --- a/hysop/backend/device/opencl/opencl_device.py +++ b/hysop/backend/device/opencl/opencl_device.py @@ -1,7 +1,8 @@ import re, fractions +import numpy as np + from hysop.tools.types import check_instance from hysop import vprint -from hysop.deps import np from hysop.backend.device.opencl import cl, cl_api from hysop.constants import DeviceType, CacheType, MemoryType, FpConfig from hysop.tools.units import bytes2str, freq2str, time2str diff --git a/hysop/backend/device/opencl/opencl_env.py b/hysop/backend/device/opencl/opencl_env.py index 010152196..31328da03 100644 --- a/hysop/backend/device/opencl/opencl_env.py +++ b/hysop/backend/device/opencl/opencl_env.py @@ -1,6 +1,8 @@ +import hashlib, os, copy, re +import numpy as np + from hysop import vprint, dprint from hysop import __VERBOSE__, __KERNEL_DEBUG__, __DEFAULT_PLATFORM_ID__, __DEFAULT_DEVICE_ID__ -from hysop.deps import hashlib, np, os, copy, re from hysop.constants import Precision, DeviceType from hysop.tools.types import check_instance, first_not_None from hysop.tools.io_utils import IO diff --git a/hysop/backend/device/opencl/opencl_kernel.py b/hysop/backend/device/opencl/opencl_kernel.py index 5516aed30..429da47d7 100644 --- a/hysop/backend/device/opencl/opencl_kernel.py +++ b/hysop/backend/device/opencl/opencl_kernel.py @@ -66,8 +66,7 @@ class OpenClKernel(object): assert len(program.all_kernels())==1 self._kernel = program.all_kernels()[0] - default_args = default_args or {} - self.default_args = default_args + self.default_args = first_not_None(default_args, {}) def _get_name(self): """Get the name of this program.""" diff --git a/hysop/backend/device/opencl/opencl_kernel_launcher.py b/hysop/backend/device/opencl/opencl_kernel_launcher.py index b96823f27..f5a64f10a 100644 --- a/hysop/backend/device/opencl/opencl_kernel_launcher.py +++ b/hysop/backend/device/opencl/opencl_kernel_launcher.py @@ -1,6 +1,8 @@ +import warnings +import itertools as it from abc import ABCMeta, abstractmethod + from hysop import __KERNEL_DEBUG__, __TRACE_KERNELS__, __TRACE_NOCOPY__, __TRACE_NOACCUMULATE__ -from hysop.deps import it, warnings from hysop.tools.decorators import debug from hysop.tools.types import check_instance, first_not_None from hysop.tools.numpywrappers import npw diff --git a/hysop/backend/device/opencl/opencl_operator.py b/hysop/backend/device/opencl/opencl_operator.py index 3dcff415c..95259f3cf 100644 --- a/hysop/backend/device/opencl/opencl_operator.py +++ b/hysop/backend/device/opencl/opencl_operator.py @@ -76,8 +76,8 @@ class OpenClOperator(ComputationalGraphOperator, metaclass=ABCMeta): msg='mpi_params was {} and cl_env was {}.' - for topo in set(kwds.get('input_fields', []).values()).union( - kwds.get('output_fields',[]).values()): + for topo in set(kwds.get('input_fields', {}).values()).union( + kwds.get('output_fields',{}).values()): if isinstance(topo, Topology): if (cl_env is None): cl_env = topo.backend.cl_env diff --git a/hysop/backend/device/opencl/opencl_tools.py b/hysop/backend/device/opencl/opencl_tools.py index e0dc4de79..84032733d 100644 --- a/hysop/backend/device/opencl/opencl_tools.py +++ b/hysop/backend/device/opencl/opencl_tools.py @@ -12,7 +12,8 @@ """ -from hysop.deps import sys, os, re, itertools, hashlib, pickle, gzip, hashlib + +import sys, os, re, itertools, hashlib, gzip, hashlib from hysop import __VERBOSE__, __KERNEL_DEBUG__, \ __DEFAULT_PLATFORM_ID__, __DEFAULT_DEVICE_ID__ diff --git a/hysop/backend/device/opencl/opencl_types.py b/hysop/backend/device/opencl/opencl_types.py index f62930e1c..455fef9bb 100644 --- a/hysop/backend/device/opencl/opencl_types.py +++ b/hysop/backend/device/opencl/opencl_types.py @@ -1,5 +1,9 @@ +import string, re +import sympy as sm +import numpy as np +import itertools as it + from hysop import __KERNEL_DEBUG__, vprint, dprint -from hysop.deps import sm, np, it, string, re from hysop.backend.device.opencl import cl, clArray, clTypes from hysop.tools.numerics import MPZ, MPQ, MPFR, F2Q from hysop.tools.types import first_not_None, to_tuple diff --git a/hysop/backend/device/opencl/operator/analytic.py b/hysop/backend/device/opencl/operator/analytic.py index c601c860e..ff0d64cfc 100644 --- a/hysop/backend/device/opencl/operator/analytic.py +++ b/hysop/backend/device/opencl/operator/analytic.py @@ -1,5 +1,5 @@ +import sympy as sm -from hysop.deps import sm from hysop.tools.types import check_instance, first_not_None, to_tuple from hysop.tools.decorators import debug from hysop.fields.continuous_field import ScalarField, Field diff --git a/hysop/backend/device/opencl/operator/curl.py b/hysop/backend/device/opencl/operator/curl.py index 30d3b5afc..da4c64dfa 100644 --- a/hysop/backend/device/opencl/operator/curl.py +++ b/hysop/backend/device/opencl/operator/curl.py @@ -19,11 +19,15 @@ class OpenClSpectralCurl(SpectralCurlOperatorBase, OpenClSymbolic): """ Compute the curl by using an OpenCL FFT backend. """ - + + @debug + def __new__(cls, **kwds): + return super(OpenClSpectralCurl, cls).__new__(cls, **kwds) + @debug def __init__(self, **kwds): super(OpenClSpectralCurl, self).__init__(**kwds) - + assert (len(self.forward_transforms) % 2 == 0) N = len(self.forward_transforms)//2 @@ -32,10 +36,10 @@ class OpenClSpectralCurl(SpectralCurlOperatorBase, OpenClSymbolic): kernel_names = () for (i,(Ft,(tg,Ki))) in enumerate(zip(self.forward_transforms, self.K)): Fhs = Ft.output_symbolic_array('F{}_hat'.format(i)) - + kname = 'filter_curl_{}d_{}'.format(Fhs.dim, i) kernel_names += (kname,) - + is_complex = Ki.is_complex Ki = tg._indexed_wave_numbers[Ki] @@ -52,7 +56,7 @@ class OpenClSpectralCurl(SpectralCurlOperatorBase, OpenClSymbolic): self.require_symbolic_kernel(kname, expr) self._kernel_names = kernel_names - + @debug def setup(self, work): super(OpenClSpectralCurl, self).setup(work) diff --git a/hysop/backend/device/opencl/operator/derivative.py b/hysop/backend/device/opencl/operator/derivative.py index 7612f7db3..7de3304f7 100644 --- a/hysop/backend/device/opencl/operator/derivative.py +++ b/hysop/backend/device/opencl/operator/derivative.py @@ -1,5 +1,5 @@ +import sympy as sm -from hysop.deps import sm from hysop.symbolic import space_symbols from hysop.symbolic.complex import ComplexMul from hysop.constants import DirectionLabels @@ -22,6 +22,11 @@ from hysop.symbolic.relational import Assignment class OpenClFiniteDifferencesSpaceDerivative(FiniteDifferencesSpaceDerivativeBase, OpenClSymbolic): + + @debug + def __new__(cls, **kwds): + return super(OpenClFiniteDifferencesSpaceDerivative, cls).__new__(cls, require_tmp=False, **kwds) + @debug def __init__(self, **kwds): super(OpenClFiniteDifferencesSpaceDerivative, self).__init__(require_tmp=False, **kwds) @@ -58,6 +63,10 @@ class OpenClSpectralSpaceDerivative(SpectralSpaceDerivativeBase, OpenClSymbolic) using spectral methods. """ + @debug + def __new__(cls, **kwds): + return super(OpenClSpectralSpaceDerivative, cls).__new__(cls, **kwds) + @debug def __init__(self, **kwds): """ diff --git a/hysop/backend/device/opencl/operator/directional/advection_dir.py b/hysop/backend/device/opencl/operator/directional/advection_dir.py index 346e57752..84aa65eb0 100644 --- a/hysop/backend/device/opencl/operator/directional/advection_dir.py +++ b/hysop/backend/device/opencl/operator/directional/advection_dir.py @@ -14,8 +14,13 @@ class OpenClDirectionalAdvection(DirectionalAdvectionBase, OpenClDirectionalOper DEBUG=False @debug - def __init__(self, force_atomics=False, relax_min_particles=False, remesh_criteria_eps=None, - **kwds): + def __new__(cls, force_atomics=False, relax_min_particles=False, + remesh_criteria_eps=None, **kwds): + return super(OpenClDirectionalAdvection, cls).__new__(cls, **kwds) + + @debug + def __init__(self, force_atomics=False, relax_min_particles=False, + remesh_criteria_eps=None, **kwds): """ Particular advection of field(s) in a given direction, on opencl backend, with remeshing. diff --git a/hysop/backend/device/opencl/operator/directional/opencl_directional_operator.py b/hysop/backend/device/opencl/operator/directional/opencl_directional_operator.py index c78c299d8..6dffc4fc2 100644 --- a/hysop/backend/device/opencl/operator/directional/opencl_directional_operator.py +++ b/hysop/backend/device/opencl/operator/directional/opencl_directional_operator.py @@ -9,14 +9,7 @@ class OpenClDirectionalOperator(DirectionalOperatorBase, OpenClOperator): OpenCL kernels are build once per dimension in order to handle directional splitting with resolution non uniform in directions. - - Field requirements are set such that the current direction will + + Field requirements are set such that the current direction will be contiguous in memory. """ - - @debug - def __init__(self, **kwds): - """ - Create a directional operator in a given direction, OpenCl version. - """ - super(OpenClDirectionalOperator,self).__init__(**kwds) diff --git a/hysop/backend/device/opencl/operator/directional/stretching_dir.py b/hysop/backend/device/opencl/operator/directional/stretching_dir.py index cab44515b..93d3e26f6 100644 --- a/hysop/backend/device/opencl/operator/directional/stretching_dir.py +++ b/hysop/backend/device/opencl/operator/directional/stretching_dir.py @@ -1,6 +1,6 @@ +import numpy as np from hysop import Field, TopologyDescriptor -from hysop.deps import np from hysop.tools.decorators import debug from hysop.tools.types import check_instance from hysop.core.graph.graph import not_initialized, initialized, discretized, ready, op_apply @@ -20,23 +20,29 @@ from hysop.backend.device.codegen.kernels.directional_stretching import \ DirectionalStretchingKernel class OpenClDirectionalStretching(OpenClDirectionalOperator): - + __default_method = { #KernelConfig: KernelConfig(), - TimeIntegrator: Euler, + TimeIntegrator: Euler, StretchingFormulation: StretchingFormulation.GRAD_UW, SpaceDiscretization: SpaceDiscretization.FDC4 } - + __available_methods = { #KernelConfig: InstanceOf(KernelConfig), - TimeIntegrator: InstanceOf(ExplicitRungeKutta), + TimeIntegrator: InstanceOf(ExplicitRungeKutta), StretchingFormulation: InstanceOf(StretchingFormulation), SpaceDiscretization: InstanceOf(SpaceDiscretization) } @debug - def __init__(self, velocity, vorticity, vorticity_out, + def __new__(cls, velocity, vorticity, vorticity_out, + variables, **kwds): + return super(OpenClDirectionalStretching, cls).__new__(cls, + input_fields=None, output_fields=None, **kwds) + + @debug + def __init__(self, velocity, vorticity, vorticity_out, variables, **kwds): """ Directionnal stretching of vorticity in a given direction @@ -57,7 +63,7 @@ class OpenClDirectionalStretching(OpenClDirectionalOperator): Dictionary of continuous fields as keys and topologies as values. kwds: Extra parameters passed to generated directional operators. - + Attributes ---------- velocity: Field @@ -75,7 +81,7 @@ class OpenClDirectionalStretching(OpenClDirectionalOperator): input_fields = { velocity: variables[velocity], vorticity: variables[vorticity] } output_fields = { vorticity_out: variables[vorticity_out] } - + super(OpenClDirectionalStretching,self).__init__(input_fields=input_fields, output_fields=output_fields, **kwds) @@ -83,22 +89,22 @@ class OpenClDirectionalStretching(OpenClDirectionalOperator): self.vorticity_in = vorticity self.vorticity_out = vorticity_out self.is_inplace = (vorticity is vorticity_out) - + @debug def handle_method(self,method): super(OpenClDirectionalStretching,self).handle_method(method) - + self.space_discretization = method.pop(SpaceDiscretization) self.formulation = method.pop(StretchingFormulation) self.time_integrator = method.pop(TimeIntegrator) - + assert str(self.space_discretization)[:3] == 'FDC' self.order = int(str(self.space_discretization)[3:]) - + @debug def get_field_requirements(self): requirements = super(OpenClDirectionalStretching, self).get_field_requirements() - + direction = self.splitting_direction is_inplace = self.is_inplace @@ -113,7 +119,7 @@ class OpenClDirectionalStretching(OpenClDirectionalOperator): v_topo, v_requirements = requirements.get_input_requirement(velocity) win_topo, win_requirements = requirements.get_input_requirement(vorticity_in) wout_topo, wout_requirements = requirements.get_output_requirement(vorticity_out) - + if v_topo.mpi_params.size == 1: lboundary = v_topo.domain.lboundaries[-1] rboundary = v_topo.domain.rboundaries[-1] @@ -122,17 +128,17 @@ class OpenClDirectionalStretching(OpenClDirectionalOperator): rboundary = BoundaryCondition.NONE boundaries = (lboundary, rboundary) - v_ghosts, w_ghosts = DirectionalStretchingKernel.min_ghosts(boundaries, + v_ghosts, w_ghosts = DirectionalStretchingKernel.min_ghosts(boundaries, formulation, order, time_integrator, direction) v_requirements.min_ghosts = v_ghosts win_requirements.min_ghosts = w_ghosts - + if is_inplace: wout_requirements.min_ghosts = w_ghosts return requirements - + @debug def discretize(self): super(OpenClDirectionalStretching,self).discretize() @@ -140,17 +146,17 @@ class OpenClDirectionalStretching(OpenClDirectionalOperator): dvorticity_in = self.input_discrete_fields[self.vorticity_in] dvorticity_out = self.output_discrete_fields[self.vorticity_out] assert dvorticity_in.topology.topology is dvorticity_out.topology.topology - + vorticity_mesh_info_in = self.input_mesh_info[self.vorticity_in] vorticity_mesh_info_out = self.output_mesh_info[self.vorticity_out] - + self.dvelocity = dvelocity self.dvorticity_in = dvorticity_in self.dvorticity_out = dvorticity_out self.velocity_mesh_info = self.input_mesh_info[self.velocity] self.vorticity_mesh_info = vorticity_mesh_info_in - + @debug def setup(self, work): super(OpenClDirectionalStretching,self).setup(work) @@ -160,25 +166,25 @@ class OpenClDirectionalStretching(OpenClDirectionalOperator): self._collect_stretching_kernel() def _collect_stretching_kernel(self): - + velocity = self.dvelocity vorticity_in = self.dvorticity_in vorticity_out = self.dvorticity_out velocity_mesh_info = self.velocity_mesh_info vorticity_mesh_info = self.vorticity_mesh_info - + direction = self.splitting_direction formulation = self.formulation discretization = self.space_discretization time_integrator = self.time_integrator - + cl_env = self.cl_env precision = self.precision build_options = self.build_options() autotuner_config = self.autotuner_config - (kernel_launcher, kernel_args, kernel_args_mapping, + (kernel_launcher, kernel_args, kernel_args_mapping, total_work, per_work_statistic, cached_bytes) = \ DirectionalStretchingKernel.autotune( cl_env=cl_env, @@ -217,21 +223,21 @@ class OpenClDirectionalStretching(OpenClDirectionalOperator): @classmethod def supports_mpi(cls): return False - + # DirectionalOperatorBase @classmethod def supported_dimensions(cls): return [3] - + # ComputationalGraphNode @classmethod def supports_multiscale(cls): return False - + def _do_compute(self,simulation,dt_coeff,**kargs): dt = simulation.time_step * dt_coeff self._do_compute_impl(dt=dt,**kargs) - + def _do_compute_monoscale(self, dt): raise NotImplementedError() def _do_compute_multiscale(self, dt): diff --git a/hysop/backend/device/opencl/operator/enstrophy.py b/hysop/backend/device/opencl/operator/enstrophy.py index c067736e2..8310362d8 100644 --- a/hysop/backend/device/opencl/operator/enstrophy.py +++ b/hysop/backend/device/opencl/operator/enstrophy.py @@ -1,4 +1,5 @@ -from hysop.deps import sm +import sympy as sm + from hysop.constants import DirectionLabels from hysop.backend.device.opencl.opencl_array_backend import OpenClArrayBackend from hysop.tools.decorators import debug @@ -16,6 +17,10 @@ from hysop.symbolic.relational import Assignment class OpenClEnstrophy(EnstrophyBase, OpenClSymbolic): + @debug + def __new__(cls, **kwds): + return super(OpenClEnstrophy, cls).__new__(cls, **kwds) + @debug def __init__(self, **kwds): super(OpenClEnstrophy, self).__init__(**kwds) diff --git a/hysop/backend/device/opencl/operator/external_force.py b/hysop/backend/device/opencl/operator/external_force.py index dcc2690d3..35f0b356b 100644 --- a/hysop/backend/device/opencl/operator/external_force.py +++ b/hysop/backend/device/opencl/operator/external_force.py @@ -29,14 +29,23 @@ class OpenClSpectralExternalForce(SpectralExternalForceOperatorBase, OpenClSymbo Operator to compute the curl of a symbolic expression. """ + @debug + def __new__(cls, Fext, **kwds): + return super(OpenClSpectralExternalForce, cls).__new__(cls, Fext=Fext, **kwds) + @debug def __init__(self, Fext, **kwds): check_instance(Fext, SymbolicExternalForce) super(OpenClSpectralExternalForce, self).__init__(Fext=Fext, **kwds) - class SymbolicExternalForce(ExternalForce): + @debug + def __new__(cls, name, Fext, diffusion=None, **kwds): + return super(SymbolicExternalForce, cls).__new__(cls, + name=name, dim=None, Fext=Fext, **kwds) + + @debug def __init__(self, name, Fext, diffusion=None, **kwds): """ Specify an external force as a tuple of symbolic expressions. diff --git a/hysop/backend/device/opencl/operator/integrate.py b/hysop/backend/device/opencl/operator/integrate.py index 5682a5b62..8e0e76cbe 100644 --- a/hysop/backend/device/opencl/operator/integrate.py +++ b/hysop/backend/device/opencl/operator/integrate.py @@ -6,10 +6,6 @@ import pyopencl class OpenClIntegrate(IntegrateBase, OpenClOperator): - @debug - def __init__(self, **kwds): - super(OpenClIntegrate, self).__init__(**kwds) - @debug def get_field_requirements(self): # force 0 ghosts for the reduction (pyopencl reduction kernel) diff --git a/hysop/backend/device/opencl/operator/memory_reordering.py b/hysop/backend/device/opencl/operator/memory_reordering.py index 6a889d9f1..f770b060a 100644 --- a/hysop/backend/device/opencl/operator/memory_reordering.py +++ b/hysop/backend/device/opencl/operator/memory_reordering.py @@ -10,7 +10,11 @@ class OpenClMemoryReordering(MemoryReorderingBase, OpenClOperator): """ @debug - def __init__(self, **kwds): + def __new__(cls, **kwds): + return super(OpenClMemoryReordering, cls).__new__(cls, **kwds) + + @debug + def __init__(self, **kwds): """Initialize a MemoryReordering operator on the opencl backend.""" super(OpenClMemoryReordering, self).__init__(**kwds) msg='FATAL ERROR: OpenClMemoryReordering has been deprecated.' @@ -22,6 +26,6 @@ class OpenClMemoryReordering(MemoryReorderingBase, OpenClOperator): super(OpenClMemoryReordering,self).apply(**kwds) pass - def check_dfield_memory_order(self, dfield): + def check_dfield_memory_order(self, dfield): # force no checks pass diff --git a/hysop/backend/device/opencl/operator/poisson.py b/hysop/backend/device/opencl/operator/poisson.py index 8f7607b2d..de60ea3d2 100644 --- a/hysop/backend/device/opencl/operator/poisson.py +++ b/hysop/backend/device/opencl/operator/poisson.py @@ -18,16 +18,20 @@ class OpenClPoisson(PoissonOperatorBase, OpenClSymbolic): """ Solves the poisson equation using an OpenCL FFT backend. """ - + + @debug + def __new__(cls, **kwds): + return super(OpenClPoisson, cls).__new__(cls, **kwds) + @debug def __init__(self, **kwds): super(OpenClPoisson, self).__init__(**kwds) - + kernel_names = () for (i,(Ft,Wn)) in enumerate(zip(self.forward_transforms, self.wave_numbers)): Fhs = Ft.output_symbolic_array('F{}_hat'.format(i)) indices = local_indices_symbols[:Fhs.dim] - + kname = 'filter_poisson_{}d_{}'.format(Fhs.dim, i) kernel_names += (kname,) @@ -37,11 +41,11 @@ class OpenClPoisson(PoissonOperatorBase, OpenClSymbolic): F += indexed_Wi cond = LogicalAND(*tuple(LogicalEQ(idx,0) for idx in indices)) expr = Assignment(Fhs, Select(Fhs/F, 0, cond)) - + self.require_symbolic_kernel(kname, expr) self._kernel_names = kernel_names - + @debug def setup(self, work): super(OpenClPoisson, self).setup(work) diff --git a/hysop/backend/device/opencl/operator/poisson_curl.py b/hysop/backend/device/opencl/operator/poisson_curl.py index ad66521a1..23c229a37 100644 --- a/hysop/backend/device/opencl/operator/poisson_curl.py +++ b/hysop/backend/device/opencl/operator/poisson_curl.py @@ -22,6 +22,9 @@ class OpenClPoissonCurl(SpectralPoissonCurlOperatorBase, OpenClSymbolic): Solves the poisson-rotational equation using clFFT. ''' + def __new__(cls, **kwds): + return super(OpenClPoissonCurl, cls).__new__(cls, **kwds) + def __init__(self, **kwds): super(OpenClPoissonCurl, self).__init__(**kwds) dim = self.dim diff --git a/hysop/backend/device/opencl/operator/transpose.py b/hysop/backend/device/opencl/operator/transpose.py index c3baecaef..732dbdfb5 100644 --- a/hysop/backend/device/opencl/operator/transpose.py +++ b/hysop/backend/device/opencl/operator/transpose.py @@ -7,10 +7,6 @@ from hysop.backend.device.opencl.opencl_kernel_launcher import OpenClKernelListL class OpenClTranspose(TransposeOperatorBase, OpenClOperator): - @debug - def __init__(self, **kwds): - super(OpenClTranspose, self).__init__(**kwds) - @debug def setup(self, work): super(OpenClTranspose, self).setup(work) diff --git a/hysop/backend/hardware/hwinfo.py b/hysop/backend/hardware/hwinfo.py index 19080abab..3bfdf6bd3 100644 --- a/hysop/backend/hardware/hwinfo.py +++ b/hysop/backend/hardware/hwinfo.py @@ -1,11 +1,11 @@ - -import sys +import sys, subprocess, math, copy +import itertools as it +import numpy as np from xml.etree import cElementTree as ElementTree from abc import abstractmethod, ABCMeta from hysop import vprint from hysop.backend import __HAS_OPENCL_BACKEND__ -from hysop.deps import subprocess, math, np, it, copy from hysop.tools.enum import EnumFactory from hysop.tools.decorators import requires_cmd diff --git a/hysop/backend/hardware/machine.py b/hysop/backend/hardware/machine.py index 095ddb20b..c4a2eab44 100644 --- a/hysop/backend/hardware/machine.py +++ b/hysop/backend/hardware/machine.py @@ -1,7 +1,5 @@ - -from hysop.deps import platform +import platform, math, itertools as it from hysop.constants import System -from hysop.deps import it, math from hysop.tools.units import bytes2str from hysop.tools.contexts import printoptions from hysop.tools.cache import machine_id diff --git a/hysop/backend/hardware/pci.py b/hysop/backend/hardware/pci.py index fef7bd6a2..f423f3a80 100644 --- a/hysop/backend/hardware/pci.py +++ b/hysop/backend/hardware/pci.py @@ -1,4 +1,5 @@ -from hysop.deps import re, it +import re, itertools as it + from hysop.tools.enum import EnumFactory from hysop.tools.string_utils import prepend from hysop.backend.hardware.hwinfo import TopologyObject, bytes2str diff --git a/hysop/backend/host/host_allocator.py b/hysop/backend/host/host_allocator.py index 30339d028..f2cd99d2e 100644 --- a/hysop/backend/host/host_allocator.py +++ b/hysop/backend/host/host_allocator.py @@ -1,6 +1,6 @@ - +import cpuinfo from psutil import virtual_memory -from hysop.deps import cpuinfo + from hysop.constants import default_order from hysop.core.memory.allocator import AllocatorBase from hysop.backend.host.host_buffer import HostBuffer diff --git a/hysop/backend/host/host_array.py b/hysop/backend/host/host_array.py index dcaf51d8a..070256fe2 100644 --- a/hysop/backend/host/host_array.py +++ b/hysop/backend/host/host_array.py @@ -1,4 +1,5 @@ -from hysop.deps import np +import numpy as np + from hysop.core.arrays import MemoryType, MemoryOrdering from hysop.core.arrays import default_order from hysop.core.arrays.array import Array diff --git a/hysop/backend/host/host_array_backend.py b/hysop/backend/host/host_array_backend.py index ae05dcf9b..eaeee1e36 100644 --- a/hysop/backend/host/host_array_backend.py +++ b/hysop/backend/host/host_array_backend.py @@ -1,7 +1,6 @@ - - import warnings -from hysop.deps import np +import numpy as np + from hysop.constants import Backend from hysop.constants import HYSOP_REAL, HYSOP_INTEGER, HYSOP_BOOL from hysop.tools.decorators import wraps diff --git a/hysop/backend/host/host_buffer.py b/hysop/backend/host/host_buffer.py index a3e6c08be..9d343d21b 100644 --- a/hysop/backend/host/host_buffer.py +++ b/hysop/backend/host/host_buffer.py @@ -1,5 +1,5 @@ +import numpy as np -from hysop.deps import np from hysop.constants import MemoryOrdering, default_order from hysop.tools.types import check_instance from hysop.core.memory.buffer import Buffer, PooledBuffer @@ -9,7 +9,7 @@ class HostBuffer(np.ndarray, Buffer): Host buffer class. """ __array_priority__ = -1.0 - + def __new__(cls, size, shape=None, dtype=np.uint8, order=None, buffer=None, offset=0, strides=None): @@ -20,7 +20,7 @@ class HostBuffer(np.ndarray, Buffer): buffer = buffer.buf from_buffer = True - obj = super(HostBuffer,cls).__new__(cls, + obj = super(HostBuffer,cls).__new__(cls, shape=shape or (size,), dtype=dtype, order=order, buffer=buffer, offset=offset, strides=strides) @@ -29,7 +29,7 @@ class HostBuffer(np.ndarray, Buffer): #on this HostBuffer have been destroyed. if from_buffer and isinstance(__buffer, HostPooledBuffer): obj._hysop_base_data = __buffer - + return obj def __array_finalize__(self, obj): @@ -45,7 +45,7 @@ class HostBuffer(np.ndarray, Buffer): return self.ctypes.data def release(self): pass - + @classmethod def from_int_ptr(cls, int_ptr_value, size): """ @@ -79,9 +79,9 @@ class HostBuffer(np.ndarray, Buffer): assert handle.ndim == 1 assert handle.dtype == np.uint8 return handle.view(cls) - + int_ptr = property(get_int_ptr) - + class HostPooledBuffer(PooledBuffer): def get_array(self): return self._bufview diff --git a/hysop/backend/host/python/operator/convergence.py b/hysop/backend/host/python/operator/convergence.py index 7a2c3651f..aadde625a 100644 --- a/hysop/backend/host/python/operator/convergence.py +++ b/hysop/backend/host/python/operator/convergence.py @@ -16,6 +16,10 @@ import numpy as np class PythonConvergence(ConvergenceBase, HostOperator): """Computes convergence of a field through iterations""" + @debug + def __new__(cls, **kwds): + return super(PythonConvergence, cls).__new__(cls, **kwds) + @debug def __init__(self, **kwds): super(PythonConvergence, self).__init__(**kwds) diff --git a/hysop/backend/host/python/operator/custom.py b/hysop/backend/host/python/operator/custom.py index 25f8f48fb..7910c515e 100644 --- a/hysop/backend/host/python/operator/custom.py +++ b/hysop/backend/host/python/operator/custom.py @@ -8,6 +8,15 @@ from hysop.core.graph.graph import op_apply class PythonCustomOperator(HostOperator): + + @debug + def __new__(cls, func, invars=None, outvars=None, + extra_args=None, variables=None, ghosts=None, **kwds): + return super(PythonCustomOperator, cls).__new__(cls, + input_fields=None, output_fields=None, + input_params=None, output_params=None, + **kwds) + @debug def __init__(self, func, invars=None, outvars=None, extra_args=None, variables=None, ghosts=None, **kwds): diff --git a/hysop/backend/host/python/operator/derivative.py b/hysop/backend/host/python/operator/derivative.py index 2625c15a5..f7c63ce0e 100644 --- a/hysop/backend/host/python/operator/derivative.py +++ b/hysop/backend/host/python/operator/derivative.py @@ -16,9 +16,8 @@ class PythonSpectralSpaceDerivative(SpectralSpaceDerivativeBase, HostOperator): super(PythonSpectralSpaceDerivative, self).setup(work=work) dA = self.dA if self.scale_by_field: - assert isinstance(self.scaling_view, int) aview = dA.compute_slices - self.scale = dA.sbuffer[self.scaling_view][aview] + self.scale = dA.sbuffer[aview] else: self.scale = dA @@ -41,10 +40,7 @@ class PythonSpectralSpaceDerivative(SpectralSpaceDerivativeBase, HostOperator): if self.scale_by_field: out[...] *= scale elif self.scale_by_parameter: - if (self.scaling_view is not None): - out[...] *= scale[self.scaling_view] - else: - out[...] *= scale() + out[...] *= scale() elif self.scale_by_value: out[...] *= scale @@ -124,9 +120,8 @@ class PythonFiniteDifferencesSpaceDerivative(FiniteDifferencesSpaceDerivativeBas self.iview = iview if self.scale_by_field: - assert isinstance(self.scaling_view, int) aview = dA.compute_slices - self.scale = dA.buffers[self.scaling_view][aview] + self.scale = dA.buffers[aview] else: self.scale = dA @@ -150,10 +145,7 @@ class PythonFiniteDifferencesSpaceDerivative(FiniteDifferencesSpaceDerivativeBas if self.scale_by_field: out[...] *= scale elif self.scale_by_parameter: - if (self.scaling_view is not None): - out[...] *= scale[self.scaling_view] - else: - out[...] *= scale() + out[...] *= scale() elif self.scale_by_value: out[...] *= scale diff --git a/hysop/backend/host/python/operator/directional/advection_dir.py b/hysop/backend/host/python/operator/directional/advection_dir.py index 28477a5cd..39f37f0d4 100644 --- a/hysop/backend/host/python/operator/directional/advection_dir.py +++ b/hysop/backend/host/python/operator/directional/advection_dir.py @@ -18,7 +18,7 @@ class PythonDirectionalAdvection(DirectionalAdvectionBase, HostDirectionalOperat counter = 0 @debug - def __kwds__(cls, **kwds): + def __new__(cls, **kwds): return super(PythonDirectionalAdvection, cls).__new__(cls, **kwds) @debug diff --git a/hysop/backend/host/python/operator/enstrophy.py b/hysop/backend/host/python/operator/enstrophy.py index a11a3b5cb..7944e382e 100644 --- a/hysop/backend/host/python/operator/enstrophy.py +++ b/hysop/backend/host/python/operator/enstrophy.py @@ -11,6 +11,11 @@ from hysop.tools.numpywrappers import npw class PythonEnstrophy(EnstrophyBase, HostOperator): """Compute enstrophy of the given vorticity field.""" + + @debug + def __new__(cls, **kwds): + return super(PythonEnstrophy, cls).__new__(cls, **kwds) + @debug def __init__(self, **kwds): super(PythonEnstrophy, self).__init__(**kwds) diff --git a/hysop/backend/host/python/operator/integrate.py b/hysop/backend/host/python/operator/integrate.py index 759eabfad..5521b4f88 100644 --- a/hysop/backend/host/python/operator/integrate.py +++ b/hysop/backend/host/python/operator/integrate.py @@ -7,6 +7,10 @@ import numpy as np class PythonIntegrate(IntegrateBase, HostOperator): + @debug + def __new__(cls, **kwds): + return super(PythonIntegrate, cls).__new__(cls, **kwds) + @debug def __init__(self, **kwds): super(PythonIntegrate, self).__init__(**kwds) diff --git a/hysop/backend/host/python/operator/memory_reordering.py b/hysop/backend/host/python/operator/memory_reordering.py index 478a20bc6..8fd67436f 100644 --- a/hysop/backend/host/python/operator/memory_reordering.py +++ b/hysop/backend/host/python/operator/memory_reordering.py @@ -1,4 +1,4 @@ -from hysop.deps import np +import numpy as np from hysop.tools.decorators import debug, profile from hysop.backend.host.host_operator import HostOperator @@ -12,7 +12,11 @@ class PythonMemoryReordering(MemoryReorderingBase, HostOperator): """ @debug - def __init__(self, **kwds): + def __new__(cls, **kwds): + return super(PythonMemoryReordering, cls).__new__(cls, **kwds) + + @debug + def __init__(self, **kwds): """Initialize a MemoryReordering operator on the python backend.""" super(PythonMemoryReordering, self).__init__(**kwds) diff --git a/hysop/backend/host/python/operator/min_max.py b/hysop/backend/host/python/operator/min_max.py index f16aa7be7..4774846b8 100644 --- a/hysop/backend/host/python/operator/min_max.py +++ b/hysop/backend/host/python/operator/min_max.py @@ -6,10 +6,14 @@ from hysop.backend.host.host_operator import HostOperator from hysop.backend.host.python.operator.derivative import PythonSpectralSpaceDerivative, \ PythonFiniteDifferencesSpaceDerivative -class PythonMinMaxFieldStatistics(MinMaxFieldStatisticsBase, - HostOperator): + +class PythonMinMaxFieldStatistics(MinMaxFieldStatisticsBase, HostOperator): """Python implementation backend of operator MinMaxFieldStatistics.""" + @debug + def __new__(cls, **kwds): + return super(PythonMinMaxFieldStatistics, cls).__new__(cls, **kwds) + @debug def __init__(self, **kwds): """See MinMaxFieldStatisticsBase.__init__().""" diff --git a/hysop/backend/host/python/operator/vorticity_absorption.py b/hysop/backend/host/python/operator/vorticity_absorption.py index 5f43942e6..1ee44d97d 100644 --- a/hysop/backend/host/python/operator/vorticity_absorption.py +++ b/hysop/backend/host/python/operator/vorticity_absorption.py @@ -1,3 +1,7 @@ +import numpy as np +import sympy as sm +from sympy.utilities.lambdify import lambdify + from hysop.backend.host.host_operator import HostOperator from hysop.tools.types import check_instance from hysop.tools.decorators import debug @@ -7,9 +11,6 @@ from hysop.parameters.tensor_parameter import TensorParameter from hysop.topology.cartesian_descriptor import CartesianTopologyDescriptors from hysop.core.graph.graph import op_apply from hysop.core.memory.memory_request import MemoryRequest -import numpy as np -from hysop.deps import sm -from sympy.utilities.lambdify import lambdify class PythonVorticityAbsorption(HostOperator): @@ -151,7 +152,7 @@ class PythonVorticityAbsorption(HostOperator): self._filter, self._filter_diff = None, None self._apply = self._false_apply if ind is not None: - x = sm.abc.x + x = sm.Symbol('x') if self.custom_filter is None: # Default filter xl = mesh_local_compute_slices[-1].stop-ind[-1].start diff --git a/hysop/constants.py.in b/hysop/constants.py.in index 21923e645..8556a1fc6 100644 --- a/hysop/constants.py.in +++ b/hysop/constants.py.in @@ -8,11 +8,13 @@ This file is generated from constants.py.in and it's probably a bad idea to modify it. """ +import math, inspect, os +import itertools as it +import numpy as np import hysop from hysop import __VERBOSE__, __DEBUG__, __PROFILE__,\ __KERNEL_DEBUG__, __MPI_ENABLED__ -from hysop.deps import math, np, it, inspect, os from hysop.tools.enum import EnumFactory if __MPI_ENABLED__: diff --git a/hysop/core/arrays/array_backend.py b/hysop/core/arrays/array_backend.py index f04a1506e..2d732eb89 100644 --- a/hysop/core/arrays/array_backend.py +++ b/hysop/core/arrays/array_backend.py @@ -1,6 +1,7 @@ - +import sys +import numpy as np from abc import ABCMeta, abstractmethod -from hysop.deps import np, sys + from hysop.constants import default_order, MemoryOrdering, Backend from hysop.constants import HYSOP_REAL, HYSOP_COMPLEX from hysop.constants import HYSOP_INTEGER, HYSOP_INDEX, HYSOP_DIM, HYSOP_BOOL diff --git a/hysop/core/graph/allocator.py b/hysop/core/graph/allocator.py index 08cbe0b85..154b38e73 100644 --- a/hysop/core/graph/allocator.py +++ b/hysop/core/graph/allocator.py @@ -1,8 +1,8 @@ from abc import ABCMeta, abstractmethod -from hysop.deps import np -from hysop.tools.types import check_instance +import numpy as np +from hysop.tools.types import check_instance from hysop.core.arrays.all import ArrayBackend, HostArrayBackend, OpenClArrayBackend diff --git a/hysop/core/graph/computational_graph.py b/hysop/core/graph/computational_graph.py index e3400d790..5535f39c6 100644 --- a/hysop/core/graph/computational_graph.py +++ b/hysop/core/graph/computational_graph.py @@ -728,6 +728,8 @@ class ComputationalGraph(ComputationalGraphNode, metaclass=ABCMeta): return net = self.to_pyvis() + if (net is None): + return net.write_html(path) @graph_built @@ -738,9 +740,9 @@ class ComputationalGraph(ComputationalGraphNode, metaclass=ABCMeta): try: import pyvis, matplotlib except ImportError: - msg='\nFATAL ERROR: Graph vizualization requires pyvis and matplotlib.\n' + msg='\nGraph vizualization requires pyvis and matplotlib, which are not present on your system.\n' print(msg) - raise + return width = first_not_None(width, 1920) height = first_not_None(height, 1080) diff --git a/hysop/core/graph/computational_node.py b/hysop/core/graph/computational_node.py index 5222ab09c..bc7a1be82 100644 --- a/hysop/core/graph/computational_node.py +++ b/hysop/core/graph/computational_node.py @@ -3,10 +3,10 @@ Base for directionally splitted advection solvers (pure-python and GPU version). """ +import copy, warnings from abc import ABCMeta, abstractmethod from hysop import dprint -from hysop.deps import copy, warnings from hysop.tools.types import InstanceOf, to_set, check_instance, first_not_None from hysop.tools.io_utils import IOParams from hysop.parameters.parameter import Parameter diff --git a/hysop/core/graph/graph_builder.py b/hysop/core/graph/graph_builder.py index d8ea7e0a9..086e72523 100644 --- a/hysop/core/graph/graph_builder.py +++ b/hysop/core/graph/graph_builder.py @@ -1,6 +1,6 @@ +import numpy as np from hysop import vprint, dprint, Problem -from hysop.deps import np, __builtin__, print_function from hysop.tools.types import check_instance from hysop.tools.io_utils import IOParams @@ -35,7 +35,7 @@ GRAPH_BUILDER_DEBUG_LEVEL=0 def gprint(*args, **kwds): level = kwds.pop('level', 1) if GRAPH_BUILDER_DEBUG_LEVEL >= level: - __builtin__.print(*args, **kwds) + print(*args, **kwds) def gprint2(*args, **kwds): kwds['level'] = 2 diff --git a/hysop/core/memory/buffer.py b/hysop/core/memory/buffer.py index a70f3eb66..a887d9ff9 100644 --- a/hysop/core/memory/buffer.py +++ b/hysop/core/memory/buffer.py @@ -1,6 +1,6 @@ - from abc import ABCMeta, abstractmethod -from hysop.deps import np +import numpy as np + from hysop.tools.types import check_instance from hysop.tools.units import bytes2str diff --git a/hysop/core/memory/memory_request.py b/hysop/core/memory/memory_request.py index 98387c3d6..e4b93a61b 100644 --- a/hysop/core/memory/memory_request.py +++ b/hysop/core/memory/memory_request.py @@ -1,6 +1,7 @@ from abc import ABCMeta, abstractmethod +import copy +import numpy as np -from hysop.deps import np, copy from hysop.tools.types import check_instance, first_not_None from hysop.tools.units import bytes2str from hysop.tools.numerics import get_dtype diff --git a/hysop/core/memory/mempool.py b/hysop/core/memory/mempool.py index db678c1b2..b16bb1c39 100644 --- a/hysop/core/memory/mempool.py +++ b/hysop/core/memory/mempool.py @@ -1,6 +1,6 @@ +import math from abc import ABCMeta, abstractmethod -from hysop.deps import math, six from hysop.constants import __VERBOSE__, __DEBUG__ from hysop.backend import __HAS_OPENCL_BACKEND__, __HAS_CUDA_BACKEND__ from hysop.tools.units import bytes2str, time2str @@ -190,7 +190,7 @@ class MemoryPool(object, metaclass=ABCMeta): Returns the number of held blocks. """ return sum(len(bin_list) - for bin_list in six.itervalues(self.bin_nr_to_bin)) + for bin_list in self.bin_nr_to_bin.values()) def header(self): """ @@ -369,7 +369,7 @@ class MemoryPool(object, metaclass=ABCMeta): statistics.push_free(size, t.interval) def _try_to_free_memory(self): - for bin_nr, bin_list in six.iteritems(self.bin_nr_to_bin): + for bin_nr, bin_list in self.bin_nr_to_bin.items(): if not bin_list: continue size = bin_list[0].size diff --git a/hysop/core/memory/tests/test_buffer.py b/hysop/core/memory/tests/test_buffer.py index bb50c103f..9dc4afe62 100644 --- a/hysop/core/memory/tests/test_buffer.py +++ b/hysop/core/memory/tests/test_buffer.py @@ -1,4 +1,5 @@ -from hysop.deps import np +import numpy as np + from hysop.backend.host.host_buffer import HostBuffer from hysop.core.mpi import default_mpi_params from hysop.backend import __HAS_OPENCL_BACKEND__, __HAS_CUDA_BACKEND__ diff --git a/hysop/core/memory/tests/test_mempool.py b/hysop/core/memory/tests/test_mempool.py index 2646442f5..4cdb3b80c 100644 --- a/hysop/core/memory/tests/test_mempool.py +++ b/hysop/core/memory/tests/test_mempool.py @@ -1,4 +1,5 @@ -from hysop.deps import np +import numpy as np + from hysop.testsenv import opencl_failed, iter_clenv, \ __HAS_OPENCL_BACKEND__, __ENABLE_LONG_TESTS__ from hysop.core.memory.mempool import MemoryPool diff --git a/hysop/core/mpi/redistribute.py b/hysop/core/mpi/redistribute.py index 1d77e4940..e81435291 100644 --- a/hysop/core/mpi/redistribute.py +++ b/hysop/core/mpi/redistribute.py @@ -107,6 +107,8 @@ class RedistributeIntra(RedistributeOperatorBase): return True + def __new__(cls, **kwds): + return super(RedistributeIntra, cls).__new__(cls, **kwds) def __init__(self, **kwds): """Data transfer between two operators/topologies defined on the diff --git a/hysop/deps.py b/hysop/deps.py deleted file mode 100644 index 52a7937c2..000000000 --- a/hysop/deps.py +++ /dev/null @@ -1,39 +0,0 @@ -from __future__ import absolute_import -from __future__ import print_function - -try: - import __builtin__ -except: - import builtins as __builtin__ - -try: - import cPickle as pickle -except: - import pickle - -try: - import h5py -except ImportError as e: - h5py = None - msg = 'Warning: h5py not found, you may not be able to' - msg += ' use hdf5 I/O functionnalities.' - print(msg) - raise - -import sys, os, subprocess, platform, warnings, traceback -import resource, psutil, tempfile, cpuinfo, time -import inspect, functools, operator, random -import hashlib, gzip, copy, types, string -import math, re, contextlib -import six, itertools - -import itertools as it -import numpy as np - -import sympy as sm -import sympy.abc, sympy.polys, sympy.solvers, sympy.functions - -import scipy as sp -import scipy.linalg, scipy.interpolate - -import gmpy2 as gmp diff --git a/hysop/domain/box.py b/hysop/domain/box.py index 40f89c479..56ca2f951 100644 --- a/hysop/domain/box.py +++ b/hysop/domain/box.py @@ -1,7 +1,8 @@ """Box-shaped domains definition. """ import warnings -from hysop.deps import np +import numpy as np + from hysop.constants import BoxBoundaryCondition, HYSOP_REAL from hysop.domain.domain import Domain, DomainView from hysop.tools.decorators import debug @@ -154,8 +155,8 @@ class Box(BoxView, Domain): from hysop.topology.cartesian_topology import CartesianTopologyState check_instance(dim, int, minval=1, allow_none=True) - check_instance(length, (np.ndarray,list,tuple), values=(int,float), allow_none=True) - check_instance(origin, (np.ndarray,list,tuple), values=(int,float), allow_none=True) + check_instance(length, (np.ndarray,list,tuple), values=(np.integer,int,float), allow_none=True) + check_instance(origin, (np.ndarray,list,tuple), values=(np.integer,int,float), allow_none=True) check_instance(lboundaries, (np.ndarray,list,tuple), values=BoxBoundaryCondition, allow_none=True) check_instance(rboundaries, (np.ndarray,list,tuple), values=BoxBoundaryCondition, diff --git a/hysop/domain/domain.py b/hysop/domain/domain.py index eb9ea8830..8fa87345a 100644 --- a/hysop/domain/domain.py +++ b/hysop/domain/domain.py @@ -3,7 +3,10 @@ Abstract interfaces for physical domains description. * :class:`~hysop.domain.domain.Domain` * :class:`~hysop.domain.domain.DomainView` """ +import hashlib +import numpy as np from abc import ABCMeta, abstractmethod + from hysop.constants import HYSOP_DEFAULT_TASK_ID, HYSOP_DIM from hysop.core.mpi import main_comm, MPI from hysop.tools.parameters import MPIParams @@ -12,7 +15,6 @@ from hysop.tools.handle import RegisteredObject, TaggedObjectView from hysop.tools.types import check_instance from hysop.tools.numpywrappers import npw from hysop.symbolic.frame import SymbolicFrame -from hysop.deps import hashlib, np class DomainView(TaggedObjectView, metaclass=ABCMeta): diff --git a/hysop/fields/cartesian_discrete_field.py b/hysop/fields/cartesian_discrete_field.py index 4cb537849..3128bd4f6 100644 --- a/hysop/fields/cartesian_discrete_field.py +++ b/hysop/fields/cartesian_discrete_field.py @@ -8,8 +8,10 @@ Discrete fields (scalars or vectors) descriptions. Documentation and examples can be found in :ref:`fields`. """ +import hashlib +import numpy as np + from hysop import vprint, dprint, MPI -from hysop.deps import np, hashlib from hysop.core.arrays.all import HostArray, OpenClArray from hysop.constants import Backend, DirectionLabels, GhostOperation, GhostMask, ExchangeMethod, \ MemoryOrdering diff --git a/hysop/fields/discrete_field.py b/hysop/fields/discrete_field.py index c979bfd87..c8ebd79ef 100644 --- a/hysop/fields/discrete_field.py +++ b/hysop/fields/discrete_field.py @@ -7,8 +7,9 @@ Discrete fields (scalars or vectors) descriptions. """ from abc import ABCMeta, abstractmethod +import numpy as np + from hysop import vprint -from hysop.deps import np from hysop.tools.decorators import debug from hysop.tools.types import check_instance, first_not_None from hysop.tools.variable import VariableTag, Variable diff --git a/hysop/fields/field_requirements.py b/hysop/fields/field_requirements.py index 2d982aff7..f08450b6c 100644 --- a/hysop/fields/field_requirements.py +++ b/hysop/fields/field_requirements.py @@ -1,8 +1,10 @@ +import numpy as np +import itertools as it + from hysop import __DEBUG__, main_size -from hysop.deps import np, it, __builtin__, print_function from hysop.constants import MemoryOrdering from hysop.tools.transposition_states import TranspositionState -from hysop.tools.types import to_list, to_tuple, check_instance +from hysop.tools.types import to_list, to_tuple, check_instance, first_not_None from hysop.tools.numpywrappers import npw from hysop.tools.decorators import debug from hysop.topology.topology import Topology @@ -21,7 +23,7 @@ TOPO_CREATION_DEBUG_LEVEL = 0 def gprint(*args, **kwds): level = kwds.pop('level', 2) if TOPO_CREATION_DEBUG_LEVEL >= level: - __builtin__.print(*args, **kwds) + print(*args, **kwds) class DiscreteFieldRequirements(object): @@ -509,11 +511,11 @@ class OperatorFieldRequirements(object): check_instance(input_field_requirements, dict, keys=ScalarField, values=MultiFieldRequirements, allow_none=True) - self._input_field_requirements = input_field_requirements or dict() + self._input_field_requirements = first_not_None(input_field_requirements, {}) check_instance(output_field_requirements, dict, keys=ScalarField, values=MultiFieldRequirements, allow_none=True) - self._output_field_requirements = output_field_requirements or dict() + self._output_field_requirements = first_not_None(output_field_requirements, {}) def get_input_field_requirements(self): return self._input_field_requirements diff --git a/hysop/fields/ghost_exchangers.py b/hysop/fields/ghost_exchangers.py index 99bcbfa87..258b03cba 100644 --- a/hysop/fields/ghost_exchangers.py +++ b/hysop/fields/ghost_exchangers.py @@ -1,5 +1,7 @@ from abc import ABCMeta, abstractmethod -from hysop.deps import np, hashlib, __builtin__, print_function +import hashlib +import numpy as np + from hysop.tools.types import check_instance, to_tuple, first_not_None from hysop.tools.numerics import default_invalid_value from hysop.tools.mpi_utils import iter_mpi_requests, dtype_to_mpi_type @@ -18,7 +20,7 @@ GHOST_EXCHANGE_DEBUG_LEVEL=0 def gprint(*args, **kwds): level = kwds.pop('level', 2) if GHOST_EXCHANGE_DEBUG_LEVEL >= level: - __builtin__.print(*args, **kwds) + print(*args, **kwds) def gprint_buffer(msg, buf, *args, **kwds): no_data = kwds.pop('no_data', False) if isinstance(buf, list): diff --git a/hysop/fields/tests/test_cartesian.py b/hysop/fields/tests/test_cartesian.py index baacac2e8..6eb9e4fb0 100644 --- a/hysop/fields/tests/test_cartesian.py +++ b/hysop/fields/tests/test_cartesian.py @@ -1,6 +1,8 @@ import os, subprocess, sys, time +import itertools as it +import numpy as np + from hysop import __ENABLE_LONG_TESTS__ -from hysop.deps import it, np from hysop.constants import Backend, ExchangeMethod, GhostOperation, \ GhostMask, DirectionLabels, BoundaryCondition from hysop.tools.parameters import CartesianDiscretization diff --git a/hysop/mesh/cartesian_mesh.py b/hysop/mesh/cartesian_mesh.py index 8053befc8..bef6f8fcf 100644 --- a/hysop/mesh/cartesian_mesh.py +++ b/hysop/mesh/cartesian_mesh.py @@ -9,9 +9,9 @@ See also * :class:`~hysop.topology.topology.CartesianTopology` * :ref:`topologies` in HySoP user guide. """ +import itertools as it from hysop.constants import np, BoundaryCondition, GhostMask, HYSOP_INTEGER, HYSOP_REAL, MemoryOrdering -from hysop.deps import it from hysop.tools.decorators import debug from hysop.tools.numpywrappers import npw from hysop.tools.types import check_instance, to_tuple diff --git a/hysop/numerics/odesolvers/runge_kutta.py b/hysop/numerics/odesolvers/runge_kutta.py index ca555e42b..cefb09bbc 100644 --- a/hysop/numerics/odesolvers/runge_kutta.py +++ b/hysop/numerics/odesolvers/runge_kutta.py @@ -1,5 +1,5 @@ +import numpy as np -from hysop.deps import np from hysop.tools.types import check_instance, first_not_None from hysop.tools.numerics import is_fp from hysop.numerics.odesolvers.runge_kutta_coeffs import Itype,Qtype,rk_params, available_methods diff --git a/hysop/numerics/remesh/kernel_generator.py b/hysop/numerics/remesh/kernel_generator.py index 1fd7be909..6363553fe 100644 --- a/hysop/numerics/remesh/kernel_generator.py +++ b/hysop/numerics/remesh/kernel_generator.py @@ -1,4 +1,9 @@ -from hysop.deps import os, hashlib, sm, np, gzip, sp +import os, hashlib, gzip +import numpy as np +import scipy as sp +import sympy as sm +from scipy import interpolate + from hysop.tools.io_utils import IO from hysop.tools.numerics import mpq,mpfr,mpqize,f2q from hysop.tools.cache import load_data_from_cache, update_cache @@ -57,8 +62,8 @@ class Kernel(object): def _build(self,verbose,split_polys): #polynom symbolic variables - x = sm.abc.x - t = sm.abc.t + x = sm.Symbol('x') + t = sm.Symbol('t') #usefull vars Ms = self.Ms diff --git a/hysop/numerics/remesh/remesh.py b/hysop/numerics/remesh/remesh.py index b889e4d39..5a96511c9 100644 --- a/hysop/numerics/remesh/remesh.py +++ b/hysop/numerics/remesh/remesh.py @@ -1,3 +1,5 @@ +import sympy as sm + from hysop.constants import __VERBOSE__, __DEBUG__ from hysop.tools.enum import EnumFactory from hysop.tools.types import check_instance @@ -42,7 +44,6 @@ class RemeshKernel(Kernel): 'Only lambda remesh kernels are supported.' if remesh in ('M4', 'M8'): # given M4 or M8 kernels - from hysop.deps import sm x = sm.abc.x if remesh == 'M4': M4 = (sm.Poly((1/sm.Rational(6))*((2-x)**3-4*(1-x)**3), x), diff --git a/hysop/numerics/stencil/stencil.py b/hysop/numerics/stencil/stencil.py index 85dd6c1a6..fab19aa66 100644 --- a/hysop/numerics/stencil/stencil.py +++ b/hysop/numerics/stencil/stencil.py @@ -7,7 +7,12 @@ """ -from hysop.deps import sm, sp, it, np, hashlib +import hashlib +import numpy as np +import scipy as sp +import sympy as sm +import itertools as it + from hysop.tools.types import check_instance, first_not_None, to_tuple from hysop.tools.sympy_utils import recurse_expression_tree diff --git a/hysop/numerics/stencil/stencil_generator.py b/hysop/numerics/stencil/stencil_generator.py index 2d78ac6dd..7e2d9e120 100644 --- a/hysop/numerics/stencil/stencil_generator.py +++ b/hysop/numerics/stencil/stencil_generator.py @@ -4,8 +4,17 @@ * :class:`~hysop.numerics.stencil.StencilGenerator` """ -import fractions -from hysop.deps import it, np, sp, sm, os, copy, math, gzip, pickle +import fractions, os, copy, math, gzip +import itertools as it +import numpy as np +import scipy as sp +import sympy as sm + +try: + import cPickle as pickle +except: + import pickle + from hysop.tools.misc import prod from hysop.tools.io_utils import IO from hysop.tools.numerics import MPQ, MPZ, MPFR, F2Q, mpqize, mpq, mpz diff --git a/hysop/numerics/tests/bench_fft.py b/hysop/numerics/tests/bench_fft.py index ee6d45fc0..f038a317b 100644 --- a/hysop/numerics/tests/bench_fft.py +++ b/hysop/numerics/tests/bench_fft.py @@ -1,17 +1,13 @@ """ Test of fields defined with an analytic formula. """ -import os -import random -import gc -import pyfftw -import gpyfft +import os, random, gc, pyfftw, gpyfft +import sympy as sm import numpy as np import itertools as it import pyopencl as cl -from hysop.deps import it, sm, random from hysop.constants import Implementation, Backend, HYSOP_REAL from hysop.testsenv import __ENABLE_LONG_TESTS__, __HAS_OPENCL_BACKEND__ from hysop.testsenv import opencl_failed, iter_clenv diff --git a/hysop/numerics/tests/test_fft.py b/hysop/numerics/tests/test_fft.py index d4923c894..b4244926a 100644 --- a/hysop/numerics/tests/test_fft.py +++ b/hysop/numerics/tests/test_fft.py @@ -1,13 +1,12 @@ """ Test of fields defined with an analytic formula. """ -import random -import pyfftw +import random, pyfftw import numpy as np +import sympy as sm import itertools as it -from hysop.deps import it, sm, random from hysop.constants import Implementation, HYSOP_REAL from hysop.testsenv import __ENABLE_LONG_TESTS__, __HAS_OPENCL_BACKEND__ from hysop.testsenv import opencl_failed, iter_clenv diff --git a/hysop/operator/adapt_timestep.py b/hysop/operator/adapt_timestep.py index a019fe773..46e5769ad 100755 --- a/hysop/operator/adapt_timestep.py +++ b/hysop/operator/adapt_timestep.py @@ -17,6 +17,12 @@ from hysop.core.mpi import MPI class TimestepCriteria(ComputationalGraphOperator, metaclass=ABCMeta): + @debug + def __new__(cls, parameter, input_params, output_params, + dt_coeff=None, min_dt=None, max_dt=None, **kwds): + return super(TimestepCriteria, cls).__new__(cls, + input_params=input_params, output_params=output_params, **kwds) + @debug def __init__(self, parameter, input_params, output_params, dt_coeff=None, min_dt=None, max_dt=None, **kwds): @@ -98,6 +104,14 @@ class TimestepCriteria(ComputationalGraphOperator, metaclass=ABCMeta): class ConstantTimestepCriteria(TimestepCriteria): + @debug + def __new__(cls, cst, parameter, Finf, + name=None, pretty_name=None, **kwds): + return super(ConstantTimestepCriteria, cls).__new__(cls, + name=name, pretty_name=pretty_name, + input_params=None, output_params=None, + parameter=parameter, **kwds) + @debug def __init__(self, cst, parameter, Finf, name=None, pretty_name=None, **kwds): @@ -169,6 +183,17 @@ class ConstantTimestepCriteria(TimestepCriteria): class CflTimestepCriteria(TimestepCriteria): + @debug + def __new__(cls, cfl, parameter, + Finf=None, Fmin=None, Fmax=None, + dx=None, + name=None, pretty_name=None, + relative_velocities=None, **kwds): + return super(CflTimestepCriteria, cls).__new__(cls, + name=name, pretty_name=pretty_name, + input_params=None, output_params=None, + parameter=parameter, **kwds) + @debug def __init__(self, cfl, parameter, Finf=None, Fmin=None, Fmax=None, @@ -303,6 +328,15 @@ class CflTimestepCriteria(TimestepCriteria): class AdvectionTimestepCriteria(TimestepCriteria): + @debug + def __new__(cls, lcfl, parameter, criteria, + Finf=None, gradFinf=None, + name=None, pretty_name=None, **kwds): + return super(AdvectionTimestepCriteria, cls).__new__(cls, + name=name, pretty_name=pretty_name, + input_params=None, output_params=None, + parameter=parameter, **kwds) + @debug def __init__(self, lcfl, parameter, criteria, Finf=None, gradFinf=None, @@ -389,6 +423,16 @@ class AdvectionTimestepCriteria(TimestepCriteria): class StretchingTimestepCriteria(TimestepCriteria): + @debug + def __new__(cls, gradFinf, parameter, + cst=1.0, criteria=StretchingCriteria.GRAD_U, + name=None, pretty_name=None, + **kwds): + return super(StretchingTimestepCriteria, cls).__new__(cls, + name=name, pretty_name=pretty_name, + input_params=None, output_params=None, + parameter=parameter, **kwds) + @debug def __init__(self, gradFinf, parameter, cst=1.0, criteria=StretchingCriteria.GRAD_U, @@ -445,6 +489,14 @@ class StretchingTimestepCriteria(TimestepCriteria): class MergeTimeStepCriterias(TimestepCriteria): + @debug + def __new__(cls, parameter, criterias, + equivalent_CFL=None, cfl_criteria=None, start_time=None, + **kwds): + return super(MergeTimeStepCriterias, cls).__new__(cls, + input_params=None, output_params=None, + parameter=parameter, **kwds) + @debug def __init__(self, parameter, criterias, equivalent_CFL=None, cfl_criteria=None, start_time=None, @@ -489,6 +541,14 @@ class AdaptiveTimeStep(ComputationalGraphNodeGenerator): dt = max(min(max_dt, dt_criterias), min_dt) """ + @debug + def __new__(cls, dt, min_dt=None, max_dt=None, dt_coeff=None, + equivalent_CFL=False, base_kwds=None, start_time=None, + **kwds): + base_kwds = first_not_None(base_kwds, {}) + return super(AdaptiveTimeStep, cls).__new__(cls, + candidate_input_tensors=None, candidate_output_tensors=None, **base_kwds) + @debug def __init__(self, dt, min_dt=None, max_dt=None, dt_coeff=None, equivalent_CFL=False, base_kwds=None, start_time=None, @@ -645,6 +705,6 @@ class AdaptiveTimeStep(ComputationalGraphNodeGenerator): cfl_criteria=self.cfl_criteria, criterias=self.criterias, **self.merge_kwds) - operators = self.criterias.values() + operators = list(self.criterias.values()) operators.append(merge) return operators diff --git a/hysop/operator/advection.py b/hysop/operator/advection.py index 2f2560e1c..f165a25c0 100644 --- a/hysop/operator/advection.py +++ b/hysop/operator/advection.py @@ -71,6 +71,23 @@ class Advection(ComputationalGraphNodeFrontend): def default_implementation(cls): return Implementation.FORTRAN + @debug + def __new__(cls, velocity, + advected_fields, + variables, + dt, + advected_fields_out=None, + implementation=None, + base_kwds=None, + **kwds): + return super(Advection, cls).__new__(cls, + velocity=velocity, dt=dt, + advected_fields_in=None, + advected_fields_out=None, + variables=variables, + implementation=implementation, + base_kwds=base_kwds, **kwds) + @debug def __init__(self, velocity, advected_fields, @@ -127,7 +144,7 @@ class Advection(ComputationalGraphNodeFrontend): advected_fields = tuple(advected_fields) advected_fields_out = tuple(advected_fields_out) - base_kwds = base_kwds or dict() + base_kwds = first_not_None(base_kwds, {}) check_instance(velocity, Field) check_instance(advected_fields, tuple, values=Field) @@ -144,3 +161,4 @@ class Advection(ComputationalGraphNodeFrontend): variables=variables, implementation=implementation, base_kwds=base_kwds, **kwds) + diff --git a/hysop/operator/analytic.py b/hysop/operator/analytic.py index 8f6da9093..820cd7698 100644 --- a/hysop/operator/analytic.py +++ b/hysop/operator/analytic.py @@ -15,6 +15,15 @@ class AnalyticField(ComputationalGraphNodeGenerator): chosen implementation backend. """ + @debug + def __new__(cls, field, formula, variables, extra_input_kwds=None, + implementation=None, base_kwds=None, **kwds): + base_kwds = first_not_None(base_kwds, {}) + return super(AnalyticField, cls).__new__(cls, + candidate_input_tensors=None, + candidate_output_tensors=None, + **base_kwds) + @debug def __init__(self, field, formula, variables, extra_input_kwds=None, implementation=None, base_kwds=None, **kwds): diff --git a/hysop/operator/base/convergence.py b/hysop/operator/base/convergence.py index 7d3cfcdbc..0f16c1c2e 100644 --- a/hysop/operator/base/convergence.py +++ b/hysop/operator/base/convergence.py @@ -31,6 +31,12 @@ class ConvergenceBase(object): am.update(cls.__available_methods) return am + @debug + def __new__(cls, variables, convergence=None, + implementation=None, **kwds): + return super(ConvergenceBase, cls).__new__(cls, + input_fields=None, output_params=None, **kwds) + @debug def __init__(self, variables, convergence=None, implementation=None, **kwds): diff --git a/hysop/operator/base/custom_symbolic_operator.py b/hysop/operator/base/custom_symbolic_operator.py index 3a3df48c8..d4cf372f1 100644 --- a/hysop/operator/base/custom_symbolic_operator.py +++ b/hysop/operator/base/custom_symbolic_operator.py @@ -1,7 +1,7 @@ from abc import ABCMeta - +import sympy as sm import numpy as np -from hysop.deps import sm + from hysop.tools.numpywrappers import npw from hysop.tools.types import check_instance, to_tuple, InstanceOf, first_not_None, to_set from hysop.tools.decorators import debug diff --git a/hysop/operator/base/derivative.py b/hysop/operator/base/derivative.py index 259a996a6..c10296de4 100644 --- a/hysop/operator/base/derivative.py +++ b/hysop/operator/base/derivative.py @@ -1,7 +1,6 @@ - from abc import ABCMeta, abstractmethod +import sympy as sm -from hysop.deps import sm from hysop.tools.numpywrappers import npw from hysop.tools.types import check_instance, to_tuple, first_not_None, InstanceOf from hysop.tools.decorators import debug diff --git a/hysop/operator/base/enstrophy.py b/hysop/operator/base/enstrophy.py index 9321cb456..ed12f108f 100644 --- a/hysop/operator/base/enstrophy.py +++ b/hysop/operator/base/enstrophy.py @@ -14,6 +14,13 @@ class EnstrophyBase(object, metaclass=ABCMeta): Common implementation interface for enstrophy. """ + @debug + def __new__(cls, vorticity, enstrophy, WdotW, rho, rho_0, + variables, name=None, pretty_name=None, **kwds): + return super(EnstrophyBase, cls).__new__(cls, + input_fields=None, output_fields=None, output_params=None, + name=name, pretty_name=pretty_name, **kwds) + @debug def __init__(self, vorticity, enstrophy, WdotW, rho, rho_0, variables, name=None, pretty_name=None, **kwds): diff --git a/hysop/operator/base/external_force.py b/hysop/operator/base/external_force.py index 59d9cb5ad..0fef2bb95 100644 --- a/hysop/operator/base/external_force.py +++ b/hysop/operator/base/external_force.py @@ -18,6 +18,9 @@ from hysop.tools.interface import NamedObjectI class ExternalForce(NamedObjectI, metaclass=ABCMeta): """Interface to implement a custom external force.""" + def __new__(cls, name, dim, Fext, **kwds): + return super(ExternalForce, cls).__new__(cls, name=name, **kwds) + def __init__(self, name, dim, Fext, **kwds): super(ExternalForce, self).__init__(name=name, **kwds) @@ -79,6 +82,15 @@ class SpectralExternalForceOperatorBase(SpectralOperatorBase): Compute the curl of a symbolic expression and perfom Euler time integration. """ + @debug + def __new__(cls, vorticity, Fext, dt, variables, + Fmin=None, Fmax=None, Finf=None, + implementation=None, **kwds): + return super(SpectralExternalForceOperatorBase, cls).__new__(cls, + input_fields=None, output_fields=None, + input_params=None, output_params=None, + **kwds) + @debug def __init__(self, vorticity, Fext, dt, variables, Fmin=None, Fmax=None, Finf=None, diff --git a/hysop/operator/base/integrate.py b/hysop/operator/base/integrate.py index aef3d35b2..196a40582 100644 --- a/hysop/operator/base/integrate.py +++ b/hysop/operator/base/integrate.py @@ -15,6 +15,14 @@ class IntegrateBase(object, metaclass=ABCMeta): Common implementation interface for field integration. """ + @debug + def __new__(cls, field, variables, + name=None, pretty_name=None, cst=1, + parameter=None, scaling=None, expr=None, **kwds): + return super(IntegrateBase, cls).__new__(cls, + name=name, pretty_name=pretty_name, + input_fields=None, output_params=None, **kwds) + @debug def __init__(self, field, variables, name=None, pretty_name=None, cst=1, diff --git a/hysop/operator/base/memory_reordering.py b/hysop/operator/base/memory_reordering.py index 85813c916..cbcf5d9cf 100644 --- a/hysop/operator/base/memory_reordering.py +++ b/hysop/operator/base/memory_reordering.py @@ -13,6 +13,16 @@ class MemoryReorderingBase(object, metaclass=ABCMeta): Common implementation interface for memory reordering operators. """ + @debug + def __new__(cls, input_field, output_field, variables, + target_memory_order, name=None, pretty_name=None, + **kwds): + return super(MemoryReorderingBase, cls).__new__(cls, + input_fields=input_fields, + output_fields=output_fields, + name=name, pretty_name=pname, + **kwds) + @debug def __init__(self, input_field, output_field, variables, target_memory_order, name=None, pretty_name=None, diff --git a/hysop/operator/base/min_max.py b/hysop/operator/base/min_max.py index d932ff6e8..7a1faeedd 100644 --- a/hysop/operator/base/min_max.py +++ b/hysop/operator/base/min_max.py @@ -1,7 +1,7 @@ """ @file min_max.py MinMaxFieldStatisticsBase: compute min(F), max(F) and/or max(|F|) for a given field -MinMaxGradientStatisticsBase: compute min(gradF), max(gradF) and/or max(|gradF|) for a given field, component and direction-wise. +MinMaxGradientStatisticsBase: compute min(gradF), max(gradF) and/or max(|gradF|) for a given field, direction-wise. """ from abc import abstractmethod from hysop.tools.types import check_instance, first_not_None, to_tuple @@ -81,6 +81,20 @@ class MinMaxFieldStatisticsBase(object): parameters[k] = param return parameters + @debug + def __new__(cls, field, components=None, coeffs=None, + Fmin=None, Fmax=None, Finf=None, all_quiet=None, + name=None, pretty_name=None, + pbasename=None, ppbasename=None, + variables=None, **kwds): + if MinMaxDerivativeStatisticsBase in cls.__mro__: + return super(MinMaxFieldStatisticsBase, cls).__new__(cls, + name=name, pretty_name=pretty_name, + variables=variables, output_params=None, **kwds) + else: + return super(MinMaxFieldStatisticsBase, cls).__new__(cls, + name=name, pretty_name=pretty_name, + input_fields=None, output_params=None, **kwds) @debug def __init__(self, field, components=None, coeffs=None, @@ -268,13 +282,28 @@ class MinMaxFieldStatisticsBase(object): class MinMaxDerivativeStatisticsBase(MinMaxFieldStatisticsBase): """ Abstract operator base to compute min and max statistics on the derivative - of a specific field component. + of a specific scalar field. """ + @debug + def __new__(cls, F, dF=None, A=None, + derivative=None, direction=None, + Fmin=None, Fmax=None, Finf=None, coeffs=None, + all_quiet=False, + name=None, pretty_name=None, + pbasename=None, ppbasename=None, + variables=None, **kwds): + return super(MinMaxDerivativeStatisticsBase, cls).__new__(cls, + field=dF, coeffs=coeffs, Fmin=Fmin, Fmax=Fmax, Finf=Finf, + name=name, pretty_name=pretty_name, + pbasename=pbasename, variables=variables, + F=F, dF=dF, A=A, + derivative=derivative, direction=direction, + **kwds) + @debug def __init__(self, F, dF=None, A=None, - derivative=None, component=None, direction=None, - out_component=None, scaling_view=None, + derivative=None, direction=None, Fmin=None, Fmax=None, Finf=None, coeffs=None, all_quiet=False, name=None, pretty_name=None, @@ -289,8 +318,8 @@ class MinMaxDerivativeStatisticsBase(MinMaxFieldStatisticsBase): Finf: max value of the absolute value of a derivative of the field (computed using Fmin and Fmax). - First compute the derivative of a component of a field F in a given direction - at a given order and on a given backend out of place in a specific output component of dF. + First compute the derivative of a scalar field F in a given direction + at a given order and on a given backend out of place in a specific output scalar field dF. The derivative is then possibly scaled by another field/parameter/value A. After the scaled derivative has been computed, compute user requested statistics @@ -298,21 +327,17 @@ class MinMaxDerivativeStatisticsBase(MinMaxFieldStatisticsBase): parameters stored in coeffs. 1) Compute derivative - dF[k] = alpha * d^n(F[i])/dXj**n + dF = alpha * d^n(F)/dXj**n 2) Compute statistics - Fmin = Smin * min(dF[k]) - Fmax = Smax * max(dF[k]) + Fmin = Smin * min(dF) + Fmax = Smax * max(dF) Finf = Sinf * max(|Fmin|, |Fmax|) where F is an input field dF is an output field (by default a temporary field). - k = out_component < dF.nb_components - i = component < F.nb_components n = derivative order > 0 - alpha = A[scaling_view] - where A is a Field, a Parameter or a scalar. - scaling_view is a component, a slice or None. + alpha = A, where A is a Field, a Parameter or a scalar. Fmin = created or supplied TensorParameter. Fmax = created or supplied TensorParameter. Finf = created or supplied TensorParameter. @@ -340,22 +365,9 @@ class MinMaxDerivativeStatisticsBase(MinMaxFieldStatisticsBase): derivative: int, optional Which derivative to generate. Defaults to 1. - component: int, optional - The component on which to take the derivative. - Defaults to 0. direction: int, optional Directions in which to take the derivative. Defaults to 0. - out_component: int, optional - The component were the result will be stored. - Defaults to component. - scaling_view: int or slice, optional - View on the scaling field/parameter/value A. - Should be a component if this is a field. - Should be a slice if this is a TensorParameter. - Should be None it this is a ScalarParameter or - a numerical value. - Should only be given if A is given. F...: TensorParameter or boolean, optional The output parameters that will contain the statistics. At least one statistic should be specified (either by boolean or TensorParameter). @@ -413,8 +425,6 @@ class MinMaxDerivativeStatisticsBase(MinMaxFieldStatisticsBase): if (dF is None): dF = F.tmp_like('dF', nb_components=1) - assert (out_component is None), out_component - out_component = 0 variables.setdefault(dF, variables[F]) super(MinMaxDerivativeStatisticsBase, self).__init__(field=dF, @@ -422,5 +432,5 @@ class MinMaxDerivativeStatisticsBase(MinMaxFieldStatisticsBase): name=name, pretty_name=pretty_name, pbasename=pbasename, variables=variables, F=F, dF=dF, A=A, - derivative=derivative, component=component, direction=direction, - out_component=out_component, scaling_view=scaling_view, **kwds) + derivative=derivative, direction=direction, + **kwds) diff --git a/hysop/operator/base/redistribute_operator.py b/hysop/operator/base/redistribute_operator.py index 5da99e91b..e03298246 100644 --- a/hysop/operator/base/redistribute_operator.py +++ b/hysop/operator/base/redistribute_operator.py @@ -30,6 +30,12 @@ class RedistributeOperatorBase(ComputationalGraphOperator, metaclass=ABCMeta): """ return Backend.all + def __new__(cls, variable, source_topo, target_topo, + name=None, pretty_name=None, **kwds): + return super(RedistributeOperatorBase, cls).__new__(cls, + name=name, pretty_name=pretty_name, + input_fields=None, output_fields=None, **kwds) + def __init__(self, variable, source_topo, target_topo, name=None, pretty_name=None, **kwds): """ diff --git a/hysop/operator/base/spatial_filtering.py b/hysop/operator/base/spatial_filtering.py index 1d2fad979..a660f46c5 100644 --- a/hysop/operator/base/spatial_filtering.py +++ b/hysop/operator/base/spatial_filtering.py @@ -33,9 +33,7 @@ class SpatialFilterBase(object): input_topo, output_topo, **kwds): return super(SpatialFilterBase, cls).__new__(cls, - input_fields=None, - output_fields=None, - **kwds) + input_fields=None, output_fields=None, **kwds) def __init__(self, input_field, output_field, input_topo, output_topo, diff --git a/hysop/operator/base/stretching_dir.py b/hysop/operator/base/stretching_dir.py index 2939654f0..33131ce1e 100644 --- a/hysop/operator/base/stretching_dir.py +++ b/hysop/operator/base/stretching_dir.py @@ -1,4 +1,6 @@ -from hysop.deps import sm, np +import numpy as np +import sympy as sm + from hysop.tools.numpywrappers import npw from hysop.tools.decorators import debug from hysop.constants import StretchingFormulation diff --git a/hysop/operator/convergence.py b/hysop/operator/convergence.py index 935464300..d6939368d 100644 --- a/hysop/operator/convergence.py +++ b/hysop/operator/convergence.py @@ -16,7 +16,6 @@ class Convergence(ComputationalGraphNodeFrontend): Computes the convergence citeria for a given field. Available implementations are: - *OPENCL (gpu based implementation) (default) *PYTHON """ @@ -32,6 +31,13 @@ class Convergence(ComputationalGraphNodeFrontend): def default_implementation(cls): return Implementation.PYTHON + @debug + def __new__(cls, variables, error=None, convergence=None, + implementation=None, **kwds): + return super(Convergence, cls).__new__(cls, + error=error, convergence=convergence, + variables=variables, implementation=implementation, **kwds) + @debug def __init__(self, variables, error=None, convergence=None, implementation=None, **kwds): @@ -62,3 +68,4 @@ class Convergence(ComputationalGraphNodeFrontend): error=error, convergence=convergence, variables=variables, implementation=implementation, **kwds) + diff --git a/hysop/operator/curl.py b/hysop/operator/curl.py index ed68c1bcb..344915f03 100644 --- a/hysop/operator/curl.py +++ b/hysop/operator/curl.py @@ -12,7 +12,7 @@ class Curl(ComputationalGraphNodeFrontend): @classmethod def fd(*args, **kwds): return FiniteDifferencesCurl(*args, **kwds) - + @classmethod def spectral(*args, **kwds): return SpectralCurl(*args, **kwds) @@ -27,13 +27,23 @@ class Curl(ComputationalGraphNodeFrontend): raise NotImplementedError @debug - def __init__(self, Fin, Fout, variables, + def __new__(cls, Fin, Fout, variables, + implementation=None, base_kwds=None, **kwds): + return super(Curl, cls).__new__(cls, + Fin=Fin, Fout=Fout, variables=variables, + candidate_input_tensors=None, + candidate_output_tensors=None, + implementation=implementation, + base_kwds=base_kwds, **kwds) + + @debug + def __init__(self, Fin, Fout, variables, implementation=None, base_kwds=None, **kwds): """ Create an operator that computes the curl of an input field Fin. Given Fin, a 2D ScalarField or VectorField or a 3D VectorField, compute Fout = curl(Fin). - + Only the following configurations are supported: dim nb_components | dim nb_components Input: 2 (1,2) | 3 3 @@ -63,9 +73,10 @@ class Curl(ComputationalGraphNodeFrontend): super(Curl, self).__init__(Fin=Fin, Fout=Fout, variables=variables, candidate_input_tensors=(Fin,), candidate_output_tensors=(Fout,), - implementation=implementation, + implementation=implementation, base_kwds=base_kwds, **kwds) + class SpectralCurl(Curl): @classmethod def implementations(cls): @@ -76,7 +87,7 @@ class SpectralCurl(Curl): Implementation.OPENCL: OpenClSpectralCurl, } return __implementations - + @classmethod def default_implementation(cls): return Implementation.PYTHON diff --git a/hysop/operator/custom.py b/hysop/operator/custom.py index e4aa9bf82..99820828f 100755 --- a/hysop/operator/custom.py +++ b/hysop/operator/custom.py @@ -30,6 +30,11 @@ class CustomOperator(ComputationalGraphNodeFrontend): def default_implementation(cls): return Implementation.PYTHON + @debug + def __new__(cls, func, invars=None, outvars=None, extra_args=None, ghosts=None, **kwds): + return super(CustomOperator, cls).__new__(cls, + func=func, invars=invars, outvars=outvars, extra_args=extra_args, ghosts=ghosts, **kwds) + @debug def __init__(self, func, invars=None, outvars=None, extra_args=None, ghosts=None, **kwds): check_instance(invars, (tuple, list), values=(Field, Parameter), @@ -62,3 +67,4 @@ class CustomOperator(ComputationalGraphNodeFrontend): super(CustomOperator, self).__init__( func=func, invars=invars, outvars=outvars, extra_args=extra_args, ghosts=ghosts, **kwds) + diff --git a/hysop/operator/custom_symbolic.py b/hysop/operator/custom_symbolic.py index 6f41185b8..056c73030 100644 --- a/hysop/operator/custom_symbolic.py +++ b/hysop/operator/custom_symbolic.py @@ -4,7 +4,7 @@ CustomSymbolicOperator solver frontend. """ from hysop.constants import Implementation -from hysop.tools.types import check_instance, to_tuple +from hysop.tools.types import check_instance, to_tuple, first_not_None from hysop.tools.decorators import debug from hysop.fields.continuous_field import Field from hysop.topology.cartesian_descriptor import CartesianTopologyDescriptors @@ -13,7 +13,7 @@ from hysop.core.graph.computational_node_frontend import ComputationalGraphNodeF class CustomSymbolicOperator(ComputationalGraphNodeFrontend): """ Interface for custom symbolic operators. - Available implementations are: + Available implementations are: *OPENCL (opencl code generated kernels) """ @@ -24,20 +24,27 @@ class CustomSymbolicOperator(ComputationalGraphNodeFrontend): Implementation.OPENCL: OpenClCustomSymbolicOperator } return __implementations - + @classmethod def default_implementation(cls): return Implementation.OPENCL - + + @debug + def __new__(cls, name, exprs, variables, + implementation=None, base_kwds=None, **kwds): + return super(CustomSymbolicOperator, cls).__new__(cls, + name=name, exprs=exprs, variables=variables, + base_kwds=base_kwds, implementation=implementation, **kwds) + @debug - def __init__(self, name, exprs, variables, + def __init__(self, name, exprs, variables, implementation=None, base_kwds=None, **kwds): """ Initialize a CustomSymbolicOperator operator frontend. See hysop.operator.base.CustomSymbolicOperatorBase to see how expressions are parsed. - + Parameters ---------- name: str @@ -54,15 +61,15 @@ class CustomSymbolicOperator(ComputationalGraphNodeFrontend): Base class keywords arguments. If None, an empty dict will be passed. kwds: - Keywords arguments that will be passed towards implementation + Keywords arguments that will be passed towards implementation operator __init__. """ - base_kwds = base_kwds or dict() + base_kwds = first_not_None(base_kwds, {}) exprs = to_tuple(exprs) check_instance(variables, dict, keys=Field, values=CartesianTopologyDescriptors) check_instance(base_kwds, dict, keys=str) - + super(CustomSymbolicOperator, self).__init__(name=name, exprs=exprs, variables=variables, base_kwds=base_kwds, implementation=implementation, **kwds) diff --git a/hysop/operator/diffusion.py b/hysop/operator/diffusion.py index 41da64275..f05cb2f24 100644 --- a/hysop/operator/diffusion.py +++ b/hysop/operator/diffusion.py @@ -43,6 +43,17 @@ class Diffusion(SpectralComputationalGraphNodeFrontend): def default_implementation(cls): return Implementation.PYTHON + @debug + def __new__(cls, Fin, variables, nu, dt, + Fout=None, implementation=None, + base_kwds=None, **kwds): + base_kwds = first_not_None(base_kwds, {}) + return super(Diffusion, cls).__new__(cls, + Fin=Fin, Fout=Fout, + variables=variables, nu=nu, dt=dt, + implementation=implementation, + base_kwds=base_kwds, **kwds) + @debug def __init__(self, Fin, variables, nu, dt, Fout=None, implementation=None, @@ -96,3 +107,4 @@ class Diffusion(SpectralComputationalGraphNodeFrontend): variables=variables, nu=nu, dt=dt, implementation=implementation, base_kwds=base_kwds, **kwds) + diff --git a/hysop/operator/directional/diffusion_dir.py b/hysop/operator/directional/diffusion_dir.py index 27222c4cb..0b345d7de 100644 --- a/hysop/operator/directional/diffusion_dir.py +++ b/hysop/operator/directional/diffusion_dir.py @@ -2,8 +2,8 @@ @file diffusion_dir.py Directional diffusion frontend (operator generator). """ +import sympy as sm -from hysop.deps import sm from hysop.constants import DirectionLabels, Implementation from hysop.tools.types import check_instance, to_tuple, to_list, first_not_None from hysop.tools.decorators import debug @@ -33,7 +33,6 @@ class DirectionalDiffusion(DirectionalSymbolic): candidate_output_tensors=None, **kwds) - @debug def __init__(self, fields, coeffs, variables, dt, laplacian_formulation=True, diff --git a/hysop/operator/directional/stretching_diffusion_dir.py b/hysop/operator/directional/stretching_diffusion_dir.py index 598027c76..d7d50c402 100644 --- a/hysop/operator/directional/stretching_diffusion_dir.py +++ b/hysop/operator/directional/stretching_diffusion_dir.py @@ -2,8 +2,8 @@ @file stretching_dir.py Directional stretching frontend (operator generator). """ +import sympy as sm -from hysop.deps import sm from hysop.constants import DirectionLabels, Implementation, StretchingFormulation from hysop.tools.types import check_instance, to_tuple, to_list, first_not_None from hysop.tools.decorators import debug @@ -20,7 +20,11 @@ class DirectionalStretchingDiffusion(DirectionalStretching): """ Directional stretching + diffusion using the symbolic code generation framework. """ - + + @debug + def __new__(cls, viscosity, **kwds): + return super(DirectionalStretchingDiffusion, cls).__new__(cls, **kwds) + @debug def __init__(self, viscosity, **kwds): """ @@ -52,7 +56,7 @@ class DirectionalStretchingDiffusion(DirectionalStretching): check_instance(viscosity, (float, Field)) self.viscosity = viscosity super(DirectionalStretchingDiffusion, self).__init__(**kwds) - + def _gen_expressions(self, formulation, velocity, vorticity, C, A): from hysop.symbolic.field import laplacian viscosity = self.viscosity diff --git a/hysop/operator/directional/stretching_dir.py b/hysop/operator/directional/stretching_dir.py index 905b31bb7..ed68b5aed 100644 --- a/hysop/operator/directional/stretching_dir.py +++ b/hysop/operator/directional/stretching_dir.py @@ -2,8 +2,8 @@ @file stretching_dir.py Directional stretching frontend (operator generator). """ +import sympy as sm -from hysop.deps import sm from hysop.constants import DirectionLabels, Implementation, StretchingFormulation from hysop.tools.types import check_instance, to_tuple, to_list, first_not_None from hysop.tools.decorators import debug diff --git a/hysop/operator/directional/symbolic_dir.py b/hysop/operator/directional/symbolic_dir.py index b1b5b9054..da94dd128 100644 --- a/hysop/operator/directional/symbolic_dir.py +++ b/hysop/operator/directional/symbolic_dir.py @@ -35,6 +35,21 @@ class DirectionalSymbolic(DirectionalOperatorFrontend): return Implementation.OPENCL + @debug + def __new__(cls, name, exprs, variables, + no_split=False, fixed_residue=0, force_residue=None, + implementation=None, base_kwds=None, + candidate_input_tensors=None, + candidate_output_tensors=None, + **kwds): + base_kwds = first_not_None(base_kwds, {}) + return super(DirectionalSymbolic, cls).__new__(cls, + name=name, variables=variables, + base_kwds=base_kwds, implementation=implementation, + candidate_input_tensors=candidate_input_tensors, + candidate_output_tensors=candidate_output_tensors, + **kwds) + @debug def __init__(self, name, exprs, variables, no_split=False, fixed_residue=0, force_residue=None, diff --git a/hysop/operator/dummy.py b/hysop/operator/dummy.py index e2b91c167..eac94502e 100644 --- a/hysop/operator/dummy.py +++ b/hysop/operator/dummy.py @@ -14,6 +14,11 @@ from hysop.core.graph.graph import op_apply class PythonDummy(HostOperator): + @debug + def __new__(cls, variables, **kwds): + return super(PythonDummy, cls).__new__(cls, + input_fields=None, output_fields=None, **kwds) + @debug def __init__(self, variables, **kwds): check_instance(variables, dict, keys=Field, @@ -57,3 +62,4 @@ class Dummy(ComputationalGraphNodeFrontend): @classmethod def default_implementation(cls): return Implementation.PYTHON + diff --git a/hysop/operator/enstrophy.py b/hysop/operator/enstrophy.py index 09b2a3276..e2531dc25 100644 --- a/hysop/operator/enstrophy.py +++ b/hysop/operator/enstrophy.py @@ -34,6 +34,17 @@ class Enstrophy(ComputationalGraphNodeFrontend): def default_implementation(cls): return Implementation.OPENCL + @debug + def __new__(cls, vorticity, enstrophy, variables, + rho=None, rho_0=1.0, WdotW=None, + implementation=None, base_kwds=None, **kwds): + base_kwds = first_not_None(base_kwds, {}) + return super(Enstrophy, cls).__new__(cls, + vorticity=vorticity, rho=rho, + enstrophy=enstrophy, WdotW=WdotW, rho_0=rho_0, + variables=variables, base_kwds=base_kwds, + implementation=implementation, **kwds) + @debug def __init__(self, vorticity, enstrophy, variables, rho=None, rho_0=1.0, WdotW=None, @@ -82,7 +93,7 @@ class Enstrophy(ComputationalGraphNodeFrontend): An Enstrophy operator implementation should at least support the hysop.operator.base.enstrophy.EnstrophyBase interface. """ - base_kwds = base_kwds or dict() + base_kwds = first_not_None(base_kwds, {}) check_instance(vorticity, Field) check_instance(enstrophy, ScalarParameter) @@ -96,3 +107,4 @@ class Enstrophy(ComputationalGraphNodeFrontend): enstrophy=enstrophy, WdotW=WdotW, rho_0=rho_0, variables=variables, base_kwds=base_kwds, implementation=implementation, **kwds) + diff --git a/hysop/operator/external_force.py b/hysop/operator/external_force.py index d0c9744f6..92d2d2f61 100644 --- a/hysop/operator/external_force.py +++ b/hysop/operator/external_force.py @@ -28,6 +28,21 @@ class SpectralExternalForce(ComputationalGraphNodeFrontend): def default_implementation(cls): return Implementation.OPENCL + @debug + def __new__(cls, vorticity, Fext, dt, variables, + Fmin=None, Fmax=None, Finf=None, + all_quiet=False, pbasename=None, ppbasename=None, + implementation=None, base_kwds=None, **kwds): + base_kwds = first_not_None(base_kwds, {}) + return super(SpectralExternalForce, cls).__new__(cls, + vorticity=vorticity, + Fext=Fext, dt=dt, variables=variables, + Fmin=None, Fmax=None, Finf=None, + candidate_input_tensors=None, + candidate_output_tensors=None, + implementation=implementation, + base_kwds=base_kwds, **kwds) + @debug def __init__(self, vorticity, Fext, dt, variables, Fmin=None, Fmax=None, Finf=None, diff --git a/hysop/operator/flowrate_correction.py b/hysop/operator/flowrate_correction.py index 6bc5c5fc5..2003df1ea 100644 --- a/hysop/operator/flowrate_correction.py +++ b/hysop/operator/flowrate_correction.py @@ -30,6 +30,18 @@ class FlowRateCorrection(ComputationalGraphNodeFrontend): def default_implementation(cls): return Implementation.PYTHON + def __new__(cls, velocity, vorticity, + dt, flowrate, variables, + implementation=None, **kwds): + return super(FlowRateCorrection, cls).__new__(cls, + velocity=velocity, + vorticity=vorticity, + dt=dt, + flowrate=flowrate, + variables=variables, + implementation=implementation, + **kwds) + def __init__(self, velocity, vorticity, dt, flowrate, variables, implementation=None, **kwds): @@ -67,3 +79,4 @@ class FlowRateCorrection(ComputationalGraphNodeFrontend): variables=variables, implementation=implementation, **kwds) + diff --git a/hysop/operator/gradient.py b/hysop/operator/gradient.py index b93b9264d..c90d10436 100644 --- a/hysop/operator/gradient.py +++ b/hysop/operator/gradient.py @@ -38,9 +38,7 @@ class Gradient(MultiSpaceDerivatives): cls=FiniteDifferencesSpaceDerivative, base_kwds=None, **kwds): base_kwds = {} if (base_kwds is None) else base_kwds - base_kwds.update(dict( - candidate_input_tensors=(F,), - candidate_output_tensors=(gradF,))) + base_kwds.update(dict(candidate_input_tensors=None, candidate_output_tensors=None)) return super(Gradient, mcls).__new__(mcls, Fs=None, dFs=None, cls=cls, candidate_input_tensors=(F,), diff --git a/hysop/operator/hdf_io.py b/hysop/operator/hdf_io.py index 76dcab47f..ac0494264 100755 --- a/hysop/operator/hdf_io.py +++ b/hysop/operator/hdf_io.py @@ -7,13 +7,19 @@ * :class:`~HDF_IO` abstract interface for hdf io classes """ -import subprocess -import sys -import os -import functools +import subprocess, sys, os, functools from abc import ABCMeta, abstractmethod + +try: + import h5py +except ImportError as e: + h5py = None + msg = 'Warning: h5py not found, you may not be able to' + msg += ' use hdf5 I/O functionnalities.' + print(msg) + raise + from hysop import __H5PY_PARALLEL_COMPRESSION_ENABLED__, vprint -from hysop.deps import h5py, sys from hysop.core.graph.graph import discretized from hysop.constants import DirectionLabels, HYSOP_REAL, Backend, TranspositionState, MemoryOrdering from hysop.tools.decorators import debug diff --git a/hysop/operator/integrate.py b/hysop/operator/integrate.py index 8bc7db166..2e161217e 100644 --- a/hysop/operator/integrate.py +++ b/hysop/operator/integrate.py @@ -34,6 +34,70 @@ class Integrate(ComputationalGraphNodeFrontend): def default_implementation(cls): return Implementation.PYTHON + @debug + def __new__(cls, field, variables, + parameter=None, scaling=None, + base_kwds=None, expr=None, **kwds): + base_kwds = first_not_None(base_kwds, {}) + return super(Integrate, cls).__new__(cls, + field=field, variables=variables, + parameter=parameter, scaling=scaling, expr=expr, + base_kwds=base_kwds, **kwds) + + @debug + def __init__(self, field, variables, + parameter=None, scaling=None, + base_kwds=None, expr=None, **kwds): + """ + Initialize a Integrate operator frontend. + + Integrate a field on it compute domain and put the result in a parameter. + + in: field + Possibly as multi-component field that should be integrated. + out: parameter + P = scaling * integral_V(field) + where V is the field domain volume + and scaling depends on specified scaling method. + + parameter + ---------- + field: Field + Input continuous field to be integrated. + variables: dict + dictionary of fields as keys and topologies as values. + parameter: ScalarParameter or TensorParameter + The output parameter that will contain the integral. + Should match field.nb_components. + A default parameter will be created if not specified. + scaling: None, float, str or array-like of str, optional + Scaling method used after integration. + 'volumic': scale by domain size (product of mesh space steps) + 'normalize': scale by first integration (first value will be 1.0) + Defaults to volumic integration. + expr: None, str, optional + expression performed on each entry of the array before sum, elements are referenced as `x[i]` + implementation: Implementation, optional, defaults to None + target implementation, should be contained in available_implementations(). + If None, implementation will be set to default_implementation(). + base_kwds: dict, optional, defaults to None + Base class keywords arguments. + If None, an empty dict will be passed. + kwds: + Extra keywords arguments that will be passed towards implementation + enstrophy operator __init__. + + Notes + ----- + An Integrate operator implementation should at least support + the hysop.operator.base.integrate.IntegrateBase interface. + """ + base_kwds = first_not_None(base_kwds, {}) + return super(Integrate, cls).__new__(cls, + field=field, variables=variables, + parameter=parameter, scaling=scaling, expr=expr, + base_kwds=base_kwds, **kwds) + @debug def __init__(self, field, variables, parameter=None, scaling=None, @@ -82,7 +146,7 @@ class Integrate(ComputationalGraphNodeFrontend): An Integrate operator implementation should at least support the hysop.operator.base.integrate.IntegrateBase interface. """ - base_kwds = base_kwds or dict() + base_kwds = first_not_None(base_kwds, {}) check_instance(field, Field) check_instance(variables, dict, keys=Field, values=CartesianTopologyDescriptors) @@ -105,3 +169,4 @@ class Integrate(ComputationalGraphNodeFrontend): super(Integrate, self).__init__(field=field, variables=variables, parameter=parameter, scaling=scaling, expr=expr, base_kwds=base_kwds, **kwds) + diff --git a/hysop/operator/kinetic_energy.py b/hysop/operator/kinetic_energy.py index cc563cbd6..206c78e94 100644 --- a/hysop/operator/kinetic_energy.py +++ b/hysop/operator/kinetic_energy.py @@ -17,25 +17,40 @@ from hysop.operator.enstrophy import Enstrophy class KineticEnergy(Enstrophy): """ Interface computing kinetic energy using the kinetic energy operators. - Available implementations are: + Available implementations are: *OPENCL (gpu based implementation) """ - + + @debug + def __new__(cls, velocity, kinetic_energy, variables, + rho=None, rho_0=1.0, UdotU=None, + implementation=None, base_kwds=None, **kwds): + return super(KineticEnergy, cls).__new__(cls, + vorticity=velocity, + rho=rho, + enstrophy=kinetic_energy, + WdotW=UdotU, + rho_0=rho_0, + variables=variables, + base_kwds=base_kwds, + implementation=implementation, + **kwds) + @debug - def __init__(self, velocity, kinetic_energy, variables, - rho=None, rho_0=1.0, UdotU=None, + def __init__(self, velocity, kinetic_energy, variables, + rho=None, rho_0=1.0, UdotU=None, implementation=None, base_kwds=None, **kwds): """ Initialize a KineticEnergy operator frontend. - KineticEnergy is the scaled volume average of rho*(U.U) on the domain where . represents + KineticEnergy is the scaled volume average of rho*(U.U) on the domain where . represents the vector dot product). in: U (velocity field) rho (density field, optional, defaults to 1.0 everywhere) out: E = 1.0/(2*V*rho_0) * integral(rho*(U.U)) => kinetic energy (scalar parameter) where V is the domain volume, rho_0 the reference density. - + Parameters ---------- velocity: Field @@ -43,7 +58,7 @@ class KineticEnergy(Enstrophy): kinetic_energy: ScalarParameter KineticEnergy scalar output parameter. rho: Field, optional - Input continuous density field, if not given, + Input continuous density field, if not given, defaults to 1.0 on the whole domain. rho_0: float, optional Reference density, defaults to 1.0. @@ -61,10 +76,10 @@ class KineticEnergy(Enstrophy): Base class keywords arguments. If None, an empty dict will be passed. kwds: - Extra keywords arguments that will be passed towards implementation + Extra keywords arguments that will be passed towards implementation operator __init__. """ - base_kwds = base_kwds or dict() + base_kwds = first_not_None(base_kwds, {}) check_instance(velocity, Field) check_instance(kinetic_energy, ScalarParameter) @@ -73,15 +88,15 @@ class KineticEnergy(Enstrophy): check_instance(UdotU, Field, allow_none=True) check_instance(rho, Field, allow_none=True) check_instance(rho_0, float) - + super(KineticEnergy, self).__init__( - vorticity=velocity, - rho=rho, - enstrophy=kinetic_energy, - WdotW=UdotU, + vorticity=velocity, + rho=rho, + enstrophy=kinetic_energy, + WdotW=UdotU, rho_0=rho_0, - variables=variables, - base_kwds=base_kwds, - implementation=implementation, + variables=variables, + base_kwds=base_kwds, + implementation=implementation, **kwds) diff --git a/hysop/operator/mean_field.py b/hysop/operator/mean_field.py index 94db193bd..fcf0105ce 100644 --- a/hysop/operator/mean_field.py +++ b/hysop/operator/mean_field.py @@ -26,8 +26,11 @@ class ComputeMeanField(ComputationalGraphOperator): """ @debug - def __init__(self, fields, variables, io_params, - **kwds): + def __new__(cls, fields, variables, io_params, **kwds): + return super(ComputeMeanField, cls).__new__(cls, input_fields=None, io_params=io_params, **kwds) + + @debug + def __init__(self, fields, variables, io_params, **kwds): """ Compute and write the mean of fields in given direction, possiblity on a subview. diff --git a/hysop/operator/memory_reordering.py b/hysop/operator/memory_reordering.py index 6d9f8dbc2..f479182ab 100644 --- a/hysop/operator/memory_reordering.py +++ b/hysop/operator/memory_reordering.py @@ -51,6 +51,18 @@ class MemoryReordering(ComputationalGraphNodeGenerator): msg+='implementation should match the discrete field topology backend.' raise RuntimeError(msg) + @debug + def __new__(cls, fields, variables, + target_memory_order, + output_fields=None, + implementation=None, + name=None, + base_kwds=None, + **kwds): + base_kwds = first_not_None(base_kwds, {}) + return super(MemoryReordering, cls).__new__(cls, name=name, + candidate_input_tensors=None, candidate_output_tensors=None, **base_kwds) + @debug def __init__(self, fields, variables, target_memory_order, diff --git a/hysop/operator/min_max.py b/hysop/operator/min_max.py index b353d4234..e2f925581 100644 --- a/hysop/operator/min_max.py +++ b/hysop/operator/min_max.py @@ -41,6 +41,18 @@ class MinMaxFieldStatistics(ComputationalGraphNodeFrontend): def default_implementation(cls): return Implementation.PYTHON + @debug + def __new__(cls, field, components=None, coeffs=None, + Fmin=None, Fmax=None, Finf=None, all_quiet=False, + name=None, pbasename=None, ppbasename=None, + variables=None, implementation=None, base_kwds=None, **kwds): + return super(MinMaxFieldStatistics, cls).__new__(cls, + field=field, components=components, + coeffs=coeffs, Fmin=Fmin, Fmax=Fmax, Finf=Finf, all_quiet=all_quiet, + name=name, pbasename=pbasename, ppbasename=ppbasename, + variables=variables, implementation=implementation, base_kwds=base_kwds, + **kwds) + @debug def __init__(self, field, components=None, coeffs=None, Fmin=None, Fmax=None, Finf=None, all_quiet=False, @@ -169,7 +181,7 @@ class MinMaxFieldStatistics(ComputationalGraphNodeFrontend): class MinMaxDerivativeStatistics(ComputationalGraphNodeFrontend): """ Operator frontend to compute min and max statistics on a specific - derivative of a field component, without keeping its output. + derivative of a scalar field, without keeping its output. """ @classmethod @@ -180,10 +192,23 @@ class MinMaxDerivativeStatistics(ComputationalGraphNodeFrontend): def default_implementation(cls): raise NotImplementedError + @debug + def __new__(cls, F, dF=None, A=None, + derivative=None, direction=None, + Fmin=None, Fmax=None, Finf=None, coeffs=None, all_quiet=False, + name=None, pbasename=None, ppbasename=None, + variables=None, implementation=None, base_kwds=None, **kwds): + return super(MinMaxDerivativeStatistics, cls).__new__(cls, + F=F, dF=dF, A=A, + derivative=derivative, direction=direction, + Fmin=Fmin, Fmax=Fmax, Finf=Finf, coeffs=coeffs, all_quiet=all_quiet, + name=name, pbasename=pbasename, ppbasename=ppbasename, + variables=variables, implementation=implementation, + base_kwds=base_kwds, **kwds) + @debug def __init__(self, F, dF=None, A=None, - derivative=None, component=None, direction=None, - out_component=None, scaling_view=None, + derivative=None, direction=None, Fmin=None, Fmax=None, Finf=None, coeffs=None, all_quiet=False, name=None, pbasename=None, ppbasename=None, variables=None, implementation=None, base_kwds=None, **kwds): @@ -197,9 +222,9 @@ class MinMaxDerivativeStatistics(ComputationalGraphNodeFrontend): Finf: max value of the absolute value of a derivative of the field (computed using Fmin and Fmax). - First compute the derivative of a component of a field F in a given direction - at a given order and on a given backend out of place in a specific output component of - dF. The derivative is then possibly scaled by another field/parameter/value A. + First compute the derivative of a scalar field F in a given direction + at a given order and on a given backend out of place in scalar field dF + The derivative is then possibly scaled by another field/parameter/value A. After the scaled derivative has been computed, compute user requested statistics (min and max values) on this new field and scale those statistics by other scaling @@ -209,18 +234,14 @@ class MinMaxDerivativeStatistics(ComputationalGraphNodeFrontend): dF[k] = alpha * d^n(F[i])/dXj**n 2) Compute statistics - Fmin = Smin * min(dF[k]) - Fmax = Smax * max(dF[k]) + Fmin = Smin * min(dF) + Fmax = Smax * max(dF) Finf = Sinf * max(|Fmin|, |Fmax|) where F is an input field dF is an output field (by default a temporary field). - k = out_component < dF.nb_components - i = component < F.nb_components n = derivative order > 0 - alpha = A[scaling_view] - where A is a Field, a Parameter or a scalar. - scaling_view is a component, a slice or None. + alpha = A, where A is a Field, a Parameter or a scalar. Fmin = created or supplied TensorParameter. Fmax = created or supplied TensorParameter. Finf = created or supplied TensorParameter. @@ -248,22 +269,9 @@ class MinMaxDerivativeStatistics(ComputationalGraphNodeFrontend): derivative: int, optional Which derivative to generate. Defaults to 1. - component: int, optional - The component on which to take the derivative. - Defaults to 0. direction: int, optional Directions in which to take the derivative. Defaults to 0. - out_component: int, optional - The component were the result will be stored. - Defaults to component. - scaling_view: int or slice, optional - View on the scaling field/parameter/value A. - Should be a component if this is a field. - Should be a slice if this is a TensorParameter. - Should be None it this is a ScalarParameter or - a numerical value. - Should only be given if A is given. F...: TensorParameter or boolean, optional The output parameters that will contain the statistics. At least one statistic should be specified (either by boolean or TensorParameter). @@ -315,9 +323,7 @@ class MinMaxDerivativeStatistics(ComputationalGraphNodeFrontend): check_instance(F, Field) check_instance(dF, Field, allow_none=True) check_instance(derivative, int, allow_none=True) - check_instance(component, int, allow_none=True) check_instance(direction, int, allow_none=True) - check_instance(out_component, int, allow_none=True) check_instance(coeffs, dict, keys=str, values=(int, float, npw.number), allow_none=True) check_instance(variables, dict, keys=Field, values=CartesianTopologyDescriptors, allow_none=True) @@ -338,14 +344,13 @@ class MinMaxDerivativeStatistics(ComputationalGraphNodeFrontend): # Pregenerate parameters so that we can directly store them in self. parameters = MinMaxDerivativeStatisticsBase.build_parameters(field=F, - components=(component,), all_quiet=all_quiet, + all_quiet=all_quiet, components=tuple(range(F.nb_components)), Fmin=Fmin, Fmax=Fmax, Finf=Finf, pbasename=pbasename, ppbasename=ppbasename) (Fmin, Fmax, Finf) = tuple(parameters[k] for k in ('Fmin', 'Fmax', 'Finf')) super(MinMaxDerivativeStatistics, self).__init__(F=F, dF=dF, A=A, - derivative=derivative, component=component, direction=direction, - out_component=out_component, scaling_view=scaling_view, + derivative=derivative, direction=direction, Fmin=Fmin, Fmax=Fmax, Finf=Finf, coeffs=coeffs, all_quiet=all_quiet, name=name, pbasename=pbasename, ppbasename=ppbasename, variables=variables, implementation=implementation, @@ -357,7 +362,7 @@ class MinMaxDerivativeStatistics(ComputationalGraphNodeFrontend): class MinMaxSpectralDerivativeStatistics(MinMaxDerivativeStatistics): """ Operator frontend to compute min and max statistics on a specific - derivative of a field component using the spectral method. + derivative of a scalar field using the spectral method. """ @classmethod def implementations(cls): @@ -380,7 +385,7 @@ class MinMaxSpectralDerivativeStatistics(MinMaxDerivativeStatistics): class MinMaxFiniteDifferencesDerivativeStatistics(MinMaxDerivativeStatistics): """ Operator frontend to compute min and max statistics on a specific - derivative of a field component using finite differences. + derivative of a scalar field using finite differences. """ @classmethod def implementations(cls): diff --git a/hysop/operator/parameter_plotter.py b/hysop/operator/parameter_plotter.py index 76058605d..53b33b6c4 100644 --- a/hysop/operator/parameter_plotter.py +++ b/hysop/operator/parameter_plotter.py @@ -15,6 +15,18 @@ class PlottingOperator(ComputationalGraphOperator): def supports_mpi(cls): return True + def __new__(cls, name=None, + dump_dir=None, + update_frequency=1, + save_frequency=100, + axes_shape=(1,), + figsize=(30, 18), + visu_rank=0, + fig=None, + axes=None, + **kwds): + return super(PlottingOperator, cls).__new__(cls, **kwds) + def __init__(self, name=None, dump_dir=None, update_frequency=1, diff --git a/hysop/operator/penalization.py b/hysop/operator/penalization.py index fbfa9ca28..10b6872bf 100644 --- a/hysop/operator/penalization.py +++ b/hysop/operator/penalization.py @@ -38,6 +38,23 @@ class PenalizeVorticity(ComputationalGraphNodeFrontend): def default_implementation(cls): return Implementation.PYTHON + @debug + def __new__(cls, obstacles, variables, + velocity, vorticity, + dt, coeff=None, ubar=None, formulation=None, + implementation=None, **kwds): + return super(PenalizeVorticity, cls).__new__(cls, + velocity=velocity, + vorticity=vorticity, + coeff=coeff, + ubar=ubar, + obstacles=obstacles, + dt=dt, + formulation=formulation, + variables=variables, + implementation=implementation, + **kwds) + @debug def __init__(self, obstacles, variables, velocity, vorticity, diff --git a/hysop/operator/poisson.py b/hysop/operator/poisson.py index a5a87dd5d..2ab5a674f 100644 --- a/hysop/operator/poisson.py +++ b/hysop/operator/poisson.py @@ -42,6 +42,14 @@ class Poisson(SpectralComputationalGraphNodeFrontend): def default_implementation(cls): return Implementation.PYTHON + @debug + def __new__(cls, Fin, Fout, variables, + implementation=None, base_kwds=None, **kwds): + return super(Poisson, cls).__new__(cls, + Fin=Fin, Fout=Fout, + variables=variables, base_kwds=base_kwds, + implementation=implementation, **kwds) + @debug def __init__(self, Fin, Fout, variables, implementation=None, base_kwds=None, **kwds): @@ -70,7 +78,7 @@ class Poisson(SpectralComputationalGraphNodeFrontend): Keywords arguments that will be passed towards implementation poisson operator __init__. """ - base_kwds = base_kwds or dict() + base_kwds = first_not_None(base_kwds, {}) check_instance(Fout, Field) check_instance(Fin, Field) diff --git a/hysop/operator/poisson_curl.py b/hysop/operator/poisson_curl.py index 593783628..cd8597dce 100644 --- a/hysop/operator/poisson_curl.py +++ b/hysop/operator/poisson_curl.py @@ -43,16 +43,25 @@ class PoissonCurl(SpectralComputationalGraphNodeFrontend): def default_implementation(cls): return Implementation.PYTHON + @debug + def __new__(cls, velocity, vorticity, variables, + implementation=None, base_kwds=None, **kwds): + base_kwds = first_not_None(base_kwds, {}) + return super(PoissonCurl, cls).__new__(cls, + velocity=velocity, vorticity=vorticity, + variables=variables, base_kwds=base_kwds, + implementation=implementation, **kwds) + @debug def __init__(self, velocity, vorticity, variables, implementation=None, base_kwds=None, **kwds): """ - Initialize a PoissonCurl operator frontend for 2D or 3D + Initialize a PoissonCurl operator frontend for 2D or 3D streamfunction-vorticity formulations. in = W (vorticity) out = U (velocity) - + Vorticity also becomes an output if projection or diffusion is enabled. PoissonCurl does more than just solving the Poisson equation for velocity: @@ -89,7 +98,7 @@ class PoissonCurl(SpectralComputationalGraphNodeFrontend): If diffusion is not enabled, this parameter is ignored. projection: hysop.constants.FieldProjection or positive integer, optional Project vorticity such that resolved velocity is divergence free (for 3D fields). - When active, projection is done prior to every solve, unless projection is + When active, projection is done prior to every solve, unless projection is an integer in which case it is done every given steps. This parameter is ignored for 2D fields and defaults to no projection. implementation: Implementation, optional, defaults to None @@ -107,7 +116,7 @@ class PoissonCurl(SpectralComputationalGraphNodeFrontend): A PoissonCurl operator implementation should at least support the following __init__ attributes: velocity, vorticity, variables """ - base_kwds = base_kwds or dict() + base_kwds = first_not_None(base_kwds, {}) check_instance(velocity, Field) check_instance(vorticity, Field) diff --git a/hysop/operator/redistribute.py b/hysop/operator/redistribute.py index c0fde1ed3..1578c205f 100644 --- a/hysop/operator/redistribute.py +++ b/hysop/operator/redistribute.py @@ -22,7 +22,7 @@ class RedistributeNotImplementedError(Exception): class Redistribute(ComputationalGraphNodeGenerator): """Node generator generating redistribute operators. """ - + __redistribute_operators = { RedistributeIntra : 0, #1: RedistributeInter, @@ -30,7 +30,7 @@ class Redistribute(ComputationalGraphNodeGenerator): } """ Implemented redistribute operators, - keys are classes that inerit + keys are classes that inerit hysop.core.mpi.redistribute.RedistributeOperatorBase values are operator priority (smaller value has more priority), """ @@ -39,8 +39,18 @@ class Redistribute(ComputationalGraphNodeGenerator): assert issubclass(cls, RedistributeOperatorBase), \ '{} is not a RedistributeOperatorBase.'.format(cls) - def __init__(self, variables, source_topos, target_topo, components=None, - name=None, pretty_name=None, + def __new__(cls, variables, source_topos, target_topo, + name=None, pretty_name=None, + base_kwds=None, **kwds): + base_kwds = first_not_None(base_kwds, {}) + return super(Redistribute, cls).__new__(cls, + name=name, pretty_name=pretty_name, + candidate_input_tensors=None, + candidate_output_tensors=None, + **base_kwds) + + def __init__(self, variables, source_topos, target_topo, + name=None, pretty_name=None, base_kwds=None, **kwds): """ Initialize a Redistribute operator generator. @@ -52,8 +62,6 @@ class Redistribute(ComputationalGraphNodeGenerator): candidate source mesh topologies (for each field the optimal source topology will be choosed) target_topo: :class:`~hysop.topology.topology.Topology` or dict(Field, Topology) target mesh topology for all variables (or per variable if a dictionnary is passed) - components: None, int or array like of ints or dict(Field,components) - which component of the fields must be distributed (default = all components) name: string prefix for generated operator names pretty_name: string @@ -62,15 +70,15 @@ class Redistribute(ComputationalGraphNodeGenerator): Base class keywords arguments. If None, an empty dict will be passed. kwds: - Keywords arguments that will be passed towards implementation + Keywords arguments that will be passed towards implementation redistribute operator __init__. """ assert 'source_topo' not in kwds - base_kwds = base_kwds or dict() + base_kwds = first_not_None(base_kwds, {}) variables = to_tuple(variables) - super(Redistribute,self).__init__(name=name, pretty_name=pretty_name, + super(Redistribute,self).__init__(name=name, pretty_name=pretty_name, candidate_input_tensors=variables, candidate_output_tensors=variables, **base_kwds) @@ -78,7 +86,7 @@ class Redistribute(ComputationalGraphNodeGenerator): # format variables to a set of variables variables = to_set(variables) check_instance(variables, set, values=Field) - + # format source topos to a dict(Field, set(Topology)) if isinstance(source_topos, dict): for k,v in source_topos: @@ -91,56 +99,45 @@ class Redistribute(ComputationalGraphNodeGenerator): check_instance(source_topos, dict, keys=Field, values=set) for v in source_topos.values(): check_instance(v, set, values=Topology) - + # format target_topo to a dict(Field, Topology) if not isinstance(target_topo, dict): check_instance(target_topo, Topology) target_topo = dict(zip(variables, (target_topo,)*len(variables))) check_instance(target_topo, dict, keys=Field, values=Topology) - # format components to a dict(Field, set(int)|None) - if not isinstance(components, dict): - if (components is not None): - components = to_set(components) - components = dict(zip(variables, (components,)*len(variables))) - check_instance(components, dict, keys=Field) - for v in components.values(): - check_instance(v, set, values=int, allow_none=True) - self._variables = variables self._source_topos = source_topos self._target_topo = target_topo - self._components = components self._kwds = kwds - + @debug def _generate(self): nodes = [] for var in self._variables: source_topos = self._source_topos[var] target_topo = self._target_topo[var] - components = self._components[var] kwds = self._kwds.copy() - + # if source topology is destination topology there is nothing to be done if (target_topo in source_topos): continue - + # else we find the most suitable source topology - node = self._select_redistribute(variable=var, source_topos=source_topos, - target_topo=target_topo, components=components, **kwds) + node = self._select_redistribute(variable=var, source_topos=source_topos, + target_topo=target_topo, **kwds) nodes.append(node) return nodes @staticmethod - def _select_redistribute(variable, source_topos, target_topo, components, **kwds): + def _select_redistribute(variable, source_topos, target_topo, **kwds): assert target_topo not in source_topos best_redis = None for source_topo in source_topos: - redis = Redistribute._get_compatible_redistribute(variable, source_topo, target_topo, components, + redis = Redistribute._get_compatible_redistribute(variable, source_topo, target_topo, **kwds) best_redis = Redistribute._select_best_operator(best_redis, redis) - + if (best_redis is None): msg='Failed to find a suitable redistribute operator for variables {} ' msg+='between sources topologies and destination topology.\n' @@ -156,7 +153,7 @@ class Redistribute(ComputationalGraphNodeGenerator): @staticmethod def _select_best_operator(lhs, rhs): - # select highest priority operator when there are more + # select highest priority operator when there are more # than one candidate source topology if (lhs is None): return rhs @@ -170,13 +167,13 @@ class Redistribute(ComputationalGraphNodeGenerator): return lhs else: return rhs - + @staticmethod - def _get_compatible_redistribute(variable, source_topo, target_topo, components, **kwds): + def _get_compatible_redistribute(variable, source_topo, target_topo, **kwds): # look from highest prority operator to smallest priority operators # if nothing is found return None for cls,_ in sorted(Redistribute.__redistribute_operators.items(), key=lambda x: x[1]): if cls.can_redistribute(source_topo=source_topo, target_topo=target_topo): return cls(variable=variable, source_topo=source_topo, - target_topo=target_topo, components=components, **kwds) + target_topo=target_topo, **kwds) return None diff --git a/hysop/operator/solenoidal_projection.py b/hysop/operator/solenoidal_projection.py index 15ea4c72a..9241414cb 100644 --- a/hysop/operator/solenoidal_projection.py +++ b/hysop/operator/solenoidal_projection.py @@ -17,10 +17,10 @@ from hysop.backend.device.opencl.operator.solenoidal_projection import OpenClSol class SolenoidalProjection(SpectralComputationalGraphNodeFrontend): """ Interface for solenoidal projection (project a 3d field F such that div(F)=0) - Available implementations are: + Available implementations are: *PYTHON (numpy fft based solver) """ - + __implementations = { Implementation.PYTHON: PythonSolenoidalProjection, Implementation.OPENCL: OpenClSolenoidalProjection @@ -29,24 +29,33 @@ class SolenoidalProjection(SpectralComputationalGraphNodeFrontend): @classmethod def implementations(cls): return cls.__implementations - + @classmethod def default_implementation(cls): return Implementation.PYTHON - + @debug - def __init__(self, input_field, output_field, variables, + def __new__(cls, input_field, output_field, variables, + input_field_div=None, output_field_div=None, + implementation=None, base_kwds=None, **kwds): + return super(SolenoidalProjection, cls).__new__(cls, + input_field=input_field, output_field=output_field, + input_field_div=input_field_div, output_field_div=output_field_div, + variables=variables, base_kwds=base_kwds, implementation=implementation, **kwds) + + @debug + def __init__(self, input_field, output_field, variables, input_field_div=None, output_field_div=None, implementation=None, base_kwds=None, **kwds): """ Initialize a SolenoidalProjection operator frontend for 3D solenoidal projection. - + Fin (3d input_field) Fout (3d output_field) - + Solves laplacian(Fout) = laplacian(Fin) - grad(div(Fin)) - + Parameters ---------- input_field: Field @@ -66,7 +75,7 @@ class SolenoidalProjection(SpectralComputationalGraphNodeFrontend): Base class keywords arguments. If None, an empty dict will be passed. kwds: - Keywords arguments that will be passed towards implementation + Keywords arguments that will be passed towards implementation poisson operator __init__. Notes @@ -74,7 +83,7 @@ class SolenoidalProjection(SpectralComputationalGraphNodeFrontend): A SolenoidalProjection operator implementation should inherit from hysop.operator.base.solenoidal_projection.SolenoidalProjectionBase. """ - base_kwds = base_kwds or dict() + base_kwds = first_not_None(base_kwds, {}) check_instance(input_field, Field) check_instance(output_field, Field) @@ -82,11 +91,11 @@ class SolenoidalProjection(SpectralComputationalGraphNodeFrontend): check_instance(output_field_div, Field, allow_none=True) check_instance(variables, dict, keys=Field, values=CartesianTopologyDescriptors) check_instance(base_kwds, dict, keys=str) - + dim = input_field.domain.dim icomp = input_field.nb_components ocomp = output_field.nb_components - + if (input_field.domain != output_field.domain): msg = 'input_field and output_field do not share the same domain.' raise ValueError(msg) @@ -108,6 +117,7 @@ class SolenoidalProjection(SpectralComputationalGraphNodeFrontend): msg=msg.format(output_field_div.nb_components) raise RuntimeError(msg) - super(SolenoidalProjection, self).__init__(input_field=input_field, output_field=output_field, + super(SolenoidalProjection, self).__init__(input_field=input_field, output_field=output_field, input_field_div=input_field_div, output_field_div=output_field_div, variables=variables, base_kwds=base_kwds, implementation=implementation, **kwds) + diff --git a/hysop/operator/spatial_filtering.py b/hysop/operator/spatial_filtering.py index 2f3746a3e..4abd1c09e 100644 --- a/hysop/operator/spatial_filtering.py +++ b/hysop/operator/spatial_filtering.py @@ -29,6 +29,17 @@ class SpatialFilterFrontend(MultiComputationalGraphNodeFrontend): implementation=implementation, base_kwds=base_kwds, **kwds) + def __new__(cls, input_variable, output_variable, + filtering_method, implementation=None, + base_kwds=None, + **kwds): + return super(SpatialFilterFrontend, cls).__new__(cls, + input_field=None, input_topo=None, + output_field=None, output_topo=None, + implementation_key=None, + implementation=None, + base_kwds=base_kwds, **kwds) + def __init__(self, input_variable, output_variable, filtering_method, implementation=None, base_kwds=None, @@ -168,6 +179,17 @@ class SpatialFilter(ComputationalGraphNodeGenerator): candidate_output_tensors=None, **base_kwds) + @debug + def __new__(cls, input_variables, output_variables, + filtering_method, implementation=None, + base_kwds=None, + **kwds): + base_kwds = first_not_None(base_kwds, {}) + return super(SpatialFilter, cls).__new__(cls, + candidate_input_tensors=None, + candidate_output_tensors=None, + **base_kwds) + @debug def __init__(self, input_variables, output_variables, filtering_method, implementation=None, diff --git a/hysop/operator/tests/test_absorption.py b/hysop/operator/tests/test_absorption.py index cd6b4430a..686eab917 100644 --- a/hysop/operator/tests/test_absorption.py +++ b/hysop/operator/tests/test_absorption.py @@ -2,7 +2,9 @@ Test of vorticity absorption """ import random -from hysop.deps import it, sm, random +import itertools as it +import sympy as sm + from hysop.constants import HYSOP_REAL from hysop.testsenv import __ENABLE_LONG_TESTS__, __HAS_OPENCL_BACKEND__ from hysop.testsenv import opencl_failed, iter_clenv diff --git a/hysop/operator/tests/test_analytic.py b/hysop/operator/tests/test_analytic.py index 5ca022b2e..305454c16 100644 --- a/hysop/operator/tests/test_analytic.py +++ b/hysop/operator/tests/test_analytic.py @@ -2,7 +2,9 @@ Test of fields defined with an analytic formula. """ import random -from hysop.deps import it, sm, random +import itertools as it +import sympy as sm + from hysop.constants import HYSOP_REAL from hysop.testsenv import __ENABLE_LONG_TESTS__, __HAS_OPENCL_BACKEND__ from hysop.testsenv import opencl_failed, iter_clenv diff --git a/hysop/operator/tests/test_bilevel_advection.py b/hysop/operator/tests/test_bilevel_advection.py index 3b2f64eec..45777b9e2 100644 --- a/hysop/operator/tests/test_bilevel_advection.py +++ b/hysop/operator/tests/test_bilevel_advection.py @@ -1,4 +1,5 @@ -from hysop.deps import sys +import sys + from hysop.testsenv import __ENABLE_LONG_TESTS__ from hysop.testsenv import iter_clenv from hysop.tools.numpywrappers import npw diff --git a/hysop/operator/tests/test_custom_symbolic.py b/hysop/operator/tests/test_custom_symbolic.py index 935b43d91..e3bb497a4 100644 --- a/hysop/operator/tests/test_custom_symbolic.py +++ b/hysop/operator/tests/test_custom_symbolic.py @@ -1,5 +1,8 @@ +import itertools as it +import numpy as np +import sympy as sm + from hysop import Field, Box -from hysop.deps import np, it, sm from hysop.constants import Implementation, ComputeGranularity, SpaceDiscretization, HYSOP_REAL from hysop.testsenv import __ENABLE_LONG_TESTS__, __HAS_OPENCL_BACKEND__ from hysop.testsenv import opencl_failed, iter_clenv diff --git a/hysop/operator/tests/test_directional_advection.py b/hysop/operator/tests/test_directional_advection.py index c860edb21..9109452a3 100644 --- a/hysop/operator/tests/test_directional_advection.py +++ b/hysop/operator/tests/test_directional_advection.py @@ -1,5 +1,6 @@ +import sys import numpy as np -from hysop.deps import sys + from hysop.testsenv import __ENABLE_LONG_TESTS__ from hysop.testsenv import iter_clenv from hysop.tools.numpywrappers import npw @@ -75,11 +76,11 @@ class TestDirectionalAdvectionOperator(object): for time_integrator in time_integrators: for remesh_kernel in remesh_kernels: for velocity_cfl in velocity_cfls: - print() self._test_one(time_integrator=time_integrator, remesh_kernel=remesh_kernel, shape=shape, dim=dim, dtype=dtype, is_inplace=is_inplace, domain=domain, Vin=Vin, Sin=Sin, Sout=Sout, velocity_cfl=velocity_cfl) + print() @classmethod def __velocity_init(cls, data, coords, component, axes): diff --git a/hysop/operator/tests/test_directional_diffusion.py b/hysop/operator/tests/test_directional_diffusion.py index e6ae504d6..a4aa36531 100644 --- a/hysop/operator/tests/test_directional_diffusion.py +++ b/hysop/operator/tests/test_directional_diffusion.py @@ -1,4 +1,5 @@ -from hysop.deps import sys +import sys + from hysop.tools.numpywrappers import npw from hysop.testsenv import __ENABLE_LONG_TESTS__ from hysop.testsenv import iter_clenv @@ -70,11 +71,11 @@ class TestDirectionalDiffusionOperator(object): coeffs = npw.random.rand(Fin.nb_components, dim).astype(dtype) for order in orders: for time_integrator in time_integrators: - print() self._test_one(time_integrator=time_integrator, order=order, shape=shape, dim=dim, dtype=dtype, is_inplace=is_inplace, domain=domain, Fin=Fin, Fout=Fout, coeffs=coeffs) + print() @staticmethod def __random_init(data, coords, dtype, component): diff --git a/hysop/operator/tests/test_directional_stretching.py b/hysop/operator/tests/test_directional_stretching.py index 811caabb0..02328b3a7 100644 --- a/hysop/operator/tests/test_directional_stretching.py +++ b/hysop/operator/tests/test_directional_stretching.py @@ -1,4 +1,6 @@ -from hysop.deps import sys, sm +import sys +import sympy as sm + from hysop.testsenv import __ENABLE_LONG_TESTS__, iter_clenv from hysop.tools.numpywrappers import npw from hysop.tools.contexts import printoptions @@ -77,12 +79,12 @@ class TestDirectionalStretchingOperator(object): for A in As: for order in orders: for time_integrator in time_integrators: - print() self._test_one(time_integrator=time_integrator, order=order, shape=shape, dim=dim, dtype=dtype, is_inplace=is_inplace, domain=domain, Vin=Vin, Win=Win, Wout=Wout, C=C, A=A, formulation=formulation) + print() @staticmethod def __random_init(data, coords, component): diff --git a/hysop/operator/tests/test_fd_derivative.py b/hysop/operator/tests/test_fd_derivative.py index 776d803a9..1a648bdf8 100644 --- a/hysop/operator/tests/test_fd_derivative.py +++ b/hysop/operator/tests/test_fd_derivative.py @@ -2,7 +2,9 @@ Test gradient of fields. """ import random -from hysop.deps import it, sm, random +import itertools as it +import sympy as sm + from hysop.constants import HYSOP_REAL, Backend from hysop.methods import SpaceDiscretization from hysop.testsenv import __ENABLE_LONG_TESTS__, __HAS_OPENCL_BACKEND__ diff --git a/hysop/operator/tests/test_penalization.py b/hysop/operator/tests/test_penalization.py index fe33fc94b..5dc3eccd1 100644 --- a/hysop/operator/tests/test_penalization.py +++ b/hysop/operator/tests/test_penalization.py @@ -2,7 +2,7 @@ Test of vorticity penalization """ import random -from hysop.deps import random + from hysop.constants import HYSOP_REAL from hysop.testsenv import __ENABLE_LONG_TESTS__ from hysop.tools.contexts import printoptions diff --git a/hysop/operator/tests/test_poisson.py b/hysop/operator/tests/test_poisson.py index 151f0477f..70e2c389f 100644 --- a/hysop/operator/tests/test_poisson.py +++ b/hysop/operator/tests/test_poisson.py @@ -1,6 +1,7 @@ -import random -import primefac -from hysop.deps import it, sm, random +import random, primefac +import itertools as it +import sympy as sm + from hysop.constants import HYSOP_REAL, BoundaryCondition from hysop.testsenv import __ENABLE_LONG_TESTS__, __HAS_OPENCL_BACKEND__ from hysop.testsenv import opencl_failed, iter_clenv, test_context, domain_boundary_iterator diff --git a/hysop/operator/tests/test_poisson_curl.py b/hysop/operator/tests/test_poisson_curl.py index a7433ea1a..e8a989cfa 100644 --- a/hysop/operator/tests/test_poisson_curl.py +++ b/hysop/operator/tests/test_poisson_curl.py @@ -1,7 +1,9 @@ # coding: utf-8 import random, primefac -from hysop.deps import it, sm, random +import itertools as it +import sympy as sm + from hysop.constants import HYSOP_REAL, BoxBoundaryCondition, BoundaryCondition from hysop.defaults import VelocityField, VorticityField from hysop.testsenv import __ENABLE_LONG_TESTS__, __HAS_OPENCL_BACKEND__ diff --git a/hysop/operator/tests/test_restriction_filter.py b/hysop/operator/tests/test_restriction_filter.py index 45228d948..a89e68429 100755 --- a/hysop/operator/tests/test_restriction_filter.py +++ b/hysop/operator/tests/test_restriction_filter.py @@ -72,6 +72,8 @@ class TestMultiresolutionFilter(object): def _test_one(self, shape_f, shape_c, dim, dtype, domain, f, factor): + print('\nTesting {}D SpatialFilter: dtype={} shape_f={} shape_c={}'.format( + dim, dtype.__name__, shape_f, shape_c)) implementations = (Implementation.PYTHON, ) mpi_params = MPIParams(comm=domain.task_comm, task_id=domain.current_task()) @@ -152,6 +154,7 @@ class TestMultiresolutionFilter(object): def perform_tests(self): self._test(dim=3, dtype=HYSOP_REAL) + print() def test_3d(self): self._test(dim=3, dtype=HYSOP_REAL) diff --git a/hysop/operator/tests/test_scales_advection.py b/hysop/operator/tests/test_scales_advection.py index 549fd61ef..e3430a8e6 100644 --- a/hysop/operator/tests/test_scales_advection.py +++ b/hysop/operator/tests/test_scales_advection.py @@ -1,4 +1,5 @@ -from hysop.deps import sys +import sys + from hysop.testsenv import __ENABLE_LONG_TESTS__ from hysop.testsenv import iter_clenv from hysop.tools.numpywrappers import npw diff --git a/hysop/operator/tests/test_solenoidal_projection.py b/hysop/operator/tests/test_solenoidal_projection.py index 79ad2fe2d..a6ac30a8b 100644 --- a/hysop/operator/tests/test_solenoidal_projection.py +++ b/hysop/operator/tests/test_solenoidal_projection.py @@ -1,5 +1,8 @@ import random, primefac, scipy -from hysop.deps import it, sm, random, np +import itertools as it +import numpy as np +import sympy as sm + from hysop.constants import HYSOP_REAL, Implementation, BoxBoundaryCondition from hysop.defaults import VelocityField, VorticityField from hysop.testsenv import __ENABLE_LONG_TESTS__, __HAS_OPENCL_BACKEND__ diff --git a/hysop/operator/tests/test_spectral_curl.py b/hysop/operator/tests/test_spectral_curl.py index 3d36452ef..59a2fac03 100644 --- a/hysop/operator/tests/test_spectral_curl.py +++ b/hysop/operator/tests/test_spectral_curl.py @@ -1,6 +1,7 @@ -import random -import primefac -from hysop.deps import it, sm, random +import random, primefac +import itertools as it +import sympy as sm + from hysop.constants import HYSOP_REAL, BoxBoundaryCondition from hysop.defaults import VelocityField, VorticityField from hysop.testsenv import __ENABLE_LONG_TESTS__, __HAS_OPENCL_BACKEND__ diff --git a/hysop/operator/tests/test_spectral_derivative.py b/hysop/operator/tests/test_spectral_derivative.py index 3c705422b..9fd43df96 100644 --- a/hysop/operator/tests/test_spectral_derivative.py +++ b/hysop/operator/tests/test_spectral_derivative.py @@ -1,7 +1,10 @@ """ Test gradient of fields. """ -from hysop.deps import it, sm, random +import random +import itertools as it +import sympt as sm + from hysop.constants import HYSOP_REAL, Backend, BoundaryCondition, BoxBoundaryCondition from hysop.methods import SpaceDiscretization from hysop.testsenv import __ENABLE_LONG_TESTS__, __HAS_OPENCL_BACKEND__ diff --git a/hysop/operator/tests/test_transpose.py b/hysop/operator/tests/test_transpose.py index 9008a3880..fee7dc228 100644 --- a/hysop/operator/tests/test_transpose.py +++ b/hysop/operator/tests/test_transpose.py @@ -1,5 +1,7 @@ import random -from hysop.deps import np, it +import itertools as it +import numpy as np + from hysop.testsenv import __ENABLE_LONG_TESTS__, __HAS_OPENCL_BACKEND__ from hysop.testsenv import opencl_failed, iter_clenv from hysop.tools.contexts import printoptions diff --git a/hysop/operator/tests/test_velocity_correction.py b/hysop/operator/tests/test_velocity_correction.py index 125c41042..850ae3f2d 100644 --- a/hysop/operator/tests/test_velocity_correction.py +++ b/hysop/operator/tests/test_velocity_correction.py @@ -2,7 +2,9 @@ Test of velocity correction """ import random -from hysop.deps import it, sm, random +import itertools as it +import sympy as sm + from hysop.constants import HYSOP_REAL from hysop.testsenv import __ENABLE_LONG_TESTS__, __HAS_OPENCL_BACKEND__ from hysop.testsenv import opencl_failed, iter_clenv @@ -119,7 +121,7 @@ class TestFlowRateCorrection(object): name='vorticity_correction_{}'.format(str(impl).lower())) if impl is Implementation.PYTHON: msg=' *Python: ' - print(msg) + print(msg, end=' ') yield FlowRateCorrection(flowrate=self.flowrate, **base_kwds) print() @@ -167,9 +169,8 @@ class TestFlowRateCorrection(object): dinf = npw.max(dist) deps = int(npw.ceil(dinf/eps)) if (deps < 10): - print('{}eps, '.format(deps)) - return - print() + print('{}eps, '.format(deps), end=' ') + continue print() print('Test output comparisson failed for flowrate:') print(' *dinf={} ({} eps)'.format(dinf, deps)) diff --git a/hysop/operator/vorticity_absorption.py b/hysop/operator/vorticity_absorption.py index 7a2541ed8..1269d9521 100644 --- a/hysop/operator/vorticity_absorption.py +++ b/hysop/operator/vorticity_absorption.py @@ -1,7 +1,8 @@ """ @file vorticity_absorption.py """ -from hysop.deps import sm +import sympy as sm + from hysop.constants import Implementation from hysop.core.graph.computational_node_frontend import ComputationalGraphNodeFrontend from hysop.tools.types import check_instance @@ -33,6 +34,21 @@ class VorticityAbsorption(ComputationalGraphNodeFrontend): def default_implementation(cls): return Implementation.PYTHON + def __new__(cls, velocity, vorticity, + dt, flowrate, start_coord, variables, + custom_filter=None, + implementation=None, **kwds): + return super(VorticityAbsorption, cls).__new__(cls, + velocity=velocity, + vorticity=vorticity, + dt=dt, + flowrate=flowrate, + start_coord=start_coord, + variables=variables, + custom_filter=custom_filter, + implementation=implementation, + **kwds) + def __init__(self, velocity, vorticity, dt, flowrate, start_coord, variables, custom_filter=None, diff --git a/hysop/operators.py b/hysop/operators.py index 4ab660d2d..b13c8ca54 100644 --- a/hysop/operators.py +++ b/hysop/operators.py @@ -33,14 +33,14 @@ from hysop.operator.custom import CustomOperator from hysop.operator.convergence import Convergence from hysop.operator.spatial_filtering import SpatialFilter -from hysop.operator.derivative import SpaceDerivative, \ - SpectralSpaceDerivative, \ - FiniteDifferencesSpaceDerivative, \ - MultiSpaceDerivatives +from hysop.operator.derivative import (SpaceDerivative, + SpectralSpaceDerivative, + FiniteDifferencesSpaceDerivative, + MultiSpaceDerivatives) -from hysop.operator.min_max import MinMaxFieldStatistics, \ - MinMaxFiniteDifferencesDerivativeStatistics, \ - MinMaxSpectralDerivativeStatistics +from hysop.operator.min_max import (MinMaxFieldStatistics, + MinMaxFiniteDifferencesDerivativeStatistics, + MinMaxSpectralDerivativeStatistics) from hysop.operator.gradient import Gradient, MinMaxGradientStatistics from hysop.operator.curl import Curl, SpectralCurl diff --git a/hysop/parameters/buffer_parameter.py b/hysop/parameters/buffer_parameter.py index 0a100f5b8..637dba25b 100644 --- a/hysop/parameters/buffer_parameter.py +++ b/hysop/parameters/buffer_parameter.py @@ -1,6 +1,6 @@ - +import numpy as np import sympy as sm -from hysop.deps import np + from hysop.constants import HYSOP_REAL from hysop.tools.types import check_instance from hysop.parameters.tensor_parameter import TensorParameter, Parameter @@ -11,17 +11,17 @@ class BufferParameter(Parameter): A parameter is a value that may change as simulation advances. """ - def __new__(cls, shape=None, dtype=HYSOP_REAL, initial_value=None, symbol=None, + def __new__(cls, shape=None, dtype=HYSOP_REAL, initial_value=None, symbol=None, **kwds): parameter_types = (np.ndarray,) - initial_value = TensorParameter._compute_initial_value(shape=shape, + initial_value = TensorParameter._compute_initial_value(shape=shape, dtype=dtype, initial_value=initial_value) - obj = super(BufferParameter,cls).__new__(cls, + obj = super(BufferParameter,cls).__new__(cls, parameter_types=parameter_types, initial_value=initial_value, **kwds) obj._symbol = None obj._update_symbol(symbol) return obj - + def reallocate_buffer(self, shape, dtype, initial_value=None, symbol=None): self._value = TensorParameter._compute_initial_value(shape, dtype, initial_value) self._update_symbol(symbol) @@ -33,11 +33,11 @@ class BufferParameter(Parameter): symbol.bind_memory_selfect(memory_selfect=self._value, force=True) self._symbol = symbol elif (self._symbol is None): - self._symbol = HostSymbolicBuffer(memory_object=self._value, name=self.var_name, + self._symbol = HostSymbolicBuffer(memory_object=self._value, name=self.var_name, pretty_name=self.pretty_name, var_name=self.var_name) else: self._symbol.bind_memory_object(memory_object=self._value, force=True) - + def long_description(self): ss = '''\ BufferParameter[name={}] @@ -47,7 +47,7 @@ BufferParameter[name={}] self.shape, self.dtype) return ss - + def short_description(self): attrs=('name', 'shape', 'dtype') info = [] @@ -60,14 +60,14 @@ BufferParameter[name={}] ss = 'BufferParameter[{}]' ss = ss.format(attrs) return ss - + def _get_value_impl(self): """Return a read-only reference on the underlying data buffer.""" assert (self._value is not None) view = self._value.view() view.flags.writeable = False return view.view() - + def _set_value_impl(self, value): """Given value will be copied into internal buffer.""" assert (self._value is not None) @@ -81,11 +81,11 @@ BufferParameter[name={}] msg=msg.format(self.dtype, value.dtype) raise ValueError(msg) self._value[...] = value - + def iterviews(self): """Iterate over all parameters views to yield scalarparameters.""" yield (None,self) - + def _get_shape(self): """Get parameter shape.""" return self._value.shape if (self._value is not None) else None diff --git a/hysop/parameters/scalar_parameter.py b/hysop/parameters/scalar_parameter.py index d01c60f2d..176c27ba9 100644 --- a/hysop/parameters/scalar_parameter.py +++ b/hysop/parameters/scalar_parameter.py @@ -1,5 +1,5 @@ +import numpy as np -from hysop.deps import np from hysop.constants import HYSOP_REAL from hysop.tools.types import check_instance from hysop.parameters.tensor_parameter import TensorParameter diff --git a/hysop/parameters/tensor_parameter.py b/hysop/parameters/tensor_parameter.py index 249317b69..89fb6664b 100644 --- a/hysop/parameters/tensor_parameter.py +++ b/hysop/parameters/tensor_parameter.py @@ -1,5 +1,6 @@ +import numpy as np +import sympy as sm -from hysop.deps import np, sm from hysop.constants import HYSOP_REAL from hysop.tools.types import check_instance, first_not_None from hysop.tools.numerics import is_signed, is_unsigned, is_fp, is_complex @@ -169,7 +170,7 @@ class TensorParameter(Parameter): name = first_not_None(name, _name) pretty_name = first_not_None(pretty_name, _pretty_name) if initial_value.size == 1: - from scalar_parameter import ScalarParameter + from hysop.parameters.scalar_parameter import ScalarParameter return ScalarParameter(name=name, pretty_name=pretty_name, initial_value=initial_value.ravel(), dtype=self.dtype, min_value=self.min_value, max_value=self.max_value, diff --git a/hysop/problem.py b/hysop/problem.py index b7938075a..9bf70d4dc 100644 --- a/hysop/problem.py +++ b/hysop/problem.py @@ -1,4 +1,3 @@ -from __future__ import absolute_import import sys, datetime from hysop.constants import Backend, MemoryOrdering diff --git a/hysop/simulation.py b/hysop/simulation.py index 010e81b5e..d288337bd 100644 --- a/hysop/simulation.py +++ b/hysop/simulation.py @@ -28,11 +28,12 @@ Usage s.finalize() io.apply(s) """ +import sys, os import numpy as np from abc import ABCMeta, abstractmethod + from hysop import dprint, vprint from hysop.constants import HYSOP_REAL -from hysop.deps import sys, os from hysop.parameters.scalar_parameter import ScalarParameter from hysop.tools.types import first_not_None, to_set, check_instance from hysop.tools.numpywrappers import npw diff --git a/hysop/symbolic/array.py b/hysop/symbolic/array.py index 2fadf2989..c480787af 100644 --- a/hysop/symbolic/array.py +++ b/hysop/symbolic/array.py @@ -299,7 +299,6 @@ class OpenClSymbolicNdBuffer(SymbolicDeviceMemoryObject, SymbolicNdBuffer): if __name__ == '__main__': - from hysop.deps import sm from hysop.core.arrays.all import default_host_array_backend a = npw.ones(shape=(10,10), dtype=npw.int8) b = default_host_array_backend.zeros(shape=(10,), dtype=npw.uint16) diff --git a/hysop/symbolic/base.py b/hysop/symbolic/base.py index 0ad4dca61..16c92b173 100644 --- a/hysop/symbolic/base.py +++ b/hysop/symbolic/base.py @@ -1,5 +1,5 @@ +import sympy as sm -from hysop.deps import sm from hysop.tools.numpywrappers import npw from hysop.tools.types import first_not_None from hysop.symbolic import Symbol, Dummy, subscript diff --git a/hysop/symbolic/directional.py b/hysop/symbolic/directional.py index 09b8fa402..fbfb6e7e4 100644 --- a/hysop/symbolic/directional.py +++ b/hysop/symbolic/directional.py @@ -1,6 +1,7 @@ - import warnings -from hysop.deps import np, sm +import numpy as np +import sympy as sm + from hysop.tools.types import first_not_None, check_instance from hysop.symbolic import space_symbols from hysop.symbolic.field import div, grad diff --git a/hysop/symbolic/field.py b/hysop/symbolic/field.py index 5b9c34e1e..76afce7d6 100644 --- a/hysop/symbolic/field.py +++ b/hysop/symbolic/field.py @@ -1,5 +1,6 @@ from abc import abstractmethod -from hysop.deps import sm +import sympy as sm + from hysop.constants import BoundaryCondition from hysop.tools.numpywrappers import npw diff --git a/hysop/symbolic/func.py b/hysop/symbolic/func.py index 61bd42f75..dd3978c1b 100644 --- a/hysop/symbolic/func.py +++ b/hysop/symbolic/func.py @@ -1,5 +1,6 @@ +import sympy as sm +import numpy as np -from hysop.deps import sm, np from hysop.tools.types import check_instance, first_not_None from hysop.symbolic import time_symbol, space_symbols from hysop.symbolic import AppliedUndef, UndefinedFunction diff --git a/hysop/symbolic/misc.py b/hysop/symbolic/misc.py index 813df0ec6..140fb5780 100644 --- a/hysop/symbolic/misc.py +++ b/hysop/symbolic/misc.py @@ -1,9 +1,9 @@ +import sympy as sm -from hysop.deps import sm from hysop.tools.numpywrappers import npw from hysop.tools.types import check_instance, first_not_None, to_tuple from hysop.symbolic import Expr, Symbol - + InstructionTermination = '' class Select(Expr): @@ -14,13 +14,13 @@ class Select(Expr): obj.b = b obj.c = c return obj - + def __str__(self): return '({} ? {} : {})'.format(self.c, self.b, self.a) def __repr__(self): return 'Select({}, {}, {})'.format(repr(self.a), repr(self.b), repr(self.c)) def _sympystr(self, printer): - return '({} ? {} : {})'.format(printer._print(self.c), + return '({} ? {} : {})'.format(printer._print(self.c), printer._print(self.b), printer._print(self.a)) @@ -83,7 +83,7 @@ class CodeSection(Expr): assert all(type(e) not in (tuple, list, set, frozenset, dict) for e in exprs) obj = super(CodeSection, cls).__new__(cls, *exprs) return obj - + def _sympystr(self, printer): return 'CodeSection([{}])'.format( '; '.join(printer._print(a) for a in self.args)) @@ -101,7 +101,7 @@ class MutexOp(Expr): obj.mutexes = mutexes obj.mutex_id = mutex_id return obj - + class MutexLock(MutexOp): def _sympystr(self, printer): return 'MutexLock({}, {})'.format( diff --git a/hysop/symbolic/parameter.py b/hysop/symbolic/parameter.py index c38e93d0d..313c8cfa9 100644 --- a/hysop/symbolic/parameter.py +++ b/hysop/symbolic/parameter.py @@ -49,7 +49,7 @@ class SymbolicScalarParameter(SymbolicScalar): if __name__ == '__main__': - from hysop.deps import sm + import sympy as sm from hysop.parameters.tensor_parameter import TensorParameter from hysop.parameters.scalar_parameter import ScalarParameter a = ScalarParameter('A', dtype=npw.int32, initial_value=4) diff --git a/hysop/symbolic/relational.py b/hysop/symbolic/relational.py index 8ed218e3b..4ebb20734 100644 --- a/hysop/symbolic/relational.py +++ b/hysop/symbolic/relational.py @@ -1,5 +1,5 @@ +import sympy as sm -from hysop.deps import sm from hysop.symbolic import Expr from hysop.tools.types import first_not_None from hysop.tools.numpywrappers import npw @@ -19,11 +19,11 @@ class NAryRelation(Expr): def __new__(cls, *exprs): obj = super(NAryRelation, cls).__new__(cls, *exprs) return obj - + def __str__(self): rel_op = ' {} '.format(self.rel_op) return '({})'.format(rel_op.join(str(x) for x in self.args)) - + def _sympystr(self, printer): rel_op = ' {} '.format(self.rel_op) return '({})'.format(rel_op.join('{}'.format(printer._print(x)) for x in self.args)) @@ -35,7 +35,7 @@ class NAryRelation(Expr): @property def is_number(self): return True - + @property def free_symbols(self): return () @@ -119,7 +119,7 @@ class Assignment(BinaryRelation): lhs : Expr rhs : Expr """ - + def __str__(self): lhs = first_not_None(getattr(self.lhs,'name',None), self.lhs) rhs = first_not_None(getattr(self.rhs,'name',None), self.rhs) @@ -136,11 +136,11 @@ class Assignment(BinaryRelation): printer._print(self.lhs), self.rel_op, printer._print(self.rhs)) - + @property def rel_op(self): return '=' - + @classmethod def assign(cls, lhs, rhs, skip_zero_rhs=False): exprs = () @@ -177,7 +177,7 @@ class Assignment(BinaryRelation): msg=msg.format(type(lhs), type(rhs)) raise TypeError(msg) return exprs - + class AugmentedAssignment(Assignment): """ @@ -205,8 +205,8 @@ class DivAugmentedAssignment(AugmentedAssignment): class ModAugmentedAssignment(AugmentedAssignment): _symbol = '%' - - + + class NAryFunction(Expr): """ @@ -223,11 +223,11 @@ class NAryFunction(Expr): def __new__(cls, *exprs): obj = super(NAryFunction, cls).__new__(cls, *exprs) return obj - + def __str__(self): return '{}({})'.format(self.fname, ', '.join(str(x) for x in self.args)) - + def _sympystr(self, printer): return '{}({})'.format(self.fname, ', '.join('{}'.format(printer._print(x)) for x in self.args)) @@ -239,7 +239,7 @@ class NAryFunction(Expr): @property def is_number(self): return True - + @property def free_symbols(self): return () diff --git a/hysop/tools/cache.py b/hysop/tools/cache.py index c96f4a84d..973017919 100644 --- a/hysop/tools/cache.py +++ b/hysop/tools/cache.py @@ -38,7 +38,7 @@ def lock_file(filepath, mode, compressed=True, with portalocker.Lock(filename=filepath, timeout=timeout, mode=mode, check_interval=check_interval) as fl: if compressed: - with gzip.GzipFile(fileobj=fl) as f: + with gzip.GzipFile(fileobj=fl, mode=mode) as f: yield f else: yield fl diff --git a/hysop/tools/contexts.py b/hysop/tools/contexts.py index c8314ec11..ea340e07a 100644 --- a/hysop/tools/contexts.py +++ b/hysop/tools/contexts.py @@ -1,6 +1,5 @@ - -import os -from hysop.deps import np, time, sys +import os, time, sys +import numpy as np from contextlib import contextmanager, ExitStack @contextmanager diff --git a/hysop/tools/decorators.py b/hysop/tools/decorators.py index 23a859037..7dd331ea2 100644 --- a/hysop/tools/decorators.py +++ b/hysop/tools/decorators.py @@ -1,9 +1,9 @@ -import functools +import functools, inspect, types, warnings, sys, traceback from functools import wraps as __wraps from abc import ABCMeta + from hysop.constants import __DEBUG__, __VERBOSE__, __PROFILE__, HYSOP_ROOT -from hysop.deps import inspect, types, warnings, sys, traceback from hysop.tools.sys_utils import SysUtils from hysop.tools.warning import HysopDeprecationWarning diff --git a/hysop/tools/handle.py b/hysop/tools/handle.py index 3da4d127e..072c78604 100644 --- a/hysop/tools/handle.py +++ b/hysop/tools/handle.py @@ -1,6 +1,6 @@ - from abc import ABCMeta, abstractmethod -from hysop.deps import np +import numpy as np + from hysop.tools.decorators import not_implemented, debug from hysop.tools.types import to_tuple, first_not_None from hysop.tools.sympy_utils import subscript @@ -97,8 +97,8 @@ class TaggedObject(object, metaclass=ABCMeta): tagged_cls = first_not_None(tagged_cls, cls) if kwds: - print('TARGGED OBJECT MRO is:\n {}'.format('\n '.join(map(str,cls.__mro__)))) - print('KWDS NEW are {}'.format(kwds)) + print('\n ' + '\n '.join(map(str,cls.__mro__))) + print(kwds) obj = super(TaggedObject, cls).__new__(cls, **kwds) if tagged_cls in TaggedObject.__ids: obj.__tag_id = TaggedObject.__ids[tagged_cls] @@ -122,9 +122,6 @@ class TaggedObject(object, metaclass=ABCMeta): assert (tag_postfix is None) or isinstance(tag_postfix, str) assert (tag_formatter is None) or callable(tag_formatter) - if kwds: - print('TARGGED OBJECT MRO is:\n {}'.format('\n '.join(map(str,self.__class__.__mro__)))) - print('KWDS INIT are {}'.format(kwds)) super(TaggedObject, self).__init__(**kwds) # reaffect attributes (some classes use only __init__ for simplicity) diff --git a/hysop/tools/hash.py b/hysop/tools/hash.py index 0d44ab8a0..1036fec96 100644 --- a/hysop/tools/hash.py +++ b/hysop/tools/hash.py @@ -1,5 +1,5 @@ - -from hysop.deps import np, hashlib +import hashlib +import numpy as np def hash_communicator(comm, h=None): from hysop.core.mpi import processor_hash diff --git a/hysop/tools/misc.py b/hysop/tools/misc.py index 98df7fdf7..3d4022516 100644 --- a/hysop/tools/misc.py +++ b/hysop/tools/misc.py @@ -7,7 +7,9 @@ """ -from hysop.deps import inspect, np, functools, operator +import inspect, functools, operator +import numpy as np + from hysop.constants import HYSOP_REAL, HYSOP_INTEGER def getargspec(func): diff --git a/hysop/tools/mpi_utils.py b/hysop/tools/mpi_utils.py index 3a211ba67..92fe6c97a 100644 --- a/hysop/tools/mpi_utils.py +++ b/hysop/tools/mpi_utils.py @@ -1,5 +1,5 @@ +import numpy as np -from hysop.deps import np from hysop.core.mpi import MPI from hysop.tools.numerics import get_dtype diff --git a/hysop/tools/numerics.py b/hysop/tools/numerics.py index 3b9ee9637..bcf7f4dba 100644 --- a/hysop/tools/numerics.py +++ b/hysop/tools/numerics.py @@ -1,7 +1,8 @@ +import numpy as np +import gmpy2 +from gmpy2 import mpq,mpz,mpfr,f2q from hysop.constants import HYSOP_REAL, HYSOP_INTEGER, HYSOP_INDEX, HYSOP_BOOL, HYSOP_COMPLEX -from hysop.deps import np, gmp -from gmpy2 import mpq,mpz,mpfr,f2q MPQ = mpq(0).__class__ MPZ = mpz(0).__class__ diff --git a/hysop/tools/numpywrappers.py b/hysop/tools/numpywrappers.py index c3c884f4f..4b8391d43 100644 --- a/hysop/tools/numpywrappers.py +++ b/hysop/tools/numpywrappers.py @@ -5,7 +5,7 @@ Those functions are useful to enforce hysop predefined types in numpy arrays. """ from hysop.tools.types import check_instance -from hysop.deps import np as npw +import numpy as npw ########################## ### EXTRA HYSOP METHODS ## diff --git a/hysop/tools/sympy_utils.py b/hysop/tools/sympy_utils.py index c947dce10..6a9ef8174 100644 --- a/hysop/tools/sympy_utils.py +++ b/hysop/tools/sympy_utils.py @@ -1,11 +1,13 @@ - -from hysop.deps import np, sm, copy -from hysop.tools.types import first_not_None, check_instance, to_tuple +import copy +import numpy as np +import sympy as sm from sympy.utilities import group from sympy.printing.str import StrPrinter, StrReprPrinter from sympy.printing.latex import LatexPrinter +from hysop.tools.types import first_not_None, check_instance, to_tuple + # unicode subscripts for decimal numbers, signs and parenthesis decimal_subscripts = 'â‚€â‚₂₃₄₅₆₇₈₉' decimal_exponents = 'â°Â¹Â²Â³â´âµâ¶â·â¸â¹' diff --git a/hysop/tools/transposition_states.py b/hysop/tools/transposition_states.py index a3d9ed47e..46416816c 100644 --- a/hysop/tools/transposition_states.py +++ b/hysop/tools/transposition_states.py @@ -1,5 +1,5 @@ +import itertools as it -from hysop.deps import it from hysop.tools.types import check_instance DirectionLabels = 'XYZABCDEFGHIJKLMNOPQRSTUVW' diff --git a/hysop/tools/types.py b/hysop/tools/types.py index 58655a459..fef0a85fe 100644 --- a/hysop/tools/types.py +++ b/hysop/tools/types.py @@ -1,5 +1,5 @@ -from hysop.deps import np from collections.abc import Iterable +import numpy as np class InstanceOf(object): def __init__(self, cls): diff --git a/hysop/tools/units.py b/hysop/tools/units.py index f1341b559..a5b4436ea 100644 --- a/hysop/tools/units.py +++ b/hysop/tools/units.py @@ -1,4 +1,4 @@ -from hysop.deps import np +import numpy as np def binary_unit2str(b,unit,rounded): try: diff --git a/hysop/tools/warning.py b/hysop/tools/warning.py index ee8bb9246..f36c0edb7 100644 --- a/hysop/tools/warning.py +++ b/hysop/tools/warning.py @@ -1,3 +1,4 @@ +import warnings class HysopWarning(RuntimeWarning): """ @@ -30,12 +31,11 @@ class HysopCacheWarning(HysopWarning): pass def configure_hysop_warnings(action): - """ + """ Configure hysop warnings. Action can be error, ignore, always, default, module, once. See https://docs.python.org/2/library/warnings.html#warning-filter. """ - from hysop.deps import warnings warnings.filterwarnings(action=action, category=HysopWarning) warnings.filterwarnings(action=action, category=HysopDeprecationWarning) diff --git a/hysop/topology/cartesian_descriptor.py b/hysop/topology/cartesian_descriptor.py index 747109168..47aaffbda 100644 --- a/hysop/topology/cartesian_descriptor.py +++ b/hysop/topology/cartesian_descriptor.py @@ -1,3 +1,5 @@ +import hashlib, copy +import numpy as np from hysop.tools.types import check_instance, to_tuple from hysop.topology.topology_descriptor import TopologyDescriptor @@ -6,7 +8,6 @@ from hysop.tools.parameters import CartesianDiscretization from hysop.constants import Backend, BoundaryCondition from hysop.fields.continuous_field import Field from hysop.tools.numpywrappers import npw -from hysop.deps import np, hashlib, copy class CartesianTopologyDescriptor(TopologyDescriptor): """ diff --git a/hysop/topology/cartesian_topology.py b/hysop/topology/cartesian_topology.py index 1a4450aa5..18642f8fa 100644 --- a/hysop/topology/cartesian_topology.py +++ b/hysop/topology/cartesian_topology.py @@ -1,4 +1,5 @@ -from hysop.deps import warnings +import warnings + from hysop.topology.topology import Topology, TopologyState, TopologyView, TopologyWarning from hysop.constants import np, math, Backend, MemoryOrdering from hysop.constants import HYSOP_ORDER, BoundaryCondition, HYSOP_INTEGER diff --git a/hysop_examples/examples/analytic/analytic.py b/hysop_examples/examples/analytic/analytic.py index 011865c2a..85539b859 100755 --- a/hysop_examples/examples/analytic/analytic.py +++ b/hysop_examples/examples/analytic/analytic.py @@ -29,7 +29,7 @@ def compute(args): if (impl is Implementation.PYTHON): # Setup python specific extra operator keyword arguments # (mapping: variable name => variable value) - op_kwds['extra_input_kwds'] = {'t': t} + pass elif (impl is Implementation.OPENCL): # For the OpenCL implementation we need to setup the compute device # and configure how the code is generated and compiled at runtime. @@ -63,6 +63,7 @@ def compute(args): data[...] = (1.0/(1.0+0.1*t())) for x in coords: data[...] *= np.cos(x-t()) + extra_input_kwds = {'t': t} elif (impl is Implementation.OPENCL): # With the opencl codegen implementation we use a symbolic expression # generated using sympy. OpenCL code will be automatically generated, @@ -75,6 +76,7 @@ def compute(args): compute_scalar = 1/(1+0.1*ts) for xi in xs: compute_scalar *= sm.cos(xi-ts) + extra_input_kwds = {} else: msg = 'Unknown implementation {}.'.format(impl) @@ -82,7 +84,7 @@ def compute(args): analytic = AnalyticField(name='analytic', field=scalar, formula=compute_scalar, variables={scalar: npts}, implementation=impl, - **op_kwds) + extra_input_kwds=extra_input_kwds, **op_kwds) # Write output field at given frequency io_params = IOParams(filename='analytic', frequency=args.dump_freq) diff --git a/hysop_examples/examples/particles_above_salt/particles_above_salt_symmetrized.py b/hysop_examples/examples/particles_above_salt/particles_above_salt_symmetrized.py index 36e8009be..674d447b2 100644 --- a/hysop_examples/examples/particles_above_salt/particles_above_salt_symmetrized.py +++ b/hysop_examples/examples/particles_above_salt/particles_above_salt_symmetrized.py @@ -71,7 +71,7 @@ def compute(args): nu_S = ScalarParameter(name='nu_S', dtype=args.dtype, const=True, initial_value=1.0/Sc) nu_C = ScalarParameter(name='nu_C', dtype=args.dtype, const=True, initial_value=1.0/(tau*Sc)) - nu_W = ScalarParameter(name='nu_W', dtype=args.dtype, cosnt=True, initial_value=1.0) + nu_W = ScalarParameter(name='nu_W', dtype=args.dtype, const=True, initial_value=1.0) # Define the domain dim = args.ndim diff --git a/hysop_examples/examples/shear_layer/shear_layer.py b/hysop_examples/examples/shear_layer/shear_layer.py index 39cea288a..0a3544a24 100644 --- a/hysop_examples/examples/shear_layer/shear_layer.py +++ b/hysop_examples/examples/shear_layer/shear_layer.py @@ -8,7 +8,6 @@ import numpy as np def compute(args): from hysop import Box, Simulation, Problem, MPIParams,\ ScalarParameter - from hysop.tools.debug_utils import ImshowDebugger from hysop.defaults import VelocityField, VorticityField, \ TimeParameters, ViscosityParameter from hysop.constants import Implementation, AdvectionCriteria -- GitLab