From 779daebcd3026f5e9f73da8350a72e8ba05f6e31 Mon Sep 17 00:00:00 2001 From: giadarol Date: Thu, 20 Jun 2024 11:22:10 +0200 Subject: [PATCH 01/26] Remove dependency on sortednp --- pywit/component.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pywit/component.py b/pywit/component.py index 9f589a92..c0ca0bf0 100644 --- a/pywit/component.py +++ b/pywit/component.py @@ -6,7 +6,6 @@ from typing import Optional, Callable, Tuple, Union, List import numpy as np -import sortednp as snp def mix_fine_and_rough_sampling(start: float, stop: float, rough_points: int, @@ -30,7 +29,8 @@ def mix_fine_and_rough_sampling(start: float, stop: float, rough_points: int, fine_sampling_rois = np.hstack(intervals) if intervals else np.array([]) rough_sampling = np.geomspace(start, stop, rough_points) - return unique_sigfigs(snp.merge(fine_sampling_rois, rough_sampling), 7) + return unique_sigfigs( + np.sort(np.concatenate((fine_sampling_rois, rough_sampling))), 7) class Component: From 9fb2fedb0f37236c43b39ddddb9e745b908093ae Mon Sep 17 00:00:00 2001 From: giadarol Date: Thu, 20 Jun 2024 11:38:37 +0200 Subject: [PATCH 02/26] Avoid warning --- pywit/sacherer_formula.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pywit/sacherer_formula.py b/pywit/sacherer_formula.py index 194814fe..9aec1912 100644 --- a/pywit/sacherer_formula.py +++ b/pywit/sacherer_formula.py @@ -134,6 +134,8 @@ def hmm_weighted_sum(m_mode: int, nx_mode: int, weight_function: Callable[[float k = k + k_max + summ1_inner = np.squeeze(sum1_inner) # return a scalar if only one element + return sum1_inner if impedance_function is not None and impedance_table is not None: @@ -182,6 +184,7 @@ def impedance_function(x): sum1 = hmm_weighted_sum(m, nx) # effective impedance + import pdb; pdb.set_trace() sum2 = hmm_weighted_sum(m, nx, weight_function=impedance_function) effective_impedance[inx, im] = sum2 / sum1 From 163997c18cc52923f1e2343e6f8b57f6ec3d1024 Mon Sep 17 00:00:00 2001 From: giadarol Date: Thu, 20 Jun 2024 11:41:13 +0200 Subject: [PATCH 03/26] typo --- pywit/sacherer_formula.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pywit/sacherer_formula.py b/pywit/sacherer_formula.py index 9aec1912..88e8eb99 100644 --- a/pywit/sacherer_formula.py +++ b/pywit/sacherer_formula.py @@ -11,7 +11,8 @@ def sacherer_formula(qp: float, nx_array: np.array, bunch_intensity: float, omeg impedance_table: np.array = None, freq_impedance_table: np.array = None, impedance_function: Callable[[float], float] = None, m0: float = m_p, charge: float = q_p, mode_type: str = 'sinusoidal') -> Tuple[np.array, float, np.array]: - """ + + r""" Computes frequency shift and effective impedance from Sacherer formula, in transverse, in the case of low intensity perturbations (no mode coupling), for modes of kind 'mode_type'. @@ -134,7 +135,7 @@ def hmm_weighted_sum(m_mode: int, nx_mode: int, weight_function: Callable[[float k = k + k_max - summ1_inner = np.squeeze(sum1_inner) # return a scalar if only one element + sum1_inner = np.squeeze(sum1_inner) # return a scalar if only one element return sum1_inner @@ -184,7 +185,6 @@ def impedance_function(x): sum1 = hmm_weighted_sum(m, nx) # effective impedance - import pdb; pdb.set_trace() sum2 = hmm_weighted_sum(m, nx, weight_function=impedance_function) effective_impedance[inx, im] = sum2 / sum1 From 18ddcadda578643321cdf24611a901a6f23d92a8 Mon Sep 17 00:00:00 2001 From: giadarol Date: Thu, 20 Jun 2024 11:46:15 +0200 Subject: [PATCH 04/26] Change version number --- xwakes/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xwakes/_version.py b/xwakes/_version.py index c57bfd58..b8023d8b 100644 --- a/xwakes/_version.py +++ b/xwakes/_version.py @@ -1 +1 @@ -__version__ = '0.0.0' +__version__ = '0.0.1' From 6e2724f41e3d18becc1d3d88fe2944d03e103353 Mon Sep 17 00:00:00 2001 From: giadarol Date: Thu, 20 Jun 2024 12:27:46 +0200 Subject: [PATCH 05/26] Restructure package --- pywit/__init__.py | 1 + tests/test_utilities.py | 11 ++++++----- xwakes/wit/__init__.py | 13 +++++++++++++ {pywit => xwakes/wit}/component.py | 4 ++-- {pywit => xwakes/wit}/devices.py | 8 ++++---- {pywit => xwakes/wit}/element.py | 2 +- {pywit => xwakes/wit}/elements_group.py | 4 ++-- {pywit => xwakes/wit}/interface.py | 6 +++--- {pywit => xwakes/wit}/landau_damping.py | 0 {pywit => xwakes/wit}/materials.json | 0 {pywit => xwakes/wit}/materials.py | 6 +++--- {pywit => xwakes/wit}/model.py | 2 +- {pywit => xwakes/wit}/parameters.py | 0 {pywit => xwakes/wit}/plot.py | 8 ++++---- {pywit => xwakes/wit}/sacherer_formula.py | 0 {pywit => xwakes/wit}/utilities.py | 10 +++++----- {pywit => xwakes/wit}/utils.py | 0 17 files changed, 45 insertions(+), 30 deletions(-) create mode 100644 xwakes/wit/__init__.py rename {pywit => xwakes/wit}/component.py (99%) rename {pywit => xwakes/wit}/devices.py (98%) rename {pywit => xwakes/wit}/element.py (99%) rename {pywit => xwakes/wit}/elements_group.py (99%) rename {pywit => xwakes/wit}/interface.py (99%) rename {pywit => xwakes/wit}/landau_damping.py (100%) rename {pywit => xwakes/wit}/materials.json (100%) rename {pywit => xwakes/wit}/materials.py (99%) rename {pywit => xwakes/wit}/model.py (96%) rename {pywit => xwakes/wit}/parameters.py (100%) rename {pywit => xwakes/wit}/plot.py (98%) rename {pywit => xwakes/wit}/sacherer_formula.py (100%) rename {pywit => xwakes/wit}/utilities.py (99%) rename {pywit => xwakes/wit}/utils.py (100%) diff --git a/pywit/__init__.py b/pywit/__init__.py index e69de29b..8262aed3 100644 --- a/pywit/__init__.py +++ b/pywit/__init__.py @@ -0,0 +1 @@ +from xwakes.wit import * \ No newline at end of file diff --git a/tests/test_utilities.py b/tests/test_utilities.py index 4dba81de..c32bbe20 100644 --- a/tests/test_utilities.py +++ b/tests/test_utilities.py @@ -3,13 +3,14 @@ create_resistive_wall_single_layer_approx_component, create_resistive_wall_single_layer_approx_element, create_taper_RW_approx_component, - create_taper_RW_approx_element, - _zlong_round_single_layer_approx, - _zdip_round_single_layer_approx) + create_taper_RW_approx_element) +from xwakes.wit.utilities import (_zlong_round_single_layer_approx, + _zdip_round_single_layer_approx) from test_common import relative_error from pywit.parameters import * -from pywit.interface import (Layer, _IW2DInputBase, FlatIW2DInput, - RoundIW2DInput, Sampling, component_names) +from pywit.interface import (FlatIW2DInput, RoundIW2DInput, Sampling, + component_names) +from xwakes.wit.interface import _IW2DInputBase from pywit.materials import layer_from_json_material_library, copper_at_temperature from typing import Dict diff --git a/xwakes/wit/__init__.py b/xwakes/wit/__init__.py new file mode 100644 index 00000000..94937423 --- /dev/null +++ b/xwakes/wit/__init__.py @@ -0,0 +1,13 @@ +from . import component +from . import devices +from . import element +from . import elements_group +from . import interface +from . import landau_damping +from . import materials +from . import model +from . import parameters +from . import plot +from . import sacherer_formula +from . import utilities +from . import utils \ No newline at end of file diff --git a/pywit/component.py b/xwakes/wit/component.py similarity index 99% rename from pywit/component.py rename to xwakes/wit/component.py index c0ca0bf0..89704089 100644 --- a/pywit/component.py +++ b/xwakes/wit/component.py @@ -1,7 +1,7 @@ from __future__ import annotations -from pywit.parameters import * -from pywit.utils import unique_sigfigs +from .parameters import * +from .utils import unique_sigfigs from typing import Optional, Callable, Tuple, Union, List diff --git a/pywit/devices.py b/xwakes/wit/devices.py similarity index 98% rename from pywit/devices.py rename to xwakes/wit/devices.py index 4ff77cc8..8d30bc8e 100644 --- a/pywit/devices.py +++ b/xwakes/wit/devices.py @@ -1,8 +1,8 @@ from typing import Tuple,Sequence -from pywit.component import Component -from pywit.element import Element -from pywit.utilities import create_resonator_component -from pywit.interface import component_names, get_component_name +from .component import Component +from .element import Element +from .utilities import create_resonator_component +from .interface import component_names, get_component_name import numpy as np from scipy import integrate diff --git a/pywit/element.py b/xwakes/wit/element.py similarity index 99% rename from pywit/element.py rename to xwakes/wit/element.py index cd1582ca..f35309fc 100644 --- a/pywit/element.py +++ b/xwakes/wit/element.py @@ -1,6 +1,6 @@ from __future__ import annotations -from pywit.component import Component, Union +from .component import Component, Union from typing import List from collections import defaultdict diff --git a/pywit/elements_group.py b/xwakes/wit/elements_group.py similarity index 99% rename from pywit/elements_group.py rename to xwakes/wit/elements_group.py index 87a7275a..872e340b 100644 --- a/pywit/elements_group.py +++ b/xwakes/wit/elements_group.py @@ -2,8 +2,8 @@ import numpy as np -from pywit.element import Element -from pywit.component import Component, Union +from .element import Element +from .component import Component, Union from typing import List diff --git a/pywit/interface.py b/xwakes/wit/interface.py similarity index 99% rename from pywit/interface.py rename to xwakes/wit/interface.py index d3c33091..623c9556 100644 --- a/pywit/interface.py +++ b/xwakes/wit/interface.py @@ -1,7 +1,7 @@ import os -from pywit.component import Component -from pywit.element import Element +from .component import Component +from .element import Element import subprocess from typing import Tuple, List, Optional, Dict, Any, Union @@ -560,7 +560,7 @@ def create_element_using_iw2d(iw2d_input: Union[FlatIW2DInput, RoundIW2DInput], # When the wake is computed with IW2D, a second set of files is provided by IW2D. These correspond to a "converged" # simulation with double the number of mesh points for the wake. They files have the _precise suffix to their name. - # If the wake is computed, we retrieve these file to create the pywit element. + # If the wake is computed, we retrieve these file to create the wit element. common_string = "_precise" if iw2d_input.calculate_wake else '' component_recipes = import_data_iw2d(directory=working_directory, common_string=common_string) diff --git a/pywit/landau_damping.py b/xwakes/wit/landau_damping.py similarity index 100% rename from pywit/landau_damping.py rename to xwakes/wit/landau_damping.py diff --git a/pywit/materials.json b/xwakes/wit/materials.json similarity index 100% rename from pywit/materials.json rename to xwakes/wit/materials.json diff --git a/pywit/materials.py b/xwakes/wit/materials.py similarity index 99% rename from pywit/materials.py rename to xwakes/wit/materials.py index 8fba2858..cdf73b2a 100644 --- a/pywit/materials.py +++ b/xwakes/wit/materials.py @@ -1,5 +1,5 @@ -from pywit.interface import Layer -from pywit.utils import round_sigfigs +from .interface import Layer +from .utils import round_sigfigs from pathlib import Path import numpy as np @@ -48,7 +48,7 @@ def layer_from_json_material_library(thickness: float, material_key: str, :type thickness: float :param material_key: material key in the materials.json file :type material_key: str - :param library_path: material library path, defaults to materials.json present in pywit + :param library_path: material library path, defaults to materials.json present in wit :type library_path: Path, optional :return: Layer of the selected material :rtype: Layer diff --git a/pywit/model.py b/xwakes/wit/model.py similarity index 96% rename from pywit/model.py rename to xwakes/wit/model.py index 1f2c9a8c..6e029e37 100644 --- a/pywit/model.py +++ b/xwakes/wit/model.py @@ -1,4 +1,4 @@ -from pywit.element import Element +from .element import Element from typing import List, Optional, Tuple diff --git a/pywit/parameters.py b/xwakes/wit/parameters.py similarity index 100% rename from pywit/parameters.py rename to xwakes/wit/parameters.py diff --git a/pywit/plot.py b/xwakes/wit/plot.py similarity index 98% rename from pywit/plot.py rename to xwakes/wit/plot.py index dce551c5..b4b30b3e 100644 --- a/pywit/plot.py +++ b/xwakes/wit/plot.py @@ -1,7 +1,7 @@ -from pywit.component import Component -from pywit.element import Element -from pywit.model import Model -from pywit.parameters import * +from .component import Component +from .element import Element +from .model import Model +from .parameters import * from typing import List, Dict, Union, Optional, Set from collections import defaultdict diff --git a/pywit/sacherer_formula.py b/xwakes/wit/sacherer_formula.py similarity index 100% rename from pywit/sacherer_formula.py rename to xwakes/wit/sacherer_formula.py diff --git a/pywit/utilities.py b/xwakes/wit/utilities.py similarity index 99% rename from pywit/utilities.py rename to xwakes/wit/utilities.py index 8c32d410..5b903a1c 100644 --- a/pywit/utilities.py +++ b/xwakes/wit/utilities.py @@ -1,7 +1,7 @@ -from pywit.component import Component -from pywit.element import Element -from pywit.interface import Layer, FlatIW2DInput, RoundIW2DInput -from pywit.interface import component_names +from .component import Component +from .element import Element +from .interface import Layer, FlatIW2DInput, RoundIW2DInput +from .interface import component_names from yaml import load, SafeLoader from typing import Tuple, Dict, List, Union, Sequence, Optional, Callable @@ -217,7 +217,7 @@ def create_classic_thick_wall_component(plane: str, exponents: Tuple[int, int, i Only longitudinal and transverse dipolar impedances are supported here. :param plane: the plane the component corresponds to :param exponents: four integers corresponding to (source_x, source_y, test_x, test_y) aka (a, b, c, d) - :param layer: the chamber material, as a pywit Layer object + :param layer: the chamber material, as a wit Layer object :param radius: the chamber radius in m :return: A component object """ diff --git a/pywit/utils.py b/xwakes/wit/utils.py similarity index 100% rename from pywit/utils.py rename to xwakes/wit/utils.py From 234f76048f8b35ca6aefa85b6fc56133bace19df Mon Sep 17 00:00:00 2001 From: giadarol Date: Thu, 20 Jun 2024 12:28:11 +0200 Subject: [PATCH 06/26] Clean up --- LICENSE.txt | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 LICENSE.txt diff --git a/LICENSE.txt b/LICENSE.txt deleted file mode 100644 index f85e365d..00000000 --- a/LICENSE.txt +++ /dev/null @@ -1,17 +0,0 @@ -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. From 548b48774d31c1ddba4ab0f9759d3346f2438653 Mon Sep 17 00:00:00 2001 From: giadarol Date: Thu, 20 Jun 2024 12:29:30 +0200 Subject: [PATCH 07/26] Add data file to MANIFEST.in --- MANIFEST.in | 3 +++ 1 file changed, 3 insertions(+) diff --git a/MANIFEST.in b/MANIFEST.in index 346766ba..1e3be698 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -5,3 +5,6 @@ include *.md # Include the license file include LICENSE + +# Include the data files +include xwakes/wit/materials.json From d874b2cf2df9821d6556fb8577cdc8d0b947de51 Mon Sep 17 00:00:00 2001 From: giadarol Date: Thu, 20 Jun 2024 12:30:02 +0200 Subject: [PATCH 08/26] Change version number --- xwakes/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xwakes/_version.py b/xwakes/_version.py index b8023d8b..d18f4098 100644 --- a/xwakes/_version.py +++ b/xwakes/_version.py @@ -1 +1 @@ -__version__ = '0.0.1' +__version__ = '0.0.2' From 5494b7c1d2ea8f262d578ed2300403e09b05a97c Mon Sep 17 00:00:00 2001 From: giadarol Date: Thu, 20 Jun 2024 12:32:43 +0200 Subject: [PATCH 09/26] Add missing files --- pywit/component.py | 1 + pywit/devices.py | 1 + pywit/doit.py | 10 ++++++++++ pywit/element.py | 1 + pywit/elements_group.py | 1 + pywit/interface.py | 1 + pywit/landau_damping.py | 1 + pywit/materials.py | 1 + pywit/model.py | 1 + pywit/parameters.py | 1 + pywit/plot.py | 1 + pywit/sacherer_formula.py | 1 + pywit/utilities.py | 1 + pywit/utils.py | 1 + 14 files changed, 23 insertions(+) create mode 100644 pywit/component.py create mode 100644 pywit/devices.py create mode 100644 pywit/doit.py create mode 100644 pywit/element.py create mode 100644 pywit/elements_group.py create mode 100644 pywit/interface.py create mode 100644 pywit/landau_damping.py create mode 100644 pywit/materials.py create mode 100644 pywit/model.py create mode 100644 pywit/parameters.py create mode 100644 pywit/plot.py create mode 100644 pywit/sacherer_formula.py create mode 100644 pywit/utilities.py create mode 100644 pywit/utils.py diff --git a/pywit/component.py b/pywit/component.py new file mode 100644 index 00000000..494ae52f --- /dev/null +++ b/pywit/component.py @@ -0,0 +1 @@ +from xwakes.wit.component import * diff --git a/pywit/devices.py b/pywit/devices.py new file mode 100644 index 00000000..81f8db52 --- /dev/null +++ b/pywit/devices.py @@ -0,0 +1 @@ +from xwakes.wit.devices import * diff --git a/pywit/doit.py b/pywit/doit.py new file mode 100644 index 00000000..025dff46 --- /dev/null +++ b/pywit/doit.py @@ -0,0 +1,10 @@ +import os + +fff = os.listdir('../xwakes/wit') + +for nn in fff: + if not nn.endswith('.py') or nn.startswith('_'): + continue + + with open(nn, 'w') as fid: + fid.write(f'from xwakes.wit.{nn.split(".py")[0]} import *\n') \ No newline at end of file diff --git a/pywit/element.py b/pywit/element.py new file mode 100644 index 00000000..e9a6c3d9 --- /dev/null +++ b/pywit/element.py @@ -0,0 +1 @@ +from xwakes.wit.element import * diff --git a/pywit/elements_group.py b/pywit/elements_group.py new file mode 100644 index 00000000..1a16666d --- /dev/null +++ b/pywit/elements_group.py @@ -0,0 +1 @@ +from xwakes.wit.elements_group import * diff --git a/pywit/interface.py b/pywit/interface.py new file mode 100644 index 00000000..ec0bb6ce --- /dev/null +++ b/pywit/interface.py @@ -0,0 +1 @@ +from xwakes.wit.interface import * diff --git a/pywit/landau_damping.py b/pywit/landau_damping.py new file mode 100644 index 00000000..39882ab7 --- /dev/null +++ b/pywit/landau_damping.py @@ -0,0 +1 @@ +from xwakes.wit.landau_damping import * diff --git a/pywit/materials.py b/pywit/materials.py new file mode 100644 index 00000000..0441f038 --- /dev/null +++ b/pywit/materials.py @@ -0,0 +1 @@ +from xwakes.wit.materials import * diff --git a/pywit/model.py b/pywit/model.py new file mode 100644 index 00000000..08d74639 --- /dev/null +++ b/pywit/model.py @@ -0,0 +1 @@ +from xwakes.wit.model import * diff --git a/pywit/parameters.py b/pywit/parameters.py new file mode 100644 index 00000000..2e3c6dc4 --- /dev/null +++ b/pywit/parameters.py @@ -0,0 +1 @@ +from xwakes.wit.parameters import * diff --git a/pywit/plot.py b/pywit/plot.py new file mode 100644 index 00000000..bc606669 --- /dev/null +++ b/pywit/plot.py @@ -0,0 +1 @@ +from xwakes.wit.plot import * diff --git a/pywit/sacherer_formula.py b/pywit/sacherer_formula.py new file mode 100644 index 00000000..de7b4779 --- /dev/null +++ b/pywit/sacherer_formula.py @@ -0,0 +1 @@ +from xwakes.wit.sacherer_formula import * diff --git a/pywit/utilities.py b/pywit/utilities.py new file mode 100644 index 00000000..f61c1064 --- /dev/null +++ b/pywit/utilities.py @@ -0,0 +1 @@ +from xwakes.wit.utilities import * diff --git a/pywit/utils.py b/pywit/utils.py new file mode 100644 index 00000000..10834455 --- /dev/null +++ b/pywit/utils.py @@ -0,0 +1 @@ +from xwakes.wit.utils import * From caa13a5296e7cd25b1dce34c26f1d59536a9a902 Mon Sep 17 00:00:00 2001 From: giadarol Date: Thu, 20 Jun 2024 12:33:14 +0200 Subject: [PATCH 10/26] Change version number --- xwakes/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xwakes/_version.py b/xwakes/_version.py index d18f4098..ffcc925a 100644 --- a/xwakes/_version.py +++ b/xwakes/_version.py @@ -1 +1 @@ -__version__ = '0.0.2' +__version__ = '0.0.3' From a3ffe66b5b933098ca7df1ab55cc6177ea9e9f7f Mon Sep 17 00:00:00 2001 From: giadarol Date: Thu, 20 Jun 2024 12:35:36 +0200 Subject: [PATCH 11/26] Display version --- xwakes/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/xwakes/__init__.py b/xwakes/__init__.py index e69de29b..8dee4bf8 100644 --- a/xwakes/__init__.py +++ b/xwakes/__init__.py @@ -0,0 +1 @@ +from ._version import __version__ From e82db1cdf430b962dbe246d23c000251981846a1 Mon Sep 17 00:00:00 2001 From: giadarol Date: Thu, 20 Jun 2024 16:20:09 +0200 Subject: [PATCH 12/26] Add init_pywit_directory.py --- xwakes/init_pywit_directory.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 xwakes/init_pywit_directory.py diff --git a/xwakes/init_pywit_directory.py b/xwakes/init_pywit_directory.py new file mode 100644 index 00000000..cc4aa4ae --- /dev/null +++ b/xwakes/init_pywit_directory.py @@ -0,0 +1,19 @@ +import pathlib +import pickle +import os + +def _initialize_pywit_directory() -> None: + home_path = pathlib.Path.home() + paths = [home_path.joinpath('pywit').joinpath(ext) for ext in ('config', 'IW2D/bin', 'IW2D/projects')] + for path in paths: + os.makedirs(path, exist_ok=True) + with open(pathlib.Path(paths[0]).joinpath('iw2d_settings.yaml'), 'w') as file: + file.write(f'binary_directory: {paths[1]}\n' + f'project_directory: {paths[2]}') + + filenames = ('component', 'element', 'iw2d_inputs') + for filename in filenames: + open(paths[0].joinpath(f"{filename}.yaml"), 'w').close() + + with open(paths[2].joinpath('hashmap.pickle'), 'wb') as handle: + pickle.dump(dict(), handle, protocol=pickle.HIGHEST_PROTOCOL) From 92d4dadb4c0a58ed897d1b4aecf1b6033b4de5dd Mon Sep 17 00:00:00 2001 From: giadarol Date: Thu, 20 Jun 2024 16:21:15 +0200 Subject: [PATCH 13/26] Function --- xwakes/__init__.py | 2 ++ xwakes/init_pywit_directory.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/xwakes/__init__.py b/xwakes/__init__.py index 8dee4bf8..ae263b13 100644 --- a/xwakes/__init__.py +++ b/xwakes/__init__.py @@ -1 +1,3 @@ from ._version import __version__ + +from .init_pywit_directory import initialize_pywit_directory diff --git a/xwakes/init_pywit_directory.py b/xwakes/init_pywit_directory.py index cc4aa4ae..1b02a8aa 100644 --- a/xwakes/init_pywit_directory.py +++ b/xwakes/init_pywit_directory.py @@ -2,7 +2,7 @@ import pickle import os -def _initialize_pywit_directory() -> None: +def initialize_pywit_directory() -> None: home_path = pathlib.Path.home() paths = [home_path.joinpath('pywit').joinpath(ext) for ext in ('config', 'IW2D/bin', 'IW2D/projects')] for path in paths: From 52cbdda49cad0f9bf36a83c60659e88ca5872e1a Mon Sep 17 00:00:00 2001 From: giadarol Date: Thu, 20 Jun 2024 16:35:45 +0200 Subject: [PATCH 14/26] Make matplotlib optional --- xwakes/wit/plot.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/xwakes/wit/plot.py b/xwakes/wit/plot.py index b4b30b3e..ecdbbdcc 100644 --- a/xwakes/wit/plot.py +++ b/xwakes/wit/plot.py @@ -6,7 +6,6 @@ from typing import List, Dict, Union, Optional, Set from collections import defaultdict -import matplotlib.pyplot as plt import numpy as np @@ -26,6 +25,7 @@ def plot_component(component: Component, plot_impedance: bool = True, plot_wake: :param plot_imag: A flag indicating if the imaginary values should be plotted :return: Nothing """ + import matplotlib.pyplot as plt assert (plot_wake or plot_impedance) and (plot_real or plot_imag), "There is nothing to plot" assert stop - start > 0, "stop must be greater than start" if step_size: @@ -84,6 +84,7 @@ def plot_element_in_plane(element: Element, plane: str, plot_impedance: bool = T def plot_component_impedance(component: Component, logscale_x: bool = True, logscale_y: bool = True, points: int = 1000, start=MIN_FREQ, stop=MAX_FREQ, title: Optional[str] = None) -> None: + import matplotlib.pyplot as plt fig: plt.Figure = plt.figure() ax: plt.Axes = fig.add_subplot(111) fs = np.geomspace(start, stop, points) @@ -110,6 +111,7 @@ def plot_component_impedance(component: Component, logscale_x: bool = True, logs def plot_component_wake(component: Component, logscale_x: bool = True, logscale_y: bool = True, points: int = 1000, start=MIN_TIME, stop=MAX_TIME, title: Optional[str] = None) -> None: + import matplotlib.pyplot as plt fig: plt.Figure = plt.figure() ax: plt.Axes = fig.add_subplot(111) ts = np.geomspace(start, stop, points) @@ -134,6 +136,9 @@ def plot_component_wake(component: Component, logscale_x: bool = True, logscale_ def generate_contribution_plots(model: Model, start_freq: float = MIN_FREQ, stop_freq: float = MAX_FREQ, start_time: float = MIN_TIME, stop_time: float = MAX_TIME, points: int = 1000, freq_scale: str = 'log', time_scale: str = 'log', absolute: bool = False) -> None: + + import matplotlib.pyplot as plt + # TODO: use roi's to generate grid fs = np.geomspace(start_freq, stop_freq, points) ts = np.geomspace(start_time, stop_time, points) From af6c40a7edc53bce60fe59d6e6b6f3fd599f687a Mon Sep 17 00:00:00 2001 From: giadarol Date: Thu, 20 Jun 2024 16:39:29 +0200 Subject: [PATCH 15/26] Generalize path handling --- tests/test_interface.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test_interface.py b/tests/test_interface.py index f471884c..6381839a 100644 --- a/tests/test_interface.py +++ b/tests/test_interface.py @@ -15,6 +15,8 @@ import numpy as np +CURR_DIR = Path(__file__).resolve().parent + @mark.parametrize('is_impedance, plane, exponents, expected_comp_name', [[True, 'z', (0, 0, 0, 0), 'zlong'], @@ -47,7 +49,7 @@ def test_duplicate_component_iw2d_import(): pytest.skip("IW2D is not installed") with raises(AssertionError) as error_message: - import_data_iw2d(directory=Path("test/test_data/iw2d/duplicate_components").resolve(), + import_data_iw2d(directory=CURR_DIR / "test_data/iw2d/duplicate_components", common_string="WLHC_2layersup_0layersdown6.50mm") assert error_message.value.args[0] in ["The wake files 'WlongWLHC_2layersup_0layersdown6.50mm.dat' and " From 648f02cf8bfb5938703dfc2a535e95941cbcda3e Mon Sep 17 00:00:00 2001 From: giadarol Date: Thu, 20 Jun 2024 16:42:11 +0200 Subject: [PATCH 16/26] Adapt tests --- tests/test_interface.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/test_interface.py b/tests/test_interface.py index 6381839a..93a99c45 100644 --- a/tests/test_interface.py +++ b/tests/test_interface.py @@ -68,12 +68,14 @@ def test_no_matching_filename_iw2d_import(): except ImportError: pytest.skip("IW2D is not installed") + test_dir = CURR_DIR / "test_data/iw2d/valid_directory" + with raises(AssertionError) as error_message: - import_data_iw2d(directory=Path("test/test_data/iw2d/valid_directory").resolve(), + import_data_iw2d(directory=test_dir, common_string="this_string_matches_no_file") expected_error_message = f"No files in " \ - f"'{Path('test/test_data/iw2d/valid_directory').resolve()}'" \ + f"'{test_dir.resolve()}'" \ f" matched the common string 'this_string_matches_no_file'." assert error_message.value.args[0] == expected_error_message @@ -89,7 +91,7 @@ def test_valid_iw2d_component_import(): # Normally, the relativistic gamma would be an attribute of a required IW2DInput object, but here it has been # hard-coded instead relativstic_gamma = 479.605064966 - recipes = import_data_iw2d(directory=Path("test/test_data/iw2d/valid_directory").resolve(), + recipes = import_data_iw2d(directory=CURR_DIR / "test_data/iw2d/valid_directory", common_string="precise") for recipe in recipes: component = create_component_from_data(*recipe, relativistic_gamma=relativstic_gamma) @@ -112,7 +114,7 @@ def iw2d_input(request): return RoundIW2DInput(machine='test', length=1, relativistic_gamma=7000, calculate_wake=request.param['wake_computation'], f_params=f_params, comment='test', layers=layers_tung, inner_layer_radius=5e-2, yokoya_factors=(1, 1, 1, 1, 1), z_params=z_params) - + if request.param['chamber_type'] == 'flat': return FlatIW2DInput(machine='test', length=1, relativistic_gamma=7000, calculate_wake=request.param['wake_computation'], f_params=f_params, comment='test', From 10bb5f057f5b9617236dde7e97755419428e10d9 Mon Sep 17 00:00:00 2001 From: giadarol Date: Thu, 20 Jun 2024 16:48:27 +0200 Subject: [PATCH 17/26] trapz -> trapezoid in numpy 2 --- xwakes/wit/utilities.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/xwakes/wit/utilities.py b/xwakes/wit/utilities.py index 5b903a1c..148d5d41 100644 --- a/xwakes/wit/utilities.py +++ b/xwakes/wit/utilities.py @@ -8,12 +8,17 @@ from collections import defaultdict from numpy import (vectorize, sqrt, exp, pi, sin, cos, abs, sign, - inf, floor, linspace, trapz, ones, isscalar, array) + inf, floor, linspace, ones, isscalar, array) from numpy.typing import ArrayLike import scipy.constants from scipy import special as sp import numpy as np +if hasattr(np, 'trapezoid'): + trapz = np.trapezoid # numpy 2.0 +else: + trapz = np.trapz + c_light = scipy.constants.speed_of_light # m s-1 mu0 = scipy.constants.mu_0 Z0 = mu0 * c_light From bdcd79bbe92d92fd15716a8492b0e1b5a15268a3 Mon Sep 17 00:00:00 2001 From: giadarol Date: Thu, 20 Jun 2024 17:09:06 +0200 Subject: [PATCH 18/26] Add CI workflow --- xwakes/.github/workflows/pr_workflow.yaml | 24 +++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 xwakes/.github/workflows/pr_workflow.yaml diff --git a/xwakes/.github/workflows/pr_workflow.yaml b/xwakes/.github/workflows/pr_workflow.yaml new file mode 100644 index 00000000..6e2371a7 --- /dev/null +++ b/xwakes/.github/workflows/pr_workflow.yaml @@ -0,0 +1,24 @@ +# On PR run the tests + +on: + pull_request: + branches: + - main + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up Python 3.11 + uses: actions/setup-python@v2 + with: + python-version: 3.11 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install . + - name: Run tests + run: | + cd tests + pytest -v From 7d9a60121a3f026627c042f3c2b1925c180ad673 Mon Sep 17 00:00:00 2001 From: giadarol Date: Thu, 20 Jun 2024 17:23:24 +0200 Subject: [PATCH 19/26] Add scipy dependency --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index dcc6e115..01ab50e7 100644 --- a/setup.py +++ b/setup.py @@ -40,6 +40,7 @@ include_package_data=True, install_requires=[ 'numpy>=1.0', + 'scipy', 'pyyaml', ], extras_require={ From e072fdc88158c4d6985f1d8b2243c5c21de9235d Mon Sep 17 00:00:00 2001 From: Lorenzo Giacomel <47607756+lgiacome@users.noreply.github.com> Date: Thu, 20 Jun 2024 17:55:08 +0200 Subject: [PATCH 20/26] Update README.md --- README.md | 62 +++++++++++++++++-------------------------------------- 1 file changed, 19 insertions(+), 43 deletions(-) diff --git a/README.md b/README.md index 9b2cafce..134f1415 100644 --- a/README.md +++ b/README.md @@ -1,55 +1,31 @@ -# PyWIT -####Python Wake and Impedance Toolbox - -## Installation -**NB:** Though most of this PyWIT's functionality is available independently of any non-dependency package, -the installation of IW2D (https://gitlab.cern.ch/IRIS/IW2D) is *strongly recommended* in order to have full access to -all of the features of PyWIT. For this reason, this installation guide will include the installation process required by -IW2D. If you already have IW2D downloaded and installed on your system, you can skip directly to step 3. Please note that IW2D (at the time of writing) is only available on Linux systems. - -1. Download the IW2D repository to your system by cloning the git repository. This can be done by executing the command - - `git clone https://gitlab.cern.ch/IRIS/IW2D` - - in a suitable directory. You may be prompted to enter your CERN log-in credentials for this step. - - -2. Perform the installation procedure for IW2D. This is explained in detail in the `README.md` file in the IW2D repository, but is summarized here: - 1. Install the prerequisite libraries "MPFR" and "GSL" by running: - `sudo apt-get install libgsl-dev libmpfr-dev` - or alternatively, if you have anaconda/miniconda installed: - `conda install -c conda-forge gsl mpfr` - 2. Compile the C++ code by running: - ``` - cd IW2D/cpp - cp ./Makefile_system_GMP_MPFR Makefile - make - ``` +# Xwakes +Python package for wakes and impedances handling. -3. In a new directory, where you want your PyWIT directory to be placed, Download the PyWIT repository to your system by - cloning the git repository. This can be done by executing the command - - `git clone https://gitlab.cern.ch/IRIS/pywit`. - - You may be prompted to enter your CERN log-in credentials for this step. - +## Installation -4. Install PyWIT using pip by navigating to your pywit directory executing the command +Under a conda environment with Python 3.8+ it is simply installed via PyPI by doing `pip install xwakes` - `pip install .`. +## IW2D coupling +This section describes how to couple Xwakes to IW2D using the executables obtained compiling the C++ code. +When the Python interface of IW2D will be completed this will not be needed anymore. -5. Navigate to the directory `IW2D/IW2D/cpp` in the IW2D repository. Copy the following four -files from this folder: +To begin with, a some folders need to be created in the user's home directory. +This can be automatically done by running the following command after Xwakes is installed: +``` +python -c 'import xwakes; xwakes.initialize_pywit_directory()' +``` +The IW2D executable are produced by following the [IW2D readme]([https://gitlab.cern.ch/IRIS/IW2D/-/tree/master?ref_type=heads)](https://gitlab.cern.ch/IRIS/IW2D/). +After this procedure is completed the following executable files will be created in `/path/to/iw2d/IW2D/cpp/`: * `flatchamber.x` * `roundchamber.x` * `wake_flatchamber.x` * `wake_roundchamber.x` - - -6. In your home directory, there will have appeared a new directory called 'pywit'. Navigate into this folder, then -into 'IW2D', then into 'bin'. Paste the four files copied in step 5 into this folder. +These files have to be copied in the newly created folder with the command -You should now be able to use PyWIT with your Python system interpreter. +``` +cp /path/to/iw2d/IW2D/cpp/*.x ~/pywit/IW2D/bin +``` +Now Xwakes can be used to launch IW2D calculations. From 06e8e1504bf325915c42cd6abb7a3bd28bcc666e Mon Sep 17 00:00:00 2001 From: nimounet Date: Fri, 21 Jun 2024 09:47:59 +0200 Subject: [PATCH 21/26] Correcting typo in README --- README.md | 2 +- setup.py | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 134f1415..1f3514d6 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Under a conda environment with Python 3.8+ it is simply installed via PyPI by do This section describes how to couple Xwakes to IW2D using the executables obtained compiling the C++ code. When the Python interface of IW2D will be completed this will not be needed anymore. -To begin with, a some folders need to be created in the user's home directory. +To begin with, some folders need to be created in the user's home directory. This can be automatically done by running the following command after Xwakes is installed: ``` python -c 'import xwakes; xwakes.initialize_pywit_directory()' diff --git a/setup.py b/setup.py index 01ab50e7..b8952221 100644 --- a/setup.py +++ b/setup.py @@ -25,14 +25,16 @@ setup( name='xwakes', version=__version__, - description='Wakefield and impedance toolbox for Xsuite', - long_description='Wakefield and impedance toolbox for Xsuite', + description='Wake and impedance toolbox', + long_description='Toolbox to build and manipulate impedance and wake' + ' function models, usable in Xsuite, DELPHI and others', url='https://xsuite.web.cern.ch/', - author='G. Iadarola et al.', + author='M. Rognlien, L. Giacomel, D. Amorim, E. Vik, G. Iadarola ' + 'and N. Mounet', license='Apache 2.0', download_url="https://pypi.python.org/pypi/xwakes", project_urls={ - "Bug Tracker": "https://github.com/xsuite/xsuite/issues", + "Bug Tracker": "https://github.com/xsuite/xwakes/issues", "Source Code": "https://github.com/xsuite/xwakes/", }, packages=find_packages(), From 122ba3960537d07ae2643541d5d8c547d44acc1e Mon Sep 17 00:00:00 2001 From: nimounet Date: Fri, 21 Jun 2024 09:48:52 +0200 Subject: [PATCH 22/26] Improving (speed-up) mix_fine_and_rough_sampling implementatoin in component.py --- xwakes/wit/component.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/xwakes/wit/component.py b/xwakes/wit/component.py index 89704089..8da79d90 100644 --- a/xwakes/wit/component.py +++ b/xwakes/wit/component.py @@ -26,11 +26,10 @@ def mix_fine_and_rough_sampling(start: float, stop: float, rough_points: int, intervals = [np.linspace(max(i, start), min(f, stop), fine_points) for i, f in rois if (start <= i <= stop or start <= f <= stop)] - fine_sampling_rois = np.hstack(intervals) if intervals else np.array([]) rough_sampling = np.geomspace(start, stop, rough_points) return unique_sigfigs( - np.sort(np.concatenate((fine_sampling_rois, rough_sampling))), 7) + np.sort(np.hstack((*intervals, rough_sampling)),kind='stable'), 7) class Component: From cd0e102e126676b1ada56ae4101ff4e5300a61dd Mon Sep 17 00:00:00 2001 From: Lorenzo Giacomel Date: Fri, 21 Jun 2024 09:57:15 +0200 Subject: [PATCH 23/26] add a useful comment --- xwakes/wit/component.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/xwakes/wit/component.py b/xwakes/wit/component.py index 8da79d90..d91ea08f 100644 --- a/xwakes/wit/component.py +++ b/xwakes/wit/component.py @@ -27,7 +27,9 @@ def mix_fine_and_rough_sampling(start: float, stop: float, rough_points: int, for i, f in rois if (start <= i <= stop or start <= f <= stop)] rough_sampling = np.geomspace(start, stop, rough_points) - + # the following concatenates adds the rough points to the fine sampling and sorts + # the result. Then duplicates are removed, where two points are considered + # equal if they are within 7 significant figures of each other. return unique_sigfigs( np.sort(np.hstack((*intervals, rough_sampling)),kind='stable'), 7) From 07ff0b56102985ae2e513e8dfe6e5cfb60fe9343 Mon Sep 17 00:00:00 2001 From: Lorenzo Giacomel Date: Fri, 21 Jun 2024 09:57:36 +0200 Subject: [PATCH 24/26] add tests for mix_fine_and_rough_sampling --- tests/test_component.py | 58 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/tests/test_component.py b/tests/test_component.py index da01f651..adb1786b 100644 --- a/tests/test_component.py +++ b/tests/test_component.py @@ -1,4 +1,5 @@ -from pywit.component import Component +from pywit.component import (Component, + mix_fine_and_rough_sampling) from test_common import functions from pywit.parameters import * @@ -10,6 +11,61 @@ import numpy as np +def test_mix_fine_and_rough_sampling_no_rois(): + start = 1 + stop = 10 + rough_points = 10 + assert np.allclose( + np.geomspace(start, stop, rough_points), + mix_fine_and_rough_sampling(start=start, + stop=stop, + rough_points=rough_points, + fine_points=0, + rois=[])) + +def test_mix_fine_and_rough_sampling_with_rois_no_overlap(): + start = 1 + stop = 10 + rough_points = 10 + fine_points = 100 + # here there is no overlap between the rois and the rough points + # so all the values in the rois should be included in the total array + rois = [(5.1, 5.9), (6.1, 6.9)] + target_val = np.sort( + np.concatenate((np.geomspace(start, stop, rough_points), + np.linspace(rois[0][0], rois[0][1], fine_points), + np.linspace(rois[1][0], rois[1][1], fine_points)))) + assert np.allclose( + target_val, + mix_fine_and_rough_sampling(start=start, + stop=stop, + rough_points=rough_points, + fine_points=fine_points, + rois=rois)) + +def test_mix_fine_and_rough_sampling_with_rois_with_overlap(): + start = 1 + stop = 10 + rough_points = 10 + fine_points = 100 + rough_points_arr = np.geomspace(start, stop, rough_points) + # in the first ROI the extrema overlap with two vales in the rough_points + # up to the 7th significant digit so they should not appear in the total array + rois = [(rough_points_arr[4] + 1e-7, + rough_points_arr[5] + 1e-7), + (6.1, 6.9)] + target_val = np.sort( + np.concatenate((rough_points_arr, + np.linspace(rois[0][0], rois[0][1], fine_points)[1:-1], + np.linspace(rois[1][0], rois[1][1], fine_points)))) + assert np.allclose( + target_val, + mix_fine_and_rough_sampling(start=start, + stop=stop, + rough_points=rough_points, + fine_points=fine_points, + rois=rois)) + def simple_component_from_rois(f_rois=None, t_rois=None): return Component(impedance=lambda f: f+1j*f, wake=lambda z: z, plane='z', source_exponents=(0, 0), From a4344d173341d46acdc10e72594a963507c4577b Mon Sep 17 00:00:00 2001 From: Lorenzo Giacomel Date: Fri, 21 Jun 2024 10:30:27 +0200 Subject: [PATCH 25/26] switch to skipif --- tests/test_interface.py | 47 ++++++++++------------------------------- 1 file changed, 11 insertions(+), 36 deletions(-) diff --git a/tests/test_interface.py b/tests/test_interface.py index 93a99c45..2c18ea14 100644 --- a/tests/test_interface.py +++ b/tests/test_interface.py @@ -17,6 +17,11 @@ CURR_DIR = Path(__file__).resolve().parent +try: + import IW2D + iw2d_installed = True +except ImportError: + iw2d_installed = False @mark.parametrize('is_impedance, plane, exponents, expected_comp_name', [[True, 'z', (0, 0, 0, 0), 'zlong'], @@ -41,13 +46,8 @@ def test_get_component_name_raise(is_impedance, plane, exponents): " the values of component_names dictionary" +@pytest.mark.skipif(not iw2d_installed, reason="IW2D is not installed") def test_duplicate_component_iw2d_import(): - - try: - import IW2D - except ImportError: - pytest.skip("IW2D is not installed") - with raises(AssertionError) as error_message: import_data_iw2d(directory=CURR_DIR / "test_data/iw2d/duplicate_components", common_string="WLHC_2layersup_0layersdown6.50mm") @@ -61,13 +61,8 @@ def test_duplicate_component_iw2d_import(): ] +@pytest.mark.skipif(not iw2d_installed, reason="IW2D is not installed") def test_no_matching_filename_iw2d_import(): - - try: - import IW2D - except ImportError: - pytest.skip("IW2D is not installed") - test_dir = CURR_DIR / "test_data/iw2d/valid_directory" with raises(AssertionError) as error_message: @@ -81,13 +76,8 @@ def test_no_matching_filename_iw2d_import(): assert error_message.value.args[0] == expected_error_message +@pytest.mark.skipif(not iw2d_installed, reason="IW2D is not installed") def test_valid_iw2d_component_import(): - - try: - import IW2D - except ImportError: - pytest.skip("IW2D is not installed") - # Normally, the relativistic gamma would be an attribute of a required IW2DInput object, but here it has been # hard-coded instead relativstic_gamma = 479.605064966 @@ -137,13 +127,8 @@ def _remove_non_empty_directory(directory_path: Path): ({'chamber_type': 'round', 'wake_computation': True}, ['Zlong', 'Zxdip', 'Zydip', 'Zxquad', 'Zyquad', 'Wlong', 'Wxdip', 'Wydip', 'Wxquad', 'Wyquad']), ({'chamber_type': 'flat', 'wake_computation': True}, ['Zlong', 'Zxdip', 'Zydip', 'Zxquad', 'Zyquad', 'Zycst', 'Wlong', 'Wxdip', 'Wydip', 'Wxquad', 'Wyquad', 'Wycst'])] @pytest.mark.parametrize("iw2d_input, components_to_test", list_of_inputs_to_test, indirect=["iw2d_input"]) +@pytest.mark.skipif(not iw2d_installed, reason="IW2D is not installed") def test_check_already_computed(iw2d_input, components_to_test): - - try: - import IW2D - except ImportError: - pytest.skip("IW2D is not installed") - name = 'test_hash' # create the expected directories for the dummy input @@ -191,13 +176,8 @@ def test_check_already_computed(iw2d_input, components_to_test): @pytest.mark.parametrize("iw2d_input", [{'chamber_type': 'round', 'wake_computation': False}], indirect=["iw2d_input"]) +@pytest.mark.skipif(not iw2d_installed, reason="IW2D is not installed") def test_add_iw2d_input_to_database(iw2d_input): - - try: - import IW2D - except ImportError: - pytest.skip("IW2D is not installed") - projects_path = Path(get_iw2d_config_value('project_directory')) input_hash = sha256(iw2d_input.__str__().encode()).hexdigest() directory_level_1 = projects_path.joinpath(input_hash[0:2]) @@ -218,13 +198,8 @@ def test_add_iw2d_input_to_database(iw2d_input): os.rmdir(directory_level_1) +@pytest.mark.skipif(not iw2d_installed, reason="IW2D is not installed") def test_check_valid_working_directory(): - - try: - import IW2D - except ImportError: - pytest.skip("IW2D is not installed") - projects_path = Path(get_iw2d_config_value('project_directory')) working_directory = projects_path.joinpath(Path("a/wrong/working_directory")) From 8b447cf3bda72e7fd393ee7ea8b0f33ec8387e0e Mon Sep 17 00:00:00 2001 From: giadarol Date: Fri, 21 Jun 2024 13:53:46 +0200 Subject: [PATCH 26/26] Rename and comment --- pywit/{doit.py => _generate_modules.py} | 4 ++++ 1 file changed, 4 insertions(+) rename pywit/{doit.py => _generate_modules.py} (76%) diff --git a/pywit/doit.py b/pywit/_generate_modules.py similarity index 76% rename from pywit/doit.py rename to pywit/_generate_modules.py index 025dff46..4c095198 100644 --- a/pywit/doit.py +++ b/pywit/_generate_modules.py @@ -1,3 +1,7 @@ +''' +generate files to mirror in pywit the modules from xwakes.wit +''' + import os fff = os.listdir('../xwakes/wit')