From 9432ca797a9443539707d2ce2f20c9d285548c6b Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 1 Oct 2025 17:31:05 +0200 Subject: [PATCH 01/76] Added Pyccelkernel class and use it for AccumulatorVector, Accumulator, and Pusher kernels --- src/struphy/models/base.py | 2 +- .../pic/accumulation/particles_to_grid.py | 30 +++++++++++++------ src/struphy/pic/particles.py | 2 +- src/struphy/pic/pushing/pusher.py | 6 ++-- src/struphy/utils/pyccel.py | 25 ++++++++++++++++ 5 files changed, 52 insertions(+), 13 deletions(-) create mode 100644 src/struphy/utils/pyccel.py diff --git a/src/struphy/models/base.py b/src/struphy/models/base.py index 5d02dd647..af10c5180 100644 --- a/src/struphy/models/base.py +++ b/src/struphy/models/base.py @@ -1850,7 +1850,7 @@ def _allocate_variables(self): domain_decomp = (domain_array, nprocs) kinetic_class = getattr(particles, val["space"]) - + print(f"{kinetic_class = }") val["obj"] = kinetic_class( comm_world=self.comm_world, clone_config=self.clone_config, diff --git a/src/struphy/pic/accumulation/particles_to_grid.py b/src/struphy/pic/accumulation/particles_to_grid.py index 23345df23..1fcaf54d3 100644 --- a/src/struphy/pic/accumulation/particles_to_grid.py +++ b/src/struphy/pic/accumulation/particles_to_grid.py @@ -1,5 +1,7 @@ "Base classes for particle deposition (accumulation) on the grid." +from typing import Any, Callable + import numpy as np from mpi4py import MPI from psydac.linalg.block import BlockVector @@ -13,6 +15,7 @@ from struphy.kernel_arguments.pusher_args_kernels import DerhamArguments, DomainArguments from struphy.pic.base import Particles from struphy.profiling.profiling import ProfileManager +from struphy.utils.pyccel import Pyccelkernel class Accumulator: @@ -66,6 +69,10 @@ class Accumulator: filter_params : dict Params for the accumulation filter: use_filter(string, either `three_point or `fourier), repeat(int), alpha(float) and modes(list with int). + + use_cupy : bool + Use cupy arrays + Note ---- Struphy accumulation kernels called by ``Accumulator`` objects must be added to ``struphy/pic/accumulation/accum_kernels.py`` @@ -77,7 +84,7 @@ def __init__( self, particles: Particles, space_id: str, - kernel, + kernel: Callable[..., Any], mass_ops: WeightedMassOperators, args_domain: DomainArguments, *, @@ -89,10 +96,11 @@ def __init__( "repeat": None, "alpha": None, }, + use_cupy: bool = False, ): self._particles = particles self._space_id = space_id - self._kernel = kernel + self._kernel = Pyccelkernel(kernel, use_cupy=use_cupy) self._derham = mass_ops.derham self._args_domain = args_domain @@ -204,7 +212,7 @@ def __call__(self, *optional_args, **args_control): dat[:] = 0.0 # accumulate into matrix (and vector) with markers - with ProfileManager.profile_region("kernel: " + self.kernel.__name__): + with ProfileManager.profile_region("kernel: " + self.kernel.name): self.kernel( self.particles.args_markers, self.derham.args_derham, @@ -347,7 +355,7 @@ def particles(self): return self._particles @property - def kernel(self): + def kernel(self) -> Pyccelkernel: """The accumulation kernel.""" return self._kernel @@ -521,19 +529,23 @@ class AccumulatorVector: args_domain : DomainArguments Mapping infos. + + use_cupy : bool + Use cupy arrays """ def __init__( self, particles: Particles, space_id: str, - kernel, + kernel: Callable[..., Any], mass_ops: WeightedMassOperators, args_domain: DomainArguments, + use_cupy: bool = False, ): self._particles = particles self._space_id = space_id - self._kernel = kernel + self._kernel = Pyccelkernel(kernel, use_cupy=use_cupy) self._derham = mass_ops.derham self._args_domain = args_domain @@ -609,10 +621,10 @@ def __call__(self, *optional_args, **args_control): dat[:] = 0.0 # accumulate into matrix (and vector) with markers - with ProfileManager.profile_region("kernel: " + self.kernel.__name__): + with ProfileManager.profile_region("kernel: " + self.kernel.name): self.kernel( self.particles.args_markers, - self.derham._args_derham, + self.derham.args_derham, self.args_domain, *self._args_data, *optional_args, @@ -652,7 +664,7 @@ def particles(self): return self._particles @property - def kernel(self): + def kernel(self) -> Pyccelkernel: """The accumulation kernel.""" return self._kernel diff --git a/src/struphy/pic/particles.py b/src/struphy/pic/particles.py index b5c78e32f..012b29c29 100644 --- a/src/struphy/pic/particles.py +++ b/src/struphy/pic/particles.py @@ -39,7 +39,7 @@ def __init__( # default number of diagnostics and auxiliary columns self._n_cols_diagnostics = kwargs.pop("n_cols_diagn", 0) self._n_cols_aux = kwargs.pop("n_cols_aux", 5) - + print(kwargs.keys()) super().__init__(**kwargs) # call projected mhd equilibrium in case of CanonicalMaxwellian diff --git a/src/struphy/pic/pushing/pusher.py b/src/struphy/pic/pushing/pusher.py index 855d18920..5010986f1 100644 --- a/src/struphy/pic/pushing/pusher.py +++ b/src/struphy/pic/pushing/pusher.py @@ -6,6 +6,7 @@ from struphy.kernel_arguments.pusher_args_kernels import DerhamArguments, DomainArguments from struphy.pic.base import Particles from struphy.profiling.profiling import ProfileManager +from struphy.utils.pyccel import Pyccelkernel class Pusher: @@ -109,9 +110,10 @@ def __init__( tol: float = 1.0e-8, mpi_sort: str = None, verbose: bool = False, + use_cupy: bool = False, ): self._particles = particles - self._kernel = kernel + self._kernel = Pyccelkernel(kernel, use_cupy=use_cupy) self._newton = "newton" in kernel.__name__ self._args_kernel = args_kernel self._args_domain = args_domain @@ -278,7 +280,7 @@ def __call__(self, dt: float): ) # push markers - with ProfileManager.profile_region("kernel: " + self.kernel.__name__): + with ProfileManager.profile_region("kernel: " + self.kernel.name): self.kernel( dt, stage, diff --git a/src/struphy/utils/pyccel.py b/src/struphy/utils/pyccel.py new file mode 100644 index 000000000..5e62426a3 --- /dev/null +++ b/src/struphy/utils/pyccel.py @@ -0,0 +1,25 @@ +from typing import Any, Callable + + +class Pyccelkernel: + def __init__(self, kernel: Callable[..., Any], use_cupy: bool = False) -> None: + self._kernel = kernel + self._use_cupy = use_cupy + + def __call__(self, *args: Any, **kwargs: Any) -> Any: + if self.use_cupy: + raise NotImplementedError + else: + return self._kernel(*args, **kwargs) + + @property + def name(self): + return self.kernel.__name__ + + @property + def kernel(self) -> Callable[..., Any]: + return self._kernel + + @property + def use_cupy(self): + return self._use_cupy From 45f34483f3c5e28163b600374e2fb2ba1165092e Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 1 Oct 2025 18:00:19 +0200 Subject: [PATCH 02/76] kernel = ... --> kernel = Pyccelkernel(... --- src/struphy/feec/basis_projection_ops.py | 4 +- src/struphy/feec/mass.py | 15 ++++--- .../pic/accumulation/particles_to_grid.py | 11 +---- src/struphy/pic/base.py | 10 ++--- src/struphy/pic/pushing/pusher.py | 3 +- .../propagators/propagators_coupling.py | 16 +++---- .../propagators/propagators_markers.py | 43 ++++++++++--------- 7 files changed, 48 insertions(+), 54 deletions(-) diff --git a/src/struphy/feec/basis_projection_ops.py b/src/struphy/feec/basis_projection_ops.py index b335edea5..0066422cc 100644 --- a/src/struphy/feec/basis_projection_ops.py +++ b/src/struphy/feec/basis_projection_ops.py @@ -2038,10 +2038,10 @@ def assemble(self, weights=None, verbose=False): ) dofs_mat = self._dof_mat[i, j] - kernel = getattr( + kernel = Pyccelkernel(getattr( basis_projection_kernels, "assemble_dofs_for_weighted_basisfuns_" + str(V.ldim) + "d", - ) + )) if rank == 0 and verbose: print(f"Assemble block {i, j}") diff --git a/src/struphy/feec/mass.py b/src/struphy/feec/mass.py index 9d5531e98..27800c91e 100644 --- a/src/struphy/feec/mass.py +++ b/src/struphy/feec/mass.py @@ -15,6 +15,7 @@ from struphy.feec.utilities import RotationMatrix from struphy.geometry.base import Domain from struphy.polar.linear_operators import PolarExtractionOperator +from struphy.utils.pyccel import Pyccelkernel class WeightedMassOperators: @@ -2374,10 +2375,10 @@ def __init__( # load assembly kernel if not self._matrix_free: - self._assembly_kernel = getattr( + self._assembly_kernel = Pyccelkernel(getattr( mass_kernels, "kernel_" + str(self._V.ldim) + "d_mat", - ) + )) @property def derham(self): @@ -2954,7 +2955,7 @@ def eval_quad(W, coeffs, out=None): assert isinstance(out, (list, tuple)) # load assembly kernel - kernel = getattr(mass_kernels, "kernel_" + str(W.ldim) + "d_eval") + kernel = Pyccelkernel(getattr(mass_kernels, "kernel_" + str(W.ldim) + "d_eval")) # loop over components for a, wspace in enumerate(Wspaces): @@ -3049,15 +3050,15 @@ def __init__(self, derham, V, W, weights=None, nquads=None): self._nquads = nquads self._dtype = V.coeff_space.dtype - self._dot_kernel = getattr( + self._dot_kernel = Pyccelkernel(getattr( mass_kernels, "kernel_" + str(self._V.ldim) + "d_matrixfree", - ) + )) - self._diag_kernel = getattr( + self._diag_kernel = Pyccelkernel(getattr( mass_kernels, "kernel_" + str(self._V.ldim) + "d_diag", - ) + )) shape = tuple(e - s + 1 for s, e in zip(V.coeff_space.starts, V.coeff_space.ends)) self._diag_tmp = np.zeros((shape)) diff --git a/src/struphy/pic/accumulation/particles_to_grid.py b/src/struphy/pic/accumulation/particles_to_grid.py index 1fcaf54d3..49ca45e84 100644 --- a/src/struphy/pic/accumulation/particles_to_grid.py +++ b/src/struphy/pic/accumulation/particles_to_grid.py @@ -70,9 +70,6 @@ class Accumulator: filter_params : dict Params for the accumulation filter: use_filter(string, either `three_point or `fourier), repeat(int), alpha(float) and modes(list with int). - use_cupy : bool - Use cupy arrays - Note ---- Struphy accumulation kernels called by ``Accumulator`` objects must be added to ``struphy/pic/accumulation/accum_kernels.py`` @@ -96,11 +93,10 @@ def __init__( "repeat": None, "alpha": None, }, - use_cupy: bool = False, ): self._particles = particles self._space_id = space_id - self._kernel = Pyccelkernel(kernel, use_cupy=use_cupy) + self._kernel = Pyccelkernel(kernel) self._derham = mass_ops.derham self._args_domain = args_domain @@ -530,8 +526,6 @@ class AccumulatorVector: args_domain : DomainArguments Mapping infos. - use_cupy : bool - Use cupy arrays """ def __init__( @@ -541,11 +535,10 @@ def __init__( kernel: Callable[..., Any], mass_ops: WeightedMassOperators, args_domain: DomainArguments, - use_cupy: bool = False, ): self._particles = particles self._space_id = space_id - self._kernel = Pyccelkernel(kernel, use_cupy=use_cupy) + self._kernel = Pyccelkernel(kernel) self._derham = mass_ops.derham self._args_domain = args_domain diff --git a/src/struphy/pic/base.py b/src/struphy/pic/base.py index 1c3803c68..3702fef3b 100644 --- a/src/struphy/pic/base.py +++ b/src/struphy/pic/base.py @@ -39,7 +39,7 @@ ) from struphy.utils import utils from struphy.utils.clone_config import CloneConfig - +from struphy.utils.pyccel import Pyccelkernel class Particles(metaclass=ABCMeta): r""" @@ -3736,7 +3736,7 @@ def eval_sph( self.put_particles_in_boxes() if len(_shp) == 1: - func = box_based_evaluation_flat + func = Pyccelkernel(box_based_evaluation_flat) elif len(_shp) == 3: if _shp[0] > 1: assert eta1[0, 0, 0] != eta1[1, 0, 0], "Meshgrids must be obtained with indexing='ij'!" @@ -3744,7 +3744,7 @@ def eval_sph( assert eta2[0, 0, 0] != eta2[0, 1, 0], "Meshgrids must be obtained with indexing='ij'!" if _shp[2] > 1: assert eta3[0, 0, 0] != eta3[0, 0, 1], "Meshgrids must be obtained with indexing='ij'!" - func = box_based_evaluation_meshgrid + func = Pyccelkernel(box_based_evaluation_meshgrid) func( self.args_markers, @@ -3770,9 +3770,9 @@ def eval_sph( ) else: if len(_shp) == 1: - func = naive_evaluation_flat + func = Pyccelkernel(naive_evaluation_flat) elif len(_shp) == 3: - func = naive_evaluation_meshgrid + func = Pyccelkernel(naive_evaluation_meshgrid) func( self.args_markers, eta1, diff --git a/src/struphy/pic/pushing/pusher.py b/src/struphy/pic/pushing/pusher.py index 5010986f1..131fd8ad0 100644 --- a/src/struphy/pic/pushing/pusher.py +++ b/src/struphy/pic/pushing/pusher.py @@ -110,10 +110,9 @@ def __init__( tol: float = 1.0e-8, mpi_sort: str = None, verbose: bool = False, - use_cupy: bool = False, ): self._particles = particles - self._kernel = Pyccelkernel(kernel, use_cupy=use_cupy) + self._kernel = Pyccelkernel(kernel) self._newton = "newton" in kernel.__name__ self._args_kernel = args_kernel self._args_domain = args_domain diff --git a/src/struphy/propagators/propagators_coupling.py b/src/struphy/propagators/propagators_coupling.py index f7a38b5ac..5504f87ba 100644 --- a/src/struphy/propagators/propagators_coupling.py +++ b/src/struphy/propagators/propagators_coupling.py @@ -917,11 +917,11 @@ def __init__( # load particle pusher kernel if u_space == "Hcurl": - kernel = pusher_kernels.push_bxu_Hcurl + kernel = Pyccelkernel(pusher_kernels.push_bxu_Hcurl) elif u_space == "Hdiv": - kernel = pusher_kernels.push_bxu_Hdiv + kernel = Pyccelkernel(pusher_kernels.push_bxu_Hdiv) elif u_space == "H1vec": - kernel = pusher_kernels.push_bxu_H1vec + kernel = Pyccelkernel(pusher_kernels.push_bxu_H1vec) else: raise ValueError( f'{u_space = } not valid, choose from "Hcurl", "Hdiv" or "H1vec.', @@ -1210,11 +1210,11 @@ def __init__( ) if u_space == "Hcurl": - kernel = pusher_kernels_gc.push_gc_cc_J1_Hcurl + kernel = Pyccelkernel(pusher_kernels_gc.push_gc_cc_J1_Hcurl) elif u_space == "Hdiv": - kernel = pusher_kernels_gc.push_gc_cc_J1_Hdiv + kernel = Pyccelkernel(pusher_kernels_gc.push_gc_cc_J1_Hdiv) elif u_space == "H1vec": - kernel = pusher_kernels_gc.push_gc_cc_J1_H1vec + kernel = Pyccelkernel(pusher_kernels_gc.push_gc_cc_J1_H1vec) else: raise ValueError( f'{u_space = } not valid, choose from "Hcurl", "Hdiv" or "H1vec.', @@ -1666,9 +1666,9 @@ def __init__( # instantiate Pusher if u_space == "Hdiv": - kernel = pusher_kernels_gc.push_gc_cc_J2_stage_Hdiv + kernel = Pyccelkernel(pusher_kernels_gc.push_gc_cc_J2_stage_Hdiv) elif u_space == "H1vec": - kernel = pusher_kernels_gc.push_gc_cc_J2_stage_H1vec + kernel = Pyccelkernel(pusher_kernels_gc.push_gc_cc_J2_stage_H1vec) else: raise ValueError( f'{u_space = } not valid, choose from "Hdiv" or "H1vec.', diff --git a/src/struphy/propagators/propagators_markers.py b/src/struphy/propagators/propagators_markers.py index f91d3df89..869fea784 100644 --- a/src/struphy/propagators/propagators_markers.py +++ b/src/struphy/propagators/propagators_markers.py @@ -17,6 +17,7 @@ from struphy.pic.pushing.pusher import Pusher from struphy.polar.basic import PolarVector from struphy.propagators.base import Propagator +from struphy.utils.pyccel import Pyccelkernel class PushEta(Propagator): @@ -67,7 +68,7 @@ def __init__( super().__init__(particles) # get kernel - kernel = pusher_kernels.push_eta_stage + kernel = Pyccelkernel(pusher_kernels.push_eta_stage) # define algorithm butcher = ButcherTableau(algo) @@ -168,9 +169,9 @@ def __init__( # define pusher kernel if algo == "analytic": - kernel = pusher_kernels.push_vxb_analytic + kernel = Pyccelkernel(pusher_kernels.push_vxb_analytic) elif algo == "implicit": - kernel = pusher_kernels.push_vxb_implicit + kernel = Pyccelkernel(pusher_kernels.push_vxb_implicit) else: raise ValueError(f"{algo = } not supported.") @@ -324,22 +325,22 @@ def __init__( # call Pusher class if use_perp_model: if u_space == "Hcurl": - kernel = pusher_kernels.push_pc_eta_rk4_Hcurl + kernel = Pyccelkernel(pusher_kernels.push_pc_eta_rk4_Hcurl) elif u_space == "Hdiv": - kernel = pusher_kernels.push_pc_eta_rk4_Hdiv + kernel = Pyccelkernel(pusher_kernels.push_pc_eta_rk4_Hdiv) elif u_space == "H1vec": - kernel = pusher_kernels.push_pc_eta_rk4_H1vec + kernel = Pyccelkernel(pusher_kernels.push_pc_eta_rk4_H1vec) else: raise ValueError( f'{u_space = } not valid, choose from "Hcurl", "Hdiv" or "H1vec.', ) else: if u_space == "Hcurl": - kernel = pusher_kernels.push_pc_eta_rk4_Hcurl_full + kernel = Pyccelkernel(pusher_kernels.push_pc_eta_rk4_Hcurl_full) elif u_space == "Hdiv": - kernel = pusher_kernels.push_pc_eta_rk4_Hdiv_full + kernel = Pyccelkernel(pusher_kernels.push_pc_eta_rk4_Hdiv_full) elif u_space == "H1vec": - kernel = pusher_kernels.push_pc_eta_rk4_H1vec_full + kernel = Pyccelkernel(pusher_kernels.push_pc_eta_rk4_H1vec_full) else: raise ValueError( f'{u_space = } not valid, choose from "Hcurl", "Hdiv" or "H1vec.', @@ -590,7 +591,7 @@ def __init__( ) # pusher kernel - kernel = pusher_kernels_gc.push_gc_bxEstar_discrete_gradient_1st_order_newton + kernel = Pyccelkernel(pusher_kernels_gc.push_gc_bxEstar_discrete_gradient_1st_order_newton) alpha_in_kernel = 1.0 # evaluate at eta^{n+1,k} and save args_kernel = ( @@ -624,7 +625,7 @@ def __init__( ) # evaluate at eta^{n+1,k} and save # pusher kernel - kernel = pusher_kernels_gc.push_gc_bxEstar_discrete_gradient_1st_order + kernel = Pyccelkernel(pusher_kernels_gc.push_gc_bxEstar_discrete_gradient_1st_order) alpha_in_kernel = 0.5 # evaluate at mid-point args_kernel = ( @@ -670,7 +671,7 @@ def __init__( ) # evaluate at eta^{n+1,k} and save) # pusher kernel - kernel = pusher_kernels_gc.push_gc_bxEstar_discrete_gradient_2nd_order + kernel = Pyccelkernel(pusher_kernels_gc.push_gc_bxEstar_discrete_gradient_2nd_order) alpha_in_kernel = 0.5 # evaluate at mid-point args_kernel = ( @@ -718,7 +719,7 @@ def __init__( butcher._a = np.diag(butcher.a, k=-1) butcher._a = np.array(list(butcher.a) + [0.0]) - kernel = pusher_kernels_gc.push_gc_bxEstar_explicit_multistage + kernel = Pyccelkernel(pusher_kernels_gc.push_gc_bxEstar_explicit_multistage) args_kernel = ( self.derham.args_derham, @@ -1007,7 +1008,7 @@ def __init__( ) # pusher kernel - kernel = pusher_kernels_gc.push_gc_Bstar_discrete_gradient_1st_order_newton + kernel = Pyccelkernel(pusher_kernels_gc.push_gc_Bstar_discrete_gradient_1st_order_newton) alpha_in_kernel = 1.0 # evaluate at eta^{n+1,k} and save args_kernel = ( @@ -1040,7 +1041,7 @@ def __init__( ) # evaluate at Z^{n+1,k} and save # pusher kernel - kernel = pusher_kernels_gc.push_gc_Bstar_discrete_gradient_1st_order + kernel = Pyccelkernel(pusher_kernels_gc.push_gc_Bstar_discrete_gradient_1st_order) alpha_in_kernel = 0.5 # evaluate at mid-point args_kernel = ( @@ -1086,7 +1087,7 @@ def __init__( ) # evaluate at Z^{n+1,k} and save # pusher kernel - kernel = pusher_kernels_gc.push_gc_Bstar_discrete_gradient_2nd_order + kernel = Pyccelkernel(pusher_kernels_gc.push_gc_Bstar_discrete_gradient_2nd_order) alpha_in_kernel = 0.5 # evaluate at mid-point args_kernel = ( @@ -1137,7 +1138,7 @@ def __init__( butcher._a = np.diag(butcher.a, k=-1) butcher._a = np.array(list(butcher.a) + [0.0]) - kernel = pusher_kernels_gc.push_gc_Bstar_explicit_multistage + kernel = Pyccelkernel(pusher_kernels_gc.push_gc_Bstar_explicit_multistage) args_kernel = ( self.derham.args_derham, @@ -1538,7 +1539,7 @@ def __init__( super().__init__(particles) # init kernel for evaluating density etc. before each time step. - init_kernel = eval_kernels_gc.sph_pressure_coeffs + init_kernel = Pyccelkernel(eval_kernels_gc.sph_pressure_coeffs) first_free_idx = particles.args_markers.first_free_idx comps = (0, 1, 2) @@ -1573,9 +1574,9 @@ def __init__( # pusher kernel if thermodynamics == "isothermal": - kernel = pusher_kernels.push_v_sph_pressure + kernel = Pyccelkernel(pusher_kernels.push_v_sph_pressure) elif thermodynamics == "polytropic": - kernel = pusher_kernels.push_v_sph_pressure_ideal_gas + kernel = Pyccelkernel(pusher_kernels.push_v_sph_pressure_ideal_gas) gravity = np.array(gravity, dtype=float) @@ -1709,7 +1710,7 @@ def __init__( args_init, ) - kernel = pusher_kernels.push_v_viscosity + kernel = Pyccelkernel(pusher_kernels.push_v_viscosity) args_kernel = ( boxes, From e34cd374ada38469bc44939ef09001e23bd530a9 Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 1 Oct 2025 18:03:19 +0200 Subject: [PATCH 03/76] Pass Pyccelkernel directly --- src/struphy/pic/accumulation/particles_to_grid.py | 4 ++-- src/struphy/pic/pushing/pusher.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/struphy/pic/accumulation/particles_to_grid.py b/src/struphy/pic/accumulation/particles_to_grid.py index 49ca45e84..87b5677a9 100644 --- a/src/struphy/pic/accumulation/particles_to_grid.py +++ b/src/struphy/pic/accumulation/particles_to_grid.py @@ -81,7 +81,7 @@ def __init__( self, particles: Particles, space_id: str, - kernel: Callable[..., Any], + kernel: Pyccelkernel, mass_ops: WeightedMassOperators, args_domain: DomainArguments, *, @@ -96,7 +96,7 @@ def __init__( ): self._particles = particles self._space_id = space_id - self._kernel = Pyccelkernel(kernel) + self._kernel = kernel self._derham = mass_ops.derham self._args_domain = args_domain diff --git a/src/struphy/pic/pushing/pusher.py b/src/struphy/pic/pushing/pusher.py index 131fd8ad0..935e010fd 100644 --- a/src/struphy/pic/pushing/pusher.py +++ b/src/struphy/pic/pushing/pusher.py @@ -98,7 +98,7 @@ class Pusher: def __init__( self, particles: Particles, - kernel, + kernel: Pyccelkernel, args_kernel: tuple, args_domain: DomainArguments, *, @@ -112,8 +112,8 @@ def __init__( verbose: bool = False, ): self._particles = particles - self._kernel = Pyccelkernel(kernel) - self._newton = "newton" in kernel.__name__ + self._kernel = kernel + self._newton = "newton" in kernel.name self._args_kernel = args_kernel self._args_domain = args_domain From 8fd08ba5e43a2ad9e738a5e482aee46931d3698f Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 1 Oct 2025 18:03:33 +0200 Subject: [PATCH 04/76] Formatting --- src/struphy/feec/basis_projection_ops.py | 10 +++++--- src/struphy/feec/mass.py | 32 ++++++++++++++---------- src/struphy/pic/base.py | 1 + 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/src/struphy/feec/basis_projection_ops.py b/src/struphy/feec/basis_projection_ops.py index 0066422cc..a66c69355 100644 --- a/src/struphy/feec/basis_projection_ops.py +++ b/src/struphy/feec/basis_projection_ops.py @@ -2038,10 +2038,12 @@ def assemble(self, weights=None, verbose=False): ) dofs_mat = self._dof_mat[i, j] - kernel = Pyccelkernel(getattr( - basis_projection_kernels, - "assemble_dofs_for_weighted_basisfuns_" + str(V.ldim) + "d", - )) + kernel = Pyccelkernel( + getattr( + basis_projection_kernels, + "assemble_dofs_for_weighted_basisfuns_" + str(V.ldim) + "d", + ) + ) if rank == 0 and verbose: print(f"Assemble block {i, j}") diff --git a/src/struphy/feec/mass.py b/src/struphy/feec/mass.py index 27800c91e..1b0e14734 100644 --- a/src/struphy/feec/mass.py +++ b/src/struphy/feec/mass.py @@ -2375,10 +2375,12 @@ def __init__( # load assembly kernel if not self._matrix_free: - self._assembly_kernel = Pyccelkernel(getattr( - mass_kernels, - "kernel_" + str(self._V.ldim) + "d_mat", - )) + self._assembly_kernel = Pyccelkernel( + getattr( + mass_kernels, + "kernel_" + str(self._V.ldim) + "d_mat", + ) + ) @property def derham(self): @@ -3050,15 +3052,19 @@ def __init__(self, derham, V, W, weights=None, nquads=None): self._nquads = nquads self._dtype = V.coeff_space.dtype - self._dot_kernel = Pyccelkernel(getattr( - mass_kernels, - "kernel_" + str(self._V.ldim) + "d_matrixfree", - )) - - self._diag_kernel = Pyccelkernel(getattr( - mass_kernels, - "kernel_" + str(self._V.ldim) + "d_diag", - )) + self._dot_kernel = Pyccelkernel( + getattr( + mass_kernels, + "kernel_" + str(self._V.ldim) + "d_matrixfree", + ) + ) + + self._diag_kernel = Pyccelkernel( + getattr( + mass_kernels, + "kernel_" + str(self._V.ldim) + "d_diag", + ) + ) shape = tuple(e - s + 1 for s, e in zip(V.coeff_space.starts, V.coeff_space.ends)) self._diag_tmp = np.zeros((shape)) diff --git a/src/struphy/pic/base.py b/src/struphy/pic/base.py index 3702fef3b..d40615dcf 100644 --- a/src/struphy/pic/base.py +++ b/src/struphy/pic/base.py @@ -41,6 +41,7 @@ from struphy.utils.clone_config import CloneConfig from struphy.utils.pyccel import Pyccelkernel + class Particles(metaclass=ABCMeta): r""" Base class for particle species. From ee367da8b4ab66ad12f038c879a658d9f1b0fac3 Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 1 Oct 2025 18:06:05 +0200 Subject: [PATCH 05/76] Added missing imports --- src/struphy/feec/basis_projection_ops.py | 1 + src/struphy/propagators/propagators_coupling.py | 1 + 2 files changed, 2 insertions(+) diff --git a/src/struphy/feec/basis_projection_ops.py b/src/struphy/feec/basis_projection_ops.py index a66c69355..daa6f679a 100644 --- a/src/struphy/feec/basis_projection_ops.py +++ b/src/struphy/feec/basis_projection_ops.py @@ -15,6 +15,7 @@ from struphy.feec.utilities import RotationMatrix from struphy.polar.basic import PolarDerhamSpace, PolarVector from struphy.polar.linear_operators import PolarExtractionOperator +from struphy.utils.pyccel import Pyccelkernel class BasisProjectionOperators: diff --git a/src/struphy/propagators/propagators_coupling.py b/src/struphy/propagators/propagators_coupling.py index 5504f87ba..c253a8481 100644 --- a/src/struphy/propagators/propagators_coupling.py +++ b/src/struphy/propagators/propagators_coupling.py @@ -17,6 +17,7 @@ from struphy.pic.pushing.pusher import Pusher from struphy.polar.basic import PolarVector from struphy.propagators.base import Propagator +from struphy.utils.pyccel import Pyccelkernel class VlasovAmpere(Propagator): From 39fc9fdd206b3b3eb385f4325bbf20ca0174ea27 Mon Sep 17 00:00:00 2001 From: Max Lindqvist Date: Thu, 2 Oct 2025 08:01:55 +0200 Subject: [PATCH 06/76] Fix try except case which doesn't cover the parent directory not existing --- src/struphy/post_processing/pproc_struphy.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/struphy/post_processing/pproc_struphy.py b/src/struphy/post_processing/pproc_struphy.py index 67059d648..f49c3d357 100644 --- a/src/struphy/post_processing/pproc_struphy.py +++ b/src/struphy/post_processing/pproc_struphy.py @@ -54,11 +54,12 @@ def main( # create post-processing folder path_pproc = os.path.join(path, "post_processing") - try: - os.mkdir(path_pproc) - except: + # Ensure parent exists + os.makedirs(path, exist_ok=True) + + if os.path.exists(path_pproc): shutil.rmtree(path_pproc) - os.mkdir(path_pproc) + os.mkdir(path_pproc) # check for fields and kinetic data in hdf5 file that need post processing file = h5py.File(os.path.join(path, "data/", "data_proc0.hdf5"), "r") From 753433cc11cef9ee18a2f9bf14dc488d2694007f Mon Sep 17 00:00:00 2001 From: Max Lindqvist Date: Thu, 2 Oct 2025 08:03:12 +0200 Subject: [PATCH 07/76] Simplified the dir creation --- src/struphy/post_processing/pproc_struphy.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/struphy/post_processing/pproc_struphy.py b/src/struphy/post_processing/pproc_struphy.py index f49c3d357..a97892a5e 100644 --- a/src/struphy/post_processing/pproc_struphy.py +++ b/src/struphy/post_processing/pproc_struphy.py @@ -54,12 +54,7 @@ def main( # create post-processing folder path_pproc = os.path.join(path, "post_processing") - # Ensure parent exists - os.makedirs(path, exist_ok=True) - - if os.path.exists(path_pproc): - shutil.rmtree(path_pproc) - os.mkdir(path_pproc) + os.makedirs(path_pproc, exist_ok=True) # check for fields and kinetic data in hdf5 file that need post processing file = h5py.File(os.path.join(path, "data/", "data_proc0.hdf5"), "r") From 0392cb0af25d5405994c98aacae314daa67b9012 Mon Sep 17 00:00:00 2001 From: Max Lindqvist Date: Thu, 2 Oct 2025 09:14:11 +0200 Subject: [PATCH 08/76] Added Pyccelkernel around some pusher kernels --- src/struphy/models/base.py | 2 +- src/struphy/propagators/propagators_coupling.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/struphy/models/base.py b/src/struphy/models/base.py index af10c5180..be5cd73e8 100644 --- a/src/struphy/models/base.py +++ b/src/struphy/models/base.py @@ -1850,7 +1850,7 @@ def _allocate_variables(self): domain_decomp = (domain_array, nprocs) kinetic_class = getattr(particles, val["space"]) - print(f"{kinetic_class = }") + # print(f"{kinetic_class = }") val["obj"] = kinetic_class( comm_world=self.comm_world, clone_config=self.clone_config, diff --git a/src/struphy/propagators/propagators_coupling.py b/src/struphy/propagators/propagators_coupling.py index c253a8481..1b22ee436 100644 --- a/src/struphy/propagators/propagators_coupling.py +++ b/src/struphy/propagators/propagators_coupling.py @@ -160,7 +160,7 @@ def __init__( self._pusher = Pusher( particles, - pusher_kernels.push_v_with_efield, + Pyccelkernel(pusher_kernels.push_v_with_efield), args_kernel, self.domain.args_domain, alpha_in_kernel=1.0, @@ -385,7 +385,7 @@ def __init__( self._pusher = Pusher( particles, - pusher_kernels.push_weights_with_efield_lin_va, + Pyccelkernel(pusher_kernels.push_weights_with_efield_lin_va), args_kernel, self.domain.args_domain, alpha_in_kernel=1.0, @@ -555,10 +555,10 @@ def __init__( # Call the accumulation and Pusher class if use_perp_model: accum_ker = accum_kernels.pc_lin_mhd_6d - pusher_ker = pusher_kernels.push_pc_GXu + pusher_ker = Pyccelkernel(pusher_kernels.push_pc_GXu) else: accum_ker = accum_kernels.pc_lin_mhd_6d_full - pusher_ker = pusher_kernels.push_pc_GXu_full + pusher_ker = Pyccelkernel(pusher_kernels.push_pc_GXu_full) self._coupling_mat = coupling_params["Ah"] / coupling_params["Ab"] self._coupling_vec = coupling_params["Ah"] / coupling_params["Ab"] From 644c3db751810e0c98e182519a730576fdc436d7 Mon Sep 17 00:00:00 2001 From: Max Lindqvist Date: Thu, 2 Oct 2025 09:32:42 +0200 Subject: [PATCH 09/76] Added Pyccelkernel for Accumulatorvector argument --- src/struphy/models/hybrid.py | 3 ++- src/struphy/models/kinetic.py | 9 +++++---- src/struphy/pic/accumulation/particles_to_grid.py | 5 +++-- src/struphy/pic/tests/test_accum_vec_H1.py | 4 +++- src/struphy/propagators/propagators_markers.py | 2 +- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/struphy/models/hybrid.py b/src/struphy/models/hybrid.py index 76afea648..5886fdc30 100644 --- a/src/struphy/models/hybrid.py +++ b/src/struphy/models/hybrid.py @@ -3,6 +3,7 @@ from struphy.models.base import StruphyModel from struphy.pic.accumulation import accum_kernels, accum_kernels_gc from struphy.propagators import propagators_coupling, propagators_fields, propagators_markers +from struphy.utils.pyccel import Pyccelkernel class LinearMHDVlasovCC(StruphyModel): @@ -1152,7 +1153,7 @@ def initialize_from_params(self): charge_accum = AccumulatorVector( self.pointer["hot_electrons"], "H1", - accum_kernels.vlasov_maxwell_poisson, + Pyccelkernel(accum_kernels.vlasov_maxwell_poisson), self.mass_ops, self.domain.args_domain, ) diff --git a/src/struphy/models/kinetic.py b/src/struphy/models/kinetic.py index 9964e72ad..bedf6b2fc 100644 --- a/src/struphy/models/kinetic.py +++ b/src/struphy/models/kinetic.py @@ -4,6 +4,7 @@ from struphy.models.base import StruphyModel from struphy.pic.accumulation import accum_kernels, accum_kernels_gc from struphy.propagators import propagators_coupling, propagators_fields, propagators_markers +from struphy.utils.pyccel import Pyccelkernel class VlasovAmpereOneSpecies(StruphyModel): @@ -224,7 +225,7 @@ def initialize_from_params(self): charge_accum = AccumulatorVector( self.pointer["species1"], "H1", - accum_kernels.charge_density_0form, + Pyccelkernel(accum_kernels.charge_density_0form), self.mass_ops, self.domain.args_domain, ) @@ -505,7 +506,7 @@ def initialize_from_params(self): charge_accum = AccumulatorVector( self.pointer["species1"], "H1", - accum_kernels.charge_density_0form, + Pyccelkernel(accum_kernels.charge_density_0form), self.mass_ops, self.domain.args_domain, ) @@ -826,7 +827,7 @@ def initialize_from_params(self): charge_accum = AccumulatorVector( self.pointer["species1"], "H1", - accum_kernels.charge_density_0form, + Pyccelkernel(accum_kernels.charge_density_0form), self.mass_ops, self.domain.args_domain, ) @@ -1143,7 +1144,7 @@ def __init__(self, params, comm, clone_config=None): charge_accum = AccumulatorVector( self.pointer["ions"], "H1", - accum_kernels_gc.gc_density_0form, + Pyccelkernel(accum_kernels_gc.gc_density_0form), self.mass_ops, self.domain.args_domain, ) diff --git a/src/struphy/pic/accumulation/particles_to_grid.py b/src/struphy/pic/accumulation/particles_to_grid.py index 87b5677a9..bba950dab 100644 --- a/src/struphy/pic/accumulation/particles_to_grid.py +++ b/src/struphy/pic/accumulation/particles_to_grid.py @@ -532,13 +532,14 @@ def __init__( self, particles: Particles, space_id: str, - kernel: Callable[..., Any], + kernel: Pyccelkernel, mass_ops: WeightedMassOperators, args_domain: DomainArguments, ): self._particles = particles self._space_id = space_id - self._kernel = Pyccelkernel(kernel) + assert isinstance(kernel, Pyccelkernel), f"{kernel} is not of type Pyccelkernel" + self._kernel = kernel self._derham = mass_ops.derham self._args_domain = args_domain diff --git a/src/struphy/pic/tests/test_accum_vec_H1.py b/src/struphy/pic/tests/test_accum_vec_H1.py index 6d1e90208..98b037018 100644 --- a/src/struphy/pic/tests/test_accum_vec_H1.py +++ b/src/struphy/pic/tests/test_accum_vec_H1.py @@ -1,5 +1,7 @@ import pytest +from struphy.utils.pyccel import Pyccelkernel + @pytest.mark.mpi(min_size=2) @pytest.mark.parametrize("Nel", [[8, 9, 10]]) @@ -127,7 +129,7 @@ def test_accum_poisson(Nel, p, spl_kind, mapping, num_clones, Np=1000): acc = AccumulatorVector( particles, "H1", - accum_kernels.charge_density_0form, + Pyccelkernel(accum_kernels.charge_density_0form), mass_ops, domain.args_domain, ) diff --git a/src/struphy/propagators/propagators_markers.py b/src/struphy/propagators/propagators_markers.py index 869fea784..3580f4908 100644 --- a/src/struphy/propagators/propagators_markers.py +++ b/src/struphy/propagators/propagators_markers.py @@ -1351,7 +1351,7 @@ def __init__( self._u_on_grid = AccumulatorVector( particles, "H1", - accum_kernels.charge_density_0form, + Pyccelkernel(accum_kernels.charge_density_0form), self.mass_ops, self.domain.args_domain, ) From 10251e095bdbec63aad1810e6246b62b30381ee8 Mon Sep 17 00:00:00 2001 From: Max Lindqvist Date: Thu, 2 Oct 2025 09:41:16 +0200 Subject: [PATCH 10/76] Added Pyccelkernel to more places --- src/struphy/pic/accumulation/particles_to_grid.py | 1 + src/struphy/pic/tests/test_accumulation.py | 4 +++- src/struphy/propagators/propagators_coupling.py | 14 +++++++------- src/struphy/propagators/propagators_fields.py | 9 +++++---- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/struphy/pic/accumulation/particles_to_grid.py b/src/struphy/pic/accumulation/particles_to_grid.py index bba950dab..fd351abce 100644 --- a/src/struphy/pic/accumulation/particles_to_grid.py +++ b/src/struphy/pic/accumulation/particles_to_grid.py @@ -96,6 +96,7 @@ def __init__( ): self._particles = particles self._space_id = space_id + assert isinstance(kernel, Pyccelkernel), f"{kernel} is not of type Pyccelkernel" self._kernel = kernel self._derham = mass_ops.derham self._args_domain = args_domain diff --git a/src/struphy/pic/tests/test_accumulation.py b/src/struphy/pic/tests/test_accumulation.py index d7c5ac32b..7df1df471 100644 --- a/src/struphy/pic/tests/test_accumulation.py +++ b/src/struphy/pic/tests/test_accumulation.py @@ -1,5 +1,7 @@ import pytest +from struphy.utils.pyccel import Pyccelkernel + @pytest.mark.mpi(min_size=2) @pytest.mark.parametrize("Nel", [[8, 9, 10]]) @@ -230,7 +232,7 @@ def pc_lin_mhd_6d_step_ph_full(Nel, p, spl_kind, mapping, Np, verbose=False): ACC = Accumulator( particles, "Hcurl", - accum_kernels.pc_lin_mhd_6d_full, + Pyccelkernel(accum_kernels.pc_lin_mhd_6d_full), mass_ops, domain.args_domain, add_vector=True, diff --git a/src/struphy/propagators/propagators_coupling.py b/src/struphy/propagators/propagators_coupling.py index 1b22ee436..9843cd711 100644 --- a/src/struphy/propagators/propagators_coupling.py +++ b/src/struphy/propagators/propagators_coupling.py @@ -105,7 +105,7 @@ def __init__( self._info = solver["info"] # get accumulation kernel - accum_kernel = accum_kernels.vlasov_maxwell + accum_kernel = Pyccelkernel(accum_kernels.vlasov_maxwell) # Initialize Accumulator object self._accum = Accumulator( @@ -330,7 +330,7 @@ def __init__( self._accum = Accumulator( particles, "Hcurl", - accum_kernels.linear_vlasov_ampere, + Pyccelkernel(accum_kernels.linear_vlasov_ampere), self.mass_ops, self.domain.args_domain, add_vector=True, @@ -554,10 +554,10 @@ def __init__( # Call the accumulation and Pusher class if use_perp_model: - accum_ker = accum_kernels.pc_lin_mhd_6d + accum_ker = Pyccelkernel(accum_kernels.pc_lin_mhd_6d) pusher_ker = Pyccelkernel(pusher_kernels.push_pc_GXu) else: - accum_ker = accum_kernels.pc_lin_mhd_6d_full + accum_ker = Pyccelkernel(accum_kernels.pc_lin_mhd_6d_full) pusher_ker = Pyccelkernel(pusher_kernels.push_pc_GXu_full) self._coupling_mat = coupling_params["Ah"] / coupling_params["Ab"] @@ -859,7 +859,7 @@ def __init__( self._accumulator = Accumulator( particles, u_space, - accum_kernels.cc_lin_mhd_6d_2, + Pyccelkernel(accum_kernels.cc_lin_mhd_6d_2), self.mass_ops, self.domain.args_domain, add_vector=True, @@ -1202,7 +1202,7 @@ def __init__( self._ACC = Accumulator( particles, u_space, - accum_kernels_gc.cc_lin_mhd_5d_J1, + Pyccelkernel(accum_kernels_gc.cc_lin_mhd_5d_J1), self.mass_ops, self.domain.args_domain, add_vector=True, @@ -1564,7 +1564,7 @@ def __init__( self._ACC = Accumulator( particles, u_space, - accum_kernels_gc.cc_lin_mhd_5d_J2, + Pyccelkernel(accum_kernels_gc.cc_lin_mhd_5d_J2), self.mass_ops, self.domain.args_domain, add_vector=True, diff --git a/src/struphy/propagators/propagators_fields.py b/src/struphy/propagators/propagators_fields.py index f690b501d..46bf0990f 100644 --- a/src/struphy/propagators/propagators_fields.py +++ b/src/struphy/propagators/propagators_fields.py @@ -50,6 +50,7 @@ from struphy.pic.particles import Particles5D, Particles6D from struphy.polar.basic import PolarVector from struphy.propagators.base import Propagator +from struphy.utils.pyccel import Pyccelkernel class Maxwell(Propagator): @@ -1506,7 +1507,7 @@ def __init__( self._accumulator = Accumulator( particles, u_space, - accum_kernels.cc_lin_mhd_6d_1, + Pyccelkernel(accum_kernels.cc_lin_mhd_6d_1), self.mass_ops, self.domain.args_domain, add_vector=False, @@ -1724,7 +1725,7 @@ def __init__( self._ACC = Accumulator( particles, u_space, - accum_kernels_gc.cc_lin_mhd_5d_M, + Pyccelkernel(accum_kernels_gc.cc_lin_mhd_5d_M), self.mass_ops, self.domain.args_domain, add_vector=True, @@ -1975,7 +1976,7 @@ def __init__( self._ACC = Accumulator( particles, u_space, - accum_kernels_gc.cc_lin_mhd_5d_M, + Pyccelkernel(accum_kernels_gc.cc_lin_mhd_5d_M), self.mass_ops, self.domain.args_domain, add_vector=True, @@ -2320,7 +2321,7 @@ def __init__( self._accumulator = Accumulator( particles, u_space, - accum_kernels_gc.cc_lin_mhd_5d_D, + Pyccelkernel(accum_kernels_gc.cc_lin_mhd_5d_D), self.mass_ops, self.domain.args_domain, add_vector=False, From 3655a6eafcd888b8ba1270dc880ecdc44ed9349f Mon Sep 17 00:00:00 2001 From: Max Lindqvist Date: Thu, 2 Oct 2025 09:55:56 +0200 Subject: [PATCH 11/76] Added Pyccelkernel --- src/struphy/pic/pushing/pusher.py | 1 + src/struphy/propagators/propagators_markers.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/struphy/pic/pushing/pusher.py b/src/struphy/pic/pushing/pusher.py index 935e010fd..8c7588321 100644 --- a/src/struphy/pic/pushing/pusher.py +++ b/src/struphy/pic/pushing/pusher.py @@ -112,6 +112,7 @@ def __init__( verbose: bool = False, ): self._particles = particles + assert isinstance(kernel, Pyccelkernel), f"{kernel} is not of type Pyccelkernel" self._kernel = kernel self._newton = "newton" in kernel.name self._args_kernel = args_kernel diff --git a/src/struphy/propagators/propagators_markers.py b/src/struphy/propagators/propagators_markers.py index 3580f4908..647150788 100644 --- a/src/struphy/propagators/propagators_markers.py +++ b/src/struphy/propagators/propagators_markers.py @@ -1371,7 +1371,7 @@ def __init__( self._pusher = Pusher( particles, - pusher_kernels.push_deterministic_diffusion_stage, + Pyccelkernel(pusher_kernels.push_deterministic_diffusion_stage), args_kernel, self.domain.args_domain, alpha_in_kernel=1.0, From f1ffc13a4eced0e1206e15d63edc20c840528b3e Mon Sep 17 00:00:00 2001 From: Max Lindqvist Date: Thu, 2 Oct 2025 09:57:50 +0200 Subject: [PATCH 12/76] Added missing Pyccelkernel --- src/struphy/propagators/propagators_markers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/struphy/propagators/propagators_markers.py b/src/struphy/propagators/propagators_markers.py index 647150788..ea119f1ed 100644 --- a/src/struphy/propagators/propagators_markers.py +++ b/src/struphy/propagators/propagators_markers.py @@ -257,7 +257,7 @@ def __init__( self._pusher = Pusher( particles, - pusher_kernels.push_v_with_efield, + Pyccelkernel(pusher_kernels.push_v_with_efield), args_kernel, self.domain.args_domain, alpha_in_kernel=1.0, @@ -1462,7 +1462,7 @@ def __init__( self._pusher = Pusher( particles, - pusher_kernels.push_random_diffusion_stage, + Pyccelkernel(pusher_kernels.push_random_diffusion_stage), args_kernel, self.domain.args_domain, alpha_in_kernel=1.0, From cfe431a5dfe0b01726d1a2801bd26a0fbaf69f85 Mon Sep 17 00:00:00 2001 From: Max Lindqvist Date: Thu, 2 Oct 2025 10:39:42 +0200 Subject: [PATCH 13/76] Wrap with Pyccelkernel in tutorial --- doc/tutorials/tutorial_09_vlasov_maxwell.ipynb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/tutorials/tutorial_09_vlasov_maxwell.ipynb b/doc/tutorials/tutorial_09_vlasov_maxwell.ipynb index d95589a29..7628f8f20 100644 --- a/doc/tutorials/tutorial_09_vlasov_maxwell.ipynb +++ b/doc/tutorials/tutorial_09_vlasov_maxwell.ipynb @@ -244,12 +244,13 @@ "# accumulate charge density\n", "from struphy.pic.accumulation.particles_to_grid import AccumulatorVector\n", "from struphy.pic.accumulation.accum_kernels import charge_density_0form\n", + "from struphy.utils.pyccel import Pyccelkernel\n", "\n", "# instantiate\n", "charge_accum = AccumulatorVector(\n", " particles=particles,\n", " space_id='H1',\n", - " kernel=charge_density_0form,\n", + " kernel=Pyccelkernel(charge_density_0form),\n", " mass_ops=mass_ops,\n", " args_domain=domain.args_domain,\n", ")\n", From cf88d72ae92296aa976981236fe4c41d55408d56 Mon Sep 17 00:00:00 2001 From: Max Lindqvist Date: Thu, 2 Oct 2025 11:51:47 +0200 Subject: [PATCH 14/76] Restore src/struphy/post_processing/pproc_struphy.py to devel version --- src/struphy/post_processing/pproc_struphy.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/struphy/post_processing/pproc_struphy.py b/src/struphy/post_processing/pproc_struphy.py index a97892a5e..67059d648 100644 --- a/src/struphy/post_processing/pproc_struphy.py +++ b/src/struphy/post_processing/pproc_struphy.py @@ -54,7 +54,11 @@ def main( # create post-processing folder path_pproc = os.path.join(path, "post_processing") - os.makedirs(path_pproc, exist_ok=True) + try: + os.mkdir(path_pproc) + except: + shutil.rmtree(path_pproc) + os.mkdir(path_pproc) # check for fields and kinetic data in hdf5 file that need post processing file = h5py.File(os.path.join(path, "data/", "data_proc0.hdf5"), "r") From 57572acac8f6f923143aed3c7d20845eb1a6f0c0 Mon Sep 17 00:00:00 2001 From: Max Lindqvist Date: Thu, 2 Oct 2025 12:00:58 +0200 Subject: [PATCH 15/76] group=group --- src/struphy/console/test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/struphy/console/test.py b/src/struphy/console/test.py index b99f5e482..cf64a1649 100644 --- a/src/struphy/console/test.py +++ b/src/struphy/console/test.py @@ -183,4 +183,4 @@ def struphy_test( if not verification: from struphy.models.tests.test_xxpproc import test_pproc_codes - test_pproc_codes(group) + test_pproc_codes(group=group) From 0103e675dde207cf3b518a9cdd29ab5d728d11bd Mon Sep 17 00:00:00 2001 From: Max Lindqvist Date: Mon, 6 Oct 2025 15:48:43 +0200 Subject: [PATCH 16/76] Fixed src/struphy/pic/tests/test_pushers.py --- src/struphy/pic/tests/test_pushers.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/struphy/pic/tests/test_pushers.py b/src/struphy/pic/tests/test_pushers.py index 218d65f29..657d4d079 100644 --- a/src/struphy/pic/tests/test_pushers.py +++ b/src/struphy/pic/tests/test_pushers.py @@ -1,5 +1,5 @@ import pytest - +from struphy.utils.pyccel import Pyccelkernel @pytest.mark.mpi(min_size=2) @pytest.mark.parametrize("Nel", [[8, 9, 5], [7, 8, 9]]) @@ -113,7 +113,7 @@ def test_push_vxb_analytic(Nel, p, spl_kind, mapping, show_plots=False): pusher_psy = Pusher_psy( particles, - pusher_kernels.push_vxb_analytic, + Pyccelkernel(pusher_kernels.push_vxb_analytic), ( derham.args_derham, b2_eq_psy[0]._data + b2_psy[0]._data, @@ -257,7 +257,7 @@ def test_push_bxu_Hdiv(Nel, p, spl_kind, mapping, show_plots=False): pusher_psy = Pusher_psy( particles, - pusher_kernels.push_bxu_Hdiv, + Pyccelkernel(pusher_kernels.push_bxu_Hdiv), ( derham.args_derham, b2_eq_psy[0]._data + b2_psy[0]._data, @@ -405,7 +405,7 @@ def test_push_bxu_Hcurl(Nel, p, spl_kind, mapping, show_plots=False): pusher_psy = Pusher_psy( particles, - pusher_kernels.push_bxu_Hcurl, + Pyccelkernel(pusher_kernels.push_bxu_Hcurl), ( derham.args_derham, b2_eq_psy[0]._data + b2_psy[0]._data, @@ -553,7 +553,7 @@ def test_push_bxu_H1vec(Nel, p, spl_kind, mapping, show_plots=False): pusher_psy = Pusher_psy( particles, - pusher_kernels.push_bxu_H1vec, + Pyccelkernel(pusher_kernels.push_bxu_H1vec), ( derham.args_derham, b2_eq_psy[0]._data + b2_psy[0]._data, @@ -701,7 +701,7 @@ def test_push_bxu_Hdiv_pauli(Nel, p, spl_kind, mapping, show_plots=False): pusher_psy = Pusher_psy( particles, - pusher_kernels.push_bxu_Hdiv_pauli, + Pyccelkernel(pusher_kernels.push_bxu_Hdiv_pauli), ( derham.args_derham, *derham.p, @@ -845,7 +845,7 @@ def test_push_eta_rk4(Nel, p, spl_kind, mapping, show_plots=False): pusher_psy = Pusher_psy( particles, - pusher_kernels.push_eta_stage, + Pyccelkernel(pusher_kernels.push_eta_stage), (butcher.a, butcher.b, butcher.c), domain.args_domain, alpha_in_kernel=1.0, From 244f4efd621a9141e53c316fe56405ce01dc8b2e Mon Sep 17 00:00:00 2001 From: Stefan Possanner Date: Tue, 7 Oct 2025 08:06:56 +0200 Subject: [PATCH 17/76] only grab models when inspecting model modules --- src/struphy/models/tests/test_xxpproc.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/struphy/models/tests/test_xxpproc.py b/src/struphy/models/tests/test_xxpproc.py index bfd72b7ac..32b43aef5 100644 --- a/src/struphy/models/tests/test_xxpproc.py +++ b/src/struphy/models/tests/test_xxpproc.py @@ -16,25 +16,25 @@ def test_pproc_codes(model: str = None, group: str = None): list_fluid = [] for name, obj in inspect.getmembers(fluid): - if inspect.isclass(obj): + if inspect.isclass(obj) and obj.__module__ == fluid.__name__: if name not in {"StruphyModel", "Propagator"}: list_fluid += [name] list_kinetic = [] for name, obj in inspect.getmembers(kinetic): - if inspect.isclass(obj): + if inspect.isclass(obj) and obj.__module__ == kinetic.__name__: if name not in {"StruphyModel", "KineticBackground", "Propagator"}: list_kinetic += [name] list_hybrid = [] for name, obj in inspect.getmembers(hybrid): - if inspect.isclass(obj): + if inspect.isclass(obj) and obj.__module__ == hybrid.__name__: if name not in {"StruphyModel", "Propagator"}: list_hybrid += [name] list_toy = [] for name, obj in inspect.getmembers(toy): - if inspect.isclass(obj): + if inspect.isclass(obj) and obj.__module__ == toy.__name__: if name not in {"StruphyModel", "Propagator"}: list_toy += [name] @@ -50,6 +50,8 @@ def test_pproc_codes(model: str = None, group: str = None): list_models = list_toy else: raise ValueError(f"{group = } is not a valid group specification.") + + print(f"{list_models = }") if comm.Get_rank() == 0: if model is None: From 0ffc86bea49f409230d146906518299f91703fab Mon Sep 17 00:00:00 2001 From: Stefan Possanner Date: Tue, 7 Oct 2025 08:09:20 +0200 Subject: [PATCH 18/76] formatting --- src/struphy/models/tests/test_xxpproc.py | 2 -- src/struphy/pic/tests/test_pushers.py | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/struphy/models/tests/test_xxpproc.py b/src/struphy/models/tests/test_xxpproc.py index 32b43aef5..52b5af4df 100644 --- a/src/struphy/models/tests/test_xxpproc.py +++ b/src/struphy/models/tests/test_xxpproc.py @@ -50,8 +50,6 @@ def test_pproc_codes(model: str = None, group: str = None): list_models = list_toy else: raise ValueError(f"{group = } is not a valid group specification.") - - print(f"{list_models = }") if comm.Get_rank() == 0: if model is None: diff --git a/src/struphy/pic/tests/test_pushers.py b/src/struphy/pic/tests/test_pushers.py index 657d4d079..786f08bb9 100644 --- a/src/struphy/pic/tests/test_pushers.py +++ b/src/struphy/pic/tests/test_pushers.py @@ -1,6 +1,8 @@ import pytest + from struphy.utils.pyccel import Pyccelkernel + @pytest.mark.mpi(min_size=2) @pytest.mark.parametrize("Nel", [[8, 9, 5], [7, 8, 9]]) @pytest.mark.parametrize("p", [[2, 3, 1], [1, 2, 3]]) From 8522d23f8baa09d7e0303c354a135d91a27a3830 Mon Sep 17 00:00:00 2001 From: Dominik Bell Date: Tue, 7 Oct 2025 09:20:11 +0200 Subject: [PATCH 19/76] Remove StepStaticEfield --- .../pic/pushing/pusher_utilities_kernels.py | 463 ------------------ .../propagators/propagators_markers.py | 93 ---- 2 files changed, 556 deletions(-) diff --git a/src/struphy/pic/pushing/pusher_utilities_kernels.py b/src/struphy/pic/pushing/pusher_utilities_kernels.py index a5a70ace4..0d3749660 100644 --- a/src/struphy/pic/pushing/pusher_utilities_kernels.py +++ b/src/struphy/pic/pushing/pusher_utilities_kernels.py @@ -77,466 +77,3 @@ def reflect( # update the particle velocities markers[ip, 3:6] = v[:] - - -@pure -def quicksort(a: "float[:]", lo: "int", hi: "int"): - """ - Implementation of the quicksort sorting algorithm. Ref? - - Parameters - ---------- - a : array - list that is to be sorted - - lo : integer - lower index from which the sort to start - - hi : integer - upper index until which the sort is to be done - """ - i = lo - j = hi - while i < hi: - pivot = a[(lo + hi) // 2] - while i <= j: - while a[i] < pivot: - i += 1 - while a[j] > pivot: - j -= 1 - if i <= j: - tmp = a[i] - a[i] = a[j] - a[j] = tmp - i += 1 - j -= 1 - if lo < j: - quicksort(a, lo, j) - lo = i - j = hi - - -def find_taus(eta: "float", eta_next: "float", Nel: "int", breaks: "float[:]", uniform: "int", tau_list: "float[:]"): - """ - Find the values of tau for which the particle crosses the cell boundaries while going from eta to eta_next - - Parameters - ---------- - eta : float - old position - - eta_next : float - new position - - Nel : integer - contains the number of elements in this direction - - breaks : array - break points in this direction - - uniform : integer - 0 if the grid is non-uniform, 1 if the grid is uniform - """ - - if uniform == 1: - index = int(floor(eta * Nel)) - index_next = int(floor(eta_next * Nel)) - length = int(abs(index_next - index)) - - # break = eta / dx = eta * Nel - - for i in range(length): - if index_next > index: - tau_list[i] = (1.0 / Nel * (index + i + 1) - eta) / (eta_next - eta) - elif index > index_next: - tau_list[i] = (eta - 1.0 / Nel * (index - i)) / (eta - eta_next) - - elif uniform == 0: - # TODO - print("Not implemented yet") - - else: - print("ValueError, uniform must be 1 or 0 !") - - -@stack_array("Nel") -def aux_fun_x_v_stat_e( - particle: "float[:]", - args_derham: "DerhamArguments", - args_domain: "DomainArguments", - n_quad1: "int", - n_quad2: "int", - n_quad3: "int", - dfm: "float[:,:]", - df_inv: "float[:,:]", - taus: "float[:]", - dt: "float", - loc1: "float[:]", - loc2: "float[:]", - loc3: "float[:]", - weight1: "float[:]", - weight2: "float[:]", - weight3: "float[:]", - e1_1: "float[:,:,:]", - e1_2: "float[:,:,:]", - e1_3: "float[:,:,:]", - kappa: "float", - eps: "float[:]", - maxiter: "int", -) -> "int": - """ - Auxiliary function for the pusher_x_v_static_efield, introduced to enable time-step splitting if scheme does not converge for the standard dt - - Parameters - ---------- - particle : array - shape(7), contains the values for the positions [0:3], velocities [3:6], and weights [8] - - dt2 : double - time stepping of substep - - loc1, loc2, loc3 : array - contain the positions of the Legendre-Gauss quadrature points of necessary order to integrate basis splines exactly in each direction - - weight1, weight2, weight3 : array - contain the values of the weights for the Legendre-Gauss quadrature in each direction - - e1_1, e1_2, e1_3: array[float] - 3d array of FE coeffs of the background E-field as 1-form. - - eps: array - determines the accuracy for the position (0th element) and velocity (1st element) with which the implicit scheme is executed - - maxiter : integer - sets the maximum number of iterations for the iterative scheme - """ - - # Find number of elements in each direction - Nel = empty(3, dtype=int) - Nel[0] = len(args_derham.tn1) - Nel[1] = len(args_derham.tn2) - Nel[2] = len(args_derham.tn3) - - # total number of basis functions : B-splines (pn) and D-splines (pd) - pn1 = int(args_derham.pn[0]) - pn2 = int(args_derham.pn[1]) - pn3 = int(args_derham.pn[2]) - - pd1 = pn1 - 1 - pd2 = pn2 - 1 - pd3 = pn3 - 1 - - eps_pos = eps[0] - eps_vel = eps[1] - - # position - eta1 = particle[0] - eta2 = particle[1] - eta3 = particle[2] - - # velocities - v1 = particle[3] - v2 = particle[4] - v3 = particle[5] - - # set initial value for x_k^{n+1} - eta1_curr = eta1 - eta2_curr = eta2 - eta3_curr = eta3 - - # set initial value for v_k^{n+1} - v1_curr = v1 - v2_curr = v2 - v3_curr = v3 - - # Use Euler method as a predictor for positions - evaluation_kernels.df( - eta1, - eta2, - eta3, - args_domain, - dfm, - ) - - linalg_kernels.matrix_inv(dfm, df_inv) - - v1_curv = kappa * (df_inv[0, 0] * (v1_curr + v1) + df_inv[0, 1] * (v2_curr + v2) + df_inv[0, 2] * (v3_curr + v3)) - v2_curv = kappa * (df_inv[1, 0] * (v1_curr + v1) + df_inv[1, 1] * (v2_curr + v2) + df_inv[1, 2] * (v3_curr + v3)) - v3_curv = kappa * (df_inv[2, 0] * (v1_curr + v1) + df_inv[2, 1] * (v2_curr + v2) + df_inv[2, 2] * (v3_curr + v3)) - - eta1_next = (eta1 + dt * v1_curv / 2.0) % 1 - eta2_next = (eta2 + dt * v2_curv / 2.0) % 1 - eta3_next = (eta3 + dt * v3_curv / 2.0) % 1 - - # set some initial value for v_next - v1_next = v1_curr - v2_next = v2_curr - v3_next = v3_curr - - runs = 0 - - while ( - abs(eta1_next - eta1_curr) > eps_pos - or abs(eta2_next - eta2_curr) > eps_pos - or abs(eta3_next - eta3_curr) > eps_pos - or abs(v1_next - v1_curr) > eps_vel - or abs(v2_next - v2_curr) > eps_vel - or abs(v3_next - v3_curr) > eps_vel - ): - taus[:] = 0.0 - - # update the positions and velocities - eta1_curr = eta1_next - eta2_curr = eta2_next - eta3_curr = eta3_next - - v1_curr = v1_next - v2_curr = v2_next - v3_curr = v3_next - - # find Jacobian matrix - evaluation_kernels.df( - (eta1_curr + eta1) / 2, - (eta2_curr + eta2) / 2, - (eta3_curr + eta3) / 2, - args_domain, - dfm, - ) - - # evaluate inverse Jacobian matrix - linalg_kernels.matrix_inv(dfm, df_inv) - - # ====================================================================================== - # update the positions and place them back into the computational domain - v1_curv = kappa * ( - df_inv[0, 0] * (v1_curr + v1) + df_inv[0, 1] * (v2_curr + v2) + df_inv[0, 2] * (v3_curr + v3) - ) - v2_curv = kappa * ( - df_inv[1, 0] * (v1_curr + v1) + df_inv[1, 1] * (v2_curr + v2) + df_inv[1, 2] * (v3_curr + v3) - ) - v3_curv = kappa * ( - df_inv[2, 0] * (v1_curr + v1) + df_inv[2, 1] * (v2_curr + v2) + df_inv[2, 2] * (v3_curr + v3) - ) - - # x_{n+1} = x_n + dt/2 * DF^{-1}(x_{n+1}/2 + x_n/2) * (v_{n+1} + v_n) - eta1_next = (eta1 + dt * v1_curv / 2.0) % 1 - eta2_next = (eta2 + dt * v2_curv / 2.0) % 1 - eta3_next = (eta3 + dt * v3_curv / 2.0) % 1 - - # ====================================================================================== - # Compute tau-values in [0,1] for crossings of cell-boundaries - - index1 = int(floor(eta1_curr * Nel[0])) - index1_next = int(floor(eta1_next * Nel[0])) - length1 = int(abs(index1_next - index1)) - - index2 = int(floor(eta2_curr * Nel[1])) - index2_next = int(floor(eta2_next * Nel[1])) - length2 = int(abs(index2_next - index2)) - - index3 = int(floor(eta3_curr * Nel[2])) - index3_next = int(floor(eta3_next * Nel[2])) - length3 = int(abs(index3_next - index3)) - - length = length1 + length2 + length3 - - taus[0] = 0.0 - taus[length + 1] = 1.0 - - tmp1 = taus[1 : length1 + 1] - find_taus(eta1_curr, eta1_next, Nel[0], args_derham.tn1, 1, tmp1) - taus[1 : length1 + 1] = tmp1 - - tmp2 = taus[length1 + 1 : length1 + length2 + 1] - find_taus(eta2_curr, eta2_next, Nel[1], args_derham.tn2, 1, tmp2) - taus[length1 + 1 : length1 + length2 + 1] = tmp2 - - tmp3 = taus[length1 + length2 + 1 : length + 1] - find_taus(eta3_curr, eta3_next, Nel[2], args_derham.tn3, 1, tmp3) - taus[length1 + length2 + 1 : length + 1] = tmp3 - - del tmp1, tmp2, tmp3 - - if length != 0: - tmp4 = taus[0 : length + 1] - quicksort(tmp4, 1, length) - taus[0 : length + 1] = tmp4 - del tmp4 - - # ====================================================================================== - # update velocity in direction 1 - - temp1 = 0.0 - - # loop over the cells - for k in range(length + 1): - a = eta1 + taus[k] * (eta1_curr - eta1) - b = eta1 + taus[k + 1] * (eta1_curr - eta1) - factor = (b - a) / 2 - adding = (a + b) / 2 - - for n in range(n_quad1): - quad_pos1 = factor * loc1[n] + adding - quad_pos2 = factor * loc1[n] + adding - quad_pos3 = factor * loc1[n] + adding - - # spline evaluation - span1, span2, span3 = get_spans( - quad_pos1, - quad_pos2, - quad_pos3, - args_derham, - ) - - # find global index where non-zero basis functions begin - ie1 = span1 - args_derham.pn[0] - ie2 = span2 - args_derham.pn[1] - ie3 = span3 - args_derham.pn[2] - - # (DNN) - for il1 in range(pd1 + 1): - i1 = ie1 + il1 - bi1 = args_derham.bd1[il1] - for il2 in range(pn2 + 1): - i2 = ie2 + il2 - bi2 = bi1 * args_derham.bn2[il2] - for il3 in range(pn3 + 1): - i3 = ie3 + il3 - bi3 = ( - bi2 - * args_derham.bn3[il3] - * e1_1[ - i1 - args_derham.starts[0] + pn1, - i2 - args_derham.starts[1] + pn2, - i3 - args_derham.starts[2] + pn3, - ] - ) - - temp1 += bi3 * weight1[n] - - # ====================================================================================== - # update velocity in direction 2 - - temp2 = 0.0 - - # loop over the cells - for k in range(length + 1): - a = eta2 + taus[k] * (eta2_curr - eta2) - b = eta2 + taus[k + 1] * (eta2_curr - eta2) - factor = (b - a) / 2 - adding = (a + b) / 2 - - for n in range(n_quad2): - quad_pos1 = factor * loc2[n] + adding - quad_pos2 = factor * loc2[n] + adding - quad_pos3 = factor * loc2[n] + adding - - # spline evaluation - span1, span2, span3 = get_spans( - quad_pos1, - quad_pos2, - quad_pos3, - args_derham, - ) - - # find global index where non-zero basis functions begin - ie1 = span1 - args_derham.pn[0] - ie2 = span2 - args_derham.pn[1] - ie3 = span3 - args_derham.pn[2] - - # (NDN) - for il1 in range(pn1 + 1): - i1 = ie1 + il1 - bi1 = args_derham.bn1[il1] - for il2 in range(pd2 + 1): - i2 = ie2 + il2 - bi2 = bi1 * args_derham.bd2[il2] - for il3 in range(pn3 + 1): - i3 = ie3 + il3 - bi3 = ( - bi2 - * args_derham.bn3[il3] - * e1_2[ - i1 - args_derham.starts[0] + pn1, - i2 - args_derham.starts[1] + pn2, - i3 - args_derham.starts[2] + pn3, - ] - ) - - temp2 += bi3 * weight2[n] - - # ====================================================================================== - # update velocity in direction 3 - - temp3 = 0.0 - - # loop over the cells - for k in range(length + 1): - a = eta3 + taus[k] * (eta3_curr - eta3) - b = eta3 + taus[k + 1] * (eta3_curr - eta3) - factor = (b - a) / 2 - adding = (a + b) / 2 - - for n in range(n_quad3): - quad_pos1 = factor * loc3[n] + adding - quad_pos2 = factor * loc3[n] + adding - quad_pos3 = factor * loc3[n] + adding - - # spline evaluation - span1, span2, span3 = get_spans( - quad_pos1, - quad_pos2, - quad_pos3, - args_derham, - ) - - # find global index where non-zero basis functions begin - ie1 = span1 - args_derham.pn[0] - ie2 = span2 - args_derham.pn[1] - ie3 = span3 - args_derham.pn[2] - - # (NND) - for il1 in range(pn1 + 1): - i1 = ie1 + il1 - bi1 = args_derham.bn1[il1] - for il2 in range(pn2 + 1): - i2 = ie2 + il2 - bi2 = bi1 * args_derham.bn2[il2] - for il3 in range(pd3 + 1): - i3 = ie3 + il3 - bi3 = ( - bi2 - * args_derham.bd3[il3] - * e1_3[ - i1 - args_derham.starts[0] + pn1, - i2 - args_derham.starts[1] + pn2, - i3 - args_derham.starts[2] + pn3, - ] - ) - - temp3 += bi3 * weight3[n] - - # v_{n+1} = v_n + dt * DF^{-T}(x_n) * int_0^1 d tau ( E(x_n + tau*(x_{n+1} - x_n) ) ) - v1_next = v1 + dt * kappa * (df_inv[0, 0] * temp1 + df_inv[1, 0] * temp2 + df_inv[2, 0] * temp3) - v2_next = v2 + dt * kappa * (df_inv[0, 1] * temp1 + df_inv[1, 1] * temp2 + df_inv[2, 1] * temp3) - v3_next = v3 + dt * kappa * (df_inv[0, 2] * temp1 + df_inv[1, 2] * temp2 + df_inv[2, 2] * temp3) - - runs += 1 - - if runs == maxiter: - break - - if runs < maxiter: - # print('For convergence this took runs:', runs) - # print() - runs = 0 - - # write the results in the particle array and impose periodic boundary conditions on the particles by taking modulo 1 - particle[0] = eta1_next % 1 - particle[1] = eta2_next % 1 - particle[2] = eta3_next % 1 - particle[3] = v1_next - particle[4] = v2_next - particle[5] = v3_next - - return runs diff --git a/src/struphy/propagators/propagators_markers.py b/src/struphy/propagators/propagators_markers.py index 6c3ffcec4..dabb3a359 100644 --- a/src/struphy/propagators/propagators_markers.py +++ b/src/struphy/propagators/propagators_markers.py @@ -1200,99 +1200,6 @@ def __call__(self, dt): self.particles[0].update_weights() -class StepStaticEfield(Propagator): - r"""Solve the following system - - .. math:: - - \frac{\text{d} \mathbf{\eta}_p}{\text{d} t} & = DL^{-1} \mathbf{v}_p \,, - - \frac{\text{d} \mathbf{v}_p}{\text{d} t} & = \kappa \, DL^{-T} \mathbf{E} - - which is solved by an average discrete gradient method, implicitly iterating - over :math:`k` (for every particle :math:`p`): - - .. math:: - - \mathbf{\eta}^{n+1}_{k+1} = \mathbf{\eta}^n + \frac{\Delta t}{2} DL^{-1} - \left( \frac{\mathbf{\eta}^{n+1}_k + \mathbf{\eta}^n }{2} \right) \left( \mathbf{v}^{n+1}_k + \mathbf{v}^n \right) \,, - - \mathbf{v}^{n+1}_{k+1} = \mathbf{v}^n + \Delta t \, \kappa \, DL^{-1}\left(\mathbf{\eta}^n\right) - \int_0^1 \left[ \mathbb{\Lambda}\left( \eta^n + \tau (\mathbf{\eta}^{n+1}_k - \mathbf{\eta}^n) \right) \right]^T \mathbf{e} \, \text{d} \tau - - Parameters - ---------- - particles : struphy.pic.particles.Particles6D - Holdes the markers to push. - - **params : dict - Solver- and/or other parameters for this splitting step. - """ - - def __init__(self, particles, **params): - from numpy import floor, polynomial - - super().__init__(particles) - - # parameters - params_default = { - "e_field": BlockVector(self.derham.Vh_fem["1"].coeff_space), - "kappa": 1e2, - } - - params = set_defaults(params, params_default) - self.kappa = params["kappa"] - - assert isinstance(params["e_field"], (BlockVector, PolarVector)) - self._e_field = params["e_field"] - - pn1 = self.derham.p[0] - pd1 = pn1 - 1 - pn2 = self.derham.p[1] - pd2 = pn2 - 1 - pn3 = self.derham.p[2] - pd3 = pn3 - 1 - - # number of quadrature points in direction 1 - n_quad1 = int(floor(pd1 * pn2 * pn3 / 2 + 1)) - # number of quadrature points in direction 2 - n_quad2 = int(floor(pn1 * pd2 * pn3 / 2 + 1)) - # number of quadrature points in direction 3 - n_quad3 = int(floor(pn1 * pn2 * pd3 / 2 + 1)) - - # get quadrature weights and locations - self._loc1, self._weight1 = polynomial.legendre.leggauss(n_quad1) - self._loc2, self._weight2 = polynomial.legendre.leggauss(n_quad2) - self._loc3, self._weight3 = polynomial.legendre.leggauss(n_quad3) - - self._pusher = Pusher( - self.derham, - self.domain, - "push_x_v_static_efield", - ) - - def __call__(self, dt): - """ - TODO - """ - self._pusher( - self.particles[0], - dt, - self._loc1, - self._loc2, - self._loc3, - self._weight1, - self._weight2, - self._weight3, - self._e_field.blocks[0]._data, - self._e_field.blocks[1]._data, - self._e_field.blocks[2]._data, - self.kappa, - array([1e-10, 1e-10]), - 100, - ) - - class PushDeterministicDiffusion(Propagator): r"""For each marker :math:`p`, solves From cf18e345da1e9f0a2d3ccc4471b177976df9ce8e Mon Sep 17 00:00:00 2001 From: Max Lindqvist Date: Tue, 7 Oct 2025 13:26:40 +0200 Subject: [PATCH 20/76] Updated src/struphy/propagators/__init__.py --- src/struphy/propagators/__init__.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/struphy/propagators/__init__.py b/src/struphy/propagators/__init__.py index 2dbef2b10..9d6a018ee 100644 --- a/src/struphy/propagators/__init__.py +++ b/src/struphy/propagators/__init__.py @@ -46,7 +46,6 @@ PushVinSPHpressure, PushVinViscousPotential, PushVxB, - StepStaticEfield, ) __all__ = [ @@ -89,7 +88,6 @@ "PushEtaPC", "PushGuidingCenterBxEstar", "PushGuidingCenterParallel", - "StepStaticEfield", "PushDeterministicDiffusion", "PushRandomDiffusion", "PushVinSPHpressure", From d96173de7d9c35223b2e17cefb74c544f7562625 Mon Sep 17 00:00:00 2001 From: Max Lindqvist Date: Wed, 8 Oct 2025 15:55:53 +0200 Subject: [PATCH 21/76] Use test_pproc_codes(group=mtype) --- src/struphy/console/test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/struphy/console/test.py b/src/struphy/console/test.py index cf64a1649..14be75c43 100644 --- a/src/struphy/console/test.py +++ b/src/struphy/console/test.py @@ -183,4 +183,4 @@ def struphy_test( if not verification: from struphy.models.tests.test_xxpproc import test_pproc_codes - test_pproc_codes(group=group) + test_pproc_codes(group=mtype) From 40035e662f47fbaa41fb65cccebf65fdec59523e Mon Sep 17 00:00:00 2001 From: Max Lindqvist Date: Wed, 8 Oct 2025 17:16:03 +0200 Subject: [PATCH 22/76] Added a simple xp.py --- src/struphy/xp.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/struphy/xp.py diff --git a/src/struphy/xp.py b/src/struphy/xp.py new file mode 100644 index 000000000..fcbb2859d --- /dev/null +++ b/src/struphy/xp.py @@ -0,0 +1,31 @@ +import os + +# TODO: Make this configurable via environment variable or config file. +# Default to numpy +_backend = os.getenv("ARRAY_BACKEND", "numpy").lower() + + +# TODO: Write an ArrayBackend class + +def _import_numpy(): + # print("importing numpy...") + import numpy as np + + return np + + +def _import_cupy(): + # print("importing cupy...") + try: + import cupy as cp + + return cp + except ImportError: + print("CuPy not available, falling back to NumPy.") + return _import_numpy() + +# Import numpy/cupy +if _backend == "cupy": + xp = _import_cupy() +else: + xp = _import_numpy() From 4e6fae3a4425847f456c412213c623f0847224bc Mon Sep 17 00:00:00 2001 From: Max Lindqvist Date: Wed, 8 Oct 2025 17:17:20 +0200 Subject: [PATCH 23/76] Added a temporary print --- src/struphy/xp.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/struphy/xp.py b/src/struphy/xp.py index fcbb2859d..e78273fad 100644 --- a/src/struphy/xp.py +++ b/src/struphy/xp.py @@ -29,3 +29,5 @@ def _import_cupy(): xp = _import_cupy() else: xp = _import_numpy() + +print(f"Using {xp.__name__} backend.") \ No newline at end of file From f971a6821c2c2ec1a2aba522038cb7634d0ae4ff Mon Sep 17 00:00:00 2001 From: Max Lindqvist Date: Wed, 8 Oct 2025 17:18:54 +0000 Subject: [PATCH 24/76] Update .gitlab-ci.yml file --- .gitlab-ci.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 000985fc5..676a18827 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -496,6 +496,22 @@ inspect_repo: - ./cloc --version - ./cloc $(git ls-files) +test_cupy: + tags: [nvidia-cc80] + image: gitlab-registry.mpcdf.mpg.de/mpcdf/ci-module-image/nvhpcsdk_24-openmpi_5_0:2025 + stage: startup + timeout: 5m + extends: + - .rules_startup + before_script: + - module avail + - module list + - module purge + #- module load cuda/12.6 gcc/13 openmpi/5.0 + - module load nvhpcsdk/24 openmpi/5.0 python-waterboa/2024.06 gcc/13 + script: + - ls + ##################### ### PUSH PIPELINE ### ##################### From d71d82c9e10ef86faf2c958da0bd5a02f05b539f Mon Sep 17 00:00:00 2001 From: Max Lindqvist Date: Wed, 8 Oct 2025 17:29:33 +0000 Subject: [PATCH 25/76] Update .gitlab-ci.yml file --- .gitlab-ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 676a18827..e0368e26c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -511,6 +511,9 @@ test_cupy: - module load nvhpcsdk/24 openmpi/5.0 python-waterboa/2024.06 gcc/13 script: - ls + - python3 -m pip install --user cupy-cuda12x + - nvidia-smi + - python3 -c "import cupy as cp" ##################### ### PUSH PIPELINE ### From cbbb49abe9737f6730978780e5625afbc0e46a8e Mon Sep 17 00:00:00 2001 From: Max Lindqvist Date: Wed, 8 Oct 2025 17:35:34 +0000 Subject: [PATCH 26/76] Update .gitlab-ci.yml file --- .gitlab-ci.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e0368e26c..3610ef425 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -500,7 +500,6 @@ test_cupy: tags: [nvidia-cc80] image: gitlab-registry.mpcdf.mpg.de/mpcdf/ci-module-image/nvhpcsdk_24-openmpi_5_0:2025 stage: startup - timeout: 5m extends: - .rules_startup before_script: @@ -511,8 +510,8 @@ test_cupy: - module load nvhpcsdk/24 openmpi/5.0 python-waterboa/2024.06 gcc/13 script: - ls - - python3 -m pip install --user cupy-cuda12x - nvidia-smi + - python3 -m pip install --user cupy-cuda12x - python3 -c "import cupy as cp" ##################### From e08372e5a5ae5bf84cc2a8de4b2c6b1fa35c523b Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 8 Oct 2025 19:43:45 +0200 Subject: [PATCH 27/76] Commented out jobs --- .gitlab-ci.yml | 1094 ++++++++++++++++++++++++------------------------ 1 file changed, 547 insertions(+), 547 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3610ef425..359c8952d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -514,11 +514,38 @@ test_cupy: - python3 -m pip install --user cupy-cuda12x - python3 -c "import cupy as cp" -##################### -### PUSH PIPELINE ### -##################### +# ##################### +# ### PUSH PIPELINE ### +# ##################### + +# # check_struphy_simulation_params: +# # stage: test +# # extends: +# # - .rules_mr_to_devel +# # - .image_gitlab_mpcdf_struphy +# # - .before_script_load_modules +# # - .variables_push +# # script: +# # - !reference [.scripts, install_on_push] +# # - git clone https://gitlab.mpcdf.mpg.de/struphy/struphy-simulations.git +# # - | +# # for file in struphy-simulations/**/*.yml; do +# # echo "Checking $file" +# # # TODO: How to deduce the model? +# # struphy params LinearVlasovAmpereOneSpecies --check-file $file +# # done + +# install_tests: +# stage: test +# extends: +# - .rules_mr_to_devel +# - .image_gitlab_mpcdf_struphy +# - .before_script_load_modules +# - .parallel_matrix_install +# script: +# - !reference [.scripts, install_on_push] -# check_struphy_simulation_params: +# unit_tests: # stage: test # extends: # - .rules_mr_to_devel @@ -527,566 +554,539 @@ test_cupy: # - .variables_push # script: # - !reference [.scripts, install_on_push] -# - git clone https://gitlab.mpcdf.mpg.de/struphy/struphy-simulations.git -# - | -# for file in struphy-simulations/**/*.yml; do -# echo "Checking $file" -# # TODO: How to deduce the model? -# struphy params LinearVlasovAmpereOneSpecies --check-file $file -# done - -install_tests: - stage: test - extends: - - .rules_mr_to_devel - - .image_gitlab_mpcdf_struphy - - .before_script_load_modules - - .parallel_matrix_install - script: - - !reference [.scripts, install_on_push] - -unit_tests: - stage: test - extends: - - .rules_mr_to_devel - - .image_gitlab_mpcdf_struphy - - .before_script_load_modules - - .variables_push - script: - - !reference [.scripts, install_on_push] - - !reference [.scripts, unit_tests] - -tests_pyccel_devel: - stage: test - extends: - - .rules_scheduled - - .image_gitlab_mpcdf_struphy - - .before_script_load_modules - - .variables_push - script: - - !reference [.scripts, install_pyccel_devel] - - !reference [.scripts, unit_tests] - - !reference [.scripts, model_tests] - -model_tests: - stage: test - extends: - - .rules_mr_to_devel - - .image_gitlab_mpcdf_struphy - - .before_script_load_modules - - .variables_push - script: - - !reference [.scripts, install_on_push] - - !reference [.scripts, model_tests] - -quickstart_tests: - stage: test - extends: - - .rules_mr_to_devel - - .image_gitlab_mpcdf_struphy - - .before_script_load_modules - - .variables_push - script: - - !reference [.scripts, install_on_push] - - !reference [.scripts, quickstart_tests] +# - !reference [.scripts, unit_tests] -pages_tests: - stage: test - extends: - - .rules_mr_to_devel - - .image_gitlab_mpcdf_struphy - - .before_script_load_modules - - .variables_push - script: - - !reference [.scripts, install_on_push] - - !reference [.scripts, inspect_struphy] - - module load pandoc - - module list - - pip install .[doc] - - | - struphy compile -y || ( - echo "Initial compile failed. Removing compiled kernels and trying again..." && - struphy compile -d -y && - struphy compile -y - ) - - cd doc ; make html - - mv _build/html/ $CI_PROJECT_DIR/documentation/ - artifacts: - expose_as: 'Documentation' - paths: - - documentation/ - -ubuntu_latest: - stage: test - extends: - - .rules_mr_to_devel - - .image_ubuntu_struphy - - .variables_push - script: - - !reference [.scripts, inspect_directory] - - !reference [.scripts, install_on_push] - - !reference [.scripts, quickstart_tests] - - !reference [.scripts, model_tests] - -macos_nmpp: - stage: test - tags: [macos, nmpp, private] - needs: [] - variables: - # Job ID changes for each job, so reusing the directory becomes impossible, - # therefore, the fetch strategy also becomes unusable - GIT_CLONE_PATH: $CI_BUILDS_DIR/$CI_PROJECT_NAME/$CI_JOB_ID/$CI_CONCURRENT_PROJECT_ID - _JOB_PATH: $CI_BUILDS_DIR/$CI_PROJECT_NAME/$CI_JOB_ID - extends: - - .rules_mr_to_devel - - .variables_push - before_script: - # - brew install cmake - - brew link --overwrite cmake - - cmake --version - - make -v - - printenv - - system_profiler SPHardwareDataType - - export FC=`which gfortran` # for gvec - - export CC=`which gcc` # for gvec - - export CXX=`which g++` # for gvec - script: - - !reference [.scripts, create_venv] - - !reference [.scripts, install] - - !reference [.scripts, compile] - - !reference [.scripts, quickstart_tests] - - !reference [.scripts, model_tests] - after_script: - - pwd - - ls -a - - echo $_JOB_PATH - - ls -a $_JOB_PATH - - rm -rf $_JOB_PATH - -cleanup_macos: - stage: test - tags: [macos, nmpp, private] - needs: [] - extends: - - .rules_cleanup_macos - before_script: - - make -v - - printenv - - system_profiler SPHardwareDataType - script: - - _STRUPHY_PATH=$CI_BUILDS_DIR/$CI_PROJECT_NAME - - pwd - - ls -a - - echo $_STRUPHY_PATH - - ls -a $_STRUPHY_PATH - - rm -rf $_STRUPHY_PATH/* - - ls -a $_STRUPHY_PATH - -########################## -### SCHEDULED PIPELINE ### -########################## - - -install_scheduled: - stage: install - needs: [] - extends: - - .rules_scheduled - - .image_gitlab_mpcdf_gcc_openmp - - .before_script_load_modules - - .parallel_matrix_scheduled - - .artifacts_scheduled - script: - - !reference [.scripts, create_venv_matrix] - - !reference [.scripts, install_no_binary] - - !reference [.scripts, compile_matrix] - -compile_timing: - stage: install - needs: [] - extends: - - .image_gitlab_mpcdf_gcc_openmp - - .before_script_load_modules - - .rules_scheduled - script: - - !reference [.scripts, create_venv] - - !reference [.scripts, install_no_binary] - - pyccel --version - - struphy compile --status - - struphy compile --delete - - struphy compile --time-execution -y --language c > timings_c.txt - - struphy compile --delete - - struphy compile --time-execution -y --language fortran > timings_fortran.txt - - | - cat << 'EOF' > check_pyccel.sh - #!/bin/bash - grep 'pyccel --libdir' timings_c.txt | sed -E 's|.*/site-packages/||' | while read filepath; do - echo "========================================" - echo "Kernel: $filepath" - echo "-------------------- Timers -------------------------" - echo "# Language: C" - grep -A 11 "pyccel.*${filepath}" timings_c.txt | tail -n +3 - echo "# Language: Fortran" - grep -A 13 "pyccel.*${filepath}" timings_fortran.txt | tail -n +3 - done - EOF - - cat check_pyccel.sh - - chmod +x check_pyccel.sh - - ./check_pyccel.sh - -test_build: - stage: test - extends: - - .image_gitlab_mpcdf_gcc_openmp - - .rules_scheduled - - .before_script_load_modules - needs: [] - script: - - !reference [.scripts, create_venv] - - !reference [.scripts, build] - - pip install $(echo dist/struphy*.whl) --no-cache-dir --no-binary mpi4py +# tests_pyccel_devel: +# stage: test +# extends: +# - .rules_scheduled +# - .image_gitlab_mpcdf_struphy +# - .before_script_load_modules +# - .variables_push +# script: +# - !reference [.scripts, install_pyccel_devel] +# - !reference [.scripts, unit_tests] +# - !reference [.scripts, model_tests] -unit_tests_scheduled: - stage: test - extends: - - .image_gitlab_mpcdf_gcc_openmp - - .rules_scheduled - - .parallel_matrix_scheduled - - .before_script_load_modules - script: - - !reference [.scripts, source_env_matrix] - - !reference [.scripts, unit_tests] +# model_tests: +# stage: test +# extends: +# - .rules_mr_to_devel +# - .image_gitlab_mpcdf_struphy +# - .before_script_load_modules +# - .variables_push +# script: +# - !reference [.scripts, install_on_push] +# - !reference [.scripts, model_tests] -model_tests_scheduled: - stage: test - extends: - - .image_gitlab_mpcdf_gcc_openmp - - .rules_scheduled - - .parallel_matrix_scheduled - - .before_script_load_modules - script: - - !reference [.scripts, source_env_matrix] - - !reference [.scripts, model_tests] +# quickstart_tests: +# stage: test +# extends: +# - .rules_mr_to_devel +# - .image_gitlab_mpcdf_struphy +# - .before_script_load_modules +# - .variables_push +# script: +# - !reference [.scripts, install_on_push] +# - !reference [.scripts, quickstart_tests] -check_release_dependencies: - stage: test - extends: - - .image_gitlab_mpcdf_gcc_openmp - - .before_script_load_modules - - .rules_mr_to_master - script: - - !reference [.scripts, inspect_directory] - - !reference [.scripts, create_venv] - - !reference [.scripts, install_all] - - python src/struphy/utils/set_release_dependencies.py - - | - if git diff --exit-code pyproject.toml; then - echo "pyproject.toml has not changed, dependencies are set correctly!" - else - echo "pyproject.toml has changed, dependencies are set incorrectly!" - echo "Run python src/struphy/utils/set_release_dependencies.py to update pyproject.toml" - exit 1 - fi - -Ubuntu-latest-from-registry: - stage: test - needs: [] - extends: - - .image_ubuntu_latest - - .rules_scheduled - - .parallel_matrix_scheduled - before_script: - - !reference [.scripts, inspect_directory] - - !reference [.scripts, create_venv] - script: - - !reference [.scripts, install] - - !reference [.scripts, compile_matrix] - - !reference [.scripts, model_tests] +# pages_tests: +# stage: test +# extends: +# - .rules_mr_to_devel +# - .image_gitlab_mpcdf_struphy +# - .before_script_load_modules +# - .variables_push +# script: +# - !reference [.scripts, install_on_push] +# - !reference [.scripts, inspect_struphy] +# - module load pandoc +# - module list +# - pip install .[doc] +# - | +# struphy compile -y || ( +# echo "Initial compile failed. Removing compiled kernels and trying again..." && +# struphy compile -d -y && +# struphy compile -y +# ) +# - cd doc ; make html +# - mv _build/html/ $CI_PROJECT_DIR/documentation/ +# artifacts: +# expose_as: 'Documentation' +# paths: +# - documentation/ + +# ubuntu_latest: +# stage: test +# extends: +# - .rules_mr_to_devel +# - .image_ubuntu_struphy +# - .variables_push +# script: +# - !reference [.scripts, inspect_directory] +# - !reference [.scripts, install_on_push] +# - !reference [.scripts, quickstart_tests] +# - !reference [.scripts, model_tests] -Fedora-latest: - stage: test - needs: [] - extends: - - .rules_scheduled - - .parallel_matrix_scheduled - - .requirements_fedora - image: fedora:latest - script: - - !reference [.scripts, install] - - !reference [.scripts, compile_matrix] - - !reference [.scripts, model_tests] +# macos_nmpp: +# stage: test +# tags: [macos, nmpp, private] +# needs: [] +# variables: +# # Job ID changes for each job, so reusing the directory becomes impossible, +# # therefore, the fetch strategy also becomes unusable +# GIT_CLONE_PATH: $CI_BUILDS_DIR/$CI_PROJECT_NAME/$CI_JOB_ID/$CI_CONCURRENT_PROJECT_ID +# _JOB_PATH: $CI_BUILDS_DIR/$CI_PROJECT_NAME/$CI_JOB_ID +# extends: +# - .rules_mr_to_devel +# - .variables_push +# before_script: +# # - brew install cmake +# - brew link --overwrite cmake +# - cmake --version +# - make -v +# - printenv +# - system_profiler SPHardwareDataType +# - export FC=`which gfortran` # for gvec +# - export CC=`which gcc` # for gvec +# - export CXX=`which g++` # for gvec +# script: +# - !reference [.scripts, create_venv] +# - !reference [.scripts, install] +# - !reference [.scripts, compile] +# - !reference [.scripts, quickstart_tests] +# - !reference [.scripts, model_tests] +# after_script: +# - pwd +# - ls -a +# - echo $_JOB_PATH +# - ls -a $_JOB_PATH +# - rm -rf $_JOB_PATH + +# cleanup_macos: +# stage: test +# tags: [macos, nmpp, private] +# needs: [] +# extends: +# - .rules_cleanup_macos +# before_script: +# - make -v +# - printenv +# - system_profiler SPHardwareDataType +# script: +# - _STRUPHY_PATH=$CI_BUILDS_DIR/$CI_PROJECT_NAME +# - pwd +# - ls -a +# - echo $_STRUPHY_PATH +# - ls -a $_STRUPHY_PATH +# - rm -rf $_STRUPHY_PATH/* +# - ls -a $_STRUPHY_PATH + +# ########################## +# ### SCHEDULED PIPELINE ### +# ########################## + + +# install_scheduled: +# stage: install +# needs: [] +# extends: +# - .rules_scheduled +# - .image_gitlab_mpcdf_gcc_openmp +# - .before_script_load_modules +# - .parallel_matrix_scheduled +# - .artifacts_scheduled +# script: +# - !reference [.scripts, create_venv_matrix] +# - !reference [.scripts, install_no_binary] +# - !reference [.scripts, compile_matrix] -Fedora-latest-from-registry: - stage: test - needs: [] - extends: - - .rules_scheduled - - .parallel_matrix_scheduled - image: gitlab-registry.mpcdf.mpg.de/struphy/struphy/fedora-latest - before_script: - - !reference [.scripts, inspect_directory] - - !reference [.scripts, create_venv] - - . /etc/profile.d/modules.sh - - module load mpi/openmpi-$(arch) - - module list - script: - - !reference [.scripts, install] - - !reference [.scripts, compile_matrix] - - !reference [.scripts, model_tests] +# compile_timing: +# stage: install +# needs: [] +# extends: +# - .image_gitlab_mpcdf_gcc_openmp +# - .before_script_load_modules +# - .rules_scheduled +# script: +# - !reference [.scripts, create_venv] +# - !reference [.scripts, install_no_binary] +# - pyccel --version +# - struphy compile --status +# - struphy compile --delete +# - struphy compile --time-execution -y --language c > timings_c.txt +# - struphy compile --delete +# - struphy compile --time-execution -y --language fortran > timings_fortran.txt +# - | +# cat << 'EOF' > check_pyccel.sh +# #!/bin/bash +# grep 'pyccel --libdir' timings_c.txt | sed -E 's|.*/site-packages/||' | while read filepath; do +# echo "========================================" +# echo "Kernel: $filepath" +# echo "-------------------- Timers -------------------------" +# echo "# Language: C" +# grep -A 11 "pyccel.*${filepath}" timings_c.txt | tail -n +3 +# echo "# Language: Fortran" +# grep -A 13 "pyccel.*${filepath}" timings_fortran.txt | tail -n +3 +# done +# EOF +# - cat check_pyccel.sh +# - chmod +x check_pyccel.sh +# - ./check_pyccel.sh -Fedora-latest-from-registry-base: - stage: test - needs: [] - extends: - - .rules_scheduled - - .parallel_matrix_scheduled - image: gitlab-registry.mpcdf.mpg.de/struphy/struphy/fedora-latest - before_script: - - !reference [.scripts, inspect_directory] - - !reference [.scripts, create_venv] - - . /etc/profile.d/modules.sh - - module load mpi/openmpi-$(arch) - - module list - script: - - !reference [.scripts, install_base] - - !reference [.scripts, compile_matrix] - - !reference [.scripts, model_tests] +# test_build: +# stage: test +# extends: +# - .image_gitlab_mpcdf_gcc_openmp +# - .rules_scheduled +# - .before_script_load_modules +# needs: [] +# script: +# - !reference [.scripts, create_venv] +# - !reference [.scripts, build] +# - pip install $(echo dist/struphy*.whl) --no-cache-dir --no-binary mpi4py -OpenSuse-latest: - stage: test - needs: [] - extends: - - .rules_scheduled - - .parallel_matrix_scheduled - - .requirements_opensuse - image: opensuse/tumbleweed:latest - script: - - !reference [.scripts, install] - - !reference [.scripts, compile_matrix] - - !reference [.scripts, model_tests] +# unit_tests_scheduled: +# stage: test +# extends: +# - .image_gitlab_mpcdf_gcc_openmp +# - .rules_scheduled +# - .parallel_matrix_scheduled +# - .before_script_load_modules +# script: +# - !reference [.scripts, source_env_matrix] +# - !reference [.scripts, unit_tests] -Opensuse-latest-from-registry: - stage: test - needs: [] - extends: - - .rules_scheduled - - .parallel_matrix_scheduled - image: gitlab-registry.mpcdf.mpg.de/struphy/struphy/opensuse-latest - before_script: - - !reference [.scripts, inspect_directory] - - set -x - - !reference [.scripts, create_venv] - script: - - !reference [.scripts, install] - - !reference [.scripts, compile_matrix] - - !reference [.scripts, model_tests] +# model_tests_scheduled: +# stage: test +# extends: +# - .image_gitlab_mpcdf_gcc_openmp +# - .rules_scheduled +# - .parallel_matrix_scheduled +# - .before_script_load_modules +# script: +# - !reference [.scripts, source_env_matrix] +# - !reference [.scripts, model_tests] -Opensuse-latest-from-registry-base: - stage: test - needs: [] - extends: - - .rules_scheduled - - .parallel_matrix_scheduled - image: gitlab-registry.mpcdf.mpg.de/struphy/struphy/opensuse-latest - before_script: - - !reference [.scripts, inspect_directory] - - set -x - - !reference [.scripts, create_venv] - script: - - !reference [.scripts, install_base] - - !reference [.scripts, compile_matrix] - - !reference [.scripts, model_tests] +# check_release_dependencies: +# stage: test +# extends: +# - .image_gitlab_mpcdf_gcc_openmp +# - .before_script_load_modules +# - .rules_mr_to_master +# script: +# - !reference [.scripts, inspect_directory] +# - !reference [.scripts, create_venv] +# - !reference [.scripts, install_all] +# - python src/struphy/utils/set_release_dependencies.py +# - | +# if git diff --exit-code pyproject.toml; then +# echo "pyproject.toml has not changed, dependencies are set correctly!" +# else +# echo "pyproject.toml has changed, dependencies are set incorrectly!" +# echo "Run python src/struphy/utils/set_release_dependencies.py to update pyproject.toml" +# exit 1 +# fi + +# Ubuntu-latest-from-registry: +# stage: test +# needs: [] +# extends: +# - .image_ubuntu_latest +# - .rules_scheduled +# - .parallel_matrix_scheduled +# before_script: +# - !reference [.scripts, inspect_directory] +# - !reference [.scripts, create_venv] +# script: +# - !reference [.scripts, install] +# - !reference [.scripts, compile_matrix] +# - !reference [.scripts, model_tests] -AlmaLinux-latest: - stage: test - needs: [] - extends: - - .rules_scheduled - - .parallel_matrix_scheduled - - .requirements_almalinux - image: almalinux:latest - script: - - !reference [.scripts, install_no_binary] - - !reference [.scripts, compile_matrix] - - !reference [.scripts, model_tests] +# Fedora-latest: +# stage: test +# needs: [] +# extends: +# - .rules_scheduled +# - .parallel_matrix_scheduled +# - .requirements_fedora +# image: fedora:latest +# script: +# - !reference [.scripts, install] +# - !reference [.scripts, compile_matrix] +# - !reference [.scripts, model_tests] -Almalinux-latest-from-registry: - stage: test - needs: [] - extends: - - .rules_scheduled - - .parallel_matrix_scheduled - image: gitlab-registry.mpcdf.mpg.de/struphy/struphy/almalinux-latest - before_script: - - !reference [.scripts, inspect_directory] - - python3 -m ensurepip --upgrade - - python3 -m pip install --upgrade pip - - !reference [.scripts, create_venv] - script: - - !reference [.scripts, install_no_binary] - - !reference [.scripts, compile_matrix] - - !reference [.scripts, model_tests] +# Fedora-latest-from-registry: +# stage: test +# needs: [] +# extends: +# - .rules_scheduled +# - .parallel_matrix_scheduled +# image: gitlab-registry.mpcdf.mpg.de/struphy/struphy/fedora-latest +# before_script: +# - !reference [.scripts, inspect_directory] +# - !reference [.scripts, create_venv] +# - . /etc/profile.d/modules.sh +# - module load mpi/openmpi-$(arch) +# - module list +# script: +# - !reference [.scripts, install] +# - !reference [.scripts, compile_matrix] +# - !reference [.scripts, model_tests] -Almalinux-latest-from-registry-base: - stage: test - needs: [] - extends: - - .rules_scheduled - - .parallel_matrix_scheduled - image: gitlab-registry.mpcdf.mpg.de/struphy/struphy/almalinux-latest - before_script: - - !reference [.scripts, inspect_directory] - - python3 -m ensurepip --upgrade - - python3 -m pip install --upgrade pip - - !reference [.scripts, create_venv] - script: - - !reference [.scripts, install_base_no_binary] - - !reference [.scripts, compile_matrix] - - !reference [.scripts, model_tests] +# Fedora-latest-from-registry-base: +# stage: test +# needs: [] +# extends: +# - .rules_scheduled +# - .parallel_matrix_scheduled +# image: gitlab-registry.mpcdf.mpg.de/struphy/struphy/fedora-latest +# before_script: +# - !reference [.scripts, inspect_directory] +# - !reference [.scripts, create_venv] +# - . /etc/profile.d/modules.sh +# - module load mpi/openmpi-$(arch) +# - module list +# script: +# - !reference [.scripts, install_base] +# - !reference [.scripts, compile_matrix] +# - !reference [.scripts, model_tests] -################## -### LINT STAGE ### -################## +# OpenSuse-latest: +# stage: test +# needs: [] +# extends: +# - .rules_scheduled +# - .parallel_matrix_scheduled +# - .requirements_opensuse +# image: opensuse/tumbleweed:latest +# script: +# - !reference [.scripts, install] +# - !reference [.scripts, compile_matrix] +# - !reference [.scripts, model_tests] -# Run in weekly CI pipeline only -lint_full_repo_report: - stage: lint - needs: [] - extends: - - .rules_scheduled - - .image_ubuntu_latest - script: - - !reference [.scripts, inspect_directory] - - !reference [.scripts, create_venv] - - pip install -e .[dev] # We have to install struphy in editable mode for struphy lint to work - - !reference [.scripts, inspect_struphy] - - struphy lint all --output-format report - allow_failure: true - artifacts: - expose_as: 'Branch lint report' - paths: - - code_analysis_report.html - expire_in: 1 month +# Opensuse-latest-from-registry: +# stage: test +# needs: [] +# extends: +# - .rules_scheduled +# - .parallel_matrix_scheduled +# image: gitlab-registry.mpcdf.mpg.de/struphy/struphy/opensuse-latest +# before_script: +# - !reference [.scripts, inspect_directory] +# - set -x +# - !reference [.scripts, create_venv] +# script: +# - !reference [.scripts, install] +# - !reference [.scripts, compile_matrix] +# - !reference [.scripts, model_tests] -# Lint struphy with `struphy lint` -lint_repo: - stage: lint - needs: [] - extends: - - .rules_mr_to_devel - - .image_ubuntu_latest - script: - - !reference [.scripts, inspect_directory] - - !reference [.scripts, create_venv] - - pip install -e .[dev] # We have to install struphy in editable mode for struphy lint to work - - !reference [.scripts, inspect_struphy] - # Lint all files in current branch, FAIL the CI pipeline if any files are incorrectly formatted - - struphy lint all --output-format plain --verbose - -# Lint struphy with `struphy lint` -lint_branch_report: - stage: lint - needs: [] - extends: - - .rules_mr_to_devel - - .image_ubuntu_latest - script: - - !reference [.scripts, inspect_directory] - - !reference [.scripts, create_venv] - - pip install -e .[dev] # We have to install struphy in editable mode for struphy lint to work - - !reference [.scripts, inspect_struphy] - - struphy lint branch --output-format report - allow_failure: true - artifacts: - expose_as: 'Branch lint report' - paths: - - code_analysis_report.html - expire_in: 1 month - -################### -### PAGES STAGE ### -################### -pages: - stage: pages - extends: - - .image_ubuntu_latest - - .rules_pages_release - before_script: - - !reference [.scripts, inspect_directory] - - !reference [.scripts, create_venv] - - apt show pandoc - - apt show graphviz - - echo $CI_COMMIT_MESSAGE - - pip install .[doc] - script: - - !reference [.scripts, inspect_struphy] - - !reference [.scripts, compile] - - cd doc ; make html - - mv _build/html/ $CI_PROJECT_DIR/public/ - artifacts: - name: 'pages' - paths: - - public/ +# Opensuse-latest-from-registry-base: +# stage: test +# needs: [] +# extends: +# - .rules_scheduled +# - .parallel_matrix_scheduled +# image: gitlab-registry.mpcdf.mpg.de/struphy/struphy/opensuse-latest +# before_script: +# - !reference [.scripts, inspect_directory] +# - set -x +# - !reference [.scripts, create_venv] +# script: +# - !reference [.scripts, install_base] +# - !reference [.scripts, compile_matrix] +# - !reference [.scripts, model_tests] -##################### -### RELEASE STAGE ### -##################### +# AlmaLinux-latest: +# stage: test +# needs: [] +# extends: +# - .rules_scheduled +# - .parallel_matrix_scheduled +# - .requirements_almalinux +# image: almalinux:latest +# script: +# - !reference [.scripts, install_no_binary] +# - !reference [.scripts, compile_matrix] +# - !reference [.scripts, model_tests] -deploy: - stage: release - extends: - - .rules_pypi_release - - .image_gitlab_mpcdf_gcc_openmp - - .before_script_load_modules - script: - - !reference [.scripts, create_venv] - - !reference [.scripts, build] - - pip install -U twine - - twine upload dist/* +# Almalinux-latest-from-registry: +# stage: test +# needs: [] +# extends: +# - .rules_scheduled +# - .parallel_matrix_scheduled +# image: gitlab-registry.mpcdf.mpg.de/struphy/struphy/almalinux-latest +# before_script: +# - !reference [.scripts, inspect_directory] +# - python3 -m ensurepip --upgrade +# - python3 -m pip install --upgrade pip +# - !reference [.scripts, create_venv] +# script: +# - !reference [.scripts, install_no_binary] +# - !reference [.scripts, compile_matrix] +# - !reference [.scripts, model_tests] -vars: - stage: release - extends: - - .rules_gitlab_release - before_script: - - !reference [.scripts, inspect_directory] - script: - - var=$(> vars.env - artifacts: - name: 'vars' - reports: - dotenv: vars.env - expire_in: 1 day +# Almalinux-latest-from-registry-base: +# stage: test +# needs: [] +# extends: +# - .rules_scheduled +# - .parallel_matrix_scheduled +# image: gitlab-registry.mpcdf.mpg.de/struphy/struphy/almalinux-latest +# before_script: +# - !reference [.scripts, inspect_directory] +# - python3 -m ensurepip --upgrade +# - python3 -m pip install --upgrade pip +# - !reference [.scripts, create_venv] +# script: +# - !reference [.scripts, install_base_no_binary] +# - !reference [.scripts, compile_matrix] +# - !reference [.scripts, model_tests] + +# ################## +# ### LINT STAGE ### +# ################## + +# # Run in weekly CI pipeline only +# lint_full_repo_report: +# stage: lint +# needs: [] +# extends: +# - .rules_scheduled +# - .image_ubuntu_latest +# script: +# - !reference [.scripts, inspect_directory] +# - !reference [.scripts, create_venv] +# - pip install -e .[dev] # We have to install struphy in editable mode for struphy lint to work +# - !reference [.scripts, inspect_struphy] +# - struphy lint all --output-format report +# allow_failure: true +# artifacts: +# expose_as: 'Branch lint report' +# paths: +# - code_analysis_report.html +# expire_in: 1 month + +# # Lint struphy with `struphy lint` +# lint_repo: +# stage: lint +# needs: [] +# extends: +# - .rules_mr_to_devel +# - .image_ubuntu_latest +# script: +# - !reference [.scripts, inspect_directory] +# - !reference [.scripts, create_venv] +# - pip install -e .[dev] # We have to install struphy in editable mode for struphy lint to work +# - !reference [.scripts, inspect_struphy] +# # Lint all files in current branch, FAIL the CI pipeline if any files are incorrectly formatted +# - struphy lint all --output-format plain --verbose + +# # Lint struphy with `struphy lint` +# lint_branch_report: +# stage: lint +# needs: [] +# extends: +# - .rules_mr_to_devel +# - .image_ubuntu_latest +# script: +# - !reference [.scripts, inspect_directory] +# - !reference [.scripts, create_venv] +# - pip install -e .[dev] # We have to install struphy in editable mode for struphy lint to work +# - !reference [.scripts, inspect_struphy] +# - struphy lint branch --output-format report +# allow_failure: true +# artifacts: +# expose_as: 'Branch lint report' +# paths: +# - code_analysis_report.html +# expire_in: 1 month + +# ################### +# ### PAGES STAGE ### +# ################### +# pages: +# stage: pages +# extends: +# - .image_ubuntu_latest +# - .rules_pages_release +# before_script: +# - !reference [.scripts, inspect_directory] +# - !reference [.scripts, create_venv] +# - apt show pandoc +# - apt show graphviz +# - echo $CI_COMMIT_MESSAGE +# - pip install .[doc] +# script: +# - !reference [.scripts, inspect_struphy] +# - !reference [.scripts, compile] +# - cd doc ; make html +# - mv _build/html/ $CI_PROJECT_DIR/public/ +# artifacts: +# name: 'pages' +# paths: +# - public/ + +# ##################### +# ### RELEASE STAGE ### +# ##################### + +# deploy: +# stage: release +# extends: +# - .rules_pypi_release +# - .image_gitlab_mpcdf_gcc_openmp +# - .before_script_load_modules +# script: +# - !reference [.scripts, create_venv] +# - !reference [.scripts, build] +# - pip install -U twine +# - twine upload dist/* -release_job: - stage: release - image: registry.gitlab.com/gitlab-org/release-cli:latest - extends: - - .rules_gitlab_release - needs: ['vars'] - before_script: - - !reference [.scripts, inspect_directory] - script: - - cat /etc/*-release - - echo $VERSION - release: # See https://docs.gitlab.com/ee/ci/yaml/#release for available properties - tag_name: 'v$VERSION' # The version is incremented per pipeline. - name: 'v$VERSION' - ref: '$CI_COMMIT_SHA' # The tag is created from the pipeline SHA. - description: 'CHANGELOG.md' - assets: - links: - - name: 'Documentation' - url: 'https://struphy.pages.mpcdf.de/struphy/index.html' - - name: 'PyPI' - url: 'https://pypi.org/project/struphy/' +# vars: +# stage: release +# extends: +# - .rules_gitlab_release +# before_script: +# - !reference [.scripts, inspect_directory] +# script: +# - var=$(> vars.env +# artifacts: +# name: 'vars' +# reports: +# dotenv: vars.env +# expire_in: 1 day + +# release_job: +# stage: release +# image: registry.gitlab.com/gitlab-org/release-cli:latest +# extends: +# - .rules_gitlab_release +# needs: ['vars'] +# before_script: +# - !reference [.scripts, inspect_directory] +# script: +# - cat /etc/*-release +# - echo $VERSION +# release: # See https://docs.gitlab.com/ee/ci/yaml/#release for available properties +# tag_name: 'v$VERSION' # The version is incremented per pipeline. +# name: 'v$VERSION' +# ref: '$CI_COMMIT_SHA' # The tag is created from the pipeline SHA. +# description: 'CHANGELOG.md' +# assets: +# links: +# - name: 'Documentation' +# url: 'https://struphy.pages.mpcdf.de/struphy/index.html' +# - name: 'PyPI' +# url: 'https://pypi.org/project/struphy/' From 45e91149554e7563b3df5e04a2327ee128403a3a Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 8 Oct 2025 19:44:48 +0200 Subject: [PATCH 28/76] Run src/struphy/xp.py --- .gitlab-ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 359c8952d..e3c48ab16 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -513,6 +513,9 @@ test_cupy: - nvidia-smi - python3 -m pip install --user cupy-cuda12x - python3 -c "import cupy as cp" + - python3 src/struphy/xp.py + - export ARRAY_BACKEND=cupy + - python3 src/struphy/xp.py # ##################### # ### PUSH PIPELINE ### From 65cb598e7f15d6bf23a9ca2763cc5321199788be Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 8 Oct 2025 19:53:45 +0200 Subject: [PATCH 29/76] Added src/struphy/test_xp.py --- .gitlab-ci.yml | 2 ++ src/struphy/test_xp.py | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 src/struphy/test_xp.py diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e3c48ab16..39b42662e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -514,8 +514,10 @@ test_cupy: - python3 -m pip install --user cupy-cuda12x - python3 -c "import cupy as cp" - python3 src/struphy/xp.py + - python3 python src/struphy/test_xp.py - export ARRAY_BACKEND=cupy - python3 src/struphy/xp.py + - python3 python src/struphy/test_xp.py # ##################### # ### PUSH PIPELINE ### diff --git a/src/struphy/test_xp.py b/src/struphy/test_xp.py new file mode 100644 index 000000000..82d312411 --- /dev/null +++ b/src/struphy/test_xp.py @@ -0,0 +1,24 @@ +from xp import xp +import time + +def main(N = 8192): + print(f"Creating {N}x{N} random matrices...") + + A = xp.random.rand(N, N) + B = xp.random.rand(N, N) + + print("Running matrix multiplication...") + t0 = time.perf_counter() + C = A @ B + t1 = time.perf_counter() + print(f"Matrix multiplication took {t1 - t0:.3f} seconds") + + print("Applying nonlinear transform...") + t0 = time.perf_counter() + D = xp.tanh(C * 0.01) + xp.exp(-C * 0.001) + + t1 = time.perf_counter() + print(f"Transformation took {t1 - t0:.3f} seconds") + +if __name__ == "__main__": + main() From 3043957945a27689beed2058d1651010a9879219 Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 8 Oct 2025 19:58:00 +0200 Subject: [PATCH 30/76] Bugfix --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 39b42662e..b4f488e5a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -514,10 +514,10 @@ test_cupy: - python3 -m pip install --user cupy-cuda12x - python3 -c "import cupy as cp" - python3 src/struphy/xp.py - - python3 python src/struphy/test_xp.py + - python3 src/struphy/test_xp.py - export ARRAY_BACKEND=cupy - python3 src/struphy/xp.py - - python3 python src/struphy/test_xp.py + - python3 src/struphy/test_xp.py # ##################### # ### PUSH PIPELINE ### From f397e7dcbf48cbf63b7e7aae200a99daa4e33f27 Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 8 Oct 2025 20:42:30 +0200 Subject: [PATCH 31/76] Updated prints --- src/struphy/test_xp.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/struphy/test_xp.py b/src/struphy/test_xp.py index 82d312411..79c893086 100644 --- a/src/struphy/test_xp.py +++ b/src/struphy/test_xp.py @@ -7,13 +7,13 @@ def main(N = 8192): A = xp.random.rand(N, N) B = xp.random.rand(N, N) - print("Running matrix multiplication...") + print("Running matrix multiplication: C = A @ B...") t0 = time.perf_counter() C = A @ B t1 = time.perf_counter() print(f"Matrix multiplication took {t1 - t0:.3f} seconds") - print("Applying nonlinear transform...") + print("Running D = xp.tanh(C * 0.01) + xp.exp(-C * 0.001)...") t0 = time.perf_counter() D = xp.tanh(C * 0.01) + xp.exp(-C * 0.001) From 5e5f8719bfa5729f98c1523e59d79878c4e138bd Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 8 Oct 2025 20:49:30 +0200 Subject: [PATCH 32/76] Added ArrayBackend class --- src/struphy/xp.py | 51 +++++++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 19 deletions(-) diff --git a/src/struphy/xp.py b/src/struphy/xp.py index e78273fad..d4a18d0d2 100644 --- a/src/struphy/xp.py +++ b/src/struphy/xp.py @@ -1,3 +1,4 @@ +import array import os # TODO: Make this configurable via environment variable or config file. @@ -5,29 +6,41 @@ _backend = os.getenv("ARRAY_BACKEND", "numpy").lower() -# TODO: Write an ArrayBackend class +class ArrayBackend: + def __init__(self, backend: str = "numpy") -> None: + self._backend = backend + pass -def _import_numpy(): - # print("importing numpy...") - import numpy as np + def _import_numpy(self): + import numpy as np - return np + return np + def _import_cupy(self): + # print("importing cupy...") + try: + import cupy as cp -def _import_cupy(): - # print("importing cupy...") - try: - import cupy as cp + return cp + except ImportError: + print("CuPy not available, falling back to NumPy.") + return self._import_numpy() - return cp - except ImportError: - print("CuPy not available, falling back to NumPy.") - return _import_numpy() + @property + def backend(self): + return self._backend -# Import numpy/cupy -if _backend == "cupy": - xp = _import_cupy() -else: - xp = _import_numpy() + @property + def xp(self): + # Import numpy/cupy + if _backend == "cupy": + return self._import_cupy() + else: + return self._import_numpy() -print(f"Using {xp.__name__} backend.") \ No newline at end of file + +array_backend = ArrayBackend(_backend) + +xp = array_backend.xp + +print(f"Using {xp} backend.") From fbc200ec3d8fa502dc3da5a3b84e01fa68230a51 Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 8 Oct 2025 21:27:44 +0200 Subject: [PATCH 33/76] Rewrite the class a bit to only import xp once in the init --- src/struphy/test_xp.py | 7 +++++-- src/struphy/xp.py | 45 +++++++++++++++++++----------------------- 2 files changed, 25 insertions(+), 27 deletions(-) diff --git a/src/struphy/test_xp.py b/src/struphy/test_xp.py index 79c893086..14a9b16fc 100644 --- a/src/struphy/test_xp.py +++ b/src/struphy/test_xp.py @@ -1,7 +1,9 @@ -from xp import xp import time -def main(N = 8192): +from xp import xp + + +def main(N=8192): print(f"Creating {N}x{N} random matrices...") A = xp.random.rand(N, N) @@ -20,5 +22,6 @@ def main(N = 8192): t1 = time.perf_counter() print(f"Transformation took {t1 - t0:.3f} seconds") + if __name__ == "__main__": main() diff --git a/src/struphy/xp.py b/src/struphy/xp.py index d4a18d0d2..61c39b8b1 100644 --- a/src/struphy/xp.py +++ b/src/struphy/xp.py @@ -1,46 +1,41 @@ -import array import os -# TODO: Make this configurable via environment variable or config file. -# Default to numpy -_backend = os.getenv("ARRAY_BACKEND", "numpy").lower() - class ArrayBackend: + def __init__(self, backend: str = "numpy") -> None: self._backend = backend - pass - def _import_numpy(self): - import numpy as np + # Import numpy/cupy + if self.backend == "cupy": + try: + import cupy as cp - return np + return cp + except ImportError: + print("CuPy not available, falling back to NumPy.") + self._backend = "numpy" - def _import_cupy(self): - # print("importing cupy...") - try: - import cupy as cp + if self.backend == "numpy": + import numpy as np - return cp - except ImportError: - print("CuPy not available, falling back to NumPy.") - return self._import_numpy() + self._xp = np + print(f"{self._xp = }") @property - def backend(self): + def backend(self) -> str: return self._backend @property def xp(self): - # Import numpy/cupy - if _backend == "cupy": - return self._import_cupy() - else: - return self._import_numpy() + return self._xp -array_backend = ArrayBackend(_backend) +# TODO: Make this configurable via environment variable or config file. +array_backend = ArrayBackend( + backend=os.getenv("ARRAY_BACKEND", "numpy").lower(), +) xp = array_backend.xp -print(f"Using {xp} backend.") +print(f"Using {xp.__name__} backend.") From 0c0ed2b8d2801a19f7929b42443cdc38134471f1 Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 8 Oct 2025 21:29:13 +0200 Subject: [PATCH 34/76] Formatting --- src/struphy/xp.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/struphy/xp.py b/src/struphy/xp.py index 61c39b8b1..6032387fd 100644 --- a/src/struphy/xp.py +++ b/src/struphy/xp.py @@ -2,7 +2,6 @@ class ArrayBackend: - def __init__(self, backend: str = "numpy") -> None: self._backend = backend From cd698c001282dc3e9135b40b711260821df7fcae Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 8 Oct 2025 21:31:22 +0200 Subject: [PATCH 35/76] Bugfix --- src/struphy/xp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/struphy/xp.py b/src/struphy/xp.py index 6032387fd..3cef15b40 100644 --- a/src/struphy/xp.py +++ b/src/struphy/xp.py @@ -10,7 +10,7 @@ def __init__(self, backend: str = "numpy") -> None: try: import cupy as cp - return cp + self._xp = cp except ImportError: print("CuPy not available, falling back to NumPy.") self._backend = "numpy" From d9fbee4af58750add8fe30904d6a9f3b535712ff Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 8 Oct 2025 21:54:15 +0200 Subject: [PATCH 36/76] Added typing magic so that autocompletion works with xp --- src/struphy/xp.py | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/struphy/xp.py b/src/struphy/xp.py index 3cef15b40..c5c46d6c5 100644 --- a/src/struphy/xp.py +++ b/src/struphy/xp.py @@ -1,8 +1,18 @@ import os +from types import ModuleType +from typing import TYPE_CHECKING, Literal + +from numpy import isin + +BackendType = Literal["numpy", "cupy"] class ArrayBackend: - def __init__(self, backend: str = "numpy") -> None: + def __init__( + self, + backend: BackendType = "numpy", + verbose: bool = False, + ) -> None: self._backend = backend # Import numpy/cupy @@ -10,23 +20,24 @@ def __init__(self, backend: str = "numpy") -> None: try: import cupy as cp - self._xp = cp + self._xp = cp except ImportError: - print("CuPy not available, falling back to NumPy.") + if verbose: + print("CuPy not available, falling back to NumPy.") self._backend = "numpy" if self.backend == "numpy": import numpy as np self._xp = np - print(f"{self._xp = }") @property - def backend(self) -> str: + def backend(self) -> BackendType: return self._backend @property - def xp(self): + def xp(self) -> ModuleType: + assert isinstance(self._xp, ModuleType) return self._xp @@ -35,6 +46,9 @@ def xp(self): backend=os.getenv("ARRAY_BACKEND", "numpy").lower(), ) -xp = array_backend.xp +if TYPE_CHECKING: + import numpy as xp +else: + xp = array_backend.xp print(f"Using {xp.__name__} backend.") From 0bc6867e4877fb2888ddcdb5702349981641ed51 Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 8 Oct 2025 22:12:04 +0200 Subject: [PATCH 37/76] xp --> arrays --- src/struphy/{xp.py => arrays.py} | 0 src/struphy/test_xp.py | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename src/struphy/{xp.py => arrays.py} (100%) diff --git a/src/struphy/xp.py b/src/struphy/arrays.py similarity index 100% rename from src/struphy/xp.py rename to src/struphy/arrays.py diff --git a/src/struphy/test_xp.py b/src/struphy/test_xp.py index 14a9b16fc..d32044a58 100644 --- a/src/struphy/test_xp.py +++ b/src/struphy/test_xp.py @@ -1,6 +1,6 @@ import time -from xp import xp +from arrays import xp def main(N=8192): From 6abb8d4dc008017727126a3f05e6830ac448664a Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 8 Oct 2025 22:18:25 +0200 Subject: [PATCH 38/76] Updated .gitlab-ci.yml --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b4f488e5a..94151413c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -513,10 +513,10 @@ test_cupy: - nvidia-smi - python3 -m pip install --user cupy-cuda12x - python3 -c "import cupy as cp" - - python3 src/struphy/xp.py + - python3 src/struphy/arrays.py - python3 src/struphy/test_xp.py - export ARRAY_BACKEND=cupy - - python3 src/struphy/xp.py + - python3 src/struphy/arrays.py - python3 src/struphy/test_xp.py # ##################### From c1ef5e2f8462ac769c601b52e2016aec22757c04 Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 9 Oct 2025 23:58:49 +0200 Subject: [PATCH 39/76] Replaced import numpy as np with from struphy.arrays import xp as np --- .gitlab-ci.yml | 4 ++-- src/struphy/bsplines/bsplines.py | 4 ++-- .../bsplines/tests/test_bsplines_kernels.py | 2 +- src/struphy/bsplines/tests/test_eval_spline_mpi.py | 2 +- src/struphy/console/profile.py | 2 +- src/struphy/diagnostics/console_diagn.py | 2 +- src/struphy/diagnostics/continuous_spectra.py | 4 ++-- src/struphy/diagnostics/diagn_tools.py | 2 +- src/struphy/diagnostics/paraview/mesh_creator.py | 2 +- src/struphy/dispersion_relations/analytic.py | 2 +- src/struphy/dispersion_relations/base.py | 2 +- src/struphy/dispersion_relations/utilities.py | 2 +- src/struphy/eigenvalue_solvers/derivatives.py | 2 +- .../legacy/MHD_eigenvalues_cylinder_1D.py | 2 +- .../legacy/control_variates/control_variate.py | 2 +- .../fB_massless_control_variate.py | 2 +- .../fnB_massless_control_variate.py | 2 +- .../kinetic_extended/massless_control_variate.py | 2 +- .../eigenvalue_solvers/legacy/emw_operators.py | 2 +- .../eigenvalue_solvers/legacy/inner_products_1d.py | 2 +- .../eigenvalue_solvers/legacy/inner_products_2d.py | 2 +- .../eigenvalue_solvers/legacy/inner_products_3d.py | 2 +- .../eigenvalue_solvers/legacy/l2_error_1d.py | 2 +- .../eigenvalue_solvers/legacy/l2_error_2d.py | 2 +- .../eigenvalue_solvers/legacy/l2_error_3d.py | 2 +- .../legacy/mass_matrices_3d_pre.py | 2 +- .../legacy/massless_operators/fB_arrays.py | 2 +- .../fB_massless_linear_operators.py | 2 +- .../legacy/massless_operators/fB_vv_kernel.py | 2 +- .../eigenvalue_solvers/legacy/mhd_operators_MF.py | 2 +- .../pro_local/mhd_operators_3d_local.py | 2 +- .../projectors_local/pro_local/projectors_local.py | 2 +- .../shape_function_projectors_L2.py | 2 +- .../shape_function_projectors_local.py | 2 +- src/struphy/eigenvalue_solvers/mass_matrices_1d.py | 2 +- src/struphy/eigenvalue_solvers/mass_matrices_2d.py | 2 +- src/struphy/eigenvalue_solvers/mass_matrices_3d.py | 2 +- .../eigenvalue_solvers/mhd_axisymmetric_main.py | 2 +- .../eigenvalue_solvers/mhd_axisymmetric_pproc.py | 2 +- src/struphy/eigenvalue_solvers/mhd_operators.py | 2 +- .../eigenvalue_solvers/mhd_operators_core.py | 2 +- .../eigenvalue_solvers/projectors_global.py | 2 +- src/struphy/eigenvalue_solvers/spline_space.py | 2 +- src/struphy/examples/_draw_parallel.py | 2 +- src/struphy/examples/restelli2018/callables.py | 2 +- src/struphy/feec/basis_projection_ops.py | 2 +- src/struphy/feec/linear_operators.py | 2 +- src/struphy/feec/mass.py | 2 +- src/struphy/feec/mass_kernels.py | 6 +++--- src/struphy/feec/preconditioner.py | 2 +- src/struphy/feec/projectors.py | 2 +- src/struphy/feec/psydac_derham.py | 2 +- src/struphy/feec/tests/test_basis_ops.py | 6 +++--- src/struphy/feec/tests/test_derham.py | 2 +- src/struphy/feec/tests/test_eval_field.py | 2 +- src/struphy/feec/tests/test_field_init.py | 8 ++++---- src/struphy/feec/tests/test_l2_projectors.py | 2 +- src/struphy/feec/tests/test_local_projectors.py | 2 +- src/struphy/feec/tests/test_lowdim_nel_is_1.py | 2 +- src/struphy/feec/tests/test_mass_matrices.py | 8 ++++---- src/struphy/feec/tests/test_toarray_struphy.py | 2 +- src/struphy/feec/tests/test_tosparse_struphy.py | 2 +- src/struphy/feec/tests/xx_test_preconds.py | 2 +- src/struphy/feec/utilities.py | 2 +- src/struphy/feec/utilities_local_projectors.py | 2 +- src/struphy/feec/variational_utilities.py | 2 +- src/struphy/fields_background/base.py | 2 +- src/struphy/fields_background/coil_fields/base.py | 2 +- .../fields_background/coil_fields/coil_fields.py | 2 +- src/struphy/fields_background/equils.py | 2 +- .../fields_background/tests/test_desc_equil.py | 2 +- .../fields_background/tests/test_generic_equils.py | 2 +- .../fields_background/tests/test_mhd_equils.py | 2 +- .../tests/test_numerical_mhd_equil.py | 2 +- src/struphy/geometry/base.py | 2 +- src/struphy/geometry/domains.py | 2 +- src/struphy/geometry/tests/test_domain.py | 12 ++++++------ src/struphy/geometry/utilities.py | 2 +- src/struphy/initial/eigenfunctions.py | 2 +- src/struphy/initial/perturbations.py | 2 +- .../initial/tests/test_init_perturbations.py | 2 +- src/struphy/initial/utilities.py | 2 +- src/struphy/io/output_handling.py | 2 +- src/struphy/io/setup.py | 2 +- src/struphy/kinetic_background/base.py | 2 +- src/struphy/kinetic_background/maxwellians.py | 2 +- src/struphy/kinetic_background/moment_functions.py | 2 +- src/struphy/kinetic_background/tests/test_base.py | 2 +- .../kinetic_background/tests/test_maxwellians.py | 14 +++++++------- src/struphy/linear_algebra/linalg_kron.py | 2 +- src/struphy/linear_algebra/saddle_point.py | 2 +- .../tests/test_saddlepoint_massmatrices.py | 4 ++-- .../tests/test_stencil_dot_kernels.py | 4 ++-- .../tests/test_stencil_transpose_kernels.py | 4 ++-- src/struphy/main.py | 2 +- src/struphy/models/base.py | 2 +- src/struphy/models/fluid.py | 2 +- src/struphy/models/hybrid.py | 2 +- src/struphy/models/kinetic.py | 2 +- src/struphy/models/tests/verification.py | 2 +- src/struphy/models/toy.py | 2 +- src/struphy/ode/solvers.py | 2 +- src/struphy/ode/tests/test_ode_feec.py | 2 +- src/struphy/ode/utils.py | 2 +- src/struphy/pic/accumulation/particles_to_grid.py | 2 +- src/struphy/pic/base.py | 2 +- src/struphy/pic/particles.py | 2 +- src/struphy/pic/pushing/pusher.py | 2 +- src/struphy/pic/sobol_seq.py | 2 +- src/struphy/pic/tests/test_accum_vec_H1.py | 2 +- src/struphy/pic/tests/test_accumulation.py | 2 +- src/struphy/pic/tests/test_binning.py | 8 ++++---- src/struphy/pic/tests/test_draw_parallel.py | 2 +- src/struphy/pic/tests/test_mat_vec_filler.py | 2 +- .../tests/test_pic_legacy_files/accumulation.py | 2 +- .../pic/tests/test_pic_legacy_files/pusher.py | 2 +- src/struphy/pic/tests/test_pushers.py | 12 ++++++------ src/struphy/pic/tests/test_sorting.py | 2 +- src/struphy/pic/tests/test_sph.py | 2 +- src/struphy/pic/tests/test_tesselation.py | 2 +- src/struphy/pic/utilities.py | 2 +- src/struphy/polar/basic.py | 2 +- src/struphy/polar/extraction_operators.py | 2 +- src/struphy/polar/linear_operators.py | 2 +- .../polar/tests/test_legacy_polar_splines.py | 2 +- src/struphy/polar/tests/test_polar.py | 4 ++-- .../post_processing/likwid/plot_likwidproject.py | 2 +- .../post_processing/likwid/plot_time_traces.py | 2 +- .../post_processing/likwid/roofline_plotter.py | 2 +- src/struphy/post_processing/orbits/orbits_tools.py | 2 +- .../post_processing/post_processing_tools.py | 2 +- src/struphy/post_processing/pproc_struphy.py | 2 +- src/struphy/post_processing/profile_struphy.py | 2 +- src/struphy/profiling/profiling.py | 2 +- src/struphy/propagators/base.py | 2 +- src/struphy/propagators/propagators_coupling.py | 2 +- src/struphy/propagators/propagators_fields.py | 2 +- src/struphy/propagators/propagators_markers.py | 12 ++++++------ .../propagators/tests/test_gyrokinetic_poisson.py | 2 +- src/struphy/propagators/tests/test_poisson.py | 2 +- src/struphy/utils/clone_config.py | 2 +- src/struphy/utils/utils.py | 2 +- 142 files changed, 183 insertions(+), 183 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b4f488e5a..94151413c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -513,10 +513,10 @@ test_cupy: - nvidia-smi - python3 -m pip install --user cupy-cuda12x - python3 -c "import cupy as cp" - - python3 src/struphy/xp.py + - python3 src/struphy/arrays.py - python3 src/struphy/test_xp.py - export ARRAY_BACKEND=cupy - - python3 src/struphy/xp.py + - python3 src/struphy/arrays.py - python3 src/struphy/test_xp.py # ##################### diff --git a/src/struphy/bsplines/bsplines.py b/src/struphy/bsplines/bsplines.py index 31738fe74..b02e60854 100644 --- a/src/struphy/bsplines/bsplines.py +++ b/src/struphy/bsplines/bsplines.py @@ -16,7 +16,7 @@ """ -import numpy as np +from struphy.arrays import xp as np __all__ = [ "find_span", @@ -533,7 +533,7 @@ def elements_spans(knots, degree): Examples -------- - >>> import numpy as np + >>> from struphy.arrays import xp as np >>> from psydac.core.bsplines import make_knots, elements_spans >>> p = 3 ; n = 8 diff --git a/src/struphy/bsplines/tests/test_bsplines_kernels.py b/src/struphy/bsplines/tests/test_bsplines_kernels.py index 96e3a0a21..49504b169 100644 --- a/src/struphy/bsplines/tests/test_bsplines_kernels.py +++ b/src/struphy/bsplines/tests/test_bsplines_kernels.py @@ -1,6 +1,6 @@ import time -import numpy as np +from struphy.arrays import xp as np import pytest from mpi4py import MPI diff --git a/src/struphy/bsplines/tests/test_eval_spline_mpi.py b/src/struphy/bsplines/tests/test_eval_spline_mpi.py index 2c00eb459..d1135c6e0 100644 --- a/src/struphy/bsplines/tests/test_eval_spline_mpi.py +++ b/src/struphy/bsplines/tests/test_eval_spline_mpi.py @@ -1,7 +1,7 @@ from sys import int_info from time import sleep -import numpy as np +from struphy.arrays import xp as np import pytest from mpi4py import MPI diff --git a/src/struphy/console/profile.py b/src/struphy/console/profile.py index 76f7d1322..ee0e39920 100644 --- a/src/struphy/console/profile.py +++ b/src/struphy/console/profile.py @@ -6,7 +6,7 @@ def struphy_profile(dirs, replace, all, n_lines, print_callers, savefig): import os import pickle - import numpy as np + from struphy.arrays import xp as np import yaml from matplotlib import pyplot as plt diff --git a/src/struphy/diagnostics/console_diagn.py b/src/struphy/diagnostics/console_diagn.py index 81be7bb38..4d0061442 100644 --- a/src/struphy/diagnostics/console_diagn.py +++ b/src/struphy/diagnostics/console_diagn.py @@ -6,7 +6,7 @@ import subprocess import h5py -import numpy as np +from struphy.arrays import xp as np import yaml import struphy diff --git a/src/struphy/diagnostics/continuous_spectra.py b/src/struphy/diagnostics/continuous_spectra.py index ec52b4744..ad791dfa8 100644 --- a/src/struphy/diagnostics/continuous_spectra.py +++ b/src/struphy/diagnostics/continuous_spectra.py @@ -37,7 +37,7 @@ def get_mhd_continua_2d(space, domain, omega2, U_eig, m_range, omega_A, div_tol, the radial location s_spec[m][0], squared eigenfrequencis s_spec[m][1] and global mode index s_spec[m][2] corresponding to slow sound modes for each poloidal mode number m in m_range. """ - import numpy as np + from struphy.arrays import xp as np import struphy.bsplines.bsplines as bsp @@ -152,7 +152,7 @@ def get_mhd_continua_2d(space, domain, omega2, U_eig, m_range, omega_A, div_tol, import os import shutil - import numpy as np + from struphy.arrays import xp as np import yaml # parse arguments diff --git a/src/struphy/diagnostics/diagn_tools.py b/src/struphy/diagnostics/diagn_tools.py index 7a2005482..8b937b1c8 100644 --- a/src/struphy/diagnostics/diagn_tools.py +++ b/src/struphy/diagnostics/diagn_tools.py @@ -5,7 +5,7 @@ import matplotlib.colors as colors import matplotlib.pyplot as plt -import numpy as np +from struphy.arrays import xp as np from scipy.fft import fftfreq, fftn from scipy.signal import argrelextrema from tqdm import tqdm diff --git a/src/struphy/diagnostics/paraview/mesh_creator.py b/src/struphy/diagnostics/paraview/mesh_creator.py index aad81c3ba..c994d7908 100644 --- a/src/struphy/diagnostics/paraview/mesh_creator.py +++ b/src/struphy/diagnostics/paraview/mesh_creator.py @@ -1,4 +1,4 @@ -import numpy as np +from struphy.arrays import xp as np # from tqdm import tqdm import vtkmodules.all as vtk diff --git a/src/struphy/dispersion_relations/analytic.py b/src/struphy/dispersion_relations/analytic.py index f68ca5774..c203aa99c 100644 --- a/src/struphy/dispersion_relations/analytic.py +++ b/src/struphy/dispersion_relations/analytic.py @@ -1,6 +1,6 @@ "Analytic dispersion relations." -import numpy as np +from struphy.arrays import xp as np from numpy.polynomial import Polynomial from scipy.optimize import fsolve diff --git a/src/struphy/dispersion_relations/base.py b/src/struphy/dispersion_relations/base.py index 1700955c2..8b213549d 100644 --- a/src/struphy/dispersion_relations/base.py +++ b/src/struphy/dispersion_relations/base.py @@ -2,7 +2,7 @@ from abc import ABCMeta, abstractmethod -import numpy as np +from struphy.arrays import xp as np from matplotlib import pyplot as plt diff --git a/src/struphy/dispersion_relations/utilities.py b/src/struphy/dispersion_relations/utilities.py index 40c2b57f0..c26ecb271 100644 --- a/src/struphy/dispersion_relations/utilities.py +++ b/src/struphy/dispersion_relations/utilities.py @@ -1,4 +1,4 @@ -import numpy as np +from struphy.arrays import xp as np from scipy.special import erfi diff --git a/src/struphy/eigenvalue_solvers/derivatives.py b/src/struphy/eigenvalue_solvers/derivatives.py index 122dade81..9ec0529ed 100644 --- a/src/struphy/eigenvalue_solvers/derivatives.py +++ b/src/struphy/eigenvalue_solvers/derivatives.py @@ -6,7 +6,7 @@ Modules to assemble discrete derivatives. """ -import numpy as np +from struphy.arrays import xp as np import scipy.sparse as spa diff --git a/src/struphy/eigenvalue_solvers/legacy/MHD_eigenvalues_cylinder_1D.py b/src/struphy/eigenvalue_solvers/legacy/MHD_eigenvalues_cylinder_1D.py index 4d2bd5fa2..d86000069 100644 --- a/src/struphy/eigenvalue_solvers/legacy/MHD_eigenvalues_cylinder_1D.py +++ b/src/struphy/eigenvalue_solvers/legacy/MHD_eigenvalues_cylinder_1D.py @@ -1,4 +1,4 @@ -import numpy as np +from struphy.arrays import xp as np import scipy as sc import scipy.sparse as spa import scipy.special as sp diff --git a/src/struphy/eigenvalue_solvers/legacy/control_variates/control_variate.py b/src/struphy/eigenvalue_solvers/legacy/control_variates/control_variate.py index ca5134edc..f5df27d77 100644 --- a/src/struphy/eigenvalue_solvers/legacy/control_variates/control_variate.py +++ b/src/struphy/eigenvalue_solvers/legacy/control_variates/control_variate.py @@ -6,7 +6,7 @@ Class for control variates in delta-f method for current coupling scheme. """ -import numpy as np +from struphy.arrays import xp as np import scipy.sparse as spa import struphy.feec.basics.kernels_3d as ker diff --git a/src/struphy/eigenvalue_solvers/legacy/control_variates/kinetic_extended/fB_massless_control_variate.py b/src/struphy/eigenvalue_solvers/legacy/control_variates/kinetic_extended/fB_massless_control_variate.py index 562df0691..b0872c07b 100644 --- a/src/struphy/eigenvalue_solvers/legacy/control_variates/kinetic_extended/fB_massless_control_variate.py +++ b/src/struphy/eigenvalue_solvers/legacy/control_variates/kinetic_extended/fB_massless_control_variate.py @@ -1,4 +1,4 @@ -import numpy as np +from struphy.arrays import xp as np import scipy.sparse as spa import struphy.feec.basics.kernels_3d as ker diff --git a/src/struphy/eigenvalue_solvers/legacy/control_variates/kinetic_extended/fnB_massless_control_variate.py b/src/struphy/eigenvalue_solvers/legacy/control_variates/kinetic_extended/fnB_massless_control_variate.py index f0279fbcf..b3906fa69 100644 --- a/src/struphy/eigenvalue_solvers/legacy/control_variates/kinetic_extended/fnB_massless_control_variate.py +++ b/src/struphy/eigenvalue_solvers/legacy/control_variates/kinetic_extended/fnB_massless_control_variate.py @@ -1,6 +1,6 @@ import hylife.utilitis_FEEC.basics.kernels_3d as ker import hylife.utilitis_FEEC.control_variates.fnB_massless_kernels_control_variate as ker_cv -import numpy as np +from struphy.arrays import xp as np import scipy.sparse as spa diff --git a/src/struphy/eigenvalue_solvers/legacy/control_variates/kinetic_extended/massless_control_variate.py b/src/struphy/eigenvalue_solvers/legacy/control_variates/kinetic_extended/massless_control_variate.py index 09deb07f1..5aa74841b 100644 --- a/src/struphy/eigenvalue_solvers/legacy/control_variates/kinetic_extended/massless_control_variate.py +++ b/src/struphy/eigenvalue_solvers/legacy/control_variates/kinetic_extended/massless_control_variate.py @@ -1,6 +1,6 @@ import hylife.utilitis_FEEC.basics.kernels_3d as ker import hylife.utilitis_FEEC.control_variates.massless_kernels_control_variate as ker_cv -import numpy as np +from struphy.arrays import xp as np import scipy.sparse as spa diff --git a/src/struphy/eigenvalue_solvers/legacy/emw_operators.py b/src/struphy/eigenvalue_solvers/legacy/emw_operators.py index 171ad21f8..ab99918dd 100755 --- a/src/struphy/eigenvalue_solvers/legacy/emw_operators.py +++ b/src/struphy/eigenvalue_solvers/legacy/emw_operators.py @@ -6,7 +6,7 @@ Class for 2D/3D linear MHD projection operators. """ -import numpy as np +from struphy.arrays import xp as np import scipy.sparse as spa import struphy.eigenvalue_solvers.kernels_3d as ker diff --git a/src/struphy/eigenvalue_solvers/legacy/inner_products_1d.py b/src/struphy/eigenvalue_solvers/legacy/inner_products_1d.py index c894496b5..8451ef01a 100644 --- a/src/struphy/eigenvalue_solvers/legacy/inner_products_1d.py +++ b/src/struphy/eigenvalue_solvers/legacy/inner_products_1d.py @@ -6,7 +6,7 @@ Modules to compute inner products in 1d. """ -import numpy as np +from struphy.arrays import xp as np import scipy.sparse as spa diff --git a/src/struphy/eigenvalue_solvers/legacy/inner_products_2d.py b/src/struphy/eigenvalue_solvers/legacy/inner_products_2d.py index ab8ce9f04..9ac13af21 100644 --- a/src/struphy/eigenvalue_solvers/legacy/inner_products_2d.py +++ b/src/struphy/eigenvalue_solvers/legacy/inner_products_2d.py @@ -6,7 +6,7 @@ Modules to compute inner products with given functions in 2D. """ -import numpy as np +from struphy.arrays import xp as np import scipy.sparse as spa import struphy.eigenvalue_solvers.kernels_2d as ker diff --git a/src/struphy/eigenvalue_solvers/legacy/inner_products_3d.py b/src/struphy/eigenvalue_solvers/legacy/inner_products_3d.py index 29394e7e8..e806fb420 100644 --- a/src/struphy/eigenvalue_solvers/legacy/inner_products_3d.py +++ b/src/struphy/eigenvalue_solvers/legacy/inner_products_3d.py @@ -6,7 +6,7 @@ Modules to compute inner products with given functions in 3D. """ -import numpy as np +from struphy.arrays import xp as np import scipy.sparse as spa import struphy.eigenvalue_solvers.kernels_3d as ker diff --git a/src/struphy/eigenvalue_solvers/legacy/l2_error_1d.py b/src/struphy/eigenvalue_solvers/legacy/l2_error_1d.py index 3fcc3d55f..ecd609c31 100644 --- a/src/struphy/eigenvalue_solvers/legacy/l2_error_1d.py +++ b/src/struphy/eigenvalue_solvers/legacy/l2_error_1d.py @@ -6,7 +6,7 @@ Modules to compute L2-errors in 1d. """ -import numpy as np +from struphy.arrays import xp as np import scipy.sparse as spa diff --git a/src/struphy/eigenvalue_solvers/legacy/l2_error_2d.py b/src/struphy/eigenvalue_solvers/legacy/l2_error_2d.py index f7224061b..f29e75d48 100644 --- a/src/struphy/eigenvalue_solvers/legacy/l2_error_2d.py +++ b/src/struphy/eigenvalue_solvers/legacy/l2_error_2d.py @@ -6,7 +6,7 @@ Modules to compute L2-errors of discrete p-forms with analytical forms in 2D. """ -import numpy as np +from struphy.arrays import xp as np import scipy.sparse as spa import struphy.eigenvalue_solvers.kernels_2d as ker diff --git a/src/struphy/eigenvalue_solvers/legacy/l2_error_3d.py b/src/struphy/eigenvalue_solvers/legacy/l2_error_3d.py index bc246310a..efe860064 100644 --- a/src/struphy/eigenvalue_solvers/legacy/l2_error_3d.py +++ b/src/struphy/eigenvalue_solvers/legacy/l2_error_3d.py @@ -6,7 +6,7 @@ Modules to compute L2-errors of discrete p-forms with analytical forms in 3D. """ -import numpy as np +from struphy.arrays import xp as np import scipy.sparse as spa import struphy.eigenvalue_solvers.kernels_3d as ker diff --git a/src/struphy/eigenvalue_solvers/legacy/mass_matrices_3d_pre.py b/src/struphy/eigenvalue_solvers/legacy/mass_matrices_3d_pre.py index 3b6d2a31b..ac7b19a23 100644 --- a/src/struphy/eigenvalue_solvers/legacy/mass_matrices_3d_pre.py +++ b/src/struphy/eigenvalue_solvers/legacy/mass_matrices_3d_pre.py @@ -6,7 +6,7 @@ Modules to obtain preconditioners for mass matrices in 3D. """ -import numpy as np +from struphy.arrays import xp as np import scipy.sparse as spa import struphy.eigenvalue_solvers.spline_space as spl diff --git a/src/struphy/eigenvalue_solvers/legacy/massless_operators/fB_arrays.py b/src/struphy/eigenvalue_solvers/legacy/massless_operators/fB_arrays.py index 7705da576..b0ab5f566 100644 --- a/src/struphy/eigenvalue_solvers/legacy/massless_operators/fB_arrays.py +++ b/src/struphy/eigenvalue_solvers/legacy/massless_operators/fB_arrays.py @@ -1,7 +1,7 @@ import time import timeit -import numpy as np +from struphy.arrays import xp as np import scipy.sparse as spa from mpi4py import MPI diff --git a/src/struphy/eigenvalue_solvers/legacy/massless_operators/fB_massless_linear_operators.py b/src/struphy/eigenvalue_solvers/legacy/massless_operators/fB_massless_linear_operators.py index a26a22679..1012ee1ff 100644 --- a/src/struphy/eigenvalue_solvers/legacy/massless_operators/fB_massless_linear_operators.py +++ b/src/struphy/eigenvalue_solvers/legacy/massless_operators/fB_massless_linear_operators.py @@ -1,6 +1,6 @@ import time -import numpy as np +from struphy.arrays import xp as np import scipy.sparse as spa import struphy.feec.massless_operators.fB_bb_kernel as bb_kernel diff --git a/src/struphy/eigenvalue_solvers/legacy/massless_operators/fB_vv_kernel.py b/src/struphy/eigenvalue_solvers/legacy/massless_operators/fB_vv_kernel.py index 7adfaf080..1c99ce628 100644 --- a/src/struphy/eigenvalue_solvers/legacy/massless_operators/fB_vv_kernel.py +++ b/src/struphy/eigenvalue_solvers/legacy/massless_operators/fB_vv_kernel.py @@ -1,4 +1,4 @@ -import numpy as np +from struphy.arrays import xp as np from numpy import empty, exp, floor, zeros import struphy.bsplines.bsplines_kernels as bsp diff --git a/src/struphy/eigenvalue_solvers/legacy/mhd_operators_MF.py b/src/struphy/eigenvalue_solvers/legacy/mhd_operators_MF.py index 6cdfc04b1..89737bb10 100644 --- a/src/struphy/eigenvalue_solvers/legacy/mhd_operators_MF.py +++ b/src/struphy/eigenvalue_solvers/legacy/mhd_operators_MF.py @@ -1,4 +1,4 @@ -import numpy as np +from struphy.arrays import xp as np import scipy.sparse as spa from struphy.eigenvalue_solvers.projectors_global import Projectors_tensor_3d diff --git a/src/struphy/eigenvalue_solvers/legacy/projectors_local/pro_local/mhd_operators_3d_local.py b/src/struphy/eigenvalue_solvers/legacy/projectors_local/pro_local/mhd_operators_3d_local.py index aef91b87d..7d9e27cb7 100644 --- a/src/struphy/eigenvalue_solvers/legacy/projectors_local/pro_local/mhd_operators_3d_local.py +++ b/src/struphy/eigenvalue_solvers/legacy/projectors_local/pro_local/mhd_operators_3d_local.py @@ -8,7 +8,7 @@ import sys -import numpy as np +from struphy.arrays import xp as np import scipy.sparse as spa import source_run.kernels_projectors_evaluation as ker_eva diff --git a/src/struphy/eigenvalue_solvers/legacy/projectors_local/pro_local/projectors_local.py b/src/struphy/eigenvalue_solvers/legacy/projectors_local/pro_local/projectors_local.py index f7f880f2b..247857d5f 100644 --- a/src/struphy/eigenvalue_solvers/legacy/projectors_local/pro_local/projectors_local.py +++ b/src/struphy/eigenvalue_solvers/legacy/projectors_local/pro_local/projectors_local.py @@ -6,7 +6,7 @@ Classes for local projectors in 1D and 3D based on quasi-spline interpolation and histopolation. """ -import numpy as np +from struphy.arrays import xp as np import scipy.sparse as spa import struphy.feec.bsplines as bsp diff --git a/src/struphy/eigenvalue_solvers/legacy/projectors_local/shape_pro_local/shape_function_projectors_L2.py b/src/struphy/eigenvalue_solvers/legacy/projectors_local/shape_pro_local/shape_function_projectors_L2.py index c1ae9e9f6..61426fe24 100644 --- a/src/struphy/eigenvalue_solvers/legacy/projectors_local/shape_pro_local/shape_function_projectors_L2.py +++ b/src/struphy/eigenvalue_solvers/legacy/projectors_local/shape_pro_local/shape_function_projectors_L2.py @@ -5,7 +5,7 @@ Classes for local projectors in 1D and 3D based on quasi-spline interpolation and histopolation. """ -import numpy as np +from struphy.arrays import xp as np import scipy.sparse as spa from mpi4py import MPI diff --git a/src/struphy/eigenvalue_solvers/legacy/projectors_local/shape_pro_local/shape_function_projectors_local.py b/src/struphy/eigenvalue_solvers/legacy/projectors_local/shape_pro_local/shape_function_projectors_local.py index d361075e3..f369349d8 100644 --- a/src/struphy/eigenvalue_solvers/legacy/projectors_local/shape_pro_local/shape_function_projectors_local.py +++ b/src/struphy/eigenvalue_solvers/legacy/projectors_local/shape_pro_local/shape_function_projectors_local.py @@ -5,7 +5,7 @@ Classes for local projectors in 1D and 3D based on quasi-spline interpolation and histopolation. """ -import numpy as np +from struphy.arrays import xp as np import scipy.sparse as spa from mpi4py import MPI diff --git a/src/struphy/eigenvalue_solvers/mass_matrices_1d.py b/src/struphy/eigenvalue_solvers/mass_matrices_1d.py index 4af163bc4..792a0dceb 100644 --- a/src/struphy/eigenvalue_solvers/mass_matrices_1d.py +++ b/src/struphy/eigenvalue_solvers/mass_matrices_1d.py @@ -2,7 +2,7 @@ # # Copyright 2020 Florian Holderied -import numpy as np +from struphy.arrays import xp as np import scipy.sparse as spa import struphy.bsplines.bsplines as bsp diff --git a/src/struphy/eigenvalue_solvers/mass_matrices_2d.py b/src/struphy/eigenvalue_solvers/mass_matrices_2d.py index 4e62c6c72..8e26569c8 100644 --- a/src/struphy/eigenvalue_solvers/mass_matrices_2d.py +++ b/src/struphy/eigenvalue_solvers/mass_matrices_2d.py @@ -2,7 +2,7 @@ # # Copyright 2020 Florian Holderied -import numpy as np +from struphy.arrays import xp as np import scipy.sparse as spa import struphy.eigenvalue_solvers.kernels_2d as ker diff --git a/src/struphy/eigenvalue_solvers/mass_matrices_3d.py b/src/struphy/eigenvalue_solvers/mass_matrices_3d.py index d77052727..7b286d8ba 100644 --- a/src/struphy/eigenvalue_solvers/mass_matrices_3d.py +++ b/src/struphy/eigenvalue_solvers/mass_matrices_3d.py @@ -2,7 +2,7 @@ # # Copyright 2020 Florian Holderied (florian.holderied@ipp.mpg.de) -import numpy as np +from struphy.arrays import xp as np import scipy.sparse as spa import struphy.eigenvalue_solvers.kernels_3d as ker diff --git a/src/struphy/eigenvalue_solvers/mhd_axisymmetric_main.py b/src/struphy/eigenvalue_solvers/mhd_axisymmetric_main.py index 3810f1d60..cd6bf9810 100644 --- a/src/struphy/eigenvalue_solvers/mhd_axisymmetric_main.py +++ b/src/struphy/eigenvalue_solvers/mhd_axisymmetric_main.py @@ -32,7 +32,7 @@ def solve_mhd_ev_problem_2d(num_params, eq_mhd, n_tor, basis_tor="i", path_out=N import os import time - import numpy as np + from struphy.arrays import xp as np import scipy.sparse as spa from struphy.eigenvalue_solvers.mhd_operators import MHDOperators diff --git a/src/struphy/eigenvalue_solvers/mhd_axisymmetric_pproc.py b/src/struphy/eigenvalue_solvers/mhd_axisymmetric_pproc.py index 75a116c09..1678b66db 100644 --- a/src/struphy/eigenvalue_solvers/mhd_axisymmetric_pproc.py +++ b/src/struphy/eigenvalue_solvers/mhd_axisymmetric_pproc.py @@ -3,7 +3,7 @@ def main(): import argparse import os - import numpy as np + from struphy.arrays import xp as np import yaml # parse arguments diff --git a/src/struphy/eigenvalue_solvers/mhd_operators.py b/src/struphy/eigenvalue_solvers/mhd_operators.py index 22355c1c9..3edaf1e88 100644 --- a/src/struphy/eigenvalue_solvers/mhd_operators.py +++ b/src/struphy/eigenvalue_solvers/mhd_operators.py @@ -3,7 +3,7 @@ # Copyright 2021 Florian Holderied (florian.holderied@ipp.mpg.de) -import numpy as np +from struphy.arrays import xp as np import scipy.sparse as spa import struphy.eigenvalue_solvers.legacy.mass_matrices_3d_pre as mass_3d_pre diff --git a/src/struphy/eigenvalue_solvers/mhd_operators_core.py b/src/struphy/eigenvalue_solvers/mhd_operators_core.py index a8c23e3c7..17c0341b5 100644 --- a/src/struphy/eigenvalue_solvers/mhd_operators_core.py +++ b/src/struphy/eigenvalue_solvers/mhd_operators_core.py @@ -3,7 +3,7 @@ # Copyright 2021 Florian Holderied (florian.holderied@ipp.mpg.de) -import numpy as np +from struphy.arrays import xp as np import scipy.sparse as spa import struphy.eigenvalue_solvers.kernels_projectors_global_mhd as ker diff --git a/src/struphy/eigenvalue_solvers/projectors_global.py b/src/struphy/eigenvalue_solvers/projectors_global.py index df9080f01..fd27f16a4 100644 --- a/src/struphy/eigenvalue_solvers/projectors_global.py +++ b/src/struphy/eigenvalue_solvers/projectors_global.py @@ -6,7 +6,7 @@ Classes for commuting projectors in 1D, 2D and 3D based on global spline interpolation and histopolation. """ -import numpy as np +from struphy.arrays import xp as np import scipy.sparse as spa import struphy.bsplines.bsplines as bsp diff --git a/src/struphy/eigenvalue_solvers/spline_space.py b/src/struphy/eigenvalue_solvers/spline_space.py index a4239af46..8e762e94a 100644 --- a/src/struphy/eigenvalue_solvers/spline_space.py +++ b/src/struphy/eigenvalue_solvers/spline_space.py @@ -7,7 +7,7 @@ """ import matplotlib -import numpy as np +from struphy.arrays import xp as np import scipy.sparse as spa matplotlib.rcParams.update({"font.size": 16}) diff --git a/src/struphy/examples/_draw_parallel.py b/src/struphy/examples/_draw_parallel.py index 040e55c65..894cf999f 100644 --- a/src/struphy/examples/_draw_parallel.py +++ b/src/struphy/examples/_draw_parallel.py @@ -1,4 +1,4 @@ -import numpy as np +from struphy.arrays import xp as np from mpi4py import MPI from struphy.feec.psydac_derham import Derham diff --git a/src/struphy/examples/restelli2018/callables.py b/src/struphy/examples/restelli2018/callables.py index 89ce4bfda..4f9dddb0e 100644 --- a/src/struphy/examples/restelli2018/callables.py +++ b/src/struphy/examples/restelli2018/callables.py @@ -1,6 +1,6 @@ "Analytical callables needed for the simulation of the Two-Fluid Quasi-Neutral Model by Restelli." -import numpy as np +from struphy.arrays import xp as np class RestelliForcingTerm: diff --git a/src/struphy/feec/basis_projection_ops.py b/src/struphy/feec/basis_projection_ops.py index b335edea5..1ee02f74a 100644 --- a/src/struphy/feec/basis_projection_ops.py +++ b/src/struphy/feec/basis_projection_ops.py @@ -1,4 +1,4 @@ -import numpy as np +from struphy.arrays import xp as np from mpi4py import MPI from psydac.api.settings import PSYDAC_BACKEND_GPYCCEL from psydac.fem.basic import FemSpace diff --git a/src/struphy/feec/linear_operators.py b/src/struphy/feec/linear_operators.py index d0413b292..695e5ec22 100644 --- a/src/struphy/feec/linear_operators.py +++ b/src/struphy/feec/linear_operators.py @@ -1,7 +1,7 @@ import itertools from abc import abstractmethod -import numpy as np +from struphy.arrays import xp as np from mpi4py import MPI from psydac.linalg.basic import LinearOperator, Vector, VectorSpace from psydac.linalg.block import BlockVectorSpace diff --git a/src/struphy/feec/mass.py b/src/struphy/feec/mass.py index 9d5531e98..f309c4973 100644 --- a/src/struphy/feec/mass.py +++ b/src/struphy/feec/mass.py @@ -1,6 +1,6 @@ import inspect -import numpy as np +from struphy.arrays import xp as np from mpi4py import MPI from psydac.api.settings import PSYDAC_BACKEND_GPYCCEL from psydac.fem.tensor import TensorFemSpace diff --git a/src/struphy/feec/mass_kernels.py b/src/struphy/feec/mass_kernels.py index f5fc6926b..f31175cf0 100644 --- a/src/struphy/feec/mass_kernels.py +++ b/src/struphy/feec/mass_kernels.py @@ -314,7 +314,7 @@ def kernel_3d_mat( The results are written into data (attention: data is NOT set to zero first, but the results are added to data). """ - import numpy as np + from struphy.arrays import xp as np ne1 = spans1.size ne2 = spans2.size @@ -575,7 +575,7 @@ def kernel_3d_matrixfree( The results are written into data (attention: data is NOT set to zero first, but the results are added to data). """ - import numpy as np + from struphy.arrays import xp as np ne1 = spansi1.size ne2 = spansi2.size @@ -692,7 +692,7 @@ def kernel_3d_diag( The results are written into data (attention: data is NOT set to zero first, but the results are added to data). """ - import numpy as np + from struphy.arrays import xp as np ne1 = spans1.size ne2 = spans2.size diff --git a/src/struphy/feec/preconditioner.py b/src/struphy/feec/preconditioner.py index eab61c930..38de94f6f 100644 --- a/src/struphy/feec/preconditioner.py +++ b/src/struphy/feec/preconditioner.py @@ -1,4 +1,4 @@ -import numpy as np +from struphy.arrays import xp as np from psydac.api.essential_bc import apply_essential_bc_stencil from psydac.ddm.cart import CartDecomposition, DomainDecomposition from psydac.fem.tensor import TensorFemSpace diff --git a/src/struphy/feec/projectors.py b/src/struphy/feec/projectors.py index c8c93f668..60efb3cfe 100644 --- a/src/struphy/feec/projectors.py +++ b/src/struphy/feec/projectors.py @@ -1,4 +1,4 @@ -import numpy as np +from struphy.arrays import xp as np from mpi4py import MPI from psydac.api.settings import PSYDAC_BACKEND_GPYCCEL from psydac.feec.global_projectors import GlobalProjector diff --git a/src/struphy/feec/psydac_derham.py b/src/struphy/feec/psydac_derham.py index 15037a0e9..03cb24fdc 100644 --- a/src/struphy/feec/psydac_derham.py +++ b/src/struphy/feec/psydac_derham.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 import importlib.metadata -import numpy as np +from struphy.arrays import xp as np import psydac.core.bsplines as bsp from mpi4py import MPI from mpi4py.MPI import Intracomm diff --git a/src/struphy/feec/tests/test_basis_ops.py b/src/struphy/feec/tests/test_basis_ops.py index 67b810faa..4b91a4ab9 100644 --- a/src/struphy/feec/tests/test_basis_ops.py +++ b/src/struphy/feec/tests/test_basis_ops.py @@ -14,7 +14,7 @@ def test_some_basis_ops(Nel, p, spl_kind, mapping): """ from time import time - import numpy as np + from struphy.arrays import xp as np from mpi4py import MPI from psydac.linalg.block import BlockVector from psydac.linalg.stencil import StencilVector @@ -465,7 +465,7 @@ def test_some_basis_ops(Nel, p, spl_kind, mapping): ) @pytest.mark.parametrize("mapping", [["IGAPolarCylinder", {"a": 1.0, "Lz": 3.0}]]) def test_basis_ops_polar(Nel, p, spl_kind, dirichlet_bc, mapping, show_plots=False): - import numpy as np + from struphy.arrays import xp as np from mpi4py import MPI from struphy.eigenvalue_solvers.mhd_operators import MHDOperators @@ -725,7 +725,7 @@ def assert_ops(mpi_rank, res_PSY, res_STR, verbose=False, MPI_COMM=None): TODO """ - import numpy as np + from struphy.arrays import xp as np if verbose: if MPI_COMM is not None: diff --git a/src/struphy/feec/tests/test_derham.py b/src/struphy/feec/tests/test_derham.py index e89d1a1a6..ddbdf325a 100644 --- a/src/struphy/feec/tests/test_derham.py +++ b/src/struphy/feec/tests/test_derham.py @@ -8,7 +8,7 @@ def test_psydac_derham(Nel, p, spl_kind): """Remark: p=even projectors yield slightly different results, pass with atol=1e-3.""" - import numpy as np + from struphy.arrays import xp as np from mpi4py import MPI from psydac.linalg.block import BlockVector from psydac.linalg.stencil import StencilVector diff --git a/src/struphy/feec/tests/test_eval_field.py b/src/struphy/feec/tests/test_eval_field.py index de547c56b..fa4db43aa 100644 --- a/src/struphy/feec/tests/test_eval_field.py +++ b/src/struphy/feec/tests/test_eval_field.py @@ -1,4 +1,4 @@ -import numpy as np +from struphy.arrays import xp as np import pytest from mpi4py import MPI diff --git a/src/struphy/feec/tests/test_field_init.py b/src/struphy/feec/tests/test_field_init.py index 335c8c647..d2d35ead9 100644 --- a/src/struphy/feec/tests/test_field_init.py +++ b/src/struphy/feec/tests/test_field_init.py @@ -10,7 +10,7 @@ def test_bckgr_init_const(Nel, p, spl_kind, spaces, vec_comps): """Test field background initialization of "LogicalConst" with multiple fields in params.""" - import numpy as np + from struphy.arrays import xp as np from mpi4py import MPI from struphy.feec.psydac_derham import Derham @@ -65,7 +65,7 @@ def test_bckgr_init_mhd(Nel, p, spl_kind, with_desc=False, with_gvec=False, show import inspect - import numpy as np + from struphy.arrays import xp as np from matplotlib import pyplot as plt from mpi4py import MPI @@ -1087,7 +1087,7 @@ def test_bckgr_init_mhd(Nel, p, spl_kind, with_desc=False, with_gvec=False, show def test_sincos_init_const(Nel, p, spl_kind, show_plot=False): """Test field perturbation with ModesSin + ModesCos on top of of "LogicalConst" with multiple fields in params.""" - import numpy as np + from struphy.arrays import xp as np from matplotlib import pyplot as plt from mpi4py import MPI @@ -1321,7 +1321,7 @@ def test_sincos_init_const(Nel, p, spl_kind, show_plot=False): def test_noise_init(Nel, p, spl_kind, space, direction): """Only tests 1d noise ('e1', 'e2', 'e3') !!""" - import numpy as np + from struphy.arrays import xp as np from mpi4py import MPI from struphy.feec.psydac_derham import Derham diff --git a/src/struphy/feec/tests/test_l2_projectors.py b/src/struphy/feec/tests/test_l2_projectors.py index e376d2d84..2a8372350 100644 --- a/src/struphy/feec/tests/test_l2_projectors.py +++ b/src/struphy/feec/tests/test_l2_projectors.py @@ -1,7 +1,7 @@ import inspect import matplotlib.pyplot as plt -import numpy as np +from struphy.arrays import xp as np import pytest from mpi4py import MPI diff --git a/src/struphy/feec/tests/test_local_projectors.py b/src/struphy/feec/tests/test_local_projectors.py index 3a6216c9f..e1d4b2918 100644 --- a/src/struphy/feec/tests/test_local_projectors.py +++ b/src/struphy/feec/tests/test_local_projectors.py @@ -2,7 +2,7 @@ import time import matplotlib.pyplot as plt -import numpy as np +from struphy.arrays import xp as np import pytest from mpi4py import MPI diff --git a/src/struphy/feec/tests/test_lowdim_nel_is_1.py b/src/struphy/feec/tests/test_lowdim_nel_is_1.py index fe8c11727..be4fd1877 100644 --- a/src/struphy/feec/tests/test_lowdim_nel_is_1.py +++ b/src/struphy/feec/tests/test_lowdim_nel_is_1.py @@ -8,7 +8,7 @@ def test_lowdim_derham(Nel, p, spl_kind, do_plot=False): """Test Nel=1 in various directions.""" - import numpy as np + from struphy.arrays import xp as np from matplotlib import pyplot as plt from mpi4py import MPI from psydac.linalg.block import BlockVector diff --git a/src/struphy/feec/tests/test_mass_matrices.py b/src/struphy/feec/tests/test_mass_matrices.py index d1031c32e..bb736a870 100644 --- a/src/struphy/feec/tests/test_mass_matrices.py +++ b/src/struphy/feec/tests/test_mass_matrices.py @@ -13,7 +13,7 @@ def test_mass(Nel, p, spl_kind, dirichlet_bc, mapping, show_plots=False): """Compare Struphy mass matrices to Struphy-legacy mass matrices.""" - import numpy as np + from struphy.arrays import xp as np from mpi4py import MPI from struphy.eigenvalue_solvers.mhd_operators import MHDOperators @@ -377,7 +377,7 @@ def test_mass(Nel, p, spl_kind, dirichlet_bc, mapping, show_plots=False): def test_mass_polar(Nel, p, spl_kind, dirichlet_bc, mapping, show_plots=False): """Compare Struphy polar mass matrices to Struphy-legacy polar mass matrices.""" - import numpy as np + from struphy.arrays import xp as np from mpi4py import MPI from struphy.eigenvalue_solvers.mhd_operators import MHDOperators @@ -575,7 +575,7 @@ def test_mass_preconditioner(Nel, p, spl_kind, dirichlet_bc, mapping, show_plots import time - import numpy as np + from struphy.arrays import xp as np from mpi4py import MPI from psydac.linalg.solvers import inverse @@ -881,7 +881,7 @@ def test_mass_preconditioner_polar(Nel, p, spl_kind, dirichlet_bc, mapping, show import time - import numpy as np + from struphy.arrays import xp as np from mpi4py import MPI from psydac.linalg.solvers import inverse diff --git a/src/struphy/feec/tests/test_toarray_struphy.py b/src/struphy/feec/tests/test_toarray_struphy.py index 3b7386fca..1bdb30401 100644 --- a/src/struphy/feec/tests/test_toarray_struphy.py +++ b/src/struphy/feec/tests/test_toarray_struphy.py @@ -13,7 +13,7 @@ def test_toarray_struphy(Nel, p, spl_kind, mapping): TODO """ - import numpy as np + from struphy.arrays import xp as np from mpi4py import MPI from struphy.feec.mass import WeightedMassOperators diff --git a/src/struphy/feec/tests/test_tosparse_struphy.py b/src/struphy/feec/tests/test_tosparse_struphy.py index 2e3850890..c95525dce 100644 --- a/src/struphy/feec/tests/test_tosparse_struphy.py +++ b/src/struphy/feec/tests/test_tosparse_struphy.py @@ -15,7 +15,7 @@ def test_tosparse_struphy(Nel, p, spl_kind, mapping): TODO """ - import numpy as np + from struphy.arrays import xp as np from mpi4py import MPI from struphy.feec.mass import WeightedMassOperators diff --git a/src/struphy/feec/tests/xx_test_preconds.py b/src/struphy/feec/tests/xx_test_preconds.py index c00a8fdaf..ca980fe3d 100644 --- a/src/struphy/feec/tests/xx_test_preconds.py +++ b/src/struphy/feec/tests/xx_test_preconds.py @@ -12,7 +12,7 @@ ], ) def test_mass_preconditioner(Nel, p, spl_kind, mapping): - import numpy as np + from struphy.arrays import xp as np from mpi4py import MPI from psydac.linalg.block import BlockVector from psydac.linalg.stencil import StencilVector diff --git a/src/struphy/feec/utilities.py b/src/struphy/feec/utilities.py index 292eb61e6..e87afe211 100644 --- a/src/struphy/feec/utilities.py +++ b/src/struphy/feec/utilities.py @@ -1,4 +1,4 @@ -import numpy as np +from struphy.arrays import xp as np from psydac.api.essential_bc import apply_essential_bc_stencil from psydac.fem.tensor import TensorFemSpace from psydac.fem.vector import VectorFemSpace diff --git a/src/struphy/feec/utilities_local_projectors.py b/src/struphy/feec/utilities_local_projectors.py index 1831cb31e..3867af721 100644 --- a/src/struphy/feec/utilities_local_projectors.py +++ b/src/struphy/feec/utilities_local_projectors.py @@ -1,4 +1,4 @@ -import numpy as np +from struphy.arrays import xp as np from struphy.feec.local_projectors_kernels import are_quadrature_points_zero, get_rows, select_quasi_points diff --git a/src/struphy/feec/variational_utilities.py b/src/struphy/feec/variational_utilities.py index 8a9dabe9c..49f543be4 100644 --- a/src/struphy/feec/variational_utilities.py +++ b/src/struphy/feec/variational_utilities.py @@ -1,6 +1,6 @@ from copy import deepcopy -import numpy as np +from struphy.arrays import xp as np from psydac.linalg.basic import IdentityOperator, Vector from psydac.linalg.block import BlockVector from psydac.linalg.solvers import inverse diff --git a/src/struphy/fields_background/base.py b/src/struphy/fields_background/base.py index 910e56297..03bbb28e1 100644 --- a/src/struphy/fields_background/base.py +++ b/src/struphy/fields_background/base.py @@ -2,7 +2,7 @@ from abc import ABCMeta, abstractmethod -import numpy as np +from struphy.arrays import xp as np from matplotlib import pyplot as plt from pyevtk.hl import gridToVTK diff --git a/src/struphy/fields_background/coil_fields/base.py b/src/struphy/fields_background/coil_fields/base.py index 4255db943..e9699692b 100644 --- a/src/struphy/fields_background/coil_fields/base.py +++ b/src/struphy/fields_background/coil_fields/base.py @@ -1,6 +1,6 @@ from abc import ABCMeta, abstractmethod -import numpy as np +from struphy.arrays import xp as np from matplotlib import pyplot as plt from pyevtk.hl import gridToVTK diff --git a/src/struphy/fields_background/coil_fields/coil_fields.py b/src/struphy/fields_background/coil_fields/coil_fields.py index 50ddc4105..34ed1547d 100644 --- a/src/struphy/fields_background/coil_fields/coil_fields.py +++ b/src/struphy/fields_background/coil_fields/coil_fields.py @@ -1,4 +1,4 @@ -import numpy as np +from struphy.arrays import xp as np from struphy.feec.psydac_derham import Derham from struphy.fields_background.coil_fields.base import CoilMagneticField, load_csv_data diff --git a/src/struphy/fields_background/equils.py b/src/struphy/fields_background/equils.py index 9358b0850..7d9dc3be5 100644 --- a/src/struphy/fields_background/equils.py +++ b/src/struphy/fields_background/equils.py @@ -7,7 +7,7 @@ import warnings from time import time -import numpy as np +from struphy.arrays import xp as np from scipy.integrate import odeint, quad from scipy.interpolate import RectBivariateSpline, UnivariateSpline from scipy.optimize import fsolve, minimize diff --git a/src/struphy/fields_background/tests/test_desc_equil.py b/src/struphy/fields_background/tests/test_desc_equil.py index be5a3d2db..d108f4bf0 100644 --- a/src/struphy/fields_background/tests/test_desc_equil.py +++ b/src/struphy/fields_background/tests/test_desc_equil.py @@ -1,6 +1,6 @@ import importlib.util -import numpy as np +from struphy.arrays import xp as np import pytest from matplotlib import pyplot as plt diff --git a/src/struphy/fields_background/tests/test_generic_equils.py b/src/struphy/fields_background/tests/test_generic_equils.py index d4d7fc25b..21fff05ad 100644 --- a/src/struphy/fields_background/tests/test_generic_equils.py +++ b/src/struphy/fields_background/tests/test_generic_equils.py @@ -1,4 +1,4 @@ -import numpy as np +from struphy.arrays import xp as np import pytest from matplotlib import pyplot as plt diff --git a/src/struphy/fields_background/tests/test_mhd_equils.py b/src/struphy/fields_background/tests/test_mhd_equils.py index 4ab6f7e19..6aceaf220 100644 --- a/src/struphy/fields_background/tests/test_mhd_equils.py +++ b/src/struphy/fields_background/tests/test_mhd_equils.py @@ -1,4 +1,4 @@ -import numpy as np +from struphy.arrays import xp as np import pytest from struphy.fields_background import equils diff --git a/src/struphy/fields_background/tests/test_numerical_mhd_equil.py b/src/struphy/fields_background/tests/test_numerical_mhd_equil.py index 619bad2d9..ed94977b6 100644 --- a/src/struphy/fields_background/tests/test_numerical_mhd_equil.py +++ b/src/struphy/fields_background/tests/test_numerical_mhd_equil.py @@ -1,4 +1,4 @@ -import numpy as np +from struphy.arrays import xp as np import pytest from struphy.fields_background.base import FluidEquilibrium, LogicalMHDequilibrium diff --git a/src/struphy/geometry/base.py b/src/struphy/geometry/base.py index 5b9ff359f..5a0ce8399 100644 --- a/src/struphy/geometry/base.py +++ b/src/struphy/geometry/base.py @@ -4,7 +4,7 @@ from abc import ABCMeta, abstractmethod import h5py -import numpy as np +from struphy.arrays import xp as np from scipy.sparse import csc_matrix, kron from scipy.sparse.linalg import splu, spsolve diff --git a/src/struphy/geometry/domains.py b/src/struphy/geometry/domains.py index 269ebfc81..495eed035 100644 --- a/src/struphy/geometry/domains.py +++ b/src/struphy/geometry/domains.py @@ -2,7 +2,7 @@ import copy -import numpy as np +from struphy.arrays import xp as np from struphy.fields_background.base import AxisymmMHDequilibrium from struphy.fields_background.equils import EQDSKequilibrium diff --git a/src/struphy/geometry/tests/test_domain.py b/src/struphy/geometry/tests/test_domain.py index b63c5b4c6..ea4df734a 100644 --- a/src/struphy/geometry/tests/test_domain.py +++ b/src/struphy/geometry/tests/test_domain.py @@ -4,7 +4,7 @@ def test_prepare_arg(): """Tests prepare_arg static method in domain base class.""" - import numpy as np + from struphy.arrays import xp as np from struphy.geometry.base import Domain @@ -158,7 +158,7 @@ def a_vec(e1, e2, e3): def test_evaluation_mappings(mapping): """Tests domain object creation with default parameters and evaluation of metric coefficients.""" - import numpy as np + from struphy.arrays import xp as np from struphy.geometry import domains from struphy.geometry.base import Domain @@ -318,7 +318,7 @@ def test_evaluation_mappings(mapping): def test_pullback(): """Tests pullbacks to p-forms.""" - import numpy as np + from struphy.arrays import xp as np from struphy.geometry import domains from struphy.geometry.base import Domain @@ -478,7 +478,7 @@ def fun(x, y, z): def test_pushforward(): """Tests pushforward of p-forms.""" - import numpy as np + from struphy.arrays import xp as np from struphy.geometry import domains from struphy.geometry.base import Domain @@ -638,7 +638,7 @@ def fun(e1, e2, e3): def test_transform(): """Tests transformation of p-forms.""" - import numpy as np + from struphy.arrays import xp as np from struphy.geometry import domains from struphy.geometry.base import Domain @@ -821,7 +821,7 @@ def fun(e1, e2, e3): # """ # # from struphy.geometry import domains -# import numpy as np +# from struphy.arrays import xp as np # # # arrays: # arr1 = np.linspace(0., 1., 4) diff --git a/src/struphy/geometry/utilities.py b/src/struphy/geometry/utilities.py index 70b8fc361..dad9de590 100644 --- a/src/struphy/geometry/utilities.py +++ b/src/struphy/geometry/utilities.py @@ -1,6 +1,6 @@ "Domain-related utility functions." -import numpy as np +from struphy.arrays import xp as np from scipy.optimize import newton, root, root_scalar from scipy.sparse import csc_matrix from scipy.sparse.linalg import splu diff --git a/src/struphy/initial/eigenfunctions.py b/src/struphy/initial/eigenfunctions.py index c13397a1f..a264e54ab 100644 --- a/src/struphy/initial/eigenfunctions.py +++ b/src/struphy/initial/eigenfunctions.py @@ -1,6 +1,6 @@ import os -import numpy as np +from struphy.arrays import xp as np import yaml from psydac.api.discretization import discretize from sympde.topology import Derham, Line diff --git a/src/struphy/initial/perturbations.py b/src/struphy/initial/perturbations.py index bda66860e..4bd5ca54b 100644 --- a/src/struphy/initial/perturbations.py +++ b/src/struphy/initial/perturbations.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 "Analytical perturbations (modes)." -import numpy as np +from struphy.arrays import xp as np import scipy import scipy.special diff --git a/src/struphy/initial/tests/test_init_perturbations.py b/src/struphy/initial/tests/test_init_perturbations.py index edc82413e..eaea2416c 100644 --- a/src/struphy/initial/tests/test_init_perturbations.py +++ b/src/struphy/initial/tests/test_init_perturbations.py @@ -20,7 +20,7 @@ def test_init_modes(Nel, p, spl_kind, mapping, combine_comps=None, do_plot=False): """Test the initialization Field.initialize_coeffs with all "Modes" classes in perturbations.py.""" - import numpy as np + from struphy.arrays import xp as np from matplotlib import pyplot as plt from mpi4py import MPI diff --git a/src/struphy/initial/utilities.py b/src/struphy/initial/utilities.py index 3f9f2dfec..e84a81e29 100644 --- a/src/struphy/initial/utilities.py +++ b/src/struphy/initial/utilities.py @@ -1,7 +1,7 @@ import os import h5py -import numpy as np +from struphy.arrays import xp as np from struphy.fields_background.equils import set_defaults from struphy.io.output_handling import DataContainer diff --git a/src/struphy/io/output_handling.py b/src/struphy/io/output_handling.py index 35c8fbfc0..ca84dff00 100644 --- a/src/struphy/io/output_handling.py +++ b/src/struphy/io/output_handling.py @@ -2,7 +2,7 @@ import os import h5py -import numpy as np +from struphy.arrays import xp as np class DataContainer: diff --git a/src/struphy/io/setup.py b/src/struphy/io/setup.py index ff7323f45..f1a8297ec 100644 --- a/src/struphy/io/setup.py +++ b/src/struphy/io/setup.py @@ -1,6 +1,6 @@ from dataclasses import dataclass -import numpy as np +from struphy.arrays import xp as np from mpi4py import MPI from struphy.utils.utils import dict_to_yaml diff --git a/src/struphy/kinetic_background/base.py b/src/struphy/kinetic_background/base.py index 3538674ec..cbb774225 100644 --- a/src/struphy/kinetic_background/base.py +++ b/src/struphy/kinetic_background/base.py @@ -3,7 +3,7 @@ import copy from abc import ABCMeta, abstractmethod -import numpy as np +from struphy.arrays import xp as np from struphy.fields_background.base import FluidEquilibrium from struphy.fields_background.equils import set_defaults diff --git a/src/struphy/kinetic_background/maxwellians.py b/src/struphy/kinetic_background/maxwellians.py index 12c27e06a..908013fbd 100644 --- a/src/struphy/kinetic_background/maxwellians.py +++ b/src/struphy/kinetic_background/maxwellians.py @@ -1,6 +1,6 @@ "Maxwellian (Gaussian) distributions in velocity space." -import numpy as np +from struphy.arrays import xp as np from struphy.fields_background.base import FluidEquilibrium from struphy.fields_background.equils import set_defaults diff --git a/src/struphy/kinetic_background/moment_functions.py b/src/struphy/kinetic_background/moment_functions.py index 629958bfe..6f688c668 100644 --- a/src/struphy/kinetic_background/moment_functions.py +++ b/src/struphy/kinetic_background/moment_functions.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 "Analytical moment functions." -import numpy as np +from struphy.arrays import xp as np class ITPA_density: diff --git a/src/struphy/kinetic_background/tests/test_base.py b/src/struphy/kinetic_background/tests/test_base.py index 425dad0ff..18dfe50f2 100644 --- a/src/struphy/kinetic_background/tests/test_base.py +++ b/src/struphy/kinetic_background/tests/test_base.py @@ -2,7 +2,7 @@ def test_kinetic_background_magics(show_plot=False): """Test the magic commands __sum__, __mul__ and __sub__ of the Maxwellian base class.""" import matplotlib.pyplot as plt - import numpy as np + from struphy.arrays import xp as np from struphy.kinetic_background.maxwellians import Maxwellian3D diff --git a/src/struphy/kinetic_background/tests/test_maxwellians.py b/src/struphy/kinetic_background/tests/test_maxwellians.py index dc346f6c7..a4db897ee 100644 --- a/src/struphy/kinetic_background/tests/test_maxwellians.py +++ b/src/struphy/kinetic_background/tests/test_maxwellians.py @@ -9,7 +9,7 @@ def test_maxwellian_3d_uniform(Nel, show_plot=False): analytical computation. """ import matplotlib.pyplot as plt - import numpy as np + from struphy.arrays import xp as np from struphy.kinetic_background.maxwellians import Maxwellian3D @@ -89,7 +89,7 @@ def test_maxwellian_3d_perturbed(Nel, show_plot=False): """Tests the Maxwellian3D class for perturbations.""" import matplotlib.pyplot as plt - import numpy as np + from struphy.arrays import xp as np from struphy.kinetic_background.maxwellians import Maxwellian3D @@ -285,7 +285,7 @@ def test_maxwellian_3d_mhd(Nel, with_desc, show_plot=False): import inspect import matplotlib.pyplot as plt - import numpy as np + from struphy.arrays import xp as np from struphy.fields_background import equils from struphy.geometry import domains @@ -692,7 +692,7 @@ def test_maxwellian_2d_uniform(Nel, show_plot=False): analytical computation. """ import matplotlib.pyplot as plt - import numpy as np + from struphy.arrays import xp as np from struphy.kinetic_background.maxwellians import GyroMaxwellian2D @@ -781,7 +781,7 @@ def test_maxwellian_2d_perturbed(Nel, show_plot=False): """Tests the GyroMaxwellian2D class for perturbations.""" import matplotlib.pyplot as plt - import numpy as np + from struphy.arrays import xp as np from struphy.kinetic_background.maxwellians import GyroMaxwellian2D @@ -1035,7 +1035,7 @@ def test_maxwellian_2d_mhd(Nel, with_desc, show_plot=False): import inspect import matplotlib.pyplot as plt - import numpy as np + from struphy.arrays import xp as np from struphy.fields_background import equils from struphy.fields_background.base import FluidEquilibriumWithB @@ -1436,7 +1436,7 @@ def test_canonical_maxwellian_uniform(Nel, show_plot=False): analytical computation. """ import matplotlib.pyplot as plt - import numpy as np + from struphy.arrays import xp as np from struphy.fields_background import equils from struphy.geometry import domains diff --git a/src/struphy/linear_algebra/linalg_kron.py b/src/struphy/linear_algebra/linalg_kron.py index 712b47e43..846fd9744 100644 --- a/src/struphy/linear_algebra/linalg_kron.py +++ b/src/struphy/linear_algebra/linalg_kron.py @@ -13,7 +13,7 @@ [r_M11, rM12, ... , r_MNO]] """ -import numpy as np +from struphy.arrays import xp as np from scipy.linalg import solve_circulant from scipy.sparse.linalg import splu diff --git a/src/struphy/linear_algebra/saddle_point.py b/src/struphy/linear_algebra/saddle_point.py index 15ca4aac4..acc2e15ce 100644 --- a/src/struphy/linear_algebra/saddle_point.py +++ b/src/struphy/linear_algebra/saddle_point.py @@ -1,6 +1,6 @@ from typing import Union -import numpy as np +from struphy.arrays import xp as np import scipy as sc from psydac.linalg.basic import LinearOperator, Vector from psydac.linalg.block import BlockLinearOperator, BlockVector, BlockVectorSpace diff --git a/src/struphy/linear_algebra/tests/test_saddlepoint_massmatrices.py b/src/struphy/linear_algebra/tests/test_saddlepoint_massmatrices.py index 7d188fb48..cebb89033 100644 --- a/src/struphy/linear_algebra/tests/test_saddlepoint_massmatrices.py +++ b/src/struphy/linear_algebra/tests/test_saddlepoint_massmatrices.py @@ -13,7 +13,7 @@ def test_saddlepointsolver(method_for_solving, Nel, p, spl_kind, dirichlet_bc, m import time - import numpy as np + from struphy.arrays import xp as np import scipy as sc from mpi4py import MPI from psydac.linalg.basic import IdentityOperator @@ -374,7 +374,7 @@ def _plot_residual_norms(residual_norms): def _plot_velocity(data_reshaped): import matplotlib import matplotlib.pyplot as plt - import numpy as np + from struphy.arrays import xp as np matplotlib.use("Agg") diff --git a/src/struphy/linear_algebra/tests/test_stencil_dot_kernels.py b/src/struphy/linear_algebra/tests/test_stencil_dot_kernels.py index c66a67aa0..ed07ec90d 100644 --- a/src/struphy/linear_algebra/tests/test_stencil_dot_kernels.py +++ b/src/struphy/linear_algebra/tests/test_stencil_dot_kernels.py @@ -14,7 +14,7 @@ def test_1d(Nel, p, spl_kind, domain_ind, codomain_ind): a) the result from kernel in struphy.linear_algebra.stencil_dot_kernels.matvec_1d_kernel b) the result from Stencil .dot with precompiled=True""" - import numpy as np + from struphy.arrays import xp as np from mpi4py import MPI from psydac.api.settings import PSYDAC_BACKEND_GPYCCEL from psydac.linalg.stencil import StencilMatrix, StencilVector @@ -137,7 +137,7 @@ def test_3d(Nel, p, spl_kind, domain_ind, codomain_ind): a) the result from kernel in struphy.linear_algebra.stencil_dot_kernels.matvec_1d_kernel b) the result from Stencil .dot with precompiled=True""" - import numpy as np + from struphy.arrays import xp as np from mpi4py import MPI from psydac.api.settings import PSYDAC_BACKEND_GPYCCEL from psydac.linalg.stencil import StencilMatrix, StencilVector diff --git a/src/struphy/linear_algebra/tests/test_stencil_transpose_kernels.py b/src/struphy/linear_algebra/tests/test_stencil_transpose_kernels.py index 92f65410d..ebbbb4d87 100644 --- a/src/struphy/linear_algebra/tests/test_stencil_transpose_kernels.py +++ b/src/struphy/linear_algebra/tests/test_stencil_transpose_kernels.py @@ -14,7 +14,7 @@ def test_1d(Nel, p, spl_kind, domain_ind, codomain_ind): a) the result from kernel in struphy.linear_algebra.stencil_transpose_kernels.transpose_1d_kernel b) the result from Stencil .transpose with precompiled=True""" - import numpy as np + from struphy.arrays import xp as np from mpi4py import MPI from psydac.api.settings import PSYDAC_BACKEND_GPYCCEL from psydac.linalg.stencil import StencilMatrix @@ -131,7 +131,7 @@ def test_3d(Nel, p, spl_kind, domain_ind, codomain_ind): a) the result from kernel in struphy.linear_algebra.stencil_transpose_kernels.transpose_3d_kernel b) the result from Stencil .transpose with precompiled=True""" - import numpy as np + from struphy.arrays import xp as np from mpi4py import MPI from psydac.api.settings import PSYDAC_BACKEND_GPYCCEL from psydac.linalg.stencil import StencilMatrix diff --git a/src/struphy/main.py b/src/struphy/main.py index 2e81d283a..67629ff9c 100644 --- a/src/struphy/main.py +++ b/src/struphy/main.py @@ -54,7 +54,7 @@ def main( import os import time - import numpy as np + from struphy.arrays import xp as np from mpi4py import MPI from pyevtk.hl import gridToVTK diff --git a/src/struphy/models/base.py b/src/struphy/models/base.py index 5d02dd647..ca8c03d25 100644 --- a/src/struphy/models/base.py +++ b/src/struphy/models/base.py @@ -3,7 +3,7 @@ from abc import ABCMeta, abstractmethod from functools import reduce -import numpy as np +from struphy.arrays import xp as np import yaml from mpi4py import MPI from psydac.linalg.stencil import StencilVector diff --git a/src/struphy/models/fluid.py b/src/struphy/models/fluid.py index 6afe01ace..4ac6fb045 100644 --- a/src/struphy/models/fluid.py +++ b/src/struphy/models/fluid.py @@ -1,4 +1,4 @@ -import numpy as np +from struphy.arrays import xp as np from struphy.models.base import StruphyModel from struphy.propagators import propagators_coupling, propagators_fields, propagators_markers diff --git a/src/struphy/models/hybrid.py b/src/struphy/models/hybrid.py index 76afea648..574c817be 100644 --- a/src/struphy/models/hybrid.py +++ b/src/struphy/models/hybrid.py @@ -1,4 +1,4 @@ -import numpy as np +from struphy.arrays import xp as np from struphy.models.base import StruphyModel from struphy.pic.accumulation import accum_kernels, accum_kernels_gc diff --git a/src/struphy/models/kinetic.py b/src/struphy/models/kinetic.py index 9964e72ad..00464e617 100644 --- a/src/struphy/models/kinetic.py +++ b/src/struphy/models/kinetic.py @@ -1,4 +1,4 @@ -import numpy as np +from struphy.arrays import xp as np from struphy.kinetic_background.base import KineticBackground from struphy.models.base import StruphyModel diff --git a/src/struphy/models/tests/verification.py b/src/struphy/models/tests/verification.py index aa122c5de..23a136a31 100644 --- a/src/struphy/models/tests/verification.py +++ b/src/struphy/models/tests/verification.py @@ -3,7 +3,7 @@ from pathlib import Path import h5py -import numpy as np +from struphy.arrays import xp as np import yaml from matplotlib import pyplot as plt from matplotlib.ticker import FormatStrFormatter diff --git a/src/struphy/models/toy.py b/src/struphy/models/toy.py index b3774cf18..759d06883 100644 --- a/src/struphy/models/toy.py +++ b/src/struphy/models/toy.py @@ -1,4 +1,4 @@ -import numpy as np +from struphy.arrays import xp as np from struphy.models.base import StruphyModel from struphy.propagators import propagators_coupling, propagators_fields, propagators_markers diff --git a/src/struphy/ode/solvers.py b/src/struphy/ode/solvers.py index 4706b6b26..bfb3bce47 100644 --- a/src/struphy/ode/solvers.py +++ b/src/struphy/ode/solvers.py @@ -1,6 +1,6 @@ from inspect import signature -import numpy as np +from struphy.arrays import xp as np from psydac.linalg.block import BlockVector from psydac.linalg.stencil import StencilVector diff --git a/src/struphy/ode/tests/test_ode_feec.py b/src/struphy/ode/tests/test_ode_feec.py index 7825d2537..654247427 100644 --- a/src/struphy/ode/tests/test_ode_feec.py +++ b/src/struphy/ode/tests/test_ode_feec.py @@ -19,7 +19,7 @@ def test_exp_growth(spaces, algo, show_plots=False): """Solve dy/dt = omega*y for different feec variables y and with all available solvers from the ButcherTableau.""" - import numpy as np + from struphy.arrays import xp as np from matplotlib import pyplot as plt from mpi4py import MPI from psydac.linalg.block import BlockVector diff --git a/src/struphy/ode/utils.py b/src/struphy/ode/utils.py index 4f306a60d..a8d61d5f6 100644 --- a/src/struphy/ode/utils.py +++ b/src/struphy/ode/utils.py @@ -1,4 +1,4 @@ -import numpy as np +from struphy.arrays import xp as np class ButcherTableau: diff --git a/src/struphy/pic/accumulation/particles_to_grid.py b/src/struphy/pic/accumulation/particles_to_grid.py index 23345df23..9dea9f790 100644 --- a/src/struphy/pic/accumulation/particles_to_grid.py +++ b/src/struphy/pic/accumulation/particles_to_grid.py @@ -1,6 +1,6 @@ "Base classes for particle deposition (accumulation) on the grid." -import numpy as np +from struphy.arrays import xp as np from mpi4py import MPI from psydac.linalg.block import BlockVector from psydac.linalg.stencil import StencilMatrix, StencilVector diff --git a/src/struphy/pic/base.py b/src/struphy/pic/base.py index 1c3803c68..ffa87c930 100644 --- a/src/struphy/pic/base.py +++ b/src/struphy/pic/base.py @@ -4,7 +4,7 @@ from abc import ABCMeta, abstractmethod import h5py -import numpy as np +from struphy.arrays import xp as np import scipy.special as sp from mpi4py import MPI from mpi4py.MPI import Intracomm diff --git a/src/struphy/pic/particles.py b/src/struphy/pic/particles.py index b5c78e32f..be1db3794 100644 --- a/src/struphy/pic/particles.py +++ b/src/struphy/pic/particles.py @@ -1,6 +1,6 @@ import copy -import numpy as np +from struphy.arrays import xp as np from struphy.fields_background.base import FluidEquilibriumWithB from struphy.fields_background.projected_equils import ProjectedFluidEquilibriumWithB diff --git a/src/struphy/pic/pushing/pusher.py b/src/struphy/pic/pushing/pusher.py index 855d18920..014f8276f 100644 --- a/src/struphy/pic/pushing/pusher.py +++ b/src/struphy/pic/pushing/pusher.py @@ -1,6 +1,6 @@ "Accelerated particle pushing." -import numpy as np +from struphy.arrays import xp as np from mpi4py.MPI import IN_PLACE, SUM from struphy.kernel_arguments.pusher_args_kernels import DerhamArguments, DomainArguments diff --git a/src/struphy/pic/sobol_seq.py b/src/struphy/pic/sobol_seq.py index 430b5442b..3160ce5d3 100644 --- a/src/struphy/pic/sobol_seq.py +++ b/src/struphy/pic/sobol_seq.py @@ -17,7 +17,7 @@ from __future__ import division -import numpy as np +from struphy.arrays import xp as np from scipy.stats import norm __all__ = ["i4_bit_hi1", "i4_bit_lo0", "i4_sobol_generate", "i4_sobol", "i4_uniform", "prime_ge", "is_prime"] diff --git a/src/struphy/pic/tests/test_accum_vec_H1.py b/src/struphy/pic/tests/test_accum_vec_H1.py index 6d1e90208..a9118cd33 100644 --- a/src/struphy/pic/tests/test_accum_vec_H1.py +++ b/src/struphy/pic/tests/test_accum_vec_H1.py @@ -46,7 +46,7 @@ def test_accum_poisson(Nel, p, spl_kind, mapping, num_clones, Np=1000): import copy - import numpy as np + from struphy.arrays import xp as np from mpi4py import MPI from struphy.feec.mass import WeightedMassOperators diff --git a/src/struphy/pic/tests/test_accumulation.py b/src/struphy/pic/tests/test_accumulation.py index d7c5ac32b..eb4d5943f 100644 --- a/src/struphy/pic/tests/test_accumulation.py +++ b/src/struphy/pic/tests/test_accumulation.py @@ -47,7 +47,7 @@ def test_accumulation(Nel, p, spl_kind, mapping, Np=40, verbose=False): def pc_lin_mhd_6d_step_ph_full(Nel, p, spl_kind, mapping, Np, verbose=False): from time import time - import numpy as np + from struphy.arrays import xp as np from mpi4py import MPI from struphy.eigenvalue_solvers.spline_space import Spline_space_1d, Tensor_spline_space diff --git a/src/struphy/pic/tests/test_binning.py b/src/struphy/pic/tests/test_binning.py index 3d4875cf2..5e4d49c38 100644 --- a/src/struphy/pic/tests/test_binning.py +++ b/src/struphy/pic/tests/test_binning.py @@ -36,7 +36,7 @@ def test_binning_6D_full_f(mapping, show_plot=False): """ import matplotlib.pyplot as plt - import numpy as np + from struphy.arrays import xp as np from mpi4py import MPI from struphy.geometry import domains @@ -295,7 +295,7 @@ def test_binning_6D_delta_f(mapping, show_plot=False): """ import matplotlib.pyplot as plt - import numpy as np + from struphy.arrays import xp as np from mpi4py import MPI from struphy.geometry import domains @@ -519,7 +519,7 @@ def test_binning_6D_full_f_mpi(mapping, show_plot=False): """ import matplotlib.pyplot as plt - import numpy as np + from struphy.arrays import xp as np from mpi4py import MPI from struphy.geometry import domains @@ -801,7 +801,7 @@ def test_binning_6D_delta_f_mpi(mapping, show_plot=False): """ import matplotlib.pyplot as plt - import numpy as np + from struphy.arrays import xp as np from mpi4py import MPI from struphy.geometry import domains diff --git a/src/struphy/pic/tests/test_draw_parallel.py b/src/struphy/pic/tests/test_draw_parallel.py index 7efad5f2b..9f3f71598 100644 --- a/src/struphy/pic/tests/test_draw_parallel.py +++ b/src/struphy/pic/tests/test_draw_parallel.py @@ -36,7 +36,7 @@ def test_draw(Nel, p, spl_kind, mapping, ppc=10): """Asserts whether all particles are on the correct process after `particles.mpi_sort_markers()`.""" - import numpy as np + from struphy.arrays import xp as np from mpi4py import MPI from struphy.feec.psydac_derham import Derham diff --git a/src/struphy/pic/tests/test_mat_vec_filler.py b/src/struphy/pic/tests/test_mat_vec_filler.py index 36f3924f0..1ed8e2634 100644 --- a/src/struphy/pic/tests/test_mat_vec_filler.py +++ b/src/struphy/pic/tests/test_mat_vec_filler.py @@ -1,4 +1,4 @@ -import numpy as np +from struphy.arrays import xp as np import pytest diff --git a/src/struphy/pic/tests/test_pic_legacy_files/accumulation.py b/src/struphy/pic/tests/test_pic_legacy_files/accumulation.py index 5687f6287..cea8a4fd6 100644 --- a/src/struphy/pic/tests/test_pic_legacy_files/accumulation.py +++ b/src/struphy/pic/tests/test_pic_legacy_files/accumulation.py @@ -8,7 +8,7 @@ import time -import numpy as np +from struphy.arrays import xp as np import scipy.sparse as spa from mpi4py import MPI diff --git a/src/struphy/pic/tests/test_pic_legacy_files/pusher.py b/src/struphy/pic/tests/test_pic_legacy_files/pusher.py index 1da52c793..919e1774e 100644 --- a/src/struphy/pic/tests/test_pic_legacy_files/pusher.py +++ b/src/struphy/pic/tests/test_pic_legacy_files/pusher.py @@ -1,4 +1,4 @@ -import numpy as np +from struphy.arrays import xp as np import struphy.pic.tests.test_pic_legacy_files.pusher_pos as push_pos import struphy.pic.tests.test_pic_legacy_files.pusher_vel_2d as push_vel_2d diff --git a/src/struphy/pic/tests/test_pushers.py b/src/struphy/pic/tests/test_pushers.py index 218d65f29..a9c3bc086 100644 --- a/src/struphy/pic/tests/test_pushers.py +++ b/src/struphy/pic/tests/test_pushers.py @@ -22,7 +22,7 @@ ], ) def test_push_vxb_analytic(Nel, p, spl_kind, mapping, show_plots=False): - import numpy as np + from struphy.arrays import xp as np from mpi4py import MPI from struphy.eigenvalue_solvers.spline_space import Spline_space_1d, Tensor_spline_space @@ -159,7 +159,7 @@ def test_push_vxb_analytic(Nel, p, spl_kind, mapping, show_plots=False): ], ) def test_push_bxu_Hdiv(Nel, p, spl_kind, mapping, show_plots=False): - import numpy as np + from struphy.arrays import xp as np from mpi4py import MPI from struphy.eigenvalue_solvers.spline_space import Spline_space_1d, Tensor_spline_space @@ -307,7 +307,7 @@ def test_push_bxu_Hdiv(Nel, p, spl_kind, mapping, show_plots=False): ], ) def test_push_bxu_Hcurl(Nel, p, spl_kind, mapping, show_plots=False): - import numpy as np + from struphy.arrays import xp as np from mpi4py import MPI from struphy.eigenvalue_solvers.spline_space import Spline_space_1d, Tensor_spline_space @@ -455,7 +455,7 @@ def test_push_bxu_Hcurl(Nel, p, spl_kind, mapping, show_plots=False): ], ) def test_push_bxu_H1vec(Nel, p, spl_kind, mapping, show_plots=False): - import numpy as np + from struphy.arrays import xp as np from mpi4py import MPI from struphy.eigenvalue_solvers.spline_space import Spline_space_1d, Tensor_spline_space @@ -603,7 +603,7 @@ def test_push_bxu_H1vec(Nel, p, spl_kind, mapping, show_plots=False): ], ) def test_push_bxu_Hdiv_pauli(Nel, p, spl_kind, mapping, show_plots=False): - import numpy as np + from struphy.arrays import xp as np from mpi4py import MPI from struphy.eigenvalue_solvers.spline_space import Spline_space_1d, Tensor_spline_space @@ -753,7 +753,7 @@ def test_push_bxu_Hdiv_pauli(Nel, p, spl_kind, mapping, show_plots=False): ], ) def test_push_eta_rk4(Nel, p, spl_kind, mapping, show_plots=False): - import numpy as np + from struphy.arrays import xp as np from mpi4py import MPI from struphy.eigenvalue_solvers.spline_space import Spline_space_1d, Tensor_spline_space diff --git a/src/struphy/pic/tests/test_sorting.py b/src/struphy/pic/tests/test_sorting.py index 89f2bafbd..6872b5d53 100644 --- a/src/struphy/pic/tests/test_sorting.py +++ b/src/struphy/pic/tests/test_sorting.py @@ -1,6 +1,6 @@ from time import time -import numpy as np +from struphy.arrays import xp as np import pytest from mpi4py import MPI diff --git a/src/struphy/pic/tests/test_sph.py b/src/struphy/pic/tests/test_sph.py index a823181f7..437d35ecc 100644 --- a/src/struphy/pic/tests/test_sph.py +++ b/src/struphy/pic/tests/test_sph.py @@ -1,4 +1,4 @@ -import numpy as np +from struphy.arrays import xp as np import pytest from matplotlib import pyplot as plt from mpi4py import MPI diff --git a/src/struphy/pic/tests/test_tesselation.py b/src/struphy/pic/tests/test_tesselation.py index 145931d15..a54f3d3f3 100644 --- a/src/struphy/pic/tests/test_tesselation.py +++ b/src/struphy/pic/tests/test_tesselation.py @@ -1,6 +1,6 @@ from time import time -import numpy as np +from struphy.arrays import xp as np import pytest from matplotlib import pyplot as plt from mpi4py import MPI diff --git a/src/struphy/pic/utilities.py b/src/struphy/pic/utilities.py index fe702e8c2..69ae71027 100644 --- a/src/struphy/pic/utilities.py +++ b/src/struphy/pic/utilities.py @@ -1,4 +1,4 @@ -import numpy as np +from struphy.arrays import xp as np import struphy.pic.utilities_kernels as utils diff --git a/src/struphy/polar/basic.py b/src/struphy/polar/basic.py index d863997db..eb35dbca2 100644 --- a/src/struphy/polar/basic.py +++ b/src/struphy/polar/basic.py @@ -1,4 +1,4 @@ -import numpy as np +from struphy.arrays import xp as np from mpi4py import MPI from psydac.linalg.basic import Vector, VectorSpace from psydac.linalg.block import BlockVector diff --git a/src/struphy/polar/extraction_operators.py b/src/struphy/polar/extraction_operators.py index 14af375e4..497136515 100644 --- a/src/struphy/polar/extraction_operators.py +++ b/src/struphy/polar/extraction_operators.py @@ -1,4 +1,4 @@ -import numpy as np +from struphy.arrays import xp as np # ============================= 2D polar splines (C1) =================================== diff --git a/src/struphy/polar/linear_operators.py b/src/struphy/polar/linear_operators.py index f6253dd52..977571311 100644 --- a/src/struphy/polar/linear_operators.py +++ b/src/struphy/polar/linear_operators.py @@ -1,4 +1,4 @@ -import numpy as np +from struphy.arrays import xp as np from mpi4py import MPI from psydac.linalg.block import BlockVector, BlockVectorSpace from psydac.linalg.stencil import StencilVector, StencilVectorSpace diff --git a/src/struphy/polar/tests/test_legacy_polar_splines.py b/src/struphy/polar/tests/test_legacy_polar_splines.py index eda4c378a..e1f1ed1d1 100644 --- a/src/struphy/polar/tests/test_legacy_polar_splines.py +++ b/src/struphy/polar/tests/test_legacy_polar_splines.py @@ -8,7 +8,7 @@ def test_polar_splines_2D(plot=False): sys.path.append("..") import matplotlib.pyplot as plt - import numpy as np + from struphy.arrays import xp as np from mpl_toolkits.mplot3d import Axes3D from struphy.eigenvalue_solvers.spline_space import Spline_space_1d, Tensor_spline_space diff --git a/src/struphy/polar/tests/test_polar.py b/src/struphy/polar/tests/test_polar.py index 0c8f597d3..8b1a97b20 100644 --- a/src/struphy/polar/tests/test_polar.py +++ b/src/struphy/polar/tests/test_polar.py @@ -168,7 +168,7 @@ def test_spaces(Nel, p, spl_kind): @pytest.mark.parametrize("p", [[3, 2, 2]]) @pytest.mark.parametrize("spl_kind", [[False, True, True], [False, True, False]]) def test_extraction_ops_and_derivatives(Nel, p, spl_kind): - import numpy as np + from struphy.arrays import xp as np from mpi4py import MPI from struphy.eigenvalue_solvers.spline_space import Spline_space_1d, Tensor_spline_space @@ -303,7 +303,7 @@ def test_extraction_ops_and_derivatives(Nel, p, spl_kind): @pytest.mark.parametrize("p", [[4, 3, 2]]) @pytest.mark.parametrize("spl_kind", [[False, True, True], [False, True, False]]) def test_projectors(Nel, p, spl_kind): - import numpy as np + from struphy.arrays import xp as np from mpi4py import MPI from struphy.eigenvalue_solvers.spline_space import Spline_space_1d, Tensor_spline_space diff --git a/src/struphy/post_processing/likwid/plot_likwidproject.py b/src/struphy/post_processing/likwid/plot_likwidproject.py index 4dfae20e7..74c93569a 100644 --- a/src/struphy/post_processing/likwid/plot_likwidproject.py +++ b/src/struphy/post_processing/likwid/plot_likwidproject.py @@ -8,7 +8,7 @@ import sys import matplotlib.pyplot as plt -import numpy as np +from struphy.arrays import xp as np import pandas as pd import plotly.express as px import plotly.graph_objects as go diff --git a/src/struphy/post_processing/likwid/plot_time_traces.py b/src/struphy/post_processing/likwid/plot_time_traces.py index 818d96935..bd1da4ffb 100644 --- a/src/struphy/post_processing/likwid/plot_time_traces.py +++ b/src/struphy/post_processing/likwid/plot_time_traces.py @@ -3,7 +3,7 @@ import re import matplotlib.pyplot as plt -import numpy as np +from struphy.arrays import xp as np import plotly.io as pio # pio.kaleido.scope.mathjax = None diff --git a/src/struphy/post_processing/likwid/roofline_plotter.py b/src/struphy/post_processing/likwid/roofline_plotter.py index 1621e5d8d..46e8b92b0 100644 --- a/src/struphy/post_processing/likwid/roofline_plotter.py +++ b/src/struphy/post_processing/likwid/roofline_plotter.py @@ -1,7 +1,7 @@ import glob import pickle -import numpy as np +from struphy.arrays import xp as np import pandas as pd import yaml diff --git a/src/struphy/post_processing/orbits/orbits_tools.py b/src/struphy/post_processing/orbits/orbits_tools.py index 060232cdf..358f052b3 100644 --- a/src/struphy/post_processing/orbits/orbits_tools.py +++ b/src/struphy/post_processing/orbits/orbits_tools.py @@ -2,7 +2,7 @@ import shutil import h5py -import numpy as np +from struphy.arrays import xp as np import yaml from tqdm import tqdm diff --git a/src/struphy/post_processing/post_processing_tools.py b/src/struphy/post_processing/post_processing_tools.py index 127cda4f6..49b72b408 100644 --- a/src/struphy/post_processing/post_processing_tools.py +++ b/src/struphy/post_processing/post_processing_tools.py @@ -3,7 +3,7 @@ import h5py import matplotlib.pyplot as plt -import numpy as np +from struphy.arrays import xp as np import yaml from tqdm import tqdm diff --git a/src/struphy/post_processing/pproc_struphy.py b/src/struphy/post_processing/pproc_struphy.py index 67059d648..f1e839949 100644 --- a/src/struphy/post_processing/pproc_struphy.py +++ b/src/struphy/post_processing/pproc_struphy.py @@ -42,7 +42,7 @@ def main( import shutil import h5py - import numpy as np + from struphy.arrays import xp as np import yaml import struphy.post_processing.orbits.orbits_tools as orbits_pproc diff --git a/src/struphy/post_processing/profile_struphy.py b/src/struphy/post_processing/profile_struphy.py index 0c0d77e73..513e582ef 100644 --- a/src/struphy/post_processing/profile_struphy.py +++ b/src/struphy/post_processing/profile_struphy.py @@ -1,7 +1,7 @@ import pickle import sys -import numpy as np +from struphy.arrays import xp as np import yaml from matplotlib import pyplot as plt diff --git a/src/struphy/profiling/profiling.py b/src/struphy/profiling/profiling.py index 160002c15..00f8f9c03 100644 --- a/src/struphy/profiling/profiling.py +++ b/src/struphy/profiling/profiling.py @@ -17,7 +17,7 @@ # Import the profiling configuration class and context manager from functools import lru_cache -import numpy as np +from struphy.arrays import xp as np from mpi4py import MPI diff --git a/src/struphy/propagators/base.py b/src/struphy/propagators/base.py index ac7887ea8..ee0cc39ba 100644 --- a/src/struphy/propagators/base.py +++ b/src/struphy/propagators/base.py @@ -2,7 +2,7 @@ from abc import ABCMeta, abstractmethod -import numpy as np +from struphy.arrays import xp as np from struphy.feec.basis_projection_ops import BasisProjectionOperators from struphy.feec.mass import WeightedMassOperators diff --git a/src/struphy/propagators/propagators_coupling.py b/src/struphy/propagators/propagators_coupling.py index f7a38b5ac..9e1df7653 100644 --- a/src/struphy/propagators/propagators_coupling.py +++ b/src/struphy/propagators/propagators_coupling.py @@ -1,6 +1,6 @@ "Particle and FEEC variables are updated." -import numpy as np +from struphy.arrays import xp as np from psydac.linalg.block import BlockVector from psydac.linalg.stencil import StencilVector diff --git a/src/struphy/propagators/propagators_fields.py b/src/struphy/propagators/propagators_fields.py index f690b501d..2d73e8971 100644 --- a/src/struphy/propagators/propagators_fields.py +++ b/src/struphy/propagators/propagators_fields.py @@ -3,7 +3,7 @@ from collections.abc import Callable from copy import deepcopy -import numpy as np +from struphy.arrays import xp as np import scipy as sc from matplotlib import pyplot as plt from mpi4py import MPI diff --git a/src/struphy/propagators/propagators_markers.py b/src/struphy/propagators/propagators_markers.py index 46a941707..847ede30e 100644 --- a/src/struphy/propagators/propagators_markers.py +++ b/src/struphy/propagators/propagators_markers.py @@ -1,6 +1,6 @@ "Only particle variables are updated." -import numpy as np +from struphy.arrays import xp as np from numpy import array, polynomial, random from psydac.linalg.block import BlockVector from psydac.linalg.stencil import StencilVector @@ -72,7 +72,7 @@ def __init__( # define algorithm butcher = ButcherTableau(algo) # temp fix due to refactoring of ButcherTableau: - import numpy as np + from struphy.arrays import xp as np butcher._a = np.diag(butcher.a, k=-1) butcher._a = np.array(list(butcher.a) + [0.0]) @@ -713,7 +713,7 @@ def __init__( else: butcher = ButcherTableau(algo["method"]) # temp fix due to refactoring of ButcherTableau: - import numpy as np + from struphy.arrays import xp as np butcher._a = np.diag(butcher.a, k=-1) butcher._a = np.array(list(butcher.a) + [0.0]) @@ -1132,7 +1132,7 @@ def __init__( else: butcher = ButcherTableau(algo["method"]) # temp fix due to refactoring of ButcherTableau: - import numpy as np + from struphy.arrays import xp as np butcher._a = np.diag(butcher.a, k=-1) butcher._a = np.array(list(butcher.a) + [0.0]) @@ -1342,7 +1342,7 @@ def __init__( # choose algorithm self._butcher = ButcherTableau(algo) # temp fix due to refactoring of ButcherTableau: - import numpy as np + from struphy.arrays import xp as np self._butcher._a = np.diag(self._butcher.a, k=-1) self._butcher._a = np.array(list(self._butcher.a) + [0.0]) @@ -1445,7 +1445,7 @@ def __init__( # choose algorithm self._butcher = ButcherTableau("forward_euler") # temp fix due to refactoring of ButcherTableau: - import numpy as np + from struphy.arrays import xp as np self._butcher._a = np.diag(self._butcher.a, k=-1) self._butcher._a = np.array(list(self._butcher.a) + [0.0]) diff --git a/src/struphy/propagators/tests/test_gyrokinetic_poisson.py b/src/struphy/propagators/tests/test_gyrokinetic_poisson.py index 040cc4658..5fa4abbf8 100644 --- a/src/struphy/propagators/tests/test_gyrokinetic_poisson.py +++ b/src/struphy/propagators/tests/test_gyrokinetic_poisson.py @@ -1,5 +1,5 @@ import matplotlib.pyplot as plt -import numpy as np +from struphy.arrays import xp as np import pytest from mpi4py import MPI diff --git a/src/struphy/propagators/tests/test_poisson.py b/src/struphy/propagators/tests/test_poisson.py index cb6aec5c3..5e5c4ec75 100644 --- a/src/struphy/propagators/tests/test_poisson.py +++ b/src/struphy/propagators/tests/test_poisson.py @@ -1,5 +1,5 @@ import matplotlib.pyplot as plt -import numpy as np +from struphy.arrays import xp as np import pytest from mpi4py import MPI diff --git a/src/struphy/utils/clone_config.py b/src/struphy/utils/clone_config.py index b4894e2cf..289bb582a 100644 --- a/src/struphy/utils/clone_config.py +++ b/src/struphy/utils/clone_config.py @@ -1,4 +1,4 @@ -import numpy as np +from struphy.arrays import xp as np from mpi4py import MPI diff --git a/src/struphy/utils/utils.py b/src/struphy/utils/utils.py index 46be2d25b..24462fd17 100644 --- a/src/struphy/utils/utils.py +++ b/src/struphy/utils/utils.py @@ -61,7 +61,7 @@ def save_state(state, libpath=STRUPHY_LIBPATH): def print_all_attr(obj): """Print all object's attributes that do not start with "_" to screen.""" - import numpy as np + from struphy.arrays import xp as np for k in dir(obj): if k[0] != "_": From b634b23c271b1261f2205ce5fa4fa1f94ec865bb Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 9 Oct 2025 23:59:37 +0200 Subject: [PATCH 40/76] Fix in src/struphy/test_xp.py --- src/struphy/test_xp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/struphy/test_xp.py b/src/struphy/test_xp.py index d32044a58..5467932fc 100644 --- a/src/struphy/test_xp.py +++ b/src/struphy/test_xp.py @@ -1,6 +1,6 @@ import time -from arrays import xp +from struphy.arrays import xp def main(N=8192): From c54bdc648053dfc4acf5564f40c2f014fba93f75 Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 10 Oct 2025 00:02:58 +0200 Subject: [PATCH 41/76] renamed test_xp.py --- .gitlab-ci.yml | 4 ++-- src/struphy/{test_xp.py => cupy_vs_numpy.py} | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) rename src/struphy/{test_xp.py => cupy_vs_numpy.py} (95%) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 94151413c..4737c8309 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -514,10 +514,10 @@ test_cupy: - python3 -m pip install --user cupy-cuda12x - python3 -c "import cupy as cp" - python3 src/struphy/arrays.py - - python3 src/struphy/test_xp.py + - python3 src/struphy/cupy_vs_numpy.py - export ARRAY_BACKEND=cupy - python3 src/struphy/arrays.py - - python3 src/struphy/test_xp.py + - python3 src/struphy/cupy_vs_numpy.py # ##################### # ### PUSH PIPELINE ### diff --git a/src/struphy/test_xp.py b/src/struphy/cupy_vs_numpy.py similarity index 95% rename from src/struphy/test_xp.py rename to src/struphy/cupy_vs_numpy.py index 5467932fc..d32044a58 100644 --- a/src/struphy/test_xp.py +++ b/src/struphy/cupy_vs_numpy.py @@ -1,6 +1,6 @@ import time -from struphy.arrays import xp +from arrays import xp def main(N=8192): From 947aa7fb8d8936180f93e87b44fa2d2b55fc7d3c Mon Sep 17 00:00:00 2001 From: Max Lindqvist Date: Fri, 10 Oct 2025 09:08:09 +0200 Subject: [PATCH 42/76] Formatting --- .../bsplines/tests/test_bsplines_kernels.py | 3 ++- src/struphy/bsplines/tests/test_eval_spline_mpi.py | 3 ++- src/struphy/console/profile.py | 2 +- src/struphy/diagnostics/console_diagn.py | 2 +- src/struphy/diagnostics/continuous_spectra.py | 6 +++--- src/struphy/diagnostics/diagn_tools.py | 2 +- src/struphy/diagnostics/paraview/mesh_creator.py | 4 ++-- src/struphy/dispersion_relations/analytic.py | 2 +- src/struphy/dispersion_relations/base.py | 3 ++- src/struphy/dispersion_relations/utilities.py | 3 ++- src/struphy/eigenvalue_solvers/derivatives.py | 3 ++- .../legacy/MHD_eigenvalues_cylinder_1D.py | 2 +- .../legacy/control_variates/control_variate.py | 2 +- .../fB_massless_control_variate.py | 2 +- .../fnB_massless_control_variate.py | 3 ++- .../kinetic_extended/massless_control_variate.py | 3 ++- .../eigenvalue_solvers/legacy/emw_operators.py | 2 +- .../eigenvalue_solvers/legacy/inner_products_1d.py | 3 ++- .../eigenvalue_solvers/legacy/inner_products_2d.py | 2 +- .../eigenvalue_solvers/legacy/inner_products_3d.py | 2 +- .../eigenvalue_solvers/legacy/l2_error_1d.py | 3 ++- .../eigenvalue_solvers/legacy/l2_error_2d.py | 2 +- .../eigenvalue_solvers/legacy/l2_error_3d.py | 2 +- .../legacy/mass_matrices_3d_pre.py | 2 +- .../legacy/massless_operators/fB_arrays.py | 2 +- .../fB_massless_linear_operators.py | 2 +- .../legacy/massless_operators/fB_vv_kernel.py | 2 +- .../eigenvalue_solvers/legacy/mhd_operators_MF.py | 2 +- .../pro_local/mhd_operators_3d_local.py | 2 +- .../projectors_local/pro_local/projectors_local.py | 2 +- .../shape_function_projectors_L2.py | 2 +- .../shape_function_projectors_local.py | 2 +- src/struphy/eigenvalue_solvers/mass_matrices_1d.py | 2 +- src/struphy/eigenvalue_solvers/mass_matrices_2d.py | 2 +- src/struphy/eigenvalue_solvers/mass_matrices_3d.py | 2 +- .../eigenvalue_solvers/mhd_axisymmetric_main.py | 2 +- .../eigenvalue_solvers/mhd_axisymmetric_pproc.py | 3 ++- src/struphy/eigenvalue_solvers/mhd_operators.py | 2 +- .../eigenvalue_solvers/mhd_operators_core.py | 2 +- .../eigenvalue_solvers/projectors_global.py | 2 +- src/struphy/eigenvalue_solvers/spline_space.py | 3 ++- src/struphy/examples/_draw_parallel.py | 2 +- src/struphy/feec/basis_projection_ops.py | 2 +- src/struphy/feec/linear_operators.py | 2 +- src/struphy/feec/mass.py | 2 +- src/struphy/feec/preconditioner.py | 2 +- src/struphy/feec/projectors.py | 2 +- src/struphy/feec/psydac_derham.py | 2 +- src/struphy/feec/tests/test_basis_ops.py | 4 ++-- src/struphy/feec/tests/test_derham.py | 2 +- src/struphy/feec/tests/test_eval_field.py | 3 ++- src/struphy/feec/tests/test_field_init.py | 8 ++++---- src/struphy/feec/tests/test_l2_projectors.py | 2 +- src/struphy/feec/tests/test_local_projectors.py | 2 +- src/struphy/feec/tests/test_lowdim_nel_is_1.py | 2 +- src/struphy/feec/tests/test_mass_matrices.py | 8 ++++---- src/struphy/feec/tests/test_toarray_struphy.py | 2 +- src/struphy/feec/tests/test_tosparse_struphy.py | 2 +- src/struphy/feec/tests/xx_test_preconds.py | 2 +- src/struphy/feec/utilities.py | 2 +- src/struphy/feec/utilities_local_projectors.py | 1 - src/struphy/feec/variational_utilities.py | 2 +- src/struphy/fields_background/base.py | 2 +- src/struphy/fields_background/coil_fields/base.py | 3 ++- .../fields_background/coil_fields/coil_fields.py | 1 - src/struphy/fields_background/equils.py | 2 +- .../fields_background/tests/test_desc_equil.py | 3 ++- .../fields_background/tests/test_generic_equils.py | 2 +- .../fields_background/tests/test_mhd_equils.py | 2 +- .../tests/test_numerical_mhd_equil.py | 2 +- src/struphy/geometry/base.py | 2 +- src/struphy/geometry/domains.py | 1 - src/struphy/geometry/tests/test_domain.py | 5 ----- src/struphy/geometry/utilities.py | 2 +- src/struphy/initial/eigenfunctions.py | 2 +- src/struphy/initial/perturbations.py | 3 ++- .../initial/tests/test_init_perturbations.py | 2 +- src/struphy/initial/utilities.py | 2 +- src/struphy/io/output_handling.py | 1 + src/struphy/io/setup.py | 2 +- src/struphy/kinetic_background/base.py | 1 - src/struphy/kinetic_background/maxwellians.py | 1 - src/struphy/kinetic_background/tests/test_base.py | 2 +- .../kinetic_background/tests/test_maxwellians.py | 14 +++++++------- src/struphy/linear_algebra/linalg_kron.py | 3 ++- src/struphy/linear_algebra/saddle_point.py | 2 +- .../tests/test_saddlepoint_massmatrices.py | 3 ++- .../tests/test_stencil_dot_kernels.py | 4 ++-- .../tests/test_stencil_transpose_kernels.py | 4 ++-- src/struphy/main.py | 2 +- src/struphy/models/base.py | 2 +- src/struphy/models/fluid.py | 1 - src/struphy/models/hybrid.py | 1 - src/struphy/models/kinetic.py | 1 - src/struphy/models/tests/verification.py | 2 +- src/struphy/models/toy.py | 1 - src/struphy/ode/solvers.py | 2 +- src/struphy/ode/tests/test_ode_feec.py | 2 +- src/struphy/pic/accumulation/particles_to_grid.py | 2 +- src/struphy/pic/base.py | 2 +- src/struphy/pic/particles.py | 1 - src/struphy/pic/pushing/pusher.py | 2 +- src/struphy/pic/sobol_seq.py | 3 ++- src/struphy/pic/tests/test_accum_vec_H1.py | 2 +- src/struphy/pic/tests/test_accumulation.py | 2 +- src/struphy/pic/tests/test_binning.py | 8 ++++---- src/struphy/pic/tests/test_draw_parallel.py | 2 +- src/struphy/pic/tests/test_mat_vec_filler.py | 3 ++- .../tests/test_pic_legacy_files/accumulation.py | 2 +- .../pic/tests/test_pic_legacy_files/pusher.py | 3 +-- src/struphy/pic/tests/test_pushers.py | 12 ++++++------ src/struphy/pic/tests/test_sorting.py | 2 +- src/struphy/pic/tests/test_sph.py | 2 +- src/struphy/pic/tests/test_tesselation.py | 2 +- src/struphy/pic/utilities.py | 3 +-- src/struphy/polar/basic.py | 3 ++- src/struphy/polar/linear_operators.py | 2 +- .../polar/tests/test_legacy_polar_splines.py | 2 +- src/struphy/polar/tests/test_polar.py | 4 ++-- .../post_processing/likwid/plot_likwidproject.py | 2 +- .../post_processing/likwid/plot_time_traces.py | 2 +- .../post_processing/likwid/roofline_plotter.py | 3 ++- src/struphy/post_processing/orbits/orbits_tools.py | 2 +- .../post_processing/post_processing_tools.py | 2 +- src/struphy/post_processing/pproc_struphy.py | 2 +- src/struphy/post_processing/profile_struphy.py | 2 +- src/struphy/profiling/profiling.py | 3 ++- src/struphy/propagators/base.py | 1 - src/struphy/propagators/propagators_coupling.py | 2 +- src/struphy/propagators/propagators_fields.py | 2 +- src/struphy/propagators/propagators_markers.py | 2 +- .../propagators/tests/test_gyrokinetic_poisson.py | 2 +- src/struphy/propagators/tests/test_poisson.py | 2 +- src/struphy/utils/clone_config.py | 3 ++- 134 files changed, 172 insertions(+), 166 deletions(-) diff --git a/src/struphy/bsplines/tests/test_bsplines_kernels.py b/src/struphy/bsplines/tests/test_bsplines_kernels.py index 49504b169..387886625 100644 --- a/src/struphy/bsplines/tests/test_bsplines_kernels.py +++ b/src/struphy/bsplines/tests/test_bsplines_kernels.py @@ -1,9 +1,10 @@ import time -from struphy.arrays import xp as np import pytest from mpi4py import MPI +from struphy.arrays import xp as np + @pytest.mark.mpi(min_size=2) @pytest.mark.parametrize("Nel", [[8, 9, 10]]) diff --git a/src/struphy/bsplines/tests/test_eval_spline_mpi.py b/src/struphy/bsplines/tests/test_eval_spline_mpi.py index d1135c6e0..b582971a4 100644 --- a/src/struphy/bsplines/tests/test_eval_spline_mpi.py +++ b/src/struphy/bsplines/tests/test_eval_spline_mpi.py @@ -1,10 +1,11 @@ from sys import int_info from time import sleep -from struphy.arrays import xp as np import pytest from mpi4py import MPI +from struphy.arrays import xp as np + @pytest.mark.mpi(min_size=2) @pytest.mark.parametrize("Nel", [[8, 9, 10]]) diff --git a/src/struphy/console/profile.py b/src/struphy/console/profile.py index ee0e39920..4f57320a3 100644 --- a/src/struphy/console/profile.py +++ b/src/struphy/console/profile.py @@ -6,11 +6,11 @@ def struphy_profile(dirs, replace, all, n_lines, print_callers, savefig): import os import pickle - from struphy.arrays import xp as np import yaml from matplotlib import pyplot as plt import struphy.utils.utils as utils + from struphy.arrays import xp as np from struphy.post_processing.cprofile_analyser import get_cprofile_data, replace_keys # Read struphy state file diff --git a/src/struphy/diagnostics/console_diagn.py b/src/struphy/diagnostics/console_diagn.py index 4d0061442..214f7a0da 100644 --- a/src/struphy/diagnostics/console_diagn.py +++ b/src/struphy/diagnostics/console_diagn.py @@ -6,11 +6,11 @@ import subprocess import h5py -from struphy.arrays import xp as np import yaml import struphy import struphy.utils.utils as utils +from struphy.arrays import xp as np from struphy.diagnostics.diagn_tools import plot_distr_fun, plot_scalars, plots_videos_2d diff --git a/src/struphy/diagnostics/continuous_spectra.py b/src/struphy/diagnostics/continuous_spectra.py index ad791dfa8..940f76c86 100644 --- a/src/struphy/diagnostics/continuous_spectra.py +++ b/src/struphy/diagnostics/continuous_spectra.py @@ -37,9 +37,8 @@ def get_mhd_continua_2d(space, domain, omega2, U_eig, m_range, omega_A, div_tol, the radial location s_spec[m][0], squared eigenfrequencis s_spec[m][1] and global mode index s_spec[m][2] corresponding to slow sound modes for each poloidal mode number m in m_range. """ - from struphy.arrays import xp as np - import struphy.bsplines.bsplines as bsp + from struphy.arrays import xp as np # greville points in radial direction (s) gN_1 = bsp.greville(space.T[0], space.p[0], space.spl_kind[0]) @@ -152,9 +151,10 @@ def get_mhd_continua_2d(space, domain, omega2, U_eig, m_range, omega_A, div_tol, import os import shutil - from struphy.arrays import xp as np import yaml + from struphy.arrays import xp as np + # parse arguments parser = argparse.ArgumentParser( description="Looks for eigenmodes in a given MHD eigenspectrum in a certain poloidal mode number range and plots the continuous shear Alfvén and slow sound spectra (frequency versus radial-like coordinate)." diff --git a/src/struphy/diagnostics/diagn_tools.py b/src/struphy/diagnostics/diagn_tools.py index 8b937b1c8..0811e23e3 100644 --- a/src/struphy/diagnostics/diagn_tools.py +++ b/src/struphy/diagnostics/diagn_tools.py @@ -5,11 +5,11 @@ import matplotlib.colors as colors import matplotlib.pyplot as plt -from struphy.arrays import xp as np from scipy.fft import fftfreq, fftn from scipy.signal import argrelextrema from tqdm import tqdm +from struphy.arrays import xp as np from struphy.dispersion_relations import analytic diff --git a/src/struphy/diagnostics/paraview/mesh_creator.py b/src/struphy/diagnostics/paraview/mesh_creator.py index c994d7908..51d002c06 100644 --- a/src/struphy/diagnostics/paraview/mesh_creator.py +++ b/src/struphy/diagnostics/paraview/mesh_creator.py @@ -1,11 +1,11 @@ -from struphy.arrays import xp as np - # from tqdm import tqdm import vtkmodules.all as vtk from vtkmodules.util.numpy_support import numpy_to_vtk as np2vtk from vtkmodules.util.numpy_support import vtk_to_numpy as vtk2np from vtkmodules.vtkCommonDataModel import vtkUnstructuredGrid +from struphy.arrays import xp as np + def make_ugrid_and_write_vtu(filename: str, writer, vtk_dir, gvec, s_range, u_range, v_range, periodic): """A helper function to orchestrate operations to run many test cases. diff --git a/src/struphy/dispersion_relations/analytic.py b/src/struphy/dispersion_relations/analytic.py index c203aa99c..97a99ac7e 100644 --- a/src/struphy/dispersion_relations/analytic.py +++ b/src/struphy/dispersion_relations/analytic.py @@ -1,9 +1,9 @@ "Analytic dispersion relations." -from struphy.arrays import xp as np from numpy.polynomial import Polynomial from scipy.optimize import fsolve +from struphy.arrays import xp as np from struphy.dispersion_relations.base import ContinuousSpectra1D, DispersionRelations1D from struphy.dispersion_relations.utilities import Zplasma from struphy.fields_background.equils import set_defaults diff --git a/src/struphy/dispersion_relations/base.py b/src/struphy/dispersion_relations/base.py index 8b213549d..eae8f5f57 100644 --- a/src/struphy/dispersion_relations/base.py +++ b/src/struphy/dispersion_relations/base.py @@ -2,9 +2,10 @@ from abc import ABCMeta, abstractmethod -from struphy.arrays import xp as np from matplotlib import pyplot as plt +from struphy.arrays import xp as np + class DispersionRelations1D(metaclass=ABCMeta): r""" diff --git a/src/struphy/dispersion_relations/utilities.py b/src/struphy/dispersion_relations/utilities.py index c26ecb271..66a86ddbb 100644 --- a/src/struphy/dispersion_relations/utilities.py +++ b/src/struphy/dispersion_relations/utilities.py @@ -1,6 +1,7 @@ -from struphy.arrays import xp as np from scipy.special import erfi +from struphy.arrays import xp as np + def Zplasma(xi, der=0): """ diff --git a/src/struphy/eigenvalue_solvers/derivatives.py b/src/struphy/eigenvalue_solvers/derivatives.py index 9ec0529ed..40e64a0ed 100644 --- a/src/struphy/eigenvalue_solvers/derivatives.py +++ b/src/struphy/eigenvalue_solvers/derivatives.py @@ -6,9 +6,10 @@ Modules to assemble discrete derivatives. """ -from struphy.arrays import xp as np import scipy.sparse as spa +from struphy.arrays import xp as np + # ================== 1d incident matrix ======================= def grad_1d_matrix(spl_kind, NbaseN): diff --git a/src/struphy/eigenvalue_solvers/legacy/MHD_eigenvalues_cylinder_1D.py b/src/struphy/eigenvalue_solvers/legacy/MHD_eigenvalues_cylinder_1D.py index d86000069..bea3f3cbe 100644 --- a/src/struphy/eigenvalue_solvers/legacy/MHD_eigenvalues_cylinder_1D.py +++ b/src/struphy/eigenvalue_solvers/legacy/MHD_eigenvalues_cylinder_1D.py @@ -1,4 +1,3 @@ -from struphy.arrays import xp as np import scipy as sc import scipy.sparse as spa import scipy.special as sp @@ -10,6 +9,7 @@ import struphy.eigenvalue_solvers.mass_matrices_1d as mass import struphy.eigenvalue_solvers.projectors_global as pro import struphy.eigenvalue_solvers.spline_space as spl +from struphy.arrays import xp as np # numerical solution of the general ideal MHD eigenvalue problem in a cylinder using 1d B-splines in radial direction diff --git a/src/struphy/eigenvalue_solvers/legacy/control_variates/control_variate.py b/src/struphy/eigenvalue_solvers/legacy/control_variates/control_variate.py index f5df27d77..ad448fcb2 100644 --- a/src/struphy/eigenvalue_solvers/legacy/control_variates/control_variate.py +++ b/src/struphy/eigenvalue_solvers/legacy/control_variates/control_variate.py @@ -6,11 +6,11 @@ Class for control variates in delta-f method for current coupling scheme. """ -from struphy.arrays import xp as np import scipy.sparse as spa import struphy.feec.basics.kernels_3d as ker import struphy.feec.control_variates.kernels_control_variate as ker_cv +from struphy.arrays import xp as np class terms_control_variate: diff --git a/src/struphy/eigenvalue_solvers/legacy/control_variates/kinetic_extended/fB_massless_control_variate.py b/src/struphy/eigenvalue_solvers/legacy/control_variates/kinetic_extended/fB_massless_control_variate.py index b0872c07b..36889f1bf 100644 --- a/src/struphy/eigenvalue_solvers/legacy/control_variates/kinetic_extended/fB_massless_control_variate.py +++ b/src/struphy/eigenvalue_solvers/legacy/control_variates/kinetic_extended/fB_massless_control_variate.py @@ -1,9 +1,9 @@ -from struphy.arrays import xp as np import scipy.sparse as spa import struphy.feec.basics.kernels_3d as ker import struphy.feec.control_variates.kinetic_extended.fB_massless_kernels_control_variate as ker_cv import struphy.feec.control_variates.kinetic_extended.fnB_massless_cv_kernel_2 as ker_cv2 +from struphy.arrays import xp as np def bv_right( diff --git a/src/struphy/eigenvalue_solvers/legacy/control_variates/kinetic_extended/fnB_massless_control_variate.py b/src/struphy/eigenvalue_solvers/legacy/control_variates/kinetic_extended/fnB_massless_control_variate.py index b3906fa69..df29e23dc 100644 --- a/src/struphy/eigenvalue_solvers/legacy/control_variates/kinetic_extended/fnB_massless_control_variate.py +++ b/src/struphy/eigenvalue_solvers/legacy/control_variates/kinetic_extended/fnB_massless_control_variate.py @@ -1,8 +1,9 @@ import hylife.utilitis_FEEC.basics.kernels_3d as ker import hylife.utilitis_FEEC.control_variates.fnB_massless_kernels_control_variate as ker_cv -from struphy.arrays import xp as np import scipy.sparse as spa +from struphy.arrays import xp as np + def bv_pre(tol, n, LO_inv, tensor_space_FEM, p, Nel, idnx, idny, idnz): r""" diff --git a/src/struphy/eigenvalue_solvers/legacy/control_variates/kinetic_extended/massless_control_variate.py b/src/struphy/eigenvalue_solvers/legacy/control_variates/kinetic_extended/massless_control_variate.py index 5aa74841b..f5d75b9cf 100644 --- a/src/struphy/eigenvalue_solvers/legacy/control_variates/kinetic_extended/massless_control_variate.py +++ b/src/struphy/eigenvalue_solvers/legacy/control_variates/kinetic_extended/massless_control_variate.py @@ -1,8 +1,9 @@ import hylife.utilitis_FEEC.basics.kernels_3d as ker import hylife.utilitis_FEEC.control_variates.massless_kernels_control_variate as ker_cv -from struphy.arrays import xp as np import scipy.sparse as spa +from struphy.arrays import xp as np + def bv_pre(u, uvalue, tensor_space_FEM, p, Nel, idnx, idny, idnz): r""" diff --git a/src/struphy/eigenvalue_solvers/legacy/emw_operators.py b/src/struphy/eigenvalue_solvers/legacy/emw_operators.py index ab99918dd..0d7237036 100755 --- a/src/struphy/eigenvalue_solvers/legacy/emw_operators.py +++ b/src/struphy/eigenvalue_solvers/legacy/emw_operators.py @@ -6,11 +6,11 @@ Class for 2D/3D linear MHD projection operators. """ -from struphy.arrays import xp as np import scipy.sparse as spa import struphy.eigenvalue_solvers.kernels_3d as ker import struphy.eigenvalue_solvers.legacy.mass_matrices_3d_pre as mass_3d_pre +from struphy.arrays import xp as np class EMW_operators: diff --git a/src/struphy/eigenvalue_solvers/legacy/inner_products_1d.py b/src/struphy/eigenvalue_solvers/legacy/inner_products_1d.py index 8451ef01a..84fd96b12 100644 --- a/src/struphy/eigenvalue_solvers/legacy/inner_products_1d.py +++ b/src/struphy/eigenvalue_solvers/legacy/inner_products_1d.py @@ -6,9 +6,10 @@ Modules to compute inner products in 1d. """ -from struphy.arrays import xp as np import scipy.sparse as spa +from struphy.arrays import xp as np + # ======= inner product in V0 ==================== def inner_prod_V0(spline_space, fun, mapping=None): diff --git a/src/struphy/eigenvalue_solvers/legacy/inner_products_2d.py b/src/struphy/eigenvalue_solvers/legacy/inner_products_2d.py index 9ac13af21..16ffb76c2 100644 --- a/src/struphy/eigenvalue_solvers/legacy/inner_products_2d.py +++ b/src/struphy/eigenvalue_solvers/legacy/inner_products_2d.py @@ -6,10 +6,10 @@ Modules to compute inner products with given functions in 2D. """ -from struphy.arrays import xp as np import scipy.sparse as spa import struphy.eigenvalue_solvers.kernels_2d as ker +from struphy.arrays import xp as np # ================ inner product in V0 =========================== diff --git a/src/struphy/eigenvalue_solvers/legacy/inner_products_3d.py b/src/struphy/eigenvalue_solvers/legacy/inner_products_3d.py index e806fb420..985fbe4bc 100644 --- a/src/struphy/eigenvalue_solvers/legacy/inner_products_3d.py +++ b/src/struphy/eigenvalue_solvers/legacy/inner_products_3d.py @@ -6,10 +6,10 @@ Modules to compute inner products with given functions in 3D. """ -from struphy.arrays import xp as np import scipy.sparse as spa import struphy.eigenvalue_solvers.kernels_3d as ker +from struphy.arrays import xp as np # ================ inner product in V0 =========================== diff --git a/src/struphy/eigenvalue_solvers/legacy/l2_error_1d.py b/src/struphy/eigenvalue_solvers/legacy/l2_error_1d.py index ecd609c31..82b13a974 100644 --- a/src/struphy/eigenvalue_solvers/legacy/l2_error_1d.py +++ b/src/struphy/eigenvalue_solvers/legacy/l2_error_1d.py @@ -6,9 +6,10 @@ Modules to compute L2-errors in 1d. """ -from struphy.arrays import xp as np import scipy.sparse as spa +from struphy.arrays import xp as np + # ======= error in V0 ==================== def l2_error_V0(spline_space, mapping, coeff, fun): diff --git a/src/struphy/eigenvalue_solvers/legacy/l2_error_2d.py b/src/struphy/eigenvalue_solvers/legacy/l2_error_2d.py index f29e75d48..9a8cf24e6 100644 --- a/src/struphy/eigenvalue_solvers/legacy/l2_error_2d.py +++ b/src/struphy/eigenvalue_solvers/legacy/l2_error_2d.py @@ -6,10 +6,10 @@ Modules to compute L2-errors of discrete p-forms with analytical forms in 2D. """ -from struphy.arrays import xp as np import scipy.sparse as spa import struphy.eigenvalue_solvers.kernels_2d as ker +from struphy.arrays import xp as np # ======= error in V0 ==================== diff --git a/src/struphy/eigenvalue_solvers/legacy/l2_error_3d.py b/src/struphy/eigenvalue_solvers/legacy/l2_error_3d.py index efe860064..44b19e90d 100644 --- a/src/struphy/eigenvalue_solvers/legacy/l2_error_3d.py +++ b/src/struphy/eigenvalue_solvers/legacy/l2_error_3d.py @@ -6,10 +6,10 @@ Modules to compute L2-errors of discrete p-forms with analytical forms in 3D. """ -from struphy.arrays import xp as np import scipy.sparse as spa import struphy.eigenvalue_solvers.kernels_3d as ker +from struphy.arrays import xp as np # ======= error in V0 ==================== diff --git a/src/struphy/eigenvalue_solvers/legacy/mass_matrices_3d_pre.py b/src/struphy/eigenvalue_solvers/legacy/mass_matrices_3d_pre.py index ac7b19a23..c1d4b242d 100644 --- a/src/struphy/eigenvalue_solvers/legacy/mass_matrices_3d_pre.py +++ b/src/struphy/eigenvalue_solvers/legacy/mass_matrices_3d_pre.py @@ -6,11 +6,11 @@ Modules to obtain preconditioners for mass matrices in 3D. """ -from struphy.arrays import xp as np import scipy.sparse as spa import struphy.eigenvalue_solvers.spline_space as spl import struphy.linear_algebra.linalg_kron as linkron +from struphy.arrays import xp as np # ================ inverse mass matrix in V0 =========================== diff --git a/src/struphy/eigenvalue_solvers/legacy/massless_operators/fB_arrays.py b/src/struphy/eigenvalue_solvers/legacy/massless_operators/fB_arrays.py index b0ab5f566..e3dce71d9 100644 --- a/src/struphy/eigenvalue_solvers/legacy/massless_operators/fB_arrays.py +++ b/src/struphy/eigenvalue_solvers/legacy/massless_operators/fB_arrays.py @@ -1,13 +1,13 @@ import time import timeit -from struphy.arrays import xp as np import scipy.sparse as spa from mpi4py import MPI import struphy.geometry.mappings_3d as mapping3d import struphy.geometry.mappings_3d_fast as mapping_fast import struphy.linear_algebra.linalg_kernels as linalg +from struphy.arrays import xp as np class Temp_arrays: diff --git a/src/struphy/eigenvalue_solvers/legacy/massless_operators/fB_massless_linear_operators.py b/src/struphy/eigenvalue_solvers/legacy/massless_operators/fB_massless_linear_operators.py index 1012ee1ff..af195fcdd 100644 --- a/src/struphy/eigenvalue_solvers/legacy/massless_operators/fB_massless_linear_operators.py +++ b/src/struphy/eigenvalue_solvers/legacy/massless_operators/fB_massless_linear_operators.py @@ -1,11 +1,11 @@ import time -from struphy.arrays import xp as np import scipy.sparse as spa import struphy.feec.massless_operators.fB_bb_kernel as bb_kernel import struphy.feec.massless_operators.fB_bv_kernel as bv_kernel import struphy.feec.massless_operators.fB_vv_kernel as vv_kernel +from struphy.arrays import xp as np class Massless_linear_operators: diff --git a/src/struphy/eigenvalue_solvers/legacy/massless_operators/fB_vv_kernel.py b/src/struphy/eigenvalue_solvers/legacy/massless_operators/fB_vv_kernel.py index 1c99ce628..8850b4107 100644 --- a/src/struphy/eigenvalue_solvers/legacy/massless_operators/fB_vv_kernel.py +++ b/src/struphy/eigenvalue_solvers/legacy/massless_operators/fB_vv_kernel.py @@ -1,9 +1,9 @@ -from struphy.arrays import xp as np from numpy import empty, exp, floor, zeros import struphy.bsplines.bsplines_kernels as bsp import struphy.geometry.mappings_kernels as mapping_fast import struphy.linear_algebra.linalg_kernels as linalg +from struphy.arrays import xp as np # ========================================================================================== diff --git a/src/struphy/eigenvalue_solvers/legacy/mhd_operators_MF.py b/src/struphy/eigenvalue_solvers/legacy/mhd_operators_MF.py index 89737bb10..bd343c2b4 100644 --- a/src/struphy/eigenvalue_solvers/legacy/mhd_operators_MF.py +++ b/src/struphy/eigenvalue_solvers/legacy/mhd_operators_MF.py @@ -1,6 +1,6 @@ -from struphy.arrays import xp as np import scipy.sparse as spa +from struphy.arrays import xp as np from struphy.eigenvalue_solvers.projectors_global import Projectors_tensor_3d from struphy.eigenvalue_solvers.spline_space import Tensor_spline_space from struphy.linear_algebra.linalg_kron import kron_matvec_3d, kron_solve_3d diff --git a/src/struphy/eigenvalue_solvers/legacy/projectors_local/pro_local/mhd_operators_3d_local.py b/src/struphy/eigenvalue_solvers/legacy/projectors_local/pro_local/mhd_operators_3d_local.py index 7d9e27cb7..61e9bbd8e 100644 --- a/src/struphy/eigenvalue_solvers/legacy/projectors_local/pro_local/mhd_operators_3d_local.py +++ b/src/struphy/eigenvalue_solvers/legacy/projectors_local/pro_local/mhd_operators_3d_local.py @@ -8,13 +8,13 @@ import sys -from struphy.arrays import xp as np import scipy.sparse as spa import source_run.kernels_projectors_evaluation as ker_eva import struphy.feec.basics.kernels_3d as ker_loc_3d import struphy.feec.bsplines as bsp import struphy.feec.projectors.pro_local.kernels_projectors_local_mhd as ker_loc +from struphy.arrays import xp as np class projectors_local_mhd: diff --git a/src/struphy/eigenvalue_solvers/legacy/projectors_local/pro_local/projectors_local.py b/src/struphy/eigenvalue_solvers/legacy/projectors_local/pro_local/projectors_local.py index 247857d5f..d465b28c2 100644 --- a/src/struphy/eigenvalue_solvers/legacy/projectors_local/pro_local/projectors_local.py +++ b/src/struphy/eigenvalue_solvers/legacy/projectors_local/pro_local/projectors_local.py @@ -6,11 +6,11 @@ Classes for local projectors in 1D and 3D based on quasi-spline interpolation and histopolation. """ -from struphy.arrays import xp as np import scipy.sparse as spa import struphy.feec.bsplines as bsp import struphy.feec.projectors.pro_local.kernels_projectors_local as ker_loc +from struphy.arrays import xp as np # ======================= 1d ==================================== diff --git a/src/struphy/eigenvalue_solvers/legacy/projectors_local/shape_pro_local/shape_function_projectors_L2.py b/src/struphy/eigenvalue_solvers/legacy/projectors_local/shape_pro_local/shape_function_projectors_L2.py index 61426fe24..8a132ed61 100644 --- a/src/struphy/eigenvalue_solvers/legacy/projectors_local/shape_pro_local/shape_function_projectors_L2.py +++ b/src/struphy/eigenvalue_solvers/legacy/projectors_local/shape_pro_local/shape_function_projectors_L2.py @@ -5,12 +5,12 @@ Classes for local projectors in 1D and 3D based on quasi-spline interpolation and histopolation. """ -from struphy.arrays import xp as np import scipy.sparse as spa from mpi4py import MPI import struphy.feec.bsplines as bsp import struphy.feec.projectors.shape_pro_local.shape_L2_projector_kernel as ker_loc +from struphy.arrays import xp as np # ======================= 3d ==================================== diff --git a/src/struphy/eigenvalue_solvers/legacy/projectors_local/shape_pro_local/shape_function_projectors_local.py b/src/struphy/eigenvalue_solvers/legacy/projectors_local/shape_pro_local/shape_function_projectors_local.py index f369349d8..cfad48c0e 100644 --- a/src/struphy/eigenvalue_solvers/legacy/projectors_local/shape_pro_local/shape_function_projectors_local.py +++ b/src/struphy/eigenvalue_solvers/legacy/projectors_local/shape_pro_local/shape_function_projectors_local.py @@ -5,12 +5,12 @@ Classes for local projectors in 1D and 3D based on quasi-spline interpolation and histopolation. """ -from struphy.arrays import xp as np import scipy.sparse as spa from mpi4py import MPI import struphy.feec.bsplines as bsp import struphy.feec.projectors.shape_pro_local.shape_local_projector_kernel as ker_loc +from struphy.arrays import xp as np # ======================= 3d ==================================== diff --git a/src/struphy/eigenvalue_solvers/mass_matrices_1d.py b/src/struphy/eigenvalue_solvers/mass_matrices_1d.py index 792a0dceb..bdd2c897d 100644 --- a/src/struphy/eigenvalue_solvers/mass_matrices_1d.py +++ b/src/struphy/eigenvalue_solvers/mass_matrices_1d.py @@ -2,10 +2,10 @@ # # Copyright 2020 Florian Holderied -from struphy.arrays import xp as np import scipy.sparse as spa import struphy.bsplines.bsplines as bsp +from struphy.arrays import xp as np # ======= mass matrices in 1D ==================== diff --git a/src/struphy/eigenvalue_solvers/mass_matrices_2d.py b/src/struphy/eigenvalue_solvers/mass_matrices_2d.py index 8e26569c8..fc905296f 100644 --- a/src/struphy/eigenvalue_solvers/mass_matrices_2d.py +++ b/src/struphy/eigenvalue_solvers/mass_matrices_2d.py @@ -2,10 +2,10 @@ # # Copyright 2020 Florian Holderied -from struphy.arrays import xp as np import scipy.sparse as spa import struphy.eigenvalue_solvers.kernels_2d as ker +from struphy.arrays import xp as np # ================ mass matrix in V0 =========================== diff --git a/src/struphy/eigenvalue_solvers/mass_matrices_3d.py b/src/struphy/eigenvalue_solvers/mass_matrices_3d.py index 7b286d8ba..f3fb627be 100644 --- a/src/struphy/eigenvalue_solvers/mass_matrices_3d.py +++ b/src/struphy/eigenvalue_solvers/mass_matrices_3d.py @@ -2,10 +2,10 @@ # # Copyright 2020 Florian Holderied (florian.holderied@ipp.mpg.de) -from struphy.arrays import xp as np import scipy.sparse as spa import struphy.eigenvalue_solvers.kernels_3d as ker +from struphy.arrays import xp as np # ================ mass matrix in V0 =========================== diff --git a/src/struphy/eigenvalue_solvers/mhd_axisymmetric_main.py b/src/struphy/eigenvalue_solvers/mhd_axisymmetric_main.py index cd6bf9810..b1c3f92a8 100644 --- a/src/struphy/eigenvalue_solvers/mhd_axisymmetric_main.py +++ b/src/struphy/eigenvalue_solvers/mhd_axisymmetric_main.py @@ -32,9 +32,9 @@ def solve_mhd_ev_problem_2d(num_params, eq_mhd, n_tor, basis_tor="i", path_out=N import os import time - from struphy.arrays import xp as np import scipy.sparse as spa + from struphy.arrays import xp as np from struphy.eigenvalue_solvers.mhd_operators import MHDOperators from struphy.eigenvalue_solvers.spline_space import Spline_space_1d, Tensor_spline_space diff --git a/src/struphy/eigenvalue_solvers/mhd_axisymmetric_pproc.py b/src/struphy/eigenvalue_solvers/mhd_axisymmetric_pproc.py index 1678b66db..fe5d9b87b 100644 --- a/src/struphy/eigenvalue_solvers/mhd_axisymmetric_pproc.py +++ b/src/struphy/eigenvalue_solvers/mhd_axisymmetric_pproc.py @@ -3,9 +3,10 @@ def main(): import argparse import os - from struphy.arrays import xp as np import yaml + from struphy.arrays import xp as np + # parse arguments parser = argparse.ArgumentParser(description="Restrict a full .npy eigenspectrum to a range of eigenfrequencies.") diff --git a/src/struphy/eigenvalue_solvers/mhd_operators.py b/src/struphy/eigenvalue_solvers/mhd_operators.py index 3edaf1e88..2bbc619f4 100644 --- a/src/struphy/eigenvalue_solvers/mhd_operators.py +++ b/src/struphy/eigenvalue_solvers/mhd_operators.py @@ -3,10 +3,10 @@ # Copyright 2021 Florian Holderied (florian.holderied@ipp.mpg.de) -from struphy.arrays import xp as np import scipy.sparse as spa import struphy.eigenvalue_solvers.legacy.mass_matrices_3d_pre as mass_3d_pre +from struphy.arrays import xp as np from struphy.eigenvalue_solvers.mhd_operators_core import MHDOperatorsCore diff --git a/src/struphy/eigenvalue_solvers/mhd_operators_core.py b/src/struphy/eigenvalue_solvers/mhd_operators_core.py index 17c0341b5..fe909586b 100644 --- a/src/struphy/eigenvalue_solvers/mhd_operators_core.py +++ b/src/struphy/eigenvalue_solvers/mhd_operators_core.py @@ -3,12 +3,12 @@ # Copyright 2021 Florian Holderied (florian.holderied@ipp.mpg.de) -from struphy.arrays import xp as np import scipy.sparse as spa import struphy.eigenvalue_solvers.kernels_projectors_global_mhd as ker import struphy.eigenvalue_solvers.mass_matrices_2d as mass_2d import struphy.eigenvalue_solvers.mass_matrices_3d as mass_3d +from struphy.arrays import xp as np class MHDOperatorsCore: diff --git a/src/struphy/eigenvalue_solvers/projectors_global.py b/src/struphy/eigenvalue_solvers/projectors_global.py index fd27f16a4..02c67a67e 100644 --- a/src/struphy/eigenvalue_solvers/projectors_global.py +++ b/src/struphy/eigenvalue_solvers/projectors_global.py @@ -6,10 +6,10 @@ Classes for commuting projectors in 1D, 2D and 3D based on global spline interpolation and histopolation. """ -from struphy.arrays import xp as np import scipy.sparse as spa import struphy.bsplines.bsplines as bsp +from struphy.arrays import xp as np from struphy.linear_algebra.linalg_kron import kron_lusolve_2d, kron_lusolve_3d, kron_matvec_2d, kron_matvec_3d diff --git a/src/struphy/eigenvalue_solvers/spline_space.py b/src/struphy/eigenvalue_solvers/spline_space.py index 8e762e94a..d41ea4191 100644 --- a/src/struphy/eigenvalue_solvers/spline_space.py +++ b/src/struphy/eigenvalue_solvers/spline_space.py @@ -7,9 +7,10 @@ """ import matplotlib -from struphy.arrays import xp as np import scipy.sparse as spa +from struphy.arrays import xp as np + matplotlib.rcParams.update({"font.size": 16}) import matplotlib.pyplot as plt diff --git a/src/struphy/examples/_draw_parallel.py b/src/struphy/examples/_draw_parallel.py index 894cf999f..1ae8938ca 100644 --- a/src/struphy/examples/_draw_parallel.py +++ b/src/struphy/examples/_draw_parallel.py @@ -1,6 +1,6 @@ -from struphy.arrays import xp as np from mpi4py import MPI +from struphy.arrays import xp as np from struphy.feec.psydac_derham import Derham from struphy.geometry import domains from struphy.pic.particles import Particles6D diff --git a/src/struphy/feec/basis_projection_ops.py b/src/struphy/feec/basis_projection_ops.py index 1ee02f74a..847436971 100644 --- a/src/struphy/feec/basis_projection_ops.py +++ b/src/struphy/feec/basis_projection_ops.py @@ -1,4 +1,3 @@ -from struphy.arrays import xp as np from mpi4py import MPI from psydac.api.settings import PSYDAC_BACKEND_GPYCCEL from psydac.fem.basic import FemSpace @@ -7,6 +6,7 @@ from psydac.linalg.block import BlockLinearOperator, BlockVector, BlockVectorSpace from psydac.linalg.stencil import StencilMatrix, StencilVector, StencilVectorSpace +from struphy.arrays import xp as np from struphy.feec import basis_projection_kernels from struphy.feec.linear_operators import BoundaryOperator, LinOpWithTransp from struphy.feec.local_projectors_kernels import assemble_basis_projection_operator_local diff --git a/src/struphy/feec/linear_operators.py b/src/struphy/feec/linear_operators.py index 695e5ec22..bb676d0a5 100644 --- a/src/struphy/feec/linear_operators.py +++ b/src/struphy/feec/linear_operators.py @@ -1,13 +1,13 @@ import itertools from abc import abstractmethod -from struphy.arrays import xp as np from mpi4py import MPI from psydac.linalg.basic import LinearOperator, Vector, VectorSpace from psydac.linalg.block import BlockVectorSpace from psydac.linalg.stencil import StencilVectorSpace from scipy import sparse +from struphy.arrays import xp as np from struphy.feec.utilities import apply_essential_bc_to_array from struphy.polar.basic import PolarDerhamSpace diff --git a/src/struphy/feec/mass.py b/src/struphy/feec/mass.py index f309c4973..f7f59c3a0 100644 --- a/src/struphy/feec/mass.py +++ b/src/struphy/feec/mass.py @@ -1,6 +1,5 @@ import inspect -from struphy.arrays import xp as np from mpi4py import MPI from psydac.api.settings import PSYDAC_BACKEND_GPYCCEL from psydac.fem.tensor import TensorFemSpace @@ -9,6 +8,7 @@ from psydac.linalg.block import BlockLinearOperator, BlockVector from psydac.linalg.stencil import StencilDiagonalMatrix, StencilMatrix, StencilVector +from struphy.arrays import xp as np from struphy.feec import mass_kernels from struphy.feec.linear_operators import BoundaryOperator, LinOpWithTransp from struphy.feec.psydac_derham import Derham diff --git a/src/struphy/feec/preconditioner.py b/src/struphy/feec/preconditioner.py index 38de94f6f..4ea453a6a 100644 --- a/src/struphy/feec/preconditioner.py +++ b/src/struphy/feec/preconditioner.py @@ -1,4 +1,3 @@ -from struphy.arrays import xp as np from psydac.api.essential_bc import apply_essential_bc_stencil from psydac.ddm.cart import CartDecomposition, DomainDecomposition from psydac.fem.tensor import TensorFemSpace @@ -10,6 +9,7 @@ from scipy import sparse from scipy.linalg import solve_circulant +from struphy.arrays import xp as np from struphy.feec.linear_operators import BoundaryOperator from struphy.feec.mass import WeightedMassOperator diff --git a/src/struphy/feec/projectors.py b/src/struphy/feec/projectors.py index 60efb3cfe..429e21ff8 100644 --- a/src/struphy/feec/projectors.py +++ b/src/struphy/feec/projectors.py @@ -1,4 +1,3 @@ -from struphy.arrays import xp as np from mpi4py import MPI from psydac.api.settings import PSYDAC_BACKEND_GPYCCEL from psydac.feec.global_projectors import GlobalProjector @@ -11,6 +10,7 @@ from psydac.linalg.solvers import inverse from psydac.linalg.stencil import StencilMatrix, StencilVector +from struphy.arrays import xp as np from struphy.feec import mass_kernels from struphy.feec.local_projectors_kernels import ( compute_shifts, diff --git a/src/struphy/feec/psydac_derham.py b/src/struphy/feec/psydac_derham.py index 03cb24fdc..6531b3051 100644 --- a/src/struphy/feec/psydac_derham.py +++ b/src/struphy/feec/psydac_derham.py @@ -1,7 +1,6 @@ #!/usr/bin/env python3 import importlib.metadata -from struphy.arrays import xp as np import psydac.core.bsplines as bsp from mpi4py import MPI from mpi4py.MPI import Intracomm @@ -17,6 +16,7 @@ from psydac.linalg.block import BlockVector, BlockVectorSpace from psydac.linalg.stencil import StencilVector, StencilVectorSpace +from struphy.arrays import xp as np from struphy.bsplines import evaluation_kernels_3d as eval_3d from struphy.bsplines.evaluation_kernels_3d import eval_spline_mpi_tensor_product_fixed from struphy.feec.linear_operators import BoundaryOperator diff --git a/src/struphy/feec/tests/test_basis_ops.py b/src/struphy/feec/tests/test_basis_ops.py index 4b91a4ab9..d93319a1c 100644 --- a/src/struphy/feec/tests/test_basis_ops.py +++ b/src/struphy/feec/tests/test_basis_ops.py @@ -14,11 +14,11 @@ def test_some_basis_ops(Nel, p, spl_kind, mapping): """ from time import time - from struphy.arrays import xp as np from mpi4py import MPI from psydac.linalg.block import BlockVector from psydac.linalg.stencil import StencilVector + from struphy.arrays import xp as np from struphy.eigenvalue_solvers.legacy.mhd_operators_MF import projectors_dot_x from struphy.eigenvalue_solvers.spline_space import Spline_space_1d, Tensor_spline_space from struphy.feec.basis_projection_ops import BasisProjectionOperators @@ -465,9 +465,9 @@ def test_some_basis_ops(Nel, p, spl_kind, mapping): ) @pytest.mark.parametrize("mapping", [["IGAPolarCylinder", {"a": 1.0, "Lz": 3.0}]]) def test_basis_ops_polar(Nel, p, spl_kind, dirichlet_bc, mapping, show_plots=False): - from struphy.arrays import xp as np from mpi4py import MPI + from struphy.arrays import xp as np from struphy.eigenvalue_solvers.mhd_operators import MHDOperators from struphy.eigenvalue_solvers.spline_space import Spline_space_1d, Tensor_spline_space from struphy.feec.basis_projection_ops import BasisProjectionOperators diff --git a/src/struphy/feec/tests/test_derham.py b/src/struphy/feec/tests/test_derham.py index ddbdf325a..ee44f64f0 100644 --- a/src/struphy/feec/tests/test_derham.py +++ b/src/struphy/feec/tests/test_derham.py @@ -8,11 +8,11 @@ def test_psydac_derham(Nel, p, spl_kind): """Remark: p=even projectors yield slightly different results, pass with atol=1e-3.""" - from struphy.arrays import xp as np from mpi4py import MPI from psydac.linalg.block import BlockVector from psydac.linalg.stencil import StencilVector + from struphy.arrays import xp as np from struphy.eigenvalue_solvers.spline_space import Spline_space_1d, Tensor_spline_space from struphy.feec.psydac_derham import Derham from struphy.feec.utilities import compare_arrays diff --git a/src/struphy/feec/tests/test_eval_field.py b/src/struphy/feec/tests/test_eval_field.py index fa4db43aa..f14f72f6b 100644 --- a/src/struphy/feec/tests/test_eval_field.py +++ b/src/struphy/feec/tests/test_eval_field.py @@ -1,7 +1,8 @@ -from struphy.arrays import xp as np import pytest from mpi4py import MPI +from struphy.arrays import xp as np + @pytest.mark.mpi(min_size=2) @pytest.mark.parametrize("Nel", [[8, 9, 10]]) diff --git a/src/struphy/feec/tests/test_field_init.py b/src/struphy/feec/tests/test_field_init.py index d2d35ead9..434a754fe 100644 --- a/src/struphy/feec/tests/test_field_init.py +++ b/src/struphy/feec/tests/test_field_init.py @@ -10,9 +10,9 @@ def test_bckgr_init_const(Nel, p, spl_kind, spaces, vec_comps): """Test field background initialization of "LogicalConst" with multiple fields in params.""" - from struphy.arrays import xp as np from mpi4py import MPI + from struphy.arrays import xp as np from struphy.feec.psydac_derham import Derham comm = MPI.COMM_WORLD @@ -65,10 +65,10 @@ def test_bckgr_init_mhd(Nel, p, spl_kind, with_desc=False, with_gvec=False, show import inspect - from struphy.arrays import xp as np from matplotlib import pyplot as plt from mpi4py import MPI + from struphy.arrays import xp as np from struphy.feec.psydac_derham import Derham from struphy.fields_background import equils from struphy.fields_background.base import FluidEquilibriumWithB @@ -1087,10 +1087,10 @@ def test_bckgr_init_mhd(Nel, p, spl_kind, with_desc=False, with_gvec=False, show def test_sincos_init_const(Nel, p, spl_kind, show_plot=False): """Test field perturbation with ModesSin + ModesCos on top of of "LogicalConst" with multiple fields in params.""" - from struphy.arrays import xp as np from matplotlib import pyplot as plt from mpi4py import MPI + from struphy.arrays import xp as np from struphy.feec.psydac_derham import Derham from struphy.initial.perturbations import ModesCos, ModesSin @@ -1321,9 +1321,9 @@ def test_sincos_init_const(Nel, p, spl_kind, show_plot=False): def test_noise_init(Nel, p, spl_kind, space, direction): """Only tests 1d noise ('e1', 'e2', 'e3') !!""" - from struphy.arrays import xp as np from mpi4py import MPI + from struphy.arrays import xp as np from struphy.feec.psydac_derham import Derham from struphy.feec.utilities import compare_arrays diff --git a/src/struphy/feec/tests/test_l2_projectors.py b/src/struphy/feec/tests/test_l2_projectors.py index 2a8372350..610a16ef8 100644 --- a/src/struphy/feec/tests/test_l2_projectors.py +++ b/src/struphy/feec/tests/test_l2_projectors.py @@ -1,10 +1,10 @@ import inspect import matplotlib.pyplot as plt -from struphy.arrays import xp as np import pytest from mpi4py import MPI +from struphy.arrays import xp as np from struphy.feec.mass import WeightedMassOperators from struphy.feec.projectors import L2Projector from struphy.feec.psydac_derham import Derham diff --git a/src/struphy/feec/tests/test_local_projectors.py b/src/struphy/feec/tests/test_local_projectors.py index e1d4b2918..ff81d522c 100644 --- a/src/struphy/feec/tests/test_local_projectors.py +++ b/src/struphy/feec/tests/test_local_projectors.py @@ -2,10 +2,10 @@ import time import matplotlib.pyplot as plt -from struphy.arrays import xp as np import pytest from mpi4py import MPI +from struphy.arrays import xp as np from struphy.bsplines.bsplines import basis_funs, find_span from struphy.bsplines.evaluation_kernels_1d import evaluation_kernel_1d from struphy.feec.basis_projection_ops import BasisProjectionOperator, BasisProjectionOperatorLocal diff --git a/src/struphy/feec/tests/test_lowdim_nel_is_1.py b/src/struphy/feec/tests/test_lowdim_nel_is_1.py index be4fd1877..8ff3e6b06 100644 --- a/src/struphy/feec/tests/test_lowdim_nel_is_1.py +++ b/src/struphy/feec/tests/test_lowdim_nel_is_1.py @@ -8,12 +8,12 @@ def test_lowdim_derham(Nel, p, spl_kind, do_plot=False): """Test Nel=1 in various directions.""" - from struphy.arrays import xp as np from matplotlib import pyplot as plt from mpi4py import MPI from psydac.linalg.block import BlockVector from psydac.linalg.stencil import StencilVector + from struphy.arrays import xp as np from struphy.feec.psydac_derham import Derham comm = MPI.COMM_WORLD diff --git a/src/struphy/feec/tests/test_mass_matrices.py b/src/struphy/feec/tests/test_mass_matrices.py index bb736a870..efcb86cda 100644 --- a/src/struphy/feec/tests/test_mass_matrices.py +++ b/src/struphy/feec/tests/test_mass_matrices.py @@ -13,9 +13,9 @@ def test_mass(Nel, p, spl_kind, dirichlet_bc, mapping, show_plots=False): """Compare Struphy mass matrices to Struphy-legacy mass matrices.""" - from struphy.arrays import xp as np from mpi4py import MPI + from struphy.arrays import xp as np from struphy.eigenvalue_solvers.mhd_operators import MHDOperators from struphy.eigenvalue_solvers.spline_space import Spline_space_1d, Tensor_spline_space from struphy.feec.mass import WeightedMassOperators, WeightedMassOperatorsOldForTesting @@ -377,9 +377,9 @@ def test_mass(Nel, p, spl_kind, dirichlet_bc, mapping, show_plots=False): def test_mass_polar(Nel, p, spl_kind, dirichlet_bc, mapping, show_plots=False): """Compare Struphy polar mass matrices to Struphy-legacy polar mass matrices.""" - from struphy.arrays import xp as np from mpi4py import MPI + from struphy.arrays import xp as np from struphy.eigenvalue_solvers.mhd_operators import MHDOperators from struphy.eigenvalue_solvers.spline_space import Spline_space_1d, Tensor_spline_space from struphy.feec.mass import WeightedMassOperators @@ -575,10 +575,10 @@ def test_mass_preconditioner(Nel, p, spl_kind, dirichlet_bc, mapping, show_plots import time - from struphy.arrays import xp as np from mpi4py import MPI from psydac.linalg.solvers import inverse + from struphy.arrays import xp as np from struphy.feec.mass import WeightedMassOperators, WeightedMassOperatorsOldForTesting from struphy.feec.preconditioner import MassMatrixPreconditioner from struphy.feec.psydac_derham import Derham @@ -881,10 +881,10 @@ def test_mass_preconditioner_polar(Nel, p, spl_kind, dirichlet_bc, mapping, show import time - from struphy.arrays import xp as np from mpi4py import MPI from psydac.linalg.solvers import inverse + from struphy.arrays import xp as np from struphy.feec.mass import WeightedMassOperators from struphy.feec.preconditioner import MassMatrixPreconditioner from struphy.feec.psydac_derham import Derham diff --git a/src/struphy/feec/tests/test_toarray_struphy.py b/src/struphy/feec/tests/test_toarray_struphy.py index 1bdb30401..e6a049ed3 100644 --- a/src/struphy/feec/tests/test_toarray_struphy.py +++ b/src/struphy/feec/tests/test_toarray_struphy.py @@ -13,9 +13,9 @@ def test_toarray_struphy(Nel, p, spl_kind, mapping): TODO """ - from struphy.arrays import xp as np from mpi4py import MPI + from struphy.arrays import xp as np from struphy.feec.mass import WeightedMassOperators from struphy.feec.psydac_derham import Derham from struphy.feec.utilities import compare_arrays, create_equal_random_arrays diff --git a/src/struphy/feec/tests/test_tosparse_struphy.py b/src/struphy/feec/tests/test_tosparse_struphy.py index c95525dce..af62d925a 100644 --- a/src/struphy/feec/tests/test_tosparse_struphy.py +++ b/src/struphy/feec/tests/test_tosparse_struphy.py @@ -15,9 +15,9 @@ def test_tosparse_struphy(Nel, p, spl_kind, mapping): TODO """ - from struphy.arrays import xp as np from mpi4py import MPI + from struphy.arrays import xp as np from struphy.feec.mass import WeightedMassOperators from struphy.feec.psydac_derham import Derham from struphy.feec.utilities import create_equal_random_arrays diff --git a/src/struphy/feec/tests/xx_test_preconds.py b/src/struphy/feec/tests/xx_test_preconds.py index ca980fe3d..b6d35cc41 100644 --- a/src/struphy/feec/tests/xx_test_preconds.py +++ b/src/struphy/feec/tests/xx_test_preconds.py @@ -12,11 +12,11 @@ ], ) def test_mass_preconditioner(Nel, p, spl_kind, mapping): - from struphy.arrays import xp as np from mpi4py import MPI from psydac.linalg.block import BlockVector from psydac.linalg.stencil import StencilVector + from struphy.arrays import xp as np from struphy.feec.linear_operators import InverseLinearOperator from struphy.feec.mass import WeightedMassOperators from struphy.feec.preconditioner import MassMatrixPreconditioner diff --git a/src/struphy/feec/utilities.py b/src/struphy/feec/utilities.py index e87afe211..ece3aa90d 100644 --- a/src/struphy/feec/utilities.py +++ b/src/struphy/feec/utilities.py @@ -1,4 +1,3 @@ -from struphy.arrays import xp as np from psydac.api.essential_bc import apply_essential_bc_stencil from psydac.fem.tensor import TensorFemSpace from psydac.fem.vector import VectorFemSpace @@ -6,6 +5,7 @@ from psydac.linalg.stencil import StencilMatrix, StencilVector import struphy.feec.utilities_kernels as kernels +from struphy.arrays import xp as np from struphy.feec import banded_to_stencil_kernels as bts from struphy.polar.basic import PolarVector diff --git a/src/struphy/feec/utilities_local_projectors.py b/src/struphy/feec/utilities_local_projectors.py index 3867af721..df12631e7 100644 --- a/src/struphy/feec/utilities_local_projectors.py +++ b/src/struphy/feec/utilities_local_projectors.py @@ -1,5 +1,4 @@ from struphy.arrays import xp as np - from struphy.feec.local_projectors_kernels import are_quadrature_points_zero, get_rows, select_quasi_points diff --git a/src/struphy/feec/variational_utilities.py b/src/struphy/feec/variational_utilities.py index 49f543be4..af24988f3 100644 --- a/src/struphy/feec/variational_utilities.py +++ b/src/struphy/feec/variational_utilities.py @@ -1,10 +1,10 @@ from copy import deepcopy -from struphy.arrays import xp as np from psydac.linalg.basic import IdentityOperator, Vector from psydac.linalg.block import BlockVector from psydac.linalg.solvers import inverse +from struphy.arrays import xp as np from struphy.feec import preconditioner from struphy.feec.basis_projection_ops import ( BasisProjectionOperator, diff --git a/src/struphy/fields_background/base.py b/src/struphy/fields_background/base.py index 03bbb28e1..8e748f5e3 100644 --- a/src/struphy/fields_background/base.py +++ b/src/struphy/fields_background/base.py @@ -2,10 +2,10 @@ from abc import ABCMeta, abstractmethod -from struphy.arrays import xp as np from matplotlib import pyplot as plt from pyevtk.hl import gridToVTK +from struphy.arrays import xp as np from struphy.geometry.base import Domain diff --git a/src/struphy/fields_background/coil_fields/base.py b/src/struphy/fields_background/coil_fields/base.py index e9699692b..ea40dee39 100644 --- a/src/struphy/fields_background/coil_fields/base.py +++ b/src/struphy/fields_background/coil_fields/base.py @@ -1,9 +1,10 @@ from abc import ABCMeta, abstractmethod -from struphy.arrays import xp as np from matplotlib import pyplot as plt from pyevtk.hl import gridToVTK +from struphy.arrays import xp as np + class CoilMagneticField(metaclass=ABCMeta): """ diff --git a/src/struphy/fields_background/coil_fields/coil_fields.py b/src/struphy/fields_background/coil_fields/coil_fields.py index 34ed1547d..681a705c7 100644 --- a/src/struphy/fields_background/coil_fields/coil_fields.py +++ b/src/struphy/fields_background/coil_fields/coil_fields.py @@ -1,5 +1,4 @@ from struphy.arrays import xp as np - from struphy.feec.psydac_derham import Derham from struphy.fields_background.coil_fields.base import CoilMagneticField, load_csv_data diff --git a/src/struphy/fields_background/equils.py b/src/struphy/fields_background/equils.py index 7d9dc3be5..e0cee328f 100644 --- a/src/struphy/fields_background/equils.py +++ b/src/struphy/fields_background/equils.py @@ -7,12 +7,12 @@ import warnings from time import time -from struphy.arrays import xp as np from scipy.integrate import odeint, quad from scipy.interpolate import RectBivariateSpline, UnivariateSpline from scipy.optimize import fsolve, minimize import struphy +from struphy.arrays import xp as np from struphy.fields_background.base import ( AxisymmMHDequilibrium, CartesianFluidEquilibrium, diff --git a/src/struphy/fields_background/tests/test_desc_equil.py b/src/struphy/fields_background/tests/test_desc_equil.py index d108f4bf0..26e10f1bf 100644 --- a/src/struphy/fields_background/tests/test_desc_equil.py +++ b/src/struphy/fields_background/tests/test_desc_equil.py @@ -1,9 +1,10 @@ import importlib.util -from struphy.arrays import xp as np import pytest from matplotlib import pyplot as plt +from struphy.arrays import xp as np + desc_spec = importlib.util.find_spec("desc") diff --git a/src/struphy/fields_background/tests/test_generic_equils.py b/src/struphy/fields_background/tests/test_generic_equils.py index 21fff05ad..43efe834e 100644 --- a/src/struphy/fields_background/tests/test_generic_equils.py +++ b/src/struphy/fields_background/tests/test_generic_equils.py @@ -1,7 +1,7 @@ -from struphy.arrays import xp as np import pytest from matplotlib import pyplot as plt +from struphy.arrays import xp as np from struphy.fields_background.generic import ( GenericCartesianFluidEquilibrium, GenericCartesianFluidEquilibriumWithB, diff --git a/src/struphy/fields_background/tests/test_mhd_equils.py b/src/struphy/fields_background/tests/test_mhd_equils.py index 6aceaf220..31165e247 100644 --- a/src/struphy/fields_background/tests/test_mhd_equils.py +++ b/src/struphy/fields_background/tests/test_mhd_equils.py @@ -1,6 +1,6 @@ -from struphy.arrays import xp as np import pytest +from struphy.arrays import xp as np from struphy.fields_background import equils diff --git a/src/struphy/fields_background/tests/test_numerical_mhd_equil.py b/src/struphy/fields_background/tests/test_numerical_mhd_equil.py index ed94977b6..a3f8466b9 100644 --- a/src/struphy/fields_background/tests/test_numerical_mhd_equil.py +++ b/src/struphy/fields_background/tests/test_numerical_mhd_equil.py @@ -1,6 +1,6 @@ -from struphy.arrays import xp as np import pytest +from struphy.arrays import xp as np from struphy.fields_background.base import FluidEquilibrium, LogicalMHDequilibrium diff --git a/src/struphy/geometry/base.py b/src/struphy/geometry/base.py index 5a0ce8399..d94d21687 100644 --- a/src/struphy/geometry/base.py +++ b/src/struphy/geometry/base.py @@ -4,11 +4,11 @@ from abc import ABCMeta, abstractmethod import h5py -from struphy.arrays import xp as np from scipy.sparse import csc_matrix, kron from scipy.sparse.linalg import splu, spsolve import struphy.bsplines.bsplines as bsp +from struphy.arrays import xp as np from struphy.geometry import evaluation_kernels, transform_kernels from struphy.kernel_arguments.pusher_args_kernels import DomainArguments from struphy.linear_algebra import linalg_kron diff --git a/src/struphy/geometry/domains.py b/src/struphy/geometry/domains.py index 495eed035..12c2e626f 100644 --- a/src/struphy/geometry/domains.py +++ b/src/struphy/geometry/domains.py @@ -3,7 +3,6 @@ import copy from struphy.arrays import xp as np - from struphy.fields_background.base import AxisymmMHDequilibrium from struphy.fields_background.equils import EQDSKequilibrium from struphy.geometry.base import ( diff --git a/src/struphy/geometry/tests/test_domain.py b/src/struphy/geometry/tests/test_domain.py index ea4df734a..ef5cad940 100644 --- a/src/struphy/geometry/tests/test_domain.py +++ b/src/struphy/geometry/tests/test_domain.py @@ -5,7 +5,6 @@ def test_prepare_arg(): """Tests prepare_arg static method in domain base class.""" from struphy.arrays import xp as np - from struphy.geometry.base import Domain def a1(e1, e2, e3): @@ -159,7 +158,6 @@ def test_evaluation_mappings(mapping): """Tests domain object creation with default parameters and evaluation of metric coefficients.""" from struphy.arrays import xp as np - from struphy.geometry import domains from struphy.geometry.base import Domain @@ -319,7 +317,6 @@ def test_pullback(): """Tests pullbacks to p-forms.""" from struphy.arrays import xp as np - from struphy.geometry import domains from struphy.geometry.base import Domain @@ -479,7 +476,6 @@ def test_pushforward(): """Tests pushforward of p-forms.""" from struphy.arrays import xp as np - from struphy.geometry import domains from struphy.geometry.base import Domain @@ -639,7 +635,6 @@ def test_transform(): """Tests transformation of p-forms.""" from struphy.arrays import xp as np - from struphy.geometry import domains from struphy.geometry.base import Domain diff --git a/src/struphy/geometry/utilities.py b/src/struphy/geometry/utilities.py index dad9de590..53364b899 100644 --- a/src/struphy/geometry/utilities.py +++ b/src/struphy/geometry/utilities.py @@ -1,10 +1,10 @@ "Domain-related utility functions." -from struphy.arrays import xp as np from scipy.optimize import newton, root, root_scalar from scipy.sparse import csc_matrix from scipy.sparse.linalg import splu +from struphy.arrays import xp as np from struphy.bsplines import bsplines as bsp from struphy.geometry.base import PoloidalSplineTorus from struphy.geometry.utilities_kernels import weighted_arc_lengths_flux_surface diff --git a/src/struphy/initial/eigenfunctions.py b/src/struphy/initial/eigenfunctions.py index a264e54ab..12c1b037c 100644 --- a/src/struphy/initial/eigenfunctions.py +++ b/src/struphy/initial/eigenfunctions.py @@ -1,10 +1,10 @@ import os -from struphy.arrays import xp as np import yaml from psydac.api.discretization import discretize from sympde.topology import Derham, Line +from struphy.arrays import xp as np from struphy.fields_background.equils import set_defaults diff --git a/src/struphy/initial/perturbations.py b/src/struphy/initial/perturbations.py index 4bd5ca54b..01b8e9bd1 100644 --- a/src/struphy/initial/perturbations.py +++ b/src/struphy/initial/perturbations.py @@ -1,10 +1,11 @@ #!/usr/bin/env python3 "Analytical perturbations (modes)." -from struphy.arrays import xp as np import scipy import scipy.special +from struphy.arrays import xp as np + class ModesSin: r"""Sinusoidal function in 3D. diff --git a/src/struphy/initial/tests/test_init_perturbations.py b/src/struphy/initial/tests/test_init_perturbations.py index eaea2416c..b9f9ae613 100644 --- a/src/struphy/initial/tests/test_init_perturbations.py +++ b/src/struphy/initial/tests/test_init_perturbations.py @@ -20,10 +20,10 @@ def test_init_modes(Nel, p, spl_kind, mapping, combine_comps=None, do_plot=False): """Test the initialization Field.initialize_coeffs with all "Modes" classes in perturbations.py.""" - from struphy.arrays import xp as np from matplotlib import pyplot as plt from mpi4py import MPI + from struphy.arrays import xp as np from struphy.feec.psydac_derham import Derham from struphy.geometry import domains from struphy.geometry.base import Domain diff --git a/src/struphy/initial/utilities.py b/src/struphy/initial/utilities.py index e84a81e29..9174bf593 100644 --- a/src/struphy/initial/utilities.py +++ b/src/struphy/initial/utilities.py @@ -1,8 +1,8 @@ import os import h5py -from struphy.arrays import xp as np +from struphy.arrays import xp as np from struphy.fields_background.equils import set_defaults from struphy.io.output_handling import DataContainer diff --git a/src/struphy/io/output_handling.py b/src/struphy/io/output_handling.py index ca84dff00..7651c4451 100644 --- a/src/struphy/io/output_handling.py +++ b/src/struphy/io/output_handling.py @@ -2,6 +2,7 @@ import os import h5py + from struphy.arrays import xp as np diff --git a/src/struphy/io/setup.py b/src/struphy/io/setup.py index f1a8297ec..1a701d69f 100644 --- a/src/struphy/io/setup.py +++ b/src/struphy/io/setup.py @@ -1,8 +1,8 @@ from dataclasses import dataclass -from struphy.arrays import xp as np from mpi4py import MPI +from struphy.arrays import xp as np from struphy.utils.utils import dict_to_yaml diff --git a/src/struphy/kinetic_background/base.py b/src/struphy/kinetic_background/base.py index cbb774225..af52cc36b 100644 --- a/src/struphy/kinetic_background/base.py +++ b/src/struphy/kinetic_background/base.py @@ -4,7 +4,6 @@ from abc import ABCMeta, abstractmethod from struphy.arrays import xp as np - from struphy.fields_background.base import FluidEquilibrium from struphy.fields_background.equils import set_defaults from struphy.initial import perturbations diff --git a/src/struphy/kinetic_background/maxwellians.py b/src/struphy/kinetic_background/maxwellians.py index 908013fbd..4801e732f 100644 --- a/src/struphy/kinetic_background/maxwellians.py +++ b/src/struphy/kinetic_background/maxwellians.py @@ -1,7 +1,6 @@ "Maxwellian (Gaussian) distributions in velocity space." from struphy.arrays import xp as np - from struphy.fields_background.base import FluidEquilibrium from struphy.fields_background.equils import set_defaults from struphy.kinetic_background import moment_functions diff --git a/src/struphy/kinetic_background/tests/test_base.py b/src/struphy/kinetic_background/tests/test_base.py index 18dfe50f2..4b5a3ccee 100644 --- a/src/struphy/kinetic_background/tests/test_base.py +++ b/src/struphy/kinetic_background/tests/test_base.py @@ -2,8 +2,8 @@ def test_kinetic_background_magics(show_plot=False): """Test the magic commands __sum__, __mul__ and __sub__ of the Maxwellian base class.""" import matplotlib.pyplot as plt - from struphy.arrays import xp as np + from struphy.arrays import xp as np from struphy.kinetic_background.maxwellians import Maxwellian3D Nel = [32, 1, 1] diff --git a/src/struphy/kinetic_background/tests/test_maxwellians.py b/src/struphy/kinetic_background/tests/test_maxwellians.py index a4db897ee..fbb1229aa 100644 --- a/src/struphy/kinetic_background/tests/test_maxwellians.py +++ b/src/struphy/kinetic_background/tests/test_maxwellians.py @@ -9,8 +9,8 @@ def test_maxwellian_3d_uniform(Nel, show_plot=False): analytical computation. """ import matplotlib.pyplot as plt - from struphy.arrays import xp as np + from struphy.arrays import xp as np from struphy.kinetic_background.maxwellians import Maxwellian3D e1 = np.linspace(0.0, 1.0, Nel[0]) @@ -89,8 +89,8 @@ def test_maxwellian_3d_perturbed(Nel, show_plot=False): """Tests the Maxwellian3D class for perturbations.""" import matplotlib.pyplot as plt - from struphy.arrays import xp as np + from struphy.arrays import xp as np from struphy.kinetic_background.maxwellians import Maxwellian3D e1 = np.linspace(0.0, 1.0, Nel[0]) @@ -285,8 +285,8 @@ def test_maxwellian_3d_mhd(Nel, with_desc, show_plot=False): import inspect import matplotlib.pyplot as plt - from struphy.arrays import xp as np + from struphy.arrays import xp as np from struphy.fields_background import equils from struphy.geometry import domains from struphy.initial import perturbations @@ -692,8 +692,8 @@ def test_maxwellian_2d_uniform(Nel, show_plot=False): analytical computation. """ import matplotlib.pyplot as plt - from struphy.arrays import xp as np + from struphy.arrays import xp as np from struphy.kinetic_background.maxwellians import GyroMaxwellian2D e1 = np.linspace(0.0, 1.0, Nel[0]) @@ -781,8 +781,8 @@ def test_maxwellian_2d_perturbed(Nel, show_plot=False): """Tests the GyroMaxwellian2D class for perturbations.""" import matplotlib.pyplot as plt - from struphy.arrays import xp as np + from struphy.arrays import xp as np from struphy.kinetic_background.maxwellians import GyroMaxwellian2D e1 = np.linspace(0.0, 1.0, Nel[0]) @@ -1035,8 +1035,8 @@ def test_maxwellian_2d_mhd(Nel, with_desc, show_plot=False): import inspect import matplotlib.pyplot as plt - from struphy.arrays import xp as np + from struphy.arrays import xp as np from struphy.fields_background import equils from struphy.fields_background.base import FluidEquilibriumWithB from struphy.geometry import domains @@ -1436,8 +1436,8 @@ def test_canonical_maxwellian_uniform(Nel, show_plot=False): analytical computation. """ import matplotlib.pyplot as plt - from struphy.arrays import xp as np + from struphy.arrays import xp as np from struphy.fields_background import equils from struphy.geometry import domains from struphy.kinetic_background.maxwellians import CanonicalMaxwellian diff --git a/src/struphy/linear_algebra/linalg_kron.py b/src/struphy/linear_algebra/linalg_kron.py index 846fd9744..21f4cced7 100644 --- a/src/struphy/linear_algebra/linalg_kron.py +++ b/src/struphy/linear_algebra/linalg_kron.py @@ -13,10 +13,11 @@ [r_M11, rM12, ... , r_MNO]] """ -from struphy.arrays import xp as np from scipy.linalg import solve_circulant from scipy.sparse.linalg import splu +from struphy.arrays import xp as np + def kron_matvec_2d(kmat, vec2d): """ diff --git a/src/struphy/linear_algebra/saddle_point.py b/src/struphy/linear_algebra/saddle_point.py index acc2e15ce..2da6900d0 100644 --- a/src/struphy/linear_algebra/saddle_point.py +++ b/src/struphy/linear_algebra/saddle_point.py @@ -1,12 +1,12 @@ from typing import Union -from struphy.arrays import xp as np import scipy as sc from psydac.linalg.basic import LinearOperator, Vector from psydac.linalg.block import BlockLinearOperator, BlockVector, BlockVectorSpace from psydac.linalg.direct_solvers import SparseSolver from psydac.linalg.solvers import inverse +from struphy.arrays import xp as np from struphy.linear_algebra.tests.test_saddlepoint_massmatrices import _plot_residual_norms diff --git a/src/struphy/linear_algebra/tests/test_saddlepoint_massmatrices.py b/src/struphy/linear_algebra/tests/test_saddlepoint_massmatrices.py index cebb89033..973a71eeb 100644 --- a/src/struphy/linear_algebra/tests/test_saddlepoint_massmatrices.py +++ b/src/struphy/linear_algebra/tests/test_saddlepoint_massmatrices.py @@ -13,12 +13,12 @@ def test_saddlepointsolver(method_for_solving, Nel, p, spl_kind, dirichlet_bc, m import time - from struphy.arrays import xp as np import scipy as sc from mpi4py import MPI from psydac.linalg.basic import IdentityOperator from psydac.linalg.block import BlockLinearOperator, BlockVector, BlockVectorSpace + from struphy.arrays import xp as np from struphy.examples.restelli2018 import callables from struphy.feec.basis_projection_ops import BasisProjectionOperatorLocal, BasisProjectionOperators from struphy.feec.mass import WeightedMassOperators @@ -374,6 +374,7 @@ def _plot_residual_norms(residual_norms): def _plot_velocity(data_reshaped): import matplotlib import matplotlib.pyplot as plt + from struphy.arrays import xp as np matplotlib.use("Agg") diff --git a/src/struphy/linear_algebra/tests/test_stencil_dot_kernels.py b/src/struphy/linear_algebra/tests/test_stencil_dot_kernels.py index ed07ec90d..6d801dff7 100644 --- a/src/struphy/linear_algebra/tests/test_stencil_dot_kernels.py +++ b/src/struphy/linear_algebra/tests/test_stencil_dot_kernels.py @@ -14,11 +14,11 @@ def test_1d(Nel, p, spl_kind, domain_ind, codomain_ind): a) the result from kernel in struphy.linear_algebra.stencil_dot_kernels.matvec_1d_kernel b) the result from Stencil .dot with precompiled=True""" - from struphy.arrays import xp as np from mpi4py import MPI from psydac.api.settings import PSYDAC_BACKEND_GPYCCEL from psydac.linalg.stencil import StencilMatrix, StencilVector + from struphy.arrays import xp as np from struphy.feec.psydac_derham import Derham from struphy.linear_algebra.stencil_dot_kernels import matvec_1d_kernel @@ -137,11 +137,11 @@ def test_3d(Nel, p, spl_kind, domain_ind, codomain_ind): a) the result from kernel in struphy.linear_algebra.stencil_dot_kernels.matvec_1d_kernel b) the result from Stencil .dot with precompiled=True""" - from struphy.arrays import xp as np from mpi4py import MPI from psydac.api.settings import PSYDAC_BACKEND_GPYCCEL from psydac.linalg.stencil import StencilMatrix, StencilVector + from struphy.arrays import xp as np from struphy.feec.psydac_derham import Derham from struphy.linear_algebra.stencil_dot_kernels import matvec_3d_kernel diff --git a/src/struphy/linear_algebra/tests/test_stencil_transpose_kernels.py b/src/struphy/linear_algebra/tests/test_stencil_transpose_kernels.py index ebbbb4d87..95015a12d 100644 --- a/src/struphy/linear_algebra/tests/test_stencil_transpose_kernels.py +++ b/src/struphy/linear_algebra/tests/test_stencil_transpose_kernels.py @@ -14,11 +14,11 @@ def test_1d(Nel, p, spl_kind, domain_ind, codomain_ind): a) the result from kernel in struphy.linear_algebra.stencil_transpose_kernels.transpose_1d_kernel b) the result from Stencil .transpose with precompiled=True""" - from struphy.arrays import xp as np from mpi4py import MPI from psydac.api.settings import PSYDAC_BACKEND_GPYCCEL from psydac.linalg.stencil import StencilMatrix + from struphy.arrays import xp as np from struphy.feec.psydac_derham import Derham from struphy.linear_algebra.stencil_transpose_kernels import transpose_1d_kernel @@ -131,11 +131,11 @@ def test_3d(Nel, p, spl_kind, domain_ind, codomain_ind): a) the result from kernel in struphy.linear_algebra.stencil_transpose_kernels.transpose_3d_kernel b) the result from Stencil .transpose with precompiled=True""" - from struphy.arrays import xp as np from mpi4py import MPI from psydac.api.settings import PSYDAC_BACKEND_GPYCCEL from psydac.linalg.stencil import StencilMatrix + from struphy.arrays import xp as np from struphy.feec.psydac_derham import Derham from struphy.linear_algebra.stencil_transpose_kernels import transpose_3d_kernel diff --git a/src/struphy/main.py b/src/struphy/main.py index 67629ff9c..05de5cdc0 100644 --- a/src/struphy/main.py +++ b/src/struphy/main.py @@ -54,10 +54,10 @@ def main( import os import time - from struphy.arrays import xp as np from mpi4py import MPI from pyevtk.hl import gridToVTK + from struphy.arrays import xp as np from struphy.feec.psydac_derham import SplineFunction from struphy.fields_background.base import FluidEquilibriumWithB from struphy.io.output_handling import DataContainer diff --git a/src/struphy/models/base.py b/src/struphy/models/base.py index ca8c03d25..4e90b67ea 100644 --- a/src/struphy/models/base.py +++ b/src/struphy/models/base.py @@ -3,11 +3,11 @@ from abc import ABCMeta, abstractmethod from functools import reduce -from struphy.arrays import xp as np import yaml from mpi4py import MPI from psydac.linalg.stencil import StencilVector +from struphy.arrays import xp as np from struphy.feec.basis_projection_ops import BasisProjectionOperators from struphy.feec.mass import WeightedMassOperators from struphy.feec.psydac_derham import SplineFunction diff --git a/src/struphy/models/fluid.py b/src/struphy/models/fluid.py index 4ac6fb045..1ed93f996 100644 --- a/src/struphy/models/fluid.py +++ b/src/struphy/models/fluid.py @@ -1,5 +1,4 @@ from struphy.arrays import xp as np - from struphy.models.base import StruphyModel from struphy.propagators import propagators_coupling, propagators_fields, propagators_markers diff --git a/src/struphy/models/hybrid.py b/src/struphy/models/hybrid.py index 574c817be..1714f37a6 100644 --- a/src/struphy/models/hybrid.py +++ b/src/struphy/models/hybrid.py @@ -1,5 +1,4 @@ from struphy.arrays import xp as np - from struphy.models.base import StruphyModel from struphy.pic.accumulation import accum_kernels, accum_kernels_gc from struphy.propagators import propagators_coupling, propagators_fields, propagators_markers diff --git a/src/struphy/models/kinetic.py b/src/struphy/models/kinetic.py index 00464e617..6997258cf 100644 --- a/src/struphy/models/kinetic.py +++ b/src/struphy/models/kinetic.py @@ -1,5 +1,4 @@ from struphy.arrays import xp as np - from struphy.kinetic_background.base import KineticBackground from struphy.models.base import StruphyModel from struphy.pic.accumulation import accum_kernels, accum_kernels_gc diff --git a/src/struphy/models/tests/verification.py b/src/struphy/models/tests/verification.py index 23a136a31..b56197254 100644 --- a/src/struphy/models/tests/verification.py +++ b/src/struphy/models/tests/verification.py @@ -3,7 +3,6 @@ from pathlib import Path import h5py -from struphy.arrays import xp as np import yaml from matplotlib import pyplot as plt from matplotlib.ticker import FormatStrFormatter @@ -11,6 +10,7 @@ from scipy.special import jv, yn import struphy +from struphy.arrays import xp as np from struphy.post_processing import pproc_struphy diff --git a/src/struphy/models/toy.py b/src/struphy/models/toy.py index 759d06883..895a8af69 100644 --- a/src/struphy/models/toy.py +++ b/src/struphy/models/toy.py @@ -1,5 +1,4 @@ from struphy.arrays import xp as np - from struphy.models.base import StruphyModel from struphy.propagators import propagators_coupling, propagators_fields, propagators_markers diff --git a/src/struphy/ode/solvers.py b/src/struphy/ode/solvers.py index bfb3bce47..9091f565f 100644 --- a/src/struphy/ode/solvers.py +++ b/src/struphy/ode/solvers.py @@ -1,9 +1,9 @@ from inspect import signature -from struphy.arrays import xp as np from psydac.linalg.block import BlockVector from psydac.linalg.stencil import StencilVector +from struphy.arrays import xp as np from struphy.ode.utils import ButcherTableau diff --git a/src/struphy/ode/tests/test_ode_feec.py b/src/struphy/ode/tests/test_ode_feec.py index 654247427..31b46cc1f 100644 --- a/src/struphy/ode/tests/test_ode_feec.py +++ b/src/struphy/ode/tests/test_ode_feec.py @@ -19,12 +19,12 @@ def test_exp_growth(spaces, algo, show_plots=False): """Solve dy/dt = omega*y for different feec variables y and with all available solvers from the ButcherTableau.""" - from struphy.arrays import xp as np from matplotlib import pyplot as plt from mpi4py import MPI from psydac.linalg.block import BlockVector from psydac.linalg.stencil import StencilVector + from struphy.arrays import xp as np from struphy.feec.psydac_derham import Derham from struphy.ode.solvers import ODEsolverFEEC diff --git a/src/struphy/pic/accumulation/particles_to_grid.py b/src/struphy/pic/accumulation/particles_to_grid.py index 9dea9f790..f23accd29 100644 --- a/src/struphy/pic/accumulation/particles_to_grid.py +++ b/src/struphy/pic/accumulation/particles_to_grid.py @@ -1,6 +1,5 @@ "Base classes for particle deposition (accumulation) on the grid." -from struphy.arrays import xp as np from mpi4py import MPI from psydac.linalg.block import BlockVector from psydac.linalg.stencil import StencilMatrix, StencilVector @@ -8,6 +7,7 @@ import struphy.pic.accumulation.accum_kernels as accums import struphy.pic.accumulation.accum_kernels_gc as accums_gc import struphy.pic.accumulation.filter_kernels as filters +from struphy.arrays import xp as np from struphy.feec.mass import WeightedMassOperators from struphy.feec.psydac_derham import Derham from struphy.kernel_arguments.pusher_args_kernels import DerhamArguments, DomainArguments diff --git a/src/struphy/pic/base.py b/src/struphy/pic/base.py index ffa87c930..8a76cafdb 100644 --- a/src/struphy/pic/base.py +++ b/src/struphy/pic/base.py @@ -4,12 +4,12 @@ from abc import ABCMeta, abstractmethod import h5py -from struphy.arrays import xp as np import scipy.special as sp from mpi4py import MPI from mpi4py.MPI import Intracomm from sympy.ntheory import factorint +from struphy.arrays import xp as np from struphy.bsplines.bsplines import quadrature_grid from struphy.fields_background import equils from struphy.fields_background.base import FluidEquilibrium, FluidEquilibriumWithB, NumericalFluidEquilibrium diff --git a/src/struphy/pic/particles.py b/src/struphy/pic/particles.py index be1db3794..6ebf96570 100644 --- a/src/struphy/pic/particles.py +++ b/src/struphy/pic/particles.py @@ -1,7 +1,6 @@ import copy from struphy.arrays import xp as np - from struphy.fields_background.base import FluidEquilibriumWithB from struphy.fields_background.projected_equils import ProjectedFluidEquilibriumWithB from struphy.geometry.base import Domain diff --git a/src/struphy/pic/pushing/pusher.py b/src/struphy/pic/pushing/pusher.py index 014f8276f..77d8110e6 100644 --- a/src/struphy/pic/pushing/pusher.py +++ b/src/struphy/pic/pushing/pusher.py @@ -1,8 +1,8 @@ "Accelerated particle pushing." -from struphy.arrays import xp as np from mpi4py.MPI import IN_PLACE, SUM +from struphy.arrays import xp as np from struphy.kernel_arguments.pusher_args_kernels import DerhamArguments, DomainArguments from struphy.pic.base import Particles from struphy.profiling.profiling import ProfileManager diff --git a/src/struphy/pic/sobol_seq.py b/src/struphy/pic/sobol_seq.py index 3160ce5d3..8c30be765 100644 --- a/src/struphy/pic/sobol_seq.py +++ b/src/struphy/pic/sobol_seq.py @@ -17,9 +17,10 @@ from __future__ import division -from struphy.arrays import xp as np from scipy.stats import norm +from struphy.arrays import xp as np + __all__ = ["i4_bit_hi1", "i4_bit_lo0", "i4_sobol_generate", "i4_sobol", "i4_uniform", "prime_ge", "is_prime"] diff --git a/src/struphy/pic/tests/test_accum_vec_H1.py b/src/struphy/pic/tests/test_accum_vec_H1.py index a9118cd33..125a9dec6 100644 --- a/src/struphy/pic/tests/test_accum_vec_H1.py +++ b/src/struphy/pic/tests/test_accum_vec_H1.py @@ -46,9 +46,9 @@ def test_accum_poisson(Nel, p, spl_kind, mapping, num_clones, Np=1000): import copy - from struphy.arrays import xp as np from mpi4py import MPI + from struphy.arrays import xp as np from struphy.feec.mass import WeightedMassOperators from struphy.feec.psydac_derham import Derham from struphy.geometry import domains diff --git a/src/struphy/pic/tests/test_accumulation.py b/src/struphy/pic/tests/test_accumulation.py index eb4d5943f..dec9f81d8 100644 --- a/src/struphy/pic/tests/test_accumulation.py +++ b/src/struphy/pic/tests/test_accumulation.py @@ -47,9 +47,9 @@ def test_accumulation(Nel, p, spl_kind, mapping, Np=40, verbose=False): def pc_lin_mhd_6d_step_ph_full(Nel, p, spl_kind, mapping, Np, verbose=False): from time import time - from struphy.arrays import xp as np from mpi4py import MPI + from struphy.arrays import xp as np from struphy.eigenvalue_solvers.spline_space import Spline_space_1d, Tensor_spline_space from struphy.feec.mass import WeightedMassOperators from struphy.feec.psydac_derham import Derham diff --git a/src/struphy/pic/tests/test_binning.py b/src/struphy/pic/tests/test_binning.py index 5e4d49c38..f033f5ce7 100644 --- a/src/struphy/pic/tests/test_binning.py +++ b/src/struphy/pic/tests/test_binning.py @@ -36,9 +36,9 @@ def test_binning_6D_full_f(mapping, show_plot=False): """ import matplotlib.pyplot as plt - from struphy.arrays import xp as np from mpi4py import MPI + from struphy.arrays import xp as np from struphy.geometry import domains from struphy.kinetic_background.maxwellians import Maxwellian3D from struphy.pic.particles import Particles6D @@ -295,9 +295,9 @@ def test_binning_6D_delta_f(mapping, show_plot=False): """ import matplotlib.pyplot as plt - from struphy.arrays import xp as np from mpi4py import MPI + from struphy.arrays import xp as np from struphy.geometry import domains from struphy.kinetic_background.maxwellians import Maxwellian3D from struphy.pic.particles import DeltaFParticles6D @@ -519,9 +519,9 @@ def test_binning_6D_full_f_mpi(mapping, show_plot=False): """ import matplotlib.pyplot as plt - from struphy.arrays import xp as np from mpi4py import MPI + from struphy.arrays import xp as np from struphy.geometry import domains from struphy.kinetic_background.maxwellians import Maxwellian3D from struphy.pic.particles import Particles6D @@ -801,9 +801,9 @@ def test_binning_6D_delta_f_mpi(mapping, show_plot=False): """ import matplotlib.pyplot as plt - from struphy.arrays import xp as np from mpi4py import MPI + from struphy.arrays import xp as np from struphy.geometry import domains from struphy.kinetic_background.maxwellians import Maxwellian3D from struphy.pic.particles import DeltaFParticles6D diff --git a/src/struphy/pic/tests/test_draw_parallel.py b/src/struphy/pic/tests/test_draw_parallel.py index 9f3f71598..e7c7d6bcc 100644 --- a/src/struphy/pic/tests/test_draw_parallel.py +++ b/src/struphy/pic/tests/test_draw_parallel.py @@ -36,9 +36,9 @@ def test_draw(Nel, p, spl_kind, mapping, ppc=10): """Asserts whether all particles are on the correct process after `particles.mpi_sort_markers()`.""" - from struphy.arrays import xp as np from mpi4py import MPI + from struphy.arrays import xp as np from struphy.feec.psydac_derham import Derham from struphy.geometry import domains from struphy.pic.particles import Particles6D diff --git a/src/struphy/pic/tests/test_mat_vec_filler.py b/src/struphy/pic/tests/test_mat_vec_filler.py index 1ed8e2634..c759f67c8 100644 --- a/src/struphy/pic/tests/test_mat_vec_filler.py +++ b/src/struphy/pic/tests/test_mat_vec_filler.py @@ -1,6 +1,7 @@ -from struphy.arrays import xp as np import pytest +from struphy.arrays import xp as np + @pytest.mark.mpi(min_size=2) @pytest.mark.parametrize("Nel", [[8, 9, 10]]) diff --git a/src/struphy/pic/tests/test_pic_legacy_files/accumulation.py b/src/struphy/pic/tests/test_pic_legacy_files/accumulation.py index cea8a4fd6..f96e93e92 100644 --- a/src/struphy/pic/tests/test_pic_legacy_files/accumulation.py +++ b/src/struphy/pic/tests/test_pic_legacy_files/accumulation.py @@ -8,11 +8,11 @@ import time -from struphy.arrays import xp as np import scipy.sparse as spa from mpi4py import MPI import struphy.pic.tests.test_pic_legacy_files.accumulation_kernels_3d as pic_ker_3d +from struphy.arrays import xp as np # import struphy.pic.tests.test_pic_legacy_files.accumulation_kernels_2d as pic_ker_2d diff --git a/src/struphy/pic/tests/test_pic_legacy_files/pusher.py b/src/struphy/pic/tests/test_pic_legacy_files/pusher.py index 919e1774e..f31e12b99 100644 --- a/src/struphy/pic/tests/test_pic_legacy_files/pusher.py +++ b/src/struphy/pic/tests/test_pic_legacy_files/pusher.py @@ -1,8 +1,7 @@ -from struphy.arrays import xp as np - import struphy.pic.tests.test_pic_legacy_files.pusher_pos as push_pos import struphy.pic.tests.test_pic_legacy_files.pusher_vel_2d as push_vel_2d import struphy.pic.tests.test_pic_legacy_files.pusher_vel_3d as push_vel_3d +from struphy.arrays import xp as np class Pusher: diff --git a/src/struphy/pic/tests/test_pushers.py b/src/struphy/pic/tests/test_pushers.py index a9c3bc086..1fca079ea 100644 --- a/src/struphy/pic/tests/test_pushers.py +++ b/src/struphy/pic/tests/test_pushers.py @@ -22,9 +22,9 @@ ], ) def test_push_vxb_analytic(Nel, p, spl_kind, mapping, show_plots=False): - from struphy.arrays import xp as np from mpi4py import MPI + from struphy.arrays import xp as np from struphy.eigenvalue_solvers.spline_space import Spline_space_1d, Tensor_spline_space from struphy.feec.psydac_derham import Derham from struphy.feec.utilities import create_equal_random_arrays @@ -159,9 +159,9 @@ def test_push_vxb_analytic(Nel, p, spl_kind, mapping, show_plots=False): ], ) def test_push_bxu_Hdiv(Nel, p, spl_kind, mapping, show_plots=False): - from struphy.arrays import xp as np from mpi4py import MPI + from struphy.arrays import xp as np from struphy.eigenvalue_solvers.spline_space import Spline_space_1d, Tensor_spline_space from struphy.feec.psydac_derham import Derham from struphy.feec.utilities import create_equal_random_arrays @@ -307,9 +307,9 @@ def test_push_bxu_Hdiv(Nel, p, spl_kind, mapping, show_plots=False): ], ) def test_push_bxu_Hcurl(Nel, p, spl_kind, mapping, show_plots=False): - from struphy.arrays import xp as np from mpi4py import MPI + from struphy.arrays import xp as np from struphy.eigenvalue_solvers.spline_space import Spline_space_1d, Tensor_spline_space from struphy.feec.psydac_derham import Derham from struphy.feec.utilities import create_equal_random_arrays @@ -455,9 +455,9 @@ def test_push_bxu_Hcurl(Nel, p, spl_kind, mapping, show_plots=False): ], ) def test_push_bxu_H1vec(Nel, p, spl_kind, mapping, show_plots=False): - from struphy.arrays import xp as np from mpi4py import MPI + from struphy.arrays import xp as np from struphy.eigenvalue_solvers.spline_space import Spline_space_1d, Tensor_spline_space from struphy.feec.psydac_derham import Derham from struphy.feec.utilities import create_equal_random_arrays @@ -603,9 +603,9 @@ def test_push_bxu_H1vec(Nel, p, spl_kind, mapping, show_plots=False): ], ) def test_push_bxu_Hdiv_pauli(Nel, p, spl_kind, mapping, show_plots=False): - from struphy.arrays import xp as np from mpi4py import MPI + from struphy.arrays import xp as np from struphy.eigenvalue_solvers.spline_space import Spline_space_1d, Tensor_spline_space from struphy.feec.psydac_derham import Derham from struphy.feec.utilities import create_equal_random_arrays @@ -753,9 +753,9 @@ def test_push_bxu_Hdiv_pauli(Nel, p, spl_kind, mapping, show_plots=False): ], ) def test_push_eta_rk4(Nel, p, spl_kind, mapping, show_plots=False): - from struphy.arrays import xp as np from mpi4py import MPI + from struphy.arrays import xp as np from struphy.eigenvalue_solvers.spline_space import Spline_space_1d, Tensor_spline_space from struphy.feec.psydac_derham import Derham from struphy.feec.utilities import create_equal_random_arrays diff --git a/src/struphy/pic/tests/test_sorting.py b/src/struphy/pic/tests/test_sorting.py index 6872b5d53..810a08e0b 100644 --- a/src/struphy/pic/tests/test_sorting.py +++ b/src/struphy/pic/tests/test_sorting.py @@ -1,9 +1,9 @@ from time import time -from struphy.arrays import xp as np import pytest from mpi4py import MPI +from struphy.arrays import xp as np from struphy.feec.psydac_derham import Derham from struphy.geometry import domains from struphy.pic.particles import Particles6D diff --git a/src/struphy/pic/tests/test_sph.py b/src/struphy/pic/tests/test_sph.py index 437d35ecc..efd2cfe5b 100644 --- a/src/struphy/pic/tests/test_sph.py +++ b/src/struphy/pic/tests/test_sph.py @@ -1,8 +1,8 @@ -from struphy.arrays import xp as np import pytest from matplotlib import pyplot as plt from mpi4py import MPI +from struphy.arrays import xp as np from struphy.geometry import domains from struphy.pic.particles import ParticlesSPH diff --git a/src/struphy/pic/tests/test_tesselation.py b/src/struphy/pic/tests/test_tesselation.py index a54f3d3f3..277365f64 100644 --- a/src/struphy/pic/tests/test_tesselation.py +++ b/src/struphy/pic/tests/test_tesselation.py @@ -1,10 +1,10 @@ from time import time -from struphy.arrays import xp as np import pytest from matplotlib import pyplot as plt from mpi4py import MPI +from struphy.arrays import xp as np from struphy.feec.psydac_derham import Derham from struphy.geometry import domains from struphy.pic.particles import ParticlesSPH diff --git a/src/struphy/pic/utilities.py b/src/struphy/pic/utilities.py index 69ae71027..d27cca7de 100644 --- a/src/struphy/pic/utilities.py +++ b/src/struphy/pic/utilities.py @@ -1,6 +1,5 @@ -from struphy.arrays import xp as np - import struphy.pic.utilities_kernels as utils +from struphy.arrays import xp as np def get_kinetic_energy_particles(fe_coeffs, derham, domain, particles): diff --git a/src/struphy/polar/basic.py b/src/struphy/polar/basic.py index eb35dbca2..87da77db3 100644 --- a/src/struphy/polar/basic.py +++ b/src/struphy/polar/basic.py @@ -1,9 +1,10 @@ -from struphy.arrays import xp as np from mpi4py import MPI from psydac.linalg.basic import Vector, VectorSpace from psydac.linalg.block import BlockVector from psydac.linalg.stencil import StencilVector +from struphy.arrays import xp as np + class PolarDerhamSpace(VectorSpace): """ diff --git a/src/struphy/polar/linear_operators.py b/src/struphy/polar/linear_operators.py index 977571311..5af6d2373 100644 --- a/src/struphy/polar/linear_operators.py +++ b/src/struphy/polar/linear_operators.py @@ -1,9 +1,9 @@ -from struphy.arrays import xp as np from mpi4py import MPI from psydac.linalg.block import BlockVector, BlockVectorSpace from psydac.linalg.stencil import StencilVector, StencilVectorSpace from scipy.sparse import csr_matrix, identity +from struphy.arrays import xp as np from struphy.feec.linear_operators import LinOpWithTransp from struphy.linear_algebra.linalg_kron import kron_matvec_2d from struphy.polar.basic import PolarDerhamSpace, PolarVector diff --git a/src/struphy/polar/tests/test_legacy_polar_splines.py b/src/struphy/polar/tests/test_legacy_polar_splines.py index e1f1ed1d1..114558116 100644 --- a/src/struphy/polar/tests/test_legacy_polar_splines.py +++ b/src/struphy/polar/tests/test_legacy_polar_splines.py @@ -8,9 +8,9 @@ def test_polar_splines_2D(plot=False): sys.path.append("..") import matplotlib.pyplot as plt - from struphy.arrays import xp as np from mpl_toolkits.mplot3d import Axes3D + from struphy.arrays import xp as np from struphy.eigenvalue_solvers.spline_space import Spline_space_1d, Tensor_spline_space from struphy.geometry import domains diff --git a/src/struphy/polar/tests/test_polar.py b/src/struphy/polar/tests/test_polar.py index 8b1a97b20..967dd72dd 100644 --- a/src/struphy/polar/tests/test_polar.py +++ b/src/struphy/polar/tests/test_polar.py @@ -168,9 +168,9 @@ def test_spaces(Nel, p, spl_kind): @pytest.mark.parametrize("p", [[3, 2, 2]]) @pytest.mark.parametrize("spl_kind", [[False, True, True], [False, True, False]]) def test_extraction_ops_and_derivatives(Nel, p, spl_kind): - from struphy.arrays import xp as np from mpi4py import MPI + from struphy.arrays import xp as np from struphy.eigenvalue_solvers.spline_space import Spline_space_1d, Tensor_spline_space from struphy.feec.psydac_derham import Derham from struphy.feec.utilities import compare_arrays, create_equal_random_arrays @@ -303,9 +303,9 @@ def test_extraction_ops_and_derivatives(Nel, p, spl_kind): @pytest.mark.parametrize("p", [[4, 3, 2]]) @pytest.mark.parametrize("spl_kind", [[False, True, True], [False, True, False]]) def test_projectors(Nel, p, spl_kind): - from struphy.arrays import xp as np from mpi4py import MPI + from struphy.arrays import xp as np from struphy.eigenvalue_solvers.spline_space import Spline_space_1d, Tensor_spline_space from struphy.feec.psydac_derham import Derham from struphy.geometry.domains import IGAPolarCylinder diff --git a/src/struphy/post_processing/likwid/plot_likwidproject.py b/src/struphy/post_processing/likwid/plot_likwidproject.py index 74c93569a..12f70a2dd 100644 --- a/src/struphy/post_processing/likwid/plot_likwidproject.py +++ b/src/struphy/post_processing/likwid/plot_likwidproject.py @@ -8,7 +8,6 @@ import sys import matplotlib.pyplot as plt -from struphy.arrays import xp as np import pandas as pd import plotly.express as px import plotly.graph_objects as go @@ -17,6 +16,7 @@ import struphy.post_processing.likwid.likwid_parser as lp import struphy.post_processing.likwid.maxplotlylib as mply import struphy.post_processing.likwid.roofline_plotter as rp +from struphy.arrays import xp as np def clean_string(string_in): diff --git a/src/struphy/post_processing/likwid/plot_time_traces.py b/src/struphy/post_processing/likwid/plot_time_traces.py index bd1da4ffb..cf0049efe 100644 --- a/src/struphy/post_processing/likwid/plot_time_traces.py +++ b/src/struphy/post_processing/likwid/plot_time_traces.py @@ -3,11 +3,11 @@ import re import matplotlib.pyplot as plt -from struphy.arrays import xp as np import plotly.io as pio # pio.kaleido.scope.mathjax = None import struphy.post_processing.likwid.maxplotlylib as mply +from struphy.arrays import xp as np def glob_to_regex(pat: str) -> str: diff --git a/src/struphy/post_processing/likwid/roofline_plotter.py b/src/struphy/post_processing/likwid/roofline_plotter.py index 46e8b92b0..584fadbdb 100644 --- a/src/struphy/post_processing/likwid/roofline_plotter.py +++ b/src/struphy/post_processing/likwid/roofline_plotter.py @@ -1,10 +1,11 @@ import glob import pickle -from struphy.arrays import xp as np import pandas as pd import yaml +from struphy.arrays import xp as np + def sort_by_num_threads(bm): sorted_arrays = {} diff --git a/src/struphy/post_processing/orbits/orbits_tools.py b/src/struphy/post_processing/orbits/orbits_tools.py index 358f052b3..0b6b2d47c 100644 --- a/src/struphy/post_processing/orbits/orbits_tools.py +++ b/src/struphy/post_processing/orbits/orbits_tools.py @@ -2,10 +2,10 @@ import shutil import h5py -from struphy.arrays import xp as np import yaml from tqdm import tqdm +from struphy.arrays import xp as np from struphy.io.setup import setup_domain_and_equil from struphy.post_processing.orbits.orbits_kernels import calculate_guiding_center_from_6d diff --git a/src/struphy/post_processing/post_processing_tools.py b/src/struphy/post_processing/post_processing_tools.py index 49b72b408..3e5ce165f 100644 --- a/src/struphy/post_processing/post_processing_tools.py +++ b/src/struphy/post_processing/post_processing_tools.py @@ -3,10 +3,10 @@ import h5py import matplotlib.pyplot as plt -from struphy.arrays import xp as np import yaml from tqdm import tqdm +from struphy.arrays import xp as np from struphy.feec.psydac_derham import Derham from struphy.io.setup import setup_domain_and_equil from struphy.kinetic_background import maxwellians diff --git a/src/struphy/post_processing/pproc_struphy.py b/src/struphy/post_processing/pproc_struphy.py index f1e839949..0e1a87752 100644 --- a/src/struphy/post_processing/pproc_struphy.py +++ b/src/struphy/post_processing/pproc_struphy.py @@ -42,11 +42,11 @@ def main( import shutil import h5py - from struphy.arrays import xp as np import yaml import struphy.post_processing.orbits.orbits_tools as orbits_pproc import struphy.post_processing.post_processing_tools as pproc + from struphy.arrays import xp as np from struphy.models import fluid, hybrid, kinetic, toy print("") diff --git a/src/struphy/post_processing/profile_struphy.py b/src/struphy/post_processing/profile_struphy.py index 513e582ef..a1602095d 100644 --- a/src/struphy/post_processing/profile_struphy.py +++ b/src/struphy/post_processing/profile_struphy.py @@ -1,10 +1,10 @@ import pickle import sys -from struphy.arrays import xp as np import yaml from matplotlib import pyplot as plt +from struphy.arrays import xp as np from struphy.post_processing.cprofile_analyser import get_cprofile_data, replace_keys diff --git a/src/struphy/profiling/profiling.py b/src/struphy/profiling/profiling.py index 00f8f9c03..9b42d50ca 100644 --- a/src/struphy/profiling/profiling.py +++ b/src/struphy/profiling/profiling.py @@ -17,9 +17,10 @@ # Import the profiling configuration class and context manager from functools import lru_cache -from struphy.arrays import xp as np from mpi4py import MPI +from struphy.arrays import xp as np + @lru_cache(maxsize=None) # Cache the import result to avoid repeated imports def _import_pylikwid(): diff --git a/src/struphy/propagators/base.py b/src/struphy/propagators/base.py index ee0cc39ba..8ef61c56a 100644 --- a/src/struphy/propagators/base.py +++ b/src/struphy/propagators/base.py @@ -3,7 +3,6 @@ from abc import ABCMeta, abstractmethod from struphy.arrays import xp as np - from struphy.feec.basis_projection_ops import BasisProjectionOperators from struphy.feec.mass import WeightedMassOperators from struphy.feec.psydac_derham import Derham diff --git a/src/struphy/propagators/propagators_coupling.py b/src/struphy/propagators/propagators_coupling.py index 9e1df7653..8476bd756 100644 --- a/src/struphy/propagators/propagators_coupling.py +++ b/src/struphy/propagators/propagators_coupling.py @@ -1,9 +1,9 @@ "Particle and FEEC variables are updated." -from struphy.arrays import xp as np from psydac.linalg.block import BlockVector from psydac.linalg.stencil import StencilVector +from struphy.arrays import xp as np from struphy.feec import preconditioner from struphy.feec.linear_operators import LinOpWithTransp from struphy.io.setup import descend_options_dict diff --git a/src/struphy/propagators/propagators_fields.py b/src/struphy/propagators/propagators_fields.py index 2d73e8971..c8759254a 100644 --- a/src/struphy/propagators/propagators_fields.py +++ b/src/struphy/propagators/propagators_fields.py @@ -3,7 +3,6 @@ from collections.abc import Callable from copy import deepcopy -from struphy.arrays import xp as np import scipy as sc from matplotlib import pyplot as plt from mpi4py import MPI @@ -15,6 +14,7 @@ from psydac.linalg.stencil import StencilVector import struphy.feec.utilities as util +from struphy.arrays import xp as np from struphy.examples.restelli2018 import callables from struphy.feec import preconditioner from struphy.feec.basis_projection_ops import ( diff --git a/src/struphy/propagators/propagators_markers.py b/src/struphy/propagators/propagators_markers.py index 847ede30e..523dd65cb 100644 --- a/src/struphy/propagators/propagators_markers.py +++ b/src/struphy/propagators/propagators_markers.py @@ -1,10 +1,10 @@ "Only particle variables are updated." -from struphy.arrays import xp as np from numpy import array, polynomial, random from psydac.linalg.block import BlockVector from psydac.linalg.stencil import StencilVector +from struphy.arrays import xp as np from struphy.feec.mass import WeightedMassOperators from struphy.fields_background.base import MHDequilibrium from struphy.fields_background.equils import set_defaults diff --git a/src/struphy/propagators/tests/test_gyrokinetic_poisson.py b/src/struphy/propagators/tests/test_gyrokinetic_poisson.py index 5fa4abbf8..a89e0a351 100644 --- a/src/struphy/propagators/tests/test_gyrokinetic_poisson.py +++ b/src/struphy/propagators/tests/test_gyrokinetic_poisson.py @@ -1,8 +1,8 @@ import matplotlib.pyplot as plt -from struphy.arrays import xp as np import pytest from mpi4py import MPI +from struphy.arrays import xp as np from struphy.feec.mass import WeightedMassOperators from struphy.feec.projectors import L2Projector from struphy.feec.psydac_derham import Derham diff --git a/src/struphy/propagators/tests/test_poisson.py b/src/struphy/propagators/tests/test_poisson.py index 5e5c4ec75..4a67f257c 100644 --- a/src/struphy/propagators/tests/test_poisson.py +++ b/src/struphy/propagators/tests/test_poisson.py @@ -1,8 +1,8 @@ import matplotlib.pyplot as plt -from struphy.arrays import xp as np import pytest from mpi4py import MPI +from struphy.arrays import xp as np from struphy.feec.mass import WeightedMassOperators from struphy.feec.projectors import L2Projector from struphy.feec.psydac_derham import Derham diff --git a/src/struphy/utils/clone_config.py b/src/struphy/utils/clone_config.py index 289bb582a..cb8ab64e3 100644 --- a/src/struphy/utils/clone_config.py +++ b/src/struphy/utils/clone_config.py @@ -1,6 +1,7 @@ -from struphy.arrays import xp as np from mpi4py import MPI +from struphy.arrays import xp as np + class CloneConfig: """ From cd820f9bc0d5b77287ac7e7897d10c63b0555f25 Mon Sep 17 00:00:00 2001 From: Max Lindqvist Date: Fri, 10 Oct 2025 09:20:28 +0200 Subject: [PATCH 43/76] Moved the printing into the class and fixed the literals wuth BackendType --- src/struphy/arrays.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/struphy/arrays.py b/src/struphy/arrays.py index c5c46d6c5..17f2e78b6 100644 --- a/src/struphy/arrays.py +++ b/src/struphy/arrays.py @@ -13,7 +13,9 @@ def __init__( backend: BackendType = "numpy", verbose: bool = False, ) -> None: - self._backend = backend + assert backend.lower() in ["numpy", "cupy"], "Array backend must be either 'numpy' or 'cupy'." + + self._backend: BackendType = "cupy" if backend.lower() == "cupy" else "numpy" # Import numpy/cupy if self.backend == "cupy": @@ -23,13 +25,15 @@ def __init__( self._xp = cp except ImportError: if verbose: - print("CuPy not available, falling back to NumPy.") + print("CuPy not available.") self._backend = "numpy" if self.backend == "numpy": import numpy as np self._xp = np + if verbose: + print(f"Using {xp.__name__} backend.") @property def backend(self) -> BackendType: @@ -43,12 +47,13 @@ def xp(self) -> ModuleType: # TODO: Make this configurable via environment variable or config file. array_backend = ArrayBackend( - backend=os.getenv("ARRAY_BACKEND", "numpy").lower(), + backend="cupy" if os.getenv("ARRAY_BACKEND", "numpy").lower() == "cupy" else "numpy", + verbose=True, ) +# TYPE_CHECKING is True when type checking (e.g., mypy), but False at runtime. +# This allows us to use autocompletion for xp (i.e., numpy/cupy) as if numpy was imported. if TYPE_CHECKING: import numpy as xp else: xp = array_backend.xp - -print(f"Using {xp.__name__} backend.") From 209c3d4debc0b8065197c7af6938c8936c79f534 Mon Sep 17 00:00:00 2001 From: Max Lindqvist Date: Fri, 10 Oct 2025 09:20:45 +0200 Subject: [PATCH 44/76] Formattign --- src/struphy/arrays.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/struphy/arrays.py b/src/struphy/arrays.py index 17f2e78b6..61acd33bc 100644 --- a/src/struphy/arrays.py +++ b/src/struphy/arrays.py @@ -2,8 +2,6 @@ from types import ModuleType from typing import TYPE_CHECKING, Literal -from numpy import isin - BackendType = Literal["numpy", "cupy"] From 087e8f0281d1c35bf04548aa7d7fc939a173dc38 Mon Sep 17 00:00:00 2001 From: Max Lindqvist Date: Fri, 10 Oct 2025 09:23:12 +0200 Subject: [PATCH 45/76] Moved test_cupy to test stage and uncommented the usual pipelines --- .gitlab-ci.yml | 1113 ++++++++++++++++++++++++------------------------ 1 file changed, 556 insertions(+), 557 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4737c8309..c6f5c8171 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -496,17 +496,37 @@ inspect_repo: - ./cloc --version - ./cloc $(git ls-files) +##################### +### PUSH PIPELINE ### +##################### + +# check_struphy_simulation_params: +# stage: test +# extends: +# - .rules_mr_to_devel +# - .image_gitlab_mpcdf_struphy +# - .before_script_load_modules +# - .variables_push +# script: +# - !reference [.scripts, install_on_push] +# - git clone https://gitlab.mpcdf.mpg.de/struphy/struphy-simulations.git +# - | +# for file in struphy-simulations/**/*.yml; do +# echo "Checking $file" +# # TODO: How to deduce the model? +# struphy params LinearVlasovAmpereOneSpecies --check-file $file +# done + test_cupy: tags: [nvidia-cc80] image: gitlab-registry.mpcdf.mpg.de/mpcdf/ci-module-image/nvhpcsdk_24-openmpi_5_0:2025 - stage: startup + stage: test extends: - .rules_startup before_script: - module avail - module list - module purge - #- module load cuda/12.6 gcc/13 openmpi/5.0 - module load nvhpcsdk/24 openmpi/5.0 python-waterboa/2024.06 gcc/13 script: - ls @@ -519,579 +539,558 @@ test_cupy: - python3 src/struphy/arrays.py - python3 src/struphy/cupy_vs_numpy.py -# ##################### -# ### PUSH PIPELINE ### -# ##################### - -# # check_struphy_simulation_params: -# # stage: test -# # extends: -# # - .rules_mr_to_devel -# # - .image_gitlab_mpcdf_struphy -# # - .before_script_load_modules -# # - .variables_push -# # script: -# # - !reference [.scripts, install_on_push] -# # - git clone https://gitlab.mpcdf.mpg.de/struphy/struphy-simulations.git -# # - | -# # for file in struphy-simulations/**/*.yml; do -# # echo "Checking $file" -# # # TODO: How to deduce the model? -# # struphy params LinearVlasovAmpereOneSpecies --check-file $file -# # done - -# install_tests: -# stage: test -# extends: -# - .rules_mr_to_devel -# - .image_gitlab_mpcdf_struphy -# - .before_script_load_modules -# - .parallel_matrix_install -# script: -# - !reference [.scripts, install_on_push] +install_tests: + stage: test + extends: + - .rules_mr_to_devel + - .image_gitlab_mpcdf_struphy + - .before_script_load_modules + - .parallel_matrix_install + script: + - !reference [.scripts, install_on_push] -# unit_tests: -# stage: test -# extends: -# - .rules_mr_to_devel -# - .image_gitlab_mpcdf_struphy -# - .before_script_load_modules -# - .variables_push -# script: -# - !reference [.scripts, install_on_push] -# - !reference [.scripts, unit_tests] +unit_tests: + stage: test + extends: + - .rules_mr_to_devel + - .image_gitlab_mpcdf_struphy + - .before_script_load_modules + - .variables_push + script: + - !reference [.scripts, install_on_push] + - !reference [.scripts, unit_tests] -# tests_pyccel_devel: -# stage: test -# extends: -# - .rules_scheduled -# - .image_gitlab_mpcdf_struphy -# - .before_script_load_modules -# - .variables_push -# script: -# - !reference [.scripts, install_pyccel_devel] -# - !reference [.scripts, unit_tests] -# - !reference [.scripts, model_tests] +tests_pyccel_devel: + stage: test + extends: + - .rules_scheduled + - .image_gitlab_mpcdf_struphy + - .before_script_load_modules + - .variables_push + script: + - !reference [.scripts, install_pyccel_devel] + - !reference [.scripts, unit_tests] + - !reference [.scripts, model_tests] -# model_tests: -# stage: test -# extends: -# - .rules_mr_to_devel -# - .image_gitlab_mpcdf_struphy -# - .before_script_load_modules -# - .variables_push -# script: -# - !reference [.scripts, install_on_push] -# - !reference [.scripts, model_tests] +model_tests: + stage: test + extends: + - .rules_mr_to_devel + - .image_gitlab_mpcdf_struphy + - .before_script_load_modules + - .variables_push + script: + - !reference [.scripts, install_on_push] + - !reference [.scripts, model_tests] -# quickstart_tests: -# stage: test -# extends: -# - .rules_mr_to_devel -# - .image_gitlab_mpcdf_struphy -# - .before_script_load_modules -# - .variables_push -# script: -# - !reference [.scripts, install_on_push] -# - !reference [.scripts, quickstart_tests] +quickstart_tests: + stage: test + extends: + - .rules_mr_to_devel + - .image_gitlab_mpcdf_struphy + - .before_script_load_modules + - .variables_push + script: + - !reference [.scripts, install_on_push] + - !reference [.scripts, quickstart_tests] -# pages_tests: -# stage: test -# extends: -# - .rules_mr_to_devel -# - .image_gitlab_mpcdf_struphy -# - .before_script_load_modules -# - .variables_push -# script: -# - !reference [.scripts, install_on_push] -# - !reference [.scripts, inspect_struphy] -# - module load pandoc -# - module list -# - pip install .[doc] -# - | -# struphy compile -y || ( -# echo "Initial compile failed. Removing compiled kernels and trying again..." && -# struphy compile -d -y && -# struphy compile -y -# ) -# - cd doc ; make html -# - mv _build/html/ $CI_PROJECT_DIR/documentation/ -# artifacts: -# expose_as: 'Documentation' -# paths: -# - documentation/ - -# ubuntu_latest: -# stage: test -# extends: -# - .rules_mr_to_devel -# - .image_ubuntu_struphy -# - .variables_push -# script: -# - !reference [.scripts, inspect_directory] -# - !reference [.scripts, install_on_push] -# - !reference [.scripts, quickstart_tests] -# - !reference [.scripts, model_tests] +pages_tests: + stage: test + extends: + - .rules_mr_to_devel + - .image_gitlab_mpcdf_struphy + - .before_script_load_modules + - .variables_push + script: + - !reference [.scripts, install_on_push] + - !reference [.scripts, inspect_struphy] + - module load pandoc + - module list + - pip install .[doc] + - | + struphy compile -y || ( + echo "Initial compile failed. Removing compiled kernels and trying again..." && + struphy compile -d -y && + struphy compile -y + ) + - cd doc ; make html + - mv _build/html/ $CI_PROJECT_DIR/documentation/ + artifacts: + expose_as: 'Documentation' + paths: + - documentation/ -# macos_nmpp: -# stage: test -# tags: [macos, nmpp, private] -# needs: [] -# variables: -# # Job ID changes for each job, so reusing the directory becomes impossible, -# # therefore, the fetch strategy also becomes unusable -# GIT_CLONE_PATH: $CI_BUILDS_DIR/$CI_PROJECT_NAME/$CI_JOB_ID/$CI_CONCURRENT_PROJECT_ID -# _JOB_PATH: $CI_BUILDS_DIR/$CI_PROJECT_NAME/$CI_JOB_ID -# extends: -# - .rules_mr_to_devel -# - .variables_push -# before_script: -# # - brew install cmake -# - brew link --overwrite cmake -# - cmake --version -# - make -v -# - printenv -# - system_profiler SPHardwareDataType -# - export FC=`which gfortran` # for gvec -# - export CC=`which gcc` # for gvec -# - export CXX=`which g++` # for gvec -# script: -# - !reference [.scripts, create_venv] -# - !reference [.scripts, install] -# - !reference [.scripts, compile] -# - !reference [.scripts, quickstart_tests] -# - !reference [.scripts, model_tests] -# after_script: -# - pwd -# - ls -a -# - echo $_JOB_PATH -# - ls -a $_JOB_PATH -# - rm -rf $_JOB_PATH - -# cleanup_macos: -# stage: test -# tags: [macos, nmpp, private] -# needs: [] -# extends: -# - .rules_cleanup_macos -# before_script: -# - make -v -# - printenv -# - system_profiler SPHardwareDataType -# script: -# - _STRUPHY_PATH=$CI_BUILDS_DIR/$CI_PROJECT_NAME -# - pwd -# - ls -a -# - echo $_STRUPHY_PATH -# - ls -a $_STRUPHY_PATH -# - rm -rf $_STRUPHY_PATH/* -# - ls -a $_STRUPHY_PATH - -# ########################## -# ### SCHEDULED PIPELINE ### -# ########################## - - -# install_scheduled: -# stage: install -# needs: [] -# extends: -# - .rules_scheduled -# - .image_gitlab_mpcdf_gcc_openmp -# - .before_script_load_modules -# - .parallel_matrix_scheduled -# - .artifacts_scheduled -# script: -# - !reference [.scripts, create_venv_matrix] -# - !reference [.scripts, install_no_binary] -# - !reference [.scripts, compile_matrix] +ubuntu_latest: + stage: test + extends: + - .rules_mr_to_devel + - .image_ubuntu_struphy + - .variables_push + script: + - !reference [.scripts, inspect_directory] + - !reference [.scripts, install_on_push] + - !reference [.scripts, quickstart_tests] + - !reference [.scripts, model_tests] + +macos_nmpp: + stage: test + tags: [macos, nmpp, private] + needs: [] + variables: + # Job ID changes for each job, so reusing the directory becomes impossible, + # therefore, the fetch strategy also becomes unusable + GIT_CLONE_PATH: $CI_BUILDS_DIR/$CI_PROJECT_NAME/$CI_JOB_ID/$CI_CONCURRENT_PROJECT_ID + _JOB_PATH: $CI_BUILDS_DIR/$CI_PROJECT_NAME/$CI_JOB_ID + extends: + - .rules_mr_to_devel + - .variables_push + before_script: + # - brew install cmake + - brew link --overwrite cmake + - cmake --version + - make -v + - printenv + - system_profiler SPHardwareDataType + - export FC=`which gfortran` # for gvec + - export CC=`which gcc` # for gvec + - export CXX=`which g++` # for gvec + script: + - !reference [.scripts, create_venv] + - !reference [.scripts, install] + - !reference [.scripts, compile] + - !reference [.scripts, quickstart_tests] + - !reference [.scripts, model_tests] + after_script: + - pwd + - ls -a + - echo $_JOB_PATH + - ls -a $_JOB_PATH + - rm -rf $_JOB_PATH + +cleanup_macos: + stage: test + tags: [macos, nmpp, private] + needs: [] + extends: + - .rules_cleanup_macos + before_script: + - make -v + - printenv + - system_profiler SPHardwareDataType + script: + - _STRUPHY_PATH=$CI_BUILDS_DIR/$CI_PROJECT_NAME + - pwd + - ls -a + - echo $_STRUPHY_PATH + - ls -a $_STRUPHY_PATH + - rm -rf $_STRUPHY_PATH/* + - ls -a $_STRUPHY_PATH -# compile_timing: -# stage: install -# needs: [] -# extends: -# - .image_gitlab_mpcdf_gcc_openmp -# - .before_script_load_modules -# - .rules_scheduled -# script: -# - !reference [.scripts, create_venv] -# - !reference [.scripts, install_no_binary] -# - pyccel --version -# - struphy compile --status -# - struphy compile --delete -# - struphy compile --time-execution -y --language c > timings_c.txt -# - struphy compile --delete -# - struphy compile --time-execution -y --language fortran > timings_fortran.txt -# - | -# cat << 'EOF' > check_pyccel.sh -# #!/bin/bash -# grep 'pyccel --libdir' timings_c.txt | sed -E 's|.*/site-packages/||' | while read filepath; do -# echo "========================================" -# echo "Kernel: $filepath" -# echo "-------------------- Timers -------------------------" -# echo "# Language: C" -# grep -A 11 "pyccel.*${filepath}" timings_c.txt | tail -n +3 -# echo "# Language: Fortran" -# grep -A 13 "pyccel.*${filepath}" timings_fortran.txt | tail -n +3 -# done -# EOF -# - cat check_pyccel.sh -# - chmod +x check_pyccel.sh -# - ./check_pyccel.sh +########################## +### SCHEDULED PIPELINE ### +########################## -# test_build: -# stage: test -# extends: -# - .image_gitlab_mpcdf_gcc_openmp -# - .rules_scheduled -# - .before_script_load_modules -# needs: [] -# script: -# - !reference [.scripts, create_venv] -# - !reference [.scripts, build] -# - pip install $(echo dist/struphy*.whl) --no-cache-dir --no-binary mpi4py -# unit_tests_scheduled: -# stage: test -# extends: -# - .image_gitlab_mpcdf_gcc_openmp -# - .rules_scheduled -# - .parallel_matrix_scheduled -# - .before_script_load_modules -# script: -# - !reference [.scripts, source_env_matrix] -# - !reference [.scripts, unit_tests] +install_scheduled: + stage: install + needs: [] + extends: + - .rules_scheduled + - .image_gitlab_mpcdf_gcc_openmp + - .before_script_load_modules + - .parallel_matrix_scheduled + - .artifacts_scheduled + script: + - !reference [.scripts, create_venv_matrix] + - !reference [.scripts, install_no_binary] + - !reference [.scripts, compile_matrix] -# model_tests_scheduled: -# stage: test -# extends: -# - .image_gitlab_mpcdf_gcc_openmp -# - .rules_scheduled -# - .parallel_matrix_scheduled -# - .before_script_load_modules -# script: -# - !reference [.scripts, source_env_matrix] -# - !reference [.scripts, model_tests] +compile_timing: + stage: install + needs: [] + extends: + - .image_gitlab_mpcdf_gcc_openmp + - .before_script_load_modules + - .rules_scheduled + script: + - !reference [.scripts, create_venv] + - !reference [.scripts, install_no_binary] + - pyccel --version + - struphy compile --status + - struphy compile --delete + - struphy compile --time-execution -y --language c > timings_c.txt + - struphy compile --delete + - struphy compile --time-execution -y --language fortran > timings_fortran.txt + - | + cat << 'EOF' > check_pyccel.sh + #!/bin/bash + grep 'pyccel --libdir' timings_c.txt | sed -E 's|.*/site-packages/||' | while read filepath; do + echo "========================================" + echo "Kernel: $filepath" + echo "-------------------- Timers -------------------------" + echo "# Language: C" + grep -A 11 "pyccel.*${filepath}" timings_c.txt | tail -n +3 + echo "# Language: Fortran" + grep -A 13 "pyccel.*${filepath}" timings_fortran.txt | tail -n +3 + done + EOF + - cat check_pyccel.sh + - chmod +x check_pyccel.sh + - ./check_pyccel.sh + +test_build: + stage: test + extends: + - .image_gitlab_mpcdf_gcc_openmp + - .rules_scheduled + - .before_script_load_modules + needs: [] + script: + - !reference [.scripts, create_venv] + - !reference [.scripts, build] + - pip install $(echo dist/struphy*.whl) --no-cache-dir --no-binary mpi4py -# check_release_dependencies: -# stage: test -# extends: -# - .image_gitlab_mpcdf_gcc_openmp -# - .before_script_load_modules -# - .rules_mr_to_master -# script: -# - !reference [.scripts, inspect_directory] -# - !reference [.scripts, create_venv] -# - !reference [.scripts, install_all] -# - python src/struphy/utils/set_release_dependencies.py -# - | -# if git diff --exit-code pyproject.toml; then -# echo "pyproject.toml has not changed, dependencies are set correctly!" -# else -# echo "pyproject.toml has changed, dependencies are set incorrectly!" -# echo "Run python src/struphy/utils/set_release_dependencies.py to update pyproject.toml" -# exit 1 -# fi - -# Ubuntu-latest-from-registry: -# stage: test -# needs: [] -# extends: -# - .image_ubuntu_latest -# - .rules_scheduled -# - .parallel_matrix_scheduled -# before_script: -# - !reference [.scripts, inspect_directory] -# - !reference [.scripts, create_venv] -# script: -# - !reference [.scripts, install] -# - !reference [.scripts, compile_matrix] -# - !reference [.scripts, model_tests] +unit_tests_scheduled: + stage: test + extends: + - .image_gitlab_mpcdf_gcc_openmp + - .rules_scheduled + - .parallel_matrix_scheduled + - .before_script_load_modules + script: + - !reference [.scripts, source_env_matrix] + - !reference [.scripts, unit_tests] -# Fedora-latest: -# stage: test -# needs: [] -# extends: -# - .rules_scheduled -# - .parallel_matrix_scheduled -# - .requirements_fedora -# image: fedora:latest -# script: -# - !reference [.scripts, install] -# - !reference [.scripts, compile_matrix] -# - !reference [.scripts, model_tests] +model_tests_scheduled: + stage: test + extends: + - .image_gitlab_mpcdf_gcc_openmp + - .rules_scheduled + - .parallel_matrix_scheduled + - .before_script_load_modules + script: + - !reference [.scripts, source_env_matrix] + - !reference [.scripts, model_tests] -# Fedora-latest-from-registry: -# stage: test -# needs: [] -# extends: -# - .rules_scheduled -# - .parallel_matrix_scheduled -# image: gitlab-registry.mpcdf.mpg.de/struphy/struphy/fedora-latest -# before_script: -# - !reference [.scripts, inspect_directory] -# - !reference [.scripts, create_venv] -# - . /etc/profile.d/modules.sh -# - module load mpi/openmpi-$(arch) -# - module list -# script: -# - !reference [.scripts, install] -# - !reference [.scripts, compile_matrix] -# - !reference [.scripts, model_tests] +check_release_dependencies: + stage: test + extends: + - .image_gitlab_mpcdf_gcc_openmp + - .before_script_load_modules + - .rules_mr_to_master + script: + - !reference [.scripts, inspect_directory] + - !reference [.scripts, create_venv] + - !reference [.scripts, install_all] + - python src/struphy/utils/set_release_dependencies.py + - | + if git diff --exit-code pyproject.toml; then + echo "pyproject.toml has not changed, dependencies are set correctly!" + else + echo "pyproject.toml has changed, dependencies are set incorrectly!" + echo "Run python src/struphy/utils/set_release_dependencies.py to update pyproject.toml" + exit 1 + fi + +Ubuntu-latest-from-registry: + stage: test + needs: [] + extends: + - .image_ubuntu_latest + - .rules_scheduled + - .parallel_matrix_scheduled + before_script: + - !reference [.scripts, inspect_directory] + - !reference [.scripts, create_venv] + script: + - !reference [.scripts, install] + - !reference [.scripts, compile_matrix] + - !reference [.scripts, model_tests] -# Fedora-latest-from-registry-base: -# stage: test -# needs: [] -# extends: -# - .rules_scheduled -# - .parallel_matrix_scheduled -# image: gitlab-registry.mpcdf.mpg.de/struphy/struphy/fedora-latest -# before_script: -# - !reference [.scripts, inspect_directory] -# - !reference [.scripts, create_venv] -# - . /etc/profile.d/modules.sh -# - module load mpi/openmpi-$(arch) -# - module list -# script: -# - !reference [.scripts, install_base] -# - !reference [.scripts, compile_matrix] -# - !reference [.scripts, model_tests] +Fedora-latest: + stage: test + needs: [] + extends: + - .rules_scheduled + - .parallel_matrix_scheduled + - .requirements_fedora + image: fedora:latest + script: + - !reference [.scripts, install] + - !reference [.scripts, compile_matrix] + - !reference [.scripts, model_tests] -# OpenSuse-latest: -# stage: test -# needs: [] -# extends: -# - .rules_scheduled -# - .parallel_matrix_scheduled -# - .requirements_opensuse -# image: opensuse/tumbleweed:latest -# script: -# - !reference [.scripts, install] -# - !reference [.scripts, compile_matrix] -# - !reference [.scripts, model_tests] +Fedora-latest-from-registry: + stage: test + needs: [] + extends: + - .rules_scheduled + - .parallel_matrix_scheduled + image: gitlab-registry.mpcdf.mpg.de/struphy/struphy/fedora-latest + before_script: + - !reference [.scripts, inspect_directory] + - !reference [.scripts, create_venv] + - . /etc/profile.d/modules.sh + - module load mpi/openmpi-$(arch) + - module list + script: + - !reference [.scripts, install] + - !reference [.scripts, compile_matrix] + - !reference [.scripts, model_tests] -# Opensuse-latest-from-registry: -# stage: test -# needs: [] -# extends: -# - .rules_scheduled -# - .parallel_matrix_scheduled -# image: gitlab-registry.mpcdf.mpg.de/struphy/struphy/opensuse-latest -# before_script: -# - !reference [.scripts, inspect_directory] -# - set -x -# - !reference [.scripts, create_venv] -# script: -# - !reference [.scripts, install] -# - !reference [.scripts, compile_matrix] -# - !reference [.scripts, model_tests] +Fedora-latest-from-registry-base: + stage: test + needs: [] + extends: + - .rules_scheduled + - .parallel_matrix_scheduled + image: gitlab-registry.mpcdf.mpg.de/struphy/struphy/fedora-latest + before_script: + - !reference [.scripts, inspect_directory] + - !reference [.scripts, create_venv] + - . /etc/profile.d/modules.sh + - module load mpi/openmpi-$(arch) + - module list + script: + - !reference [.scripts, install_base] + - !reference [.scripts, compile_matrix] + - !reference [.scripts, model_tests] -# Opensuse-latest-from-registry-base: -# stage: test -# needs: [] -# extends: -# - .rules_scheduled -# - .parallel_matrix_scheduled -# image: gitlab-registry.mpcdf.mpg.de/struphy/struphy/opensuse-latest -# before_script: -# - !reference [.scripts, inspect_directory] -# - set -x -# - !reference [.scripts, create_venv] -# script: -# - !reference [.scripts, install_base] -# - !reference [.scripts, compile_matrix] -# - !reference [.scripts, model_tests] +OpenSuse-latest: + stage: test + needs: [] + extends: + - .rules_scheduled + - .parallel_matrix_scheduled + - .requirements_opensuse + image: opensuse/tumbleweed:latest + script: + - !reference [.scripts, install] + - !reference [.scripts, compile_matrix] + - !reference [.scripts, model_tests] -# AlmaLinux-latest: -# stage: test -# needs: [] -# extends: -# - .rules_scheduled -# - .parallel_matrix_scheduled -# - .requirements_almalinux -# image: almalinux:latest -# script: -# - !reference [.scripts, install_no_binary] -# - !reference [.scripts, compile_matrix] -# - !reference [.scripts, model_tests] +Opensuse-latest-from-registry: + stage: test + needs: [] + extends: + - .rules_scheduled + - .parallel_matrix_scheduled + image: gitlab-registry.mpcdf.mpg.de/struphy/struphy/opensuse-latest + before_script: + - !reference [.scripts, inspect_directory] + - set -x + - !reference [.scripts, create_venv] + script: + - !reference [.scripts, install] + - !reference [.scripts, compile_matrix] + - !reference [.scripts, model_tests] -# Almalinux-latest-from-registry: -# stage: test -# needs: [] -# extends: -# - .rules_scheduled -# - .parallel_matrix_scheduled -# image: gitlab-registry.mpcdf.mpg.de/struphy/struphy/almalinux-latest -# before_script: -# - !reference [.scripts, inspect_directory] -# - python3 -m ensurepip --upgrade -# - python3 -m pip install --upgrade pip -# - !reference [.scripts, create_venv] -# script: -# - !reference [.scripts, install_no_binary] -# - !reference [.scripts, compile_matrix] -# - !reference [.scripts, model_tests] +Opensuse-latest-from-registry-base: + stage: test + needs: [] + extends: + - .rules_scheduled + - .parallel_matrix_scheduled + image: gitlab-registry.mpcdf.mpg.de/struphy/struphy/opensuse-latest + before_script: + - !reference [.scripts, inspect_directory] + - set -x + - !reference [.scripts, create_venv] + script: + - !reference [.scripts, install_base] + - !reference [.scripts, compile_matrix] + - !reference [.scripts, model_tests] -# Almalinux-latest-from-registry-base: -# stage: test -# needs: [] -# extends: -# - .rules_scheduled -# - .parallel_matrix_scheduled -# image: gitlab-registry.mpcdf.mpg.de/struphy/struphy/almalinux-latest -# before_script: -# - !reference [.scripts, inspect_directory] -# - python3 -m ensurepip --upgrade -# - python3 -m pip install --upgrade pip -# - !reference [.scripts, create_venv] -# script: -# - !reference [.scripts, install_base_no_binary] -# - !reference [.scripts, compile_matrix] -# - !reference [.scripts, model_tests] - -# ################## -# ### LINT STAGE ### -# ################## - -# # Run in weekly CI pipeline only -# lint_full_repo_report: -# stage: lint -# needs: [] -# extends: -# - .rules_scheduled -# - .image_ubuntu_latest -# script: -# - !reference [.scripts, inspect_directory] -# - !reference [.scripts, create_venv] -# - pip install -e .[dev] # We have to install struphy in editable mode for struphy lint to work -# - !reference [.scripts, inspect_struphy] -# - struphy lint all --output-format report -# allow_failure: true -# artifacts: -# expose_as: 'Branch lint report' -# paths: -# - code_analysis_report.html -# expire_in: 1 month - -# # Lint struphy with `struphy lint` -# lint_repo: -# stage: lint -# needs: [] -# extends: -# - .rules_mr_to_devel -# - .image_ubuntu_latest -# script: -# - !reference [.scripts, inspect_directory] -# - !reference [.scripts, create_venv] -# - pip install -e .[dev] # We have to install struphy in editable mode for struphy lint to work -# - !reference [.scripts, inspect_struphy] -# # Lint all files in current branch, FAIL the CI pipeline if any files are incorrectly formatted -# - struphy lint all --output-format plain --verbose - -# # Lint struphy with `struphy lint` -# lint_branch_report: -# stage: lint -# needs: [] -# extends: -# - .rules_mr_to_devel -# - .image_ubuntu_latest -# script: -# - !reference [.scripts, inspect_directory] -# - !reference [.scripts, create_venv] -# - pip install -e .[dev] # We have to install struphy in editable mode for struphy lint to work -# - !reference [.scripts, inspect_struphy] -# - struphy lint branch --output-format report -# allow_failure: true -# artifacts: -# expose_as: 'Branch lint report' -# paths: -# - code_analysis_report.html -# expire_in: 1 month - -# ################### -# ### PAGES STAGE ### -# ################### -# pages: -# stage: pages -# extends: -# - .image_ubuntu_latest -# - .rules_pages_release -# before_script: -# - !reference [.scripts, inspect_directory] -# - !reference [.scripts, create_venv] -# - apt show pandoc -# - apt show graphviz -# - echo $CI_COMMIT_MESSAGE -# - pip install .[doc] -# script: -# - !reference [.scripts, inspect_struphy] -# - !reference [.scripts, compile] -# - cd doc ; make html -# - mv _build/html/ $CI_PROJECT_DIR/public/ -# artifacts: -# name: 'pages' -# paths: -# - public/ - -# ##################### -# ### RELEASE STAGE ### -# ##################### - -# deploy: -# stage: release -# extends: -# - .rules_pypi_release -# - .image_gitlab_mpcdf_gcc_openmp -# - .before_script_load_modules -# script: -# - !reference [.scripts, create_venv] -# - !reference [.scripts, build] -# - pip install -U twine -# - twine upload dist/* +AlmaLinux-latest: + stage: test + needs: [] + extends: + - .rules_scheduled + - .parallel_matrix_scheduled + - .requirements_almalinux + image: almalinux:latest + script: + - !reference [.scripts, install_no_binary] + - !reference [.scripts, compile_matrix] + - !reference [.scripts, model_tests] -# vars: -# stage: release -# extends: -# - .rules_gitlab_release -# before_script: -# - !reference [.scripts, inspect_directory] -# script: -# - var=$(> vars.env -# artifacts: -# name: 'vars' -# reports: -# dotenv: vars.env -# expire_in: 1 day - -# release_job: -# stage: release -# image: registry.gitlab.com/gitlab-org/release-cli:latest -# extends: -# - .rules_gitlab_release -# needs: ['vars'] -# before_script: -# - !reference [.scripts, inspect_directory] -# script: -# - cat /etc/*-release -# - echo $VERSION -# release: # See https://docs.gitlab.com/ee/ci/yaml/#release for available properties -# tag_name: 'v$VERSION' # The version is incremented per pipeline. -# name: 'v$VERSION' -# ref: '$CI_COMMIT_SHA' # The tag is created from the pipeline SHA. -# description: 'CHANGELOG.md' -# assets: -# links: -# - name: 'Documentation' -# url: 'https://struphy.pages.mpcdf.de/struphy/index.html' -# - name: 'PyPI' -# url: 'https://pypi.org/project/struphy/' +Almalinux-latest-from-registry: + stage: test + needs: [] + extends: + - .rules_scheduled + - .parallel_matrix_scheduled + image: gitlab-registry.mpcdf.mpg.de/struphy/struphy/almalinux-latest + before_script: + - !reference [.scripts, inspect_directory] + - python3 -m ensurepip --upgrade + - python3 -m pip install --upgrade pip + - !reference [.scripts, create_venv] + script: + - !reference [.scripts, install_no_binary] + - !reference [.scripts, compile_matrix] + - !reference [.scripts, model_tests] + +Almalinux-latest-from-registry-base: + stage: test + needs: [] + extends: + - .rules_scheduled + - .parallel_matrix_scheduled + image: gitlab-registry.mpcdf.mpg.de/struphy/struphy/almalinux-latest + before_script: + - !reference [.scripts, inspect_directory] + - python3 -m ensurepip --upgrade + - python3 -m pip install --upgrade pip + - !reference [.scripts, create_venv] + script: + - !reference [.scripts, install_base_no_binary] + - !reference [.scripts, compile_matrix] + - !reference [.scripts, model_tests] + +################## +### LINT STAGE ### +################## + +# Run in weekly CI pipeline only +lint_full_repo_report: + stage: lint + needs: [] + extends: + - .rules_scheduled + - .image_ubuntu_latest + script: + - !reference [.scripts, inspect_directory] + - !reference [.scripts, create_venv] + - pip install -e .[dev] # We have to install struphy in editable mode for struphy lint to work + - !reference [.scripts, inspect_struphy] + - struphy lint all --output-format report + allow_failure: true + artifacts: + expose_as: 'Branch lint report' + paths: + - code_analysis_report.html + expire_in: 1 month + +# Lint struphy with `struphy lint` +lint_repo: + stage: lint + needs: [] + extends: + - .rules_mr_to_devel + - .image_ubuntu_latest + script: + - !reference [.scripts, inspect_directory] + - !reference [.scripts, create_venv] + - pip install -e .[dev] # We have to install struphy in editable mode for struphy lint to work + - !reference [.scripts, inspect_struphy] + # Lint all files in current branch, FAIL the CI pipeline if any files are incorrectly formatted + - struphy lint all --output-format plain --verbose + +# Lint struphy with `struphy lint` +lint_branch_report: + stage: lint + needs: [] + extends: + - .rules_mr_to_devel + - .image_ubuntu_latest + script: + - !reference [.scripts, inspect_directory] + - !reference [.scripts, create_venv] + - pip install -e .[dev] # We have to install struphy in editable mode for struphy lint to work + - !reference [.scripts, inspect_struphy] + - struphy lint branch --output-format report + allow_failure: true + artifacts: + expose_as: 'Branch lint report' + paths: + - code_analysis_report.html + expire_in: 1 month + +################### +### PAGES STAGE ### +################### +pages: + stage: pages + extends: + - .image_ubuntu_latest + - .rules_pages_release + before_script: + - !reference [.scripts, inspect_directory] + - !reference [.scripts, create_venv] + - apt show pandoc + - apt show graphviz + - echo $CI_COMMIT_MESSAGE + - pip install .[doc] + script: + - !reference [.scripts, inspect_struphy] + - !reference [.scripts, compile] + - cd doc ; make html + - mv _build/html/ $CI_PROJECT_DIR/public/ + artifacts: + name: 'pages' + paths: + - public/ + +##################### +### RELEASE STAGE ### +##################### + +deploy: + stage: release + extends: + - .rules_pypi_release + - .image_gitlab_mpcdf_gcc_openmp + - .before_script_load_modules + script: + - !reference [.scripts, create_venv] + - !reference [.scripts, build] + - pip install -U twine + - twine upload dist/* + +vars: + stage: release + extends: + - .rules_gitlab_release + before_script: + - !reference [.scripts, inspect_directory] + script: + - var=$(> vars.env + artifacts: + name: 'vars' + reports: + dotenv: vars.env + expire_in: 1 day + +release_job: + stage: release + image: registry.gitlab.com/gitlab-org/release-cli:latest + extends: + - .rules_gitlab_release + needs: ['vars'] + before_script: + - !reference [.scripts, inspect_directory] + script: + - cat /etc/*-release + - echo $VERSION + release: # See https://docs.gitlab.com/ee/ci/yaml/#release for available properties + tag_name: 'v$VERSION' # The version is incremented per pipeline. + name: 'v$VERSION' + ref: '$CI_COMMIT_SHA' # The tag is created from the pipeline SHA. + description: 'CHANGELOG.md' + assets: + links: + - name: 'Documentation' + url: 'https://struphy.pages.mpcdf.de/struphy/index.html' + - name: 'PyPI' + url: 'https://pypi.org/project/struphy/' From 587ff25241b03b389ea8f41a0b7349941fbfcc09 Mon Sep 17 00:00:00 2001 From: Max Lindqvist Date: Fri, 10 Oct 2025 09:25:57 +0200 Subject: [PATCH 46/76] Bugfix --- src/struphy/arrays.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/struphy/arrays.py b/src/struphy/arrays.py index 61acd33bc..ae2b9ef82 100644 --- a/src/struphy/arrays.py +++ b/src/struphy/arrays.py @@ -30,8 +30,11 @@ def __init__( import numpy as np self._xp = np + + assert isinstance(self.xp, ModuleType) + if verbose: - print(f"Using {xp.__name__} backend.") + print(f"Using {self.xp.__name__} backend.") @property def backend(self) -> BackendType: @@ -39,7 +42,6 @@ def backend(self) -> BackendType: @property def xp(self) -> ModuleType: - assert isinstance(self._xp, ModuleType) return self._xp From 6e8b8519fa6e32efb5e83c7cf04dc68dd9e35e1a Mon Sep 17 00:00:00 2001 From: Max Lindqvist Date: Fri, 10 Oct 2025 09:36:42 +0200 Subject: [PATCH 47/76] Fixed kernel, must import numpy --- src/struphy/feec/mass_kernels.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/struphy/feec/mass_kernels.py b/src/struphy/feec/mass_kernels.py index f31175cf0..22a94f5fd 100644 --- a/src/struphy/feec/mass_kernels.py +++ b/src/struphy/feec/mass_kernels.py @@ -3,6 +3,7 @@ """ from numpy import shape +import numpy as np # ================= 1d ================================= @@ -314,8 +315,6 @@ def kernel_3d_mat( The results are written into data (attention: data is NOT set to zero first, but the results are added to data). """ - from struphy.arrays import xp as np - ne1 = spans1.size ne2 = spans2.size ne3 = spans3.size @@ -575,8 +574,6 @@ def kernel_3d_matrixfree( The results are written into data (attention: data is NOT set to zero first, but the results are added to data). """ - from struphy.arrays import xp as np - ne1 = spansi1.size ne2 = spansi2.size ne3 = spansi3.size @@ -692,8 +689,6 @@ def kernel_3d_diag( The results are written into data (attention: data is NOT set to zero first, but the results are added to data). """ - from struphy.arrays import xp as np - ne1 = spans1.size ne2 = spans2.size ne3 = spans3.size From d63132b016a5ba9b8ffb6117af6c268977da6a62 Mon Sep 17 00:00:00 2001 From: Max Lindqvist Date: Fri, 10 Oct 2025 10:59:00 +0200 Subject: [PATCH 48/76] Fixed docstring --- src/struphy/bsplines/bsplines.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/struphy/bsplines/bsplines.py b/src/struphy/bsplines/bsplines.py index b02e60854..7cbd31400 100644 --- a/src/struphy/bsplines/bsplines.py +++ b/src/struphy/bsplines/bsplines.py @@ -533,7 +533,7 @@ def elements_spans(knots, degree): Examples -------- - >>> from struphy.arrays import xp as np + >>> import numpy as np >>> from psydac.core.bsplines import make_knots, elements_spans >>> p = 3 ; n = 8 From f3f8c78805ede104c5f014a94b8e8e22fdcb5e10 Mon Sep 17 00:00:00 2001 From: Max Lindqvist Date: Fri, 10 Oct 2025 11:13:46 +0200 Subject: [PATCH 49/76] Moved arrays.py to utils/ --- .gitlab-ci.yml | 11 +++++++---- src/struphy/bsplines/bsplines.py | 2 +- .../bsplines/tests/test_bsplines_kernels.py | 2 +- src/struphy/bsplines/tests/test_eval_spline_mpi.py | 2 +- src/struphy/console/profile.py | 2 +- src/struphy/diagnostics/console_diagn.py | 2 +- src/struphy/diagnostics/continuous_spectra.py | 4 ++-- src/struphy/diagnostics/diagn_tools.py | 2 +- src/struphy/diagnostics/paraview/mesh_creator.py | 2 +- src/struphy/dispersion_relations/analytic.py | 2 +- src/struphy/dispersion_relations/base.py | 2 +- src/struphy/dispersion_relations/utilities.py | 2 +- src/struphy/eigenvalue_solvers/derivatives.py | 2 +- .../legacy/MHD_eigenvalues_cylinder_1D.py | 2 +- .../legacy/control_variates/control_variate.py | 2 +- .../fB_massless_control_variate.py | 2 +- .../fnB_massless_control_variate.py | 2 +- .../kinetic_extended/massless_control_variate.py | 2 +- .../eigenvalue_solvers/legacy/emw_operators.py | 2 +- .../eigenvalue_solvers/legacy/inner_products_1d.py | 2 +- .../eigenvalue_solvers/legacy/inner_products_2d.py | 2 +- .../eigenvalue_solvers/legacy/inner_products_3d.py | 2 +- .../eigenvalue_solvers/legacy/l2_error_1d.py | 2 +- .../eigenvalue_solvers/legacy/l2_error_2d.py | 2 +- .../eigenvalue_solvers/legacy/l2_error_3d.py | 2 +- .../legacy/mass_matrices_3d_pre.py | 2 +- .../legacy/massless_operators/fB_arrays.py | 2 +- .../fB_massless_linear_operators.py | 2 +- .../legacy/massless_operators/fB_vv_kernel.py | 2 +- .../eigenvalue_solvers/legacy/mhd_operators_MF.py | 2 +- .../pro_local/mhd_operators_3d_local.py | 2 +- .../projectors_local/pro_local/projectors_local.py | 2 +- .../shape_function_projectors_L2.py | 2 +- .../shape_function_projectors_local.py | 2 +- src/struphy/eigenvalue_solvers/mass_matrices_1d.py | 2 +- src/struphy/eigenvalue_solvers/mass_matrices_2d.py | 2 +- src/struphy/eigenvalue_solvers/mass_matrices_3d.py | 2 +- .../eigenvalue_solvers/mhd_axisymmetric_main.py | 2 +- .../eigenvalue_solvers/mhd_axisymmetric_pproc.py | 2 +- src/struphy/eigenvalue_solvers/mhd_operators.py | 2 +- .../eigenvalue_solvers/mhd_operators_core.py | 2 +- .../eigenvalue_solvers/projectors_global.py | 2 +- src/struphy/eigenvalue_solvers/spline_space.py | 2 +- src/struphy/examples/_draw_parallel.py | 2 +- src/struphy/examples/restelli2018/callables.py | 2 +- src/struphy/feec/basis_projection_ops.py | 2 +- src/struphy/feec/linear_operators.py | 2 +- src/struphy/feec/mass.py | 2 +- src/struphy/feec/mass_kernels.py | 2 +- src/struphy/feec/preconditioner.py | 2 +- src/struphy/feec/projectors.py | 2 +- src/struphy/feec/psydac_derham.py | 2 +- src/struphy/feec/tests/test_basis_ops.py | 6 +++--- src/struphy/feec/tests/test_derham.py | 2 +- src/struphy/feec/tests/test_eval_field.py | 2 +- src/struphy/feec/tests/test_field_init.py | 8 ++++---- src/struphy/feec/tests/test_l2_projectors.py | 2 +- src/struphy/feec/tests/test_local_projectors.py | 2 +- src/struphy/feec/tests/test_lowdim_nel_is_1.py | 2 +- src/struphy/feec/tests/test_mass_matrices.py | 8 ++++---- src/struphy/feec/tests/test_toarray_struphy.py | 2 +- src/struphy/feec/tests/test_tosparse_struphy.py | 2 +- src/struphy/feec/tests/xx_test_preconds.py | 2 +- src/struphy/feec/utilities.py | 2 +- src/struphy/feec/utilities_local_projectors.py | 2 +- src/struphy/feec/variational_utilities.py | 2 +- src/struphy/fields_background/base.py | 2 +- src/struphy/fields_background/coil_fields/base.py | 2 +- .../fields_background/coil_fields/coil_fields.py | 2 +- src/struphy/fields_background/equils.py | 2 +- .../fields_background/tests/test_desc_equil.py | 2 +- .../fields_background/tests/test_generic_equils.py | 2 +- .../fields_background/tests/test_mhd_equils.py | 2 +- .../tests/test_numerical_mhd_equil.py | 2 +- src/struphy/geometry/base.py | 2 +- src/struphy/geometry/domains.py | 2 +- src/struphy/geometry/tests/test_domain.py | 12 ++++++------ src/struphy/geometry/utilities.py | 2 +- src/struphy/initial/eigenfunctions.py | 2 +- src/struphy/initial/perturbations.py | 2 +- .../initial/tests/test_init_perturbations.py | 2 +- src/struphy/initial/utilities.py | 2 +- src/struphy/io/output_handling.py | 2 +- src/struphy/io/setup.py | 2 +- src/struphy/kinetic_background/base.py | 2 +- src/struphy/kinetic_background/maxwellians.py | 2 +- src/struphy/kinetic_background/moment_functions.py | 2 +- src/struphy/kinetic_background/tests/test_base.py | 2 +- .../kinetic_background/tests/test_maxwellians.py | 14 +++++++------- src/struphy/linear_algebra/linalg_kron.py | 2 +- src/struphy/linear_algebra/saddle_point.py | 2 +- .../tests/test_saddlepoint_massmatrices.py | 4 ++-- .../tests/test_stencil_dot_kernels.py | 4 ++-- .../tests/test_stencil_transpose_kernels.py | 4 ++-- src/struphy/main.py | 2 +- src/struphy/models/base.py | 2 +- src/struphy/models/fluid.py | 2 +- src/struphy/models/hybrid.py | 2 +- src/struphy/models/kinetic.py | 2 +- src/struphy/models/tests/verification.py | 2 +- src/struphy/models/toy.py | 2 +- src/struphy/ode/solvers.py | 2 +- src/struphy/ode/tests/test_ode_feec.py | 2 +- src/struphy/ode/utils.py | 2 +- src/struphy/pic/accumulation/particles_to_grid.py | 2 +- src/struphy/pic/base.py | 2 +- src/struphy/pic/particles.py | 2 +- src/struphy/pic/pushing/pusher.py | 2 +- src/struphy/pic/sobol_seq.py | 2 +- src/struphy/pic/tests/test_accum_vec_H1.py | 2 +- src/struphy/pic/tests/test_accumulation.py | 2 +- src/struphy/pic/tests/test_binning.py | 8 ++++---- src/struphy/pic/tests/test_draw_parallel.py | 2 +- src/struphy/pic/tests/test_mat_vec_filler.py | 2 +- .../tests/test_pic_legacy_files/accumulation.py | 2 +- .../pic/tests/test_pic_legacy_files/pusher.py | 2 +- src/struphy/pic/tests/test_pushers.py | 12 ++++++------ src/struphy/pic/tests/test_sorting.py | 2 +- src/struphy/pic/tests/test_sph.py | 2 +- src/struphy/pic/tests/test_tesselation.py | 2 +- src/struphy/pic/utilities.py | 2 +- src/struphy/polar/basic.py | 2 +- src/struphy/polar/extraction_operators.py | 2 +- src/struphy/polar/linear_operators.py | 2 +- .../polar/tests/test_legacy_polar_splines.py | 2 +- src/struphy/polar/tests/test_polar.py | 4 ++-- .../post_processing/likwid/plot_likwidproject.py | 2 +- .../post_processing/likwid/plot_time_traces.py | 2 +- .../post_processing/likwid/roofline_plotter.py | 2 +- src/struphy/post_processing/orbits/orbits_tools.py | 2 +- .../post_processing/post_processing_tools.py | 2 +- src/struphy/post_processing/pproc_struphy.py | 2 +- src/struphy/post_processing/profile_struphy.py | 2 +- src/struphy/profiling/profiling.py | 2 +- src/struphy/propagators/base.py | 2 +- src/struphy/propagators/propagators_coupling.py | 2 +- src/struphy/propagators/propagators_fields.py | 2 +- src/struphy/propagators/propagators_markers.py | 12 ++++++------ .../propagators/tests/test_gyrokinetic_poisson.py | 2 +- src/struphy/propagators/tests/test_poisson.py | 2 +- src/struphy/{ => utils}/arrays.py | 0 src/struphy/utils/clone_config.py | 2 +- src/struphy/{ => utils}/cupy_vs_numpy.py | 0 src/struphy/utils/utils.py | 2 +- 144 files changed, 185 insertions(+), 182 deletions(-) rename src/struphy/{ => utils}/arrays.py (100%) rename src/struphy/{ => utils}/cupy_vs_numpy.py (100%) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c6f5c8171..ea160b849 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -531,13 +531,16 @@ test_cupy: script: - ls - nvidia-smi + # Install cupy - python3 -m pip install --user cupy-cuda12x - python3 -c "import cupy as cp" - - python3 src/struphy/arrays.py - - python3 src/struphy/cupy_vs_numpy.py + # Test numpy backend + - python3 src/struphy/utils/arrays.py + - python3 src/struphy/utils/cupy_vs_numpy.py + # Test cupy backend - export ARRAY_BACKEND=cupy - - python3 src/struphy/arrays.py - - python3 src/struphy/cupy_vs_numpy.py + - python3 src/struphy/utils/arrays.py + - python3 src/struphy/utils/cupy_vs_numpy.py install_tests: stage: test diff --git a/src/struphy/bsplines/bsplines.py b/src/struphy/bsplines/bsplines.py index 7cbd31400..a659e4c61 100644 --- a/src/struphy/bsplines/bsplines.py +++ b/src/struphy/bsplines/bsplines.py @@ -16,7 +16,7 @@ """ -from struphy.arrays import xp as np +from struphy.utils.arrays import xp as np __all__ = [ "find_span", diff --git a/src/struphy/bsplines/tests/test_bsplines_kernels.py b/src/struphy/bsplines/tests/test_bsplines_kernels.py index 387886625..ffa26ee66 100644 --- a/src/struphy/bsplines/tests/test_bsplines_kernels.py +++ b/src/struphy/bsplines/tests/test_bsplines_kernels.py @@ -3,7 +3,7 @@ import pytest from mpi4py import MPI -from struphy.arrays import xp as np +from struphy.utils.arrays import xp as np @pytest.mark.mpi(min_size=2) diff --git a/src/struphy/bsplines/tests/test_eval_spline_mpi.py b/src/struphy/bsplines/tests/test_eval_spline_mpi.py index b582971a4..95cbec8ec 100644 --- a/src/struphy/bsplines/tests/test_eval_spline_mpi.py +++ b/src/struphy/bsplines/tests/test_eval_spline_mpi.py @@ -4,7 +4,7 @@ import pytest from mpi4py import MPI -from struphy.arrays import xp as np +from struphy.utils.arrays import xp as np @pytest.mark.mpi(min_size=2) diff --git a/src/struphy/console/profile.py b/src/struphy/console/profile.py index 4f57320a3..aa6a36d56 100644 --- a/src/struphy/console/profile.py +++ b/src/struphy/console/profile.py @@ -10,8 +10,8 @@ def struphy_profile(dirs, replace, all, n_lines, print_callers, savefig): from matplotlib import pyplot as plt import struphy.utils.utils as utils - from struphy.arrays import xp as np from struphy.post_processing.cprofile_analyser import get_cprofile_data, replace_keys + from struphy.utils.arrays import xp as np # Read struphy state file state = utils.read_state() diff --git a/src/struphy/diagnostics/console_diagn.py b/src/struphy/diagnostics/console_diagn.py index 214f7a0da..35294b37a 100644 --- a/src/struphy/diagnostics/console_diagn.py +++ b/src/struphy/diagnostics/console_diagn.py @@ -10,8 +10,8 @@ import struphy import struphy.utils.utils as utils -from struphy.arrays import xp as np from struphy.diagnostics.diagn_tools import plot_distr_fun, plot_scalars, plots_videos_2d +from struphy.utils.arrays import xp as np def main(): diff --git a/src/struphy/diagnostics/continuous_spectra.py b/src/struphy/diagnostics/continuous_spectra.py index 940f76c86..cbe42dc94 100644 --- a/src/struphy/diagnostics/continuous_spectra.py +++ b/src/struphy/diagnostics/continuous_spectra.py @@ -38,7 +38,7 @@ def get_mhd_continua_2d(space, domain, omega2, U_eig, m_range, omega_A, div_tol, """ import struphy.bsplines.bsplines as bsp - from struphy.arrays import xp as np + from struphy.utils.arrays import xp as np # greville points in radial direction (s) gN_1 = bsp.greville(space.T[0], space.p[0], space.spl_kind[0]) @@ -153,7 +153,7 @@ def get_mhd_continua_2d(space, domain, omega2, U_eig, m_range, omega_A, div_tol, import yaml - from struphy.arrays import xp as np + from struphy.utils.arrays import xp as np # parse arguments parser = argparse.ArgumentParser( diff --git a/src/struphy/diagnostics/diagn_tools.py b/src/struphy/diagnostics/diagn_tools.py index 0811e23e3..8ab8ec36a 100644 --- a/src/struphy/diagnostics/diagn_tools.py +++ b/src/struphy/diagnostics/diagn_tools.py @@ -9,8 +9,8 @@ from scipy.signal import argrelextrema from tqdm import tqdm -from struphy.arrays import xp as np from struphy.dispersion_relations import analytic +from struphy.utils.arrays import xp as np def power_spectrum_2d( diff --git a/src/struphy/diagnostics/paraview/mesh_creator.py b/src/struphy/diagnostics/paraview/mesh_creator.py index 51d002c06..0a8a35903 100644 --- a/src/struphy/diagnostics/paraview/mesh_creator.py +++ b/src/struphy/diagnostics/paraview/mesh_creator.py @@ -4,7 +4,7 @@ from vtkmodules.util.numpy_support import vtk_to_numpy as vtk2np from vtkmodules.vtkCommonDataModel import vtkUnstructuredGrid -from struphy.arrays import xp as np +from struphy.utils.arrays import xp as np def make_ugrid_and_write_vtu(filename: str, writer, vtk_dir, gvec, s_range, u_range, v_range, periodic): diff --git a/src/struphy/dispersion_relations/analytic.py b/src/struphy/dispersion_relations/analytic.py index 97a99ac7e..8a87a65bb 100644 --- a/src/struphy/dispersion_relations/analytic.py +++ b/src/struphy/dispersion_relations/analytic.py @@ -3,10 +3,10 @@ from numpy.polynomial import Polynomial from scipy.optimize import fsolve -from struphy.arrays import xp as np from struphy.dispersion_relations.base import ContinuousSpectra1D, DispersionRelations1D from struphy.dispersion_relations.utilities import Zplasma from struphy.fields_background.equils import set_defaults +from struphy.utils.arrays import xp as np class Maxwell1D(DispersionRelations1D): diff --git a/src/struphy/dispersion_relations/base.py b/src/struphy/dispersion_relations/base.py index eae8f5f57..31a237a90 100644 --- a/src/struphy/dispersion_relations/base.py +++ b/src/struphy/dispersion_relations/base.py @@ -4,7 +4,7 @@ from matplotlib import pyplot as plt -from struphy.arrays import xp as np +from struphy.utils.arrays import xp as np class DispersionRelations1D(metaclass=ABCMeta): diff --git a/src/struphy/dispersion_relations/utilities.py b/src/struphy/dispersion_relations/utilities.py index 66a86ddbb..b0f74fbb4 100644 --- a/src/struphy/dispersion_relations/utilities.py +++ b/src/struphy/dispersion_relations/utilities.py @@ -1,6 +1,6 @@ from scipy.special import erfi -from struphy.arrays import xp as np +from struphy.utils.arrays import xp as np def Zplasma(xi, der=0): diff --git a/src/struphy/eigenvalue_solvers/derivatives.py b/src/struphy/eigenvalue_solvers/derivatives.py index 40e64a0ed..45d8e2d94 100644 --- a/src/struphy/eigenvalue_solvers/derivatives.py +++ b/src/struphy/eigenvalue_solvers/derivatives.py @@ -8,7 +8,7 @@ import scipy.sparse as spa -from struphy.arrays import xp as np +from struphy.utils.arrays import xp as np # ================== 1d incident matrix ======================= diff --git a/src/struphy/eigenvalue_solvers/legacy/MHD_eigenvalues_cylinder_1D.py b/src/struphy/eigenvalue_solvers/legacy/MHD_eigenvalues_cylinder_1D.py index bea3f3cbe..e60d565fb 100644 --- a/src/struphy/eigenvalue_solvers/legacy/MHD_eigenvalues_cylinder_1D.py +++ b/src/struphy/eigenvalue_solvers/legacy/MHD_eigenvalues_cylinder_1D.py @@ -9,7 +9,7 @@ import struphy.eigenvalue_solvers.mass_matrices_1d as mass import struphy.eigenvalue_solvers.projectors_global as pro import struphy.eigenvalue_solvers.spline_space as spl -from struphy.arrays import xp as np +from struphy.utils.arrays import xp as np # numerical solution of the general ideal MHD eigenvalue problem in a cylinder using 1d B-splines in radial direction diff --git a/src/struphy/eigenvalue_solvers/legacy/control_variates/control_variate.py b/src/struphy/eigenvalue_solvers/legacy/control_variates/control_variate.py index ad448fcb2..37940a8d6 100644 --- a/src/struphy/eigenvalue_solvers/legacy/control_variates/control_variate.py +++ b/src/struphy/eigenvalue_solvers/legacy/control_variates/control_variate.py @@ -10,7 +10,7 @@ import struphy.feec.basics.kernels_3d as ker import struphy.feec.control_variates.kernels_control_variate as ker_cv -from struphy.arrays import xp as np +from struphy.utils.arrays import xp as np class terms_control_variate: diff --git a/src/struphy/eigenvalue_solvers/legacy/control_variates/kinetic_extended/fB_massless_control_variate.py b/src/struphy/eigenvalue_solvers/legacy/control_variates/kinetic_extended/fB_massless_control_variate.py index 36889f1bf..e39a463ab 100644 --- a/src/struphy/eigenvalue_solvers/legacy/control_variates/kinetic_extended/fB_massless_control_variate.py +++ b/src/struphy/eigenvalue_solvers/legacy/control_variates/kinetic_extended/fB_massless_control_variate.py @@ -3,7 +3,7 @@ import struphy.feec.basics.kernels_3d as ker import struphy.feec.control_variates.kinetic_extended.fB_massless_kernels_control_variate as ker_cv import struphy.feec.control_variates.kinetic_extended.fnB_massless_cv_kernel_2 as ker_cv2 -from struphy.arrays import xp as np +from struphy.utils.arrays import xp as np def bv_right( diff --git a/src/struphy/eigenvalue_solvers/legacy/control_variates/kinetic_extended/fnB_massless_control_variate.py b/src/struphy/eigenvalue_solvers/legacy/control_variates/kinetic_extended/fnB_massless_control_variate.py index df29e23dc..cb8877c6f 100644 --- a/src/struphy/eigenvalue_solvers/legacy/control_variates/kinetic_extended/fnB_massless_control_variate.py +++ b/src/struphy/eigenvalue_solvers/legacy/control_variates/kinetic_extended/fnB_massless_control_variate.py @@ -2,7 +2,7 @@ import hylife.utilitis_FEEC.control_variates.fnB_massless_kernels_control_variate as ker_cv import scipy.sparse as spa -from struphy.arrays import xp as np +from struphy.utils.arrays import xp as np def bv_pre(tol, n, LO_inv, tensor_space_FEM, p, Nel, idnx, idny, idnz): diff --git a/src/struphy/eigenvalue_solvers/legacy/control_variates/kinetic_extended/massless_control_variate.py b/src/struphy/eigenvalue_solvers/legacy/control_variates/kinetic_extended/massless_control_variate.py index f5d75b9cf..1ea567314 100644 --- a/src/struphy/eigenvalue_solvers/legacy/control_variates/kinetic_extended/massless_control_variate.py +++ b/src/struphy/eigenvalue_solvers/legacy/control_variates/kinetic_extended/massless_control_variate.py @@ -2,7 +2,7 @@ import hylife.utilitis_FEEC.control_variates.massless_kernels_control_variate as ker_cv import scipy.sparse as spa -from struphy.arrays import xp as np +from struphy.utils.arrays import xp as np def bv_pre(u, uvalue, tensor_space_FEM, p, Nel, idnx, idny, idnz): diff --git a/src/struphy/eigenvalue_solvers/legacy/emw_operators.py b/src/struphy/eigenvalue_solvers/legacy/emw_operators.py index 0d7237036..3187ac649 100755 --- a/src/struphy/eigenvalue_solvers/legacy/emw_operators.py +++ b/src/struphy/eigenvalue_solvers/legacy/emw_operators.py @@ -10,7 +10,7 @@ import struphy.eigenvalue_solvers.kernels_3d as ker import struphy.eigenvalue_solvers.legacy.mass_matrices_3d_pre as mass_3d_pre -from struphy.arrays import xp as np +from struphy.utils.arrays import xp as np class EMW_operators: diff --git a/src/struphy/eigenvalue_solvers/legacy/inner_products_1d.py b/src/struphy/eigenvalue_solvers/legacy/inner_products_1d.py index 84fd96b12..5cae935fb 100644 --- a/src/struphy/eigenvalue_solvers/legacy/inner_products_1d.py +++ b/src/struphy/eigenvalue_solvers/legacy/inner_products_1d.py @@ -8,7 +8,7 @@ import scipy.sparse as spa -from struphy.arrays import xp as np +from struphy.utils.arrays import xp as np # ======= inner product in V0 ==================== diff --git a/src/struphy/eigenvalue_solvers/legacy/inner_products_2d.py b/src/struphy/eigenvalue_solvers/legacy/inner_products_2d.py index 16ffb76c2..fd7ecabd4 100644 --- a/src/struphy/eigenvalue_solvers/legacy/inner_products_2d.py +++ b/src/struphy/eigenvalue_solvers/legacy/inner_products_2d.py @@ -9,7 +9,7 @@ import scipy.sparse as spa import struphy.eigenvalue_solvers.kernels_2d as ker -from struphy.arrays import xp as np +from struphy.utils.arrays import xp as np # ================ inner product in V0 =========================== diff --git a/src/struphy/eigenvalue_solvers/legacy/inner_products_3d.py b/src/struphy/eigenvalue_solvers/legacy/inner_products_3d.py index 985fbe4bc..5aa9f710a 100644 --- a/src/struphy/eigenvalue_solvers/legacy/inner_products_3d.py +++ b/src/struphy/eigenvalue_solvers/legacy/inner_products_3d.py @@ -9,7 +9,7 @@ import scipy.sparse as spa import struphy.eigenvalue_solvers.kernels_3d as ker -from struphy.arrays import xp as np +from struphy.utils.arrays import xp as np # ================ inner product in V0 =========================== diff --git a/src/struphy/eigenvalue_solvers/legacy/l2_error_1d.py b/src/struphy/eigenvalue_solvers/legacy/l2_error_1d.py index 82b13a974..f8544c1cf 100644 --- a/src/struphy/eigenvalue_solvers/legacy/l2_error_1d.py +++ b/src/struphy/eigenvalue_solvers/legacy/l2_error_1d.py @@ -8,7 +8,7 @@ import scipy.sparse as spa -from struphy.arrays import xp as np +from struphy.utils.arrays import xp as np # ======= error in V0 ==================== diff --git a/src/struphy/eigenvalue_solvers/legacy/l2_error_2d.py b/src/struphy/eigenvalue_solvers/legacy/l2_error_2d.py index 9a8cf24e6..818d0d7c2 100644 --- a/src/struphy/eigenvalue_solvers/legacy/l2_error_2d.py +++ b/src/struphy/eigenvalue_solvers/legacy/l2_error_2d.py @@ -9,7 +9,7 @@ import scipy.sparse as spa import struphy.eigenvalue_solvers.kernels_2d as ker -from struphy.arrays import xp as np +from struphy.utils.arrays import xp as np # ======= error in V0 ==================== diff --git a/src/struphy/eigenvalue_solvers/legacy/l2_error_3d.py b/src/struphy/eigenvalue_solvers/legacy/l2_error_3d.py index 44b19e90d..39eac0b66 100644 --- a/src/struphy/eigenvalue_solvers/legacy/l2_error_3d.py +++ b/src/struphy/eigenvalue_solvers/legacy/l2_error_3d.py @@ -9,7 +9,7 @@ import scipy.sparse as spa import struphy.eigenvalue_solvers.kernels_3d as ker -from struphy.arrays import xp as np +from struphy.utils.arrays import xp as np # ======= error in V0 ==================== diff --git a/src/struphy/eigenvalue_solvers/legacy/mass_matrices_3d_pre.py b/src/struphy/eigenvalue_solvers/legacy/mass_matrices_3d_pre.py index c1d4b242d..673069c0e 100644 --- a/src/struphy/eigenvalue_solvers/legacy/mass_matrices_3d_pre.py +++ b/src/struphy/eigenvalue_solvers/legacy/mass_matrices_3d_pre.py @@ -10,7 +10,7 @@ import struphy.eigenvalue_solvers.spline_space as spl import struphy.linear_algebra.linalg_kron as linkron -from struphy.arrays import xp as np +from struphy.utils.arrays import xp as np # ================ inverse mass matrix in V0 =========================== diff --git a/src/struphy/eigenvalue_solvers/legacy/massless_operators/fB_arrays.py b/src/struphy/eigenvalue_solvers/legacy/massless_operators/fB_arrays.py index e3dce71d9..784ea8e0b 100644 --- a/src/struphy/eigenvalue_solvers/legacy/massless_operators/fB_arrays.py +++ b/src/struphy/eigenvalue_solvers/legacy/massless_operators/fB_arrays.py @@ -7,7 +7,7 @@ import struphy.geometry.mappings_3d as mapping3d import struphy.geometry.mappings_3d_fast as mapping_fast import struphy.linear_algebra.linalg_kernels as linalg -from struphy.arrays import xp as np +from struphy.utils.arrays import xp as np class Temp_arrays: diff --git a/src/struphy/eigenvalue_solvers/legacy/massless_operators/fB_massless_linear_operators.py b/src/struphy/eigenvalue_solvers/legacy/massless_operators/fB_massless_linear_operators.py index af195fcdd..843952a7b 100644 --- a/src/struphy/eigenvalue_solvers/legacy/massless_operators/fB_massless_linear_operators.py +++ b/src/struphy/eigenvalue_solvers/legacy/massless_operators/fB_massless_linear_operators.py @@ -5,7 +5,7 @@ import struphy.feec.massless_operators.fB_bb_kernel as bb_kernel import struphy.feec.massless_operators.fB_bv_kernel as bv_kernel import struphy.feec.massless_operators.fB_vv_kernel as vv_kernel -from struphy.arrays import xp as np +from struphy.utils.arrays import xp as np class Massless_linear_operators: diff --git a/src/struphy/eigenvalue_solvers/legacy/massless_operators/fB_vv_kernel.py b/src/struphy/eigenvalue_solvers/legacy/massless_operators/fB_vv_kernel.py index 8850b4107..216103640 100644 --- a/src/struphy/eigenvalue_solvers/legacy/massless_operators/fB_vv_kernel.py +++ b/src/struphy/eigenvalue_solvers/legacy/massless_operators/fB_vv_kernel.py @@ -3,7 +3,7 @@ import struphy.bsplines.bsplines_kernels as bsp import struphy.geometry.mappings_kernels as mapping_fast import struphy.linear_algebra.linalg_kernels as linalg -from struphy.arrays import xp as np +from struphy.utils.arrays import xp as np # ========================================================================================== diff --git a/src/struphy/eigenvalue_solvers/legacy/mhd_operators_MF.py b/src/struphy/eigenvalue_solvers/legacy/mhd_operators_MF.py index bd343c2b4..9591fe06b 100644 --- a/src/struphy/eigenvalue_solvers/legacy/mhd_operators_MF.py +++ b/src/struphy/eigenvalue_solvers/legacy/mhd_operators_MF.py @@ -1,9 +1,9 @@ import scipy.sparse as spa -from struphy.arrays import xp as np from struphy.eigenvalue_solvers.projectors_global import Projectors_tensor_3d from struphy.eigenvalue_solvers.spline_space import Tensor_spline_space from struphy.linear_algebra.linalg_kron import kron_matvec_3d, kron_solve_3d +from struphy.utils.arrays import xp as np # ================================================================================================= diff --git a/src/struphy/eigenvalue_solvers/legacy/projectors_local/pro_local/mhd_operators_3d_local.py b/src/struphy/eigenvalue_solvers/legacy/projectors_local/pro_local/mhd_operators_3d_local.py index 61e9bbd8e..bd840b3f0 100644 --- a/src/struphy/eigenvalue_solvers/legacy/projectors_local/pro_local/mhd_operators_3d_local.py +++ b/src/struphy/eigenvalue_solvers/legacy/projectors_local/pro_local/mhd_operators_3d_local.py @@ -14,7 +14,7 @@ import struphy.feec.basics.kernels_3d as ker_loc_3d import struphy.feec.bsplines as bsp import struphy.feec.projectors.pro_local.kernels_projectors_local_mhd as ker_loc -from struphy.arrays import xp as np +from struphy.utils.arrays import xp as np class projectors_local_mhd: diff --git a/src/struphy/eigenvalue_solvers/legacy/projectors_local/pro_local/projectors_local.py b/src/struphy/eigenvalue_solvers/legacy/projectors_local/pro_local/projectors_local.py index d465b28c2..72c5babfd 100644 --- a/src/struphy/eigenvalue_solvers/legacy/projectors_local/pro_local/projectors_local.py +++ b/src/struphy/eigenvalue_solvers/legacy/projectors_local/pro_local/projectors_local.py @@ -10,7 +10,7 @@ import struphy.feec.bsplines as bsp import struphy.feec.projectors.pro_local.kernels_projectors_local as ker_loc -from struphy.arrays import xp as np +from struphy.utils.arrays import xp as np # ======================= 1d ==================================== diff --git a/src/struphy/eigenvalue_solvers/legacy/projectors_local/shape_pro_local/shape_function_projectors_L2.py b/src/struphy/eigenvalue_solvers/legacy/projectors_local/shape_pro_local/shape_function_projectors_L2.py index 8a132ed61..44ec28cc0 100644 --- a/src/struphy/eigenvalue_solvers/legacy/projectors_local/shape_pro_local/shape_function_projectors_L2.py +++ b/src/struphy/eigenvalue_solvers/legacy/projectors_local/shape_pro_local/shape_function_projectors_L2.py @@ -10,7 +10,7 @@ import struphy.feec.bsplines as bsp import struphy.feec.projectors.shape_pro_local.shape_L2_projector_kernel as ker_loc -from struphy.arrays import xp as np +from struphy.utils.arrays import xp as np # ======================= 3d ==================================== diff --git a/src/struphy/eigenvalue_solvers/legacy/projectors_local/shape_pro_local/shape_function_projectors_local.py b/src/struphy/eigenvalue_solvers/legacy/projectors_local/shape_pro_local/shape_function_projectors_local.py index cfad48c0e..d75f5f871 100644 --- a/src/struphy/eigenvalue_solvers/legacy/projectors_local/shape_pro_local/shape_function_projectors_local.py +++ b/src/struphy/eigenvalue_solvers/legacy/projectors_local/shape_pro_local/shape_function_projectors_local.py @@ -10,7 +10,7 @@ import struphy.feec.bsplines as bsp import struphy.feec.projectors.shape_pro_local.shape_local_projector_kernel as ker_loc -from struphy.arrays import xp as np +from struphy.utils.arrays import xp as np # ======================= 3d ==================================== diff --git a/src/struphy/eigenvalue_solvers/mass_matrices_1d.py b/src/struphy/eigenvalue_solvers/mass_matrices_1d.py index bdd2c897d..99316215d 100644 --- a/src/struphy/eigenvalue_solvers/mass_matrices_1d.py +++ b/src/struphy/eigenvalue_solvers/mass_matrices_1d.py @@ -5,7 +5,7 @@ import scipy.sparse as spa import struphy.bsplines.bsplines as bsp -from struphy.arrays import xp as np +from struphy.utils.arrays import xp as np # ======= mass matrices in 1D ==================== diff --git a/src/struphy/eigenvalue_solvers/mass_matrices_2d.py b/src/struphy/eigenvalue_solvers/mass_matrices_2d.py index fc905296f..e19b31ac6 100644 --- a/src/struphy/eigenvalue_solvers/mass_matrices_2d.py +++ b/src/struphy/eigenvalue_solvers/mass_matrices_2d.py @@ -5,7 +5,7 @@ import scipy.sparse as spa import struphy.eigenvalue_solvers.kernels_2d as ker -from struphy.arrays import xp as np +from struphy.utils.arrays import xp as np # ================ mass matrix in V0 =========================== diff --git a/src/struphy/eigenvalue_solvers/mass_matrices_3d.py b/src/struphy/eigenvalue_solvers/mass_matrices_3d.py index f3fb627be..ef6ee1e0c 100644 --- a/src/struphy/eigenvalue_solvers/mass_matrices_3d.py +++ b/src/struphy/eigenvalue_solvers/mass_matrices_3d.py @@ -5,7 +5,7 @@ import scipy.sparse as spa import struphy.eigenvalue_solvers.kernels_3d as ker -from struphy.arrays import xp as np +from struphy.utils.arrays import xp as np # ================ mass matrix in V0 =========================== diff --git a/src/struphy/eigenvalue_solvers/mhd_axisymmetric_main.py b/src/struphy/eigenvalue_solvers/mhd_axisymmetric_main.py index b1c3f92a8..009190582 100644 --- a/src/struphy/eigenvalue_solvers/mhd_axisymmetric_main.py +++ b/src/struphy/eigenvalue_solvers/mhd_axisymmetric_main.py @@ -34,9 +34,9 @@ def solve_mhd_ev_problem_2d(num_params, eq_mhd, n_tor, basis_tor="i", path_out=N import scipy.sparse as spa - from struphy.arrays import xp as np from struphy.eigenvalue_solvers.mhd_operators import MHDOperators from struphy.eigenvalue_solvers.spline_space import Spline_space_1d, Tensor_spline_space + from struphy.utils.arrays import xp as np print("\nStart of eigenspectrum calculation for toroidal mode number", n_tor) print("") diff --git a/src/struphy/eigenvalue_solvers/mhd_axisymmetric_pproc.py b/src/struphy/eigenvalue_solvers/mhd_axisymmetric_pproc.py index fe5d9b87b..dc6e53ddd 100644 --- a/src/struphy/eigenvalue_solvers/mhd_axisymmetric_pproc.py +++ b/src/struphy/eigenvalue_solvers/mhd_axisymmetric_pproc.py @@ -5,7 +5,7 @@ def main(): import yaml - from struphy.arrays import xp as np + from struphy.utils.arrays import xp as np # parse arguments parser = argparse.ArgumentParser(description="Restrict a full .npy eigenspectrum to a range of eigenfrequencies.") diff --git a/src/struphy/eigenvalue_solvers/mhd_operators.py b/src/struphy/eigenvalue_solvers/mhd_operators.py index 2bbc619f4..b2cb669ae 100644 --- a/src/struphy/eigenvalue_solvers/mhd_operators.py +++ b/src/struphy/eigenvalue_solvers/mhd_operators.py @@ -6,8 +6,8 @@ import scipy.sparse as spa import struphy.eigenvalue_solvers.legacy.mass_matrices_3d_pre as mass_3d_pre -from struphy.arrays import xp as np from struphy.eigenvalue_solvers.mhd_operators_core import MHDOperatorsCore +from struphy.utils.arrays import xp as np class MHDOperators: diff --git a/src/struphy/eigenvalue_solvers/mhd_operators_core.py b/src/struphy/eigenvalue_solvers/mhd_operators_core.py index fe909586b..528ec2b78 100644 --- a/src/struphy/eigenvalue_solvers/mhd_operators_core.py +++ b/src/struphy/eigenvalue_solvers/mhd_operators_core.py @@ -8,7 +8,7 @@ import struphy.eigenvalue_solvers.kernels_projectors_global_mhd as ker import struphy.eigenvalue_solvers.mass_matrices_2d as mass_2d import struphy.eigenvalue_solvers.mass_matrices_3d as mass_3d -from struphy.arrays import xp as np +from struphy.utils.arrays import xp as np class MHDOperatorsCore: diff --git a/src/struphy/eigenvalue_solvers/projectors_global.py b/src/struphy/eigenvalue_solvers/projectors_global.py index 02c67a67e..208ff701a 100644 --- a/src/struphy/eigenvalue_solvers/projectors_global.py +++ b/src/struphy/eigenvalue_solvers/projectors_global.py @@ -9,8 +9,8 @@ import scipy.sparse as spa import struphy.bsplines.bsplines as bsp -from struphy.arrays import xp as np from struphy.linear_algebra.linalg_kron import kron_lusolve_2d, kron_lusolve_3d, kron_matvec_2d, kron_matvec_3d +from struphy.utils.arrays import xp as np # ======================= 1d ==================================== diff --git a/src/struphy/eigenvalue_solvers/spline_space.py b/src/struphy/eigenvalue_solvers/spline_space.py index d41ea4191..cffc1902d 100644 --- a/src/struphy/eigenvalue_solvers/spline_space.py +++ b/src/struphy/eigenvalue_solvers/spline_space.py @@ -9,7 +9,7 @@ import matplotlib import scipy.sparse as spa -from struphy.arrays import xp as np +from struphy.utils.arrays import xp as np matplotlib.rcParams.update({"font.size": 16}) import matplotlib.pyplot as plt diff --git a/src/struphy/examples/_draw_parallel.py b/src/struphy/examples/_draw_parallel.py index 1ae8938ca..95881b912 100644 --- a/src/struphy/examples/_draw_parallel.py +++ b/src/struphy/examples/_draw_parallel.py @@ -1,9 +1,9 @@ from mpi4py import MPI -from struphy.arrays import xp as np from struphy.feec.psydac_derham import Derham from struphy.geometry import domains from struphy.pic.particles import Particles6D +from struphy.utils.arrays import xp as np def main(): diff --git a/src/struphy/examples/restelli2018/callables.py b/src/struphy/examples/restelli2018/callables.py index 4f9dddb0e..4a4b3d5c5 100644 --- a/src/struphy/examples/restelli2018/callables.py +++ b/src/struphy/examples/restelli2018/callables.py @@ -1,6 +1,6 @@ "Analytical callables needed for the simulation of the Two-Fluid Quasi-Neutral Model by Restelli." -from struphy.arrays import xp as np +from struphy.utils.arrays import xp as np class RestelliForcingTerm: diff --git a/src/struphy/feec/basis_projection_ops.py b/src/struphy/feec/basis_projection_ops.py index 847436971..280ed3f29 100644 --- a/src/struphy/feec/basis_projection_ops.py +++ b/src/struphy/feec/basis_projection_ops.py @@ -6,7 +6,6 @@ from psydac.linalg.block import BlockLinearOperator, BlockVector, BlockVectorSpace from psydac.linalg.stencil import StencilMatrix, StencilVector, StencilVectorSpace -from struphy.arrays import xp as np from struphy.feec import basis_projection_kernels from struphy.feec.linear_operators import BoundaryOperator, LinOpWithTransp from struphy.feec.local_projectors_kernels import assemble_basis_projection_operator_local @@ -15,6 +14,7 @@ from struphy.feec.utilities import RotationMatrix from struphy.polar.basic import PolarDerhamSpace, PolarVector from struphy.polar.linear_operators import PolarExtractionOperator +from struphy.utils.arrays import xp as np class BasisProjectionOperators: diff --git a/src/struphy/feec/linear_operators.py b/src/struphy/feec/linear_operators.py index bb676d0a5..524152503 100644 --- a/src/struphy/feec/linear_operators.py +++ b/src/struphy/feec/linear_operators.py @@ -7,9 +7,9 @@ from psydac.linalg.stencil import StencilVectorSpace from scipy import sparse -from struphy.arrays import xp as np from struphy.feec.utilities import apply_essential_bc_to_array from struphy.polar.basic import PolarDerhamSpace +from struphy.utils.arrays import xp as np class LinOpWithTransp(LinearOperator): diff --git a/src/struphy/feec/mass.py b/src/struphy/feec/mass.py index f7f59c3a0..8d4b00842 100644 --- a/src/struphy/feec/mass.py +++ b/src/struphy/feec/mass.py @@ -8,13 +8,13 @@ from psydac.linalg.block import BlockLinearOperator, BlockVector from psydac.linalg.stencil import StencilDiagonalMatrix, StencilMatrix, StencilVector -from struphy.arrays import xp as np from struphy.feec import mass_kernels from struphy.feec.linear_operators import BoundaryOperator, LinOpWithTransp from struphy.feec.psydac_derham import Derham from struphy.feec.utilities import RotationMatrix from struphy.geometry.base import Domain from struphy.polar.linear_operators import PolarExtractionOperator +from struphy.utils.arrays import xp as np class WeightedMassOperators: diff --git a/src/struphy/feec/mass_kernels.py b/src/struphy/feec/mass_kernels.py index 22a94f5fd..7e62b3248 100644 --- a/src/struphy/feec/mass_kernels.py +++ b/src/struphy/feec/mass_kernels.py @@ -2,8 +2,8 @@ Integral kernels for mass matrices and L2-projections. """ -from numpy import shape import numpy as np +from numpy import shape # ================= 1d ================================= diff --git a/src/struphy/feec/preconditioner.py b/src/struphy/feec/preconditioner.py index 4ea453a6a..b3a8744eb 100644 --- a/src/struphy/feec/preconditioner.py +++ b/src/struphy/feec/preconditioner.py @@ -9,9 +9,9 @@ from scipy import sparse from scipy.linalg import solve_circulant -from struphy.arrays import xp as np from struphy.feec.linear_operators import BoundaryOperator from struphy.feec.mass import WeightedMassOperator +from struphy.utils.arrays import xp as np class MassMatrixPreconditioner(LinearOperator): diff --git a/src/struphy/feec/projectors.py b/src/struphy/feec/projectors.py index 429e21ff8..1adae832f 100644 --- a/src/struphy/feec/projectors.py +++ b/src/struphy/feec/projectors.py @@ -10,7 +10,6 @@ from psydac.linalg.solvers import inverse from psydac.linalg.stencil import StencilMatrix, StencilVector -from struphy.arrays import xp as np from struphy.feec import mass_kernels from struphy.feec.local_projectors_kernels import ( compute_shifts, @@ -38,6 +37,7 @@ from struphy.kernel_arguments.local_projectors_args_kernels import LocalProjectorsArguments from struphy.polar.basic import PolarVector from struphy.polar.linear_operators import PolarExtractionOperator +from struphy.utils.arrays import xp as np class CommutingProjector: diff --git a/src/struphy/feec/psydac_derham.py b/src/struphy/feec/psydac_derham.py index 6531b3051..b1995f4f6 100644 --- a/src/struphy/feec/psydac_derham.py +++ b/src/struphy/feec/psydac_derham.py @@ -16,7 +16,6 @@ from psydac.linalg.block import BlockVector, BlockVectorSpace from psydac.linalg.stencil import StencilVector, StencilVectorSpace -from struphy.arrays import xp as np from struphy.bsplines import evaluation_kernels_3d as eval_3d from struphy.bsplines.evaluation_kernels_3d import eval_spline_mpi_tensor_product_fixed from struphy.feec.linear_operators import BoundaryOperator @@ -31,6 +30,7 @@ from struphy.polar.basic import PolarDerhamSpace, PolarVector from struphy.polar.extraction_operators import PolarExtractionBlocksC1 from struphy.polar.linear_operators import PolarExtractionOperator, PolarLinearOperator +from struphy.utils.arrays import xp as np class Derham: diff --git a/src/struphy/feec/tests/test_basis_ops.py b/src/struphy/feec/tests/test_basis_ops.py index d93319a1c..afc88b44d 100644 --- a/src/struphy/feec/tests/test_basis_ops.py +++ b/src/struphy/feec/tests/test_basis_ops.py @@ -18,13 +18,13 @@ def test_some_basis_ops(Nel, p, spl_kind, mapping): from psydac.linalg.block import BlockVector from psydac.linalg.stencil import StencilVector - from struphy.arrays import xp as np from struphy.eigenvalue_solvers.legacy.mhd_operators_MF import projectors_dot_x from struphy.eigenvalue_solvers.spline_space import Spline_space_1d, Tensor_spline_space from struphy.feec.basis_projection_ops import BasisProjectionOperators from struphy.feec.psydac_derham import Derham from struphy.fields_background.equils import HomogenSlab from struphy.geometry import domains + from struphy.utils.arrays import xp as np # mpi communicator MPI_COMM = MPI.COMM_WORLD @@ -467,7 +467,6 @@ def test_some_basis_ops(Nel, p, spl_kind, mapping): def test_basis_ops_polar(Nel, p, spl_kind, dirichlet_bc, mapping, show_plots=False): from mpi4py import MPI - from struphy.arrays import xp as np from struphy.eigenvalue_solvers.mhd_operators import MHDOperators from struphy.eigenvalue_solvers.spline_space import Spline_space_1d, Tensor_spline_space from struphy.feec.basis_projection_ops import BasisProjectionOperators @@ -476,6 +475,7 @@ def test_basis_ops_polar(Nel, p, spl_kind, dirichlet_bc, mapping, show_plots=Fal from struphy.fields_background.equils import ScrewPinch from struphy.geometry import domains from struphy.polar.basic import PolarVector + from struphy.utils.arrays import xp as np mpi_comm = MPI.COMM_WORLD mpi_rank = mpi_comm.Get_rank() @@ -725,7 +725,7 @@ def assert_ops(mpi_rank, res_PSY, res_STR, verbose=False, MPI_COMM=None): TODO """ - from struphy.arrays import xp as np + from struphy.utils.arrays import xp as np if verbose: if MPI_COMM is not None: diff --git a/src/struphy/feec/tests/test_derham.py b/src/struphy/feec/tests/test_derham.py index ee44f64f0..8aa2bfff5 100644 --- a/src/struphy/feec/tests/test_derham.py +++ b/src/struphy/feec/tests/test_derham.py @@ -12,10 +12,10 @@ def test_psydac_derham(Nel, p, spl_kind): from psydac.linalg.block import BlockVector from psydac.linalg.stencil import StencilVector - from struphy.arrays import xp as np from struphy.eigenvalue_solvers.spline_space import Spline_space_1d, Tensor_spline_space from struphy.feec.psydac_derham import Derham from struphy.feec.utilities import compare_arrays + from struphy.utils.arrays import xp as np comm = MPI.COMM_WORLD assert comm.size >= 2 diff --git a/src/struphy/feec/tests/test_eval_field.py b/src/struphy/feec/tests/test_eval_field.py index f14f72f6b..1cfa93d5e 100644 --- a/src/struphy/feec/tests/test_eval_field.py +++ b/src/struphy/feec/tests/test_eval_field.py @@ -1,7 +1,7 @@ import pytest from mpi4py import MPI -from struphy.arrays import xp as np +from struphy.utils.arrays import xp as np @pytest.mark.mpi(min_size=2) diff --git a/src/struphy/feec/tests/test_field_init.py b/src/struphy/feec/tests/test_field_init.py index 434a754fe..f24231de6 100644 --- a/src/struphy/feec/tests/test_field_init.py +++ b/src/struphy/feec/tests/test_field_init.py @@ -12,8 +12,8 @@ def test_bckgr_init_const(Nel, p, spl_kind, spaces, vec_comps): from mpi4py import MPI - from struphy.arrays import xp as np from struphy.feec.psydac_derham import Derham + from struphy.utils.arrays import xp as np comm = MPI.COMM_WORLD rank = comm.Get_rank() @@ -68,11 +68,11 @@ def test_bckgr_init_mhd(Nel, p, spl_kind, with_desc=False, with_gvec=False, show from matplotlib import pyplot as plt from mpi4py import MPI - from struphy.arrays import xp as np from struphy.feec.psydac_derham import Derham from struphy.fields_background import equils from struphy.fields_background.base import FluidEquilibriumWithB from struphy.geometry import domains + from struphy.utils.arrays import xp as np comm = MPI.COMM_WORLD rank = comm.Get_rank() @@ -1090,9 +1090,9 @@ def test_sincos_init_const(Nel, p, spl_kind, show_plot=False): from matplotlib import pyplot as plt from mpi4py import MPI - from struphy.arrays import xp as np from struphy.feec.psydac_derham import Derham from struphy.initial.perturbations import ModesCos, ModesSin + from struphy.utils.arrays import xp as np comm = MPI.COMM_WORLD rank = comm.Get_rank() @@ -1323,9 +1323,9 @@ def test_noise_init(Nel, p, spl_kind, space, direction): from mpi4py import MPI - from struphy.arrays import xp as np from struphy.feec.psydac_derham import Derham from struphy.feec.utilities import compare_arrays + from struphy.utils.arrays import xp as np comm = MPI.COMM_WORLD rank = comm.Get_rank() diff --git a/src/struphy/feec/tests/test_l2_projectors.py b/src/struphy/feec/tests/test_l2_projectors.py index 610a16ef8..a38e27aa7 100644 --- a/src/struphy/feec/tests/test_l2_projectors.py +++ b/src/struphy/feec/tests/test_l2_projectors.py @@ -4,11 +4,11 @@ import pytest from mpi4py import MPI -from struphy.arrays import xp as np from struphy.feec.mass import WeightedMassOperators from struphy.feec.projectors import L2Projector from struphy.feec.psydac_derham import Derham from struphy.geometry import domains +from struphy.utils.arrays import xp as np @pytest.mark.mpi(min_size=2) diff --git a/src/struphy/feec/tests/test_local_projectors.py b/src/struphy/feec/tests/test_local_projectors.py index ff81d522c..b000194a2 100644 --- a/src/struphy/feec/tests/test_local_projectors.py +++ b/src/struphy/feec/tests/test_local_projectors.py @@ -5,13 +5,13 @@ import pytest from mpi4py import MPI -from struphy.arrays import xp as np from struphy.bsplines.bsplines import basis_funs, find_span from struphy.bsplines.evaluation_kernels_1d import evaluation_kernel_1d from struphy.feec.basis_projection_ops import BasisProjectionOperator, BasisProjectionOperatorLocal from struphy.feec.local_projectors_kernels import fill_matrix_column from struphy.feec.psydac_derham import Derham from struphy.feec.utilities_local_projectors import get_one_spline, get_span_and_basis, get_values_and_indices_splines +from struphy.utils.arrays import xp as np def get_span_and_basis(pts, space): diff --git a/src/struphy/feec/tests/test_lowdim_nel_is_1.py b/src/struphy/feec/tests/test_lowdim_nel_is_1.py index 8ff3e6b06..78f76ff02 100644 --- a/src/struphy/feec/tests/test_lowdim_nel_is_1.py +++ b/src/struphy/feec/tests/test_lowdim_nel_is_1.py @@ -13,8 +13,8 @@ def test_lowdim_derham(Nel, p, spl_kind, do_plot=False): from psydac.linalg.block import BlockVector from psydac.linalg.stencil import StencilVector - from struphy.arrays import xp as np from struphy.feec.psydac_derham import Derham + from struphy.utils.arrays import xp as np comm = MPI.COMM_WORLD assert comm.size >= 2 diff --git a/src/struphy/feec/tests/test_mass_matrices.py b/src/struphy/feec/tests/test_mass_matrices.py index efcb86cda..4fde81f3a 100644 --- a/src/struphy/feec/tests/test_mass_matrices.py +++ b/src/struphy/feec/tests/test_mass_matrices.py @@ -15,7 +15,6 @@ def test_mass(Nel, p, spl_kind, dirichlet_bc, mapping, show_plots=False): from mpi4py import MPI - from struphy.arrays import xp as np from struphy.eigenvalue_solvers.mhd_operators import MHDOperators from struphy.eigenvalue_solvers.spline_space import Spline_space_1d, Tensor_spline_space from struphy.feec.mass import WeightedMassOperators, WeightedMassOperatorsOldForTesting @@ -23,6 +22,7 @@ def test_mass(Nel, p, spl_kind, dirichlet_bc, mapping, show_plots=False): from struphy.feec.utilities import RotationMatrix, compare_arrays, create_equal_random_arrays from struphy.fields_background.equils import ScrewPinch, ShearedSlab from struphy.geometry import domains + from struphy.utils.arrays import xp as np mpi_comm = MPI.COMM_WORLD mpi_rank = mpi_comm.Get_rank() @@ -379,7 +379,6 @@ def test_mass_polar(Nel, p, spl_kind, dirichlet_bc, mapping, show_plots=False): from mpi4py import MPI - from struphy.arrays import xp as np from struphy.eigenvalue_solvers.mhd_operators import MHDOperators from struphy.eigenvalue_solvers.spline_space import Spline_space_1d, Tensor_spline_space from struphy.feec.mass import WeightedMassOperators @@ -388,6 +387,7 @@ def test_mass_polar(Nel, p, spl_kind, dirichlet_bc, mapping, show_plots=False): from struphy.fields_background.equils import ScrewPinch from struphy.geometry import domains from struphy.polar.basic import PolarVector + from struphy.utils.arrays import xp as np mpi_comm = MPI.COMM_WORLD mpi_rank = mpi_comm.Get_rank() @@ -578,13 +578,13 @@ def test_mass_preconditioner(Nel, p, spl_kind, dirichlet_bc, mapping, show_plots from mpi4py import MPI from psydac.linalg.solvers import inverse - from struphy.arrays import xp as np from struphy.feec.mass import WeightedMassOperators, WeightedMassOperatorsOldForTesting from struphy.feec.preconditioner import MassMatrixPreconditioner from struphy.feec.psydac_derham import Derham from struphy.feec.utilities import create_equal_random_arrays from struphy.fields_background.equils import ScrewPinch, ShearedSlab from struphy.geometry import domains + from struphy.utils.arrays import xp as np mpi_comm = MPI.COMM_WORLD mpi_rank = mpi_comm.Get_rank() @@ -884,7 +884,6 @@ def test_mass_preconditioner_polar(Nel, p, spl_kind, dirichlet_bc, mapping, show from mpi4py import MPI from psydac.linalg.solvers import inverse - from struphy.arrays import xp as np from struphy.feec.mass import WeightedMassOperators from struphy.feec.preconditioner import MassMatrixPreconditioner from struphy.feec.psydac_derham import Derham @@ -892,6 +891,7 @@ def test_mass_preconditioner_polar(Nel, p, spl_kind, dirichlet_bc, mapping, show from struphy.fields_background.equils import ScrewPinch from struphy.geometry import domains from struphy.polar.basic import PolarVector + from struphy.utils.arrays import xp as np mpi_comm = MPI.COMM_WORLD mpi_rank = mpi_comm.Get_rank() diff --git a/src/struphy/feec/tests/test_toarray_struphy.py b/src/struphy/feec/tests/test_toarray_struphy.py index e6a049ed3..1feb0f467 100644 --- a/src/struphy/feec/tests/test_toarray_struphy.py +++ b/src/struphy/feec/tests/test_toarray_struphy.py @@ -15,11 +15,11 @@ def test_toarray_struphy(Nel, p, spl_kind, mapping): from mpi4py import MPI - from struphy.arrays import xp as np from struphy.feec.mass import WeightedMassOperators from struphy.feec.psydac_derham import Derham from struphy.feec.utilities import compare_arrays, create_equal_random_arrays from struphy.geometry import domains + from struphy.utils.arrays import xp as np comm = MPI.COMM_WORLD rank = comm.Get_rank() diff --git a/src/struphy/feec/tests/test_tosparse_struphy.py b/src/struphy/feec/tests/test_tosparse_struphy.py index af62d925a..177e0cc80 100644 --- a/src/struphy/feec/tests/test_tosparse_struphy.py +++ b/src/struphy/feec/tests/test_tosparse_struphy.py @@ -17,11 +17,11 @@ def test_tosparse_struphy(Nel, p, spl_kind, mapping): from mpi4py import MPI - from struphy.arrays import xp as np from struphy.feec.mass import WeightedMassOperators from struphy.feec.psydac_derham import Derham from struphy.feec.utilities import create_equal_random_arrays from struphy.geometry import domains + from struphy.utils.arrays import xp as np comm = MPI.COMM_WORLD rank = comm.Get_rank() diff --git a/src/struphy/feec/tests/xx_test_preconds.py b/src/struphy/feec/tests/xx_test_preconds.py index b6d35cc41..e05cdcb13 100644 --- a/src/struphy/feec/tests/xx_test_preconds.py +++ b/src/struphy/feec/tests/xx_test_preconds.py @@ -16,12 +16,12 @@ def test_mass_preconditioner(Nel, p, spl_kind, mapping): from psydac.linalg.block import BlockVector from psydac.linalg.stencil import StencilVector - from struphy.arrays import xp as np from struphy.feec.linear_operators import InverseLinearOperator from struphy.feec.mass import WeightedMassOperators from struphy.feec.preconditioner import MassMatrixPreconditioner from struphy.feec.psydac_derham import Derham from struphy.geometry import domains + from struphy.utils.arrays import xp as np MPI_COMM = MPI.COMM_WORLD diff --git a/src/struphy/feec/utilities.py b/src/struphy/feec/utilities.py index ece3aa90d..4ceb7842a 100644 --- a/src/struphy/feec/utilities.py +++ b/src/struphy/feec/utilities.py @@ -5,9 +5,9 @@ from psydac.linalg.stencil import StencilMatrix, StencilVector import struphy.feec.utilities_kernels as kernels -from struphy.arrays import xp as np from struphy.feec import banded_to_stencil_kernels as bts from struphy.polar.basic import PolarVector +from struphy.utils.arrays import xp as np class RotationMatrix: diff --git a/src/struphy/feec/utilities_local_projectors.py b/src/struphy/feec/utilities_local_projectors.py index df12631e7..5aa9a5b61 100644 --- a/src/struphy/feec/utilities_local_projectors.py +++ b/src/struphy/feec/utilities_local_projectors.py @@ -1,5 +1,5 @@ -from struphy.arrays import xp as np from struphy.feec.local_projectors_kernels import are_quadrature_points_zero, get_rows, select_quasi_points +from struphy.utils.arrays import xp as np def split_points( diff --git a/src/struphy/feec/variational_utilities.py b/src/struphy/feec/variational_utilities.py index af24988f3..61773122e 100644 --- a/src/struphy/feec/variational_utilities.py +++ b/src/struphy/feec/variational_utilities.py @@ -4,7 +4,6 @@ from psydac.linalg.block import BlockVector from psydac.linalg.solvers import inverse -from struphy.arrays import xp as np from struphy.feec import preconditioner from struphy.feec.basis_projection_ops import ( BasisProjectionOperator, @@ -13,6 +12,7 @@ ) from struphy.feec.linear_operators import LinOpWithTransp from struphy.feec.psydac_derham import Derham +from struphy.utils.arrays import xp as np class BracketOperator(LinOpWithTransp): diff --git a/src/struphy/fields_background/base.py b/src/struphy/fields_background/base.py index 8e748f5e3..275fb13f9 100644 --- a/src/struphy/fields_background/base.py +++ b/src/struphy/fields_background/base.py @@ -5,8 +5,8 @@ from matplotlib import pyplot as plt from pyevtk.hl import gridToVTK -from struphy.arrays import xp as np from struphy.geometry.base import Domain +from struphy.utils.arrays import xp as np class FluidEquilibrium(metaclass=ABCMeta): diff --git a/src/struphy/fields_background/coil_fields/base.py b/src/struphy/fields_background/coil_fields/base.py index ea40dee39..540268ef3 100644 --- a/src/struphy/fields_background/coil_fields/base.py +++ b/src/struphy/fields_background/coil_fields/base.py @@ -3,7 +3,7 @@ from matplotlib import pyplot as plt from pyevtk.hl import gridToVTK -from struphy.arrays import xp as np +from struphy.utils.arrays import xp as np class CoilMagneticField(metaclass=ABCMeta): diff --git a/src/struphy/fields_background/coil_fields/coil_fields.py b/src/struphy/fields_background/coil_fields/coil_fields.py index 681a705c7..75895c465 100644 --- a/src/struphy/fields_background/coil_fields/coil_fields.py +++ b/src/struphy/fields_background/coil_fields/coil_fields.py @@ -1,6 +1,6 @@ -from struphy.arrays import xp as np from struphy.feec.psydac_derham import Derham from struphy.fields_background.coil_fields.base import CoilMagneticField, load_csv_data +from struphy.utils.arrays import xp as np class RatGUI(CoilMagneticField): diff --git a/src/struphy/fields_background/equils.py b/src/struphy/fields_background/equils.py index e0cee328f..71488ce7f 100644 --- a/src/struphy/fields_background/equils.py +++ b/src/struphy/fields_background/equils.py @@ -12,7 +12,6 @@ from scipy.optimize import fsolve, minimize import struphy -from struphy.arrays import xp as np from struphy.fields_background.base import ( AxisymmMHDequilibrium, CartesianFluidEquilibrium, @@ -29,6 +28,7 @@ NumericalMHDequilibrium, ) from struphy.fields_background.mhd_equil.eqdsk import readeqdsk +from struphy.utils.arrays import xp as np from struphy.utils.utils import read_state, subp_run diff --git a/src/struphy/fields_background/tests/test_desc_equil.py b/src/struphy/fields_background/tests/test_desc_equil.py index 26e10f1bf..c8f1dc6fe 100644 --- a/src/struphy/fields_background/tests/test_desc_equil.py +++ b/src/struphy/fields_background/tests/test_desc_equil.py @@ -3,7 +3,7 @@ import pytest from matplotlib import pyplot as plt -from struphy.arrays import xp as np +from struphy.utils.arrays import xp as np desc_spec = importlib.util.find_spec("desc") diff --git a/src/struphy/fields_background/tests/test_generic_equils.py b/src/struphy/fields_background/tests/test_generic_equils.py index 43efe834e..8c10eb80e 100644 --- a/src/struphy/fields_background/tests/test_generic_equils.py +++ b/src/struphy/fields_background/tests/test_generic_equils.py @@ -1,11 +1,11 @@ import pytest from matplotlib import pyplot as plt -from struphy.arrays import xp as np from struphy.fields_background.generic import ( GenericCartesianFluidEquilibrium, GenericCartesianFluidEquilibriumWithB, ) +from struphy.utils.arrays import xp as np def test_generic_equils(show=False): diff --git a/src/struphy/fields_background/tests/test_mhd_equils.py b/src/struphy/fields_background/tests/test_mhd_equils.py index 31165e247..bd750e9d9 100644 --- a/src/struphy/fields_background/tests/test_mhd_equils.py +++ b/src/struphy/fields_background/tests/test_mhd_equils.py @@ -1,7 +1,7 @@ import pytest -from struphy.arrays import xp as np from struphy.fields_background import equils +from struphy.utils.arrays import xp as np @pytest.mark.parametrize( diff --git a/src/struphy/fields_background/tests/test_numerical_mhd_equil.py b/src/struphy/fields_background/tests/test_numerical_mhd_equil.py index a3f8466b9..4d34e8352 100644 --- a/src/struphy/fields_background/tests/test_numerical_mhd_equil.py +++ b/src/struphy/fields_background/tests/test_numerical_mhd_equil.py @@ -1,7 +1,7 @@ import pytest -from struphy.arrays import xp as np from struphy.fields_background.base import FluidEquilibrium, LogicalMHDequilibrium +from struphy.utils.arrays import xp as np @pytest.mark.parametrize( diff --git a/src/struphy/geometry/base.py b/src/struphy/geometry/base.py index d94d21687..2a3141e96 100644 --- a/src/struphy/geometry/base.py +++ b/src/struphy/geometry/base.py @@ -8,10 +8,10 @@ from scipy.sparse.linalg import splu, spsolve import struphy.bsplines.bsplines as bsp -from struphy.arrays import xp as np from struphy.geometry import evaluation_kernels, transform_kernels from struphy.kernel_arguments.pusher_args_kernels import DomainArguments from struphy.linear_algebra import linalg_kron +from struphy.utils.arrays import xp as np class Domain(metaclass=ABCMeta): diff --git a/src/struphy/geometry/domains.py b/src/struphy/geometry/domains.py index 12c2e626f..8543c98ed 100644 --- a/src/struphy/geometry/domains.py +++ b/src/struphy/geometry/domains.py @@ -2,7 +2,6 @@ import copy -from struphy.arrays import xp as np from struphy.fields_background.base import AxisymmMHDequilibrium from struphy.fields_background.equils import EQDSKequilibrium from struphy.geometry.base import ( @@ -13,6 +12,7 @@ interp_mapping, ) from struphy.geometry.utilities import field_line_tracing +from struphy.utils.arrays import xp as np class Tokamak(PoloidalSplineTorus): diff --git a/src/struphy/geometry/tests/test_domain.py b/src/struphy/geometry/tests/test_domain.py index ef5cad940..d53c98548 100644 --- a/src/struphy/geometry/tests/test_domain.py +++ b/src/struphy/geometry/tests/test_domain.py @@ -4,8 +4,8 @@ def test_prepare_arg(): """Tests prepare_arg static method in domain base class.""" - from struphy.arrays import xp as np from struphy.geometry.base import Domain + from struphy.utils.arrays import xp as np def a1(e1, e2, e3): return e1 * e2 @@ -157,9 +157,9 @@ def a_vec(e1, e2, e3): def test_evaluation_mappings(mapping): """Tests domain object creation with default parameters and evaluation of metric coefficients.""" - from struphy.arrays import xp as np from struphy.geometry import domains from struphy.geometry.base import Domain + from struphy.utils.arrays import xp as np # arrays: arr1 = np.linspace(0.0, 1.0, 4) @@ -316,9 +316,9 @@ def test_evaluation_mappings(mapping): def test_pullback(): """Tests pullbacks to p-forms.""" - from struphy.arrays import xp as np from struphy.geometry import domains from struphy.geometry.base import Domain + from struphy.utils.arrays import xp as np # arrays: arr1 = np.linspace(0.0, 1.0, 4) @@ -475,9 +475,9 @@ def fun(x, y, z): def test_pushforward(): """Tests pushforward of p-forms.""" - from struphy.arrays import xp as np from struphy.geometry import domains from struphy.geometry.base import Domain + from struphy.utils.arrays import xp as np # arrays: arr1 = np.linspace(0.0, 1.0, 4) @@ -634,9 +634,9 @@ def fun(e1, e2, e3): def test_transform(): """Tests transformation of p-forms.""" - from struphy.arrays import xp as np from struphy.geometry import domains from struphy.geometry.base import Domain + from struphy.utils.arrays import xp as np # arrays: arr1 = np.linspace(0.0, 1.0, 4) @@ -816,7 +816,7 @@ def fun(e1, e2, e3): # """ # # from struphy.geometry import domains -# from struphy.arrays import xp as np +# from struphy.utils.arrays import xp as np # # # arrays: # arr1 = np.linspace(0., 1., 4) diff --git a/src/struphy/geometry/utilities.py b/src/struphy/geometry/utilities.py index 53364b899..732cf48c0 100644 --- a/src/struphy/geometry/utilities.py +++ b/src/struphy/geometry/utilities.py @@ -4,11 +4,11 @@ from scipy.sparse import csc_matrix from scipy.sparse.linalg import splu -from struphy.arrays import xp as np from struphy.bsplines import bsplines as bsp from struphy.geometry.base import PoloidalSplineTorus from struphy.geometry.utilities_kernels import weighted_arc_lengths_flux_surface from struphy.linear_algebra.linalg_kron import kron_lusolve_2d +from struphy.utils.arrays import xp as np def field_line_tracing( diff --git a/src/struphy/initial/eigenfunctions.py b/src/struphy/initial/eigenfunctions.py index 12c1b037c..172386bdf 100644 --- a/src/struphy/initial/eigenfunctions.py +++ b/src/struphy/initial/eigenfunctions.py @@ -4,8 +4,8 @@ from psydac.api.discretization import discretize from sympde.topology import Derham, Line -from struphy.arrays import xp as np from struphy.fields_background.equils import set_defaults +from struphy.utils.arrays import xp as np class InitialMHDAxisymHdivEigFun: diff --git a/src/struphy/initial/perturbations.py b/src/struphy/initial/perturbations.py index 01b8e9bd1..9062c42b3 100644 --- a/src/struphy/initial/perturbations.py +++ b/src/struphy/initial/perturbations.py @@ -4,7 +4,7 @@ import scipy import scipy.special -from struphy.arrays import xp as np +from struphy.utils.arrays import xp as np class ModesSin: diff --git a/src/struphy/initial/tests/test_init_perturbations.py b/src/struphy/initial/tests/test_init_perturbations.py index b9f9ae613..57d49fa0c 100644 --- a/src/struphy/initial/tests/test_init_perturbations.py +++ b/src/struphy/initial/tests/test_init_perturbations.py @@ -23,11 +23,11 @@ def test_init_modes(Nel, p, spl_kind, mapping, combine_comps=None, do_plot=False from matplotlib import pyplot as plt from mpi4py import MPI - from struphy.arrays import xp as np from struphy.feec.psydac_derham import Derham from struphy.geometry import domains from struphy.geometry.base import Domain from struphy.initial import perturbations + from struphy.utils.arrays import xp as np comm = MPI.COMM_WORLD rank = comm.Get_rank() diff --git a/src/struphy/initial/utilities.py b/src/struphy/initial/utilities.py index 9174bf593..da5edd45a 100644 --- a/src/struphy/initial/utilities.py +++ b/src/struphy/initial/utilities.py @@ -2,9 +2,9 @@ import h5py -from struphy.arrays import xp as np from struphy.fields_background.equils import set_defaults from struphy.io.output_handling import DataContainer +from struphy.utils.arrays import xp as np class InitFromOutput: diff --git a/src/struphy/io/output_handling.py b/src/struphy/io/output_handling.py index 7651c4451..66551425c 100644 --- a/src/struphy/io/output_handling.py +++ b/src/struphy/io/output_handling.py @@ -3,7 +3,7 @@ import h5py -from struphy.arrays import xp as np +from struphy.utils.arrays import xp as np class DataContainer: diff --git a/src/struphy/io/setup.py b/src/struphy/io/setup.py index 1a701d69f..bfec7fe76 100644 --- a/src/struphy/io/setup.py +++ b/src/struphy/io/setup.py @@ -2,7 +2,7 @@ from mpi4py import MPI -from struphy.arrays import xp as np +from struphy.utils.arrays import xp as np from struphy.utils.utils import dict_to_yaml diff --git a/src/struphy/kinetic_background/base.py b/src/struphy/kinetic_background/base.py index af52cc36b..a694a0b1e 100644 --- a/src/struphy/kinetic_background/base.py +++ b/src/struphy/kinetic_background/base.py @@ -3,12 +3,12 @@ import copy from abc import ABCMeta, abstractmethod -from struphy.arrays import xp as np from struphy.fields_background.base import FluidEquilibrium from struphy.fields_background.equils import set_defaults from struphy.initial import perturbations from struphy.initial.utilities import Noise from struphy.kinetic_background import moment_functions +from struphy.utils.arrays import xp as np class KineticBackground(metaclass=ABCMeta): diff --git a/src/struphy/kinetic_background/maxwellians.py b/src/struphy/kinetic_background/maxwellians.py index 4801e732f..7965b4e04 100644 --- a/src/struphy/kinetic_background/maxwellians.py +++ b/src/struphy/kinetic_background/maxwellians.py @@ -1,10 +1,10 @@ "Maxwellian (Gaussian) distributions in velocity space." -from struphy.arrays import xp as np from struphy.fields_background.base import FluidEquilibrium from struphy.fields_background.equils import set_defaults from struphy.kinetic_background import moment_functions from struphy.kinetic_background.base import CanonicalMaxwellian, Maxwellian +from struphy.utils.arrays import xp as np class Maxwellian3D(Maxwellian): diff --git a/src/struphy/kinetic_background/moment_functions.py b/src/struphy/kinetic_background/moment_functions.py index 6f688c668..8d17f670c 100644 --- a/src/struphy/kinetic_background/moment_functions.py +++ b/src/struphy/kinetic_background/moment_functions.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 "Analytical moment functions." -from struphy.arrays import xp as np +from struphy.utils.arrays import xp as np class ITPA_density: diff --git a/src/struphy/kinetic_background/tests/test_base.py b/src/struphy/kinetic_background/tests/test_base.py index 4b5a3ccee..2556d27b1 100644 --- a/src/struphy/kinetic_background/tests/test_base.py +++ b/src/struphy/kinetic_background/tests/test_base.py @@ -3,8 +3,8 @@ def test_kinetic_background_magics(show_plot=False): of the Maxwellian base class.""" import matplotlib.pyplot as plt - from struphy.arrays import xp as np from struphy.kinetic_background.maxwellians import Maxwellian3D + from struphy.utils.arrays import xp as np Nel = [32, 1, 1] e1 = np.linspace(0.0, 1.0, Nel[0]) diff --git a/src/struphy/kinetic_background/tests/test_maxwellians.py b/src/struphy/kinetic_background/tests/test_maxwellians.py index fbb1229aa..8378ffe17 100644 --- a/src/struphy/kinetic_background/tests/test_maxwellians.py +++ b/src/struphy/kinetic_background/tests/test_maxwellians.py @@ -10,8 +10,8 @@ def test_maxwellian_3d_uniform(Nel, show_plot=False): """ import matplotlib.pyplot as plt - from struphy.arrays import xp as np from struphy.kinetic_background.maxwellians import Maxwellian3D + from struphy.utils.arrays import xp as np e1 = np.linspace(0.0, 1.0, Nel[0]) e2 = np.linspace(0.0, 1.0, Nel[1]) @@ -90,8 +90,8 @@ def test_maxwellian_3d_perturbed(Nel, show_plot=False): import matplotlib.pyplot as plt - from struphy.arrays import xp as np from struphy.kinetic_background.maxwellians import Maxwellian3D + from struphy.utils.arrays import xp as np e1 = np.linspace(0.0, 1.0, Nel[0]) v1 = np.linspace(-5.0, 5.0, 128) @@ -286,11 +286,11 @@ def test_maxwellian_3d_mhd(Nel, with_desc, show_plot=False): import matplotlib.pyplot as plt - from struphy.arrays import xp as np from struphy.fields_background import equils from struphy.geometry import domains from struphy.initial import perturbations from struphy.kinetic_background.maxwellians import Maxwellian3D + from struphy.utils.arrays import xp as np maxw_params_mhd = { "n": "fluid_background", @@ -693,8 +693,8 @@ def test_maxwellian_2d_uniform(Nel, show_plot=False): """ import matplotlib.pyplot as plt - from struphy.arrays import xp as np from struphy.kinetic_background.maxwellians import GyroMaxwellian2D + from struphy.utils.arrays import xp as np e1 = np.linspace(0.0, 1.0, Nel[0]) e2 = np.linspace(0.0, 1.0, Nel[1]) @@ -782,8 +782,8 @@ def test_maxwellian_2d_perturbed(Nel, show_plot=False): import matplotlib.pyplot as plt - from struphy.arrays import xp as np from struphy.kinetic_background.maxwellians import GyroMaxwellian2D + from struphy.utils.arrays import xp as np e1 = np.linspace(0.0, 1.0, Nel[0]) v1 = np.linspace(-5.0, 5.0, 128) @@ -1036,12 +1036,12 @@ def test_maxwellian_2d_mhd(Nel, with_desc, show_plot=False): import matplotlib.pyplot as plt - from struphy.arrays import xp as np from struphy.fields_background import equils from struphy.fields_background.base import FluidEquilibriumWithB from struphy.geometry import domains from struphy.initial import perturbations from struphy.kinetic_background.maxwellians import GyroMaxwellian2D + from struphy.utils.arrays import xp as np maxw_params_mhd = { "n": "fluid_background", @@ -1437,10 +1437,10 @@ def test_canonical_maxwellian_uniform(Nel, show_plot=False): """ import matplotlib.pyplot as plt - from struphy.arrays import xp as np from struphy.fields_background import equils from struphy.geometry import domains from struphy.kinetic_background.maxwellians import CanonicalMaxwellian + from struphy.utils.arrays import xp as np e1 = np.linspace(0.0, 1.0, Nel[0]) e2 = np.linspace(0.0, 1.0, Nel[1]) diff --git a/src/struphy/linear_algebra/linalg_kron.py b/src/struphy/linear_algebra/linalg_kron.py index 21f4cced7..68e2513f7 100644 --- a/src/struphy/linear_algebra/linalg_kron.py +++ b/src/struphy/linear_algebra/linalg_kron.py @@ -16,7 +16,7 @@ from scipy.linalg import solve_circulant from scipy.sparse.linalg import splu -from struphy.arrays import xp as np +from struphy.utils.arrays import xp as np def kron_matvec_2d(kmat, vec2d): diff --git a/src/struphy/linear_algebra/saddle_point.py b/src/struphy/linear_algebra/saddle_point.py index 2da6900d0..5da783b3a 100644 --- a/src/struphy/linear_algebra/saddle_point.py +++ b/src/struphy/linear_algebra/saddle_point.py @@ -6,8 +6,8 @@ from psydac.linalg.direct_solvers import SparseSolver from psydac.linalg.solvers import inverse -from struphy.arrays import xp as np from struphy.linear_algebra.tests.test_saddlepoint_massmatrices import _plot_residual_norms +from struphy.utils.arrays import xp as np class SaddlePointSolver: diff --git a/src/struphy/linear_algebra/tests/test_saddlepoint_massmatrices.py b/src/struphy/linear_algebra/tests/test_saddlepoint_massmatrices.py index 973a71eeb..dd258ad92 100644 --- a/src/struphy/linear_algebra/tests/test_saddlepoint_massmatrices.py +++ b/src/struphy/linear_algebra/tests/test_saddlepoint_massmatrices.py @@ -18,7 +18,6 @@ def test_saddlepointsolver(method_for_solving, Nel, p, spl_kind, dirichlet_bc, m from psydac.linalg.basic import IdentityOperator from psydac.linalg.block import BlockLinearOperator, BlockVector, BlockVectorSpace - from struphy.arrays import xp as np from struphy.examples.restelli2018 import callables from struphy.feec.basis_projection_ops import BasisProjectionOperatorLocal, BasisProjectionOperators from struphy.feec.mass import WeightedMassOperators @@ -30,6 +29,7 @@ def test_saddlepointsolver(method_for_solving, Nel, p, spl_kind, dirichlet_bc, m from struphy.geometry import domains from struphy.initial import perturbations from struphy.linear_algebra.saddle_point import SaddlePointSolver + from struphy.utils.arrays import xp as np mpi_comm = MPI.COMM_WORLD mpi_rank = mpi_comm.Get_rank() @@ -375,7 +375,7 @@ def _plot_velocity(data_reshaped): import matplotlib import matplotlib.pyplot as plt - from struphy.arrays import xp as np + from struphy.utils.arrays import xp as np matplotlib.use("Agg") diff --git a/src/struphy/linear_algebra/tests/test_stencil_dot_kernels.py b/src/struphy/linear_algebra/tests/test_stencil_dot_kernels.py index 6d801dff7..abb385894 100644 --- a/src/struphy/linear_algebra/tests/test_stencil_dot_kernels.py +++ b/src/struphy/linear_algebra/tests/test_stencil_dot_kernels.py @@ -18,9 +18,9 @@ def test_1d(Nel, p, spl_kind, domain_ind, codomain_ind): from psydac.api.settings import PSYDAC_BACKEND_GPYCCEL from psydac.linalg.stencil import StencilMatrix, StencilVector - from struphy.arrays import xp as np from struphy.feec.psydac_derham import Derham from struphy.linear_algebra.stencil_dot_kernels import matvec_1d_kernel + from struphy.utils.arrays import xp as np # only for M1 Mac users PSYDAC_BACKEND_GPYCCEL["flags"] = "-O3 -march=native -mtune=native -ffast-math -ffree-line-length-none" @@ -141,9 +141,9 @@ def test_3d(Nel, p, spl_kind, domain_ind, codomain_ind): from psydac.api.settings import PSYDAC_BACKEND_GPYCCEL from psydac.linalg.stencil import StencilMatrix, StencilVector - from struphy.arrays import xp as np from struphy.feec.psydac_derham import Derham from struphy.linear_algebra.stencil_dot_kernels import matvec_3d_kernel + from struphy.utils.arrays import xp as np # only for M1 Mac users PSYDAC_BACKEND_GPYCCEL["flags"] = "-O3 -march=native -mtune=native -ffast-math -ffree-line-length-none" diff --git a/src/struphy/linear_algebra/tests/test_stencil_transpose_kernels.py b/src/struphy/linear_algebra/tests/test_stencil_transpose_kernels.py index 95015a12d..fce53b3a6 100644 --- a/src/struphy/linear_algebra/tests/test_stencil_transpose_kernels.py +++ b/src/struphy/linear_algebra/tests/test_stencil_transpose_kernels.py @@ -18,9 +18,9 @@ def test_1d(Nel, p, spl_kind, domain_ind, codomain_ind): from psydac.api.settings import PSYDAC_BACKEND_GPYCCEL from psydac.linalg.stencil import StencilMatrix - from struphy.arrays import xp as np from struphy.feec.psydac_derham import Derham from struphy.linear_algebra.stencil_transpose_kernels import transpose_1d_kernel + from struphy.utils.arrays import xp as np # only for M1 Mac users PSYDAC_BACKEND_GPYCCEL["flags"] = "-O3 -march=native -mtune=native -ffast-math -ffree-line-length-none" @@ -135,9 +135,9 @@ def test_3d(Nel, p, spl_kind, domain_ind, codomain_ind): from psydac.api.settings import PSYDAC_BACKEND_GPYCCEL from psydac.linalg.stencil import StencilMatrix - from struphy.arrays import xp as np from struphy.feec.psydac_derham import Derham from struphy.linear_algebra.stencil_transpose_kernels import transpose_3d_kernel + from struphy.utils.arrays import xp as np # only for M1 Mac users PSYDAC_BACKEND_GPYCCEL["flags"] = "-O3 -march=native -mtune=native -ffast-math -ffree-line-length-none" diff --git a/src/struphy/main.py b/src/struphy/main.py index 05de5cdc0..4987ac6d7 100644 --- a/src/struphy/main.py +++ b/src/struphy/main.py @@ -57,7 +57,6 @@ def main( from mpi4py import MPI from pyevtk.hl import gridToVTK - from struphy.arrays import xp as np from struphy.feec.psydac_derham import SplineFunction from struphy.fields_background.base import FluidEquilibriumWithB from struphy.io.output_handling import DataContainer @@ -65,6 +64,7 @@ def main( from struphy.models import fluid, hybrid, kinetic, toy from struphy.models.base import StruphyModel from struphy.profiling.profiling import ProfileManager + from struphy.utils.arrays import xp as np from struphy.utils.clone_config import CloneConfig if sort_step: diff --git a/src/struphy/models/base.py b/src/struphy/models/base.py index 4e90b67ea..1db07b1f4 100644 --- a/src/struphy/models/base.py +++ b/src/struphy/models/base.py @@ -7,7 +7,6 @@ from mpi4py import MPI from psydac.linalg.stencil import StencilVector -from struphy.arrays import xp as np from struphy.feec.basis_projection_ops import BasisProjectionOperators from struphy.feec.mass import WeightedMassOperators from struphy.feec.psydac_derham import SplineFunction @@ -20,6 +19,7 @@ from struphy.io.setup import setup_derham, setup_domain_and_equil from struphy.profiling.profiling import ProfileManager from struphy.propagators.base import Propagator +from struphy.utils.arrays import xp as np from struphy.utils.clone_config import CloneConfig from struphy.utils.utils import dict_to_yaml diff --git a/src/struphy/models/fluid.py b/src/struphy/models/fluid.py index 1ed93f996..04f5fca1c 100644 --- a/src/struphy/models/fluid.py +++ b/src/struphy/models/fluid.py @@ -1,6 +1,6 @@ -from struphy.arrays import xp as np from struphy.models.base import StruphyModel from struphy.propagators import propagators_coupling, propagators_fields, propagators_markers +from struphy.utils.arrays import xp as np class LinearMHD(StruphyModel): diff --git a/src/struphy/models/hybrid.py b/src/struphy/models/hybrid.py index 1714f37a6..a1d618eb7 100644 --- a/src/struphy/models/hybrid.py +++ b/src/struphy/models/hybrid.py @@ -1,7 +1,7 @@ -from struphy.arrays import xp as np from struphy.models.base import StruphyModel from struphy.pic.accumulation import accum_kernels, accum_kernels_gc from struphy.propagators import propagators_coupling, propagators_fields, propagators_markers +from struphy.utils.arrays import xp as np class LinearMHDVlasovCC(StruphyModel): diff --git a/src/struphy/models/kinetic.py b/src/struphy/models/kinetic.py index 6997258cf..0a8ea1f78 100644 --- a/src/struphy/models/kinetic.py +++ b/src/struphy/models/kinetic.py @@ -1,8 +1,8 @@ -from struphy.arrays import xp as np from struphy.kinetic_background.base import KineticBackground from struphy.models.base import StruphyModel from struphy.pic.accumulation import accum_kernels, accum_kernels_gc from struphy.propagators import propagators_coupling, propagators_fields, propagators_markers +from struphy.utils.arrays import xp as np class VlasovAmpereOneSpecies(StruphyModel): diff --git a/src/struphy/models/tests/verification.py b/src/struphy/models/tests/verification.py index b56197254..0a207e2d6 100644 --- a/src/struphy/models/tests/verification.py +++ b/src/struphy/models/tests/verification.py @@ -10,8 +10,8 @@ from scipy.special import jv, yn import struphy -from struphy.arrays import xp as np from struphy.post_processing import pproc_struphy +from struphy.utils.arrays import xp as np def VlasovAmpereOneSpecies_weakLandau( diff --git a/src/struphy/models/toy.py b/src/struphy/models/toy.py index 895a8af69..4610dab3e 100644 --- a/src/struphy/models/toy.py +++ b/src/struphy/models/toy.py @@ -1,6 +1,6 @@ -from struphy.arrays import xp as np from struphy.models.base import StruphyModel from struphy.propagators import propagators_coupling, propagators_fields, propagators_markers +from struphy.utils.arrays import xp as np class Maxwell(StruphyModel): diff --git a/src/struphy/ode/solvers.py b/src/struphy/ode/solvers.py index 9091f565f..414afd8e0 100644 --- a/src/struphy/ode/solvers.py +++ b/src/struphy/ode/solvers.py @@ -3,8 +3,8 @@ from psydac.linalg.block import BlockVector from psydac.linalg.stencil import StencilVector -from struphy.arrays import xp as np from struphy.ode.utils import ButcherTableau +from struphy.utils.arrays import xp as np class ODEsolverFEEC: diff --git a/src/struphy/ode/tests/test_ode_feec.py b/src/struphy/ode/tests/test_ode_feec.py index 31b46cc1f..f664474fa 100644 --- a/src/struphy/ode/tests/test_ode_feec.py +++ b/src/struphy/ode/tests/test_ode_feec.py @@ -24,9 +24,9 @@ def test_exp_growth(spaces, algo, show_plots=False): from psydac.linalg.block import BlockVector from psydac.linalg.stencil import StencilVector - from struphy.arrays import xp as np from struphy.feec.psydac_derham import Derham from struphy.ode.solvers import ODEsolverFEEC + from struphy.utils.arrays import xp as np comm = MPI.COMM_WORLD rank = comm.Get_rank() diff --git a/src/struphy/ode/utils.py b/src/struphy/ode/utils.py index a8d61d5f6..bdabf4406 100644 --- a/src/struphy/ode/utils.py +++ b/src/struphy/ode/utils.py @@ -1,4 +1,4 @@ -from struphy.arrays import xp as np +from struphy.utils.arrays import xp as np class ButcherTableau: diff --git a/src/struphy/pic/accumulation/particles_to_grid.py b/src/struphy/pic/accumulation/particles_to_grid.py index f23accd29..4212557f6 100644 --- a/src/struphy/pic/accumulation/particles_to_grid.py +++ b/src/struphy/pic/accumulation/particles_to_grid.py @@ -7,12 +7,12 @@ import struphy.pic.accumulation.accum_kernels as accums import struphy.pic.accumulation.accum_kernels_gc as accums_gc import struphy.pic.accumulation.filter_kernels as filters -from struphy.arrays import xp as np from struphy.feec.mass import WeightedMassOperators from struphy.feec.psydac_derham import Derham from struphy.kernel_arguments.pusher_args_kernels import DerhamArguments, DomainArguments from struphy.pic.base import Particles from struphy.profiling.profiling import ProfileManager +from struphy.utils.arrays import xp as np class Accumulator: diff --git a/src/struphy/pic/base.py b/src/struphy/pic/base.py index 8a76cafdb..d7b7fb5c9 100644 --- a/src/struphy/pic/base.py +++ b/src/struphy/pic/base.py @@ -9,7 +9,6 @@ from mpi4py.MPI import Intracomm from sympy.ntheory import factorint -from struphy.arrays import xp as np from struphy.bsplines.bsplines import quadrature_grid from struphy.fields_background import equils from struphy.fields_background.base import FluidEquilibrium, FluidEquilibriumWithB, NumericalFluidEquilibrium @@ -38,6 +37,7 @@ naive_evaluation_meshgrid, ) from struphy.utils import utils +from struphy.utils.arrays import xp as np from struphy.utils.clone_config import CloneConfig diff --git a/src/struphy/pic/particles.py b/src/struphy/pic/particles.py index 6ebf96570..581bbd986 100644 --- a/src/struphy/pic/particles.py +++ b/src/struphy/pic/particles.py @@ -1,12 +1,12 @@ import copy -from struphy.arrays import xp as np from struphy.fields_background.base import FluidEquilibriumWithB from struphy.fields_background.projected_equils import ProjectedFluidEquilibriumWithB from struphy.geometry.base import Domain from struphy.kinetic_background import maxwellians from struphy.pic import utilities_kernels from struphy.pic.base import Particles +from struphy.utils.arrays import xp as np class Particles6D(Particles): diff --git a/src/struphy/pic/pushing/pusher.py b/src/struphy/pic/pushing/pusher.py index 77d8110e6..4d9340b5a 100644 --- a/src/struphy/pic/pushing/pusher.py +++ b/src/struphy/pic/pushing/pusher.py @@ -2,10 +2,10 @@ from mpi4py.MPI import IN_PLACE, SUM -from struphy.arrays import xp as np from struphy.kernel_arguments.pusher_args_kernels import DerhamArguments, DomainArguments from struphy.pic.base import Particles from struphy.profiling.profiling import ProfileManager +from struphy.utils.arrays import xp as np class Pusher: diff --git a/src/struphy/pic/sobol_seq.py b/src/struphy/pic/sobol_seq.py index 8c30be765..ff073b1b3 100644 --- a/src/struphy/pic/sobol_seq.py +++ b/src/struphy/pic/sobol_seq.py @@ -19,7 +19,7 @@ from scipy.stats import norm -from struphy.arrays import xp as np +from struphy.utils.arrays import xp as np __all__ = ["i4_bit_hi1", "i4_bit_lo0", "i4_sobol_generate", "i4_sobol", "i4_uniform", "prime_ge", "is_prime"] diff --git a/src/struphy/pic/tests/test_accum_vec_H1.py b/src/struphy/pic/tests/test_accum_vec_H1.py index 125a9dec6..e90eca703 100644 --- a/src/struphy/pic/tests/test_accum_vec_H1.py +++ b/src/struphy/pic/tests/test_accum_vec_H1.py @@ -48,13 +48,13 @@ def test_accum_poisson(Nel, p, spl_kind, mapping, num_clones, Np=1000): from mpi4py import MPI - from struphy.arrays import xp as np from struphy.feec.mass import WeightedMassOperators from struphy.feec.psydac_derham import Derham from struphy.geometry import domains from struphy.pic.accumulation import accum_kernels from struphy.pic.accumulation.particles_to_grid import AccumulatorVector from struphy.pic.particles import Particles6D + from struphy.utils.arrays import xp as np from struphy.utils.clone_config import CloneConfig mpi_comm = MPI.COMM_WORLD diff --git a/src/struphy/pic/tests/test_accumulation.py b/src/struphy/pic/tests/test_accumulation.py index dec9f81d8..996d7c886 100644 --- a/src/struphy/pic/tests/test_accumulation.py +++ b/src/struphy/pic/tests/test_accumulation.py @@ -49,7 +49,6 @@ def pc_lin_mhd_6d_step_ph_full(Nel, p, spl_kind, mapping, Np, verbose=False): from mpi4py import MPI - from struphy.arrays import xp as np from struphy.eigenvalue_solvers.spline_space import Spline_space_1d, Tensor_spline_space from struphy.feec.mass import WeightedMassOperators from struphy.feec.psydac_derham import Derham @@ -59,6 +58,7 @@ def pc_lin_mhd_6d_step_ph_full(Nel, p, spl_kind, mapping, Np, verbose=False): from struphy.pic.accumulation.particles_to_grid import Accumulator from struphy.pic.particles import Particles6D from struphy.pic.tests.test_pic_legacy_files.accumulation_kernels_3d import kernel_step_ph_full + from struphy.utils.arrays import xp as np mpi_comm = MPI.COMM_WORLD # assert mpi_comm.size >= 2 diff --git a/src/struphy/pic/tests/test_binning.py b/src/struphy/pic/tests/test_binning.py index f033f5ce7..b3e8774cf 100644 --- a/src/struphy/pic/tests/test_binning.py +++ b/src/struphy/pic/tests/test_binning.py @@ -38,10 +38,10 @@ def test_binning_6D_full_f(mapping, show_plot=False): import matplotlib.pyplot as plt from mpi4py import MPI - from struphy.arrays import xp as np from struphy.geometry import domains from struphy.kinetic_background.maxwellians import Maxwellian3D from struphy.pic.particles import Particles6D + from struphy.utils.arrays import xp as np # Set seed seed = 1234 @@ -297,10 +297,10 @@ def test_binning_6D_delta_f(mapping, show_plot=False): import matplotlib.pyplot as plt from mpi4py import MPI - from struphy.arrays import xp as np from struphy.geometry import domains from struphy.kinetic_background.maxwellians import Maxwellian3D from struphy.pic.particles import DeltaFParticles6D + from struphy.utils.arrays import xp as np # Set seed seed = 1234 @@ -521,10 +521,10 @@ def test_binning_6D_full_f_mpi(mapping, show_plot=False): import matplotlib.pyplot as plt from mpi4py import MPI - from struphy.arrays import xp as np from struphy.geometry import domains from struphy.kinetic_background.maxwellians import Maxwellian3D from struphy.pic.particles import Particles6D + from struphy.utils.arrays import xp as np # Set seed seed = 1234 @@ -803,10 +803,10 @@ def test_binning_6D_delta_f_mpi(mapping, show_plot=False): import matplotlib.pyplot as plt from mpi4py import MPI - from struphy.arrays import xp as np from struphy.geometry import domains from struphy.kinetic_background.maxwellians import Maxwellian3D from struphy.pic.particles import DeltaFParticles6D + from struphy.utils.arrays import xp as np # Set seed seed = 1234 diff --git a/src/struphy/pic/tests/test_draw_parallel.py b/src/struphy/pic/tests/test_draw_parallel.py index e7c7d6bcc..cc636797e 100644 --- a/src/struphy/pic/tests/test_draw_parallel.py +++ b/src/struphy/pic/tests/test_draw_parallel.py @@ -38,10 +38,10 @@ def test_draw(Nel, p, spl_kind, mapping, ppc=10): from mpi4py import MPI - from struphy.arrays import xp as np from struphy.feec.psydac_derham import Derham from struphy.geometry import domains from struphy.pic.particles import Particles6D + from struphy.utils.arrays import xp as np comm = MPI.COMM_WORLD assert comm.size >= 2 diff --git a/src/struphy/pic/tests/test_mat_vec_filler.py b/src/struphy/pic/tests/test_mat_vec_filler.py index c759f67c8..0d2a61df1 100644 --- a/src/struphy/pic/tests/test_mat_vec_filler.py +++ b/src/struphy/pic/tests/test_mat_vec_filler.py @@ -1,6 +1,6 @@ import pytest -from struphy.arrays import xp as np +from struphy.utils.arrays import xp as np @pytest.mark.mpi(min_size=2) diff --git a/src/struphy/pic/tests/test_pic_legacy_files/accumulation.py b/src/struphy/pic/tests/test_pic_legacy_files/accumulation.py index f96e93e92..c66a43b2e 100644 --- a/src/struphy/pic/tests/test_pic_legacy_files/accumulation.py +++ b/src/struphy/pic/tests/test_pic_legacy_files/accumulation.py @@ -12,7 +12,7 @@ from mpi4py import MPI import struphy.pic.tests.test_pic_legacy_files.accumulation_kernels_3d as pic_ker_3d -from struphy.arrays import xp as np +from struphy.utils.arrays import xp as np # import struphy.pic.tests.test_pic_legacy_files.accumulation_kernels_2d as pic_ker_2d diff --git a/src/struphy/pic/tests/test_pic_legacy_files/pusher.py b/src/struphy/pic/tests/test_pic_legacy_files/pusher.py index f31e12b99..6bdb74642 100644 --- a/src/struphy/pic/tests/test_pic_legacy_files/pusher.py +++ b/src/struphy/pic/tests/test_pic_legacy_files/pusher.py @@ -1,7 +1,7 @@ import struphy.pic.tests.test_pic_legacy_files.pusher_pos as push_pos import struphy.pic.tests.test_pic_legacy_files.pusher_vel_2d as push_vel_2d import struphy.pic.tests.test_pic_legacy_files.pusher_vel_3d as push_vel_3d -from struphy.arrays import xp as np +from struphy.utils.arrays import xp as np class Pusher: diff --git a/src/struphy/pic/tests/test_pushers.py b/src/struphy/pic/tests/test_pushers.py index 1fca079ea..3e4ac1f4e 100644 --- a/src/struphy/pic/tests/test_pushers.py +++ b/src/struphy/pic/tests/test_pushers.py @@ -24,7 +24,6 @@ def test_push_vxb_analytic(Nel, p, spl_kind, mapping, show_plots=False): from mpi4py import MPI - from struphy.arrays import xp as np from struphy.eigenvalue_solvers.spline_space import Spline_space_1d, Tensor_spline_space from struphy.feec.psydac_derham import Derham from struphy.feec.utilities import create_equal_random_arrays @@ -33,6 +32,7 @@ def test_push_vxb_analytic(Nel, p, spl_kind, mapping, show_plots=False): from struphy.pic.pushing import pusher_kernels from struphy.pic.pushing.pusher import Pusher as Pusher_psy from struphy.pic.tests.test_pic_legacy_files.pusher import Pusher as Pusher_str + from struphy.utils.arrays import xp as np comm = MPI.COMM_WORLD rank = comm.Get_rank() @@ -161,7 +161,6 @@ def test_push_vxb_analytic(Nel, p, spl_kind, mapping, show_plots=False): def test_push_bxu_Hdiv(Nel, p, spl_kind, mapping, show_plots=False): from mpi4py import MPI - from struphy.arrays import xp as np from struphy.eigenvalue_solvers.spline_space import Spline_space_1d, Tensor_spline_space from struphy.feec.psydac_derham import Derham from struphy.feec.utilities import create_equal_random_arrays @@ -170,6 +169,7 @@ def test_push_bxu_Hdiv(Nel, p, spl_kind, mapping, show_plots=False): from struphy.pic.pushing import pusher_kernels from struphy.pic.pushing.pusher import Pusher as Pusher_psy from struphy.pic.tests.test_pic_legacy_files.pusher import Pusher as Pusher_str + from struphy.utils.arrays import xp as np comm = MPI.COMM_WORLD rank = comm.Get_rank() @@ -309,7 +309,6 @@ def test_push_bxu_Hdiv(Nel, p, spl_kind, mapping, show_plots=False): def test_push_bxu_Hcurl(Nel, p, spl_kind, mapping, show_plots=False): from mpi4py import MPI - from struphy.arrays import xp as np from struphy.eigenvalue_solvers.spline_space import Spline_space_1d, Tensor_spline_space from struphy.feec.psydac_derham import Derham from struphy.feec.utilities import create_equal_random_arrays @@ -318,6 +317,7 @@ def test_push_bxu_Hcurl(Nel, p, spl_kind, mapping, show_plots=False): from struphy.pic.pushing import pusher_kernels from struphy.pic.pushing.pusher import Pusher as Pusher_psy from struphy.pic.tests.test_pic_legacy_files.pusher import Pusher as Pusher_str + from struphy.utils.arrays import xp as np comm = MPI.COMM_WORLD rank = comm.Get_rank() @@ -457,7 +457,6 @@ def test_push_bxu_Hcurl(Nel, p, spl_kind, mapping, show_plots=False): def test_push_bxu_H1vec(Nel, p, spl_kind, mapping, show_plots=False): from mpi4py import MPI - from struphy.arrays import xp as np from struphy.eigenvalue_solvers.spline_space import Spline_space_1d, Tensor_spline_space from struphy.feec.psydac_derham import Derham from struphy.feec.utilities import create_equal_random_arrays @@ -466,6 +465,7 @@ def test_push_bxu_H1vec(Nel, p, spl_kind, mapping, show_plots=False): from struphy.pic.pushing import pusher_kernels from struphy.pic.pushing.pusher import Pusher as Pusher_psy from struphy.pic.tests.test_pic_legacy_files.pusher import Pusher as Pusher_str + from struphy.utils.arrays import xp as np comm = MPI.COMM_WORLD rank = comm.Get_rank() @@ -605,7 +605,6 @@ def test_push_bxu_H1vec(Nel, p, spl_kind, mapping, show_plots=False): def test_push_bxu_Hdiv_pauli(Nel, p, spl_kind, mapping, show_plots=False): from mpi4py import MPI - from struphy.arrays import xp as np from struphy.eigenvalue_solvers.spline_space import Spline_space_1d, Tensor_spline_space from struphy.feec.psydac_derham import Derham from struphy.feec.utilities import create_equal_random_arrays @@ -614,6 +613,7 @@ def test_push_bxu_Hdiv_pauli(Nel, p, spl_kind, mapping, show_plots=False): from struphy.pic.pushing import pusher_kernels from struphy.pic.pushing.pusher import Pusher as Pusher_psy from struphy.pic.tests.test_pic_legacy_files.pusher import Pusher as Pusher_str + from struphy.utils.arrays import xp as np comm = MPI.COMM_WORLD rank = comm.Get_rank() @@ -755,7 +755,6 @@ def test_push_bxu_Hdiv_pauli(Nel, p, spl_kind, mapping, show_plots=False): def test_push_eta_rk4(Nel, p, spl_kind, mapping, show_plots=False): from mpi4py import MPI - from struphy.arrays import xp as np from struphy.eigenvalue_solvers.spline_space import Spline_space_1d, Tensor_spline_space from struphy.feec.psydac_derham import Derham from struphy.feec.utilities import create_equal_random_arrays @@ -765,6 +764,7 @@ def test_push_eta_rk4(Nel, p, spl_kind, mapping, show_plots=False): from struphy.pic.pushing import pusher_kernels from struphy.pic.pushing.pusher import Pusher as Pusher_psy from struphy.pic.tests.test_pic_legacy_files.pusher import Pusher as Pusher_str + from struphy.utils.arrays import xp as np comm = MPI.COMM_WORLD rank = comm.Get_rank() diff --git a/src/struphy/pic/tests/test_sorting.py b/src/struphy/pic/tests/test_sorting.py index 810a08e0b..291f91387 100644 --- a/src/struphy/pic/tests/test_sorting.py +++ b/src/struphy/pic/tests/test_sorting.py @@ -3,10 +3,10 @@ import pytest from mpi4py import MPI -from struphy.arrays import xp as np from struphy.feec.psydac_derham import Derham from struphy.geometry import domains from struphy.pic.particles import Particles6D +from struphy.utils.arrays import xp as np @pytest.mark.parametrize("nx", [8, 70]) diff --git a/src/struphy/pic/tests/test_sph.py b/src/struphy/pic/tests/test_sph.py index efd2cfe5b..b1db7c18d 100644 --- a/src/struphy/pic/tests/test_sph.py +++ b/src/struphy/pic/tests/test_sph.py @@ -2,9 +2,9 @@ from matplotlib import pyplot as plt from mpi4py import MPI -from struphy.arrays import xp as np from struphy.geometry import domains from struphy.pic.particles import ParticlesSPH +from struphy.utils.arrays import xp as np @pytest.mark.parametrize("boxes_per_dim", [(24, 1, 1)]) diff --git a/src/struphy/pic/tests/test_tesselation.py b/src/struphy/pic/tests/test_tesselation.py index 277365f64..c650d9980 100644 --- a/src/struphy/pic/tests/test_tesselation.py +++ b/src/struphy/pic/tests/test_tesselation.py @@ -4,10 +4,10 @@ from matplotlib import pyplot as plt from mpi4py import MPI -from struphy.arrays import xp as np from struphy.feec.psydac_derham import Derham from struphy.geometry import domains from struphy.pic.particles import ParticlesSPH +from struphy.utils.arrays import xp as np @pytest.mark.mpi(min_size=2) diff --git a/src/struphy/pic/utilities.py b/src/struphy/pic/utilities.py index d27cca7de..5507526a5 100644 --- a/src/struphy/pic/utilities.py +++ b/src/struphy/pic/utilities.py @@ -1,5 +1,5 @@ import struphy.pic.utilities_kernels as utils -from struphy.arrays import xp as np +from struphy.utils.arrays import xp as np def get_kinetic_energy_particles(fe_coeffs, derham, domain, particles): diff --git a/src/struphy/polar/basic.py b/src/struphy/polar/basic.py index 87da77db3..c87ec12e9 100644 --- a/src/struphy/polar/basic.py +++ b/src/struphy/polar/basic.py @@ -3,7 +3,7 @@ from psydac.linalg.block import BlockVector from psydac.linalg.stencil import StencilVector -from struphy.arrays import xp as np +from struphy.utils.arrays import xp as np class PolarDerhamSpace(VectorSpace): diff --git a/src/struphy/polar/extraction_operators.py b/src/struphy/polar/extraction_operators.py index 497136515..9afb9d237 100644 --- a/src/struphy/polar/extraction_operators.py +++ b/src/struphy/polar/extraction_operators.py @@ -1,4 +1,4 @@ -from struphy.arrays import xp as np +from struphy.utils.arrays import xp as np # ============================= 2D polar splines (C1) =================================== diff --git a/src/struphy/polar/linear_operators.py b/src/struphy/polar/linear_operators.py index 5af6d2373..858bad9ba 100644 --- a/src/struphy/polar/linear_operators.py +++ b/src/struphy/polar/linear_operators.py @@ -3,10 +3,10 @@ from psydac.linalg.stencil import StencilVector, StencilVectorSpace from scipy.sparse import csr_matrix, identity -from struphy.arrays import xp as np from struphy.feec.linear_operators import LinOpWithTransp from struphy.linear_algebra.linalg_kron import kron_matvec_2d from struphy.polar.basic import PolarDerhamSpace, PolarVector +from struphy.utils.arrays import xp as np class PolarExtractionOperator(LinOpWithTransp): diff --git a/src/struphy/polar/tests/test_legacy_polar_splines.py b/src/struphy/polar/tests/test_legacy_polar_splines.py index 114558116..b9665ae0b 100644 --- a/src/struphy/polar/tests/test_legacy_polar_splines.py +++ b/src/struphy/polar/tests/test_legacy_polar_splines.py @@ -10,9 +10,9 @@ def test_polar_splines_2D(plot=False): import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D - from struphy.arrays import xp as np from struphy.eigenvalue_solvers.spline_space import Spline_space_1d, Tensor_spline_space from struphy.geometry import domains + from struphy.utils.arrays import xp as np # parameters # number of elements (number of elements in angular direction must be a multiple of 3) diff --git a/src/struphy/polar/tests/test_polar.py b/src/struphy/polar/tests/test_polar.py index 967dd72dd..def55cb7b 100644 --- a/src/struphy/polar/tests/test_polar.py +++ b/src/struphy/polar/tests/test_polar.py @@ -170,7 +170,6 @@ def test_spaces(Nel, p, spl_kind): def test_extraction_ops_and_derivatives(Nel, p, spl_kind): from mpi4py import MPI - from struphy.arrays import xp as np from struphy.eigenvalue_solvers.spline_space import Spline_space_1d, Tensor_spline_space from struphy.feec.psydac_derham import Derham from struphy.feec.utilities import compare_arrays, create_equal_random_arrays @@ -178,6 +177,7 @@ def test_extraction_ops_and_derivatives(Nel, p, spl_kind): from struphy.polar.basic import PolarDerhamSpace, PolarVector from struphy.polar.extraction_operators import PolarExtractionBlocksC1 from struphy.polar.linear_operators import PolarExtractionOperator, PolarLinearOperator + from struphy.utils.arrays import xp as np comm = MPI.COMM_WORLD rank = comm.Get_rank() @@ -305,10 +305,10 @@ def test_extraction_ops_and_derivatives(Nel, p, spl_kind): def test_projectors(Nel, p, spl_kind): from mpi4py import MPI - from struphy.arrays import xp as np from struphy.eigenvalue_solvers.spline_space import Spline_space_1d, Tensor_spline_space from struphy.feec.psydac_derham import Derham from struphy.geometry.domains import IGAPolarCylinder + from struphy.utils.arrays import xp as np comm = MPI.COMM_WORLD rank = comm.Get_rank() diff --git a/src/struphy/post_processing/likwid/plot_likwidproject.py b/src/struphy/post_processing/likwid/plot_likwidproject.py index 12f70a2dd..33b0426af 100644 --- a/src/struphy/post_processing/likwid/plot_likwidproject.py +++ b/src/struphy/post_processing/likwid/plot_likwidproject.py @@ -16,7 +16,7 @@ import struphy.post_processing.likwid.likwid_parser as lp import struphy.post_processing.likwid.maxplotlylib as mply import struphy.post_processing.likwid.roofline_plotter as rp -from struphy.arrays import xp as np +from struphy.utils.arrays import xp as np def clean_string(string_in): diff --git a/src/struphy/post_processing/likwid/plot_time_traces.py b/src/struphy/post_processing/likwid/plot_time_traces.py index cf0049efe..4f3f4eeb8 100644 --- a/src/struphy/post_processing/likwid/plot_time_traces.py +++ b/src/struphy/post_processing/likwid/plot_time_traces.py @@ -7,7 +7,7 @@ # pio.kaleido.scope.mathjax = None import struphy.post_processing.likwid.maxplotlylib as mply -from struphy.arrays import xp as np +from struphy.utils.arrays import xp as np def glob_to_regex(pat: str) -> str: diff --git a/src/struphy/post_processing/likwid/roofline_plotter.py b/src/struphy/post_processing/likwid/roofline_plotter.py index 584fadbdb..6a49f9c34 100644 --- a/src/struphy/post_processing/likwid/roofline_plotter.py +++ b/src/struphy/post_processing/likwid/roofline_plotter.py @@ -4,7 +4,7 @@ import pandas as pd import yaml -from struphy.arrays import xp as np +from struphy.utils.arrays import xp as np def sort_by_num_threads(bm): diff --git a/src/struphy/post_processing/orbits/orbits_tools.py b/src/struphy/post_processing/orbits/orbits_tools.py index 0b6b2d47c..eb72ebdfb 100644 --- a/src/struphy/post_processing/orbits/orbits_tools.py +++ b/src/struphy/post_processing/orbits/orbits_tools.py @@ -5,9 +5,9 @@ import yaml from tqdm import tqdm -from struphy.arrays import xp as np from struphy.io.setup import setup_domain_and_equil from struphy.post_processing.orbits.orbits_kernels import calculate_guiding_center_from_6d +from struphy.utils.arrays import xp as np def post_process_orbit_guiding_center(path_in, path_kinetics_species, species): diff --git a/src/struphy/post_processing/post_processing_tools.py b/src/struphy/post_processing/post_processing_tools.py index 3e5ce165f..28919c6d3 100644 --- a/src/struphy/post_processing/post_processing_tools.py +++ b/src/struphy/post_processing/post_processing_tools.py @@ -6,11 +6,11 @@ import yaml from tqdm import tqdm -from struphy.arrays import xp as np from struphy.feec.psydac_derham import Derham from struphy.io.setup import setup_domain_and_equil from struphy.kinetic_background import maxwellians from struphy.models import fluid, hybrid, kinetic, toy +from struphy.utils.arrays import xp as np def create_femfields( diff --git a/src/struphy/post_processing/pproc_struphy.py b/src/struphy/post_processing/pproc_struphy.py index 0e1a87752..29199d065 100644 --- a/src/struphy/post_processing/pproc_struphy.py +++ b/src/struphy/post_processing/pproc_struphy.py @@ -46,8 +46,8 @@ def main( import struphy.post_processing.orbits.orbits_tools as orbits_pproc import struphy.post_processing.post_processing_tools as pproc - from struphy.arrays import xp as np from struphy.models import fluid, hybrid, kinetic, toy + from struphy.utils.arrays import xp as np print("") diff --git a/src/struphy/post_processing/profile_struphy.py b/src/struphy/post_processing/profile_struphy.py index a1602095d..8c738a9a7 100644 --- a/src/struphy/post_processing/profile_struphy.py +++ b/src/struphy/post_processing/profile_struphy.py @@ -4,8 +4,8 @@ import yaml from matplotlib import pyplot as plt -from struphy.arrays import xp as np from struphy.post_processing.cprofile_analyser import get_cprofile_data, replace_keys +from struphy.utils.arrays import xp as np def main(): diff --git a/src/struphy/profiling/profiling.py b/src/struphy/profiling/profiling.py index 9b42d50ca..c560a10ce 100644 --- a/src/struphy/profiling/profiling.py +++ b/src/struphy/profiling/profiling.py @@ -19,7 +19,7 @@ from mpi4py import MPI -from struphy.arrays import xp as np +from struphy.utils.arrays import xp as np @lru_cache(maxsize=None) # Cache the import result to avoid repeated imports diff --git a/src/struphy/propagators/base.py b/src/struphy/propagators/base.py index 8ef61c56a..8e05b1b17 100644 --- a/src/struphy/propagators/base.py +++ b/src/struphy/propagators/base.py @@ -2,11 +2,11 @@ from abc import ABCMeta, abstractmethod -from struphy.arrays import xp as np from struphy.feec.basis_projection_ops import BasisProjectionOperators from struphy.feec.mass import WeightedMassOperators from struphy.feec.psydac_derham import Derham from struphy.geometry.base import Domain +from struphy.utils.arrays import xp as np class Propagator(metaclass=ABCMeta): diff --git a/src/struphy/propagators/propagators_coupling.py b/src/struphy/propagators/propagators_coupling.py index 8476bd756..faf1f046b 100644 --- a/src/struphy/propagators/propagators_coupling.py +++ b/src/struphy/propagators/propagators_coupling.py @@ -3,7 +3,6 @@ from psydac.linalg.block import BlockVector from psydac.linalg.stencil import StencilVector -from struphy.arrays import xp as np from struphy.feec import preconditioner from struphy.feec.linear_operators import LinOpWithTransp from struphy.io.setup import descend_options_dict @@ -17,6 +16,7 @@ from struphy.pic.pushing.pusher import Pusher from struphy.polar.basic import PolarVector from struphy.propagators.base import Propagator +from struphy.utils.arrays import xp as np class VlasovAmpere(Propagator): diff --git a/src/struphy/propagators/propagators_fields.py b/src/struphy/propagators/propagators_fields.py index c8759254a..18d874c77 100644 --- a/src/struphy/propagators/propagators_fields.py +++ b/src/struphy/propagators/propagators_fields.py @@ -14,7 +14,6 @@ from psydac.linalg.stencil import StencilVector import struphy.feec.utilities as util -from struphy.arrays import xp as np from struphy.examples.restelli2018 import callables from struphy.feec import preconditioner from struphy.feec.basis_projection_ops import ( @@ -50,6 +49,7 @@ from struphy.pic.particles import Particles5D, Particles6D from struphy.polar.basic import PolarVector from struphy.propagators.base import Propagator +from struphy.utils.arrays import xp as np class Maxwell(Propagator): diff --git a/src/struphy/propagators/propagators_markers.py b/src/struphy/propagators/propagators_markers.py index 523dd65cb..9e77269f8 100644 --- a/src/struphy/propagators/propagators_markers.py +++ b/src/struphy/propagators/propagators_markers.py @@ -4,7 +4,6 @@ from psydac.linalg.block import BlockVector from psydac.linalg.stencil import StencilVector -from struphy.arrays import xp as np from struphy.feec.mass import WeightedMassOperators from struphy.fields_background.base import MHDequilibrium from struphy.fields_background.equils import set_defaults @@ -17,6 +16,7 @@ from struphy.pic.pushing.pusher import Pusher from struphy.polar.basic import PolarVector from struphy.propagators.base import Propagator +from struphy.utils.arrays import xp as np class PushEta(Propagator): @@ -72,7 +72,7 @@ def __init__( # define algorithm butcher = ButcherTableau(algo) # temp fix due to refactoring of ButcherTableau: - from struphy.arrays import xp as np + from struphy.utils.arrays import xp as np butcher._a = np.diag(butcher.a, k=-1) butcher._a = np.array(list(butcher.a) + [0.0]) @@ -713,7 +713,7 @@ def __init__( else: butcher = ButcherTableau(algo["method"]) # temp fix due to refactoring of ButcherTableau: - from struphy.arrays import xp as np + from struphy.utils.arrays import xp as np butcher._a = np.diag(butcher.a, k=-1) butcher._a = np.array(list(butcher.a) + [0.0]) @@ -1132,7 +1132,7 @@ def __init__( else: butcher = ButcherTableau(algo["method"]) # temp fix due to refactoring of ButcherTableau: - from struphy.arrays import xp as np + from struphy.utils.arrays import xp as np butcher._a = np.diag(butcher.a, k=-1) butcher._a = np.array(list(butcher.a) + [0.0]) @@ -1342,7 +1342,7 @@ def __init__( # choose algorithm self._butcher = ButcherTableau(algo) # temp fix due to refactoring of ButcherTableau: - from struphy.arrays import xp as np + from struphy.utils.arrays import xp as np self._butcher._a = np.diag(self._butcher.a, k=-1) self._butcher._a = np.array(list(self._butcher.a) + [0.0]) @@ -1445,7 +1445,7 @@ def __init__( # choose algorithm self._butcher = ButcherTableau("forward_euler") # temp fix due to refactoring of ButcherTableau: - from struphy.arrays import xp as np + from struphy.utils.arrays import xp as np self._butcher._a = np.diag(self._butcher.a, k=-1) self._butcher._a = np.array(list(self._butcher.a) + [0.0]) diff --git a/src/struphy/propagators/tests/test_gyrokinetic_poisson.py b/src/struphy/propagators/tests/test_gyrokinetic_poisson.py index a89e0a351..62ea2b485 100644 --- a/src/struphy/propagators/tests/test_gyrokinetic_poisson.py +++ b/src/struphy/propagators/tests/test_gyrokinetic_poisson.py @@ -2,13 +2,13 @@ import pytest from mpi4py import MPI -from struphy.arrays import xp as np from struphy.feec.mass import WeightedMassOperators from struphy.feec.projectors import L2Projector from struphy.feec.psydac_derham import Derham from struphy.geometry import domains from struphy.propagators import ImplicitDiffusion from struphy.propagators.base import Propagator +from struphy.utils.arrays import xp as np comm = MPI.COMM_WORLD rank = comm.Get_rank() diff --git a/src/struphy/propagators/tests/test_poisson.py b/src/struphy/propagators/tests/test_poisson.py index 4a67f257c..6b7233822 100644 --- a/src/struphy/propagators/tests/test_poisson.py +++ b/src/struphy/propagators/tests/test_poisson.py @@ -2,13 +2,13 @@ import pytest from mpi4py import MPI -from struphy.arrays import xp as np from struphy.feec.mass import WeightedMassOperators from struphy.feec.projectors import L2Projector from struphy.feec.psydac_derham import Derham from struphy.geometry import domains from struphy.propagators import ImplicitDiffusion from struphy.propagators.base import Propagator +from struphy.utils.arrays import xp as np comm = MPI.COMM_WORLD rank = comm.Get_rank() diff --git a/src/struphy/arrays.py b/src/struphy/utils/arrays.py similarity index 100% rename from src/struphy/arrays.py rename to src/struphy/utils/arrays.py diff --git a/src/struphy/utils/clone_config.py b/src/struphy/utils/clone_config.py index cb8ab64e3..65ca43bf5 100644 --- a/src/struphy/utils/clone_config.py +++ b/src/struphy/utils/clone_config.py @@ -1,6 +1,6 @@ from mpi4py import MPI -from struphy.arrays import xp as np +from struphy.utils.arrays import xp as np class CloneConfig: diff --git a/src/struphy/cupy_vs_numpy.py b/src/struphy/utils/cupy_vs_numpy.py similarity index 100% rename from src/struphy/cupy_vs_numpy.py rename to src/struphy/utils/cupy_vs_numpy.py diff --git a/src/struphy/utils/utils.py b/src/struphy/utils/utils.py index 24462fd17..f3d96c0f9 100644 --- a/src/struphy/utils/utils.py +++ b/src/struphy/utils/utils.py @@ -61,7 +61,7 @@ def save_state(state, libpath=STRUPHY_LIBPATH): def print_all_attr(obj): """Print all object's attributes that do not start with "_" to screen.""" - from struphy.arrays import xp as np + from struphy.utils.arrays import xp as np for k in dir(obj): if k[0] != "_": From 09d2a710b65983ee099fa24de49071f11424f66c Mon Sep 17 00:00:00 2001 From: Max Lindqvist Date: Fri, 10 Oct 2025 16:40:46 +0200 Subject: [PATCH 50/76] Fixes for running struphy with cupy arrays --- src/struphy/bsplines/bsplines.py | 4 +-- src/struphy/feec/basis_projection_ops.py | 2 +- src/struphy/feec/preconditioner.py | 2 +- src/struphy/feec/psydac_derham.py | 29 ++++++++++++++----- src/struphy/geometry/base.py | 9 +++--- .../kernel_arguments/pusher_args_kernels.py | 15 +++++----- src/struphy/utils/pyccel.py | 10 +++++-- 7 files changed, 46 insertions(+), 25 deletions(-) diff --git a/src/struphy/bsplines/bsplines.py b/src/struphy/bsplines/bsplines.py index a659e4c61..ed84dde53 100644 --- a/src/struphy/bsplines/bsplines.py +++ b/src/struphy/bsplines/bsplines.py @@ -611,8 +611,8 @@ def make_knots(breaks, degree, periodic): if periodic: period = breaks[-1] - breaks[0] - T[0:p] = [xi - period for xi in breaks[-p - 1 : -1]] - T[-p:] = [xi + period for xi in breaks[1 : p + 1]] + T[0:p] = np.asarray([xi - period for xi in breaks[-p - 1 : -1]]) + T[-p:] = np.asarray([xi + period for xi in breaks[1 : p + 1]]) else: T[0:p] = breaks[0] T[-p:] = breaks[-1] diff --git a/src/struphy/feec/basis_projection_ops.py b/src/struphy/feec/basis_projection_ops.py index f0208efe7..e1f1400b9 100644 --- a/src/struphy/feec/basis_projection_ops.py +++ b/src/struphy/feec/basis_projection_ops.py @@ -51,7 +51,7 @@ def __init__(self, derham, domain, verbose=True, **weights): self._rank = derham.comm.Get_rank() if derham.comm is not None else 0 - if np.any([p == 1 and Nel > 1 for p, Nel in zip(derham.p, derham.Nel)]): + if np.any(np.array([int(p) == 1 and int(Nel) > 1 for p, Nel in zip(derham.p, derham.Nel)])): if MPI.COMM_WORLD.Get_rank() == 0: print( f'\nWARNING: Class "BasisProjectionOperators" called with p={derham.p} (interpolation of piece-wise constants should be avoided).', diff --git a/src/struphy/feec/preconditioner.py b/src/struphy/feec/preconditioner.py index b3a8744eb..d4a6d44a3 100644 --- a/src/struphy/feec/preconditioner.py +++ b/src/struphy/feec/preconditioner.py @@ -937,7 +937,7 @@ def is_circulant(mat): Whether the matrix is circulant (=True) or not (=False). """ - assert isinstance(mat, np.ndarray) + # assert isinstance(mat, np.ndarray) # could be a cupy array assert len(mat.shape) == 2 assert mat.shape[0] == mat.shape[1] diff --git a/src/struphy/feec/psydac_derham.py b/src/struphy/feec/psydac_derham.py index b1995f4f6..dd34e0fdb 100644 --- a/src/struphy/feec/psydac_derham.py +++ b/src/struphy/feec/psydac_derham.py @@ -1124,7 +1124,8 @@ def _get_domain_array(self): # distribute if self.comm is not None: - self.comm.Allgather(dom_arr_loc, dom_arr) + # self.comm.Allgather(dom_arr_loc, dom_arr) + dom_arr[:] = dom_arr_loc # TODO: Fix MPI communication with cupy arrays else: dom_arr[:] = dom_arr_loc @@ -1170,7 +1171,8 @@ def _get_index_array(self, decomposition): # distribute if self.comm is not None: - self.comm.Allgather(ind_arr_loc, ind_arr) + # self.comm.Allgather(ind_arr_loc, ind_arr) + ind_arr[:] = ind_arr_loc # TODO: Fix MPI communication with cupy arrays else: ind_arr[:] = ind_arr_loc @@ -2731,12 +2733,17 @@ def get_pts_and_wts(space_1d, start, end, n_quad=None, polar_shift=False): union_breaks = space_1d.breaks[:-1] # Make union of Greville and break points - tmp = set(np.round(space_1d.histopolation_grid, decimals=14)).union( - np.round(union_breaks, decimals=14), + # tmp = set(np.round(space_1d.histopolation_grid, decimals=14)).union( + # np.round(union_breaks, decimals=14), + # ) + # tmp = list(tmp) + # tmp.sort() + # tmp_a = np.array(tmp) + + tmp = set(np.round(space_1d.histopolation_grid, decimals=14).tolist()).union( + np.round(union_breaks, decimals=14).tolist() ) - - tmp = list(tmp) - tmp.sort() + tmp = sorted(tmp) tmp_a = np.array(tmp) x_grid = tmp_a[ @@ -2764,7 +2771,13 @@ def get_pts_and_wts(space_1d, start, end, n_quad=None, polar_shift=False): # products of basis functions are integrated exactly n_quad = space_1d.degree + 1 - pts_loc, wts_loc = np.polynomial.legendre.leggauss(n_quad) + import numpy as _np + pts_loc, wts_loc = _np.polynomial.legendre.leggauss(n_quad) + + if "cupy" in np.__name__: + import cupy as cp + pts_loc = cp.array(pts_loc) + wts_loc = cp.array(wts_loc) x, wts = bsp.quadrature_grid(x_grid, pts_loc, wts_loc) diff --git a/src/struphy/geometry/base.py b/src/struphy/geometry/base.py index 2a3141e96..837c8d249 100644 --- a/src/struphy/geometry/base.py +++ b/src/struphy/geometry/base.py @@ -12,7 +12,7 @@ from struphy.kernel_arguments.pusher_args_kernels import DomainArguments from struphy.linear_algebra import linalg_kron from struphy.utils.arrays import xp as np - +from struphy.utils.pyccel import Pyccelkernel class Domain(metaclass=ABCMeta): r"""Base class for mapped domains (single patch). @@ -769,8 +769,8 @@ def _evaluate_metric_coefficient(self, *etas, which=0, **kwargs): # to keep C-ordering the (3, 3)-part is in the last indices out = np.empty((markers.shape[0], 3, 3), dtype=float) - - n_inside = evaluation_kernels.kernel_evaluate_pic( + kernel = Pyccelkernel(evaluation_kernels.kernel_evaluate_pic) + n_inside = kernel( markers, which, self.args_domain, @@ -813,7 +813,8 @@ def _evaluate_metric_coefficient(self, *etas, which=0, **kwargs): (E1.shape[0], E2.shape[1], E3.shape[2], 3, 3), dtype=float, ) - evaluation_kernels.kernel_evaluate( + kernel = Pyccelkernel(evaluation_kernels.kernel_evaluate) + kernel( E1, E2, E3, diff --git a/src/struphy/kernel_arguments/pusher_args_kernels.py b/src/struphy/kernel_arguments/pusher_args_kernels.py index d80a5058b..f070bc5f0 100644 --- a/src/struphy/kernel_arguments/pusher_args_kernels.py +++ b/src/struphy/kernel_arguments/pusher_args_kernels.py @@ -1,5 +1,6 @@ # from numpy import copy -from numpy import empty +from struphy.utils.arrays import xp as np + class MarkerArguments: @@ -99,12 +100,12 @@ def __init__( self.tn3 = tn3 self.starts = starts - self.bn1 = empty(pn[0] + 1, dtype=float) - self.bn2 = empty(pn[1] + 1, dtype=float) - self.bn3 = empty(pn[2] + 1, dtype=float) - self.bd1 = empty(pn[0], dtype=float) - self.bd2 = empty(pn[1], dtype=float) - self.bd3 = empty(pn[2], dtype=float) + self.bn1 = np.empty(int(pn[0] + 1), dtype=float) + self.bn2 = np.empty(int(pn[1] + 1), dtype=float) + self.bn3 = np.empty(int(pn[2] + 1), dtype=float) + self.bd1 = np.empty(int(pn[0]), dtype=float) + self.bd2 = np.empty(int(pn[1]), dtype=float) + self.bd3 = np.empty(int(pn[2]), dtype=float) class DomainArguments: diff --git a/src/struphy/utils/pyccel.py b/src/struphy/utils/pyccel.py index 5e62426a3..25cc2b856 100644 --- a/src/struphy/utils/pyccel.py +++ b/src/struphy/utils/pyccel.py @@ -1,14 +1,20 @@ from typing import Any, Callable - +from struphy.utils.arrays import xp as np class Pyccelkernel: def __init__(self, kernel: Callable[..., Any], use_cupy: bool = False) -> None: self._kernel = kernel self._use_cupy = use_cupy + if "cupy" in np.__name__: + self._use_cupy = True def __call__(self, *args: Any, **kwargs: Any) -> Any: if self.use_cupy: - raise NotImplementedError + # Convert all args from CuPy to NumPy + args_np = [x.get() if isinstance(x, np.ndarray) else x for x in args] + # Convert all kwargs from CuPy to NumPy + kwargs_np = {k: v.get() if isinstance(v, np.ndarray) else v for k, v in kwargs.items()} + return self._kernel(*args_np, **kwargs_np) else: return self._kernel(*args, **kwargs) From ccae0877054328a42281c396a5122efed4c35737 Mon Sep 17 00:00:00 2001 From: Max Lindqvist Date: Tue, 14 Oct 2025 08:34:36 +0200 Subject: [PATCH 51/76] Formatting --- src/struphy/feec/basis_projection_ops.py | 2 +- src/struphy/feec/mass.py | 2 +- src/struphy/feec/psydac_derham.py | 6 ++++-- src/struphy/geometry/base.py | 1 + src/struphy/kernel_arguments/pusher_args_kernels.py | 1 - src/struphy/models/hybrid.py | 2 +- src/struphy/models/kinetic.py | 2 +- src/struphy/pic/accumulation/particles_to_grid.py | 2 +- src/struphy/pic/pushing/pusher.py | 2 +- src/struphy/propagators/propagators_coupling.py | 2 +- src/struphy/propagators/propagators_fields.py | 2 +- src/struphy/propagators/propagators_markers.py | 2 +- src/struphy/utils/pyccel.py | 2 ++ 13 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/struphy/feec/basis_projection_ops.py b/src/struphy/feec/basis_projection_ops.py index e1f1400b9..930ace08f 100644 --- a/src/struphy/feec/basis_projection_ops.py +++ b/src/struphy/feec/basis_projection_ops.py @@ -14,8 +14,8 @@ from struphy.feec.utilities import RotationMatrix from struphy.polar.basic import PolarDerhamSpace, PolarVector from struphy.polar.linear_operators import PolarExtractionOperator -from struphy.utils.pyccel import Pyccelkernel from struphy.utils.arrays import xp as np +from struphy.utils.pyccel import Pyccelkernel class BasisProjectionOperators: diff --git a/src/struphy/feec/mass.py b/src/struphy/feec/mass.py index a08ec3d86..cdda382da 100644 --- a/src/struphy/feec/mass.py +++ b/src/struphy/feec/mass.py @@ -14,8 +14,8 @@ from struphy.feec.utilities import RotationMatrix from struphy.geometry.base import Domain from struphy.polar.linear_operators import PolarExtractionOperator -from struphy.utils.pyccel import Pyccelkernel from struphy.utils.arrays import xp as np +from struphy.utils.pyccel import Pyccelkernel class WeightedMassOperators: diff --git a/src/struphy/feec/psydac_derham.py b/src/struphy/feec/psydac_derham.py index dd34e0fdb..67d38c83a 100644 --- a/src/struphy/feec/psydac_derham.py +++ b/src/struphy/feec/psydac_derham.py @@ -1125,7 +1125,7 @@ def _get_domain_array(self): # distribute if self.comm is not None: # self.comm.Allgather(dom_arr_loc, dom_arr) - dom_arr[:] = dom_arr_loc # TODO: Fix MPI communication with cupy arrays + dom_arr[:] = dom_arr_loc # TODO: Fix MPI communication with cupy arrays else: dom_arr[:] = dom_arr_loc @@ -1172,7 +1172,7 @@ def _get_index_array(self, decomposition): # distribute if self.comm is not None: # self.comm.Allgather(ind_arr_loc, ind_arr) - ind_arr[:] = ind_arr_loc # TODO: Fix MPI communication with cupy arrays + ind_arr[:] = ind_arr_loc # TODO: Fix MPI communication with cupy arrays else: ind_arr[:] = ind_arr_loc @@ -2772,10 +2772,12 @@ def get_pts_and_wts(space_1d, start, end, n_quad=None, polar_shift=False): n_quad = space_1d.degree + 1 import numpy as _np + pts_loc, wts_loc = _np.polynomial.legendre.leggauss(n_quad) if "cupy" in np.__name__: import cupy as cp + pts_loc = cp.array(pts_loc) wts_loc = cp.array(wts_loc) diff --git a/src/struphy/geometry/base.py b/src/struphy/geometry/base.py index 837c8d249..2ea6f8092 100644 --- a/src/struphy/geometry/base.py +++ b/src/struphy/geometry/base.py @@ -14,6 +14,7 @@ from struphy.utils.arrays import xp as np from struphy.utils.pyccel import Pyccelkernel + class Domain(metaclass=ABCMeta): r"""Base class for mapped domains (single patch). diff --git a/src/struphy/kernel_arguments/pusher_args_kernels.py b/src/struphy/kernel_arguments/pusher_args_kernels.py index f070bc5f0..dfd49b108 100644 --- a/src/struphy/kernel_arguments/pusher_args_kernels.py +++ b/src/struphy/kernel_arguments/pusher_args_kernels.py @@ -2,7 +2,6 @@ from struphy.utils.arrays import xp as np - class MarkerArguments: """Holds arguments pertaining to :class:`~struphy.pic.base.Particles` passed to particle kernels. diff --git a/src/struphy/models/hybrid.py b/src/struphy/models/hybrid.py index c93135aa0..0ba8b6626 100644 --- a/src/struphy/models/hybrid.py +++ b/src/struphy/models/hybrid.py @@ -1,8 +1,8 @@ from struphy.models.base import StruphyModel from struphy.pic.accumulation import accum_kernels, accum_kernels_gc from struphy.propagators import propagators_coupling, propagators_fields, propagators_markers -from struphy.utils.pyccel import Pyccelkernel from struphy.utils.arrays import xp as np +from struphy.utils.pyccel import Pyccelkernel class LinearMHDVlasovCC(StruphyModel): diff --git a/src/struphy/models/kinetic.py b/src/struphy/models/kinetic.py index ffe912307..0fa7eeda7 100644 --- a/src/struphy/models/kinetic.py +++ b/src/struphy/models/kinetic.py @@ -2,8 +2,8 @@ from struphy.models.base import StruphyModel from struphy.pic.accumulation import accum_kernels, accum_kernels_gc from struphy.propagators import propagators_coupling, propagators_fields, propagators_markers -from struphy.utils.pyccel import Pyccelkernel from struphy.utils.arrays import xp as np +from struphy.utils.pyccel import Pyccelkernel class VlasovAmpereOneSpecies(StruphyModel): diff --git a/src/struphy/pic/accumulation/particles_to_grid.py b/src/struphy/pic/accumulation/particles_to_grid.py index ece8ec616..53ff761fa 100644 --- a/src/struphy/pic/accumulation/particles_to_grid.py +++ b/src/struphy/pic/accumulation/particles_to_grid.py @@ -12,8 +12,8 @@ from struphy.kernel_arguments.pusher_args_kernels import DerhamArguments, DomainArguments from struphy.pic.base import Particles from struphy.profiling.profiling import ProfileManager -from struphy.utils.pyccel import Pyccelkernel from struphy.utils.arrays import xp as np +from struphy.utils.pyccel import Pyccelkernel class Accumulator: diff --git a/src/struphy/pic/pushing/pusher.py b/src/struphy/pic/pushing/pusher.py index d3d6db3a2..9ddfe1e8c 100644 --- a/src/struphy/pic/pushing/pusher.py +++ b/src/struphy/pic/pushing/pusher.py @@ -5,8 +5,8 @@ from struphy.kernel_arguments.pusher_args_kernels import DerhamArguments, DomainArguments from struphy.pic.base import Particles from struphy.profiling.profiling import ProfileManager -from struphy.utils.pyccel import Pyccelkernel from struphy.utils.arrays import xp as np +from struphy.utils.pyccel import Pyccelkernel class Pusher: diff --git a/src/struphy/propagators/propagators_coupling.py b/src/struphy/propagators/propagators_coupling.py index e1d2298aa..820eeaba8 100644 --- a/src/struphy/propagators/propagators_coupling.py +++ b/src/struphy/propagators/propagators_coupling.py @@ -16,8 +16,8 @@ from struphy.pic.pushing.pusher import Pusher from struphy.polar.basic import PolarVector from struphy.propagators.base import Propagator -from struphy.utils.pyccel import Pyccelkernel from struphy.utils.arrays import xp as np +from struphy.utils.pyccel import Pyccelkernel class VlasovAmpere(Propagator): diff --git a/src/struphy/propagators/propagators_fields.py b/src/struphy/propagators/propagators_fields.py index 2b4a1fbb5..38ab9f73b 100644 --- a/src/struphy/propagators/propagators_fields.py +++ b/src/struphy/propagators/propagators_fields.py @@ -49,8 +49,8 @@ from struphy.pic.particles import Particles5D, Particles6D from struphy.polar.basic import PolarVector from struphy.propagators.base import Propagator -from struphy.utils.pyccel import Pyccelkernel from struphy.utils.arrays import xp as np +from struphy.utils.pyccel import Pyccelkernel class Maxwell(Propagator): diff --git a/src/struphy/propagators/propagators_markers.py b/src/struphy/propagators/propagators_markers.py index 964f90f1b..fff58d514 100644 --- a/src/struphy/propagators/propagators_markers.py +++ b/src/struphy/propagators/propagators_markers.py @@ -16,8 +16,8 @@ from struphy.pic.pushing.pusher import Pusher from struphy.polar.basic import PolarVector from struphy.propagators.base import Propagator -from struphy.utils.pyccel import Pyccelkernel from struphy.utils.arrays import xp as np +from struphy.utils.pyccel import Pyccelkernel class PushEta(Propagator): diff --git a/src/struphy/utils/pyccel.py b/src/struphy/utils/pyccel.py index 25cc2b856..cc9bf727d 100644 --- a/src/struphy/utils/pyccel.py +++ b/src/struphy/utils/pyccel.py @@ -1,6 +1,8 @@ from typing import Any, Callable + from struphy.utils.arrays import xp as np + class Pyccelkernel: def __init__(self, kernel: Callable[..., Any], use_cupy: bool = False) -> None: self._kernel = kernel From c48eec40be2a2ff023d3731ca5a8e19157133692 Mon Sep 17 00:00:00 2001 From: Max Lindqvist Date: Wed, 15 Oct 2025 19:22:06 +0200 Subject: [PATCH 52/76] fixed product of list --- src/struphy/pic/base.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/struphy/pic/base.py b/src/struphy/pic/base.py index 746b5d5c6..8de6465c9 100644 --- a/src/struphy/pic/base.py +++ b/src/struphy/pic/base.py @@ -226,7 +226,7 @@ def __init__( assert all([nboxes % nproc == 0 for nboxes, nproc in zip(self.boxes_per_dim, self.nprocs)]), ( f"Number of boxes {self.boxes_per_dim = } must be divisible by number of processes {self.nprocs = } in each direction." ) - n_boxes = np.prod(self.boxes_per_dim, dtype=int) * self.num_clones + n_boxes = np.prod(np.array(self.boxes_per_dim), dtype=int) * self.num_clones if verbose: print(f"{self.mpi_rank = }, {n_boxes = }") @@ -3983,6 +3983,7 @@ def _gather_scalar_in_subcomm_array(self, scalar: int, out: np.ndarray = None): _tmp[self.mpi_rank] = scalar if self.mpi_comm is not None: + print(f"{self.mpi_comm = }") self.mpi_comm.Allgather( _tmp[self.mpi_rank], _tmp, From c7f306a02bc26b03b970a2000aa8bdd26ab9c434 Mon Sep 17 00:00:00 2001 From: Max Lindqvist Date: Mon, 20 Oct 2025 13:57:29 +0200 Subject: [PATCH 53/76] Fixed round commands containing numpy numbers --- src/struphy/pic/base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/struphy/pic/base.py b/src/struphy/pic/base.py index df3a9f43b..48d643c0f 100644 --- a/src/struphy/pic/base.py +++ b/src/struphy/pic/base.py @@ -1099,7 +1099,7 @@ def _allocate_marker_array(self): bufsize = self.bufsize + 1.0 / np.sqrt(n_mks_load_loc) # allocate markers array (3 x positions, vdim x velocities, weight, s0, w0, ..., ID) with buffer - self._n_rows = round(n_mks_load_loc * (1 + bufsize)) + self._n_rows = round(float(n_mks_load_loc * (1 + bufsize))) self._markers = np.zeros((self.n_rows, self.n_cols), dtype=float) # allocate auxiliary arrays @@ -2383,7 +2383,7 @@ def _set_boxes(self): n_particles = self._markers_shape[0] n_mkr = int(n_particles / n_box_in) + 1 n_cols = round( - n_mkr * (1 + 1 / np.sqrt(n_mkr) + self._box_bufsize), + float(n_mkr) * (1 + 1 / float(np.sqrt(n_mkr)) + self._box_bufsize), ) # cartesian boxes From e6b9fea160f96d66bd317fc40f85c16759d4707d Mon Sep 17 00:00:00 2001 From: Max Lindqvist Date: Mon, 20 Oct 2025 14:47:53 +0200 Subject: [PATCH 54/76] TEMPORARY, import from cupy in pyccel kernel (only works with non-pyccelized kernels) --- src/struphy/geometry/transform_kernels.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/struphy/geometry/transform_kernels.py b/src/struphy/geometry/transform_kernels.py index c95156b96..5cedbf8ff 100644 --- a/src/struphy/geometry/transform_kernels.py +++ b/src/struphy/geometry/transform_kernels.py @@ -43,7 +43,7 @@ - 2-form --> vector : (a_1, a_2, a_3) = (a^2_1, a^2_2, a^2_3) / |det(DF)| """ -from numpy import empty, shape, sqrt, zeros +from cupy import empty, shape, sqrt, zeros from pyccel.decorators import stack_array import struphy.geometry.evaluation_kernels as evaluation_kernels From 76ab8945ed7a2dae28511c4c9ac94cafed6a6a95 Mon Sep 17 00:00:00 2001 From: Max Lindqvist Date: Mon, 20 Oct 2025 17:29:56 +0200 Subject: [PATCH 55/76] Conditional import --- src/struphy/geometry/transform_kernels.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/struphy/geometry/transform_kernels.py b/src/struphy/geometry/transform_kernels.py index 5cedbf8ff..4465a7c08 100644 --- a/src/struphy/geometry/transform_kernels.py +++ b/src/struphy/geometry/transform_kernels.py @@ -42,8 +42,14 @@ - 1-form --> vector : (a_1, a_2, a_3) = G^(-1) * (a^1_1, a^1_2, a^1_3) - 2-form --> vector : (a_1, a_2, a_3) = (a^2_1, a^2_2, a^2_3) / |det(DF)| """ +from struphy.utils.arrays import xp as np +from struphy.utils.arrays import array_backend + +if array_backend.backend == "cupy": + from cupy import empty, shape, sqrt, zeros +else: + from cupy import empty, shape, sqrt, zeros -from cupy import empty, shape, sqrt, zeros from pyccel.decorators import stack_array import struphy.geometry.evaluation_kernels as evaluation_kernels @@ -332,7 +338,7 @@ def kernel_pullpush( e1 = eta1[i1, i2 * sparse_factor, i3 * sparse_factor] e2 = eta2[i1 * sparse_factor, i2, i3 * sparse_factor] e3 = eta3[i1 * sparse_factor, i2 * sparse_factor, i3] - + print(f"{type(a) = }") tmp1[:] = a[i1, i2, i3, :] tmp2[:] = out[i1, i2, i3, :] From 3e03606acd8fedf14556775728664622b9340bb6 Mon Sep 17 00:00:00 2001 From: Max Lindqvist Date: Mon, 20 Oct 2025 17:35:04 +0200 Subject: [PATCH 56/76] Fix import --- src/struphy/geometry/transform_kernels.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/struphy/geometry/transform_kernels.py b/src/struphy/geometry/transform_kernels.py index 4465a7c08..7fba8bf6c 100644 --- a/src/struphy/geometry/transform_kernels.py +++ b/src/struphy/geometry/transform_kernels.py @@ -48,7 +48,7 @@ if array_backend.backend == "cupy": from cupy import empty, shape, sqrt, zeros else: - from cupy import empty, shape, sqrt, zeros + from numpy import empty, shape, sqrt, zeros from pyccel.decorators import stack_array @@ -338,7 +338,7 @@ def kernel_pullpush( e1 = eta1[i1, i2 * sparse_factor, i3 * sparse_factor] e2 = eta2[i1 * sparse_factor, i2, i3 * sparse_factor] e3 = eta3[i1 * sparse_factor, i2 * sparse_factor, i3] - print(f"{type(a) = }") + tmp1[:] = a[i1, i2, i3, :] tmp2[:] = out[i1, i2, i3, :] From 37f34b82baa28b3cbeb87cfbd08501fd015068c0 Mon Sep 17 00:00:00 2001 From: Max Lindqvist Date: Mon, 20 Oct 2025 18:09:20 +0200 Subject: [PATCH 57/76] Convert st to st_array --- src/struphy/ode/utils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/struphy/ode/utils.py b/src/struphy/ode/utils.py index bdabf4406..43b64befe 100644 --- a/src/struphy/ode/utils.py +++ b/src/struphy/ode/utils.py @@ -74,7 +74,9 @@ def __init__(self, algo: str = "rk4"): self._a = np.tri(self.n_stages, k=-1) for l, st in enumerate(a): assert len(st) == l + 1 - self._a[l + 1, : l + 1] = st + st_array = np.array(st) if isinstance(st, tuple) else st + + self._a[l + 1, : l + 1] = st_array self._conv_rate = conv_rate From f8d6afca1b402dfda623449b9082117f8b05e84b Mon Sep 17 00:00:00 2001 From: Max Lindqvist Date: Mon, 20 Oct 2025 18:20:31 +0200 Subject: [PATCH 58/76] convert butcher to array --- src/struphy/ode/utils.py | 3 +-- src/struphy/propagators/propagators_markers.py | 7 ++++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/struphy/ode/utils.py b/src/struphy/ode/utils.py index 43b64befe..a2af79914 100644 --- a/src/struphy/ode/utils.py +++ b/src/struphy/ode/utils.py @@ -74,9 +74,8 @@ def __init__(self, algo: str = "rk4"): self._a = np.tri(self.n_stages, k=-1) for l, st in enumerate(a): assert len(st) == l + 1 - st_array = np.array(st) if isinstance(st, tuple) else st - self._a[l + 1, : l + 1] = st_array + self._a[l + 1, : l + 1] = np.array(st) self._conv_rate = conv_rate diff --git a/src/struphy/propagators/propagators_markers.py b/src/struphy/propagators/propagators_markers.py index fff58d514..84c1c9e89 100644 --- a/src/struphy/propagators/propagators_markers.py +++ b/src/struphy/propagators/propagators_markers.py @@ -76,7 +76,8 @@ def __init__( from struphy.utils.arrays import xp as np butcher._a = np.diag(butcher.a, k=-1) - butcher._a = np.array(list(butcher.a) + [0.0]) + butcher._a = np.concatenate([np.asarray(butcher.a), np.array([0.0])]) + args_kernel = ( butcher.a, @@ -717,7 +718,7 @@ def __init__( from struphy.utils.arrays import xp as np butcher._a = np.diag(butcher.a, k=-1) - butcher._a = np.array(list(butcher.a) + [0.0]) + butcher._a = np.concatenate([np.asarray(butcher.a), np.array([0.0])]) kernel = Pyccelkernel(pusher_kernels_gc.push_gc_bxEstar_explicit_multistage) @@ -1136,7 +1137,7 @@ def __init__( from struphy.utils.arrays import xp as np butcher._a = np.diag(butcher.a, k=-1) - butcher._a = np.array(list(butcher.a) + [0.0]) + butcher._a = np.concatenate([np.asarray(butcher.a), np.array([0.0])]) kernel = Pyccelkernel(pusher_kernels_gc.push_gc_Bstar_explicit_multistage) From 388ac98cd8af22269068930da5821b36519009dc Mon Sep 17 00:00:00 2001 From: Max Lindqvist Date: Mon, 20 Oct 2025 18:21:04 +0200 Subject: [PATCH 59/76] vtk with cpu arrays --- src/struphy/main.py | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/src/struphy/main.py b/src/struphy/main.py index 4175d1024..57b86961d 100644 --- a/src/struphy/main.py +++ b/src/struphy/main.py @@ -128,7 +128,7 @@ def main( clone_config.print_clone_config() if "kinetic" in params: clone_config.print_particle_config() - + print('aaa') # instantiate Struphy model (will allocate model objects and associated memory) StruphyModel.verbose = verbose @@ -138,10 +138,10 @@ def main( model_class = getattr(obj, model_name) except AttributeError: pass - + print('a2') with ProfileManager.profile_region("model_class_setup"): model = model_class(params=params, comm=comm, clone_config=clone_config) - + print('bbb') assert isinstance(model, StruphyModel) # store geometry vtk @@ -166,12 +166,23 @@ def main( absB0 = model.equil.absB0(*grids_log) pointData["absB0"] = absB0 - gridToVTK(os.path.join(path_out, "geometry"), *grids_phy, pointData=pointData) + from struphy.utils.arrays import array_backend + if array_backend.backend == "numpy": + gridToVTK(os.path.join(path_out, "geometry"), *grids_phy, pointData=pointData) + else: + # cupy + grids_phy_cpu = [g.get() if isinstance(g, np.ndarray) else g for g in grids_phy] + + # Convert pointData values to NumPy + pointData_cpu = {k: (v.get() if isinstance(v, np.ndarray) else v) for k, v in pointData.items()} + + # Now call gridToVTK safely + gridToVTK(os.path.join(path_out, "geometry"), *grids_phy_cpu, pointData=pointData_cpu) # data object for saving (will either create new hdf5 files if restart==False or open existing files if restart==True) # use MPI.COMM_WORLD as communicator when storing the outputs data = DataContainer(path_out, comm=comm) - + print('ccc') # time quantities (current time value, value in seconds and index) time_state = {} time_state["value"] = np.zeros(1, dtype=float) @@ -182,8 +193,17 @@ def main( for key, val in time_state.items(): key_time = "time/" + key key_time_restart = "restart/time/" + key - data.add_data({key_time: val}) - data.add_data({key_time_restart: val}) + if array_backend.backend == "numpy": + data.add_data({key_time: val}) + data.add_data({key_time_restart: val}) + else: + val_cpu = val.get() if isinstance(val, np.ndarray) else val + + # Then assign + data.add_data({key_time: val_cpu}) + # self._file[key][0] = val_cpu[0] + data.add_data({key_time_restart: val_cpu}) + time_params = params["time"] From 15d542fb9d4048c6f42bcdc772565508c644d418 Mon Sep 17 00:00:00 2001 From: Max Lindqvist Date: Mon, 20 Oct 2025 18:21:59 +0200 Subject: [PATCH 60/76] Formatting --- src/struphy/geometry/transform_kernels.py | 3 ++- src/struphy/main.py | 10 +++++----- src/struphy/propagators/propagators_markers.py | 1 - 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/struphy/geometry/transform_kernels.py b/src/struphy/geometry/transform_kernels.py index 7fba8bf6c..65ebd9d3c 100644 --- a/src/struphy/geometry/transform_kernels.py +++ b/src/struphy/geometry/transform_kernels.py @@ -42,8 +42,9 @@ - 1-form --> vector : (a_1, a_2, a_3) = G^(-1) * (a^1_1, a^1_2, a^1_3) - 2-form --> vector : (a_1, a_2, a_3) = (a^2_1, a^2_2, a^2_3) / |det(DF)| """ -from struphy.utils.arrays import xp as np + from struphy.utils.arrays import array_backend +from struphy.utils.arrays import xp as np if array_backend.backend == "cupy": from cupy import empty, shape, sqrt, zeros diff --git a/src/struphy/main.py b/src/struphy/main.py index 57b86961d..e29365f8e 100644 --- a/src/struphy/main.py +++ b/src/struphy/main.py @@ -128,7 +128,7 @@ def main( clone_config.print_clone_config() if "kinetic" in params: clone_config.print_particle_config() - print('aaa') + print("aaa") # instantiate Struphy model (will allocate model objects and associated memory) StruphyModel.verbose = verbose @@ -138,10 +138,10 @@ def main( model_class = getattr(obj, model_name) except AttributeError: pass - print('a2') + print("a2") with ProfileManager.profile_region("model_class_setup"): model = model_class(params=params, comm=comm, clone_config=clone_config) - print('bbb') + print("bbb") assert isinstance(model, StruphyModel) # store geometry vtk @@ -167,6 +167,7 @@ def main( pointData["absB0"] = absB0 from struphy.utils.arrays import array_backend + if array_backend.backend == "numpy": gridToVTK(os.path.join(path_out, "geometry"), *grids_phy, pointData=pointData) else: @@ -182,7 +183,7 @@ def main( # data object for saving (will either create new hdf5 files if restart==False or open existing files if restart==True) # use MPI.COMM_WORLD as communicator when storing the outputs data = DataContainer(path_out, comm=comm) - print('ccc') + print("ccc") # time quantities (current time value, value in seconds and index) time_state = {} time_state["value"] = np.zeros(1, dtype=float) @@ -203,7 +204,6 @@ def main( data.add_data({key_time: val_cpu}) # self._file[key][0] = val_cpu[0] data.add_data({key_time_restart: val_cpu}) - time_params = params["time"] diff --git a/src/struphy/propagators/propagators_markers.py b/src/struphy/propagators/propagators_markers.py index 84c1c9e89..33af50ed5 100644 --- a/src/struphy/propagators/propagators_markers.py +++ b/src/struphy/propagators/propagators_markers.py @@ -77,7 +77,6 @@ def __init__( butcher._a = np.diag(butcher.a, k=-1) butcher._a = np.concatenate([np.asarray(butcher.a), np.array([0.0])]) - args_kernel = ( butcher.a, From 6462d0e94b325841fb5204bf1ca601587260ed14 Mon Sep 17 00:00:00 2001 From: Max Lindqvist Date: Mon, 20 Oct 2025 18:29:36 +0200 Subject: [PATCH 61/76] Use datacontainer wit numpy arrays always --- src/struphy/io/output_handling.py | 2 +- src/struphy/main.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/struphy/io/output_handling.py b/src/struphy/io/output_handling.py index 79e23692b..17218f35a 100644 --- a/src/struphy/io/output_handling.py +++ b/src/struphy/io/output_handling.py @@ -3,7 +3,7 @@ import h5py -from struphy.utils.arrays import xp as np +import numpy as np class DataContainer: diff --git a/src/struphy/main.py b/src/struphy/main.py index e29365f8e..1590f027a 100644 --- a/src/struphy/main.py +++ b/src/struphy/main.py @@ -198,9 +198,10 @@ def main( data.add_data({key_time: val}) data.add_data({key_time_restart: val}) else: - val_cpu = val.get() if isinstance(val, np.ndarray) else val + val_cpu = val.get()# if isinstance(val, np.ndarray) else val # Then assign + print(f"{val_cpu = } {type(val_cpu) = }") data.add_data({key_time: val_cpu}) # self._file[key][0] = val_cpu[0] data.add_data({key_time_restart: val_cpu}) From a228d0e6b745fb0c02ec6c33cb9c5f7a859c2df2 Mon Sep 17 00:00:00 2001 From: Max Lindqvist Date: Mon, 20 Oct 2025 18:50:40 +0200 Subject: [PATCH 62/76] bcount as numpy --- src/struphy/pic/base.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/struphy/pic/base.py b/src/struphy/pic/base.py index 48d643c0f..aca143fc7 100644 --- a/src/struphy/pic/base.py +++ b/src/struphy/pic/base.py @@ -2602,7 +2602,15 @@ def check_and_assign_particles_to_boxes(self): """Check whether the box array has enough columns (detect load imbalance wrt to sorting boxes), and then assigne the particles to boxes.""" - bcount = np.bincount(np.int64(self.markers_wo_holes[:, -2])) + from struphy.utils.arrays import array_backend + if array_backend.backend == "numpy": + bcount = np.bincount(np.int64(self.markers_wo_holes[:, -2])) + else: + import cupy as cp + indices = self.markers_wo_holes[:, -2] + indices = indices.astype(cp.int64) + bcount = cp.bincount(indices) + max_in_box = np.max(bcount) if max_in_box > self._sorting_boxes.boxes.shape[1]: warnings.warn( From 57ed6adc17e8eb86458bb3adc8d7b023587b4efc Mon Sep 17 00:00:00 2001 From: Max Lindqvist Date: Mon, 20 Oct 2025 19:04:39 +0200 Subject: [PATCH 63/76] Start fixing update_scalar --- src/struphy/main.py | 5 +++-- src/struphy/models/base.py | 17 ++++++++++------- src/struphy/models/toy.py | 2 +- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/struphy/main.py b/src/struphy/main.py index 1590f027a..11d19f659 100644 --- a/src/struphy/main.py +++ b/src/struphy/main.py @@ -167,7 +167,8 @@ def main( pointData["absB0"] = absB0 from struphy.utils.arrays import array_backend - + + print('calling gridToVTK') if array_backend.backend == "numpy": gridToVTK(os.path.join(path_out, "geometry"), *grids_phy, pointData=pointData) else: @@ -179,7 +180,7 @@ def main( # Now call gridToVTK safely gridToVTK(os.path.join(path_out, "geometry"), *grids_phy_cpu, pointData=pointData_cpu) - + # data object for saving (will either create new hdf5 files if restart==False or open existing files if restart==True) # use MPI.COMM_WORLD as communicator when storing the outputs data = DataContainer(path_out, comm=comm) diff --git a/src/struphy/models/base.py b/src/struphy/models/base.py index cf7467585..ee1d1fb02 100644 --- a/src/struphy/models/base.py +++ b/src/struphy/models/base.py @@ -186,7 +186,7 @@ def __init__( # if self.rank_world == 0: # self._show_chosen_options() - + # set propagators base class attributes (then available to all propagators) Propagator.derham = self.derham Propagator.domain = self.domain @@ -549,10 +549,11 @@ def update_scalar(self, name, value=None): if summands is None: # Ensure the value is a float if there are no summands - assert isinstance(value, float) - - # Create a numpy array to hold the scalar value - value_array = np.array([value], dtype=np.float64) + if isinstance(value, float): + # Create a numpy array to hold the scalar value + value_array = np.array([value]) + else: + value_array = np.asarray(value) # Perform MPI operations based on the compute flags if "sum_world" in compute_operations and self.comm_world is not None: @@ -590,10 +591,12 @@ def update_scalar(self, name, value=None): if "divide_n_mks" in compute_operations: # Initialize the total number of markers - n_mks_tot = np.array([self.pointer[species].Np]) - value_array /= n_mks_tot + value_array /= self.pointer[species].Np # Update the scalar value + print(f"{type(self._scalar_quantities[name]['value'][0]) = }") + print(f"{value_array = }") + print(f"{type(value_array) = }") self._scalar_quantities[name]["value"][0] = value_array[0] else: diff --git a/src/struphy/models/toy.py b/src/struphy/models/toy.py index e65212d6f..51af75343 100644 --- a/src/struphy/models/toy.py +++ b/src/struphy/models/toy.py @@ -140,7 +140,7 @@ def propagators_dct(): def __init__(self, params, comm, clone_config=None): # initialize base class super().__init__(params, comm=comm, clone_config=clone_config) - + print('after super') # prelim ions_params = self.kinetic["ions"]["params"] From 77132e016e5a5987d10a413d6d2ae3607af531f8 Mon Sep 17 00:00:00 2001 From: Max Lindqvist Date: Mon, 20 Oct 2025 19:07:16 +0200 Subject: [PATCH 64/76] Ensure that value_array is a cupy array --- src/struphy/models/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/struphy/models/base.py b/src/struphy/models/base.py index ee1d1fb02..d791659fd 100644 --- a/src/struphy/models/base.py +++ b/src/struphy/models/base.py @@ -554,7 +554,7 @@ def update_scalar(self, name, value=None): value_array = np.array([value]) else: value_array = np.asarray(value) - + value_array = np.array(value_array) # Perform MPI operations based on the compute flags if "sum_world" in compute_operations and self.comm_world is not None: self.comm_world.Allreduce( From d3b5a341b3cde84d23c27899be20148f795667e6 Mon Sep 17 00:00:00 2001 From: Max Lindqvist Date: Tue, 21 Oct 2025 08:18:46 +0200 Subject: [PATCH 65/76] Fixed update_scalar --- src/struphy/models/base.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/struphy/models/base.py b/src/struphy/models/base.py index d791659fd..02d0d0eb6 100644 --- a/src/struphy/models/base.py +++ b/src/struphy/models/base.py @@ -594,10 +594,11 @@ def update_scalar(self, name, value=None): value_array /= self.pointer[species].Np # Update the scalar value - print(f"{type(self._scalar_quantities[name]['value'][0]) = }") - print(f"{value_array = }") - print(f"{type(value_array) = }") - self._scalar_quantities[name]["value"][0] = value_array[0] + if value_array.ndim == 0: + self._scalar_quantities[name]["value"][0] = value_array.item() + else: + self._scalar_quantities[name]["value"][0] = value_array[0] + else: # Sum the values of the summands From 0775b23159c8886b670dcd0e0dd7a8b426e6ebd1 Mon Sep 17 00:00:00 2001 From: Max Lindqvist Date: Tue, 21 Oct 2025 14:05:29 +0200 Subject: [PATCH 66/76] Convert lists to arrays --- src/struphy/models/base.py | 2 +- src/struphy/pic/base.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/struphy/models/base.py b/src/struphy/models/base.py index 02d0d0eb6..df55fcdf4 100644 --- a/src/struphy/models/base.py +++ b/src/struphy/models/base.py @@ -775,7 +775,7 @@ def update_distr_functions(self): h2 = 1 / obj.boxes_per_dim[1] h3 = 1 / obj.boxes_per_dim[2] - ndim = np.count_nonzero([d > 1 for d in obj.boxes_per_dim]) + ndim = np.count_nonzero(np.array([d > 1 for d in obj.boxes_per_dim])) if ndim == 0: kernel_type = "gaussian_3d" else: diff --git a/src/struphy/pic/base.py b/src/struphy/pic/base.py index aca143fc7..c643b14b7 100644 --- a/src/struphy/pic/base.py +++ b/src/struphy/pic/base.py @@ -1877,7 +1877,7 @@ def binning(self, components, bin_edges, divide_by_jac=True): The reconstructed delta-f distribution function. """ - assert np.count_nonzero(components) == len(bin_edges) + assert np.count_nonzero(np.array(components)) == len(bin_edges) # volume of a bin bin_vol = 1.0 From b5efe7be072d5255e727494f59d60f6508cef9eb Mon Sep 17 00:00:00 2001 From: Max Lindqvist Date: Wed, 22 Oct 2025 08:48:27 +0200 Subject: [PATCH 67/76] Bufixes after merge --- src/struphy/bsplines/bsplines.py | 4 ++-- src/struphy/feec/psydac_derham.py | 10 ++++------ src/struphy/geometry/transform_kernels.py | 2 +- .../kernel_arguments/pusher_args_kernels.py | 14 +++++++------- src/struphy/main.py | 6 +++--- src/struphy/ode/utils.py | 2 +- src/struphy/pic/base.py | 2 +- src/struphy/utils/pyccel.py | 9 ++++----- 8 files changed, 23 insertions(+), 26 deletions(-) diff --git a/src/struphy/bsplines/bsplines.py b/src/struphy/bsplines/bsplines.py index f721ba9c4..d3f5d6b01 100644 --- a/src/struphy/bsplines/bsplines.py +++ b/src/struphy/bsplines/bsplines.py @@ -611,8 +611,8 @@ def make_knots(breaks, degree, periodic): if periodic: period = breaks[-1] - breaks[0] - T[0:p] = np.asarray([xi - period for xi in breaks[-p - 1 : -1]]) - T[-p:] = np.asarray([xi + period for xi in breaks[1 : p + 1]]) + T[0:p] = xp.asarray([xi - period for xi in breaks[-p - 1 : -1]]) + T[-p:] = xp.asarray([xi + period for xi in breaks[1 : p + 1]]) else: T[0:p] = breaks[0] T[-p:] = breaks[-1] diff --git a/src/struphy/feec/psydac_derham.py b/src/struphy/feec/psydac_derham.py index dba3b008b..522fdb667 100644 --- a/src/struphy/feec/psydac_derham.py +++ b/src/struphy/feec/psydac_derham.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 import importlib.metadata - +import numpy as np import psydac.core.bsplines as bsp from psydac.ddm.cart import DomainDecomposition from psydac.ddm.mpi import MockComm, MockMPI @@ -2785,12 +2785,12 @@ def get_pts_and_wts(space_1d, start, end, n_quad=None, polar_shift=False): union_breaks = space_1d.breaks[:-1] # Make union of Greville and break points - # tmp = set(np.round(space_1d.histopolation_grid, decimals=14)).union( - # np.round(union_breaks, decimals=14), + # tmp = set(xp.round(space_1d.histopolation_grid, decimals=14)).union( + # xp.round(union_breaks, decimals=14), # ) # tmp = list(tmp) # tmp.sort() - # tmp_a = np.array(tmp) + # tmp_a = xp.array(tmp) tmp = set(xp.round(space_1d.histopolation_grid, decimals=14).tolist()).union( xp.round(union_breaks, decimals=14).tolist() @@ -2823,8 +2823,6 @@ def get_pts_and_wts(space_1d, start, end, n_quad=None, polar_shift=False): # products of basis functions are integrated exactly n_quad = space_1d.degree + 1 - import numpy as np - pts_loc, wts_loc = np.polynomial.legendre.leggauss(n_quad) if "cupy" in xp.__name__: diff --git a/src/struphy/geometry/transform_kernels.py b/src/struphy/geometry/transform_kernels.py index 65ebd9d3c..3ed65b9b2 100644 --- a/src/struphy/geometry/transform_kernels.py +++ b/src/struphy/geometry/transform_kernels.py @@ -44,7 +44,7 @@ """ from struphy.utils.arrays import array_backend -from struphy.utils.arrays import xp as np +from struphy.utils.arrays import xp if array_backend.backend == "cupy": from cupy import empty, shape, sqrt, zeros diff --git a/src/struphy/kernel_arguments/pusher_args_kernels.py b/src/struphy/kernel_arguments/pusher_args_kernels.py index dfd49b108..2e81ba494 100644 --- a/src/struphy/kernel_arguments/pusher_args_kernels.py +++ b/src/struphy/kernel_arguments/pusher_args_kernels.py @@ -1,5 +1,5 @@ # from numpy import copy -from struphy.utils.arrays import xp as np +from struphy.utils.arrays import xp class MarkerArguments: @@ -99,12 +99,12 @@ def __init__( self.tn3 = tn3 self.starts = starts - self.bn1 = np.empty(int(pn[0] + 1), dtype=float) - self.bn2 = np.empty(int(pn[1] + 1), dtype=float) - self.bn3 = np.empty(int(pn[2] + 1), dtype=float) - self.bd1 = np.empty(int(pn[0]), dtype=float) - self.bd2 = np.empty(int(pn[1]), dtype=float) - self.bd3 = np.empty(int(pn[2]), dtype=float) + self.bn1 = xp.empty(int(pn[0] + 1), dtype=float) + self.bn2 = xp.empty(int(pn[1] + 1), dtype=float) + self.bn3 = xp.empty(int(pn[2] + 1), dtype=float) + self.bd1 = xp.empty(int(pn[0]), dtype=float) + self.bd2 = xp.empty(int(pn[1]), dtype=float) + self.bd3 = xp.empty(int(pn[2]), dtype=float) class DomainArguments: diff --git a/src/struphy/main.py b/src/struphy/main.py index 8faac8a70..108dfff85 100644 --- a/src/struphy/main.py +++ b/src/struphy/main.py @@ -261,10 +261,10 @@ def run( gridToVTK(os.path.join(path_out, "geometry"), *grids_phy, pointData=pointData) else: # cupy - grids_phy_cpu = [g.get() if isinstance(g, np.ndarray) else g for g in grids_phy] + grids_phy_cpu = [g.get() if isinstance(g, xp.ndarray) else g for g in grids_phy] # Convert pointData values to NumPy - pointData_cpu = {k: (v.get() if isinstance(v, np.ndarray) else v) for k, v in pointData.items()} + pointData_cpu = {k: (v.get() if isinstance(v, xp.ndarray) else v) for k, v in pointData.items()} # Now call gridToVTK safely gridToVTK(os.path.join(path_out, "geometry"), *grids_phy_cpu, pointData=pointData_cpu) @@ -287,7 +287,7 @@ def run( data.add_data({key_time: val}) data.add_data({key_time_restart: val}) else: - val_cpu = val.get()# if isinstance(val, np.ndarray) else val + val_cpu = val.get()# if isinstance(val, xp.ndarray) else val # Then assign print(f"{val_cpu = } {type(val_cpu) = }") diff --git a/src/struphy/ode/utils.py b/src/struphy/ode/utils.py index 5d80789b5..b39cc6a74 100644 --- a/src/struphy/ode/utils.py +++ b/src/struphy/ode/utils.py @@ -78,7 +78,7 @@ def __post_init__(self): for l, st in enumerate(a): assert len(st) == l + 1 - self._a[l + 1, : l + 1] = np.array(st) + self._a[l + 1, : l + 1] = xp.array(st) self._conv_rate = conv_rate diff --git a/src/struphy/pic/base.py b/src/struphy/pic/base.py index de510aba1..21b3817e5 100644 --- a/src/struphy/pic/base.py +++ b/src/struphy/pic/base.py @@ -2424,7 +2424,7 @@ def _set_boxes(self): n_particles = self._markers_shape[0] n_mkr = int(n_particles / n_box_in) + 1 n_cols = round( - float(n_mkr) * (1 + 1 / float(np.sqrt(n_mkr)) + self._box_bufsize), + float(n_mkr) * (1 + 1 / float(xp.sqrt(n_mkr)) + self._box_bufsize), ) # cartesian boxes diff --git a/src/struphy/utils/pyccel.py b/src/struphy/utils/pyccel.py index cc9bf727d..d7cbd4fb5 100644 --- a/src/struphy/utils/pyccel.py +++ b/src/struphy/utils/pyccel.py @@ -1,21 +1,20 @@ from typing import Any, Callable -from struphy.utils.arrays import xp as np - +from struphy.utils.arrays import xp class Pyccelkernel: def __init__(self, kernel: Callable[..., Any], use_cupy: bool = False) -> None: self._kernel = kernel self._use_cupy = use_cupy - if "cupy" in np.__name__: + if "cupy" in xp.__name__: self._use_cupy = True def __call__(self, *args: Any, **kwargs: Any) -> Any: if self.use_cupy: # Convert all args from CuPy to NumPy - args_np = [x.get() if isinstance(x, np.ndarray) else x for x in args] + args_np = [x.get() if isinstance(x, xp.ndarray) else x for x in args] # Convert all kwargs from CuPy to NumPy - kwargs_np = {k: v.get() if isinstance(v, np.ndarray) else v for k, v in kwargs.items()} + kwargs_np = {k: v.get() if isinstance(v, xp.ndarray) else v for k, v in kwargs.items()} return self._kernel(*args_np, **kwargs_np) else: return self._kernel(*args, **kwargs) From 2d7dc4c25eb2352ac03c1919d080a2692d6ade8f Mon Sep 17 00:00:00 2001 From: Max Lindqvist Date: Wed, 22 Oct 2025 08:58:10 +0200 Subject: [PATCH 68/76] bugfix --- src/struphy/models/base.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/struphy/models/base.py b/src/struphy/models/base.py index a9ecb4112..dc86c66de 100644 --- a/src/struphy/models/base.py +++ b/src/struphy/models/base.py @@ -563,7 +563,8 @@ def update_scalar(self, name, value=None): if "divide_n_mks" in compute_operations: # Initialize the total number of markers - value_array /= self.pointer[species].Np + n_mks_tot = xp.array([variable.particles.Np]) + value_array /= n_mks_tot # Update the scalar value if value_array.ndim == 0: From 08f8fbd6cccc15c60c517fb566ebd16bd01a2bc8 Mon Sep 17 00:00:00 2001 From: Max Lindqvist Date: Wed, 22 Oct 2025 09:01:14 +0200 Subject: [PATCH 69/76] Converted list to xp array --- src/struphy/feec/psydac_derham.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/struphy/feec/psydac_derham.py b/src/struphy/feec/psydac_derham.py index 522fdb667..2ecaa9df2 100644 --- a/src/struphy/feec/psydac_derham.py +++ b/src/struphy/feec/psydac_derham.py @@ -117,7 +117,7 @@ def __init__( if dirichlet_bc is not None: assert len(dirichlet_bc) == 3 # make sure that boundary conditions are compatible with spline space - assert xp.all([bc == (False, False) for i, bc in enumerate(dirichlet_bc) if spl_kind[i]]) + assert xp.all(xp.array([bc == (False, False) for i, bc in enumerate(dirichlet_bc) if spl_kind[i]])) self._dirichlet_bc = dirichlet_bc From a2504fdc64f665a80defe587c5573bb1aa36cae4 Mon Sep 17 00:00:00 2001 From: Max Lindqvist Date: Wed, 22 Oct 2025 13:23:11 +0200 Subject: [PATCH 70/76] Replaced arrays.py with cunumpy --- pyproject.toml | 1 + src/struphy/bsplines/bsplines.py | 2 +- .../bsplines/tests/test_bsplines_kernels.py | 2 +- .../bsplines/tests/test_eval_spline_mpi.py | 2 +- src/struphy/console/profile.py | 2 +- src/struphy/diagnostics/console_diagn.py | 2 +- src/struphy/diagnostics/continuous_spectra.py | 4 +- src/struphy/diagnostics/diagn_tools.py | 2 +- .../diagnostics/paraview/mesh_creator.py | 2 +- src/struphy/dispersion_relations/analytic.py | 2 +- src/struphy/dispersion_relations/base.py | 2 +- src/struphy/dispersion_relations/utilities.py | 2 +- src/struphy/eigenvalue_solvers/derivatives.py | 2 +- .../legacy/MHD_eigenvalues_cylinder_1D.py | 2 +- .../control_variates/control_variate.py | 2 +- .../fB_massless_control_variate.py | 2 +- .../fnB_massless_control_variate.py | 2 +- .../massless_control_variate.py | 2 +- .../legacy/emw_operators.py | 2 +- .../legacy/inner_products_1d.py | 2 +- .../legacy/inner_products_2d.py | 2 +- .../legacy/inner_products_3d.py | 2 +- .../eigenvalue_solvers/legacy/l2_error_1d.py | 2 +- .../eigenvalue_solvers/legacy/l2_error_2d.py | 2 +- .../eigenvalue_solvers/legacy/l2_error_3d.py | 2 +- .../legacy/mass_matrices_3d_pre.py | 2 +- .../legacy/massless_operators/fB_arrays.py | 2 +- .../fB_massless_linear_operators.py | 2 +- .../legacy/massless_operators/fB_vv_kernel.py | 2 +- .../legacy/mhd_operators_MF.py | 2 +- .../pro_local/mhd_operators_3d_local.py | 2 +- .../pro_local/projectors_local.py | 2 +- .../shape_function_projectors_L2.py | 2 +- .../shape_function_projectors_local.py | 2 +- .../eigenvalue_solvers/mass_matrices_1d.py | 2 +- .../eigenvalue_solvers/mass_matrices_2d.py | 2 +- .../eigenvalue_solvers/mass_matrices_3d.py | 2 +- .../mhd_axisymmetric_main.py | 2 +- .../mhd_axisymmetric_pproc.py | 2 +- .../eigenvalue_solvers/mhd_operators.py | 2 +- .../eigenvalue_solvers/mhd_operators_core.py | 2 +- .../eigenvalue_solvers/projectors_global.py | 2 +- .../eigenvalue_solvers/spline_space.py | 2 +- src/struphy/examples/_draw_parallel.py | 2 +- .../examples/restelli2018/callables.py | 2 +- src/struphy/feec/basis_projection_ops.py | 2 +- src/struphy/feec/linear_operators.py | 2 +- src/struphy/feec/mass.py | 2 +- src/struphy/feec/preconditioner.py | 2 +- src/struphy/feec/projectors.py | 2 +- src/struphy/feec/psydac_derham.py | 2 +- src/struphy/feec/tests/test_basis_ops.py | 6 +- src/struphy/feec/tests/test_derham.py | 2 +- src/struphy/feec/tests/test_eval_field.py | 2 +- src/struphy/feec/tests/test_field_init.py | 8 +-- src/struphy/feec/tests/test_l2_projectors.py | 2 +- .../feec/tests/test_local_projectors.py | 2 +- .../feec/tests/test_lowdim_nel_is_1.py | 2 +- src/struphy/feec/tests/test_mass_matrices.py | 8 +-- .../feec/tests/test_toarray_struphy.py | 2 +- .../feec/tests/test_tosparse_struphy.py | 2 +- src/struphy/feec/tests/xx_test_preconds.py | 2 +- src/struphy/feec/utilities.py | 2 +- .../feec/utilities_local_projectors.py | 2 +- src/struphy/feec/variational_utilities.py | 2 +- src/struphy/fields_background/base.py | 2 +- .../fields_background/coil_fields/base.py | 2 +- .../coil_fields/coil_fields.py | 2 +- src/struphy/fields_background/equils.py | 2 +- .../tests/test_desc_equil.py | 2 +- .../tests/test_generic_equils.py | 2 +- .../tests/test_mhd_equils.py | 2 +- .../tests/test_numerical_mhd_equil.py | 2 +- src/struphy/geometry/base.py | 2 +- src/struphy/geometry/domains.py | 2 +- src/struphy/geometry/tests/test_domain.py | 12 ++-- src/struphy/geometry/utilities.py | 2 +- src/struphy/initial/eigenfunctions.py | 2 +- src/struphy/initial/perturbations.py | 2 +- .../initial/tests/test_init_perturbations.py | 2 +- src/struphy/initial/utilities.py | 2 +- src/struphy/io/options.py | 2 +- src/struphy/io/output_handling.py | 2 +- src/struphy/io/setup.py | 2 +- src/struphy/kinetic_background/base.py | 2 +- src/struphy/kinetic_background/maxwellians.py | 2 +- .../kinetic_background/moment_functions.py | 2 +- .../kinetic_background/tests/test_base.py | 2 +- .../tests/test_maxwellians.py | 14 ++--- src/struphy/linear_algebra/linalg_kron.py | 2 +- src/struphy/linear_algebra/saddle_point.py | 2 +- .../tests/test_saddlepoint_massmatrices.py | 4 +- .../tests/test_stencil_dot_kernels.py | 4 +- .../tests/test_stencil_transpose_kernels.py | 4 +- src/struphy/main.py | 2 +- src/struphy/models/base.py | 2 +- src/struphy/models/fluid.py | 2 +- src/struphy/models/hybrid.py | 2 +- src/struphy/models/kinetic.py | 2 +- src/struphy/models/species.py | 2 +- .../models/tests/test_verif_EulerSPH.py | 2 +- .../models/tests/test_verif_LinearMHD.py | 2 +- .../models/tests/test_verif_Maxwell.py | 2 +- .../models/tests/test_verif_Poisson.py | 2 +- .../test_verif_VlasovAmpereOneSpecies.py | 2 +- src/struphy/models/tests/verification.py | 2 +- src/struphy/models/toy.py | 2 +- src/struphy/models/variables.py | 2 +- src/struphy/ode/solvers.py | 2 +- src/struphy/ode/tests/test_ode_feec.py | 2 +- src/struphy/ode/utils.py | 2 +- .../pic/accumulation/particles_to_grid.py | 2 +- src/struphy/pic/base.py | 2 +- src/struphy/pic/particles.py | 2 +- src/struphy/pic/pushing/pusher.py | 2 +- src/struphy/pic/sobol_seq.py | 2 +- src/struphy/pic/tests/test_accum_vec_H1.py | 2 +- src/struphy/pic/tests/test_accumulation.py | 2 +- src/struphy/pic/tests/test_binning.py | 8 +-- src/struphy/pic/tests/test_draw_parallel.py | 2 +- src/struphy/pic/tests/test_mat_vec_filler.py | 2 +- .../test_pic_legacy_files/accumulation.py | 2 +- .../pic/tests/test_pic_legacy_files/pusher.py | 2 +- src/struphy/pic/tests/test_pushers.py | 12 ++-- src/struphy/pic/tests/test_sorting.py | 2 +- src/struphy/pic/tests/test_sph.py | 2 +- src/struphy/pic/tests/test_tesselation.py | 2 +- src/struphy/pic/utilities.py | 2 +- src/struphy/polar/basic.py | 2 +- src/struphy/polar/extraction_operators.py | 2 +- src/struphy/polar/linear_operators.py | 2 +- .../polar/tests/test_legacy_polar_splines.py | 2 +- src/struphy/polar/tests/test_polar.py | 4 +- .../likwid/plot_likwidproject.py | 2 +- .../likwid/plot_time_traces.py | 2 +- .../likwid/roofline_plotter.py | 2 +- .../post_processing/orbits/orbits_tools.py | 2 +- .../post_processing/post_processing_tools.py | 2 +- src/struphy/post_processing/pproc_struphy.py | 2 +- .../post_processing/profile_struphy.py | 2 +- src/struphy/profiling/profiling.py | 2 +- src/struphy/propagators/base.py | 2 +- .../propagators/propagators_coupling.py | 2 +- src/struphy/propagators/propagators_fields.py | 2 +- .../propagators/propagators_markers.py | 12 ++-- .../tests/test_gyrokinetic_poisson.py | 2 +- src/struphy/propagators/tests/test_poisson.py | 2 +- src/struphy/utils/arrays.py | 59 ------------------- src/struphy/utils/clone_config.py | 2 +- src/struphy/utils/utils.py | 2 +- 150 files changed, 186 insertions(+), 244 deletions(-) delete mode 100644 src/struphy/utils/arrays.py diff --git a/pyproject.toml b/pyproject.toml index a2a6e08a1..88e6ce6a7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,6 +23,7 @@ classifiers = [ ] dependencies = [ 'numpy', + 'cunumpy', 'pyccel>=2.0', 'psydac @ git+https://github.com/max-models/psydac-for-struphy.git@devel-tiny', 'scipy', diff --git a/src/struphy/bsplines/bsplines.py b/src/struphy/bsplines/bsplines.py index ab56afd78..a04ee4851 100644 --- a/src/struphy/bsplines/bsplines.py +++ b/src/struphy/bsplines/bsplines.py @@ -16,7 +16,7 @@ """ -from struphy.utils.arrays import xp +import cunumpy as xp __all__ = [ "find_span", diff --git a/src/struphy/bsplines/tests/test_bsplines_kernels.py b/src/struphy/bsplines/tests/test_bsplines_kernels.py index 3800c8653..6aab9e0de 100644 --- a/src/struphy/bsplines/tests/test_bsplines_kernels.py +++ b/src/struphy/bsplines/tests/test_bsplines_kernels.py @@ -3,7 +3,7 @@ import pytest from psydac.ddm.mpi import mpi as MPI -from struphy.utils.arrays import xp +import cunumpy as xp @pytest.mark.parametrize("Nel", [[8, 9, 10]]) diff --git a/src/struphy/bsplines/tests/test_eval_spline_mpi.py b/src/struphy/bsplines/tests/test_eval_spline_mpi.py index 0202963ce..9f867edea 100644 --- a/src/struphy/bsplines/tests/test_eval_spline_mpi.py +++ b/src/struphy/bsplines/tests/test_eval_spline_mpi.py @@ -4,7 +4,7 @@ import pytest from psydac.ddm.mpi import mpi as MPI -from struphy.utils.arrays import xp +import cunumpy as xp @pytest.mark.parametrize("Nel", [[8, 9, 10]]) diff --git a/src/struphy/console/profile.py b/src/struphy/console/profile.py index 11c753a15..167c2905a 100644 --- a/src/struphy/console/profile.py +++ b/src/struphy/console/profile.py @@ -11,7 +11,7 @@ def struphy_profile(dirs, replace, all, n_lines, print_callers, savefig): import struphy.utils.utils as utils from struphy.post_processing.cprofile_analyser import get_cprofile_data, replace_keys - from struphy.utils.arrays import xp + import cunumpy as xp # Read struphy state file state = utils.read_state() diff --git a/src/struphy/diagnostics/console_diagn.py b/src/struphy/diagnostics/console_diagn.py index 3fa1f11ca..a835cf130 100644 --- a/src/struphy/diagnostics/console_diagn.py +++ b/src/struphy/diagnostics/console_diagn.py @@ -11,7 +11,7 @@ import struphy import struphy.utils.utils as utils from struphy.diagnostics.diagn_tools import plot_distr_fun, plot_scalars, plots_videos_2d -from struphy.utils.arrays import xp +import cunumpy as xp def main(): diff --git a/src/struphy/diagnostics/continuous_spectra.py b/src/struphy/diagnostics/continuous_spectra.py index ce805a45d..767273d04 100644 --- a/src/struphy/diagnostics/continuous_spectra.py +++ b/src/struphy/diagnostics/continuous_spectra.py @@ -38,7 +38,7 @@ def get_mhd_continua_2d(space, domain, omega2, U_eig, m_range, omega_A, div_tol, """ import struphy.bsplines.bsplines as bsp - from struphy.utils.arrays import xp + import cunumpy as xp # greville points in radial direction (s) gN_1 = bsp.greville(space.T[0], space.p[0], space.spl_kind[0]) @@ -153,7 +153,7 @@ def get_mhd_continua_2d(space, domain, omega2, U_eig, m_range, omega_A, div_tol, import yaml - from struphy.utils.arrays import xp + import cunumpy as xp # parse arguments parser = argparse.ArgumentParser( diff --git a/src/struphy/diagnostics/diagn_tools.py b/src/struphy/diagnostics/diagn_tools.py index 88c81409c..cdb564f27 100644 --- a/src/struphy/diagnostics/diagn_tools.py +++ b/src/struphy/diagnostics/diagn_tools.py @@ -10,7 +10,7 @@ from tqdm import tqdm from struphy.dispersion_relations import analytic -from struphy.utils.arrays import xp +import cunumpy as xp def power_spectrum_2d( diff --git a/src/struphy/diagnostics/paraview/mesh_creator.py b/src/struphy/diagnostics/paraview/mesh_creator.py index 2446d0391..76a8d89a8 100644 --- a/src/struphy/diagnostics/paraview/mesh_creator.py +++ b/src/struphy/diagnostics/paraview/mesh_creator.py @@ -4,7 +4,7 @@ from vtkmodules.util.numpy_support import vtk_to_numpy as vtk2np from vtkmodules.vtkCommonDataModel import vtkUnstructuredGrid -from struphy.utils.arrays import xp +import cunumpy as xp def make_ugrid_and_write_vtu(filename: str, writer, vtk_dir, gvec, s_range, u_range, v_range, periodic): diff --git a/src/struphy/dispersion_relations/analytic.py b/src/struphy/dispersion_relations/analytic.py index 756840f9a..747e97379 100644 --- a/src/struphy/dispersion_relations/analytic.py +++ b/src/struphy/dispersion_relations/analytic.py @@ -6,7 +6,7 @@ from struphy.dispersion_relations.base import ContinuousSpectra1D, DispersionRelations1D from struphy.dispersion_relations.utilities import Zplasma from struphy.fields_background.equils import set_defaults -from struphy.utils.arrays import xp +import cunumpy as xp class Maxwell1D(DispersionRelations1D): diff --git a/src/struphy/dispersion_relations/base.py b/src/struphy/dispersion_relations/base.py index dd7293867..845bdb2cb 100644 --- a/src/struphy/dispersion_relations/base.py +++ b/src/struphy/dispersion_relations/base.py @@ -4,7 +4,7 @@ from matplotlib import pyplot as plt -from struphy.utils.arrays import xp +import cunumpy as xp class DispersionRelations1D(metaclass=ABCMeta): diff --git a/src/struphy/dispersion_relations/utilities.py b/src/struphy/dispersion_relations/utilities.py index f84aa1acf..535bc9a5d 100644 --- a/src/struphy/dispersion_relations/utilities.py +++ b/src/struphy/dispersion_relations/utilities.py @@ -1,6 +1,6 @@ from scipy.special import erfi -from struphy.utils.arrays import xp +import cunumpy as xp def Zplasma(xi, der=0): diff --git a/src/struphy/eigenvalue_solvers/derivatives.py b/src/struphy/eigenvalue_solvers/derivatives.py index 738b1537a..d8c7b9df3 100644 --- a/src/struphy/eigenvalue_solvers/derivatives.py +++ b/src/struphy/eigenvalue_solvers/derivatives.py @@ -8,7 +8,7 @@ import scipy.sparse as spa -from struphy.utils.arrays import xp +import cunumpy as xp # ================== 1d incident matrix ======================= diff --git a/src/struphy/eigenvalue_solvers/legacy/MHD_eigenvalues_cylinder_1D.py b/src/struphy/eigenvalue_solvers/legacy/MHD_eigenvalues_cylinder_1D.py index b7d0d30d7..732cd5709 100644 --- a/src/struphy/eigenvalue_solvers/legacy/MHD_eigenvalues_cylinder_1D.py +++ b/src/struphy/eigenvalue_solvers/legacy/MHD_eigenvalues_cylinder_1D.py @@ -9,7 +9,7 @@ import struphy.eigenvalue_solvers.mass_matrices_1d as mass import struphy.eigenvalue_solvers.projectors_global as pro import struphy.eigenvalue_solvers.spline_space as spl -from struphy.utils.arrays import xp +import cunumpy as xp # numerical solution of the general ideal MHD eigenvalue problem in a cylinder using 1d B-splines in radial direction diff --git a/src/struphy/eigenvalue_solvers/legacy/control_variates/control_variate.py b/src/struphy/eigenvalue_solvers/legacy/control_variates/control_variate.py index 448298451..719447f7e 100644 --- a/src/struphy/eigenvalue_solvers/legacy/control_variates/control_variate.py +++ b/src/struphy/eigenvalue_solvers/legacy/control_variates/control_variate.py @@ -10,7 +10,7 @@ import struphy.feec.basics.kernels_3d as ker import struphy.feec.control_variates.kernels_control_variate as ker_cv -from struphy.utils.arrays import xp +import cunumpy as xp class terms_control_variate: diff --git a/src/struphy/eigenvalue_solvers/legacy/control_variates/kinetic_extended/fB_massless_control_variate.py b/src/struphy/eigenvalue_solvers/legacy/control_variates/kinetic_extended/fB_massless_control_variate.py index d4713c12a..11ecd04f3 100644 --- a/src/struphy/eigenvalue_solvers/legacy/control_variates/kinetic_extended/fB_massless_control_variate.py +++ b/src/struphy/eigenvalue_solvers/legacy/control_variates/kinetic_extended/fB_massless_control_variate.py @@ -3,7 +3,7 @@ import struphy.feec.basics.kernels_3d as ker import struphy.feec.control_variates.kinetic_extended.fB_massless_kernels_control_variate as ker_cv import struphy.feec.control_variates.kinetic_extended.fnB_massless_cv_kernel_2 as ker_cv2 -from struphy.utils.arrays import xp +import cunumpy as xp def bv_right( diff --git a/src/struphy/eigenvalue_solvers/legacy/control_variates/kinetic_extended/fnB_massless_control_variate.py b/src/struphy/eigenvalue_solvers/legacy/control_variates/kinetic_extended/fnB_massless_control_variate.py index b8673c837..14e3315fd 100644 --- a/src/struphy/eigenvalue_solvers/legacy/control_variates/kinetic_extended/fnB_massless_control_variate.py +++ b/src/struphy/eigenvalue_solvers/legacy/control_variates/kinetic_extended/fnB_massless_control_variate.py @@ -2,7 +2,7 @@ import hylife.utilitis_FEEC.control_variates.fnB_massless_kernels_control_variate as ker_cv import scipy.sparse as spa -from struphy.utils.arrays import xp +import cunumpy as xp def bv_pre(tol, n, LO_inv, tensor_space_FEM, p, Nel, idnx, idny, idnz): diff --git a/src/struphy/eigenvalue_solvers/legacy/control_variates/kinetic_extended/massless_control_variate.py b/src/struphy/eigenvalue_solvers/legacy/control_variates/kinetic_extended/massless_control_variate.py index 3d09c5bce..06fd6366a 100644 --- a/src/struphy/eigenvalue_solvers/legacy/control_variates/kinetic_extended/massless_control_variate.py +++ b/src/struphy/eigenvalue_solvers/legacy/control_variates/kinetic_extended/massless_control_variate.py @@ -2,7 +2,7 @@ import hylife.utilitis_FEEC.control_variates.massless_kernels_control_variate as ker_cv import scipy.sparse as spa -from struphy.utils.arrays import xp +import cunumpy as xp def bv_pre(u, uvalue, tensor_space_FEM, p, Nel, idnx, idny, idnz): diff --git a/src/struphy/eigenvalue_solvers/legacy/emw_operators.py b/src/struphy/eigenvalue_solvers/legacy/emw_operators.py index 0a0f16106..13286de97 100755 --- a/src/struphy/eigenvalue_solvers/legacy/emw_operators.py +++ b/src/struphy/eigenvalue_solvers/legacy/emw_operators.py @@ -10,7 +10,7 @@ import struphy.eigenvalue_solvers.kernels_3d as ker import struphy.eigenvalue_solvers.legacy.mass_matrices_3d_pre as mass_3d_pre -from struphy.utils.arrays import xp +import cunumpy as xp class EMW_operators: diff --git a/src/struphy/eigenvalue_solvers/legacy/inner_products_1d.py b/src/struphy/eigenvalue_solvers/legacy/inner_products_1d.py index 469798bb5..f1fc0a00d 100644 --- a/src/struphy/eigenvalue_solvers/legacy/inner_products_1d.py +++ b/src/struphy/eigenvalue_solvers/legacy/inner_products_1d.py @@ -8,7 +8,7 @@ import scipy.sparse as spa -from struphy.utils.arrays import xp +import cunumpy as xp # ======= inner product in V0 ==================== diff --git a/src/struphy/eigenvalue_solvers/legacy/inner_products_2d.py b/src/struphy/eigenvalue_solvers/legacy/inner_products_2d.py index 58ea01f2f..8d606538d 100644 --- a/src/struphy/eigenvalue_solvers/legacy/inner_products_2d.py +++ b/src/struphy/eigenvalue_solvers/legacy/inner_products_2d.py @@ -9,7 +9,7 @@ import scipy.sparse as spa import struphy.eigenvalue_solvers.kernels_2d as ker -from struphy.utils.arrays import xp +import cunumpy as xp # ================ inner product in V0 =========================== diff --git a/src/struphy/eigenvalue_solvers/legacy/inner_products_3d.py b/src/struphy/eigenvalue_solvers/legacy/inner_products_3d.py index 2616857b6..ccc451027 100644 --- a/src/struphy/eigenvalue_solvers/legacy/inner_products_3d.py +++ b/src/struphy/eigenvalue_solvers/legacy/inner_products_3d.py @@ -9,7 +9,7 @@ import scipy.sparse as spa import struphy.eigenvalue_solvers.kernels_3d as ker -from struphy.utils.arrays import xp +import cunumpy as xp # ================ inner product in V0 =========================== diff --git a/src/struphy/eigenvalue_solvers/legacy/l2_error_1d.py b/src/struphy/eigenvalue_solvers/legacy/l2_error_1d.py index 708d0352e..64a7c3362 100644 --- a/src/struphy/eigenvalue_solvers/legacy/l2_error_1d.py +++ b/src/struphy/eigenvalue_solvers/legacy/l2_error_1d.py @@ -8,7 +8,7 @@ import scipy.sparse as spa -from struphy.utils.arrays import xp +import cunumpy as xp # ======= error in V0 ==================== diff --git a/src/struphy/eigenvalue_solvers/legacy/l2_error_2d.py b/src/struphy/eigenvalue_solvers/legacy/l2_error_2d.py index ce2142ced..5b9c89c9b 100644 --- a/src/struphy/eigenvalue_solvers/legacy/l2_error_2d.py +++ b/src/struphy/eigenvalue_solvers/legacy/l2_error_2d.py @@ -9,7 +9,7 @@ import scipy.sparse as spa import struphy.eigenvalue_solvers.kernels_2d as ker -from struphy.utils.arrays import xp +import cunumpy as xp # ======= error in V0 ==================== diff --git a/src/struphy/eigenvalue_solvers/legacy/l2_error_3d.py b/src/struphy/eigenvalue_solvers/legacy/l2_error_3d.py index 93dcc4053..4535c3d8e 100644 --- a/src/struphy/eigenvalue_solvers/legacy/l2_error_3d.py +++ b/src/struphy/eigenvalue_solvers/legacy/l2_error_3d.py @@ -9,7 +9,7 @@ import scipy.sparse as spa import struphy.eigenvalue_solvers.kernels_3d as ker -from struphy.utils.arrays import xp +import cunumpy as xp # ======= error in V0 ==================== diff --git a/src/struphy/eigenvalue_solvers/legacy/mass_matrices_3d_pre.py b/src/struphy/eigenvalue_solvers/legacy/mass_matrices_3d_pre.py index fedff3c90..0fdc03526 100644 --- a/src/struphy/eigenvalue_solvers/legacy/mass_matrices_3d_pre.py +++ b/src/struphy/eigenvalue_solvers/legacy/mass_matrices_3d_pre.py @@ -10,7 +10,7 @@ import struphy.eigenvalue_solvers.spline_space as spl import struphy.linear_algebra.linalg_kron as linkron -from struphy.utils.arrays import xp +import cunumpy as xp # ================ inverse mass matrix in V0 =========================== diff --git a/src/struphy/eigenvalue_solvers/legacy/massless_operators/fB_arrays.py b/src/struphy/eigenvalue_solvers/legacy/massless_operators/fB_arrays.py index 193d51a11..e57f0af1b 100644 --- a/src/struphy/eigenvalue_solvers/legacy/massless_operators/fB_arrays.py +++ b/src/struphy/eigenvalue_solvers/legacy/massless_operators/fB_arrays.py @@ -7,7 +7,7 @@ import struphy.geometry.mappings_3d as mapping3d import struphy.geometry.mappings_3d_fast as mapping_fast import struphy.linear_algebra.linalg_kernels as linalg -from struphy.utils.arrays import xp +import cunumpy as xp class Temp_arrays: diff --git a/src/struphy/eigenvalue_solvers/legacy/massless_operators/fB_massless_linear_operators.py b/src/struphy/eigenvalue_solvers/legacy/massless_operators/fB_massless_linear_operators.py index c8b04f877..5081e52e5 100644 --- a/src/struphy/eigenvalue_solvers/legacy/massless_operators/fB_massless_linear_operators.py +++ b/src/struphy/eigenvalue_solvers/legacy/massless_operators/fB_massless_linear_operators.py @@ -5,7 +5,7 @@ import struphy.feec.massless_operators.fB_bb_kernel as bb_kernel import struphy.feec.massless_operators.fB_bv_kernel as bv_kernel import struphy.feec.massless_operators.fB_vv_kernel as vv_kernel -from struphy.utils.arrays import xp +import cunumpy as xp class Massless_linear_operators: diff --git a/src/struphy/eigenvalue_solvers/legacy/massless_operators/fB_vv_kernel.py b/src/struphy/eigenvalue_solvers/legacy/massless_operators/fB_vv_kernel.py index 449e31e50..97b72356c 100644 --- a/src/struphy/eigenvalue_solvers/legacy/massless_operators/fB_vv_kernel.py +++ b/src/struphy/eigenvalue_solvers/legacy/massless_operators/fB_vv_kernel.py @@ -3,7 +3,7 @@ import struphy.bsplines.bsplines_kernels as bsp import struphy.geometry.mappings_kernels as mapping_fast import struphy.linear_algebra.linalg_kernels as linalg -from struphy.utils.arrays import xp +import cunumpy as xp # ========================================================================================== diff --git a/src/struphy/eigenvalue_solvers/legacy/mhd_operators_MF.py b/src/struphy/eigenvalue_solvers/legacy/mhd_operators_MF.py index 7f3775389..a5ca07cf0 100644 --- a/src/struphy/eigenvalue_solvers/legacy/mhd_operators_MF.py +++ b/src/struphy/eigenvalue_solvers/legacy/mhd_operators_MF.py @@ -3,7 +3,7 @@ from struphy.eigenvalue_solvers.projectors_global import Projectors_tensor_3d from struphy.eigenvalue_solvers.spline_space import Tensor_spline_space from struphy.linear_algebra.linalg_kron import kron_matvec_3d, kron_solve_3d -from struphy.utils.arrays import xp +import cunumpy as xp # ================================================================================================= diff --git a/src/struphy/eigenvalue_solvers/legacy/projectors_local/pro_local/mhd_operators_3d_local.py b/src/struphy/eigenvalue_solvers/legacy/projectors_local/pro_local/mhd_operators_3d_local.py index 5d6c133e2..485ae0ed2 100644 --- a/src/struphy/eigenvalue_solvers/legacy/projectors_local/pro_local/mhd_operators_3d_local.py +++ b/src/struphy/eigenvalue_solvers/legacy/projectors_local/pro_local/mhd_operators_3d_local.py @@ -14,7 +14,7 @@ import struphy.feec.basics.kernels_3d as ker_loc_3d import struphy.feec.bsplines as bsp import struphy.feec.projectors.pro_local.kernels_projectors_local_mhd as ker_loc -from struphy.utils.arrays import xp +import cunumpy as xp class projectors_local_mhd: diff --git a/src/struphy/eigenvalue_solvers/legacy/projectors_local/pro_local/projectors_local.py b/src/struphy/eigenvalue_solvers/legacy/projectors_local/pro_local/projectors_local.py index f7d366c99..380e49fbb 100644 --- a/src/struphy/eigenvalue_solvers/legacy/projectors_local/pro_local/projectors_local.py +++ b/src/struphy/eigenvalue_solvers/legacy/projectors_local/pro_local/projectors_local.py @@ -10,7 +10,7 @@ import struphy.feec.bsplines as bsp import struphy.feec.projectors.pro_local.kernels_projectors_local as ker_loc -from struphy.utils.arrays import xp +import cunumpy as xp # ======================= 1d ==================================== diff --git a/src/struphy/eigenvalue_solvers/legacy/projectors_local/shape_pro_local/shape_function_projectors_L2.py b/src/struphy/eigenvalue_solvers/legacy/projectors_local/shape_pro_local/shape_function_projectors_L2.py index 04705a6a5..ca066518d 100644 --- a/src/struphy/eigenvalue_solvers/legacy/projectors_local/shape_pro_local/shape_function_projectors_L2.py +++ b/src/struphy/eigenvalue_solvers/legacy/projectors_local/shape_pro_local/shape_function_projectors_L2.py @@ -10,7 +10,7 @@ import struphy.feec.bsplines as bsp import struphy.feec.projectors.shape_pro_local.shape_L2_projector_kernel as ker_loc -from struphy.utils.arrays import xp +import cunumpy as xp # ======================= 3d ==================================== diff --git a/src/struphy/eigenvalue_solvers/legacy/projectors_local/shape_pro_local/shape_function_projectors_local.py b/src/struphy/eigenvalue_solvers/legacy/projectors_local/shape_pro_local/shape_function_projectors_local.py index dd5a313f2..13699d60b 100644 --- a/src/struphy/eigenvalue_solvers/legacy/projectors_local/shape_pro_local/shape_function_projectors_local.py +++ b/src/struphy/eigenvalue_solvers/legacy/projectors_local/shape_pro_local/shape_function_projectors_local.py @@ -10,7 +10,7 @@ import struphy.feec.bsplines as bsp import struphy.feec.projectors.shape_pro_local.shape_local_projector_kernel as ker_loc -from struphy.utils.arrays import xp +import cunumpy as xp # ======================= 3d ==================================== diff --git a/src/struphy/eigenvalue_solvers/mass_matrices_1d.py b/src/struphy/eigenvalue_solvers/mass_matrices_1d.py index 9c41ca85d..3c39c177b 100644 --- a/src/struphy/eigenvalue_solvers/mass_matrices_1d.py +++ b/src/struphy/eigenvalue_solvers/mass_matrices_1d.py @@ -5,7 +5,7 @@ import scipy.sparse as spa import struphy.bsplines.bsplines as bsp -from struphy.utils.arrays import xp +import cunumpy as xp # ======= mass matrices in 1D ==================== diff --git a/src/struphy/eigenvalue_solvers/mass_matrices_2d.py b/src/struphy/eigenvalue_solvers/mass_matrices_2d.py index e15d5e4c7..70e199640 100644 --- a/src/struphy/eigenvalue_solvers/mass_matrices_2d.py +++ b/src/struphy/eigenvalue_solvers/mass_matrices_2d.py @@ -5,7 +5,7 @@ import scipy.sparse as spa import struphy.eigenvalue_solvers.kernels_2d as ker -from struphy.utils.arrays import xp +import cunumpy as xp # ================ mass matrix in V0 =========================== diff --git a/src/struphy/eigenvalue_solvers/mass_matrices_3d.py b/src/struphy/eigenvalue_solvers/mass_matrices_3d.py index f7846f0b2..364631a7b 100644 --- a/src/struphy/eigenvalue_solvers/mass_matrices_3d.py +++ b/src/struphy/eigenvalue_solvers/mass_matrices_3d.py @@ -5,7 +5,7 @@ import scipy.sparse as spa import struphy.eigenvalue_solvers.kernels_3d as ker -from struphy.utils.arrays import xp +import cunumpy as xp # ================ mass matrix in V0 =========================== diff --git a/src/struphy/eigenvalue_solvers/mhd_axisymmetric_main.py b/src/struphy/eigenvalue_solvers/mhd_axisymmetric_main.py index e0ee63cc5..081190707 100644 --- a/src/struphy/eigenvalue_solvers/mhd_axisymmetric_main.py +++ b/src/struphy/eigenvalue_solvers/mhd_axisymmetric_main.py @@ -36,7 +36,7 @@ def solve_mhd_ev_problem_2d(num_params, eq_mhd, n_tor, basis_tor="i", path_out=N from struphy.eigenvalue_solvers.mhd_operators import MHDOperators from struphy.eigenvalue_solvers.spline_space import Spline_space_1d, Tensor_spline_space - from struphy.utils.arrays import xp + import cunumpy as xp print("\nStart of eigenspectrum calculation for toroidal mode number", n_tor) print("") diff --git a/src/struphy/eigenvalue_solvers/mhd_axisymmetric_pproc.py b/src/struphy/eigenvalue_solvers/mhd_axisymmetric_pproc.py index 779b9463e..fba128b94 100644 --- a/src/struphy/eigenvalue_solvers/mhd_axisymmetric_pproc.py +++ b/src/struphy/eigenvalue_solvers/mhd_axisymmetric_pproc.py @@ -5,7 +5,7 @@ def main(): import yaml - from struphy.utils.arrays import xp + import cunumpy as xp # parse arguments parser = argparse.ArgumentParser(description="Restrict a full .npy eigenspectrum to a range of eigenfrequencies.") diff --git a/src/struphy/eigenvalue_solvers/mhd_operators.py b/src/struphy/eigenvalue_solvers/mhd_operators.py index c0ffd0658..60bed6e4b 100644 --- a/src/struphy/eigenvalue_solvers/mhd_operators.py +++ b/src/struphy/eigenvalue_solvers/mhd_operators.py @@ -7,7 +7,7 @@ import struphy.eigenvalue_solvers.legacy.mass_matrices_3d_pre as mass_3d_pre from struphy.eigenvalue_solvers.mhd_operators_core import MHDOperatorsCore -from struphy.utils.arrays import xp +import cunumpy as xp class MHDOperators: diff --git a/src/struphy/eigenvalue_solvers/mhd_operators_core.py b/src/struphy/eigenvalue_solvers/mhd_operators_core.py index 45712afae..cc7f26d03 100644 --- a/src/struphy/eigenvalue_solvers/mhd_operators_core.py +++ b/src/struphy/eigenvalue_solvers/mhd_operators_core.py @@ -8,7 +8,7 @@ import struphy.eigenvalue_solvers.kernels_projectors_global_mhd as ker import struphy.eigenvalue_solvers.mass_matrices_2d as mass_2d import struphy.eigenvalue_solvers.mass_matrices_3d as mass_3d -from struphy.utils.arrays import xp +import cunumpy as xp class MHDOperatorsCore: diff --git a/src/struphy/eigenvalue_solvers/projectors_global.py b/src/struphy/eigenvalue_solvers/projectors_global.py index 7c66c3397..0b31c2f61 100644 --- a/src/struphy/eigenvalue_solvers/projectors_global.py +++ b/src/struphy/eigenvalue_solvers/projectors_global.py @@ -10,7 +10,7 @@ import struphy.bsplines.bsplines as bsp from struphy.linear_algebra.linalg_kron import kron_lusolve_2d, kron_lusolve_3d, kron_matvec_2d, kron_matvec_3d -from struphy.utils.arrays import xp +import cunumpy as xp # ======================= 1d ==================================== diff --git a/src/struphy/eigenvalue_solvers/spline_space.py b/src/struphy/eigenvalue_solvers/spline_space.py index b71bc867b..ef49aeaa1 100644 --- a/src/struphy/eigenvalue_solvers/spline_space.py +++ b/src/struphy/eigenvalue_solvers/spline_space.py @@ -9,7 +9,7 @@ import matplotlib import scipy.sparse as spa -from struphy.utils.arrays import xp +import cunumpy as xp matplotlib.rcParams.update({"font.size": 16}) import matplotlib.pyplot as plt diff --git a/src/struphy/examples/_draw_parallel.py b/src/struphy/examples/_draw_parallel.py index 62fae8cd2..5cfd66349 100644 --- a/src/struphy/examples/_draw_parallel.py +++ b/src/struphy/examples/_draw_parallel.py @@ -3,7 +3,7 @@ from struphy.feec.psydac_derham import Derham from struphy.geometry import domains from struphy.pic.particles import Particles6D -from struphy.utils.arrays import xp +import cunumpy as xp def main(): diff --git a/src/struphy/examples/restelli2018/callables.py b/src/struphy/examples/restelli2018/callables.py index 54404ab27..505a60f90 100644 --- a/src/struphy/examples/restelli2018/callables.py +++ b/src/struphy/examples/restelli2018/callables.py @@ -1,6 +1,6 @@ "Analytical callables needed for the simulation of the Two-Fluid Quasi-Neutral Model by Restelli." -from struphy.utils.arrays import xp +import cunumpy as xp class RestelliForcingTerm: diff --git a/src/struphy/feec/basis_projection_ops.py b/src/struphy/feec/basis_projection_ops.py index 4a8b804b0..6a0502f96 100644 --- a/src/struphy/feec/basis_projection_ops.py +++ b/src/struphy/feec/basis_projection_ops.py @@ -14,7 +14,7 @@ from struphy.feec.utilities import RotationMatrix from struphy.polar.basic import PolarDerhamSpace, PolarVector from struphy.polar.linear_operators import PolarExtractionOperator -from struphy.utils.arrays import xp +import cunumpy as xp from struphy.utils.pyccel import Pyccelkernel diff --git a/src/struphy/feec/linear_operators.py b/src/struphy/feec/linear_operators.py index 61a08e90e..3e30d4a76 100644 --- a/src/struphy/feec/linear_operators.py +++ b/src/struphy/feec/linear_operators.py @@ -10,7 +10,7 @@ from struphy.feec.utilities import apply_essential_bc_to_array from struphy.polar.basic import PolarDerhamSpace -from struphy.utils.arrays import xp +import cunumpy as xp class LinOpWithTransp(LinearOperator): diff --git a/src/struphy/feec/mass.py b/src/struphy/feec/mass.py index 1facbc2a0..f41a25c9f 100644 --- a/src/struphy/feec/mass.py +++ b/src/struphy/feec/mass.py @@ -16,7 +16,7 @@ from struphy.feec.utilities import RotationMatrix from struphy.geometry.base import Domain from struphy.polar.linear_operators import PolarExtractionOperator -from struphy.utils.arrays import xp +import cunumpy as xp from struphy.utils.pyccel import Pyccelkernel diff --git a/src/struphy/feec/preconditioner.py b/src/struphy/feec/preconditioner.py index 783eb062d..8b5a915c9 100644 --- a/src/struphy/feec/preconditioner.py +++ b/src/struphy/feec/preconditioner.py @@ -11,7 +11,7 @@ from struphy.feec.linear_operators import BoundaryOperator from struphy.feec.mass import WeightedMassOperator -from struphy.utils.arrays import xp +import cunumpy as xp class MassMatrixPreconditioner(LinearOperator): diff --git a/src/struphy/feec/projectors.py b/src/struphy/feec/projectors.py index 5a43cfc74..561468328 100644 --- a/src/struphy/feec/projectors.py +++ b/src/struphy/feec/projectors.py @@ -37,7 +37,7 @@ from struphy.kernel_arguments.local_projectors_args_kernels import LocalProjectorsArguments from struphy.polar.basic import PolarVector from struphy.polar.linear_operators import PolarExtractionOperator -from struphy.utils.arrays import xp +import cunumpy as xp class CommutingProjector: diff --git a/src/struphy/feec/psydac_derham.py b/src/struphy/feec/psydac_derham.py index fbbddae28..2cdbe9332 100644 --- a/src/struphy/feec/psydac_derham.py +++ b/src/struphy/feec/psydac_derham.py @@ -33,7 +33,7 @@ from struphy.polar.basic import PolarDerhamSpace, PolarVector from struphy.polar.extraction_operators import PolarExtractionBlocksC1 from struphy.polar.linear_operators import PolarExtractionOperator, PolarLinearOperator -from struphy.utils.arrays import xp +import cunumpy as xp class Derham: diff --git a/src/struphy/feec/tests/test_basis_ops.py b/src/struphy/feec/tests/test_basis_ops.py index e46522592..c695f1a57 100644 --- a/src/struphy/feec/tests/test_basis_ops.py +++ b/src/struphy/feec/tests/test_basis_ops.py @@ -24,7 +24,7 @@ def test_some_basis_ops(Nel, p, spl_kind, mapping): from struphy.feec.psydac_derham import Derham from struphy.fields_background.equils import HomogenSlab from struphy.geometry import domains - from struphy.utils.arrays import xp + import cunumpy as xp # mpi communicator MPI_COMM = MPI.COMM_WORLD @@ -474,7 +474,7 @@ def test_basis_ops_polar(Nel, p, spl_kind, dirichlet_bc, mapping, show_plots=Fal from struphy.fields_background.equils import ScrewPinch from struphy.geometry import domains from struphy.polar.basic import PolarVector - from struphy.utils.arrays import xp + import cunumpy as xp mpi_comm = MPI.COMM_WORLD mpi_rank = mpi_comm.Get_rank() @@ -726,7 +726,7 @@ def assert_ops(mpi_rank, res_PSY, res_STR, verbose=False, MPI_COMM=None): TODO """ - from struphy.utils.arrays import xp + import cunumpy as xp if verbose: if MPI_COMM is not None: diff --git a/src/struphy/feec/tests/test_derham.py b/src/struphy/feec/tests/test_derham.py index fff60bbfc..f00ff6835 100644 --- a/src/struphy/feec/tests/test_derham.py +++ b/src/struphy/feec/tests/test_derham.py @@ -14,7 +14,7 @@ def test_psydac_derham(Nel, p, spl_kind): from struphy.eigenvalue_solvers.spline_space import Spline_space_1d, Tensor_spline_space from struphy.feec.psydac_derham import Derham from struphy.feec.utilities import compare_arrays - from struphy.utils.arrays import xp + import cunumpy as xp comm = MPI.COMM_WORLD rank = comm.Get_rank() diff --git a/src/struphy/feec/tests/test_eval_field.py b/src/struphy/feec/tests/test_eval_field.py index 8213853b1..8341a557e 100644 --- a/src/struphy/feec/tests/test_eval_field.py +++ b/src/struphy/feec/tests/test_eval_field.py @@ -2,7 +2,7 @@ from psydac.ddm.mpi import MockComm from psydac.ddm.mpi import mpi as MPI -from struphy.utils.arrays import xp +import cunumpy as xp @pytest.mark.parametrize("Nel", [[8, 9, 10]]) diff --git a/src/struphy/feec/tests/test_field_init.py b/src/struphy/feec/tests/test_field_init.py index 248c32d58..6d414b821 100644 --- a/src/struphy/feec/tests/test_field_init.py +++ b/src/struphy/feec/tests/test_field_init.py @@ -13,7 +13,7 @@ def test_bckgr_init_const(Nel, p, spl_kind, spaces, vec_comps): from struphy.feec.psydac_derham import Derham from struphy.io.options import FieldsBackground - from struphy.utils.arrays import xp + import cunumpy as xp comm = MPI.COMM_WORLD rank = comm.Get_rank() @@ -72,7 +72,7 @@ def test_bckgr_init_mhd(Nel, p, spl_kind, with_desc=False, with_gvec=False, show from struphy.fields_background.base import FluidEquilibrium, FluidEquilibriumWithB from struphy.geometry import domains from struphy.io.options import FieldsBackground - from struphy.utils.arrays import xp + import cunumpy as xp comm = MPI.COMM_WORLD rank = comm.Get_rank() @@ -1089,7 +1089,7 @@ def test_sincos_init_const(Nel, p, spl_kind, show_plot=False): from struphy.feec.psydac_derham import Derham from struphy.initial.perturbations import ModesCos, ModesSin from struphy.io.options import FieldsBackground - from struphy.utils.arrays import xp + import cunumpy as xp comm = MPI.COMM_WORLD rank = comm.Get_rank() @@ -1317,7 +1317,7 @@ def test_noise_init(Nel, p, spl_kind, space, direction): from struphy.feec.psydac_derham import Derham from struphy.feec.utilities import compare_arrays from struphy.initial.perturbations import Noise - from struphy.utils.arrays import xp + import cunumpy as xp comm = MPI.COMM_WORLD rank = comm.Get_rank() diff --git a/src/struphy/feec/tests/test_l2_projectors.py b/src/struphy/feec/tests/test_l2_projectors.py index 500190075..f59011766 100644 --- a/src/struphy/feec/tests/test_l2_projectors.py +++ b/src/struphy/feec/tests/test_l2_projectors.py @@ -8,7 +8,7 @@ from struphy.feec.projectors import L2Projector from struphy.feec.psydac_derham import Derham from struphy.geometry import domains -from struphy.utils.arrays import xp +import cunumpy as xp @pytest.mark.parametrize("Nel", [[16, 32, 1]]) diff --git a/src/struphy/feec/tests/test_local_projectors.py b/src/struphy/feec/tests/test_local_projectors.py index a7549600c..72fc8ff69 100644 --- a/src/struphy/feec/tests/test_local_projectors.py +++ b/src/struphy/feec/tests/test_local_projectors.py @@ -12,7 +12,7 @@ from struphy.feec.local_projectors_kernels import fill_matrix_column from struphy.feec.psydac_derham import Derham from struphy.feec.utilities_local_projectors import get_one_spline, get_span_and_basis, get_values_and_indices_splines -from struphy.utils.arrays import xp +import cunumpy as xp def get_span_and_basis(pts, space): diff --git a/src/struphy/feec/tests/test_lowdim_nel_is_1.py b/src/struphy/feec/tests/test_lowdim_nel_is_1.py index 476c8f0c4..5f875f9de 100644 --- a/src/struphy/feec/tests/test_lowdim_nel_is_1.py +++ b/src/struphy/feec/tests/test_lowdim_nel_is_1.py @@ -13,7 +13,7 @@ def test_lowdim_derham(Nel, p, spl_kind, do_plot=False): from psydac.linalg.stencil import StencilVector from struphy.feec.psydac_derham import Derham - from struphy.utils.arrays import xp + import cunumpy as xp comm = MPI.COMM_WORLD rank = comm.Get_rank() diff --git a/src/struphy/feec/tests/test_mass_matrices.py b/src/struphy/feec/tests/test_mass_matrices.py index c106abc0b..c45be5c9f 100644 --- a/src/struphy/feec/tests/test_mass_matrices.py +++ b/src/struphy/feec/tests/test_mass_matrices.py @@ -21,7 +21,7 @@ def test_mass(Nel, p, spl_kind, dirichlet_bc, mapping, show_plots=False): from struphy.feec.utilities import RotationMatrix, compare_arrays, create_equal_random_arrays from struphy.fields_background.equils import ScrewPinch, ShearedSlab from struphy.geometry import domains - from struphy.utils.arrays import xp + import cunumpy as xp mpi_comm = MPI.COMM_WORLD mpi_rank = mpi_comm.Get_rank() @@ -386,7 +386,7 @@ def test_mass_polar(Nel, p, spl_kind, dirichlet_bc, mapping, show_plots=False): from struphy.fields_background.equils import ScrewPinch from struphy.geometry import domains from struphy.polar.basic import PolarVector - from struphy.utils.arrays import xp + import cunumpy as xp mpi_comm = MPI.COMM_WORLD mpi_rank = mpi_comm.Get_rank() @@ -584,7 +584,7 @@ def test_mass_preconditioner(Nel, p, spl_kind, dirichlet_bc, mapping, show_plots from struphy.feec.utilities import create_equal_random_arrays from struphy.fields_background.equils import ScrewPinch, ShearedSlab from struphy.geometry import domains - from struphy.utils.arrays import xp + import cunumpy as xp mpi_comm = MPI.COMM_WORLD mpi_rank = mpi_comm.Get_rank() @@ -892,7 +892,7 @@ def test_mass_preconditioner_polar(Nel, p, spl_kind, dirichlet_bc, mapping, show from struphy.fields_background.equils import ScrewPinch from struphy.geometry import domains from struphy.polar.basic import PolarVector - from struphy.utils.arrays import xp + import cunumpy as xp mpi_comm = MPI.COMM_WORLD mpi_rank = mpi_comm.Get_rank() diff --git a/src/struphy/feec/tests/test_toarray_struphy.py b/src/struphy/feec/tests/test_toarray_struphy.py index db266d108..3d76e55de 100644 --- a/src/struphy/feec/tests/test_toarray_struphy.py +++ b/src/struphy/feec/tests/test_toarray_struphy.py @@ -18,7 +18,7 @@ def test_toarray_struphy(Nel, p, spl_kind, mapping): from struphy.feec.psydac_derham import Derham from struphy.feec.utilities import compare_arrays, create_equal_random_arrays from struphy.geometry import domains - from struphy.utils.arrays import xp + import cunumpy as xp comm = MPI.COMM_WORLD rank = comm.Get_rank() diff --git a/src/struphy/feec/tests/test_tosparse_struphy.py b/src/struphy/feec/tests/test_tosparse_struphy.py index d9b96aee0..8b8135ed7 100644 --- a/src/struphy/feec/tests/test_tosparse_struphy.py +++ b/src/struphy/feec/tests/test_tosparse_struphy.py @@ -21,7 +21,7 @@ def test_tosparse_struphy(Nel, p, spl_kind, mapping): from struphy.feec.psydac_derham import Derham from struphy.feec.utilities import create_equal_random_arrays from struphy.geometry import domains - from struphy.utils.arrays import xp + import cunumpy as xp comm = MPI.COMM_WORLD rank = comm.Get_rank() diff --git a/src/struphy/feec/tests/xx_test_preconds.py b/src/struphy/feec/tests/xx_test_preconds.py index 1bd145fc6..081f1e0fe 100644 --- a/src/struphy/feec/tests/xx_test_preconds.py +++ b/src/struphy/feec/tests/xx_test_preconds.py @@ -21,7 +21,7 @@ def test_mass_preconditioner(Nel, p, spl_kind, mapping): from struphy.feec.preconditioner import MassMatrixPreconditioner from struphy.feec.psydac_derham import Derham from struphy.geometry import domains - from struphy.utils.arrays import xp + import cunumpy as xp MPI_COMM = MPI.COMM_WORLD diff --git a/src/struphy/feec/utilities.py b/src/struphy/feec/utilities.py index e2952572f..98fddd024 100644 --- a/src/struphy/feec/utilities.py +++ b/src/struphy/feec/utilities.py @@ -8,7 +8,7 @@ import struphy.feec.utilities_kernels as kernels from struphy.feec import banded_to_stencil_kernels as bts from struphy.polar.basic import PolarVector -from struphy.utils.arrays import xp +import cunumpy as xp class RotationMatrix: diff --git a/src/struphy/feec/utilities_local_projectors.py b/src/struphy/feec/utilities_local_projectors.py index 09fed1e54..67defc766 100644 --- a/src/struphy/feec/utilities_local_projectors.py +++ b/src/struphy/feec/utilities_local_projectors.py @@ -1,5 +1,5 @@ from struphy.feec.local_projectors_kernels import are_quadrature_points_zero, get_rows, select_quasi_points -from struphy.utils.arrays import xp +import cunumpy as xp def split_points( diff --git a/src/struphy/feec/variational_utilities.py b/src/struphy/feec/variational_utilities.py index b2549d42b..b6034645d 100644 --- a/src/struphy/feec/variational_utilities.py +++ b/src/struphy/feec/variational_utilities.py @@ -12,7 +12,7 @@ ) from struphy.feec.linear_operators import LinOpWithTransp from struphy.feec.psydac_derham import Derham -from struphy.utils.arrays import xp +import cunumpy as xp class BracketOperator(LinOpWithTransp): diff --git a/src/struphy/fields_background/base.py b/src/struphy/fields_background/base.py index c6178d579..398a0c402 100644 --- a/src/struphy/fields_background/base.py +++ b/src/struphy/fields_background/base.py @@ -6,7 +6,7 @@ from pyevtk.hl import gridToVTK from struphy.geometry.base import Domain -from struphy.utils.arrays import xp +import cunumpy as xp class FluidEquilibrium(metaclass=ABCMeta): diff --git a/src/struphy/fields_background/coil_fields/base.py b/src/struphy/fields_background/coil_fields/base.py index 55b0720e8..0e4002f15 100644 --- a/src/struphy/fields_background/coil_fields/base.py +++ b/src/struphy/fields_background/coil_fields/base.py @@ -3,7 +3,7 @@ from matplotlib import pyplot as plt from pyevtk.hl import gridToVTK -from struphy.utils.arrays import xp +import cunumpy as xp class CoilMagneticField(metaclass=ABCMeta): diff --git a/src/struphy/fields_background/coil_fields/coil_fields.py b/src/struphy/fields_background/coil_fields/coil_fields.py index 2629cc707..fc19d5494 100644 --- a/src/struphy/fields_background/coil_fields/coil_fields.py +++ b/src/struphy/fields_background/coil_fields/coil_fields.py @@ -1,6 +1,6 @@ from struphy.feec.psydac_derham import Derham from struphy.fields_background.coil_fields.base import CoilMagneticField, load_csv_data -from struphy.utils.arrays import xp +import cunumpy as xp class RatGUI(CoilMagneticField): diff --git a/src/struphy/fields_background/equils.py b/src/struphy/fields_background/equils.py index 25d3d00ad..f18ab92d8 100644 --- a/src/struphy/fields_background/equils.py +++ b/src/struphy/fields_background/equils.py @@ -28,7 +28,7 @@ NumericalMHDequilibrium, ) from struphy.fields_background.mhd_equil.eqdsk import readeqdsk -from struphy.utils.arrays import xp +import cunumpy as xp from struphy.utils.utils import read_state, subp_run diff --git a/src/struphy/fields_background/tests/test_desc_equil.py b/src/struphy/fields_background/tests/test_desc_equil.py index e7ae0872c..b06a47d11 100644 --- a/src/struphy/fields_background/tests/test_desc_equil.py +++ b/src/struphy/fields_background/tests/test_desc_equil.py @@ -3,7 +3,7 @@ import pytest from matplotlib import pyplot as plt -from struphy.utils.arrays import xp +import cunumpy as xp desc_spec = importlib.util.find_spec("desc") diff --git a/src/struphy/fields_background/tests/test_generic_equils.py b/src/struphy/fields_background/tests/test_generic_equils.py index 6ed2c6178..4bd5b078c 100644 --- a/src/struphy/fields_background/tests/test_generic_equils.py +++ b/src/struphy/fields_background/tests/test_generic_equils.py @@ -5,7 +5,7 @@ GenericCartesianFluidEquilibrium, GenericCartesianFluidEquilibriumWithB, ) -from struphy.utils.arrays import xp +import cunumpy as xp def test_generic_equils(show=False): diff --git a/src/struphy/fields_background/tests/test_mhd_equils.py b/src/struphy/fields_background/tests/test_mhd_equils.py index 076891914..b1536b2d7 100644 --- a/src/struphy/fields_background/tests/test_mhd_equils.py +++ b/src/struphy/fields_background/tests/test_mhd_equils.py @@ -1,7 +1,7 @@ import pytest from struphy.fields_background import equils -from struphy.utils.arrays import xp +import cunumpy as xp @pytest.mark.parametrize( diff --git a/src/struphy/fields_background/tests/test_numerical_mhd_equil.py b/src/struphy/fields_background/tests/test_numerical_mhd_equil.py index 1002c37c8..4f3b0f70c 100644 --- a/src/struphy/fields_background/tests/test_numerical_mhd_equil.py +++ b/src/struphy/fields_background/tests/test_numerical_mhd_equil.py @@ -1,7 +1,7 @@ import pytest from struphy.fields_background.base import FluidEquilibrium, LogicalMHDequilibrium -from struphy.utils.arrays import xp +import cunumpy as xp @pytest.mark.parametrize( diff --git a/src/struphy/geometry/base.py b/src/struphy/geometry/base.py index 9de4acede..7936d8cd6 100644 --- a/src/struphy/geometry/base.py +++ b/src/struphy/geometry/base.py @@ -11,7 +11,7 @@ from struphy.geometry import evaluation_kernels, transform_kernels from struphy.kernel_arguments.pusher_args_kernels import DomainArguments from struphy.linear_algebra import linalg_kron -from struphy.utils.arrays import xp +import cunumpy as xp class Domain(metaclass=ABCMeta): diff --git a/src/struphy/geometry/domains.py b/src/struphy/geometry/domains.py index 5e1649dc7..ee22b04f6 100644 --- a/src/struphy/geometry/domains.py +++ b/src/struphy/geometry/domains.py @@ -12,7 +12,7 @@ interp_mapping, ) from struphy.geometry.utilities import field_line_tracing -from struphy.utils.arrays import xp +import cunumpy as xp class Tokamak(PoloidalSplineTorus): diff --git a/src/struphy/geometry/tests/test_domain.py b/src/struphy/geometry/tests/test_domain.py index 76db82315..61a06cc47 100644 --- a/src/struphy/geometry/tests/test_domain.py +++ b/src/struphy/geometry/tests/test_domain.py @@ -5,7 +5,7 @@ def test_prepare_arg(): """Tests prepare_arg static method in domain base class.""" from struphy.geometry.base import Domain - from struphy.utils.arrays import xp + import cunumpy as xp def a1(e1, e2, e3): return e1 * e2 @@ -160,7 +160,7 @@ def test_evaluation_mappings(mapping): from struphy.geometry import domains from struphy.geometry.base import Domain - from struphy.utils.arrays import xp + import cunumpy as xp # arrays: arr1 = xp.linspace(0.0, 1.0, 4) @@ -319,7 +319,7 @@ def test_pullback(): from struphy.geometry import domains from struphy.geometry.base import Domain - from struphy.utils.arrays import xp + import cunumpy as xp # arrays: arr1 = xp.linspace(0.0, 1.0, 4) @@ -478,7 +478,7 @@ def test_pushforward(): from struphy.geometry import domains from struphy.geometry.base import Domain - from struphy.utils.arrays import xp + import cunumpy as xp # arrays: arr1 = xp.linspace(0.0, 1.0, 4) @@ -637,7 +637,7 @@ def test_transform(): from struphy.geometry import domains from struphy.geometry.base import Domain - from struphy.utils.arrays import xp + import cunumpy as xp # arrays: arr1 = xp.linspace(0.0, 1.0, 4) @@ -817,7 +817,7 @@ def fun(e1, e2, e3): # """ # # from struphy.geometry import domains -# from struphy.utils.arrays import xp +# import cunumpy as xp # # # arrays: # arr1 = xp.linspace(0., 1., 4) diff --git a/src/struphy/geometry/utilities.py b/src/struphy/geometry/utilities.py index 0d5c07d93..0f61950f8 100644 --- a/src/struphy/geometry/utilities.py +++ b/src/struphy/geometry/utilities.py @@ -17,7 +17,7 @@ from struphy.geometry.utilities_kernels import weighted_arc_lengths_flux_surface from struphy.io.options import GivenInBasis from struphy.linear_algebra.linalg_kron import kron_lusolve_2d -from struphy.utils.arrays import xp +import cunumpy as xp def field_line_tracing( diff --git a/src/struphy/initial/eigenfunctions.py b/src/struphy/initial/eigenfunctions.py index 093fe21ac..9d71268e2 100644 --- a/src/struphy/initial/eigenfunctions.py +++ b/src/struphy/initial/eigenfunctions.py @@ -5,7 +5,7 @@ from sympde.topology import Derham, Line from struphy.fields_background.equils import set_defaults -from struphy.utils.arrays import xp +import cunumpy as xp class InitialMHDAxisymHdivEigFun: diff --git a/src/struphy/initial/perturbations.py b/src/struphy/initial/perturbations.py index a062c3f61..011ed56ef 100644 --- a/src/struphy/initial/perturbations.py +++ b/src/struphy/initial/perturbations.py @@ -8,7 +8,7 @@ from struphy.initial.base import Perturbation from struphy.io.options import GivenInBasis, NoiseDirections, check_option -from struphy.utils.arrays import xp +import cunumpy as xp @dataclass diff --git a/src/struphy/initial/tests/test_init_perturbations.py b/src/struphy/initial/tests/test_init_perturbations.py index ee71c22c8..1fce1021e 100644 --- a/src/struphy/initial/tests/test_init_perturbations.py +++ b/src/struphy/initial/tests/test_init_perturbations.py @@ -29,7 +29,7 @@ def test_init_modes(Nel, p, spl_kind, mapping, combine_comps=None, do_plot=False from struphy.initial import perturbations from struphy.initial.base import Perturbation from struphy.models.variables import FEECVariable - from struphy.utils.arrays import xp + import cunumpy as xp comm = MPI.COMM_WORLD rank = comm.Get_rank() diff --git a/src/struphy/initial/utilities.py b/src/struphy/initial/utilities.py index 274b73ba6..71027a97d 100644 --- a/src/struphy/initial/utilities.py +++ b/src/struphy/initial/utilities.py @@ -4,7 +4,7 @@ from struphy.fields_background.equils import set_defaults from struphy.io.output_handling import DataContainer -from struphy.utils.arrays import xp +import cunumpy as xp class InitFromOutput: diff --git a/src/struphy/io/options.py b/src/struphy/io/options.py index fff19cb48..d1107fb75 100644 --- a/src/struphy/io/options.py +++ b/src/struphy/io/options.py @@ -5,7 +5,7 @@ from psydac.ddm.mpi import mpi as MPI from struphy.physics.physics import ConstantsOfNature -from struphy.utils.arrays import xp +import cunumpy as xp ## Literal options diff --git a/src/struphy/io/output_handling.py b/src/struphy/io/output_handling.py index ed9c563d4..05e030d00 100644 --- a/src/struphy/io/output_handling.py +++ b/src/struphy/io/output_handling.py @@ -3,7 +3,7 @@ import h5py -from struphy.utils.arrays import xp +import cunumpy as xp class DataContainer: diff --git a/src/struphy/io/setup.py b/src/struphy/io/setup.py index 58bcdccf0..1f0ec7522 100644 --- a/src/struphy/io/setup.py +++ b/src/struphy/io/setup.py @@ -10,7 +10,7 @@ from struphy.geometry.base import Domain from struphy.io.options import DerhamOptions from struphy.topology.grids import TensorProductGrid -from struphy.utils.arrays import xp +import cunumpy as xp def import_parameters_py(params_path: str) -> ModuleType: diff --git a/src/struphy/kinetic_background/base.py b/src/struphy/kinetic_background/base.py index 5da0a1568..4e59ac910 100644 --- a/src/struphy/kinetic_background/base.py +++ b/src/struphy/kinetic_background/base.py @@ -5,7 +5,7 @@ from struphy.fields_background.base import FluidEquilibriumWithB from struphy.initial.base import Perturbation -from struphy.utils.arrays import xp +import cunumpy as xp class KineticBackground(metaclass=ABCMeta): diff --git a/src/struphy/kinetic_background/maxwellians.py b/src/struphy/kinetic_background/maxwellians.py index ea541eb70..3faf2abfa 100644 --- a/src/struphy/kinetic_background/maxwellians.py +++ b/src/struphy/kinetic_background/maxwellians.py @@ -6,7 +6,7 @@ from struphy.fields_background.equils import set_defaults from struphy.initial.base import Perturbation from struphy.kinetic_background.base import Maxwellian -from struphy.utils.arrays import xp +import cunumpy as xp class Maxwellian3D(Maxwellian): diff --git a/src/struphy/kinetic_background/moment_functions.py b/src/struphy/kinetic_background/moment_functions.py index b573e657a..39b22c6e1 100644 --- a/src/struphy/kinetic_background/moment_functions.py +++ b/src/struphy/kinetic_background/moment_functions.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 "Analytical moment functions." -from struphy.utils.arrays import xp +import cunumpy as xp class ITPA_density: diff --git a/src/struphy/kinetic_background/tests/test_base.py b/src/struphy/kinetic_background/tests/test_base.py index 5dc077c24..ae16d052a 100644 --- a/src/struphy/kinetic_background/tests/test_base.py +++ b/src/struphy/kinetic_background/tests/test_base.py @@ -4,7 +4,7 @@ def test_kinetic_background_magics(show_plot=False): import matplotlib.pyplot as plt from struphy.kinetic_background.maxwellians import Maxwellian3D - from struphy.utils.arrays import xp + import cunumpy as xp Nel = [32, 1, 1] e1 = xp.linspace(0.0, 1.0, Nel[0]) diff --git a/src/struphy/kinetic_background/tests/test_maxwellians.py b/src/struphy/kinetic_background/tests/test_maxwellians.py index 44e3679d4..9e3523a93 100644 --- a/src/struphy/kinetic_background/tests/test_maxwellians.py +++ b/src/struphy/kinetic_background/tests/test_maxwellians.py @@ -11,7 +11,7 @@ def test_maxwellian_3d_uniform(Nel, show_plot=False): import matplotlib.pyplot as plt from struphy.kinetic_background.maxwellians import Maxwellian3D - from struphy.utils.arrays import xp + import cunumpy as xp e1 = xp.linspace(0.0, 1.0, Nel[0]) e2 = xp.linspace(0.0, 1.0, Nel[1]) @@ -97,7 +97,7 @@ def test_maxwellian_3d_perturbed(Nel, show_plot=False): from struphy.initial import perturbations from struphy.kinetic_background.maxwellians import Maxwellian3D - from struphy.utils.arrays import xp + import cunumpy as xp e1 = xp.linspace(0.0, 1.0, Nel[0]) v1 = xp.linspace(-5.0, 5.0, 128) @@ -263,7 +263,7 @@ def test_maxwellian_3d_mhd(Nel, with_desc, show_plot=False): from struphy.initial import perturbations from struphy.initial.base import Perturbation from struphy.kinetic_background.maxwellians import Maxwellian3D - from struphy.utils.arrays import xp + import cunumpy as xp e1 = xp.linspace(0.0, 1.0, Nel[0]) e2 = xp.linspace(0.0, 1.0, Nel[1]) @@ -669,7 +669,7 @@ def test_maxwellian_2d_uniform(Nel, show_plot=False): import matplotlib.pyplot as plt from struphy.kinetic_background.maxwellians import GyroMaxwellian2D - from struphy.utils.arrays import xp + import cunumpy as xp e1 = xp.linspace(0.0, 1.0, Nel[0]) e2 = xp.linspace(0.0, 1.0, Nel[1]) @@ -763,7 +763,7 @@ def test_maxwellian_2d_perturbed(Nel, show_plot=False): from struphy.initial import perturbations from struphy.kinetic_background.maxwellians import GyroMaxwellian2D - from struphy.utils.arrays import xp + import cunumpy as xp e1 = xp.linspace(0.0, 1.0, Nel[0]) v1 = xp.linspace(-5.0, 5.0, 128) @@ -1025,7 +1025,7 @@ def test_maxwellian_2d_mhd(Nel, with_desc, show_plot=False): from struphy.initial import perturbations from struphy.initial.base import Perturbation from struphy.kinetic_background.maxwellians import GyroMaxwellian2D - from struphy.utils.arrays import xp + import cunumpy as xp e1 = xp.linspace(0.0, 1.0, Nel[0]) e2 = xp.linspace(0.0, 1.0, Nel[1]) @@ -1423,7 +1423,7 @@ def test_canonical_maxwellian_uniform(Nel, show_plot=False): from struphy.geometry import domains from struphy.initial import perturbations from struphy.kinetic_background.maxwellians import CanonicalMaxwellian - from struphy.utils.arrays import xp + import cunumpy as xp e1 = xp.linspace(0.0, 1.0, Nel[0]) e2 = xp.linspace(0.0, 1.0, Nel[1]) diff --git a/src/struphy/linear_algebra/linalg_kron.py b/src/struphy/linear_algebra/linalg_kron.py index 29be15d60..6f354d2cb 100644 --- a/src/struphy/linear_algebra/linalg_kron.py +++ b/src/struphy/linear_algebra/linalg_kron.py @@ -16,7 +16,7 @@ from scipy.linalg import solve_circulant from scipy.sparse.linalg import splu -from struphy.utils.arrays import xp +import cunumpy as xp def kron_matvec_2d(kmat, vec2d): diff --git a/src/struphy/linear_algebra/saddle_point.py b/src/struphy/linear_algebra/saddle_point.py index efa4dbbbe..dccfd65bf 100644 --- a/src/struphy/linear_algebra/saddle_point.py +++ b/src/struphy/linear_algebra/saddle_point.py @@ -7,7 +7,7 @@ from psydac.linalg.solvers import inverse from struphy.linear_algebra.tests.test_saddlepoint_massmatrices import _plot_residual_norms -from struphy.utils.arrays import xp +import cunumpy as xp class SaddlePointSolver: diff --git a/src/struphy/linear_algebra/tests/test_saddlepoint_massmatrices.py b/src/struphy/linear_algebra/tests/test_saddlepoint_massmatrices.py index 9f196411e..04b86de7d 100644 --- a/src/struphy/linear_algebra/tests/test_saddlepoint_massmatrices.py +++ b/src/struphy/linear_algebra/tests/test_saddlepoint_massmatrices.py @@ -29,7 +29,7 @@ def test_saddlepointsolver(method_for_solving, Nel, p, spl_kind, dirichlet_bc, m from struphy.geometry import domains from struphy.initial import perturbations from struphy.linear_algebra.saddle_point import SaddlePointSolver - from struphy.utils.arrays import xp + import cunumpy as xp mpi_comm = MPI.COMM_WORLD mpi_rank = mpi_comm.Get_rank() @@ -375,7 +375,7 @@ def _plot_velocity(data_reshaped): import matplotlib import matplotlib.pyplot as plt - from struphy.utils.arrays import xp + import cunumpy as xp matplotlib.use("Agg") diff --git a/src/struphy/linear_algebra/tests/test_stencil_dot_kernels.py b/src/struphy/linear_algebra/tests/test_stencil_dot_kernels.py index 0475b418a..5730e8ccd 100644 --- a/src/struphy/linear_algebra/tests/test_stencil_dot_kernels.py +++ b/src/struphy/linear_algebra/tests/test_stencil_dot_kernels.py @@ -19,7 +19,7 @@ def test_1d(Nel, p, spl_kind, domain_ind, codomain_ind): from struphy.feec.psydac_derham import Derham from struphy.linear_algebra.stencil_dot_kernels import matvec_1d_kernel - from struphy.utils.arrays import xp + import cunumpy as xp # only for M1 Mac users PSYDAC_BACKEND_GPYCCEL["flags"] = "-O3 -march=native -mtune=native -ffast-math -ffree-line-length-none" @@ -140,7 +140,7 @@ def test_3d(Nel, p, spl_kind, domain_ind, codomain_ind): from struphy.feec.psydac_derham import Derham from struphy.linear_algebra.stencil_dot_kernels import matvec_3d_kernel - from struphy.utils.arrays import xp + import cunumpy as xp # only for M1 Mac users PSYDAC_BACKEND_GPYCCEL["flags"] = "-O3 -march=native -mtune=native -ffast-math -ffree-line-length-none" diff --git a/src/struphy/linear_algebra/tests/test_stencil_transpose_kernels.py b/src/struphy/linear_algebra/tests/test_stencil_transpose_kernels.py index 486e302f5..8cd0ec538 100644 --- a/src/struphy/linear_algebra/tests/test_stencil_transpose_kernels.py +++ b/src/struphy/linear_algebra/tests/test_stencil_transpose_kernels.py @@ -19,7 +19,7 @@ def test_1d(Nel, p, spl_kind, domain_ind, codomain_ind): from struphy.feec.psydac_derham import Derham from struphy.linear_algebra.stencil_transpose_kernels import transpose_1d_kernel - from struphy.utils.arrays import xp + import cunumpy as xp # only for M1 Mac users PSYDAC_BACKEND_GPYCCEL["flags"] = "-O3 -march=native -mtune=native -ffast-math -ffree-line-length-none" @@ -134,7 +134,7 @@ def test_3d(Nel, p, spl_kind, domain_ind, codomain_ind): from struphy.feec.psydac_derham import Derham from struphy.linear_algebra.stencil_transpose_kernels import transpose_3d_kernel - from struphy.utils.arrays import xp + import cunumpy as xp # only for M1 Mac users PSYDAC_BACKEND_GPYCCEL["flags"] = "-O3 -march=native -mtune=native -ffast-math -ffree-line-length-none" diff --git a/src/struphy/main.py b/src/struphy/main.py index 3b06b671e..e419593ce 100644 --- a/src/struphy/main.py +++ b/src/struphy/main.py @@ -38,7 +38,7 @@ from struphy.profiling.profiling import ProfileManager from struphy.topology import grids from struphy.topology.grids import TensorProductGrid -from struphy.utils.arrays import xp +import cunumpy as xp from struphy.utils.clone_config import CloneConfig from struphy.utils.utils import dict_to_yaml diff --git a/src/struphy/models/base.py b/src/struphy/models/base.py index d910cc41b..56eaf9f41 100644 --- a/src/struphy/models/base.py +++ b/src/struphy/models/base.py @@ -35,7 +35,7 @@ from struphy.profiling.profiling import ProfileManager from struphy.propagators.base import Propagator from struphy.topology.grids import TensorProductGrid -from struphy.utils.arrays import xp +import cunumpy as xp from struphy.utils.clone_config import CloneConfig from struphy.utils.utils import dict_to_yaml, read_state diff --git a/src/struphy/models/fluid.py b/src/struphy/models/fluid.py index 98983da4b..d060fbd30 100644 --- a/src/struphy/models/fluid.py +++ b/src/struphy/models/fluid.py @@ -9,7 +9,7 @@ from struphy.models.variables import FEECVariable, PICVariable, SPHVariable, Variable from struphy.polar.basic import PolarVector from struphy.propagators import propagators_coupling, propagators_fields, propagators_markers -from struphy.utils.arrays import xp +import cunumpy as xp rank = MPI.COMM_WORLD.Get_rank() diff --git a/src/struphy/models/hybrid.py b/src/struphy/models/hybrid.py index 0d765981d..3617b8ba5 100644 --- a/src/struphy/models/hybrid.py +++ b/src/struphy/models/hybrid.py @@ -6,7 +6,7 @@ from struphy.pic.accumulation import accum_kernels, accum_kernels_gc from struphy.polar.basic import PolarVector from struphy.propagators import propagators_coupling, propagators_fields, propagators_markers -from struphy.utils.arrays import xp +import cunumpy as xp from struphy.utils.pyccel import Pyccelkernel rank = MPI.COMM_WORLD.Get_rank() diff --git a/src/struphy/models/kinetic.py b/src/struphy/models/kinetic.py index c8f6ae452..36551e60c 100644 --- a/src/struphy/models/kinetic.py +++ b/src/struphy/models/kinetic.py @@ -9,7 +9,7 @@ from struphy.pic.accumulation import accum_kernels, accum_kernels_gc from struphy.pic.accumulation.particles_to_grid import AccumulatorVector from struphy.propagators import propagators_coupling, propagators_fields, propagators_markers -from struphy.utils.arrays import xp +import cunumpy as xp from struphy.utils.pyccel import Pyccelkernel rank = MPI.COMM_WORLD.Get_rank() diff --git a/src/struphy/models/species.py b/src/struphy/models/species.py index 4ad4c14d6..6827274e8 100644 --- a/src/struphy/models/species.py +++ b/src/struphy/models/species.py @@ -13,7 +13,7 @@ LoadingParameters, WeightsParameters, ) -from struphy.utils.arrays import xp +import cunumpy as xp class Species(metaclass=ABCMeta): diff --git a/src/struphy/models/tests/test_verif_EulerSPH.py b/src/struphy/models/tests/test_verif_EulerSPH.py index fa9b2bcfa..c11c023a3 100644 --- a/src/struphy/models/tests/test_verif_EulerSPH.py +++ b/src/struphy/models/tests/test_verif_EulerSPH.py @@ -19,7 +19,7 @@ WeightsParameters, ) from struphy.topology import grids -from struphy.utils.arrays import xp +import cunumpy as xp test_folder = os.path.join(os.getcwd(), "struphy_verification_tests") diff --git a/src/struphy/models/tests/test_verif_LinearMHD.py b/src/struphy/models/tests/test_verif_LinearMHD.py index 3ed92aca0..e29186b8c 100644 --- a/src/struphy/models/tests/test_verif_LinearMHD.py +++ b/src/struphy/models/tests/test_verif_LinearMHD.py @@ -11,7 +11,7 @@ from struphy.io.options import BaseUnits, DerhamOptions, EnvironmentOptions, FieldsBackground, Time from struphy.kinetic_background import maxwellians from struphy.topology import grids -from struphy.utils.arrays import xp +import cunumpy as xp test_folder = os.path.join(os.getcwd(), "verification_tests") diff --git a/src/struphy/models/tests/test_verif_Maxwell.py b/src/struphy/models/tests/test_verif_Maxwell.py index dc1a4794c..a39545a51 100644 --- a/src/struphy/models/tests/test_verif_Maxwell.py +++ b/src/struphy/models/tests/test_verif_Maxwell.py @@ -14,7 +14,7 @@ from struphy.kinetic_background import maxwellians from struphy.models.toy import Maxwell from struphy.topology import grids -from struphy.utils.arrays import xp +import cunumpy as xp test_folder = os.path.join(os.getcwd(), "struphy_verification_tests") diff --git a/src/struphy/models/tests/test_verif_Poisson.py b/src/struphy/models/tests/test_verif_Poisson.py index 289886cb3..adb8300b8 100644 --- a/src/struphy/models/tests/test_verif_Poisson.py +++ b/src/struphy/models/tests/test_verif_Poisson.py @@ -18,7 +18,7 @@ WeightsParameters, ) from struphy.topology import grids -from struphy.utils.arrays import xp +import cunumpy as xp test_folder = os.path.join(os.getcwd(), "struphy_verification_tests") diff --git a/src/struphy/models/tests/test_verif_VlasovAmpereOneSpecies.py b/src/struphy/models/tests/test_verif_VlasovAmpereOneSpecies.py index 980352a04..d75213038 100644 --- a/src/struphy/models/tests/test_verif_VlasovAmpereOneSpecies.py +++ b/src/struphy/models/tests/test_verif_VlasovAmpereOneSpecies.py @@ -19,7 +19,7 @@ WeightsParameters, ) from struphy.topology import grids -from struphy.utils.arrays import xp +import cunumpy as xp test_folder = os.path.join(os.getcwd(), "struphy_verification_tests") diff --git a/src/struphy/models/tests/verification.py b/src/struphy/models/tests/verification.py index d54263ee5..b128e2c3a 100644 --- a/src/struphy/models/tests/verification.py +++ b/src/struphy/models/tests/verification.py @@ -11,7 +11,7 @@ import struphy from struphy.post_processing import pproc_struphy -from struphy.utils.arrays import xp +import cunumpy as xp def VlasovAmpereOneSpecies_weakLandau( diff --git a/src/struphy/models/toy.py b/src/struphy/models/toy.py index 666e87649..788370784 100644 --- a/src/struphy/models/toy.py +++ b/src/struphy/models/toy.py @@ -6,7 +6,7 @@ from struphy.models.species import FieldSpecies, FluidSpecies, ParticleSpecies from struphy.models.variables import FEECVariable, PICVariable, SPHVariable, Variable from struphy.propagators import propagators_coupling, propagators_fields, propagators_markers -from struphy.utils.arrays import xp +import cunumpy as xp rank = MPI.COMM_WORLD.Get_rank() diff --git a/src/struphy/models/variables.py b/src/struphy/models/variables.py index 3985f4b35..2bfd03d30 100644 --- a/src/struphy/models/variables.py +++ b/src/struphy/models/variables.py @@ -21,7 +21,7 @@ from struphy.pic import particles from struphy.pic.base import Particles from struphy.pic.particles import ParticlesSPH -from struphy.utils.arrays import xp +import cunumpy as xp from struphy.utils.clone_config import CloneConfig if TYPE_CHECKING: diff --git a/src/struphy/ode/solvers.py b/src/struphy/ode/solvers.py index 4216198ff..009085495 100644 --- a/src/struphy/ode/solvers.py +++ b/src/struphy/ode/solvers.py @@ -4,7 +4,7 @@ from psydac.linalg.stencil import StencilVector from struphy.ode.utils import ButcherTableau -from struphy.utils.arrays import xp +import cunumpy as xp class ODEsolverFEEC: diff --git a/src/struphy/ode/tests/test_ode_feec.py b/src/struphy/ode/tests/test_ode_feec.py index 9d1a49be5..7a7894c2d 100644 --- a/src/struphy/ode/tests/test_ode_feec.py +++ b/src/struphy/ode/tests/test_ode_feec.py @@ -28,7 +28,7 @@ def test_exp_growth(spaces, algo, show_plots=False): from struphy.feec.psydac_derham import Derham from struphy.ode.solvers import ODEsolverFEEC from struphy.ode.utils import ButcherTableau - from struphy.utils.arrays import xp + import cunumpy as xp comm = MPI.COMM_WORLD rank = comm.Get_rank() diff --git a/src/struphy/ode/utils.py b/src/struphy/ode/utils.py index 997225d42..6748d07f1 100644 --- a/src/struphy/ode/utils.py +++ b/src/struphy/ode/utils.py @@ -1,7 +1,7 @@ from dataclasses import dataclass from typing import Literal, get_args -from struphy.utils.arrays import xp +import cunumpy as xp OptsButcher = Literal[ "rk4", diff --git a/src/struphy/pic/accumulation/particles_to_grid.py b/src/struphy/pic/accumulation/particles_to_grid.py index d694c017b..145eb8b5a 100644 --- a/src/struphy/pic/accumulation/particles_to_grid.py +++ b/src/struphy/pic/accumulation/particles_to_grid.py @@ -12,7 +12,7 @@ from struphy.pic.accumulation.filter import AccumFilter, FilterParameters from struphy.pic.base import Particles from struphy.profiling.profiling import ProfileManager -from struphy.utils.arrays import xp +import cunumpy as xp from struphy.utils.pyccel import Pyccelkernel diff --git a/src/struphy/pic/base.py b/src/struphy/pic/base.py index 824c51c0a..1589063c6 100644 --- a/src/struphy/pic/base.py +++ b/src/struphy/pic/base.py @@ -53,7 +53,7 @@ class Intracomm: WeightsParameters, ) from struphy.utils import utils -from struphy.utils.arrays import xp +import cunumpy as xp from struphy.utils.clone_config import CloneConfig from struphy.utils.pyccel import Pyccelkernel diff --git a/src/struphy/pic/particles.py b/src/struphy/pic/particles.py index f662bbac2..a7bca1be7 100644 --- a/src/struphy/pic/particles.py +++ b/src/struphy/pic/particles.py @@ -10,7 +10,7 @@ from struphy.kinetic_background.base import Maxwellian, SumKineticBackground from struphy.pic import utilities_kernels from struphy.pic.base import Particles -from struphy.utils.arrays import xp +import cunumpy as xp class Particles6D(Particles): diff --git a/src/struphy/pic/pushing/pusher.py b/src/struphy/pic/pushing/pusher.py index 53287371c..a668095ca 100644 --- a/src/struphy/pic/pushing/pusher.py +++ b/src/struphy/pic/pushing/pusher.py @@ -6,7 +6,7 @@ from struphy.kernel_arguments.pusher_args_kernels import DerhamArguments, DomainArguments from struphy.pic.base import Particles from struphy.profiling.profiling import ProfileManager -from struphy.utils.arrays import xp +import cunumpy as xp from struphy.utils.pyccel import Pyccelkernel diff --git a/src/struphy/pic/sobol_seq.py b/src/struphy/pic/sobol_seq.py index 9208d813d..97a9e582c 100644 --- a/src/struphy/pic/sobol_seq.py +++ b/src/struphy/pic/sobol_seq.py @@ -19,7 +19,7 @@ from scipy.stats import norm -from struphy.utils.arrays import xp +import cunumpy as xp __all__ = ["i4_bit_hi1", "i4_bit_lo0", "i4_sobol_generate", "i4_sobol", "i4_uniform", "prime_ge", "is_prime"] diff --git a/src/struphy/pic/tests/test_accum_vec_H1.py b/src/struphy/pic/tests/test_accum_vec_H1.py index ab7f3e2aa..3f852cb2f 100644 --- a/src/struphy/pic/tests/test_accum_vec_H1.py +++ b/src/struphy/pic/tests/test_accum_vec_H1.py @@ -57,7 +57,7 @@ def test_accum_poisson(Nel, p, spl_kind, mapping, num_clones, Np=1000): from struphy.pic.accumulation.particles_to_grid import AccumulatorVector from struphy.pic.particles import Particles6D from struphy.pic.utilities import BoundaryParameters, LoadingParameters, WeightsParameters - from struphy.utils.arrays import xp + import cunumpy as xp from struphy.utils.clone_config import CloneConfig if isinstance(MPI.COMM_WORLD, MockComm): diff --git a/src/struphy/pic/tests/test_accumulation.py b/src/struphy/pic/tests/test_accumulation.py index 693df515e..d753e5466 100644 --- a/src/struphy/pic/tests/test_accumulation.py +++ b/src/struphy/pic/tests/test_accumulation.py @@ -61,7 +61,7 @@ def pc_lin_mhd_6d_step_ph_full(Nel, p, spl_kind, mapping, Np, verbose=False): from struphy.pic.particles import Particles6D from struphy.pic.tests.test_pic_legacy_files.accumulation_kernels_3d import kernel_step_ph_full from struphy.pic.utilities import BoundaryParameters, LoadingParameters, WeightsParameters - from struphy.utils.arrays import xp + import cunumpy as xp if isinstance(MPI.COMM_WORLD, MockComm): mpi_comm = None diff --git a/src/struphy/pic/tests/test_binning.py b/src/struphy/pic/tests/test_binning.py index e9e69ae73..053a7e728 100644 --- a/src/struphy/pic/tests/test_binning.py +++ b/src/struphy/pic/tests/test_binning.py @@ -47,7 +47,7 @@ def test_binning_6D_full_f(mapping, show_plot=False): LoadingParameters, WeightsParameters, ) - from struphy.utils.arrays import xp + import cunumpy as xp # Set seed seed = 1234 @@ -280,7 +280,7 @@ def test_binning_6D_delta_f(mapping, show_plot=False): LoadingParameters, WeightsParameters, ) - from struphy.utils.arrays import xp + import cunumpy as xp # Set seed seed = 1234 @@ -477,7 +477,7 @@ def test_binning_6D_full_f_mpi(mapping, show_plot=False): LoadingParameters, WeightsParameters, ) - from struphy.utils.arrays import xp + import cunumpy as xp # Set seed seed = 1234 @@ -774,7 +774,7 @@ def test_binning_6D_delta_f_mpi(mapping, show_plot=False): LoadingParameters, WeightsParameters, ) - from struphy.utils.arrays import xp + import cunumpy as xp # Set seed seed = 1234 diff --git a/src/struphy/pic/tests/test_draw_parallel.py b/src/struphy/pic/tests/test_draw_parallel.py index 5174c83b5..6b9f16976 100644 --- a/src/struphy/pic/tests/test_draw_parallel.py +++ b/src/struphy/pic/tests/test_draw_parallel.py @@ -41,7 +41,7 @@ def test_draw(Nel, p, spl_kind, mapping, ppc=10): from struphy.geometry import domains from struphy.pic.particles import Particles6D from struphy.pic.utilities import BoundaryParameters, LoadingParameters, WeightsParameters - from struphy.utils.arrays import xp + import cunumpy as xp comm = MPI.COMM_WORLD rank = comm.Get_rank() diff --git a/src/struphy/pic/tests/test_mat_vec_filler.py b/src/struphy/pic/tests/test_mat_vec_filler.py index c3ad580f4..67c770ead 100644 --- a/src/struphy/pic/tests/test_mat_vec_filler.py +++ b/src/struphy/pic/tests/test_mat_vec_filler.py @@ -1,6 +1,6 @@ import pytest -from struphy.utils.arrays import xp +import cunumpy as xp @pytest.mark.parametrize("Nel", [[8, 9, 10]]) diff --git a/src/struphy/pic/tests/test_pic_legacy_files/accumulation.py b/src/struphy/pic/tests/test_pic_legacy_files/accumulation.py index 82c88d7cf..4230f2854 100644 --- a/src/struphy/pic/tests/test_pic_legacy_files/accumulation.py +++ b/src/struphy/pic/tests/test_pic_legacy_files/accumulation.py @@ -12,7 +12,7 @@ from psydac.ddm.mpi import mpi as MPI import struphy.pic.tests.test_pic_legacy_files.accumulation_kernels_3d as pic_ker_3d -from struphy.utils.arrays import xp +import cunumpy as xp # import struphy.pic.tests.test_pic_legacy_files.accumulation_kernels_2d as pic_ker_2d diff --git a/src/struphy/pic/tests/test_pic_legacy_files/pusher.py b/src/struphy/pic/tests/test_pic_legacy_files/pusher.py index b609b69d8..6923fed28 100644 --- a/src/struphy/pic/tests/test_pic_legacy_files/pusher.py +++ b/src/struphy/pic/tests/test_pic_legacy_files/pusher.py @@ -1,7 +1,7 @@ import struphy.pic.tests.test_pic_legacy_files.pusher_pos as push_pos import struphy.pic.tests.test_pic_legacy_files.pusher_vel_2d as push_vel_2d import struphy.pic.tests.test_pic_legacy_files.pusher_vel_3d as push_vel_3d -from struphy.utils.arrays import xp +import cunumpy as xp class Pusher: diff --git a/src/struphy/pic/tests/test_pushers.py b/src/struphy/pic/tests/test_pushers.py index 4809b7918..c71cfac2f 100644 --- a/src/struphy/pic/tests/test_pushers.py +++ b/src/struphy/pic/tests/test_pushers.py @@ -34,7 +34,7 @@ def test_push_vxb_analytic(Nel, p, spl_kind, mapping, show_plots=False): from struphy.pic.pushing.pusher import Pusher as Pusher_psy from struphy.pic.tests.test_pic_legacy_files.pusher import Pusher as Pusher_str from struphy.pic.utilities import BoundaryParameters, LoadingParameters, WeightsParameters - from struphy.utils.arrays import xp + import cunumpy as xp comm = MPI.COMM_WORLD rank = comm.Get_rank() @@ -169,7 +169,7 @@ def test_push_bxu_Hdiv(Nel, p, spl_kind, mapping, show_plots=False): from struphy.pic.pushing.pusher import Pusher as Pusher_psy from struphy.pic.tests.test_pic_legacy_files.pusher import Pusher as Pusher_str from struphy.pic.utilities import BoundaryParameters, LoadingParameters, WeightsParameters - from struphy.utils.arrays import xp + import cunumpy as xp comm = MPI.COMM_WORLD rank = comm.Get_rank() @@ -315,7 +315,7 @@ def test_push_bxu_Hcurl(Nel, p, spl_kind, mapping, show_plots=False): from struphy.pic.pushing.pusher import Pusher as Pusher_psy from struphy.pic.tests.test_pic_legacy_files.pusher import Pusher as Pusher_str from struphy.pic.utilities import BoundaryParameters, LoadingParameters, WeightsParameters - from struphy.utils.arrays import xp + import cunumpy as xp comm = MPI.COMM_WORLD rank = comm.Get_rank() @@ -461,7 +461,7 @@ def test_push_bxu_H1vec(Nel, p, spl_kind, mapping, show_plots=False): from struphy.pic.pushing.pusher import Pusher as Pusher_psy from struphy.pic.tests.test_pic_legacy_files.pusher import Pusher as Pusher_str from struphy.pic.utilities import BoundaryParameters, LoadingParameters, WeightsParameters - from struphy.utils.arrays import xp + import cunumpy as xp comm = MPI.COMM_WORLD rank = comm.Get_rank() @@ -607,7 +607,7 @@ def test_push_bxu_Hdiv_pauli(Nel, p, spl_kind, mapping, show_plots=False): from struphy.pic.pushing.pusher import Pusher as Pusher_psy from struphy.pic.tests.test_pic_legacy_files.pusher import Pusher as Pusher_str from struphy.pic.utilities import BoundaryParameters, LoadingParameters, WeightsParameters - from struphy.utils.arrays import xp + import cunumpy as xp comm = MPI.COMM_WORLD rank = comm.Get_rank() @@ -756,7 +756,7 @@ def test_push_eta_rk4(Nel, p, spl_kind, mapping, show_plots=False): from struphy.pic.pushing.pusher import Pusher as Pusher_psy from struphy.pic.tests.test_pic_legacy_files.pusher import Pusher as Pusher_str from struphy.pic.utilities import BoundaryParameters, LoadingParameters, WeightsParameters - from struphy.utils.arrays import xp + import cunumpy as xp comm = MPI.COMM_WORLD rank = comm.Get_rank() diff --git a/src/struphy/pic/tests/test_sorting.py b/src/struphy/pic/tests/test_sorting.py index 244427209..eb0d72751 100644 --- a/src/struphy/pic/tests/test_sorting.py +++ b/src/struphy/pic/tests/test_sorting.py @@ -7,7 +7,7 @@ from struphy.geometry import domains from struphy.pic.particles import Particles6D from struphy.pic.utilities import BoundaryParameters, LoadingParameters, WeightsParameters -from struphy.utils.arrays import xp +import cunumpy as xp @pytest.mark.parametrize("nx", [8, 70]) diff --git a/src/struphy/pic/tests/test_sph.py b/src/struphy/pic/tests/test_sph.py index 8e7b5b5a4..f2b075373 100644 --- a/src/struphy/pic/tests/test_sph.py +++ b/src/struphy/pic/tests/test_sph.py @@ -8,7 +8,7 @@ from struphy.initial import perturbations from struphy.pic.particles import ParticlesSPH from struphy.pic.utilities import BoundaryParameters, LoadingParameters, WeightsParameters -from struphy.utils.arrays import xp +import cunumpy as xp @pytest.mark.parametrize("boxes_per_dim", [(24, 1, 1)]) diff --git a/src/struphy/pic/tests/test_tesselation.py b/src/struphy/pic/tests/test_tesselation.py index 19a02cfad..9e300820c 100644 --- a/src/struphy/pic/tests/test_tesselation.py +++ b/src/struphy/pic/tests/test_tesselation.py @@ -10,7 +10,7 @@ from struphy.initial import perturbations from struphy.pic.particles import ParticlesSPH from struphy.pic.utilities import BoundaryParameters, LoadingParameters, WeightsParameters -from struphy.utils.arrays import xp +import cunumpy as xp @pytest.mark.parametrize("ppb", [8, 12]) diff --git a/src/struphy/pic/utilities.py b/src/struphy/pic/utilities.py index fb8fda634..521060a66 100644 --- a/src/struphy/pic/utilities.py +++ b/src/struphy/pic/utilities.py @@ -5,7 +5,7 @@ OptsRecontructBC, OptsSpatialLoading, ) -from struphy.utils.arrays import xp +import cunumpy as xp class LoadingParameters: diff --git a/src/struphy/polar/basic.py b/src/struphy/polar/basic.py index 49dc21a52..ecf8aca5f 100644 --- a/src/struphy/polar/basic.py +++ b/src/struphy/polar/basic.py @@ -3,7 +3,7 @@ from psydac.linalg.block import BlockVector from psydac.linalg.stencil import StencilVector -from struphy.utils.arrays import xp +import cunumpy as xp class PolarDerhamSpace(VectorSpace): diff --git a/src/struphy/polar/extraction_operators.py b/src/struphy/polar/extraction_operators.py index c4588e997..f58c88f59 100644 --- a/src/struphy/polar/extraction_operators.py +++ b/src/struphy/polar/extraction_operators.py @@ -1,4 +1,4 @@ -from struphy.utils.arrays import xp +import cunumpy as xp # ============================= 2D polar splines (C1) =================================== diff --git a/src/struphy/polar/linear_operators.py b/src/struphy/polar/linear_operators.py index 0412bdba3..9a63202de 100644 --- a/src/struphy/polar/linear_operators.py +++ b/src/struphy/polar/linear_operators.py @@ -6,7 +6,7 @@ from struphy.feec.linear_operators import LinOpWithTransp from struphy.linear_algebra.linalg_kron import kron_matvec_2d from struphy.polar.basic import PolarDerhamSpace, PolarVector -from struphy.utils.arrays import xp +import cunumpy as xp class PolarExtractionOperator(LinOpWithTransp): diff --git a/src/struphy/polar/tests/test_legacy_polar_splines.py b/src/struphy/polar/tests/test_legacy_polar_splines.py index f4c47060a..a87c36a15 100644 --- a/src/struphy/polar/tests/test_legacy_polar_splines.py +++ b/src/struphy/polar/tests/test_legacy_polar_splines.py @@ -12,7 +12,7 @@ def test_polar_splines_2D(plot=False): from struphy.eigenvalue_solvers.spline_space import Spline_space_1d, Tensor_spline_space from struphy.geometry import domains - from struphy.utils.arrays import xp + import cunumpy as xp # parameters # number of elements (number of elements in angular direction must be a multiple of 3) diff --git a/src/struphy/polar/tests/test_polar.py b/src/struphy/polar/tests/test_polar.py index a72abca4c..bd371e1d0 100644 --- a/src/struphy/polar/tests/test_polar.py +++ b/src/struphy/polar/tests/test_polar.py @@ -176,7 +176,7 @@ def test_extraction_ops_and_derivatives(Nel, p, spl_kind): from struphy.polar.basic import PolarDerhamSpace, PolarVector from struphy.polar.extraction_operators import PolarExtractionBlocksC1 from struphy.polar.linear_operators import PolarExtractionOperator, PolarLinearOperator - from struphy.utils.arrays import xp + import cunumpy as xp comm = MPI.COMM_WORLD rank = comm.Get_rank() @@ -307,7 +307,7 @@ def test_projectors(Nel, p, spl_kind): from struphy.eigenvalue_solvers.spline_space import Spline_space_1d, Tensor_spline_space from struphy.feec.psydac_derham import Derham from struphy.geometry.domains import IGAPolarCylinder - from struphy.utils.arrays import xp + import cunumpy as xp comm = MPI.COMM_WORLD rank = comm.Get_rank() diff --git a/src/struphy/post_processing/likwid/plot_likwidproject.py b/src/struphy/post_processing/likwid/plot_likwidproject.py index 0e8abb23b..63584e32c 100644 --- a/src/struphy/post_processing/likwid/plot_likwidproject.py +++ b/src/struphy/post_processing/likwid/plot_likwidproject.py @@ -16,7 +16,7 @@ import struphy.post_processing.likwid.likwid_parser as lp import struphy.post_processing.likwid.maxplotlylib as mply import struphy.post_processing.likwid.roofline_plotter as rp -from struphy.utils.arrays import xp +import cunumpy as xp def clean_string(string_in): diff --git a/src/struphy/post_processing/likwid/plot_time_traces.py b/src/struphy/post_processing/likwid/plot_time_traces.py index 94b491d03..9a3f18622 100644 --- a/src/struphy/post_processing/likwid/plot_time_traces.py +++ b/src/struphy/post_processing/likwid/plot_time_traces.py @@ -7,7 +7,7 @@ # pio.kaleido.scope.mathjax = None import struphy.post_processing.likwid.maxplotlylib as mply -from struphy.utils.arrays import xp +import cunumpy as xp def glob_to_regex(pat: str) -> str: diff --git a/src/struphy/post_processing/likwid/roofline_plotter.py b/src/struphy/post_processing/likwid/roofline_plotter.py index abc6bee6f..d8fa27fe5 100644 --- a/src/struphy/post_processing/likwid/roofline_plotter.py +++ b/src/struphy/post_processing/likwid/roofline_plotter.py @@ -4,7 +4,7 @@ import pandas as pd import yaml -from struphy.utils.arrays import xp +import cunumpy as xp def sort_by_num_threads(bm): diff --git a/src/struphy/post_processing/orbits/orbits_tools.py b/src/struphy/post_processing/orbits/orbits_tools.py index 02776b74f..afe896757 100644 --- a/src/struphy/post_processing/orbits/orbits_tools.py +++ b/src/struphy/post_processing/orbits/orbits_tools.py @@ -6,7 +6,7 @@ from tqdm import tqdm from struphy.post_processing.orbits.orbits_kernels import calculate_guiding_center_from_6d -from struphy.utils.arrays import xp +import cunumpy as xp def post_process_orbit_guiding_center(path_in, path_kinetics_species, species): diff --git a/src/struphy/post_processing/post_processing_tools.py b/src/struphy/post_processing/post_processing_tools.py index d2071e089..403d2a6ac 100644 --- a/src/struphy/post_processing/post_processing_tools.py +++ b/src/struphy/post_processing/post_processing_tools.py @@ -19,7 +19,7 @@ from struphy.models.species import ParticleSpecies from struphy.models.variables import PICVariable from struphy.topology.grids import TensorProductGrid -from struphy.utils.arrays import xp +import cunumpy as xp class ParamsIn: diff --git a/src/struphy/post_processing/pproc_struphy.py b/src/struphy/post_processing/pproc_struphy.py index 38dea12ba..eb3488b96 100644 --- a/src/struphy/post_processing/pproc_struphy.py +++ b/src/struphy/post_processing/pproc_struphy.py @@ -8,7 +8,7 @@ import struphy.post_processing.orbits.orbits_tools as orbits_pproc import struphy.post_processing.post_processing_tools as pproc from struphy.io.setup import import_parameters_py -from struphy.utils.arrays import xp +import cunumpy as xp def main( diff --git a/src/struphy/post_processing/profile_struphy.py b/src/struphy/post_processing/profile_struphy.py index 578e5c2e4..0aeb9c570 100644 --- a/src/struphy/post_processing/profile_struphy.py +++ b/src/struphy/post_processing/profile_struphy.py @@ -5,7 +5,7 @@ from matplotlib import pyplot as plt from struphy.post_processing.cprofile_analyser import get_cprofile_data, replace_keys -from struphy.utils.arrays import xp +import cunumpy as xp def main(): diff --git a/src/struphy/profiling/profiling.py b/src/struphy/profiling/profiling.py index 1ca22fe31..43c9fcddb 100644 --- a/src/struphy/profiling/profiling.py +++ b/src/struphy/profiling/profiling.py @@ -19,7 +19,7 @@ from psydac.ddm.mpi import mpi as MPI -from struphy.utils.arrays import xp +import cunumpy as xp @lru_cache(maxsize=None) # Cache the import result to avoid repeated imports diff --git a/src/struphy/propagators/base.py b/src/struphy/propagators/base.py index e90382cb5..1b83168a8 100644 --- a/src/struphy/propagators/base.py +++ b/src/struphy/propagators/base.py @@ -14,7 +14,7 @@ from struphy.geometry.base import Domain from struphy.io.options import check_option from struphy.models.variables import FEECVariable, PICVariable, SPHVariable, Variable -from struphy.utils.arrays import xp +import cunumpy as xp class Propagator(metaclass=ABCMeta): diff --git a/src/struphy/propagators/propagators_coupling.py b/src/struphy/propagators/propagators_coupling.py index 8a82c084d..fce1e5f66 100644 --- a/src/struphy/propagators/propagators_coupling.py +++ b/src/struphy/propagators/propagators_coupling.py @@ -28,7 +28,7 @@ from struphy.pic.pushing.pusher import Pusher from struphy.polar.basic import PolarVector from struphy.propagators.base import Propagator -from struphy.utils.arrays import xp +import cunumpy as xp from struphy.utils.pyccel import Pyccelkernel diff --git a/src/struphy/propagators/propagators_fields.py b/src/struphy/propagators/propagators_fields.py index 109638c1a..7ec9709f4 100644 --- a/src/struphy/propagators/propagators_fields.py +++ b/src/struphy/propagators/propagators_fields.py @@ -67,7 +67,7 @@ from struphy.pic.particles import Particles5D, Particles6D from struphy.polar.basic import PolarVector from struphy.propagators.base import Propagator -from struphy.utils.arrays import xp +import cunumpy as xp from struphy.utils.pyccel import Pyccelkernel diff --git a/src/struphy/propagators/propagators_markers.py b/src/struphy/propagators/propagators_markers.py index fcd091c6d..ea1776fc2 100644 --- a/src/struphy/propagators/propagators_markers.py +++ b/src/struphy/propagators/propagators_markers.py @@ -30,7 +30,7 @@ from struphy.pic.pushing.pusher import Pusher from struphy.polar.basic import PolarVector from struphy.propagators.base import Propagator -from struphy.utils.arrays import xp +import cunumpy as xp from struphy.utils.pyccel import Pyccelkernel @@ -100,7 +100,7 @@ def allocate(self): # define algorithm butcher = self.options.butcher # temp fix due to refactoring of ButcherTableau: - from struphy.utils.arrays import xp + import cunumpy as xp butcher._a = xp.diag(butcher.a, k=-1) butcher._a = xp.array(list(butcher.a) + [0.0]) @@ -842,7 +842,7 @@ def allocate(self): else: butcher = self.options.butcher # temp fix due to refactoring of ButcherTableau: - from struphy.utils.arrays import xp + import cunumpy as xp butcher._a = xp.diag(butcher.a, k=-1) butcher._a = xp.array(list(butcher.a) + [0.0]) @@ -1290,7 +1290,7 @@ def allocate(self): else: butcher = self.options.butcher # temp fix due to refactoring of ButcherTableau: - from struphy.utils.arrays import xp + import cunumpy as xp butcher._a = xp.diag(butcher.a, k=-1) butcher._a = xp.array(list(butcher.a) + [0.0]) @@ -1432,7 +1432,7 @@ def allocate(self): # choose algorithm self._butcher = self.options.butcher # temp fix due to refactoring of ButcherTableau: - from struphy.utils.arrays import xp + import cunumpy as xp self._butcher._a = xp.diag(self._butcher.a, k=-1) self._butcher._a = xp.array(list(self._butcher.a) + [0.0]) @@ -1566,7 +1566,7 @@ def allocate(self): self._butcher = self.options.butcher # temp fix due to refactoring of ButcherTableau: - from struphy.utils.arrays import xp + import cunumpy as xp self._butcher._a = xp.diag(self._butcher.a, k=-1) self._butcher._a = xp.array(list(self._butcher.a) + [0.0]) diff --git a/src/struphy/propagators/tests/test_gyrokinetic_poisson.py b/src/struphy/propagators/tests/test_gyrokinetic_poisson.py index b1e3cfe33..d519cc3da 100644 --- a/src/struphy/propagators/tests/test_gyrokinetic_poisson.py +++ b/src/struphy/propagators/tests/test_gyrokinetic_poisson.py @@ -11,7 +11,7 @@ from struphy.models.variables import FEECVariable from struphy.propagators.base import Propagator from struphy.propagators.propagators_fields import ImplicitDiffusion -from struphy.utils.arrays import xp +import cunumpy as xp comm = MPI.COMM_WORLD rank = comm.Get_rank() diff --git a/src/struphy/propagators/tests/test_poisson.py b/src/struphy/propagators/tests/test_poisson.py index 659126d14..be0d39291 100644 --- a/src/struphy/propagators/tests/test_poisson.py +++ b/src/struphy/propagators/tests/test_poisson.py @@ -22,7 +22,7 @@ ) from struphy.propagators.base import Propagator from struphy.propagators.propagators_fields import ImplicitDiffusion, Poisson -from struphy.utils.arrays import xp +import cunumpy as xp from struphy.utils.pyccel import Pyccelkernel comm = MPI.COMM_WORLD diff --git a/src/struphy/utils/arrays.py b/src/struphy/utils/arrays.py deleted file mode 100644 index ae2b9ef82..000000000 --- a/src/struphy/utils/arrays.py +++ /dev/null @@ -1,59 +0,0 @@ -import os -from types import ModuleType -from typing import TYPE_CHECKING, Literal - -BackendType = Literal["numpy", "cupy"] - - -class ArrayBackend: - def __init__( - self, - backend: BackendType = "numpy", - verbose: bool = False, - ) -> None: - assert backend.lower() in ["numpy", "cupy"], "Array backend must be either 'numpy' or 'cupy'." - - self._backend: BackendType = "cupy" if backend.lower() == "cupy" else "numpy" - - # Import numpy/cupy - if self.backend == "cupy": - try: - import cupy as cp - - self._xp = cp - except ImportError: - if verbose: - print("CuPy not available.") - self._backend = "numpy" - - if self.backend == "numpy": - import numpy as np - - self._xp = np - - assert isinstance(self.xp, ModuleType) - - if verbose: - print(f"Using {self.xp.__name__} backend.") - - @property - def backend(self) -> BackendType: - return self._backend - - @property - def xp(self) -> ModuleType: - return self._xp - - -# TODO: Make this configurable via environment variable or config file. -array_backend = ArrayBackend( - backend="cupy" if os.getenv("ARRAY_BACKEND", "numpy").lower() == "cupy" else "numpy", - verbose=True, -) - -# TYPE_CHECKING is True when type checking (e.g., mypy), but False at runtime. -# This allows us to use autocompletion for xp (i.e., numpy/cupy) as if numpy was imported. -if TYPE_CHECKING: - import numpy as xp -else: - xp = array_backend.xp diff --git a/src/struphy/utils/clone_config.py b/src/struphy/utils/clone_config.py index b292331b0..ad78973ef 100644 --- a/src/struphy/utils/clone_config.py +++ b/src/struphy/utils/clone_config.py @@ -1,7 +1,7 @@ from psydac.ddm.mpi import MockComm from psydac.ddm.mpi import mpi as MPI -from struphy.utils.arrays import xp +import cunumpy as xp class CloneConfig: diff --git a/src/struphy/utils/utils.py b/src/struphy/utils/utils.py index f9898d36f..1707f0c07 100644 --- a/src/struphy/utils/utils.py +++ b/src/struphy/utils/utils.py @@ -61,7 +61,7 @@ def save_state(state, libpath=STRUPHY_LIBPATH): def print_all_attr(obj): """Print all object's attributes that do not start with "_" to screen.""" - from struphy.utils.arrays import xp + import cunumpy as xp for k in dir(obj): if k[0] != "_": From d344353a28453a759dc76351a2996775beb8e361 Mon Sep 17 00:00:00 2001 From: Max Lindqvist Date: Wed, 22 Oct 2025 13:23:31 +0200 Subject: [PATCH 71/76] Formatting --- .../bsplines/tests/test_bsplines_kernels.py | 3 +-- .../bsplines/tests/test_eval_spline_mpi.py | 3 +-- src/struphy/console/profile.py | 2 +- src/struphy/diagnostics/console_diagn.py | 2 +- src/struphy/diagnostics/continuous_spectra.py | 6 +++--- src/struphy/diagnostics/diagn_tools.py | 2 +- src/struphy/diagnostics/paraview/mesh_creator.py | 3 +-- src/struphy/dispersion_relations/analytic.py | 2 +- src/struphy/dispersion_relations/base.py | 3 +-- src/struphy/dispersion_relations/utilities.py | 3 +-- src/struphy/eigenvalue_solvers/derivatives.py | 3 +-- .../legacy/MHD_eigenvalues_cylinder_1D.py | 2 +- .../legacy/control_variates/control_variate.py | 2 +- .../fB_massless_control_variate.py | 2 +- .../fnB_massless_control_variate.py | 3 +-- .../kinetic_extended/massless_control_variate.py | 3 +-- .../eigenvalue_solvers/legacy/emw_operators.py | 2 +- .../legacy/inner_products_1d.py | 3 +-- .../legacy/inner_products_2d.py | 2 +- .../legacy/inner_products_3d.py | 2 +- .../eigenvalue_solvers/legacy/l2_error_1d.py | 3 +-- .../eigenvalue_solvers/legacy/l2_error_2d.py | 2 +- .../eigenvalue_solvers/legacy/l2_error_3d.py | 2 +- .../legacy/mass_matrices_3d_pre.py | 2 +- .../legacy/massless_operators/fB_arrays.py | 2 +- .../fB_massless_linear_operators.py | 2 +- .../legacy/massless_operators/fB_vv_kernel.py | 2 +- .../eigenvalue_solvers/legacy/mhd_operators_MF.py | 2 +- .../pro_local/mhd_operators_3d_local.py | 2 +- .../pro_local/projectors_local.py | 2 +- .../shape_function_projectors_L2.py | 2 +- .../shape_function_projectors_local.py | 2 +- .../eigenvalue_solvers/mass_matrices_1d.py | 2 +- .../eigenvalue_solvers/mass_matrices_2d.py | 2 +- .../eigenvalue_solvers/mass_matrices_3d.py | 2 +- .../eigenvalue_solvers/mhd_axisymmetric_main.py | 2 +- .../eigenvalue_solvers/mhd_axisymmetric_pproc.py | 3 +-- src/struphy/eigenvalue_solvers/mhd_operators.py | 2 +- .../eigenvalue_solvers/mhd_operators_core.py | 2 +- .../eigenvalue_solvers/projectors_global.py | 2 +- src/struphy/eigenvalue_solvers/spline_space.py | 3 +-- src/struphy/examples/_draw_parallel.py | 2 +- src/struphy/feec/basis_projection_ops.py | 2 +- src/struphy/feec/linear_operators.py | 2 +- src/struphy/feec/mass.py | 2 +- src/struphy/feec/preconditioner.py | 2 +- src/struphy/feec/projectors.py | 2 +- src/struphy/feec/psydac_derham.py | 2 +- src/struphy/feec/tests/test_basis_ops.py | 4 ++-- src/struphy/feec/tests/test_derham.py | 2 +- src/struphy/feec/tests/test_eval_field.py | 3 +-- src/struphy/feec/tests/test_field_init.py | 8 ++++---- src/struphy/feec/tests/test_l2_projectors.py | 2 +- src/struphy/feec/tests/test_local_projectors.py | 2 +- src/struphy/feec/tests/test_lowdim_nel_is_1.py | 2 +- src/struphy/feec/tests/test_mass_matrices.py | 8 ++++---- src/struphy/feec/tests/test_toarray_struphy.py | 2 +- src/struphy/feec/tests/test_tosparse_struphy.py | 2 +- src/struphy/feec/tests/xx_test_preconds.py | 2 +- src/struphy/feec/utilities.py | 2 +- src/struphy/feec/utilities_local_projectors.py | 3 ++- src/struphy/feec/variational_utilities.py | 2 +- src/struphy/fields_background/base.py | 2 +- src/struphy/fields_background/coil_fields/base.py | 3 +-- .../fields_background/coil_fields/coil_fields.py | 3 ++- src/struphy/fields_background/equils.py | 2 +- .../fields_background/tests/test_desc_equil.py | 3 +-- .../tests/test_generic_equils.py | 2 +- .../fields_background/tests/test_mhd_equils.py | 2 +- .../tests/test_numerical_mhd_equil.py | 2 +- src/struphy/geometry/base.py | 2 +- src/struphy/geometry/domains.py | 3 ++- src/struphy/geometry/tests/test_domain.py | 15 ++++++++++----- src/struphy/geometry/utilities.py | 2 +- src/struphy/initial/eigenfunctions.py | 2 +- src/struphy/initial/perturbations.py | 2 +- .../initial/tests/test_init_perturbations.py | 2 +- src/struphy/initial/utilities.py | 2 +- src/struphy/io/options.py | 2 +- src/struphy/io/output_handling.py | 3 +-- src/struphy/io/setup.py | 2 +- src/struphy/kinetic_background/base.py | 3 ++- src/struphy/kinetic_background/maxwellians.py | 3 ++- src/struphy/kinetic_background/tests/test_base.py | 2 +- .../kinetic_background/tests/test_maxwellians.py | 14 +++++++------- src/struphy/linear_algebra/linalg_kron.py | 3 +-- src/struphy/linear_algebra/saddle_point.py | 2 +- .../tests/test_saddlepoint_massmatrices.py | 5 ++--- .../tests/test_stencil_dot_kernels.py | 4 ++-- .../tests/test_stencil_transpose_kernels.py | 4 ++-- src/struphy/main.py | 2 +- src/struphy/models/base.py | 2 +- src/struphy/models/fluid.py | 2 +- src/struphy/models/hybrid.py | 2 +- src/struphy/models/kinetic.py | 2 +- src/struphy/models/species.py | 2 +- src/struphy/models/tests/test_verif_EulerSPH.py | 2 +- src/struphy/models/tests/test_verif_LinearMHD.py | 2 +- src/struphy/models/tests/test_verif_Maxwell.py | 2 +- src/struphy/models/tests/test_verif_Poisson.py | 2 +- .../tests/test_verif_VlasovAmpereOneSpecies.py | 2 +- src/struphy/models/tests/verification.py | 2 +- src/struphy/models/toy.py | 2 +- src/struphy/models/variables.py | 2 +- src/struphy/ode/solvers.py | 2 +- src/struphy/ode/tests/test_ode_feec.py | 2 +- src/struphy/pic/accumulation/particles_to_grid.py | 2 +- src/struphy/pic/base.py | 2 +- src/struphy/pic/particles.py | 3 ++- src/struphy/pic/pushing/pusher.py | 2 +- src/struphy/pic/sobol_seq.py | 3 +-- src/struphy/pic/tests/test_accum_vec_H1.py | 2 +- src/struphy/pic/tests/test_accumulation.py | 2 +- src/struphy/pic/tests/test_binning.py | 8 ++++---- src/struphy/pic/tests/test_draw_parallel.py | 2 +- src/struphy/pic/tests/test_mat_vec_filler.py | 3 +-- .../tests/test_pic_legacy_files/accumulation.py | 2 +- .../pic/tests/test_pic_legacy_files/pusher.py | 3 ++- src/struphy/pic/tests/test_pushers.py | 12 ++++++------ src/struphy/pic/tests/test_sorting.py | 2 +- src/struphy/pic/tests/test_sph.py | 2 +- src/struphy/pic/tests/test_tesselation.py | 2 +- src/struphy/pic/utilities.py | 3 ++- src/struphy/polar/basic.py | 3 +-- src/struphy/polar/linear_operators.py | 2 +- .../polar/tests/test_legacy_polar_splines.py | 2 +- src/struphy/polar/tests/test_polar.py | 4 ++-- .../post_processing/likwid/plot_likwidproject.py | 2 +- .../post_processing/likwid/plot_time_traces.py | 2 +- .../post_processing/likwid/roofline_plotter.py | 3 +-- .../post_processing/orbits/orbits_tools.py | 2 +- .../post_processing/post_processing_tools.py | 2 +- src/struphy/post_processing/pproc_struphy.py | 2 +- src/struphy/post_processing/profile_struphy.py | 2 +- src/struphy/profiling/profiling.py | 3 +-- src/struphy/propagators/base.py | 2 +- src/struphy/propagators/propagators_coupling.py | 2 +- src/struphy/propagators/propagators_fields.py | 2 +- src/struphy/propagators/propagators_markers.py | 2 +- .../propagators/tests/test_gyrokinetic_poisson.py | 2 +- src/struphy/propagators/tests/test_poisson.py | 2 +- src/struphy/utils/clone_config.py | 3 +-- 142 files changed, 186 insertions(+), 197 deletions(-) diff --git a/src/struphy/bsplines/tests/test_bsplines_kernels.py b/src/struphy/bsplines/tests/test_bsplines_kernels.py index 6aab9e0de..c1010dd08 100644 --- a/src/struphy/bsplines/tests/test_bsplines_kernels.py +++ b/src/struphy/bsplines/tests/test_bsplines_kernels.py @@ -1,10 +1,9 @@ import time +import cunumpy as xp import pytest from psydac.ddm.mpi import mpi as MPI -import cunumpy as xp - @pytest.mark.parametrize("Nel", [[8, 9, 10]]) @pytest.mark.parametrize("p", [[1, 2, 1], [2, 1, 2], [3, 4, 3]]) diff --git a/src/struphy/bsplines/tests/test_eval_spline_mpi.py b/src/struphy/bsplines/tests/test_eval_spline_mpi.py index 9f867edea..0703fb418 100644 --- a/src/struphy/bsplines/tests/test_eval_spline_mpi.py +++ b/src/struphy/bsplines/tests/test_eval_spline_mpi.py @@ -1,11 +1,10 @@ from sys import int_info from time import sleep +import cunumpy as xp import pytest from psydac.ddm.mpi import mpi as MPI -import cunumpy as xp - @pytest.mark.parametrize("Nel", [[8, 9, 10]]) @pytest.mark.parametrize("p", [[1, 2, 3], [3, 1, 2]]) diff --git a/src/struphy/console/profile.py b/src/struphy/console/profile.py index 167c2905a..9577a00d9 100644 --- a/src/struphy/console/profile.py +++ b/src/struphy/console/profile.py @@ -6,12 +6,12 @@ def struphy_profile(dirs, replace, all, n_lines, print_callers, savefig): import os import pickle + import cunumpy as xp import yaml from matplotlib import pyplot as plt import struphy.utils.utils as utils from struphy.post_processing.cprofile_analyser import get_cprofile_data, replace_keys - import cunumpy as xp # Read struphy state file state = utils.read_state() diff --git a/src/struphy/diagnostics/console_diagn.py b/src/struphy/diagnostics/console_diagn.py index a835cf130..e110d1497 100644 --- a/src/struphy/diagnostics/console_diagn.py +++ b/src/struphy/diagnostics/console_diagn.py @@ -5,13 +5,13 @@ import os import subprocess +import cunumpy as xp import h5py import yaml import struphy import struphy.utils.utils as utils from struphy.diagnostics.diagn_tools import plot_distr_fun, plot_scalars, plots_videos_2d -import cunumpy as xp def main(): diff --git a/src/struphy/diagnostics/continuous_spectra.py b/src/struphy/diagnostics/continuous_spectra.py index 767273d04..5ed069179 100644 --- a/src/struphy/diagnostics/continuous_spectra.py +++ b/src/struphy/diagnostics/continuous_spectra.py @@ -37,9 +37,10 @@ def get_mhd_continua_2d(space, domain, omega2, U_eig, m_range, omega_A, div_tol, the radial location s_spec[m][0], squared eigenfrequencis s_spec[m][1] and global mode index s_spec[m][2] corresponding to slow sound modes for each poloidal mode number m in m_range. """ - import struphy.bsplines.bsplines as bsp import cunumpy as xp + import struphy.bsplines.bsplines as bsp + # greville points in radial direction (s) gN_1 = bsp.greville(space.T[0], space.p[0], space.spl_kind[0]) gD_1 = bsp.greville(space.t[0], space.p[0] - 1, space.spl_kind[0]) @@ -151,9 +152,8 @@ def get_mhd_continua_2d(space, domain, omega2, U_eig, m_range, omega_A, div_tol, import os import shutil - import yaml - import cunumpy as xp + import yaml # parse arguments parser = argparse.ArgumentParser( diff --git a/src/struphy/diagnostics/diagn_tools.py b/src/struphy/diagnostics/diagn_tools.py index cdb564f27..d714306f4 100644 --- a/src/struphy/diagnostics/diagn_tools.py +++ b/src/struphy/diagnostics/diagn_tools.py @@ -3,6 +3,7 @@ import shutil import subprocess +import cunumpy as xp import matplotlib.colors as colors import matplotlib.pyplot as plt from scipy.fft import fftfreq, fftn @@ -10,7 +11,6 @@ from tqdm import tqdm from struphy.dispersion_relations import analytic -import cunumpy as xp def power_spectrum_2d( diff --git a/src/struphy/diagnostics/paraview/mesh_creator.py b/src/struphy/diagnostics/paraview/mesh_creator.py index 76a8d89a8..c6c8d89a0 100644 --- a/src/struphy/diagnostics/paraview/mesh_creator.py +++ b/src/struphy/diagnostics/paraview/mesh_creator.py @@ -1,11 +1,10 @@ # from tqdm import tqdm +import cunumpy as xp import vtkmodules.all as vtk from vtkmodules.util.numpy_support import numpy_to_vtk as np2vtk from vtkmodules.util.numpy_support import vtk_to_numpy as vtk2np from vtkmodules.vtkCommonDataModel import vtkUnstructuredGrid -import cunumpy as xp - def make_ugrid_and_write_vtu(filename: str, writer, vtk_dir, gvec, s_range, u_range, v_range, periodic): """A helper function to orchestrate operations to run many test cases. diff --git a/src/struphy/dispersion_relations/analytic.py b/src/struphy/dispersion_relations/analytic.py index 747e97379..fb7a40ccd 100644 --- a/src/struphy/dispersion_relations/analytic.py +++ b/src/struphy/dispersion_relations/analytic.py @@ -1,12 +1,12 @@ "Analytic dispersion relations." +import cunumpy as xp from numpy.polynomial import Polynomial from scipy.optimize import fsolve from struphy.dispersion_relations.base import ContinuousSpectra1D, DispersionRelations1D from struphy.dispersion_relations.utilities import Zplasma from struphy.fields_background.equils import set_defaults -import cunumpy as xp class Maxwell1D(DispersionRelations1D): diff --git a/src/struphy/dispersion_relations/base.py b/src/struphy/dispersion_relations/base.py index 845bdb2cb..6994ae2fb 100644 --- a/src/struphy/dispersion_relations/base.py +++ b/src/struphy/dispersion_relations/base.py @@ -2,9 +2,8 @@ from abc import ABCMeta, abstractmethod -from matplotlib import pyplot as plt - import cunumpy as xp +from matplotlib import pyplot as plt class DispersionRelations1D(metaclass=ABCMeta): diff --git a/src/struphy/dispersion_relations/utilities.py b/src/struphy/dispersion_relations/utilities.py index 535bc9a5d..b796eb321 100644 --- a/src/struphy/dispersion_relations/utilities.py +++ b/src/struphy/dispersion_relations/utilities.py @@ -1,6 +1,5 @@ -from scipy.special import erfi - import cunumpy as xp +from scipy.special import erfi def Zplasma(xi, der=0): diff --git a/src/struphy/eigenvalue_solvers/derivatives.py b/src/struphy/eigenvalue_solvers/derivatives.py index d8c7b9df3..0e34cceb1 100644 --- a/src/struphy/eigenvalue_solvers/derivatives.py +++ b/src/struphy/eigenvalue_solvers/derivatives.py @@ -6,9 +6,8 @@ Modules to assemble discrete derivatives. """ -import scipy.sparse as spa - import cunumpy as xp +import scipy.sparse as spa # ================== 1d incident matrix ======================= diff --git a/src/struphy/eigenvalue_solvers/legacy/MHD_eigenvalues_cylinder_1D.py b/src/struphy/eigenvalue_solvers/legacy/MHD_eigenvalues_cylinder_1D.py index 732cd5709..9fbc38ce8 100644 --- a/src/struphy/eigenvalue_solvers/legacy/MHD_eigenvalues_cylinder_1D.py +++ b/src/struphy/eigenvalue_solvers/legacy/MHD_eigenvalues_cylinder_1D.py @@ -1,3 +1,4 @@ +import cunumpy as xp import scipy as sc import scipy.sparse as spa import scipy.special as sp @@ -9,7 +10,6 @@ import struphy.eigenvalue_solvers.mass_matrices_1d as mass import struphy.eigenvalue_solvers.projectors_global as pro import struphy.eigenvalue_solvers.spline_space as spl -import cunumpy as xp # numerical solution of the general ideal MHD eigenvalue problem in a cylinder using 1d B-splines in radial direction diff --git a/src/struphy/eigenvalue_solvers/legacy/control_variates/control_variate.py b/src/struphy/eigenvalue_solvers/legacy/control_variates/control_variate.py index 719447f7e..a4b95eb06 100644 --- a/src/struphy/eigenvalue_solvers/legacy/control_variates/control_variate.py +++ b/src/struphy/eigenvalue_solvers/legacy/control_variates/control_variate.py @@ -6,11 +6,11 @@ Class for control variates in delta-f method for current coupling scheme. """ +import cunumpy as xp import scipy.sparse as spa import struphy.feec.basics.kernels_3d as ker import struphy.feec.control_variates.kernels_control_variate as ker_cv -import cunumpy as xp class terms_control_variate: diff --git a/src/struphy/eigenvalue_solvers/legacy/control_variates/kinetic_extended/fB_massless_control_variate.py b/src/struphy/eigenvalue_solvers/legacy/control_variates/kinetic_extended/fB_massless_control_variate.py index 11ecd04f3..49be8c3ef 100644 --- a/src/struphy/eigenvalue_solvers/legacy/control_variates/kinetic_extended/fB_massless_control_variate.py +++ b/src/struphy/eigenvalue_solvers/legacy/control_variates/kinetic_extended/fB_massless_control_variate.py @@ -1,9 +1,9 @@ +import cunumpy as xp import scipy.sparse as spa import struphy.feec.basics.kernels_3d as ker import struphy.feec.control_variates.kinetic_extended.fB_massless_kernels_control_variate as ker_cv import struphy.feec.control_variates.kinetic_extended.fnB_massless_cv_kernel_2 as ker_cv2 -import cunumpy as xp def bv_right( diff --git a/src/struphy/eigenvalue_solvers/legacy/control_variates/kinetic_extended/fnB_massless_control_variate.py b/src/struphy/eigenvalue_solvers/legacy/control_variates/kinetic_extended/fnB_massless_control_variate.py index 14e3315fd..d52a3e90e 100644 --- a/src/struphy/eigenvalue_solvers/legacy/control_variates/kinetic_extended/fnB_massless_control_variate.py +++ b/src/struphy/eigenvalue_solvers/legacy/control_variates/kinetic_extended/fnB_massless_control_variate.py @@ -1,9 +1,8 @@ +import cunumpy as xp import hylife.utilitis_FEEC.basics.kernels_3d as ker import hylife.utilitis_FEEC.control_variates.fnB_massless_kernels_control_variate as ker_cv import scipy.sparse as spa -import cunumpy as xp - def bv_pre(tol, n, LO_inv, tensor_space_FEM, p, Nel, idnx, idny, idnz): r""" diff --git a/src/struphy/eigenvalue_solvers/legacy/control_variates/kinetic_extended/massless_control_variate.py b/src/struphy/eigenvalue_solvers/legacy/control_variates/kinetic_extended/massless_control_variate.py index 06fd6366a..4e97422f0 100644 --- a/src/struphy/eigenvalue_solvers/legacy/control_variates/kinetic_extended/massless_control_variate.py +++ b/src/struphy/eigenvalue_solvers/legacy/control_variates/kinetic_extended/massless_control_variate.py @@ -1,9 +1,8 @@ +import cunumpy as xp import hylife.utilitis_FEEC.basics.kernels_3d as ker import hylife.utilitis_FEEC.control_variates.massless_kernels_control_variate as ker_cv import scipy.sparse as spa -import cunumpy as xp - def bv_pre(u, uvalue, tensor_space_FEM, p, Nel, idnx, idny, idnz): r""" diff --git a/src/struphy/eigenvalue_solvers/legacy/emw_operators.py b/src/struphy/eigenvalue_solvers/legacy/emw_operators.py index 13286de97..e2fd4ed22 100755 --- a/src/struphy/eigenvalue_solvers/legacy/emw_operators.py +++ b/src/struphy/eigenvalue_solvers/legacy/emw_operators.py @@ -6,11 +6,11 @@ Class for 2D/3D linear MHD projection operators. """ +import cunumpy as xp import scipy.sparse as spa import struphy.eigenvalue_solvers.kernels_3d as ker import struphy.eigenvalue_solvers.legacy.mass_matrices_3d_pre as mass_3d_pre -import cunumpy as xp class EMW_operators: diff --git a/src/struphy/eigenvalue_solvers/legacy/inner_products_1d.py b/src/struphy/eigenvalue_solvers/legacy/inner_products_1d.py index f1fc0a00d..b4f019995 100644 --- a/src/struphy/eigenvalue_solvers/legacy/inner_products_1d.py +++ b/src/struphy/eigenvalue_solvers/legacy/inner_products_1d.py @@ -6,9 +6,8 @@ Modules to compute inner products in 1d. """ -import scipy.sparse as spa - import cunumpy as xp +import scipy.sparse as spa # ======= inner product in V0 ==================== diff --git a/src/struphy/eigenvalue_solvers/legacy/inner_products_2d.py b/src/struphy/eigenvalue_solvers/legacy/inner_products_2d.py index 8d606538d..05df4725f 100644 --- a/src/struphy/eigenvalue_solvers/legacy/inner_products_2d.py +++ b/src/struphy/eigenvalue_solvers/legacy/inner_products_2d.py @@ -6,10 +6,10 @@ Modules to compute inner products with given functions in 2D. """ +import cunumpy as xp import scipy.sparse as spa import struphy.eigenvalue_solvers.kernels_2d as ker -import cunumpy as xp # ================ inner product in V0 =========================== diff --git a/src/struphy/eigenvalue_solvers/legacy/inner_products_3d.py b/src/struphy/eigenvalue_solvers/legacy/inner_products_3d.py index ccc451027..20d95c05c 100644 --- a/src/struphy/eigenvalue_solvers/legacy/inner_products_3d.py +++ b/src/struphy/eigenvalue_solvers/legacy/inner_products_3d.py @@ -6,10 +6,10 @@ Modules to compute inner products with given functions in 3D. """ +import cunumpy as xp import scipy.sparse as spa import struphy.eigenvalue_solvers.kernels_3d as ker -import cunumpy as xp # ================ inner product in V0 =========================== diff --git a/src/struphy/eigenvalue_solvers/legacy/l2_error_1d.py b/src/struphy/eigenvalue_solvers/legacy/l2_error_1d.py index 64a7c3362..d568d3207 100644 --- a/src/struphy/eigenvalue_solvers/legacy/l2_error_1d.py +++ b/src/struphy/eigenvalue_solvers/legacy/l2_error_1d.py @@ -6,9 +6,8 @@ Modules to compute L2-errors in 1d. """ -import scipy.sparse as spa - import cunumpy as xp +import scipy.sparse as spa # ======= error in V0 ==================== diff --git a/src/struphy/eigenvalue_solvers/legacy/l2_error_2d.py b/src/struphy/eigenvalue_solvers/legacy/l2_error_2d.py index 5b9c89c9b..452dd570b 100644 --- a/src/struphy/eigenvalue_solvers/legacy/l2_error_2d.py +++ b/src/struphy/eigenvalue_solvers/legacy/l2_error_2d.py @@ -6,10 +6,10 @@ Modules to compute L2-errors of discrete p-forms with analytical forms in 2D. """ +import cunumpy as xp import scipy.sparse as spa import struphy.eigenvalue_solvers.kernels_2d as ker -import cunumpy as xp # ======= error in V0 ==================== diff --git a/src/struphy/eigenvalue_solvers/legacy/l2_error_3d.py b/src/struphy/eigenvalue_solvers/legacy/l2_error_3d.py index 4535c3d8e..7553e3a83 100644 --- a/src/struphy/eigenvalue_solvers/legacy/l2_error_3d.py +++ b/src/struphy/eigenvalue_solvers/legacy/l2_error_3d.py @@ -6,10 +6,10 @@ Modules to compute L2-errors of discrete p-forms with analytical forms in 3D. """ +import cunumpy as xp import scipy.sparse as spa import struphy.eigenvalue_solvers.kernels_3d as ker -import cunumpy as xp # ======= error in V0 ==================== diff --git a/src/struphy/eigenvalue_solvers/legacy/mass_matrices_3d_pre.py b/src/struphy/eigenvalue_solvers/legacy/mass_matrices_3d_pre.py index 0fdc03526..eecb68293 100644 --- a/src/struphy/eigenvalue_solvers/legacy/mass_matrices_3d_pre.py +++ b/src/struphy/eigenvalue_solvers/legacy/mass_matrices_3d_pre.py @@ -6,11 +6,11 @@ Modules to obtain preconditioners for mass matrices in 3D. """ +import cunumpy as xp import scipy.sparse as spa import struphy.eigenvalue_solvers.spline_space as spl import struphy.linear_algebra.linalg_kron as linkron -import cunumpy as xp # ================ inverse mass matrix in V0 =========================== diff --git a/src/struphy/eigenvalue_solvers/legacy/massless_operators/fB_arrays.py b/src/struphy/eigenvalue_solvers/legacy/massless_operators/fB_arrays.py index e57f0af1b..e74302878 100644 --- a/src/struphy/eigenvalue_solvers/legacy/massless_operators/fB_arrays.py +++ b/src/struphy/eigenvalue_solvers/legacy/massless_operators/fB_arrays.py @@ -1,13 +1,13 @@ import time import timeit +import cunumpy as xp import scipy.sparse as spa from psydac.ddm.mpi import mpi as MPI import struphy.geometry.mappings_3d as mapping3d import struphy.geometry.mappings_3d_fast as mapping_fast import struphy.linear_algebra.linalg_kernels as linalg -import cunumpy as xp class Temp_arrays: diff --git a/src/struphy/eigenvalue_solvers/legacy/massless_operators/fB_massless_linear_operators.py b/src/struphy/eigenvalue_solvers/legacy/massless_operators/fB_massless_linear_operators.py index 5081e52e5..2ddddc64a 100644 --- a/src/struphy/eigenvalue_solvers/legacy/massless_operators/fB_massless_linear_operators.py +++ b/src/struphy/eigenvalue_solvers/legacy/massless_operators/fB_massless_linear_operators.py @@ -1,11 +1,11 @@ import time +import cunumpy as xp import scipy.sparse as spa import struphy.feec.massless_operators.fB_bb_kernel as bb_kernel import struphy.feec.massless_operators.fB_bv_kernel as bv_kernel import struphy.feec.massless_operators.fB_vv_kernel as vv_kernel -import cunumpy as xp class Massless_linear_operators: diff --git a/src/struphy/eigenvalue_solvers/legacy/massless_operators/fB_vv_kernel.py b/src/struphy/eigenvalue_solvers/legacy/massless_operators/fB_vv_kernel.py index 97b72356c..4a5a2dbe0 100644 --- a/src/struphy/eigenvalue_solvers/legacy/massless_operators/fB_vv_kernel.py +++ b/src/struphy/eigenvalue_solvers/legacy/massless_operators/fB_vv_kernel.py @@ -1,9 +1,9 @@ +import cunumpy as xp from numpy import empty, exp, floor, zeros import struphy.bsplines.bsplines_kernels as bsp import struphy.geometry.mappings_kernels as mapping_fast import struphy.linear_algebra.linalg_kernels as linalg -import cunumpy as xp # ========================================================================================== diff --git a/src/struphy/eigenvalue_solvers/legacy/mhd_operators_MF.py b/src/struphy/eigenvalue_solvers/legacy/mhd_operators_MF.py index a5ca07cf0..560314458 100644 --- a/src/struphy/eigenvalue_solvers/legacy/mhd_operators_MF.py +++ b/src/struphy/eigenvalue_solvers/legacy/mhd_operators_MF.py @@ -1,9 +1,9 @@ +import cunumpy as xp import scipy.sparse as spa from struphy.eigenvalue_solvers.projectors_global import Projectors_tensor_3d from struphy.eigenvalue_solvers.spline_space import Tensor_spline_space from struphy.linear_algebra.linalg_kron import kron_matvec_3d, kron_solve_3d -import cunumpy as xp # ================================================================================================= diff --git a/src/struphy/eigenvalue_solvers/legacy/projectors_local/pro_local/mhd_operators_3d_local.py b/src/struphy/eigenvalue_solvers/legacy/projectors_local/pro_local/mhd_operators_3d_local.py index 485ae0ed2..0c96616de 100644 --- a/src/struphy/eigenvalue_solvers/legacy/projectors_local/pro_local/mhd_operators_3d_local.py +++ b/src/struphy/eigenvalue_solvers/legacy/projectors_local/pro_local/mhd_operators_3d_local.py @@ -8,13 +8,13 @@ import sys +import cunumpy as xp import scipy.sparse as spa import source_run.kernels_projectors_evaluation as ker_eva import struphy.feec.basics.kernels_3d as ker_loc_3d import struphy.feec.bsplines as bsp import struphy.feec.projectors.pro_local.kernels_projectors_local_mhd as ker_loc -import cunumpy as xp class projectors_local_mhd: diff --git a/src/struphy/eigenvalue_solvers/legacy/projectors_local/pro_local/projectors_local.py b/src/struphy/eigenvalue_solvers/legacy/projectors_local/pro_local/projectors_local.py index 380e49fbb..dacc4f243 100644 --- a/src/struphy/eigenvalue_solvers/legacy/projectors_local/pro_local/projectors_local.py +++ b/src/struphy/eigenvalue_solvers/legacy/projectors_local/pro_local/projectors_local.py @@ -6,11 +6,11 @@ Classes for local projectors in 1D and 3D based on quasi-spline interpolation and histopolation. """ +import cunumpy as xp import scipy.sparse as spa import struphy.feec.bsplines as bsp import struphy.feec.projectors.pro_local.kernels_projectors_local as ker_loc -import cunumpy as xp # ======================= 1d ==================================== diff --git a/src/struphy/eigenvalue_solvers/legacy/projectors_local/shape_pro_local/shape_function_projectors_L2.py b/src/struphy/eigenvalue_solvers/legacy/projectors_local/shape_pro_local/shape_function_projectors_L2.py index ca066518d..20814c8ac 100644 --- a/src/struphy/eigenvalue_solvers/legacy/projectors_local/shape_pro_local/shape_function_projectors_L2.py +++ b/src/struphy/eigenvalue_solvers/legacy/projectors_local/shape_pro_local/shape_function_projectors_L2.py @@ -5,12 +5,12 @@ Classes for local projectors in 1D and 3D based on quasi-spline interpolation and histopolation. """ +import cunumpy as xp import scipy.sparse as spa from psydac.ddm.mpi import mpi as MPI import struphy.feec.bsplines as bsp import struphy.feec.projectors.shape_pro_local.shape_L2_projector_kernel as ker_loc -import cunumpy as xp # ======================= 3d ==================================== diff --git a/src/struphy/eigenvalue_solvers/legacy/projectors_local/shape_pro_local/shape_function_projectors_local.py b/src/struphy/eigenvalue_solvers/legacy/projectors_local/shape_pro_local/shape_function_projectors_local.py index 13699d60b..7c9425e47 100644 --- a/src/struphy/eigenvalue_solvers/legacy/projectors_local/shape_pro_local/shape_function_projectors_local.py +++ b/src/struphy/eigenvalue_solvers/legacy/projectors_local/shape_pro_local/shape_function_projectors_local.py @@ -5,12 +5,12 @@ Classes for local projectors in 1D and 3D based on quasi-spline interpolation and histopolation. """ +import cunumpy as xp import scipy.sparse as spa from psydac.ddm.mpi import mpi as MPI import struphy.feec.bsplines as bsp import struphy.feec.projectors.shape_pro_local.shape_local_projector_kernel as ker_loc -import cunumpy as xp # ======================= 3d ==================================== diff --git a/src/struphy/eigenvalue_solvers/mass_matrices_1d.py b/src/struphy/eigenvalue_solvers/mass_matrices_1d.py index 3c39c177b..b5013c088 100644 --- a/src/struphy/eigenvalue_solvers/mass_matrices_1d.py +++ b/src/struphy/eigenvalue_solvers/mass_matrices_1d.py @@ -2,10 +2,10 @@ # # Copyright 2020 Florian Holderied +import cunumpy as xp import scipy.sparse as spa import struphy.bsplines.bsplines as bsp -import cunumpy as xp # ======= mass matrices in 1D ==================== diff --git a/src/struphy/eigenvalue_solvers/mass_matrices_2d.py b/src/struphy/eigenvalue_solvers/mass_matrices_2d.py index 70e199640..c2c6c3ae9 100644 --- a/src/struphy/eigenvalue_solvers/mass_matrices_2d.py +++ b/src/struphy/eigenvalue_solvers/mass_matrices_2d.py @@ -2,10 +2,10 @@ # # Copyright 2020 Florian Holderied +import cunumpy as xp import scipy.sparse as spa import struphy.eigenvalue_solvers.kernels_2d as ker -import cunumpy as xp # ================ mass matrix in V0 =========================== diff --git a/src/struphy/eigenvalue_solvers/mass_matrices_3d.py b/src/struphy/eigenvalue_solvers/mass_matrices_3d.py index 364631a7b..05f019e13 100644 --- a/src/struphy/eigenvalue_solvers/mass_matrices_3d.py +++ b/src/struphy/eigenvalue_solvers/mass_matrices_3d.py @@ -2,10 +2,10 @@ # # Copyright 2020 Florian Holderied (florian.holderied@ipp.mpg.de) +import cunumpy as xp import scipy.sparse as spa import struphy.eigenvalue_solvers.kernels_3d as ker -import cunumpy as xp # ================ mass matrix in V0 =========================== diff --git a/src/struphy/eigenvalue_solvers/mhd_axisymmetric_main.py b/src/struphy/eigenvalue_solvers/mhd_axisymmetric_main.py index 081190707..c44c97335 100644 --- a/src/struphy/eigenvalue_solvers/mhd_axisymmetric_main.py +++ b/src/struphy/eigenvalue_solvers/mhd_axisymmetric_main.py @@ -32,11 +32,11 @@ def solve_mhd_ev_problem_2d(num_params, eq_mhd, n_tor, basis_tor="i", path_out=N import os import time + import cunumpy as xp import scipy.sparse as spa from struphy.eigenvalue_solvers.mhd_operators import MHDOperators from struphy.eigenvalue_solvers.spline_space import Spline_space_1d, Tensor_spline_space - import cunumpy as xp print("\nStart of eigenspectrum calculation for toroidal mode number", n_tor) print("") diff --git a/src/struphy/eigenvalue_solvers/mhd_axisymmetric_pproc.py b/src/struphy/eigenvalue_solvers/mhd_axisymmetric_pproc.py index fba128b94..10e9e274e 100644 --- a/src/struphy/eigenvalue_solvers/mhd_axisymmetric_pproc.py +++ b/src/struphy/eigenvalue_solvers/mhd_axisymmetric_pproc.py @@ -3,9 +3,8 @@ def main(): import argparse import os - import yaml - import cunumpy as xp + import yaml # parse arguments parser = argparse.ArgumentParser(description="Restrict a full .npy eigenspectrum to a range of eigenfrequencies.") diff --git a/src/struphy/eigenvalue_solvers/mhd_operators.py b/src/struphy/eigenvalue_solvers/mhd_operators.py index 60bed6e4b..5f1462c24 100644 --- a/src/struphy/eigenvalue_solvers/mhd_operators.py +++ b/src/struphy/eigenvalue_solvers/mhd_operators.py @@ -3,11 +3,11 @@ # Copyright 2021 Florian Holderied (florian.holderied@ipp.mpg.de) +import cunumpy as xp import scipy.sparse as spa import struphy.eigenvalue_solvers.legacy.mass_matrices_3d_pre as mass_3d_pre from struphy.eigenvalue_solvers.mhd_operators_core import MHDOperatorsCore -import cunumpy as xp class MHDOperators: diff --git a/src/struphy/eigenvalue_solvers/mhd_operators_core.py b/src/struphy/eigenvalue_solvers/mhd_operators_core.py index cc7f26d03..76752ccc3 100644 --- a/src/struphy/eigenvalue_solvers/mhd_operators_core.py +++ b/src/struphy/eigenvalue_solvers/mhd_operators_core.py @@ -3,12 +3,12 @@ # Copyright 2021 Florian Holderied (florian.holderied@ipp.mpg.de) +import cunumpy as xp import scipy.sparse as spa import struphy.eigenvalue_solvers.kernels_projectors_global_mhd as ker import struphy.eigenvalue_solvers.mass_matrices_2d as mass_2d import struphy.eigenvalue_solvers.mass_matrices_3d as mass_3d -import cunumpy as xp class MHDOperatorsCore: diff --git a/src/struphy/eigenvalue_solvers/projectors_global.py b/src/struphy/eigenvalue_solvers/projectors_global.py index 0b31c2f61..fa7b69958 100644 --- a/src/struphy/eigenvalue_solvers/projectors_global.py +++ b/src/struphy/eigenvalue_solvers/projectors_global.py @@ -6,11 +6,11 @@ Classes for commuting projectors in 1D, 2D and 3D based on global spline interpolation and histopolation. """ +import cunumpy as xp import scipy.sparse as spa import struphy.bsplines.bsplines as bsp from struphy.linear_algebra.linalg_kron import kron_lusolve_2d, kron_lusolve_3d, kron_matvec_2d, kron_matvec_3d -import cunumpy as xp # ======================= 1d ==================================== diff --git a/src/struphy/eigenvalue_solvers/spline_space.py b/src/struphy/eigenvalue_solvers/spline_space.py index ef49aeaa1..b36ad73db 100644 --- a/src/struphy/eigenvalue_solvers/spline_space.py +++ b/src/struphy/eigenvalue_solvers/spline_space.py @@ -6,11 +6,10 @@ Basic modules to create tensor-product finite element spaces of univariate B-splines. """ +import cunumpy as xp import matplotlib import scipy.sparse as spa -import cunumpy as xp - matplotlib.rcParams.update({"font.size": 16}) import matplotlib.pyplot as plt diff --git a/src/struphy/examples/_draw_parallel.py b/src/struphy/examples/_draw_parallel.py index 5cfd66349..e95598b3c 100644 --- a/src/struphy/examples/_draw_parallel.py +++ b/src/struphy/examples/_draw_parallel.py @@ -1,9 +1,9 @@ +import cunumpy as xp from psydac.ddm.mpi import mpi as MPI from struphy.feec.psydac_derham import Derham from struphy.geometry import domains from struphy.pic.particles import Particles6D -import cunumpy as xp def main(): diff --git a/src/struphy/feec/basis_projection_ops.py b/src/struphy/feec/basis_projection_ops.py index 6a0502f96..3bce4701f 100644 --- a/src/struphy/feec/basis_projection_ops.py +++ b/src/struphy/feec/basis_projection_ops.py @@ -1,3 +1,4 @@ +import cunumpy as xp from psydac.api.settings import PSYDAC_BACKEND_GPYCCEL from psydac.ddm.mpi import mpi as MPI from psydac.fem.basic import FemSpace @@ -14,7 +15,6 @@ from struphy.feec.utilities import RotationMatrix from struphy.polar.basic import PolarDerhamSpace, PolarVector from struphy.polar.linear_operators import PolarExtractionOperator -import cunumpy as xp from struphy.utils.pyccel import Pyccelkernel diff --git a/src/struphy/feec/linear_operators.py b/src/struphy/feec/linear_operators.py index 3e30d4a76..3a29ea821 100644 --- a/src/struphy/feec/linear_operators.py +++ b/src/struphy/feec/linear_operators.py @@ -1,6 +1,7 @@ import itertools from abc import abstractmethod +import cunumpy as xp from psydac.ddm.mpi import MockComm from psydac.ddm.mpi import mpi as MPI from psydac.linalg.basic import LinearOperator, Vector, VectorSpace @@ -10,7 +11,6 @@ from struphy.feec.utilities import apply_essential_bc_to_array from struphy.polar.basic import PolarDerhamSpace -import cunumpy as xp class LinOpWithTransp(LinearOperator): diff --git a/src/struphy/feec/mass.py b/src/struphy/feec/mass.py index f41a25c9f..76a26bd4d 100644 --- a/src/struphy/feec/mass.py +++ b/src/struphy/feec/mass.py @@ -1,6 +1,7 @@ import inspect from copy import deepcopy +import cunumpy as xp from psydac.api.settings import PSYDAC_BACKEND_GPYCCEL from psydac.ddm.mpi import mpi as MPI from psydac.fem.tensor import TensorFemSpace @@ -16,7 +17,6 @@ from struphy.feec.utilities import RotationMatrix from struphy.geometry.base import Domain from struphy.polar.linear_operators import PolarExtractionOperator -import cunumpy as xp from struphy.utils.pyccel import Pyccelkernel diff --git a/src/struphy/feec/preconditioner.py b/src/struphy/feec/preconditioner.py index 8b5a915c9..f3016b532 100644 --- a/src/struphy/feec/preconditioner.py +++ b/src/struphy/feec/preconditioner.py @@ -1,3 +1,4 @@ +import cunumpy as xp from psydac.api.essential_bc import apply_essential_bc_stencil from psydac.ddm.cart import CartDecomposition, DomainDecomposition from psydac.fem.tensor import TensorFemSpace @@ -11,7 +12,6 @@ from struphy.feec.linear_operators import BoundaryOperator from struphy.feec.mass import WeightedMassOperator -import cunumpy as xp class MassMatrixPreconditioner(LinearOperator): diff --git a/src/struphy/feec/projectors.py b/src/struphy/feec/projectors.py index 561468328..a291d18bd 100644 --- a/src/struphy/feec/projectors.py +++ b/src/struphy/feec/projectors.py @@ -1,3 +1,4 @@ +import cunumpy as xp from psydac.api.settings import PSYDAC_BACKEND_GPYCCEL from psydac.ddm.mpi import mpi as MPI from psydac.feec.global_projectors import GlobalProjector @@ -37,7 +38,6 @@ from struphy.kernel_arguments.local_projectors_args_kernels import LocalProjectorsArguments from struphy.polar.basic import PolarVector from struphy.polar.linear_operators import PolarExtractionOperator -import cunumpy as xp class CommutingProjector: diff --git a/src/struphy/feec/psydac_derham.py b/src/struphy/feec/psydac_derham.py index 2cdbe9332..f296d95a9 100644 --- a/src/struphy/feec/psydac_derham.py +++ b/src/struphy/feec/psydac_derham.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 import importlib.metadata +import cunumpy as xp import psydac.core.bsplines as bsp from psydac.ddm.cart import DomainDecomposition from psydac.ddm.mpi import MockComm, MockMPI @@ -33,7 +34,6 @@ from struphy.polar.basic import PolarDerhamSpace, PolarVector from struphy.polar.extraction_operators import PolarExtractionBlocksC1 from struphy.polar.linear_operators import PolarExtractionOperator, PolarLinearOperator -import cunumpy as xp class Derham: diff --git a/src/struphy/feec/tests/test_basis_ops.py b/src/struphy/feec/tests/test_basis_ops.py index c695f1a57..7b06e09e1 100644 --- a/src/struphy/feec/tests/test_basis_ops.py +++ b/src/struphy/feec/tests/test_basis_ops.py @@ -14,6 +14,7 @@ def test_some_basis_ops(Nel, p, spl_kind, mapping): """ from time import time + import cunumpy as xp from psydac.ddm.mpi import mpi as MPI from psydac.linalg.block import BlockVector from psydac.linalg.stencil import StencilVector @@ -24,7 +25,6 @@ def test_some_basis_ops(Nel, p, spl_kind, mapping): from struphy.feec.psydac_derham import Derham from struphy.fields_background.equils import HomogenSlab from struphy.geometry import domains - import cunumpy as xp # mpi communicator MPI_COMM = MPI.COMM_WORLD @@ -464,6 +464,7 @@ def test_some_basis_ops(Nel, p, spl_kind, mapping): ) @pytest.mark.parametrize("mapping", [["IGAPolarCylinder", {"a": 1.0, "Lz": 3.0}]]) def test_basis_ops_polar(Nel, p, spl_kind, dirichlet_bc, mapping, show_plots=False): + import cunumpy as xp from psydac.ddm.mpi import mpi as MPI from struphy.eigenvalue_solvers.mhd_operators import MHDOperators @@ -474,7 +475,6 @@ def test_basis_ops_polar(Nel, p, spl_kind, dirichlet_bc, mapping, show_plots=Fal from struphy.fields_background.equils import ScrewPinch from struphy.geometry import domains from struphy.polar.basic import PolarVector - import cunumpy as xp mpi_comm = MPI.COMM_WORLD mpi_rank = mpi_comm.Get_rank() diff --git a/src/struphy/feec/tests/test_derham.py b/src/struphy/feec/tests/test_derham.py index f00ff6835..c5c0e57ea 100644 --- a/src/struphy/feec/tests/test_derham.py +++ b/src/struphy/feec/tests/test_derham.py @@ -7,6 +7,7 @@ def test_psydac_derham(Nel, p, spl_kind): """Remark: p=even projectors yield slightly different results, pass with atol=1e-3.""" + import cunumpy as xp from psydac.ddm.mpi import mpi as MPI from psydac.linalg.block import BlockVector from psydac.linalg.stencil import StencilVector @@ -14,7 +15,6 @@ def test_psydac_derham(Nel, p, spl_kind): from struphy.eigenvalue_solvers.spline_space import Spline_space_1d, Tensor_spline_space from struphy.feec.psydac_derham import Derham from struphy.feec.utilities import compare_arrays - import cunumpy as xp comm = MPI.COMM_WORLD rank = comm.Get_rank() diff --git a/src/struphy/feec/tests/test_eval_field.py b/src/struphy/feec/tests/test_eval_field.py index 8341a557e..6148fa41e 100644 --- a/src/struphy/feec/tests/test_eval_field.py +++ b/src/struphy/feec/tests/test_eval_field.py @@ -1,9 +1,8 @@ +import cunumpy as xp import pytest from psydac.ddm.mpi import MockComm from psydac.ddm.mpi import mpi as MPI -import cunumpy as xp - @pytest.mark.parametrize("Nel", [[8, 9, 10]]) @pytest.mark.parametrize("p", [[3, 2, 4]]) diff --git a/src/struphy/feec/tests/test_field_init.py b/src/struphy/feec/tests/test_field_init.py index 6d414b821..292edf76a 100644 --- a/src/struphy/feec/tests/test_field_init.py +++ b/src/struphy/feec/tests/test_field_init.py @@ -9,11 +9,11 @@ def test_bckgr_init_const(Nel, p, spl_kind, spaces, vec_comps): """Test field background initialization of "LogicalConst" with multiple fields in params.""" + import cunumpy as xp from psydac.ddm.mpi import mpi as MPI from struphy.feec.psydac_derham import Derham from struphy.io.options import FieldsBackground - import cunumpy as xp comm = MPI.COMM_WORLD rank = comm.Get_rank() @@ -64,6 +64,7 @@ def test_bckgr_init_mhd(Nel, p, spl_kind, with_desc=False, with_gvec=False, show import inspect + import cunumpy as xp from matplotlib import pyplot as plt from psydac.ddm.mpi import mpi as MPI @@ -72,7 +73,6 @@ def test_bckgr_init_mhd(Nel, p, spl_kind, with_desc=False, with_gvec=False, show from struphy.fields_background.base import FluidEquilibrium, FluidEquilibriumWithB from struphy.geometry import domains from struphy.io.options import FieldsBackground - import cunumpy as xp comm = MPI.COMM_WORLD rank = comm.Get_rank() @@ -1083,13 +1083,13 @@ def test_bckgr_init_mhd(Nel, p, spl_kind, with_desc=False, with_gvec=False, show def test_sincos_init_const(Nel, p, spl_kind, show_plot=False): """Test field perturbation with ModesSin + ModesCos on top of of "LogicalConst" with multiple fields in params.""" + import cunumpy as xp from matplotlib import pyplot as plt from psydac.ddm.mpi import mpi as MPI from struphy.feec.psydac_derham import Derham from struphy.initial.perturbations import ModesCos, ModesSin from struphy.io.options import FieldsBackground - import cunumpy as xp comm = MPI.COMM_WORLD rank = comm.Get_rank() @@ -1312,12 +1312,12 @@ def test_sincos_init_const(Nel, p, spl_kind, show_plot=False): def test_noise_init(Nel, p, spl_kind, space, direction): """Only tests 1d noise ('e1', 'e2', 'e3') !!""" + import cunumpy as xp from psydac.ddm.mpi import mpi as MPI from struphy.feec.psydac_derham import Derham from struphy.feec.utilities import compare_arrays from struphy.initial.perturbations import Noise - import cunumpy as xp comm = MPI.COMM_WORLD rank = comm.Get_rank() diff --git a/src/struphy/feec/tests/test_l2_projectors.py b/src/struphy/feec/tests/test_l2_projectors.py index f59011766..6d3695caa 100644 --- a/src/struphy/feec/tests/test_l2_projectors.py +++ b/src/struphy/feec/tests/test_l2_projectors.py @@ -1,5 +1,6 @@ import inspect +import cunumpy as xp import matplotlib.pyplot as plt import pytest from psydac.ddm.mpi import mpi as MPI @@ -8,7 +9,6 @@ from struphy.feec.projectors import L2Projector from struphy.feec.psydac_derham import Derham from struphy.geometry import domains -import cunumpy as xp @pytest.mark.parametrize("Nel", [[16, 32, 1]]) diff --git a/src/struphy/feec/tests/test_local_projectors.py b/src/struphy/feec/tests/test_local_projectors.py index 72fc8ff69..ce2abda01 100644 --- a/src/struphy/feec/tests/test_local_projectors.py +++ b/src/struphy/feec/tests/test_local_projectors.py @@ -1,6 +1,7 @@ import inspect import time +import cunumpy as xp import matplotlib.pyplot as plt import pytest from psydac.ddm.mpi import MockComm @@ -12,7 +13,6 @@ from struphy.feec.local_projectors_kernels import fill_matrix_column from struphy.feec.psydac_derham import Derham from struphy.feec.utilities_local_projectors import get_one_spline, get_span_and_basis, get_values_and_indices_splines -import cunumpy as xp def get_span_and_basis(pts, space): diff --git a/src/struphy/feec/tests/test_lowdim_nel_is_1.py b/src/struphy/feec/tests/test_lowdim_nel_is_1.py index 5f875f9de..fdbe6be3d 100644 --- a/src/struphy/feec/tests/test_lowdim_nel_is_1.py +++ b/src/struphy/feec/tests/test_lowdim_nel_is_1.py @@ -7,13 +7,13 @@ def test_lowdim_derham(Nel, p, spl_kind, do_plot=False): """Test Nel=1 in various directions.""" + import cunumpy as xp from matplotlib import pyplot as plt from psydac.ddm.mpi import mpi as MPI from psydac.linalg.block import BlockVector from psydac.linalg.stencil import StencilVector from struphy.feec.psydac_derham import Derham - import cunumpy as xp comm = MPI.COMM_WORLD rank = comm.Get_rank() diff --git a/src/struphy/feec/tests/test_mass_matrices.py b/src/struphy/feec/tests/test_mass_matrices.py index c45be5c9f..a57d67cdc 100644 --- a/src/struphy/feec/tests/test_mass_matrices.py +++ b/src/struphy/feec/tests/test_mass_matrices.py @@ -12,6 +12,7 @@ def test_mass(Nel, p, spl_kind, dirichlet_bc, mapping, show_plots=False): """Compare Struphy mass matrices to Struphy-legacy mass matrices.""" + import cunumpy as xp from psydac.ddm.mpi import mpi as MPI from struphy.eigenvalue_solvers.mhd_operators import MHDOperators @@ -21,7 +22,6 @@ def test_mass(Nel, p, spl_kind, dirichlet_bc, mapping, show_plots=False): from struphy.feec.utilities import RotationMatrix, compare_arrays, create_equal_random_arrays from struphy.fields_background.equils import ScrewPinch, ShearedSlab from struphy.geometry import domains - import cunumpy as xp mpi_comm = MPI.COMM_WORLD mpi_rank = mpi_comm.Get_rank() @@ -376,6 +376,7 @@ def test_mass(Nel, p, spl_kind, dirichlet_bc, mapping, show_plots=False): def test_mass_polar(Nel, p, spl_kind, dirichlet_bc, mapping, show_plots=False): """Compare Struphy polar mass matrices to Struphy-legacy polar mass matrices.""" + import cunumpy as xp from psydac.ddm.mpi import mpi as MPI from struphy.eigenvalue_solvers.mhd_operators import MHDOperators @@ -386,7 +387,6 @@ def test_mass_polar(Nel, p, spl_kind, dirichlet_bc, mapping, show_plots=False): from struphy.fields_background.equils import ScrewPinch from struphy.geometry import domains from struphy.polar.basic import PolarVector - import cunumpy as xp mpi_comm = MPI.COMM_WORLD mpi_rank = mpi_comm.Get_rank() @@ -575,6 +575,7 @@ def test_mass_preconditioner(Nel, p, spl_kind, dirichlet_bc, mapping, show_plots import time + import cunumpy as xp from psydac.ddm.mpi import mpi as MPI from psydac.linalg.solvers import inverse @@ -584,7 +585,6 @@ def test_mass_preconditioner(Nel, p, spl_kind, dirichlet_bc, mapping, show_plots from struphy.feec.utilities import create_equal_random_arrays from struphy.fields_background.equils import ScrewPinch, ShearedSlab from struphy.geometry import domains - import cunumpy as xp mpi_comm = MPI.COMM_WORLD mpi_rank = mpi_comm.Get_rank() @@ -882,6 +882,7 @@ def test_mass_preconditioner_polar(Nel, p, spl_kind, dirichlet_bc, mapping, show import time + import cunumpy as xp from psydac.ddm.mpi import mpi as MPI from psydac.linalg.solvers import inverse @@ -892,7 +893,6 @@ def test_mass_preconditioner_polar(Nel, p, spl_kind, dirichlet_bc, mapping, show from struphy.fields_background.equils import ScrewPinch from struphy.geometry import domains from struphy.polar.basic import PolarVector - import cunumpy as xp mpi_comm = MPI.COMM_WORLD mpi_rank = mpi_comm.Get_rank() diff --git a/src/struphy/feec/tests/test_toarray_struphy.py b/src/struphy/feec/tests/test_toarray_struphy.py index 3d76e55de..0279293ea 100644 --- a/src/struphy/feec/tests/test_toarray_struphy.py +++ b/src/struphy/feec/tests/test_toarray_struphy.py @@ -12,13 +12,13 @@ def test_toarray_struphy(Nel, p, spl_kind, mapping): TODO """ + import cunumpy as xp from psydac.ddm.mpi import mpi as MPI from struphy.feec.mass import WeightedMassOperators from struphy.feec.psydac_derham import Derham from struphy.feec.utilities import compare_arrays, create_equal_random_arrays from struphy.geometry import domains - import cunumpy as xp comm = MPI.COMM_WORLD rank = comm.Get_rank() diff --git a/src/struphy/feec/tests/test_tosparse_struphy.py b/src/struphy/feec/tests/test_tosparse_struphy.py index 8b8135ed7..020ab9e29 100644 --- a/src/struphy/feec/tests/test_tosparse_struphy.py +++ b/src/struphy/feec/tests/test_tosparse_struphy.py @@ -14,6 +14,7 @@ def test_tosparse_struphy(Nel, p, spl_kind, mapping): TODO """ + import cunumpy as xp from psydac.ddm.mpi import MockComm from psydac.ddm.mpi import mpi as MPI @@ -21,7 +22,6 @@ def test_tosparse_struphy(Nel, p, spl_kind, mapping): from struphy.feec.psydac_derham import Derham from struphy.feec.utilities import create_equal_random_arrays from struphy.geometry import domains - import cunumpy as xp comm = MPI.COMM_WORLD rank = comm.Get_rank() diff --git a/src/struphy/feec/tests/xx_test_preconds.py b/src/struphy/feec/tests/xx_test_preconds.py index 081f1e0fe..267e0279a 100644 --- a/src/struphy/feec/tests/xx_test_preconds.py +++ b/src/struphy/feec/tests/xx_test_preconds.py @@ -12,6 +12,7 @@ ], ) def test_mass_preconditioner(Nel, p, spl_kind, mapping): + import cunumpy as xp from psydac.ddm.mpi import mpi as MPI from psydac.linalg.block import BlockVector from psydac.linalg.stencil import StencilVector @@ -21,7 +22,6 @@ def test_mass_preconditioner(Nel, p, spl_kind, mapping): from struphy.feec.preconditioner import MassMatrixPreconditioner from struphy.feec.psydac_derham import Derham from struphy.geometry import domains - import cunumpy as xp MPI_COMM = MPI.COMM_WORLD diff --git a/src/struphy/feec/utilities.py b/src/struphy/feec/utilities.py index 98fddd024..aa3912857 100644 --- a/src/struphy/feec/utilities.py +++ b/src/struphy/feec/utilities.py @@ -1,3 +1,4 @@ +import cunumpy as xp from psydac.api.essential_bc import apply_essential_bc_stencil from psydac.fem.tensor import TensorFemSpace from psydac.fem.vector import VectorFemSpace @@ -8,7 +9,6 @@ import struphy.feec.utilities_kernels as kernels from struphy.feec import banded_to_stencil_kernels as bts from struphy.polar.basic import PolarVector -import cunumpy as xp class RotationMatrix: diff --git a/src/struphy/feec/utilities_local_projectors.py b/src/struphy/feec/utilities_local_projectors.py index 67defc766..9ff91a120 100644 --- a/src/struphy/feec/utilities_local_projectors.py +++ b/src/struphy/feec/utilities_local_projectors.py @@ -1,6 +1,7 @@ -from struphy.feec.local_projectors_kernels import are_quadrature_points_zero, get_rows, select_quasi_points import cunumpy as xp +from struphy.feec.local_projectors_kernels import are_quadrature_points_zero, get_rows, select_quasi_points + def split_points( IoH, diff --git a/src/struphy/feec/variational_utilities.py b/src/struphy/feec/variational_utilities.py index b6034645d..12695bfa2 100644 --- a/src/struphy/feec/variational_utilities.py +++ b/src/struphy/feec/variational_utilities.py @@ -1,5 +1,6 @@ from copy import deepcopy +import cunumpy as xp from psydac.linalg.basic import IdentityOperator, Vector from psydac.linalg.block import BlockVector from psydac.linalg.solvers import inverse @@ -12,7 +13,6 @@ ) from struphy.feec.linear_operators import LinOpWithTransp from struphy.feec.psydac_derham import Derham -import cunumpy as xp class BracketOperator(LinOpWithTransp): diff --git a/src/struphy/fields_background/base.py b/src/struphy/fields_background/base.py index 398a0c402..ccc3db90e 100644 --- a/src/struphy/fields_background/base.py +++ b/src/struphy/fields_background/base.py @@ -2,11 +2,11 @@ from abc import ABCMeta, abstractmethod +import cunumpy as xp from matplotlib import pyplot as plt from pyevtk.hl import gridToVTK from struphy.geometry.base import Domain -import cunumpy as xp class FluidEquilibrium(metaclass=ABCMeta): diff --git a/src/struphy/fields_background/coil_fields/base.py b/src/struphy/fields_background/coil_fields/base.py index 0e4002f15..3b068c62d 100644 --- a/src/struphy/fields_background/coil_fields/base.py +++ b/src/struphy/fields_background/coil_fields/base.py @@ -1,10 +1,9 @@ from abc import ABCMeta, abstractmethod +import cunumpy as xp from matplotlib import pyplot as plt from pyevtk.hl import gridToVTK -import cunumpy as xp - class CoilMagneticField(metaclass=ABCMeta): """ diff --git a/src/struphy/fields_background/coil_fields/coil_fields.py b/src/struphy/fields_background/coil_fields/coil_fields.py index fc19d5494..e1f66c71d 100644 --- a/src/struphy/fields_background/coil_fields/coil_fields.py +++ b/src/struphy/fields_background/coil_fields/coil_fields.py @@ -1,6 +1,7 @@ +import cunumpy as xp + from struphy.feec.psydac_derham import Derham from struphy.fields_background.coil_fields.base import CoilMagneticField, load_csv_data -import cunumpy as xp class RatGUI(CoilMagneticField): diff --git a/src/struphy/fields_background/equils.py b/src/struphy/fields_background/equils.py index f18ab92d8..93688b55f 100644 --- a/src/struphy/fields_background/equils.py +++ b/src/struphy/fields_background/equils.py @@ -7,6 +7,7 @@ import warnings from time import time +import cunumpy as xp from scipy.integrate import odeint, quad from scipy.interpolate import RectBivariateSpline, UnivariateSpline from scipy.optimize import fsolve, minimize @@ -28,7 +29,6 @@ NumericalMHDequilibrium, ) from struphy.fields_background.mhd_equil.eqdsk import readeqdsk -import cunumpy as xp from struphy.utils.utils import read_state, subp_run diff --git a/src/struphy/fields_background/tests/test_desc_equil.py b/src/struphy/fields_background/tests/test_desc_equil.py index b06a47d11..5aca31b8d 100644 --- a/src/struphy/fields_background/tests/test_desc_equil.py +++ b/src/struphy/fields_background/tests/test_desc_equil.py @@ -1,10 +1,9 @@ import importlib.util +import cunumpy as xp import pytest from matplotlib import pyplot as plt -import cunumpy as xp - desc_spec = importlib.util.find_spec("desc") diff --git a/src/struphy/fields_background/tests/test_generic_equils.py b/src/struphy/fields_background/tests/test_generic_equils.py index 4bd5b078c..77ca8baaa 100644 --- a/src/struphy/fields_background/tests/test_generic_equils.py +++ b/src/struphy/fields_background/tests/test_generic_equils.py @@ -1,3 +1,4 @@ +import cunumpy as xp import pytest from matplotlib import pyplot as plt @@ -5,7 +6,6 @@ GenericCartesianFluidEquilibrium, GenericCartesianFluidEquilibriumWithB, ) -import cunumpy as xp def test_generic_equils(show=False): diff --git a/src/struphy/fields_background/tests/test_mhd_equils.py b/src/struphy/fields_background/tests/test_mhd_equils.py index b1536b2d7..494d707b3 100644 --- a/src/struphy/fields_background/tests/test_mhd_equils.py +++ b/src/struphy/fields_background/tests/test_mhd_equils.py @@ -1,7 +1,7 @@ +import cunumpy as xp import pytest from struphy.fields_background import equils -import cunumpy as xp @pytest.mark.parametrize( diff --git a/src/struphy/fields_background/tests/test_numerical_mhd_equil.py b/src/struphy/fields_background/tests/test_numerical_mhd_equil.py index 4f3b0f70c..aa1278d5d 100644 --- a/src/struphy/fields_background/tests/test_numerical_mhd_equil.py +++ b/src/struphy/fields_background/tests/test_numerical_mhd_equil.py @@ -1,7 +1,7 @@ +import cunumpy as xp import pytest from struphy.fields_background.base import FluidEquilibrium, LogicalMHDequilibrium -import cunumpy as xp @pytest.mark.parametrize( diff --git a/src/struphy/geometry/base.py b/src/struphy/geometry/base.py index 7936d8cd6..a789913e7 100644 --- a/src/struphy/geometry/base.py +++ b/src/struphy/geometry/base.py @@ -3,6 +3,7 @@ from abc import ABCMeta, abstractmethod +import cunumpy as xp import h5py from scipy.sparse import csc_matrix, kron from scipy.sparse.linalg import splu, spsolve @@ -11,7 +12,6 @@ from struphy.geometry import evaluation_kernels, transform_kernels from struphy.kernel_arguments.pusher_args_kernels import DomainArguments from struphy.linear_algebra import linalg_kron -import cunumpy as xp class Domain(metaclass=ABCMeta): diff --git a/src/struphy/geometry/domains.py b/src/struphy/geometry/domains.py index ee22b04f6..024b980c9 100644 --- a/src/struphy/geometry/domains.py +++ b/src/struphy/geometry/domains.py @@ -2,6 +2,8 @@ import copy +import cunumpy as xp + from struphy.fields_background.base import AxisymmMHDequilibrium from struphy.fields_background.equils import EQDSKequilibrium from struphy.geometry.base import ( @@ -12,7 +14,6 @@ interp_mapping, ) from struphy.geometry.utilities import field_line_tracing -import cunumpy as xp class Tokamak(PoloidalSplineTorus): diff --git a/src/struphy/geometry/tests/test_domain.py b/src/struphy/geometry/tests/test_domain.py index 61a06cc47..c9a489331 100644 --- a/src/struphy/geometry/tests/test_domain.py +++ b/src/struphy/geometry/tests/test_domain.py @@ -4,9 +4,10 @@ def test_prepare_arg(): """Tests prepare_arg static method in domain base class.""" - from struphy.geometry.base import Domain import cunumpy as xp + from struphy.geometry.base import Domain + def a1(e1, e2, e3): return e1 * e2 @@ -158,9 +159,10 @@ def a_vec(e1, e2, e3): def test_evaluation_mappings(mapping): """Tests domain object creation with default parameters and evaluation of metric coefficients.""" + import cunumpy as xp + from struphy.geometry import domains from struphy.geometry.base import Domain - import cunumpy as xp # arrays: arr1 = xp.linspace(0.0, 1.0, 4) @@ -317,9 +319,10 @@ def test_evaluation_mappings(mapping): def test_pullback(): """Tests pullbacks to p-forms.""" + import cunumpy as xp + from struphy.geometry import domains from struphy.geometry.base import Domain - import cunumpy as xp # arrays: arr1 = xp.linspace(0.0, 1.0, 4) @@ -476,9 +479,10 @@ def fun(x, y, z): def test_pushforward(): """Tests pushforward of p-forms.""" + import cunumpy as xp + from struphy.geometry import domains from struphy.geometry.base import Domain - import cunumpy as xp # arrays: arr1 = xp.linspace(0.0, 1.0, 4) @@ -635,9 +639,10 @@ def fun(e1, e2, e3): def test_transform(): """Tests transformation of p-forms.""" + import cunumpy as xp + from struphy.geometry import domains from struphy.geometry.base import Domain - import cunumpy as xp # arrays: arr1 = xp.linspace(0.0, 1.0, 4) diff --git a/src/struphy/geometry/utilities.py b/src/struphy/geometry/utilities.py index 0f61950f8..ccc159692 100644 --- a/src/struphy/geometry/utilities.py +++ b/src/struphy/geometry/utilities.py @@ -3,6 +3,7 @@ from typing import Callable +import cunumpy as xp import numpy as np # from typing import TYPE_CHECKING @@ -17,7 +18,6 @@ from struphy.geometry.utilities_kernels import weighted_arc_lengths_flux_surface from struphy.io.options import GivenInBasis from struphy.linear_algebra.linalg_kron import kron_lusolve_2d -import cunumpy as xp def field_line_tracing( diff --git a/src/struphy/initial/eigenfunctions.py b/src/struphy/initial/eigenfunctions.py index 9d71268e2..2f66fcacb 100644 --- a/src/struphy/initial/eigenfunctions.py +++ b/src/struphy/initial/eigenfunctions.py @@ -1,11 +1,11 @@ import os +import cunumpy as xp import yaml from psydac.api.discretization import discretize from sympde.topology import Derham, Line from struphy.fields_background.equils import set_defaults -import cunumpy as xp class InitialMHDAxisymHdivEigFun: diff --git a/src/struphy/initial/perturbations.py b/src/struphy/initial/perturbations.py index 011ed56ef..767f899c9 100644 --- a/src/struphy/initial/perturbations.py +++ b/src/struphy/initial/perturbations.py @@ -3,12 +3,12 @@ from dataclasses import dataclass +import cunumpy as xp import scipy import scipy.special from struphy.initial.base import Perturbation from struphy.io.options import GivenInBasis, NoiseDirections, check_option -import cunumpy as xp @dataclass diff --git a/src/struphy/initial/tests/test_init_perturbations.py b/src/struphy/initial/tests/test_init_perturbations.py index 1fce1021e..2f5fa3176 100644 --- a/src/struphy/initial/tests/test_init_perturbations.py +++ b/src/struphy/initial/tests/test_init_perturbations.py @@ -20,6 +20,7 @@ def test_init_modes(Nel, p, spl_kind, mapping, combine_comps=None, do_plot=False): """Test the initialization Field.initialize_coeffs with all "Modes" classes in perturbations.py.""" + import cunumpy as xp from matplotlib import pyplot as plt from psydac.ddm.mpi import mpi as MPI @@ -29,7 +30,6 @@ def test_init_modes(Nel, p, spl_kind, mapping, combine_comps=None, do_plot=False from struphy.initial import perturbations from struphy.initial.base import Perturbation from struphy.models.variables import FEECVariable - import cunumpy as xp comm = MPI.COMM_WORLD rank = comm.Get_rank() diff --git a/src/struphy/initial/utilities.py b/src/struphy/initial/utilities.py index 71027a97d..7af042249 100644 --- a/src/struphy/initial/utilities.py +++ b/src/struphy/initial/utilities.py @@ -1,10 +1,10 @@ import os +import cunumpy as xp import h5py from struphy.fields_background.equils import set_defaults from struphy.io.output_handling import DataContainer -import cunumpy as xp class InitFromOutput: diff --git a/src/struphy/io/options.py b/src/struphy/io/options.py index d1107fb75..cecd4b72c 100644 --- a/src/struphy/io/options.py +++ b/src/struphy/io/options.py @@ -2,10 +2,10 @@ from dataclasses import dataclass from typing import Literal, get_args +import cunumpy as xp from psydac.ddm.mpi import mpi as MPI from struphy.physics.physics import ConstantsOfNature -import cunumpy as xp ## Literal options diff --git a/src/struphy/io/output_handling.py b/src/struphy/io/output_handling.py index 05e030d00..734a2d1a3 100644 --- a/src/struphy/io/output_handling.py +++ b/src/struphy/io/output_handling.py @@ -1,9 +1,8 @@ import ctypes import os -import h5py - import cunumpy as xp +import h5py class DataContainer: diff --git a/src/struphy/io/setup.py b/src/struphy/io/setup.py index 1f0ec7522..78a295b35 100644 --- a/src/struphy/io/setup.py +++ b/src/struphy/io/setup.py @@ -5,12 +5,12 @@ import sys from types import ModuleType +import cunumpy as xp from psydac.ddm.mpi import mpi as MPI from struphy.geometry.base import Domain from struphy.io.options import DerhamOptions from struphy.topology.grids import TensorProductGrid -import cunumpy as xp def import_parameters_py(params_path: str) -> ModuleType: diff --git a/src/struphy/kinetic_background/base.py b/src/struphy/kinetic_background/base.py index 4e59ac910..41c7b6575 100644 --- a/src/struphy/kinetic_background/base.py +++ b/src/struphy/kinetic_background/base.py @@ -3,9 +3,10 @@ from abc import ABCMeta, abstractmethod from typing import Callable +import cunumpy as xp + from struphy.fields_background.base import FluidEquilibriumWithB from struphy.initial.base import Perturbation -import cunumpy as xp class KineticBackground(metaclass=ABCMeta): diff --git a/src/struphy/kinetic_background/maxwellians.py b/src/struphy/kinetic_background/maxwellians.py index 3faf2abfa..c7dea067a 100644 --- a/src/struphy/kinetic_background/maxwellians.py +++ b/src/struphy/kinetic_background/maxwellians.py @@ -2,11 +2,12 @@ from typing import Callable +import cunumpy as xp + from struphy.fields_background.base import FluidEquilibriumWithB from struphy.fields_background.equils import set_defaults from struphy.initial.base import Perturbation from struphy.kinetic_background.base import Maxwellian -import cunumpy as xp class Maxwellian3D(Maxwellian): diff --git a/src/struphy/kinetic_background/tests/test_base.py b/src/struphy/kinetic_background/tests/test_base.py index ae16d052a..8a2e89d28 100644 --- a/src/struphy/kinetic_background/tests/test_base.py +++ b/src/struphy/kinetic_background/tests/test_base.py @@ -1,10 +1,10 @@ def test_kinetic_background_magics(show_plot=False): """Test the magic commands __sum__, __mul__ and __sub__ of the Maxwellian base class.""" + import cunumpy as xp import matplotlib.pyplot as plt from struphy.kinetic_background.maxwellians import Maxwellian3D - import cunumpy as xp Nel = [32, 1, 1] e1 = xp.linspace(0.0, 1.0, Nel[0]) diff --git a/src/struphy/kinetic_background/tests/test_maxwellians.py b/src/struphy/kinetic_background/tests/test_maxwellians.py index 9e3523a93..edf24af4c 100644 --- a/src/struphy/kinetic_background/tests/test_maxwellians.py +++ b/src/struphy/kinetic_background/tests/test_maxwellians.py @@ -8,10 +8,10 @@ def test_maxwellian_3d_uniform(Nel, show_plot=False): Asserts that the results over the domain and velocity space correspond to the analytical computation. """ + import cunumpy as xp import matplotlib.pyplot as plt from struphy.kinetic_background.maxwellians import Maxwellian3D - import cunumpy as xp e1 = xp.linspace(0.0, 1.0, Nel[0]) e2 = xp.linspace(0.0, 1.0, Nel[1]) @@ -93,11 +93,11 @@ def test_maxwellian_3d_uniform(Nel, show_plot=False): def test_maxwellian_3d_perturbed(Nel, show_plot=False): """Tests the Maxwellian3D class for perturbations.""" + import cunumpy as xp import matplotlib.pyplot as plt from struphy.initial import perturbations from struphy.kinetic_background.maxwellians import Maxwellian3D - import cunumpy as xp e1 = xp.linspace(0.0, 1.0, Nel[0]) v1 = xp.linspace(-5.0, 5.0, 128) @@ -255,6 +255,7 @@ def test_maxwellian_3d_mhd(Nel, with_desc, show_plot=False): import inspect + import cunumpy as xp import matplotlib.pyplot as plt from struphy.fields_background import equils @@ -263,7 +264,6 @@ def test_maxwellian_3d_mhd(Nel, with_desc, show_plot=False): from struphy.initial import perturbations from struphy.initial.base import Perturbation from struphy.kinetic_background.maxwellians import Maxwellian3D - import cunumpy as xp e1 = xp.linspace(0.0, 1.0, Nel[0]) e2 = xp.linspace(0.0, 1.0, Nel[1]) @@ -666,10 +666,10 @@ def test_maxwellian_2d_uniform(Nel, show_plot=False): Asserts that the results over the domain and velocity space correspond to the analytical computation. """ + import cunumpy as xp import matplotlib.pyplot as plt from struphy.kinetic_background.maxwellians import GyroMaxwellian2D - import cunumpy as xp e1 = xp.linspace(0.0, 1.0, Nel[0]) e2 = xp.linspace(0.0, 1.0, Nel[1]) @@ -759,11 +759,11 @@ def test_maxwellian_2d_uniform(Nel, show_plot=False): def test_maxwellian_2d_perturbed(Nel, show_plot=False): """Tests the GyroMaxwellian2D class for perturbations.""" + import cunumpy as xp import matplotlib.pyplot as plt from struphy.initial import perturbations from struphy.kinetic_background.maxwellians import GyroMaxwellian2D - import cunumpy as xp e1 = xp.linspace(0.0, 1.0, Nel[0]) v1 = xp.linspace(-5.0, 5.0, 128) @@ -1017,6 +1017,7 @@ def test_maxwellian_2d_mhd(Nel, with_desc, show_plot=False): import inspect + import cunumpy as xp import matplotlib.pyplot as plt from struphy.fields_background import equils @@ -1025,7 +1026,6 @@ def test_maxwellian_2d_mhd(Nel, with_desc, show_plot=False): from struphy.initial import perturbations from struphy.initial.base import Perturbation from struphy.kinetic_background.maxwellians import GyroMaxwellian2D - import cunumpy as xp e1 = xp.linspace(0.0, 1.0, Nel[0]) e2 = xp.linspace(0.0, 1.0, Nel[1]) @@ -1417,13 +1417,13 @@ def test_canonical_maxwellian_uniform(Nel, show_plot=False): Asserts that the results over the domain and velocity space correspond to the analytical computation. """ + import cunumpy as xp import matplotlib.pyplot as plt from struphy.fields_background import equils from struphy.geometry import domains from struphy.initial import perturbations from struphy.kinetic_background.maxwellians import CanonicalMaxwellian - import cunumpy as xp e1 = xp.linspace(0.0, 1.0, Nel[0]) e2 = xp.linspace(0.0, 1.0, Nel[1]) diff --git a/src/struphy/linear_algebra/linalg_kron.py b/src/struphy/linear_algebra/linalg_kron.py index 6f354d2cb..2e0dd57dc 100644 --- a/src/struphy/linear_algebra/linalg_kron.py +++ b/src/struphy/linear_algebra/linalg_kron.py @@ -13,11 +13,10 @@ [r_M11, rM12, ... , r_MNO]] """ +import cunumpy as xp from scipy.linalg import solve_circulant from scipy.sparse.linalg import splu -import cunumpy as xp - def kron_matvec_2d(kmat, vec2d): """ diff --git a/src/struphy/linear_algebra/saddle_point.py b/src/struphy/linear_algebra/saddle_point.py index dccfd65bf..47dd36190 100644 --- a/src/struphy/linear_algebra/saddle_point.py +++ b/src/struphy/linear_algebra/saddle_point.py @@ -1,5 +1,6 @@ from typing import Union +import cunumpy as xp import scipy as sc from psydac.linalg.basic import LinearOperator, Vector from psydac.linalg.block import BlockLinearOperator, BlockVector, BlockVectorSpace @@ -7,7 +8,6 @@ from psydac.linalg.solvers import inverse from struphy.linear_algebra.tests.test_saddlepoint_massmatrices import _plot_residual_norms -import cunumpy as xp class SaddlePointSolver: diff --git a/src/struphy/linear_algebra/tests/test_saddlepoint_massmatrices.py b/src/struphy/linear_algebra/tests/test_saddlepoint_massmatrices.py index 04b86de7d..ed5ff4d8a 100644 --- a/src/struphy/linear_algebra/tests/test_saddlepoint_massmatrices.py +++ b/src/struphy/linear_algebra/tests/test_saddlepoint_massmatrices.py @@ -13,6 +13,7 @@ def test_saddlepointsolver(method_for_solving, Nel, p, spl_kind, dirichlet_bc, m import time + import cunumpy as xp import scipy as sc from psydac.ddm.mpi import mpi as MPI from psydac.linalg.basic import IdentityOperator @@ -29,7 +30,6 @@ def test_saddlepointsolver(method_for_solving, Nel, p, spl_kind, dirichlet_bc, m from struphy.geometry import domains from struphy.initial import perturbations from struphy.linear_algebra.saddle_point import SaddlePointSolver - import cunumpy as xp mpi_comm = MPI.COMM_WORLD mpi_rank = mpi_comm.Get_rank() @@ -372,11 +372,10 @@ def _plot_residual_norms(residual_norms): def _plot_velocity(data_reshaped): + import cunumpy as xp import matplotlib import matplotlib.pyplot as plt - import cunumpy as xp - matplotlib.use("Agg") x = xp.linspace(0, 1, 30) diff --git a/src/struphy/linear_algebra/tests/test_stencil_dot_kernels.py b/src/struphy/linear_algebra/tests/test_stencil_dot_kernels.py index 5730e8ccd..d2c2238ff 100644 --- a/src/struphy/linear_algebra/tests/test_stencil_dot_kernels.py +++ b/src/struphy/linear_algebra/tests/test_stencil_dot_kernels.py @@ -13,13 +13,13 @@ def test_1d(Nel, p, spl_kind, domain_ind, codomain_ind): a) the result from kernel in struphy.linear_algebra.stencil_dot_kernels.matvec_1d_kernel b) the result from Stencil .dot with precompiled=True""" + import cunumpy as xp from psydac.api.settings import PSYDAC_BACKEND_GPYCCEL from psydac.ddm.mpi import mpi as MPI from psydac.linalg.stencil import StencilMatrix, StencilVector from struphy.feec.psydac_derham import Derham from struphy.linear_algebra.stencil_dot_kernels import matvec_1d_kernel - import cunumpy as xp # only for M1 Mac users PSYDAC_BACKEND_GPYCCEL["flags"] = "-O3 -march=native -mtune=native -ffast-math -ffree-line-length-none" @@ -134,13 +134,13 @@ def test_3d(Nel, p, spl_kind, domain_ind, codomain_ind): a) the result from kernel in struphy.linear_algebra.stencil_dot_kernels.matvec_1d_kernel b) the result from Stencil .dot with precompiled=True""" + import cunumpy as xp from psydac.api.settings import PSYDAC_BACKEND_GPYCCEL from psydac.ddm.mpi import mpi as MPI from psydac.linalg.stencil import StencilMatrix, StencilVector from struphy.feec.psydac_derham import Derham from struphy.linear_algebra.stencil_dot_kernels import matvec_3d_kernel - import cunumpy as xp # only for M1 Mac users PSYDAC_BACKEND_GPYCCEL["flags"] = "-O3 -march=native -mtune=native -ffast-math -ffree-line-length-none" diff --git a/src/struphy/linear_algebra/tests/test_stencil_transpose_kernels.py b/src/struphy/linear_algebra/tests/test_stencil_transpose_kernels.py index 8cd0ec538..1125a980c 100644 --- a/src/struphy/linear_algebra/tests/test_stencil_transpose_kernels.py +++ b/src/struphy/linear_algebra/tests/test_stencil_transpose_kernels.py @@ -13,13 +13,13 @@ def test_1d(Nel, p, spl_kind, domain_ind, codomain_ind): a) the result from kernel in struphy.linear_algebra.stencil_transpose_kernels.transpose_1d_kernel b) the result from Stencil .transpose with precompiled=True""" + import cunumpy as xp from psydac.api.settings import PSYDAC_BACKEND_GPYCCEL from psydac.ddm.mpi import mpi as MPI from psydac.linalg.stencil import StencilMatrix from struphy.feec.psydac_derham import Derham from struphy.linear_algebra.stencil_transpose_kernels import transpose_1d_kernel - import cunumpy as xp # only for M1 Mac users PSYDAC_BACKEND_GPYCCEL["flags"] = "-O3 -march=native -mtune=native -ffast-math -ffree-line-length-none" @@ -128,13 +128,13 @@ def test_3d(Nel, p, spl_kind, domain_ind, codomain_ind): a) the result from kernel in struphy.linear_algebra.stencil_transpose_kernels.transpose_3d_kernel b) the result from Stencil .transpose with precompiled=True""" + import cunumpy as xp from psydac.api.settings import PSYDAC_BACKEND_GPYCCEL from psydac.ddm.mpi import mpi as MPI from psydac.linalg.stencil import StencilMatrix from struphy.feec.psydac_derham import Derham from struphy.linear_algebra.stencil_transpose_kernels import transpose_3d_kernel - import cunumpy as xp # only for M1 Mac users PSYDAC_BACKEND_GPYCCEL["flags"] = "-O3 -march=native -mtune=native -ffast-math -ffree-line-length-none" diff --git a/src/struphy/main.py b/src/struphy/main.py index e419593ce..524e19eb7 100644 --- a/src/struphy/main.py +++ b/src/struphy/main.py @@ -8,6 +8,7 @@ import time from typing import Optional, TypedDict +import cunumpy as xp import h5py from line_profiler import profile from psydac.ddm.mpi import MockMPI @@ -38,7 +39,6 @@ from struphy.profiling.profiling import ProfileManager from struphy.topology import grids from struphy.topology.grids import TensorProductGrid -import cunumpy as xp from struphy.utils.clone_config import CloneConfig from struphy.utils.utils import dict_to_yaml diff --git a/src/struphy/models/base.py b/src/struphy/models/base.py index 56eaf9f41..d18942154 100644 --- a/src/struphy/models/base.py +++ b/src/struphy/models/base.py @@ -5,6 +5,7 @@ from functools import reduce from textwrap import indent +import cunumpy as xp import yaml from line_profiler import profile from psydac.ddm.mpi import MockMPI @@ -35,7 +36,6 @@ from struphy.profiling.profiling import ProfileManager from struphy.propagators.base import Propagator from struphy.topology.grids import TensorProductGrid -import cunumpy as xp from struphy.utils.clone_config import CloneConfig from struphy.utils.utils import dict_to_yaml, read_state diff --git a/src/struphy/models/fluid.py b/src/struphy/models/fluid.py index d060fbd30..2b832ba00 100644 --- a/src/struphy/models/fluid.py +++ b/src/struphy/models/fluid.py @@ -1,3 +1,4 @@ +import cunumpy as xp from psydac.ddm.mpi import mpi as MPI from psydac.linalg.block import BlockVector from psydac.linalg.stencil import StencilVector @@ -9,7 +10,6 @@ from struphy.models.variables import FEECVariable, PICVariable, SPHVariable, Variable from struphy.polar.basic import PolarVector from struphy.propagators import propagators_coupling, propagators_fields, propagators_markers -import cunumpy as xp rank = MPI.COMM_WORLD.Get_rank() diff --git a/src/struphy/models/hybrid.py b/src/struphy/models/hybrid.py index 3617b8ba5..b7801a050 100644 --- a/src/struphy/models/hybrid.py +++ b/src/struphy/models/hybrid.py @@ -1,3 +1,4 @@ +import cunumpy as xp from psydac.ddm.mpi import mpi as MPI from struphy.models.base import StruphyModel @@ -6,7 +7,6 @@ from struphy.pic.accumulation import accum_kernels, accum_kernels_gc from struphy.polar.basic import PolarVector from struphy.propagators import propagators_coupling, propagators_fields, propagators_markers -import cunumpy as xp from struphy.utils.pyccel import Pyccelkernel rank = MPI.COMM_WORLD.Get_rank() diff --git a/src/struphy/models/kinetic.py b/src/struphy/models/kinetic.py index 36551e60c..9a01e38fd 100644 --- a/src/struphy/models/kinetic.py +++ b/src/struphy/models/kinetic.py @@ -1,3 +1,4 @@ +import cunumpy as xp from psydac.ddm.mpi import mpi as MPI from struphy.feec.projectors import L2Projector @@ -9,7 +10,6 @@ from struphy.pic.accumulation import accum_kernels, accum_kernels_gc from struphy.pic.accumulation.particles_to_grid import AccumulatorVector from struphy.propagators import propagators_coupling, propagators_fields, propagators_markers -import cunumpy as xp from struphy.utils.pyccel import Pyccelkernel rank = MPI.COMM_WORLD.Get_rank() diff --git a/src/struphy/models/species.py b/src/struphy/models/species.py index 6827274e8..56a338ca9 100644 --- a/src/struphy/models/species.py +++ b/src/struphy/models/species.py @@ -1,6 +1,7 @@ import warnings from abc import ABCMeta, abstractmethod +import cunumpy as xp from psydac.ddm.mpi import mpi as MPI from struphy.io.options import Units @@ -13,7 +14,6 @@ LoadingParameters, WeightsParameters, ) -import cunumpy as xp class Species(metaclass=ABCMeta): diff --git a/src/struphy/models/tests/test_verif_EulerSPH.py b/src/struphy/models/tests/test_verif_EulerSPH.py index c11c023a3..79a248ac9 100644 --- a/src/struphy/models/tests/test_verif_EulerSPH.py +++ b/src/struphy/models/tests/test_verif_EulerSPH.py @@ -1,5 +1,6 @@ import os +import cunumpy as xp import pytest from matplotlib import pyplot as plt from matplotlib.ticker import FormatStrFormatter @@ -19,7 +20,6 @@ WeightsParameters, ) from struphy.topology import grids -import cunumpy as xp test_folder = os.path.join(os.getcwd(), "struphy_verification_tests") diff --git a/src/struphy/models/tests/test_verif_LinearMHD.py b/src/struphy/models/tests/test_verif_LinearMHD.py index e29186b8c..5cbbbc9fd 100644 --- a/src/struphy/models/tests/test_verif_LinearMHD.py +++ b/src/struphy/models/tests/test_verif_LinearMHD.py @@ -1,5 +1,6 @@ import os +import cunumpy as xp import pytest from psydac.ddm.mpi import mpi as MPI @@ -11,7 +12,6 @@ from struphy.io.options import BaseUnits, DerhamOptions, EnvironmentOptions, FieldsBackground, Time from struphy.kinetic_background import maxwellians from struphy.topology import grids -import cunumpy as xp test_folder = os.path.join(os.getcwd(), "verification_tests") diff --git a/src/struphy/models/tests/test_verif_Maxwell.py b/src/struphy/models/tests/test_verif_Maxwell.py index a39545a51..e97675e7b 100644 --- a/src/struphy/models/tests/test_verif_Maxwell.py +++ b/src/struphy/models/tests/test_verif_Maxwell.py @@ -1,5 +1,6 @@ import os +import cunumpy as xp import pytest from matplotlib import pyplot as plt from psydac.ddm.mpi import mpi as MPI @@ -14,7 +15,6 @@ from struphy.kinetic_background import maxwellians from struphy.models.toy import Maxwell from struphy.topology import grids -import cunumpy as xp test_folder = os.path.join(os.getcwd(), "struphy_verification_tests") diff --git a/src/struphy/models/tests/test_verif_Poisson.py b/src/struphy/models/tests/test_verif_Poisson.py index adb8300b8..5b62d61ab 100644 --- a/src/struphy/models/tests/test_verif_Poisson.py +++ b/src/struphy/models/tests/test_verif_Poisson.py @@ -1,5 +1,6 @@ import os +import cunumpy as xp from matplotlib import pyplot as plt from psydac.ddm.mpi import mpi as MPI @@ -18,7 +19,6 @@ WeightsParameters, ) from struphy.topology import grids -import cunumpy as xp test_folder = os.path.join(os.getcwd(), "struphy_verification_tests") diff --git a/src/struphy/models/tests/test_verif_VlasovAmpereOneSpecies.py b/src/struphy/models/tests/test_verif_VlasovAmpereOneSpecies.py index d75213038..a8c0b8b13 100644 --- a/src/struphy/models/tests/test_verif_VlasovAmpereOneSpecies.py +++ b/src/struphy/models/tests/test_verif_VlasovAmpereOneSpecies.py @@ -1,5 +1,6 @@ import os +import cunumpy as xp import h5py from matplotlib import pyplot as plt from matplotlib.ticker import FormatStrFormatter @@ -19,7 +20,6 @@ WeightsParameters, ) from struphy.topology import grids -import cunumpy as xp test_folder = os.path.join(os.getcwd(), "struphy_verification_tests") diff --git a/src/struphy/models/tests/verification.py b/src/struphy/models/tests/verification.py index b128e2c3a..75b0a1047 100644 --- a/src/struphy/models/tests/verification.py +++ b/src/struphy/models/tests/verification.py @@ -2,6 +2,7 @@ import pickle from pathlib import Path +import cunumpy as xp import h5py import yaml from matplotlib import pyplot as plt @@ -11,7 +12,6 @@ import struphy from struphy.post_processing import pproc_struphy -import cunumpy as xp def VlasovAmpereOneSpecies_weakLandau( diff --git a/src/struphy/models/toy.py b/src/struphy/models/toy.py index 788370784..bad2b7916 100644 --- a/src/struphy/models/toy.py +++ b/src/struphy/models/toy.py @@ -1,3 +1,4 @@ +import cunumpy as xp from psydac.ddm.mpi import mpi as MPI from struphy.feec.projectors import L2Projector @@ -6,7 +7,6 @@ from struphy.models.species import FieldSpecies, FluidSpecies, ParticleSpecies from struphy.models.variables import FEECVariable, PICVariable, SPHVariable, Variable from struphy.propagators import propagators_coupling, propagators_fields, propagators_markers -import cunumpy as xp rank = MPI.COMM_WORLD.Get_rank() diff --git a/src/struphy/models/variables.py b/src/struphy/models/variables.py index 2bfd03d30..d71f4644d 100644 --- a/src/struphy/models/variables.py +++ b/src/struphy/models/variables.py @@ -4,6 +4,7 @@ from abc import ABCMeta, abstractmethod from typing import TYPE_CHECKING +import cunumpy as xp from psydac.ddm.mpi import mpi as MPI from struphy.feec.psydac_derham import Derham, SplineFunction @@ -21,7 +22,6 @@ from struphy.pic import particles from struphy.pic.base import Particles from struphy.pic.particles import ParticlesSPH -import cunumpy as xp from struphy.utils.clone_config import CloneConfig if TYPE_CHECKING: diff --git a/src/struphy/ode/solvers.py b/src/struphy/ode/solvers.py index 009085495..c6d6366b9 100644 --- a/src/struphy/ode/solvers.py +++ b/src/struphy/ode/solvers.py @@ -1,10 +1,10 @@ from inspect import signature +import cunumpy as xp from psydac.linalg.block import BlockVector from psydac.linalg.stencil import StencilVector from struphy.ode.utils import ButcherTableau -import cunumpy as xp class ODEsolverFEEC: diff --git a/src/struphy/ode/tests/test_ode_feec.py b/src/struphy/ode/tests/test_ode_feec.py index 7a7894c2d..dadd3aad3 100644 --- a/src/struphy/ode/tests/test_ode_feec.py +++ b/src/struphy/ode/tests/test_ode_feec.py @@ -20,6 +20,7 @@ def test_exp_growth(spaces, algo, show_plots=False): """Solve dy/dt = omega*y for different feec variables y and with all available solvers from the ButcherTableau.""" + import cunumpy as xp from matplotlib import pyplot as plt from psydac.ddm.mpi import mpi as MPI from psydac.linalg.block import BlockVector @@ -28,7 +29,6 @@ def test_exp_growth(spaces, algo, show_plots=False): from struphy.feec.psydac_derham import Derham from struphy.ode.solvers import ODEsolverFEEC from struphy.ode.utils import ButcherTableau - import cunumpy as xp comm = MPI.COMM_WORLD rank = comm.Get_rank() diff --git a/src/struphy/pic/accumulation/particles_to_grid.py b/src/struphy/pic/accumulation/particles_to_grid.py index 145eb8b5a..06d67a6df 100644 --- a/src/struphy/pic/accumulation/particles_to_grid.py +++ b/src/struphy/pic/accumulation/particles_to_grid.py @@ -1,5 +1,6 @@ "Base classes for particle deposition (accumulation) on the grid." +import cunumpy as xp from psydac.ddm.mpi import mpi as MPI from psydac.linalg.block import BlockVector from psydac.linalg.stencil import StencilMatrix, StencilVector @@ -12,7 +13,6 @@ from struphy.pic.accumulation.filter import AccumFilter, FilterParameters from struphy.pic.base import Particles from struphy.profiling.profiling import ProfileManager -import cunumpy as xp from struphy.utils.pyccel import Pyccelkernel diff --git a/src/struphy/pic/base.py b/src/struphy/pic/base.py index 1589063c6..0f92323ae 100644 --- a/src/struphy/pic/base.py +++ b/src/struphy/pic/base.py @@ -14,6 +14,7 @@ class Intracomm: x = None +import cunumpy as xp from line_profiler import profile from psydac.ddm.mpi import MockComm from psydac.ddm.mpi import mpi as MPI @@ -53,7 +54,6 @@ class Intracomm: WeightsParameters, ) from struphy.utils import utils -import cunumpy as xp from struphy.utils.clone_config import CloneConfig from struphy.utils.pyccel import Pyccelkernel diff --git a/src/struphy/pic/particles.py b/src/struphy/pic/particles.py index a7bca1be7..7258b3cd5 100644 --- a/src/struphy/pic/particles.py +++ b/src/struphy/pic/particles.py @@ -1,5 +1,7 @@ import copy +import cunumpy as xp + from struphy.fields_background import equils from struphy.fields_background.base import FluidEquilibrium, FluidEquilibriumWithB from struphy.fields_background.projected_equils import ProjectedFluidEquilibriumWithB @@ -10,7 +12,6 @@ from struphy.kinetic_background.base import Maxwellian, SumKineticBackground from struphy.pic import utilities_kernels from struphy.pic.base import Particles -import cunumpy as xp class Particles6D(Particles): diff --git a/src/struphy/pic/pushing/pusher.py b/src/struphy/pic/pushing/pusher.py index a668095ca..190525de9 100644 --- a/src/struphy/pic/pushing/pusher.py +++ b/src/struphy/pic/pushing/pusher.py @@ -1,12 +1,12 @@ "Accelerated particle pushing." +import cunumpy as xp from line_profiler import profile from psydac.ddm.mpi import mpi as MPI from struphy.kernel_arguments.pusher_args_kernels import DerhamArguments, DomainArguments from struphy.pic.base import Particles from struphy.profiling.profiling import ProfileManager -import cunumpy as xp from struphy.utils.pyccel import Pyccelkernel diff --git a/src/struphy/pic/sobol_seq.py b/src/struphy/pic/sobol_seq.py index 97a9e582c..ce965cc8f 100644 --- a/src/struphy/pic/sobol_seq.py +++ b/src/struphy/pic/sobol_seq.py @@ -17,9 +17,8 @@ from __future__ import division -from scipy.stats import norm - import cunumpy as xp +from scipy.stats import norm __all__ = ["i4_bit_hi1", "i4_bit_lo0", "i4_sobol_generate", "i4_sobol", "i4_uniform", "prime_ge", "is_prime"] diff --git a/src/struphy/pic/tests/test_accum_vec_H1.py b/src/struphy/pic/tests/test_accum_vec_H1.py index 3f852cb2f..7ed52b153 100644 --- a/src/struphy/pic/tests/test_accum_vec_H1.py +++ b/src/struphy/pic/tests/test_accum_vec_H1.py @@ -47,6 +47,7 @@ def test_accum_poisson(Nel, p, spl_kind, mapping, num_clones, Np=1000): import copy + import cunumpy as xp from psydac.ddm.mpi import MockComm from psydac.ddm.mpi import mpi as MPI @@ -57,7 +58,6 @@ def test_accum_poisson(Nel, p, spl_kind, mapping, num_clones, Np=1000): from struphy.pic.accumulation.particles_to_grid import AccumulatorVector from struphy.pic.particles import Particles6D from struphy.pic.utilities import BoundaryParameters, LoadingParameters, WeightsParameters - import cunumpy as xp from struphy.utils.clone_config import CloneConfig if isinstance(MPI.COMM_WORLD, MockComm): diff --git a/src/struphy/pic/tests/test_accumulation.py b/src/struphy/pic/tests/test_accumulation.py index d753e5466..012c73e33 100644 --- a/src/struphy/pic/tests/test_accumulation.py +++ b/src/struphy/pic/tests/test_accumulation.py @@ -48,6 +48,7 @@ def test_accumulation(Nel, p, spl_kind, mapping, Np=40, verbose=False): def pc_lin_mhd_6d_step_ph_full(Nel, p, spl_kind, mapping, Np, verbose=False): from time import time + import cunumpy as xp from psydac.ddm.mpi import MockComm from psydac.ddm.mpi import mpi as MPI @@ -61,7 +62,6 @@ def pc_lin_mhd_6d_step_ph_full(Nel, p, spl_kind, mapping, Np, verbose=False): from struphy.pic.particles import Particles6D from struphy.pic.tests.test_pic_legacy_files.accumulation_kernels_3d import kernel_step_ph_full from struphy.pic.utilities import BoundaryParameters, LoadingParameters, WeightsParameters - import cunumpy as xp if isinstance(MPI.COMM_WORLD, MockComm): mpi_comm = None diff --git a/src/struphy/pic/tests/test_binning.py b/src/struphy/pic/tests/test_binning.py index 053a7e728..a6a1dde6e 100644 --- a/src/struphy/pic/tests/test_binning.py +++ b/src/struphy/pic/tests/test_binning.py @@ -35,6 +35,7 @@ def test_binning_6D_full_f(mapping, show_plot=False): name and specification of the mapping """ + import cunumpy as xp import matplotlib.pyplot as plt from psydac.ddm.mpi import mpi as MPI @@ -47,7 +48,6 @@ def test_binning_6D_full_f(mapping, show_plot=False): LoadingParameters, WeightsParameters, ) - import cunumpy as xp # Set seed seed = 1234 @@ -268,6 +268,7 @@ def test_binning_6D_delta_f(mapping, show_plot=False): name and specification of the mapping """ + import cunumpy as xp import matplotlib.pyplot as plt from psydac.ddm.mpi import mpi as MPI @@ -280,7 +281,6 @@ def test_binning_6D_delta_f(mapping, show_plot=False): LoadingParameters, WeightsParameters, ) - import cunumpy as xp # Set seed seed = 1234 @@ -464,6 +464,7 @@ def test_binning_6D_full_f_mpi(mapping, show_plot=False): name and specification of the mapping """ + import cunumpy as xp import matplotlib.pyplot as plt from psydac.ddm.mpi import MockComm from psydac.ddm.mpi import mpi as MPI @@ -477,7 +478,6 @@ def test_binning_6D_full_f_mpi(mapping, show_plot=False): LoadingParameters, WeightsParameters, ) - import cunumpy as xp # Set seed seed = 1234 @@ -761,6 +761,7 @@ def test_binning_6D_delta_f_mpi(mapping, show_plot=False): name and specification of the mapping """ + import cunumpy as xp import matplotlib.pyplot as plt from psydac.ddm.mpi import MockComm from psydac.ddm.mpi import mpi as MPI @@ -774,7 +775,6 @@ def test_binning_6D_delta_f_mpi(mapping, show_plot=False): LoadingParameters, WeightsParameters, ) - import cunumpy as xp # Set seed seed = 1234 diff --git a/src/struphy/pic/tests/test_draw_parallel.py b/src/struphy/pic/tests/test_draw_parallel.py index 6b9f16976..cf95f4dc7 100644 --- a/src/struphy/pic/tests/test_draw_parallel.py +++ b/src/struphy/pic/tests/test_draw_parallel.py @@ -35,13 +35,13 @@ def test_draw(Nel, p, spl_kind, mapping, ppc=10): """Asserts whether all particles are on the correct process after `particles.mpi_sort_markers()`.""" + import cunumpy as xp from psydac.ddm.mpi import mpi as MPI from struphy.feec.psydac_derham import Derham from struphy.geometry import domains from struphy.pic.particles import Particles6D from struphy.pic.utilities import BoundaryParameters, LoadingParameters, WeightsParameters - import cunumpy as xp comm = MPI.COMM_WORLD rank = comm.Get_rank() diff --git a/src/struphy/pic/tests/test_mat_vec_filler.py b/src/struphy/pic/tests/test_mat_vec_filler.py index 67c770ead..491e1f20e 100644 --- a/src/struphy/pic/tests/test_mat_vec_filler.py +++ b/src/struphy/pic/tests/test_mat_vec_filler.py @@ -1,6 +1,5 @@ -import pytest - import cunumpy as xp +import pytest @pytest.mark.parametrize("Nel", [[8, 9, 10]]) diff --git a/src/struphy/pic/tests/test_pic_legacy_files/accumulation.py b/src/struphy/pic/tests/test_pic_legacy_files/accumulation.py index 4230f2854..2ee5ba7b2 100644 --- a/src/struphy/pic/tests/test_pic_legacy_files/accumulation.py +++ b/src/struphy/pic/tests/test_pic_legacy_files/accumulation.py @@ -8,11 +8,11 @@ import time +import cunumpy as xp import scipy.sparse as spa from psydac.ddm.mpi import mpi as MPI import struphy.pic.tests.test_pic_legacy_files.accumulation_kernels_3d as pic_ker_3d -import cunumpy as xp # import struphy.pic.tests.test_pic_legacy_files.accumulation_kernels_2d as pic_ker_2d diff --git a/src/struphy/pic/tests/test_pic_legacy_files/pusher.py b/src/struphy/pic/tests/test_pic_legacy_files/pusher.py index 6923fed28..518e19ee0 100644 --- a/src/struphy/pic/tests/test_pic_legacy_files/pusher.py +++ b/src/struphy/pic/tests/test_pic_legacy_files/pusher.py @@ -1,7 +1,8 @@ +import cunumpy as xp + import struphy.pic.tests.test_pic_legacy_files.pusher_pos as push_pos import struphy.pic.tests.test_pic_legacy_files.pusher_vel_2d as push_vel_2d import struphy.pic.tests.test_pic_legacy_files.pusher_vel_3d as push_vel_3d -import cunumpy as xp class Pusher: diff --git a/src/struphy/pic/tests/test_pushers.py b/src/struphy/pic/tests/test_pushers.py index c71cfac2f..d64076cd1 100644 --- a/src/struphy/pic/tests/test_pushers.py +++ b/src/struphy/pic/tests/test_pushers.py @@ -23,6 +23,7 @@ ], ) def test_push_vxb_analytic(Nel, p, spl_kind, mapping, show_plots=False): + import cunumpy as xp from psydac.ddm.mpi import mpi as MPI from struphy.eigenvalue_solvers.spline_space import Spline_space_1d, Tensor_spline_space @@ -34,7 +35,6 @@ def test_push_vxb_analytic(Nel, p, spl_kind, mapping, show_plots=False): from struphy.pic.pushing.pusher import Pusher as Pusher_psy from struphy.pic.tests.test_pic_legacy_files.pusher import Pusher as Pusher_str from struphy.pic.utilities import BoundaryParameters, LoadingParameters, WeightsParameters - import cunumpy as xp comm = MPI.COMM_WORLD rank = comm.Get_rank() @@ -158,6 +158,7 @@ def test_push_vxb_analytic(Nel, p, spl_kind, mapping, show_plots=False): ], ) def test_push_bxu_Hdiv(Nel, p, spl_kind, mapping, show_plots=False): + import cunumpy as xp from psydac.ddm.mpi import mpi as MPI from struphy.eigenvalue_solvers.spline_space import Spline_space_1d, Tensor_spline_space @@ -169,7 +170,6 @@ def test_push_bxu_Hdiv(Nel, p, spl_kind, mapping, show_plots=False): from struphy.pic.pushing.pusher import Pusher as Pusher_psy from struphy.pic.tests.test_pic_legacy_files.pusher import Pusher as Pusher_str from struphy.pic.utilities import BoundaryParameters, LoadingParameters, WeightsParameters - import cunumpy as xp comm = MPI.COMM_WORLD rank = comm.Get_rank() @@ -304,6 +304,7 @@ def test_push_bxu_Hdiv(Nel, p, spl_kind, mapping, show_plots=False): ], ) def test_push_bxu_Hcurl(Nel, p, spl_kind, mapping, show_plots=False): + import cunumpy as xp from psydac.ddm.mpi import mpi as MPI from struphy.eigenvalue_solvers.spline_space import Spline_space_1d, Tensor_spline_space @@ -315,7 +316,6 @@ def test_push_bxu_Hcurl(Nel, p, spl_kind, mapping, show_plots=False): from struphy.pic.pushing.pusher import Pusher as Pusher_psy from struphy.pic.tests.test_pic_legacy_files.pusher import Pusher as Pusher_str from struphy.pic.utilities import BoundaryParameters, LoadingParameters, WeightsParameters - import cunumpy as xp comm = MPI.COMM_WORLD rank = comm.Get_rank() @@ -450,6 +450,7 @@ def test_push_bxu_Hcurl(Nel, p, spl_kind, mapping, show_plots=False): ], ) def test_push_bxu_H1vec(Nel, p, spl_kind, mapping, show_plots=False): + import cunumpy as xp from psydac.ddm.mpi import mpi as MPI from struphy.eigenvalue_solvers.spline_space import Spline_space_1d, Tensor_spline_space @@ -461,7 +462,6 @@ def test_push_bxu_H1vec(Nel, p, spl_kind, mapping, show_plots=False): from struphy.pic.pushing.pusher import Pusher as Pusher_psy from struphy.pic.tests.test_pic_legacy_files.pusher import Pusher as Pusher_str from struphy.pic.utilities import BoundaryParameters, LoadingParameters, WeightsParameters - import cunumpy as xp comm = MPI.COMM_WORLD rank = comm.Get_rank() @@ -596,6 +596,7 @@ def test_push_bxu_H1vec(Nel, p, spl_kind, mapping, show_plots=False): ], ) def test_push_bxu_Hdiv_pauli(Nel, p, spl_kind, mapping, show_plots=False): + import cunumpy as xp from psydac.ddm.mpi import mpi as MPI from struphy.eigenvalue_solvers.spline_space import Spline_space_1d, Tensor_spline_space @@ -607,7 +608,6 @@ def test_push_bxu_Hdiv_pauli(Nel, p, spl_kind, mapping, show_plots=False): from struphy.pic.pushing.pusher import Pusher as Pusher_psy from struphy.pic.tests.test_pic_legacy_files.pusher import Pusher as Pusher_str from struphy.pic.utilities import BoundaryParameters, LoadingParameters, WeightsParameters - import cunumpy as xp comm = MPI.COMM_WORLD rank = comm.Get_rank() @@ -744,6 +744,7 @@ def test_push_bxu_Hdiv_pauli(Nel, p, spl_kind, mapping, show_plots=False): ], ) def test_push_eta_rk4(Nel, p, spl_kind, mapping, show_plots=False): + import cunumpy as xp from psydac.ddm.mpi import mpi as MPI from struphy.eigenvalue_solvers.spline_space import Spline_space_1d, Tensor_spline_space @@ -756,7 +757,6 @@ def test_push_eta_rk4(Nel, p, spl_kind, mapping, show_plots=False): from struphy.pic.pushing.pusher import Pusher as Pusher_psy from struphy.pic.tests.test_pic_legacy_files.pusher import Pusher as Pusher_str from struphy.pic.utilities import BoundaryParameters, LoadingParameters, WeightsParameters - import cunumpy as xp comm = MPI.COMM_WORLD rank = comm.Get_rank() diff --git a/src/struphy/pic/tests/test_sorting.py b/src/struphy/pic/tests/test_sorting.py index eb0d72751..337dfaede 100644 --- a/src/struphy/pic/tests/test_sorting.py +++ b/src/struphy/pic/tests/test_sorting.py @@ -1,5 +1,6 @@ from time import time +import cunumpy as xp import pytest from psydac.ddm.mpi import mpi as MPI @@ -7,7 +8,6 @@ from struphy.geometry import domains from struphy.pic.particles import Particles6D from struphy.pic.utilities import BoundaryParameters, LoadingParameters, WeightsParameters -import cunumpy as xp @pytest.mark.parametrize("nx", [8, 70]) diff --git a/src/struphy/pic/tests/test_sph.py b/src/struphy/pic/tests/test_sph.py index f2b075373..64b7b0cc3 100644 --- a/src/struphy/pic/tests/test_sph.py +++ b/src/struphy/pic/tests/test_sph.py @@ -1,3 +1,4 @@ +import cunumpy as xp import pytest from matplotlib import pyplot as plt from psydac.ddm.mpi import MockComm @@ -8,7 +9,6 @@ from struphy.initial import perturbations from struphy.pic.particles import ParticlesSPH from struphy.pic.utilities import BoundaryParameters, LoadingParameters, WeightsParameters -import cunumpy as xp @pytest.mark.parametrize("boxes_per_dim", [(24, 1, 1)]) diff --git a/src/struphy/pic/tests/test_tesselation.py b/src/struphy/pic/tests/test_tesselation.py index 9e300820c..cf6ed922e 100644 --- a/src/struphy/pic/tests/test_tesselation.py +++ b/src/struphy/pic/tests/test_tesselation.py @@ -1,5 +1,6 @@ from time import time +import cunumpy as xp import pytest from matplotlib import pyplot as plt from psydac.ddm.mpi import mpi as MPI @@ -10,7 +11,6 @@ from struphy.initial import perturbations from struphy.pic.particles import ParticlesSPH from struphy.pic.utilities import BoundaryParameters, LoadingParameters, WeightsParameters -import cunumpy as xp @pytest.mark.parametrize("ppb", [8, 12]) diff --git a/src/struphy/pic/utilities.py b/src/struphy/pic/utilities.py index 521060a66..3ae645557 100644 --- a/src/struphy/pic/utilities.py +++ b/src/struphy/pic/utilities.py @@ -1,3 +1,5 @@ +import cunumpy as xp + import struphy.pic.utilities_kernels as utils from struphy.io.options import ( OptsLoading, @@ -5,7 +7,6 @@ OptsRecontructBC, OptsSpatialLoading, ) -import cunumpy as xp class LoadingParameters: diff --git a/src/struphy/polar/basic.py b/src/struphy/polar/basic.py index ecf8aca5f..6a1c2c2f2 100644 --- a/src/struphy/polar/basic.py +++ b/src/struphy/polar/basic.py @@ -1,10 +1,9 @@ +import cunumpy as xp from psydac.ddm.mpi import mpi as MPI from psydac.linalg.basic import Vector, VectorSpace from psydac.linalg.block import BlockVector from psydac.linalg.stencil import StencilVector -import cunumpy as xp - class PolarDerhamSpace(VectorSpace): """ diff --git a/src/struphy/polar/linear_operators.py b/src/struphy/polar/linear_operators.py index 9a63202de..03a3e504a 100644 --- a/src/struphy/polar/linear_operators.py +++ b/src/struphy/polar/linear_operators.py @@ -1,3 +1,4 @@ +import cunumpy as xp from psydac.ddm.mpi import mpi as MPI from psydac.linalg.block import BlockVector, BlockVectorSpace from psydac.linalg.stencil import StencilVector, StencilVectorSpace @@ -6,7 +7,6 @@ from struphy.feec.linear_operators import LinOpWithTransp from struphy.linear_algebra.linalg_kron import kron_matvec_2d from struphy.polar.basic import PolarDerhamSpace, PolarVector -import cunumpy as xp class PolarExtractionOperator(LinOpWithTransp): diff --git a/src/struphy/polar/tests/test_legacy_polar_splines.py b/src/struphy/polar/tests/test_legacy_polar_splines.py index a87c36a15..be2bfb654 100644 --- a/src/struphy/polar/tests/test_legacy_polar_splines.py +++ b/src/struphy/polar/tests/test_legacy_polar_splines.py @@ -7,12 +7,12 @@ def test_polar_splines_2D(plot=False): sys.path.append("..") + import cunumpy as xp import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D from struphy.eigenvalue_solvers.spline_space import Spline_space_1d, Tensor_spline_space from struphy.geometry import domains - import cunumpy as xp # parameters # number of elements (number of elements in angular direction must be a multiple of 3) diff --git a/src/struphy/polar/tests/test_polar.py b/src/struphy/polar/tests/test_polar.py index bd371e1d0..ac0113c4f 100644 --- a/src/struphy/polar/tests/test_polar.py +++ b/src/struphy/polar/tests/test_polar.py @@ -167,6 +167,7 @@ def test_spaces(Nel, p, spl_kind): @pytest.mark.parametrize("p", [[3, 2, 2]]) @pytest.mark.parametrize("spl_kind", [[False, True, True], [False, True, False]]) def test_extraction_ops_and_derivatives(Nel, p, spl_kind): + import cunumpy as xp from psydac.ddm.mpi import mpi as MPI from struphy.eigenvalue_solvers.spline_space import Spline_space_1d, Tensor_spline_space @@ -176,7 +177,6 @@ def test_extraction_ops_and_derivatives(Nel, p, spl_kind): from struphy.polar.basic import PolarDerhamSpace, PolarVector from struphy.polar.extraction_operators import PolarExtractionBlocksC1 from struphy.polar.linear_operators import PolarExtractionOperator, PolarLinearOperator - import cunumpy as xp comm = MPI.COMM_WORLD rank = comm.Get_rank() @@ -302,12 +302,12 @@ def test_extraction_ops_and_derivatives(Nel, p, spl_kind): @pytest.mark.parametrize("p", [[4, 3, 2]]) @pytest.mark.parametrize("spl_kind", [[False, True, True], [False, True, False]]) def test_projectors(Nel, p, spl_kind): + import cunumpy as xp from psydac.ddm.mpi import mpi as MPI from struphy.eigenvalue_solvers.spline_space import Spline_space_1d, Tensor_spline_space from struphy.feec.psydac_derham import Derham from struphy.geometry.domains import IGAPolarCylinder - import cunumpy as xp comm = MPI.COMM_WORLD rank = comm.Get_rank() diff --git a/src/struphy/post_processing/likwid/plot_likwidproject.py b/src/struphy/post_processing/likwid/plot_likwidproject.py index 63584e32c..feda5d3b6 100644 --- a/src/struphy/post_processing/likwid/plot_likwidproject.py +++ b/src/struphy/post_processing/likwid/plot_likwidproject.py @@ -7,6 +7,7 @@ import re import sys +import cunumpy as xp import matplotlib.pyplot as plt import pandas as pd import plotly.express as px @@ -16,7 +17,6 @@ import struphy.post_processing.likwid.likwid_parser as lp import struphy.post_processing.likwid.maxplotlylib as mply import struphy.post_processing.likwid.roofline_plotter as rp -import cunumpy as xp def clean_string(string_in): diff --git a/src/struphy/post_processing/likwid/plot_time_traces.py b/src/struphy/post_processing/likwid/plot_time_traces.py index 9a3f18622..ed0a34010 100644 --- a/src/struphy/post_processing/likwid/plot_time_traces.py +++ b/src/struphy/post_processing/likwid/plot_time_traces.py @@ -2,12 +2,12 @@ import pickle import re +import cunumpy as xp import matplotlib.pyplot as plt import plotly.io as pio # pio.kaleido.scope.mathjax = None import struphy.post_processing.likwid.maxplotlylib as mply -import cunumpy as xp def glob_to_regex(pat: str) -> str: diff --git a/src/struphy/post_processing/likwid/roofline_plotter.py b/src/struphy/post_processing/likwid/roofline_plotter.py index d8fa27fe5..3a4808bdc 100644 --- a/src/struphy/post_processing/likwid/roofline_plotter.py +++ b/src/struphy/post_processing/likwid/roofline_plotter.py @@ -1,11 +1,10 @@ import glob import pickle +import cunumpy as xp import pandas as pd import yaml -import cunumpy as xp - def sort_by_num_threads(bm): sorted_arrays = {} diff --git a/src/struphy/post_processing/orbits/orbits_tools.py b/src/struphy/post_processing/orbits/orbits_tools.py index afe896757..97eee89af 100644 --- a/src/struphy/post_processing/orbits/orbits_tools.py +++ b/src/struphy/post_processing/orbits/orbits_tools.py @@ -1,12 +1,12 @@ import os import shutil +import cunumpy as xp import h5py import yaml from tqdm import tqdm from struphy.post_processing.orbits.orbits_kernels import calculate_guiding_center_from_6d -import cunumpy as xp def post_process_orbit_guiding_center(path_in, path_kinetics_species, species): diff --git a/src/struphy/post_processing/post_processing_tools.py b/src/struphy/post_processing/post_processing_tools.py index 403d2a6ac..74a6288f6 100644 --- a/src/struphy/post_processing/post_processing_tools.py +++ b/src/struphy/post_processing/post_processing_tools.py @@ -2,6 +2,7 @@ import pickle import shutil +import cunumpy as xp import h5py import yaml from tqdm import tqdm @@ -19,7 +20,6 @@ from struphy.models.species import ParticleSpecies from struphy.models.variables import PICVariable from struphy.topology.grids import TensorProductGrid -import cunumpy as xp class ParamsIn: diff --git a/src/struphy/post_processing/pproc_struphy.py b/src/struphy/post_processing/pproc_struphy.py index eb3488b96..044ec0de8 100644 --- a/src/struphy/post_processing/pproc_struphy.py +++ b/src/struphy/post_processing/pproc_struphy.py @@ -2,13 +2,13 @@ import pickle import shutil +import cunumpy as xp import h5py import yaml import struphy.post_processing.orbits.orbits_tools as orbits_pproc import struphy.post_processing.post_processing_tools as pproc from struphy.io.setup import import_parameters_py -import cunumpy as xp def main( diff --git a/src/struphy/post_processing/profile_struphy.py b/src/struphy/post_processing/profile_struphy.py index 0aeb9c570..da4632555 100644 --- a/src/struphy/post_processing/profile_struphy.py +++ b/src/struphy/post_processing/profile_struphy.py @@ -1,11 +1,11 @@ import pickle import sys +import cunumpy as xp import yaml from matplotlib import pyplot as plt from struphy.post_processing.cprofile_analyser import get_cprofile_data, replace_keys -import cunumpy as xp def main(): diff --git a/src/struphy/profiling/profiling.py b/src/struphy/profiling/profiling.py index 43c9fcddb..e96749614 100644 --- a/src/struphy/profiling/profiling.py +++ b/src/struphy/profiling/profiling.py @@ -17,9 +17,8 @@ # Import the profiling configuration class and context manager from functools import lru_cache -from psydac.ddm.mpi import mpi as MPI - import cunumpy as xp +from psydac.ddm.mpi import mpi as MPI @lru_cache(maxsize=None) # Cache the import result to avoid repeated imports diff --git a/src/struphy/propagators/base.py b/src/struphy/propagators/base.py index 1b83168a8..f69d4c7fe 100644 --- a/src/struphy/propagators/base.py +++ b/src/struphy/propagators/base.py @@ -4,6 +4,7 @@ from dataclasses import dataclass from typing import Literal +import cunumpy as xp from psydac.linalg.block import BlockVector from psydac.linalg.stencil import StencilVector @@ -14,7 +15,6 @@ from struphy.geometry.base import Domain from struphy.io.options import check_option from struphy.models.variables import FEECVariable, PICVariable, SPHVariable, Variable -import cunumpy as xp class Propagator(metaclass=ABCMeta): diff --git a/src/struphy/propagators/propagators_coupling.py b/src/struphy/propagators/propagators_coupling.py index fce1e5f66..9d6e2fd4e 100644 --- a/src/struphy/propagators/propagators_coupling.py +++ b/src/struphy/propagators/propagators_coupling.py @@ -3,6 +3,7 @@ from dataclasses import dataclass from typing import Literal +import cunumpy as xp from line_profiler import profile from psydac.ddm.mpi import mpi as MPI from psydac.linalg.block import BlockVector @@ -28,7 +29,6 @@ from struphy.pic.pushing.pusher import Pusher from struphy.polar.basic import PolarVector from struphy.propagators.base import Propagator -import cunumpy as xp from struphy.utils.pyccel import Pyccelkernel diff --git a/src/struphy/propagators/propagators_fields.py b/src/struphy/propagators/propagators_fields.py index 7ec9709f4..750917a95 100644 --- a/src/struphy/propagators/propagators_fields.py +++ b/src/struphy/propagators/propagators_fields.py @@ -5,6 +5,7 @@ from dataclasses import dataclass from typing import Callable, Literal, get_args +import cunumpy as xp import scipy as sc from line_profiler import profile from matplotlib import pyplot as plt @@ -67,7 +68,6 @@ from struphy.pic.particles import Particles5D, Particles6D from struphy.polar.basic import PolarVector from struphy.propagators.base import Propagator -import cunumpy as xp from struphy.utils.pyccel import Pyccelkernel diff --git a/src/struphy/propagators/propagators_markers.py b/src/struphy/propagators/propagators_markers.py index ea1776fc2..69aa86159 100644 --- a/src/struphy/propagators/propagators_markers.py +++ b/src/struphy/propagators/propagators_markers.py @@ -4,6 +4,7 @@ from dataclasses import dataclass from typing import Callable, Literal, get_args +import cunumpy as xp from line_profiler import profile from numpy import array, polynomial, random from psydac.ddm.mpi import mpi as MPI @@ -30,7 +31,6 @@ from struphy.pic.pushing.pusher import Pusher from struphy.polar.basic import PolarVector from struphy.propagators.base import Propagator -import cunumpy as xp from struphy.utils.pyccel import Pyccelkernel diff --git a/src/struphy/propagators/tests/test_gyrokinetic_poisson.py b/src/struphy/propagators/tests/test_gyrokinetic_poisson.py index d519cc3da..ce29c8141 100644 --- a/src/struphy/propagators/tests/test_gyrokinetic_poisson.py +++ b/src/struphy/propagators/tests/test_gyrokinetic_poisson.py @@ -1,3 +1,4 @@ +import cunumpy as xp import matplotlib.pyplot as plt import pytest from psydac.ddm.mpi import mpi as MPI @@ -11,7 +12,6 @@ from struphy.models.variables import FEECVariable from struphy.propagators.base import Propagator from struphy.propagators.propagators_fields import ImplicitDiffusion -import cunumpy as xp comm = MPI.COMM_WORLD rank = comm.Get_rank() diff --git a/src/struphy/propagators/tests/test_poisson.py b/src/struphy/propagators/tests/test_poisson.py index be0d39291..78567f8d1 100644 --- a/src/struphy/propagators/tests/test_poisson.py +++ b/src/struphy/propagators/tests/test_poisson.py @@ -1,3 +1,4 @@ +import cunumpy as xp import matplotlib.pyplot as plt import pytest from psydac.ddm.mpi import mpi as MPI @@ -22,7 +23,6 @@ ) from struphy.propagators.base import Propagator from struphy.propagators.propagators_fields import ImplicitDiffusion, Poisson -import cunumpy as xp from struphy.utils.pyccel import Pyccelkernel comm = MPI.COMM_WORLD diff --git a/src/struphy/utils/clone_config.py b/src/struphy/utils/clone_config.py index ad78973ef..d23bee47c 100644 --- a/src/struphy/utils/clone_config.py +++ b/src/struphy/utils/clone_config.py @@ -1,8 +1,7 @@ +import cunumpy as xp from psydac.ddm.mpi import MockComm from psydac.ddm.mpi import mpi as MPI -import cunumpy as xp - class CloneConfig: """ From be32dab29847962a9473a2f694607bfccb60d8c9 Mon Sep 17 00:00:00 2001 From: Max Lindqvist Date: Wed, 22 Oct 2025 13:29:07 +0200 Subject: [PATCH 72/76] Fixed CI --- .gitlab-ci.yml | 2 -- src/struphy/utils/cupy_vs_numpy.py | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3385d72d3..896b8020e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -551,11 +551,9 @@ test_cupy: - python3 -m pip install --user cupy-cuda12x - python3 -c "import cupy as cp" # Test numpy backend - - python3 src/struphy/utils/arrays.py - python3 src/struphy/utils/cupy_vs_numpy.py # Test cupy backend - export ARRAY_BACKEND=cupy - - python3 src/struphy/utils/arrays.py - python3 src/struphy/utils/cupy_vs_numpy.py install_tests: diff --git a/src/struphy/utils/cupy_vs_numpy.py b/src/struphy/utils/cupy_vs_numpy.py index d32044a58..43f214d73 100644 --- a/src/struphy/utils/cupy_vs_numpy.py +++ b/src/struphy/utils/cupy_vs_numpy.py @@ -1,6 +1,6 @@ import time -from arrays import xp +import cunumpy as xp def main(N=8192): From 722d28d33b47df18933565fec3548c40468326af Mon Sep 17 00:00:00 2001 From: Max Lindqvist Date: Wed, 22 Oct 2025 14:43:06 +0200 Subject: [PATCH 73/76] Install cunumpy explicitly in test_cupy job --- .gitlab-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 896b8020e..9df6d696b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -550,6 +550,7 @@ test_cupy: # Install cupy - python3 -m pip install --user cupy-cuda12x - python3 -c "import cupy as cp" + - python3 -m pip install cunumpy # Test numpy backend - python3 src/struphy/utils/cupy_vs_numpy.py # Test cupy backend From 704f319a24b557afe243b04b2440b31fccdb0b87 Mon Sep 17 00:00:00 2001 From: Max Lindqvist Date: Wed, 22 Oct 2025 17:39:42 +0200 Subject: [PATCH 74/76] Formatting --- src/struphy/feec/psydac_derham.py | 2 +- src/struphy/geometry/base.py | 1 + src/struphy/geometry/transform_kernels.py | 3 +-- src/struphy/io/output_handling.py | 1 - src/struphy/main.py | 8 ++++---- src/struphy/models/base.py | 1 - src/struphy/pic/base.py | 2 ++ src/struphy/utils/pyccel.py | 1 + 8 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/struphy/feec/psydac_derham.py b/src/struphy/feec/psydac_derham.py index d5322737d..f55206d74 100644 --- a/src/struphy/feec/psydac_derham.py +++ b/src/struphy/feec/psydac_derham.py @@ -1,8 +1,8 @@ #!/usr/bin/env python3 import importlib.metadata -import numpy as np import cunumpy as xp +import numpy as np import psydac.core.bsplines as bsp from psydac.ddm.cart import DomainDecomposition from psydac.ddm.mpi import MockComm, MockMPI diff --git a/src/struphy/geometry/base.py b/src/struphy/geometry/base.py index cf8e03a09..c1a4b18a7 100644 --- a/src/struphy/geometry/base.py +++ b/src/struphy/geometry/base.py @@ -14,6 +14,7 @@ from struphy.linear_algebra import linalg_kron from struphy.utils.pyccel import Pyccelkernel + class Domain(metaclass=ABCMeta): r"""Base class for mapped domains (single patch). diff --git a/src/struphy/geometry/transform_kernels.py b/src/struphy/geometry/transform_kernels.py index 3ed65b9b2..ed1395618 100644 --- a/src/struphy/geometry/transform_kernels.py +++ b/src/struphy/geometry/transform_kernels.py @@ -43,8 +43,7 @@ - 2-form --> vector : (a_1, a_2, a_3) = (a^2_1, a^2_2, a^2_3) / |det(DF)| """ -from struphy.utils.arrays import array_backend -from struphy.utils.arrays import xp +from struphy.utils.arrays import array_backend, xp if array_backend.backend == "cupy": from cupy import empty, shape, sqrt, zeros diff --git a/src/struphy/io/output_handling.py b/src/struphy/io/output_handling.py index 17218f35a..a2599691e 100644 --- a/src/struphy/io/output_handling.py +++ b/src/struphy/io/output_handling.py @@ -2,7 +2,6 @@ import os import h5py - import numpy as np diff --git a/src/struphy/main.py b/src/struphy/main.py index d0b5eca96..25d67639a 100644 --- a/src/struphy/main.py +++ b/src/struphy/main.py @@ -255,8 +255,8 @@ def run( pointData["absB0"] = absB0 from struphy.utils.arrays import array_backend - - print('calling gridToVTK') + + print("calling gridToVTK") if array_backend.backend == "numpy": gridToVTK(os.path.join(path_out, "geometry"), *grids_phy, pointData=pointData) else: @@ -268,7 +268,7 @@ def run( # Now call gridToVTK safely gridToVTK(os.path.join(path_out, "geometry"), *grids_phy_cpu, pointData=pointData_cpu) - + # data object for saving (will either create new hdf5 files if restart==False or open existing files if restart==True) # use MPI.COMM_WORLD as communicator when storing the outputs data = DataContainer(path_out, comm=comm) @@ -287,7 +287,7 @@ def run( data.add_data({key_time: val}) data.add_data({key_time_restart: val}) else: - val_cpu = val.get()# if isinstance(val, xp.ndarray) else val + val_cpu = val.get() # if isinstance(val, xp.ndarray) else val # Then assign print(f"{val_cpu = } {type(val_cpu) = }") diff --git a/src/struphy/models/base.py b/src/struphy/models/base.py index b3257c1ce..24b4a3b3a 100644 --- a/src/struphy/models/base.py +++ b/src/struphy/models/base.py @@ -572,7 +572,6 @@ def update_scalar(self, name, value=None): else: self._scalar_quantities[name]["value"][0] = value_array[0] - else: # Sum the values of the summands value = sum(self._scalar_quantities[summand]["value"][0] for summand in summands) diff --git a/src/struphy/pic/base.py b/src/struphy/pic/base.py index 136c9a11a..caf3894aa 100644 --- a/src/struphy/pic/base.py +++ b/src/struphy/pic/base.py @@ -2644,10 +2644,12 @@ def check_and_assign_particles_to_boxes(self): and then assigne the particles to boxes.""" from struphy.utils.arrays import array_backend + if array_backend.backend == "numpy": bcount = xp.bincount(xp.int64(self.markers_wo_holes[:, -2])) else: import cupy as cp + indices = self.markers_wo_holes[:, -2] indices = indices.astype(cp.int64) bcount = cp.bincount(indices) diff --git a/src/struphy/utils/pyccel.py b/src/struphy/utils/pyccel.py index d7cbd4fb5..27e32d209 100644 --- a/src/struphy/utils/pyccel.py +++ b/src/struphy/utils/pyccel.py @@ -2,6 +2,7 @@ from struphy.utils.arrays import xp + class Pyccelkernel: def __init__(self, kernel: Callable[..., Any], use_cupy: bool = False) -> None: self._kernel = kernel From 5683c9fd7cefa0eb71144c456e56a9dfc8564deb Mon Sep 17 00:00:00 2001 From: Max Lindqvist Date: Wed, 22 Oct 2025 17:42:12 +0200 Subject: [PATCH 75/76] Fixed cunumpy imports --- src/struphy/geometry/transform_kernels.py | 3 ++- src/struphy/kernel_arguments/pusher_args_kernels.py | 2 +- src/struphy/main.py | 2 +- src/struphy/pic/base.py | 2 +- src/struphy/utils/pyccel.py | 2 +- 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/struphy/geometry/transform_kernels.py b/src/struphy/geometry/transform_kernels.py index ed1395618..4d062fa0b 100644 --- a/src/struphy/geometry/transform_kernels.py +++ b/src/struphy/geometry/transform_kernels.py @@ -43,7 +43,8 @@ - 2-form --> vector : (a_1, a_2, a_3) = (a^2_1, a^2_2, a^2_3) / |det(DF)| """ -from struphy.utils.arrays import array_backend, xp +import cunumpy as np +from cunumpy.xp import array_backend if array_backend.backend == "cupy": from cupy import empty, shape, sqrt, zeros diff --git a/src/struphy/kernel_arguments/pusher_args_kernels.py b/src/struphy/kernel_arguments/pusher_args_kernels.py index 2e81ba494..03d9e5bff 100644 --- a/src/struphy/kernel_arguments/pusher_args_kernels.py +++ b/src/struphy/kernel_arguments/pusher_args_kernels.py @@ -1,5 +1,5 @@ # from numpy import copy -from struphy.utils.arrays import xp +import cunumpy as xp class MarkerArguments: diff --git a/src/struphy/main.py b/src/struphy/main.py index 25d67639a..a4ec3df92 100644 --- a/src/struphy/main.py +++ b/src/struphy/main.py @@ -254,7 +254,7 @@ def run( absB0 = model.equil.absB0(*grids_log) pointData["absB0"] = absB0 - from struphy.utils.arrays import array_backend + from cunumpy.xp import array_backend print("calling gridToVTK") if array_backend.backend == "numpy": diff --git a/src/struphy/pic/base.py b/src/struphy/pic/base.py index caf3894aa..8406d76d1 100644 --- a/src/struphy/pic/base.py +++ b/src/struphy/pic/base.py @@ -2643,7 +2643,7 @@ def check_and_assign_particles_to_boxes(self): """Check whether the box array has enough columns (detect load imbalance wrt to sorting boxes), and then assigne the particles to boxes.""" - from struphy.utils.arrays import array_backend + from cunumpy.xp import array_backend if array_backend.backend == "numpy": bcount = xp.bincount(xp.int64(self.markers_wo_holes[:, -2])) diff --git a/src/struphy/utils/pyccel.py b/src/struphy/utils/pyccel.py index 27e32d209..defa214c4 100644 --- a/src/struphy/utils/pyccel.py +++ b/src/struphy/utils/pyccel.py @@ -1,6 +1,6 @@ from typing import Any, Callable -from struphy.utils.arrays import xp +import cunumpy as xp class Pyccelkernel: From e709c31e36d74d0d4814694aed7b6967f105f23e Mon Sep 17 00:00:00 2001 From: Max Lindqvist Date: Tue, 28 Oct 2025 16:16:30 +0100 Subject: [PATCH 76/76] Use numpy for scalars --- src/struphy/geometry/evaluation_kernels.py | 2 +- src/struphy/models/base.py | 9 +++++---- src/struphy/models/toy.py | 3 ++- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/struphy/geometry/evaluation_kernels.py b/src/struphy/geometry/evaluation_kernels.py index 4f97b9ce9..6b7995aec 100644 --- a/src/struphy/geometry/evaluation_kernels.py +++ b/src/struphy/geometry/evaluation_kernels.py @@ -3,7 +3,7 @@ corresponding to mappings (x, y, z) = F(eta_1, eta_2, eta_3). """ -from numpy import empty, shape, zeros +from cupy import empty, shape, zeros from pyccel.decorators import stack_array import struphy.geometry.mappings_kernels as mappings_kernels diff --git a/src/struphy/models/base.py b/src/struphy/models/base.py index 932bd066f..40de6f732 100644 --- a/src/struphy/models/base.py +++ b/src/struphy/models/base.py @@ -5,6 +5,7 @@ from functools import reduce from textwrap import indent +import numpy as np import cunumpy as xp import yaml from line_profiler import profile @@ -523,10 +524,10 @@ def update_scalar(self, name, value=None): # Ensure the value is a float if there are no summands if isinstance(value, float): # Create a numpy array to hold the scalar value - value_array = xp.array([value]) + value_array = np.array([value]) else: - value_array = xp.asarray(value) - value_array = xp.array(value_array) + value_array = np.asarray(value) + value_array = np.array(value_array) # Perform MPI operations based on the compute flags if "sum_world" in compute_operations and not isinstance(MPI, MockMPI): MPI.COMM_WORLD.Allreduce( @@ -563,7 +564,7 @@ def update_scalar(self, name, value=None): if "divide_n_mks" in compute_operations: # Initialize the total number of markers - n_mks_tot = xp.array([variable.particles.Np]) + n_mks_tot = np.array([variable.particles.Np]) value_array /= n_mks_tot # Update the scalar value diff --git a/src/struphy/models/toy.py b/src/struphy/models/toy.py index fd36b5d5f..5673c07a8 100644 --- a/src/struphy/models/toy.py +++ b/src/struphy/models/toy.py @@ -1,3 +1,4 @@ +import numpy as np import cunumpy as xp from psydac.ddm.mpi import mpi as MPI @@ -157,7 +158,7 @@ def velocity_scale(self): return "cyclotron" def allocate_helpers(self): - self._tmp = xp.empty(1, dtype=float) + self._tmp = np.empty(1, dtype=float) def update_scalar_quantities(self): particles = self.kinetic_ions.var.particles