From 120b11a5e986dd2323f5a69097df80f4d2e2d130 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20F=2E=20Esteban=20Mu=CC=88ller?= Date: Mon, 18 Mar 2024 14:38:59 +0100 Subject: [PATCH 01/12] fixing matching routines to work with RF cavities --- py/orbit/matrix_lattice/MATRIX_Lattice.py | 36 +++++++++++------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/py/orbit/matrix_lattice/MATRIX_Lattice.py b/py/orbit/matrix_lattice/MATRIX_Lattice.py index 77818436..22380391 100644 --- a/py/orbit/matrix_lattice/MATRIX_Lattice.py +++ b/py/orbit/matrix_lattice/MATRIX_Lattice.py @@ -231,26 +231,26 @@ def trackTwissData(self, alpha, beta, direction="x"): alpha_arr.append(track_v.get(0)) beta_arr.append(track_v.get(1)) for matrixNode in self.getNodes(): - mt = matrixNode.getMatrix() - ind0 = 0 + dir_ind - ind1 = 1 + dir_ind - track_m.set(0, 0, mt.get(ind0, ind0) * mt.get(ind1, ind1) + mt.get(ind0, ind1) * mt.get(ind1, ind0)) - track_m.set(0, 1, -mt.get(ind0, ind0) * mt.get(ind1, ind0)) - track_m.set(0, 2, -mt.get(ind0, ind1) * mt.get(ind1, ind1)) - track_m.set(1, 0, -2 * mt.get(ind0, ind0) * mt.get(ind0, ind1)) - track_m.set(1, 1, mt.get(ind0, ind0) * mt.get(ind0, ind0)) - track_m.set(1, 2, mt.get(ind0, ind1) * mt.get(ind0, ind1)) - track_m.set(2, 0, -2 * mt.get(ind1, ind0) * mt.get(ind1, ind1)) - track_m.set(2, 1, mt.get(ind1, ind0) * mt.get(ind1, ind0)) - track_m.set(2, 2, mt.get(ind1, ind1) * mt.get(ind1, ind1)) - alpha_0 = track_v.get(0) - beta_0 = track_v.get(1) - delta_phi = math.atan(mt.get(ind0, ind1) / (beta_0 * mt.get(ind0, ind0) - alpha_0 * mt.get(ind0, ind1))) - phi = phi + delta_phi - track_v = track_m.mult(track_v) - position = position + matrixNode.getLength() if isinstance(matrixNode, BaseMATRIX) == True: # only the main nodes are used, the or-cases deal with markers with zero length + mt = matrixNode.getMatrix() + ind0 = 0 + dir_ind + ind1 = 1 + dir_ind + track_m.set(0, 0, mt.get(ind0, ind0) * mt.get(ind1, ind1) + mt.get(ind0, ind1) * mt.get(ind1, ind0)) + track_m.set(0, 1, -mt.get(ind0, ind0) * mt.get(ind1, ind0)) + track_m.set(0, 2, -mt.get(ind0, ind1) * mt.get(ind1, ind1)) + track_m.set(1, 0, -2 * mt.get(ind0, ind0) * mt.get(ind0, ind1)) + track_m.set(1, 1, mt.get(ind0, ind0) * mt.get(ind0, ind0)) + track_m.set(1, 2, mt.get(ind0, ind1) * mt.get(ind0, ind1)) + track_m.set(2, 0, -2 * mt.get(ind1, ind0) * mt.get(ind1, ind1)) + track_m.set(2, 1, mt.get(ind1, ind0) * mt.get(ind1, ind0)) + track_m.set(2, 2, mt.get(ind1, ind1) * mt.get(ind1, ind1)) + alpha_0 = track_v.get(0) + beta_0 = track_v.get(1) + delta_phi = math.atan(mt.get(ind0, ind1) / (beta_0 * mt.get(ind0, ind0) - alpha_0 * mt.get(ind0, ind1))) + phi = phi + delta_phi + track_v = track_m.mult(track_v) + position = position + matrixNode.getLength() # print position, matrixNode.getParam("matrix_parent_node_active_index") == 1 # print position, matrixNode.getName(), track_v.get(1) From f6924d6b0ff3bdd98513c7613790eb0533d8b51c Mon Sep 17 00:00:00 2001 From: "Zhukov, Alexander P" Date: Sun, 31 Mar 2024 14:56:35 -0400 Subject: [PATCH 02/12] Initial meson commit --- examples/meson/test_imports.py | 18 + examples/meson/uspas_test.py | 159 +++++++ meson-scripts/gen_cc_build.py | 50 +++ meson-scripts/generate_py_build.py | 34 ++ meson.build | 3 + py/meson.build | 3 + py/orbit/aperture/meson.build | 15 + py/orbit/bumps/meson.build | 15 + py/orbit/bunch_generators/meson.build | 13 + py/orbit/bunch_utils/meson.build | 13 + py/orbit/collimation/meson.build | 14 + py/orbit/diagnostics/meson.build | 16 + py/orbit/errors/meson.build | 14 + py/orbit/fieldtracker/meson.build | 14 + py/orbit/foils/meson.build | 14 + py/orbit/impedances/meson.build | 14 + py/orbit/injection/meson.build | 17 + py/orbit/kickernodes/meson.build | 16 + py/orbit/lattice/meson.build | 16 + py/orbit/matching/meson.build | 13 + py/orbit/matrix_lattice/meson.build | 14 + py/orbit/meson.build | 36 ++ py/orbit/orbit_correction/meson.build | 13 + py/orbit/parsers/meson.build | 16 + py/orbit/py_linac/errors/meson.build | 13 + py/orbit/py_linac/lattice/meson.build | 20 + .../lattice_modifications/meson.build | 18 + py/orbit/py_linac/linac_parsers/meson.build | 14 + py/orbit/py_linac/materials/meson.build | 13 + py/orbit/py_linac/meson.build | 20 + .../py_linac/orbit_correction/meson.build | 13 + .../py_linac/overlapping_fields/meson.build | 15 + .../py_linac/rf_field_readers/meson.build | 14 + py/orbit/rf_cavities/meson.build | 14 + .../space_charge/directforce2p5d/meson.build | 14 + py/orbit/space_charge/meson.build | 20 + py/orbit/space_charge/sc1d/meson.build | 14 + .../space_charge/sc2dslicebyslice/meson.build | 14 + py/orbit/space_charge/sc2p5d/meson.build | 14 + py/orbit/space_charge/sc3d/meson.build | 14 + py/orbit/teapot/meson.build | 14 + py/orbit/teapot_base/meson.build | 12 + py/orbit/time_dep/meson.build | 14 + py/orbit/utils/fitting/meson.build | 18 + py/orbit/utils/meson.build | 22 + py/orbit/utils/orbit_mpi_utils/meson.build | 16 + py/orbit/utils/xml/meson.build | 13 + pyproject.toml | 17 +- setup.py | 80 ---- src/core/aperture_init.cc | 4 + src/core/bunch_init.cc | 4 + src/core/collimator_init.cc | 4 + src/core/error_base_init.cc | 5 + src/core/field_sources_init.cc | 4 + src/core/fieldtracker_init.cc | 4 + src/core/foil_init.cc | 4 + src/core/impedances_init.cc | 4 + src/core/linac_init.cc | 4 + src/core/mpi_init.cc | 6 + src/core/rfcavities_init.cc | 4 + src/core/spacecharge_init.cc | 4 + src/core/teapot_base_init.cc | 8 + src/core/trackerrk4_init.cc | 4 + src/core/utils_init.cc | 4 + src/meson.build | 410 ++++++++++++++++++ src/orbit/wrap_bunch.cc | 6 +- 66 files changed, 1394 insertions(+), 89 deletions(-) create mode 100644 examples/meson/test_imports.py create mode 100644 examples/meson/uspas_test.py create mode 100644 meson-scripts/gen_cc_build.py create mode 100644 meson-scripts/generate_py_build.py create mode 100644 meson.build create mode 100644 py/meson.build create mode 100644 py/orbit/aperture/meson.build create mode 100644 py/orbit/bumps/meson.build create mode 100644 py/orbit/bunch_generators/meson.build create mode 100644 py/orbit/bunch_utils/meson.build create mode 100644 py/orbit/collimation/meson.build create mode 100644 py/orbit/diagnostics/meson.build create mode 100644 py/orbit/errors/meson.build create mode 100644 py/orbit/fieldtracker/meson.build create mode 100644 py/orbit/foils/meson.build create mode 100644 py/orbit/impedances/meson.build create mode 100644 py/orbit/injection/meson.build create mode 100644 py/orbit/kickernodes/meson.build create mode 100644 py/orbit/lattice/meson.build create mode 100644 py/orbit/matching/meson.build create mode 100644 py/orbit/matrix_lattice/meson.build create mode 100644 py/orbit/meson.build create mode 100644 py/orbit/orbit_correction/meson.build create mode 100644 py/orbit/parsers/meson.build create mode 100644 py/orbit/py_linac/errors/meson.build create mode 100644 py/orbit/py_linac/lattice/meson.build create mode 100644 py/orbit/py_linac/lattice_modifications/meson.build create mode 100644 py/orbit/py_linac/linac_parsers/meson.build create mode 100644 py/orbit/py_linac/materials/meson.build create mode 100644 py/orbit/py_linac/meson.build create mode 100644 py/orbit/py_linac/orbit_correction/meson.build create mode 100644 py/orbit/py_linac/overlapping_fields/meson.build create mode 100644 py/orbit/py_linac/rf_field_readers/meson.build create mode 100644 py/orbit/rf_cavities/meson.build create mode 100644 py/orbit/space_charge/directforce2p5d/meson.build create mode 100644 py/orbit/space_charge/meson.build create mode 100644 py/orbit/space_charge/sc1d/meson.build create mode 100644 py/orbit/space_charge/sc2dslicebyslice/meson.build create mode 100644 py/orbit/space_charge/sc2p5d/meson.build create mode 100644 py/orbit/space_charge/sc3d/meson.build create mode 100644 py/orbit/teapot/meson.build create mode 100644 py/orbit/teapot_base/meson.build create mode 100644 py/orbit/time_dep/meson.build create mode 100644 py/orbit/utils/fitting/meson.build create mode 100644 py/orbit/utils/meson.build create mode 100644 py/orbit/utils/orbit_mpi_utils/meson.build create mode 100644 py/orbit/utils/xml/meson.build delete mode 100644 setup.py create mode 100644 src/core/aperture_init.cc create mode 100644 src/core/bunch_init.cc create mode 100644 src/core/collimator_init.cc create mode 100644 src/core/error_base_init.cc create mode 100644 src/core/field_sources_init.cc create mode 100644 src/core/fieldtracker_init.cc create mode 100644 src/core/foil_init.cc create mode 100644 src/core/impedances_init.cc create mode 100644 src/core/linac_init.cc create mode 100644 src/core/mpi_init.cc create mode 100644 src/core/rfcavities_init.cc create mode 100644 src/core/spacecharge_init.cc create mode 100644 src/core/teapot_base_init.cc create mode 100644 src/core/trackerrk4_init.cc create mode 100644 src/core/utils_init.cc create mode 100644 src/meson.build diff --git a/examples/meson/test_imports.py b/examples/meson/test_imports.py new file mode 100644 index 00000000..cbc8405d --- /dev/null +++ b/examples/meson/test_imports.py @@ -0,0 +1,18 @@ +import orbit.core.orbit_mpi +import orbit.core.spacecharge +import orbit.core.trackerrk4 +import orbit.core.teapot_base +import orbit.core.linac +import orbit.core.orbit_utils +import orbit.core.aperture +import orbit.core.foil +import orbit.core.field_sources +import orbit.core.rfcavities +import orbit.core.impedances +import orbit.core.fieldtracker +import orbit.core.collimator +import orbit.core.error_base + +from orbit.core.bunch import Bunch +b = Bunch() +print(b) \ No newline at end of file diff --git a/examples/meson/uspas_test.py b/examples/meson/uspas_test.py new file mode 100644 index 00000000..755e18d6 --- /dev/null +++ b/examples/meson/uspas_test.py @@ -0,0 +1,159 @@ +# This script runs through how to build a lattice, build a bunch, and how to track it. + +import numpy as np +from matplotlib import pyplot as plt + +# Import Bunch to be able to build a bunch. +from orbit.core.bunch import Bunch + +# Import LinacAccLattice to build a lattice and Sequence to build a sequence that we can then import into the lattice. +from orbit.py_linac.lattice.LinacAccLatticeLib import LinacAccLattice, Sequence + +# Import Quad and Drift components to build the lattice. +from orbit.py_linac.lattice.LinacAccNodes import Quad, Drift + +# Import AccActionsContainer, a method to add functionality throughout the accelerator. +from orbit.lattice import AccActionsContainer + +# Field strength and length of the quadrupoles +field_str = 1.8 +quad_len = 0.2 + +# Lengths of the interior and exterior drifts. +drift_end_len = 0.4 +drift_len = 0.8 + +# List to contain the drift and quadrupole nodes. +list_of_nodes = [] + +# What follows is defining each node of the lattice. +# The first drift node (needs a specified length) +D1 = Drift("Drift1") +D1.setLength(drift_end_len) +list_of_nodes.append(D1) + +# The first quadrupole node (needs a specified field gradient strength and length) +Q1 = Quad("Quad1") +Q1.setLength(quad_len) +Q1.setField(field_str) +list_of_nodes.append(Q1) + +# The second drift node +D2 = Drift("Drift2") +D2.setLength(drift_len) +list_of_nodes.append(D2) + +# The second quadrupole node +Q2 = Quad("Quad2") +Q2.setLength(quad_len) +Q2.setField(-field_str) +list_of_nodes.append(Q2) + +# The third drift node +D3 = Drift("Drift3") +D3.setLength(drift_len) +list_of_nodes.append(D3) + +# The third quadrupole node +Q3 = Quad("Quad3") +Q3.setLength(quad_len) +Q3.setField(field_str) +list_of_nodes.append(Q3) + +# The fourth drift node +D4 = Drift("Drift4") +D4.setLength(drift_len) +list_of_nodes.append(D4) + +# The fourth quadrupole node +Q4 = Quad("Quad4") +Q4.setLength(quad_len) +Q4.setField(-field_str) +list_of_nodes.append(Q4) + +# The fifth drift node +D5 = Drift("Drift5") +D5.setLength(drift_end_len) +list_of_nodes.append(D5) + +# Define the sequence and add the list of nodes to the sequence. +fodo = Sequence('FODO') +fodo.setNodes(list_of_nodes) + +# Define the lattice, add the list of nodes to the lattice, and initialize the lattice. +my_lattice = LinacAccLattice('My Lattice') +my_lattice.setNodes(list_of_nodes) +my_lattice.initialize() +print("Total length=", my_lattice.getLength()) + +# Define the bunch and it's kinetic energy. +bunch = Bunch() +bunch.getSyncParticle().kinEnergy(0.0025) # GeV + +# Add macroparticles to the bunch. +bunch.addParticle(0.00, 0.002, -0.001, 0.001, 0.0, 0.0) +bunch.addParticle(0.001, 0.000, 0.001, -0.001, 0.0, 0.0) +bunch.addParticle(-0.001, -0.002, 0.001, -0.001, 0.0, 0.0) +for i in range(100000): + bunch.addParticle(-0.001, -0.002, 0.001, -0.001, 0.0, 0.0) + +# Setup RF cavities (if we had any). +my_lattice.trackDesignBunch(bunch) + +# Prepare variables for use in our track action. We have an array of the position along the linac and an array of x +# positions. +pos_array = [] +x_array = [] + +# Create a parameter dictionary to pass to our track action. +my_params = {"old_pos": -1.0} + + +# Action function to track the horizontal position of the particle through the lattice. This will be used at the +# entrance of each node. +def action_entrance(paramsDict): + # Grab values from the parameter dictionary. + node = paramsDict["node"] + bunch = paramsDict["bunch"] + pos = paramsDict["path_length"] + + # Don't continue if current node has the same position as the previous node. + if pos <= paramsDict["old_pos"]: + return + + # Replace the old_pos value with the current nodes position, then add the position to out position array. + paramsDict["old_pos"] = pos + pos_array.append(pos) + + # Loop through the particles and add their x positions to a list, then add that list to our x_array. + nParts = bunch.getSizeGlobal() + x_temp = [] + for n in range(nParts): + x = bunch.x(n) * 1000 # [mm] + x_temp.append(x) + x_array.append(x_temp) + + +# Use the same function for an action that will take place at the exit of each node. +def action_exit(paramsDict): + action_entrance(paramsDict) + + +# Define your action container and add your actions. One action is added to the entrance of each node, the other to the +# exit of each node. +my_container = AccActionsContainer("Test Bunch Tracking") +my_container.addAction(action_entrance, AccActionsContainer.ENTRANCE) +my_container.addAction(action_exit, AccActionsContainer.EXIT) + +# Track the bunch through the lattice. We are also passing our parameter dictionary and action container. +my_lattice.trackBunch(bunch, paramsDict=my_params, actionContainer=my_container) + +# Convert x_array into a numpy array. Then loop through each particle to plot their positions through the lattice. +x_array = np.array(x_array) +num_of_parts = bunch.getSizeGlobal() +for n in range(3): + plt.plot(pos_array, x_array[:, n], label='Particle ' + str(n+1)) +plt.xlabel('Lattice position [m]') +plt.ylabel('Horizontal Position [mm]') +plt.legend() +plt.show() \ No newline at end of file diff --git a/meson-scripts/gen_cc_build.py b/meson-scripts/gen_cc_build.py new file mode 100644 index 00000000..117a09a0 --- /dev/null +++ b/meson-scripts/gen_cc_build.py @@ -0,0 +1,50 @@ +# This file is outdated, left here for reference. + +from pathlib import Path + +sources = Path(__file__).parent.parent.parent / 'src' +base_src = '../../src/' + +files = [] +headers = set() + +headers.add('main') +headers.add('utils/ellipticalint') + +for file_path in sources.glob('**/*.cc'): + f = file_path.relative_to(sources) + files.append(str(f)) + headers.add(str(f.parent)) + +files_merged = f"',\n\t'{base_src}".join(files) +headers_merged = f"',\n\t'{base_src}".join(headers) + +buffer = \ +f""" +sources = files([ + '{base_src}{files_merged}' +]) +headers = include_directories([ + '{base_src}{headers_merged}' + +]) + +inc += headers + +core_lib = library('core', + sources: sources, + include_directories: inc, + cpp_args: ['-fPIC', '-std=c++11'], + install: false, + +) + +core_dep = declare_dependency(link_with : core_lib) + +""" + + +print(buffer) + + + diff --git a/meson-scripts/generate_py_build.py b/meson-scripts/generate_py_build.py new file mode 100644 index 00000000..87836f2e --- /dev/null +++ b/meson-scripts/generate_py_build.py @@ -0,0 +1,34 @@ +import os + +from pathlib import Path +from queue import Queue + +root = Path('py') +f_q = Queue[Path]() +f_q.put(root) + +src_split = ',\n\t' +while not f_q.empty(): + path = f_q.get() + pys = [f"'{p.name}'" for p in path.iterdir() if p.is_file() and p.name.endswith('.py')] + sub = [p for p in path.iterdir() if p.is_dir()] + subdirs = [f"subdir('{p.name}')\n" for p in sub] + [f_q.put(p) for p in sub] + contents = f""" +{''.join(subdirs)} +""" + if pys: + contents += f""" +py_sources = files([ + {src_split.join(pys)} +]) + +python.install_sources( + py_sources, + subdir: '{path.relative_to(root)}', + # pure: true, +) +""" + print(contents) + with open(path / 'meson.build', 'w') as f: + f.write(contents) diff --git a/meson.build b/meson.build new file mode 100644 index 00000000..141151a6 --- /dev/null +++ b/meson.build @@ -0,0 +1,3 @@ +project('orbit', ['cpp'], version: '0.0.1') +subdir('src') +subdir('py/orbit') \ No newline at end of file diff --git a/py/meson.build b/py/meson.build new file mode 100644 index 00000000..ac635a91 --- /dev/null +++ b/py/meson.build @@ -0,0 +1,3 @@ + +subdir('orbit') + diff --git a/py/orbit/aperture/meson.build b/py/orbit/aperture/meson.build new file mode 100644 index 00000000..52caf1bc --- /dev/null +++ b/py/orbit/aperture/meson.build @@ -0,0 +1,15 @@ + + + +py_sources = files([ + 'TeapotApertureNode.py', + 'ApertureLatticeModifications.py', + '__init__.py', + 'ApertureLatticeRangeModifications.py' +]) + +python.install_sources( + py_sources, + subdir: 'orbit/aperture', + # pure: true, +) diff --git a/py/orbit/bumps/meson.build b/py/orbit/bumps/meson.build new file mode 100644 index 00000000..611afbf1 --- /dev/null +++ b/py/orbit/bumps/meson.build @@ -0,0 +1,15 @@ + + + +py_sources = files([ + 'bumps.py', + 'TeapotBumpNode.py', + '__init__.py', + 'BumpLatticeModifications.py' +]) + +python.install_sources( + py_sources, + subdir: 'orbit/bumps', + # pure: true, +) diff --git a/py/orbit/bunch_generators/meson.build b/py/orbit/bunch_generators/meson.build new file mode 100644 index 00000000..d4f91926 --- /dev/null +++ b/py/orbit/bunch_generators/meson.build @@ -0,0 +1,13 @@ + + + +py_sources = files([ + '__init__.py', + 'distribution_generators.py' +]) + +python.install_sources( + py_sources, + subdir: 'orbit/bunch_generators', + # pure: true, +) diff --git a/py/orbit/bunch_utils/meson.build b/py/orbit/bunch_utils/meson.build new file mode 100644 index 00000000..fc1531cc --- /dev/null +++ b/py/orbit/bunch_utils/meson.build @@ -0,0 +1,13 @@ + + + +py_sources = files([ + '__init__.py', + 'particleidnumber.py' +]) + +python.install_sources( + py_sources, + subdir: 'orbit/bunch_utils', + # pure: true, +) diff --git a/py/orbit/collimation/meson.build b/py/orbit/collimation/meson.build new file mode 100644 index 00000000..2250f973 --- /dev/null +++ b/py/orbit/collimation/meson.build @@ -0,0 +1,14 @@ + + + +py_sources = files([ + 'TeapotCollimatorNode.py', + '__init__.py', + 'collimationLatticeModifications.py' +]) + +python.install_sources( + py_sources, + subdir: 'orbit/collimation', + # pure: true, +) diff --git a/py/orbit/diagnostics/meson.build b/py/orbit/diagnostics/meson.build new file mode 100644 index 00000000..26e40c8e --- /dev/null +++ b/py/orbit/diagnostics/meson.build @@ -0,0 +1,16 @@ + + + +py_sources = files([ + 'diagnostics.py', + 'TeapotDiagnosticsNode.py', + 'diagnosticsLatticeModifications.py', + '__init__.py', + 'profiles.py' +]) + +python.install_sources( + py_sources, + subdir: 'orbit/diagnostics', + # pure: true, +) diff --git a/py/orbit/errors/meson.build b/py/orbit/errors/meson.build new file mode 100644 index 00000000..ba75515b --- /dev/null +++ b/py/orbit/errors/meson.build @@ -0,0 +1,14 @@ + + + +py_sources = files([ + 'ErrorLatticeModifications.py', + 'ErrorNode.py', + '__init__.py' +]) + +python.install_sources( + py_sources, + subdir: 'orbit/errors', + # pure: true, +) diff --git a/py/orbit/fieldtracker/meson.build b/py/orbit/fieldtracker/meson.build new file mode 100644 index 00000000..e8298b16 --- /dev/null +++ b/py/orbit/fieldtracker/meson.build @@ -0,0 +1,14 @@ + + + +py_sources = files([ + 'TeapotFieldTrackerNode.py', + '__init__.py', + 'TeapotFieldLatticeModifications.py' +]) + +python.install_sources( + py_sources, + subdir: 'orbit/fieldtracker', + # pure: true, +) diff --git a/py/orbit/foils/meson.build b/py/orbit/foils/meson.build new file mode 100644 index 00000000..61de5ad6 --- /dev/null +++ b/py/orbit/foils/meson.build @@ -0,0 +1,14 @@ + + + +py_sources = files([ + 'foilLatticeModifications.py', + '__init__.py', + 'TeapotFoilNode.py' +]) + +python.install_sources( + py_sources, + subdir: 'orbit/foils', + # pure: true, +) diff --git a/py/orbit/impedances/meson.build b/py/orbit/impedances/meson.build new file mode 100644 index 00000000..20d3e446 --- /dev/null +++ b/py/orbit/impedances/meson.build @@ -0,0 +1,14 @@ + + + +py_sources = files([ + 'ImpedanceNode.py', + 'ImpedanceLatticeModifications.py', + '__init__.py' +]) + +python.install_sources( + py_sources, + subdir: 'orbit/impedances', + # pure: true, +) diff --git a/py/orbit/injection/meson.build b/py/orbit/injection/meson.build new file mode 100644 index 00000000..b078dc38 --- /dev/null +++ b/py/orbit/injection/meson.build @@ -0,0 +1,17 @@ + + + +py_sources = files([ + 'joho.py', + '__init__.py', + 'injectparticles.py', + 'distributions.py', + 'TeapotInjectionNode.py', + 'InjectionLatticeModifications.py' +]) + +python.install_sources( + py_sources, + subdir: 'orbit/injection', + # pure: true, +) diff --git a/py/orbit/kickernodes/meson.build b/py/orbit/kickernodes/meson.build new file mode 100644 index 00000000..440b2130 --- /dev/null +++ b/py/orbit/kickernodes/meson.build @@ -0,0 +1,16 @@ + + + +py_sources = files([ + 'waveforms.py', + 'KickerLatticeModifications.py', + '__init__.py', + 'kicker.py', + 'TeapotKickerNode.py' +]) + +python.install_sources( + py_sources, + subdir: 'orbit/kickernodes', + # pure: true, +) diff --git a/py/orbit/lattice/meson.build b/py/orbit/lattice/meson.build new file mode 100644 index 00000000..e368f5c3 --- /dev/null +++ b/py/orbit/lattice/meson.build @@ -0,0 +1,16 @@ + + + +py_sources = files([ + 'AccNodeBunchTracker.py', + 'AccNode.py', + '__init__.py', + 'AccLattice.py', + 'AccActionsContainer.py' +]) + +python.install_sources( + py_sources, + subdir: 'orbit/lattice', + # pure: true, +) diff --git a/py/orbit/matching/meson.build b/py/orbit/matching/meson.build new file mode 100644 index 00000000..cee49c55 --- /dev/null +++ b/py/orbit/matching/meson.build @@ -0,0 +1,13 @@ + + + +py_sources = files([ + '__init__.py', + 'matching.py' +]) + +python.install_sources( + py_sources, + subdir: 'orbit/matching', + # pure: true, +) diff --git a/py/orbit/matrix_lattice/meson.build b/py/orbit/matrix_lattice/meson.build new file mode 100644 index 00000000..ed29e83e --- /dev/null +++ b/py/orbit/matrix_lattice/meson.build @@ -0,0 +1,14 @@ + + + +py_sources = files([ + 'MATRIX_Lattice.py', + '__init__.py', + 'BaseMATRIX.py' +]) + +python.install_sources( + py_sources, + subdir: 'orbit/matrix_lattice', + # pure: true, +) diff --git a/py/orbit/meson.build b/py/orbit/meson.build new file mode 100644 index 00000000..6971bdc5 --- /dev/null +++ b/py/orbit/meson.build @@ -0,0 +1,36 @@ + +subdir('bumps') +subdir('matching') +subdir('time_dep') +subdir('bunch_utils') +subdir('parsers') +subdir('fieldtracker') +subdir('teapot_base') +subdir('bunch_generators') +subdir('utils') +subdir('impedances') +subdir('lattice') +subdir('rf_cavities') +subdir('injection') +subdir('aperture') +subdir('py_linac') +subdir('kickernodes') +subdir('orbit_correction') +subdir('diagnostics') +subdir('collimation') +subdir('foils') +subdir('space_charge') +subdir('errors') +subdir('matrix_lattice') +subdir('teapot') + + +py_sources = files([ + '__init__.py' +]) + +python.install_sources( + py_sources, + subdir: 'orbit', + # pure: true, +) diff --git a/py/orbit/orbit_correction/meson.build b/py/orbit/orbit_correction/meson.build new file mode 100644 index 00000000..21dd1d31 --- /dev/null +++ b/py/orbit/orbit_correction/meson.build @@ -0,0 +1,13 @@ + + + +py_sources = files([ + 'orbit_correction.py', + '__init__.py' +]) + +python.install_sources( + py_sources, + subdir: 'orbit/orbit_correction', + # pure: true, +) diff --git a/py/orbit/parsers/meson.build b/py/orbit/parsers/meson.build new file mode 100644 index 00000000..91e79f38 --- /dev/null +++ b/py/orbit/parsers/meson.build @@ -0,0 +1,16 @@ + + + +py_sources = files([ + '__init__.py', + 'mad_parser.py', + 'madx_parser.py', + 'sad_parser.py', + 'field_parser.py' +]) + +python.install_sources( + py_sources, + subdir: 'orbit/parsers', + # pure: true, +) diff --git a/py/orbit/py_linac/errors/meson.build b/py/orbit/py_linac/errors/meson.build new file mode 100644 index 00000000..30b0f50a --- /dev/null +++ b/py/orbit/py_linac/errors/meson.build @@ -0,0 +1,13 @@ + + + +py_sources = files([ + 'ErrorNodesAndControllersLib.py', + '__init__.py' +]) + +python.install_sources( + py_sources, + subdir: 'orbit/py_linac/errors', + # pure: true, +) diff --git a/py/orbit/py_linac/lattice/meson.build b/py/orbit/py_linac/lattice/meson.build new file mode 100644 index 00000000..73b44ee8 --- /dev/null +++ b/py/orbit/py_linac/lattice/meson.build @@ -0,0 +1,20 @@ + + + +py_sources = files([ + 'LinacFieldOverlappingNodes.py', + 'LinacAccLatticeLib.py', + 'LinacTransportMatrixGenNodes.py', + 'LinacAccNodes.py', + '__init__.py', + 'LinacAccLatticeFunc.py', + 'LinacApertureNodes.py', + 'LinacDiagnosticsNodes.py', + 'LinacRfGapNodes.py' +]) + +python.install_sources( + py_sources, + subdir: 'orbit/py_linac/lattice', + # pure: true, +) diff --git a/py/orbit/py_linac/lattice_modifications/meson.build b/py/orbit/py_linac/lattice_modifications/meson.build new file mode 100644 index 00000000..d4ce539c --- /dev/null +++ b/py/orbit/py_linac/lattice_modifications/meson.build @@ -0,0 +1,18 @@ + + + +py_sources = files([ + 'rf_models_modifications_lib.py', + 'apertures_additions_lib.py', + '__init__.py', + 'sns_aperture_additions.py', + 'rf_quad_overlap_modifications_lib.py', + 'quad_overlap_modifications_lib.py', + 'errors_modifications_lib.py' +]) + +python.install_sources( + py_sources, + subdir: 'orbit/py_linac/lattice_modifications', + # pure: true, +) diff --git a/py/orbit/py_linac/linac_parsers/meson.build b/py/orbit/py_linac/linac_parsers/meson.build new file mode 100644 index 00000000..6eabb8ab --- /dev/null +++ b/py/orbit/py_linac/linac_parsers/meson.build @@ -0,0 +1,14 @@ + + + +py_sources = files([ + '__init__.py', + 'sns_linac_lattice_factory.py', + 'jparc_linac_lattice_factory.py' +]) + +python.install_sources( + py_sources, + subdir: 'orbit/py_linac/linac_parsers', + # pure: true, +) diff --git a/py/orbit/py_linac/materials/meson.build b/py/orbit/py_linac/materials/meson.build new file mode 100644 index 00000000..9404b6be --- /dev/null +++ b/py/orbit/py_linac/materials/meson.build @@ -0,0 +1,13 @@ + + + +py_sources = files([ + '__init__.py', + 'VacuumWindowLinacNode.py' +]) + +python.install_sources( + py_sources, + subdir: 'orbit/py_linac/materials', + # pure: true, +) diff --git a/py/orbit/py_linac/meson.build b/py/orbit/py_linac/meson.build new file mode 100644 index 00000000..97f3eb53 --- /dev/null +++ b/py/orbit/py_linac/meson.build @@ -0,0 +1,20 @@ + +subdir('linac_parsers') +subdir('lattice_modifications') +subdir('materials') +subdir('lattice') +subdir('overlapping_fields') +subdir('orbit_correction') +subdir('errors') +subdir('rf_field_readers') + + +py_sources = files([ + '__init__.py' +]) + +python.install_sources( + py_sources, + subdir: 'orbit/py_linac', + # pure: true, +) diff --git a/py/orbit/py_linac/orbit_correction/meson.build b/py/orbit/py_linac/orbit_correction/meson.build new file mode 100644 index 00000000..7899332a --- /dev/null +++ b/py/orbit/py_linac/orbit_correction/meson.build @@ -0,0 +1,13 @@ + + + +py_sources = files([ + 'transport_lines_orbit_correction.py', + '__init__.py' +]) + +python.install_sources( + py_sources, + subdir: 'orbit/py_linac/orbit_correction', + # pure: true, +) diff --git a/py/orbit/py_linac/overlapping_fields/meson.build b/py/orbit/py_linac/overlapping_fields/meson.build new file mode 100644 index 00000000..ef0bc88d --- /dev/null +++ b/py/orbit/py_linac/overlapping_fields/meson.build @@ -0,0 +1,15 @@ + + + +py_sources = files([ + '__init__.py', + 'jparc_enge_func_factory.py', + 'sns_enge_func_factory.py', + 'overlapping_quad_fields_lib.py' +]) + +python.install_sources( + py_sources, + subdir: 'orbit/py_linac/overlapping_fields', + # pure: true, +) diff --git a/py/orbit/py_linac/rf_field_readers/meson.build b/py/orbit/py_linac/rf_field_readers/meson.build new file mode 100644 index 00000000..b2affa2e --- /dev/null +++ b/py/orbit/py_linac/rf_field_readers/meson.build @@ -0,0 +1,14 @@ + + + +py_sources = files([ + 'SuperFish_3D_RF_FieldReader.py', + '__init__.py', + 'RF_AxisFieldAnalysis.py' +]) + +python.install_sources( + py_sources, + subdir: 'orbit/py_linac/rf_field_readers', + # pure: true, +) diff --git a/py/orbit/rf_cavities/meson.build b/py/orbit/rf_cavities/meson.build new file mode 100644 index 00000000..6d87a949 --- /dev/null +++ b/py/orbit/rf_cavities/meson.build @@ -0,0 +1,14 @@ + + + +py_sources = files([ + '__init__.py', + 'RFNode.py', + 'RFLatticeModifications.py' +]) + +python.install_sources( + py_sources, + subdir: 'orbit/rf_cavities', + # pure: true, +) diff --git a/py/orbit/space_charge/directforce2p5d/meson.build b/py/orbit/space_charge/directforce2p5d/meson.build new file mode 100644 index 00000000..75554f36 --- /dev/null +++ b/py/orbit/space_charge/directforce2p5d/meson.build @@ -0,0 +1,14 @@ + + + +py_sources = files([ + '__init__.py', + 'directforceLatticeModifications.py', + 'directforceAccNodes.py' +]) + +python.install_sources( + py_sources, + subdir: 'orbit/space_charge/directforce2p5d', + # pure: true, +) diff --git a/py/orbit/space_charge/meson.build b/py/orbit/space_charge/meson.build new file mode 100644 index 00000000..8cc2720d --- /dev/null +++ b/py/orbit/space_charge/meson.build @@ -0,0 +1,20 @@ + +subdir('sc1d') +subdir('directforce2p5d') +subdir('sc2dslicebyslice') +subdir('sc3d') +subdir('sc2p5d') + + +py_sources = files([ + 'scLatticeModifications.py', + 'scAccNodes.py', + '__init__.py', + 'sccenteredLatticeModifications.py' +]) + +python.install_sources( + py_sources, + subdir: 'orbit/space_charge', + # pure: true, +) diff --git a/py/orbit/space_charge/sc1d/meson.build b/py/orbit/space_charge/sc1d/meson.build new file mode 100644 index 00000000..fcd566dd --- /dev/null +++ b/py/orbit/space_charge/sc1d/meson.build @@ -0,0 +1,14 @@ + + + +py_sources = files([ + 'scLatticeModifications.py', + '__init__.py', + 'sc1DNode.py' +]) + +python.install_sources( + py_sources, + subdir: 'orbit/space_charge/sc1d', + # pure: true, +) diff --git a/py/orbit/space_charge/sc2dslicebyslice/meson.build b/py/orbit/space_charge/sc2dslicebyslice/meson.build new file mode 100644 index 00000000..1227f3ab --- /dev/null +++ b/py/orbit/space_charge/sc2dslicebyslice/meson.build @@ -0,0 +1,14 @@ + + + +py_sources = files([ + 'scLatticeModifications.py', + 'scAccNodes.py', + '__init__.py' +]) + +python.install_sources( + py_sources, + subdir: 'orbit/space_charge/sc2dslicebyslice', + # pure: true, +) diff --git a/py/orbit/space_charge/sc2p5d/meson.build b/py/orbit/space_charge/sc2p5d/meson.build new file mode 100644 index 00000000..c828e7ce --- /dev/null +++ b/py/orbit/space_charge/sc2p5d/meson.build @@ -0,0 +1,14 @@ + + + +py_sources = files([ + 'scLatticeModifications.py', + 'scAccNodes.py', + '__init__.py' +]) + +python.install_sources( + py_sources, + subdir: 'orbit/space_charge/sc2p5d', + # pure: true, +) diff --git a/py/orbit/space_charge/sc3d/meson.build b/py/orbit/space_charge/sc3d/meson.build new file mode 100644 index 00000000..af9ef001 --- /dev/null +++ b/py/orbit/space_charge/sc3d/meson.build @@ -0,0 +1,14 @@ + + + +py_sources = files([ + 'scLatticeModifications.py', + 'scAccNodes.py', + '__init__.py' +]) + +python.install_sources( + py_sources, + subdir: 'orbit/space_charge/sc3d', + # pure: true, +) diff --git a/py/orbit/teapot/meson.build b/py/orbit/teapot/meson.build new file mode 100644 index 00000000..46fff1cf --- /dev/null +++ b/py/orbit/teapot/meson.build @@ -0,0 +1,14 @@ + + + +py_sources = files([ + 'teapot.py', + 'teapot_matrix_lattice.py', + '__init__.py' +]) + +python.install_sources( + py_sources, + subdir: 'orbit/teapot', + # pure: true, +) diff --git a/py/orbit/teapot_base/meson.build b/py/orbit/teapot_base/meson.build new file mode 100644 index 00000000..000b0df3 --- /dev/null +++ b/py/orbit/teapot_base/meson.build @@ -0,0 +1,12 @@ + + + +py_sources = files([ + '__init__.py' +]) + +python.install_sources( + py_sources, + subdir: 'orbit/teapot_base', + # pure: true, +) diff --git a/py/orbit/time_dep/meson.build b/py/orbit/time_dep/meson.build new file mode 100644 index 00000000..eb339b91 --- /dev/null +++ b/py/orbit/time_dep/meson.build @@ -0,0 +1,14 @@ + + + +py_sources = files([ + 'waveform.py', + '__init__.py', + 'time_dep.py' +]) + +python.install_sources( + py_sources, + subdir: 'orbit/time_dep', + # pure: true, +) diff --git a/py/orbit/utils/fitting/meson.build b/py/orbit/utils/fitting/meson.build new file mode 100644 index 00000000..0cfae1d2 --- /dev/null +++ b/py/orbit/utils/fitting/meson.build @@ -0,0 +1,18 @@ + + + +py_sources = files([ + 'PolynomialFit.py', + 'SimplexSearch.py', + 'Solver_lib.py', + '__init__.py', + 'BisectionSearch1D.py', + 'RandomSearch.py', + 'GoldenSectionSearch1D.py' +]) + +python.install_sources( + py_sources, + subdir: 'orbit/utils/fitting', + # pure: true, +) diff --git a/py/orbit/utils/meson.build b/py/orbit/utils/meson.build new file mode 100644 index 00000000..6d969897 --- /dev/null +++ b/py/orbit/utils/meson.build @@ -0,0 +1,22 @@ + +subdir('fitting') +subdir('xml') +subdir('orbit_mpi_utils') + + +py_sources = files([ + 'phaseOperations.py', + 'TypedObject.py', + '__init__.py', + 'ParamsDictObject.py', + 'consts.py', + 'multiDimArray.py', + 'NamedObject.py', + 'orbitFinalize.py' +]) + +python.install_sources( + py_sources, + subdir: 'orbit/utils', + # pure: true, +) diff --git a/py/orbit/utils/orbit_mpi_utils/meson.build b/py/orbit/utils/orbit_mpi_utils/meson.build new file mode 100644 index 00000000..de91dff5 --- /dev/null +++ b/py/orbit/utils/orbit_mpi_utils/meson.build @@ -0,0 +1,16 @@ + + + +py_sources = files([ + 'bunch_pyorbit_to_orbit.py', + 'bunch_orbit_to_pyorbit_nHarm.py', + 'bunch_orbit_to_pyorbit.py', + '__init__.py', + 'bunch_pyorbit_to_orbit_nHarm.py' +]) + +python.install_sources( + py_sources, + subdir: 'orbit/utils/orbit_mpi_utils', + # pure: true, +) diff --git a/py/orbit/utils/xml/meson.build b/py/orbit/utils/xml/meson.build new file mode 100644 index 00000000..d1ec7ad9 --- /dev/null +++ b/py/orbit/utils/xml/meson.build @@ -0,0 +1,13 @@ + + + +py_sources = files([ + 'XmlDataAdaptor.py', + '__init__.py' +]) + +python.install_sources( + py_sources, + subdir: 'orbit/utils/xml', + # pure: true, +) diff --git a/pyproject.toml b/pyproject.toml index f0029b9b..a11221b5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,11 +1,14 @@ [build-system] -requires = ["setuptools>=42", "setuptools_scm[toml]>=6.2", "wheel"] # PEP 508 specifications. -build-backend = "setuptools.build_meta" +build-backend = 'mesonpy' +requires = ['meson-python'] [project] -name = "PyORBIT" -dynamic = ["version"] -description = "Acceleratop Physics Simulation Code" +name = 'orbit' +version = '0.0.1' +description = 'Use meson-python to build c++ anf python modules.' +requires-python = '>=3.9' +authors = [ + {name = 'Alexander Zhukov', email = 'zhukovap@ornl.gov'}, +] + -[tool.setuptools_scm] -write_to = "src/_version.py" diff --git a/setup.py b/setup.py deleted file mode 100644 index bcd10d32..00000000 --- a/setup.py +++ /dev/null @@ -1,80 +0,0 @@ -from setuptools import Extension, setup -from pathlib import Path -import os - -# main dir is special -# we need it in include but not the actual main.cc -# libmain contains python package def, we don't want it in C++ sources - -src = [] - -for f in Path("src").rglob("*.cc"): - excludes = ["main/main.cc"] - include = True - for e in excludes: - if str(f).endswith(e): - include = False - if include: - src.append(str(f)) - -include = [] -for folder in os.walk("src"): - excludes = ["src", "src/libmain", "src/libmain/orbit"] - if folder[0] not in excludes: - include.append(folder[0]) - print(folder[0]) - -extension_mod = Extension( - "orbit.core._orbit", - sources=src, - libraries=["fftw3"], - include_dirs=include, - extra_compile_args=["-DUSE_MPI=1", "-fPIC", "-lmpi", "-lmpicxx", "-Wl,--enable-new-dtags"], - extra_link_args=["-lfftw3", "-lm", "-lmpi", "-lmpicxx", "-fPIC"], -) - -packages = ["orbit.core"] -for folder in os.walk("py/orbit"): - path = os.path.normpath(folder[0]) - path = path.split(os.sep) - packages.append(".".join(path[1:])) - -package_dir = { - "orbit": "py/orbit", - "orbit.core": "src/libmain/orbit", -} - -# This snippet generates the package structure of the orbit.core modules -# including the __init__.py file for each module -# The purpose is to be able to load individual modules from orbit.core in a -# Pythonic fashion. -core_modules = [ - "aperture", - "orbit_mpi", - "trackerrk4", - "error_base", - "bunch", - "teapot_base", - "linac", - "spacecharge", - "orbit_utils", - "foil", - "collimator", - "field_sources", - "rfcavities", - "impedances", - "fieldtracker", -] -for mod in core_modules: - packages.append(f"orbit.core.{mod}") - package_dir.update({f"orbit.core.{mod}": "src/libmain/module_template"}) - -# Define the setup parameters -setup( - ext_modules=[extension_mod], - package_dir=package_dir, - packages=packages, - use_scm_version=True, - setup_requires=["setuptools_scm"], - scripts=["bin/pyORBIT"], -) diff --git a/src/core/aperture_init.cc b/src/core/aperture_init.cc new file mode 100644 index 00000000..08f949de --- /dev/null +++ b/src/core/aperture_init.cc @@ -0,0 +1,4 @@ +#include "wrap_aperture.hh" +PyMODINIT_FUNC PyInit_aperture(void) { + return wrap_aperture::initaperture(); +} \ No newline at end of file diff --git a/src/core/bunch_init.cc b/src/core/bunch_init.cc new file mode 100644 index 00000000..d9d6b8de --- /dev/null +++ b/src/core/bunch_init.cc @@ -0,0 +1,4 @@ +#include "wrap_bunch.hh" +PyMODINIT_FUNC PyInit_bunch(void) { + return wrap_orbit_bunch::initbunch(); +} \ No newline at end of file diff --git a/src/core/collimator_init.cc b/src/core/collimator_init.cc new file mode 100644 index 00000000..2f88f044 --- /dev/null +++ b/src/core/collimator_init.cc @@ -0,0 +1,4 @@ +# include "wrap_collimator.hh" +PyMODINIT_FUNC PyInit_collimator(void) { + return wrap_collimator::initcollimator(); +} diff --git a/src/core/error_base_init.cc b/src/core/error_base_init.cc new file mode 100644 index 00000000..1e6888aa --- /dev/null +++ b/src/core/error_base_init.cc @@ -0,0 +1,5 @@ +#include +# include "wrap_errorbase.hh" +PyMODINIT_FUNC PyInit_error_base(void) { + return wrap_errorbase::initerrorbase(); +} \ No newline at end of file diff --git a/src/core/field_sources_init.cc b/src/core/field_sources_init.cc new file mode 100644 index 00000000..e592a9c4 --- /dev/null +++ b/src/core/field_sources_init.cc @@ -0,0 +1,4 @@ +#include "wrap_field_sources_module.hh" +PyMODINIT_FUNC PyInit_field_sources(void) { + return wrap_field_sources_module::initFieldSourcesModule(); +} \ No newline at end of file diff --git a/src/core/fieldtracker_init.cc b/src/core/fieldtracker_init.cc new file mode 100644 index 00000000..15b9c9cd --- /dev/null +++ b/src/core/fieldtracker_init.cc @@ -0,0 +1,4 @@ +#include "wrap_fieldtracker.hh" +PyMODINIT_FUNC PyInit_fieldtracker(void) { + return wrap_fieldtracker::initfieldtracker(); +} \ No newline at end of file diff --git a/src/core/foil_init.cc b/src/core/foil_init.cc new file mode 100644 index 00000000..3c5869c2 --- /dev/null +++ b/src/core/foil_init.cc @@ -0,0 +1,4 @@ +#include "wrap_foil.hh" +PyMODINIT_FUNC PyInit_foil(void) { + return wrap_foil::initfoil(); +} diff --git a/src/core/impedances_init.cc b/src/core/impedances_init.cc new file mode 100644 index 00000000..48b9cf5a --- /dev/null +++ b/src/core/impedances_init.cc @@ -0,0 +1,4 @@ +#include "wrap_impedances.hh" +PyMODINIT_FUNC PyInit_impedances(void) { + return wrap_impedances::initimpedances(); +} \ No newline at end of file diff --git a/src/core/linac_init.cc b/src/core/linac_init.cc new file mode 100644 index 00000000..9797a77e --- /dev/null +++ b/src/core/linac_init.cc @@ -0,0 +1,4 @@ +#include "wrap_linacmodule.hh" +PyMODINIT_FUNC PyInit_linac(void) { + return wrap_linac::initlinac(); +} \ No newline at end of file diff --git a/src/core/mpi_init.cc b/src/core/mpi_init.cc new file mode 100644 index 00000000..19fcf616 --- /dev/null +++ b/src/core/mpi_init.cc @@ -0,0 +1,6 @@ +#include "Python.h" +#include "wrap_orbit_mpi.hh" + +PyMODINIT_FUNC PyInit_orbit_mpi(void) { + return wrap_orbit_mpi::initorbit_mpi(); +} \ No newline at end of file diff --git a/src/core/rfcavities_init.cc b/src/core/rfcavities_init.cc new file mode 100644 index 00000000..112c15dc --- /dev/null +++ b/src/core/rfcavities_init.cc @@ -0,0 +1,4 @@ +#include "wrap_rfcavities.hh" +PyMODINIT_FUNC PyInit_rfcavities(void) { + return wrap_rfcavities::initrfcavities(); +} \ No newline at end of file diff --git a/src/core/spacecharge_init.cc b/src/core/spacecharge_init.cc new file mode 100644 index 00000000..730b25b5 --- /dev/null +++ b/src/core/spacecharge_init.cc @@ -0,0 +1,4 @@ +#include "wrap_spacecharge.hh" +PyMODINIT_FUNC PyInit_spacecharge(void) { + return initspacecharge(); +} \ No newline at end of file diff --git a/src/core/teapot_base_init.cc b/src/core/teapot_base_init.cc new file mode 100644 index 00000000..9dc74c73 --- /dev/null +++ b/src/core/teapot_base_init.cc @@ -0,0 +1,8 @@ +#include +#include "wrap_orbit_mpi.hh" +#include "wrap_teapotbase.hh" +#include "wrap_errorbase.hh" + +PyMODINIT_FUNC PyInit_teapot_base(void) { + return wrap_teapotbase::initteapotbase(); +} \ No newline at end of file diff --git a/src/core/trackerrk4_init.cc b/src/core/trackerrk4_init.cc new file mode 100644 index 00000000..87f23f7d --- /dev/null +++ b/src/core/trackerrk4_init.cc @@ -0,0 +1,4 @@ +#include "wrap_trackerrk4.hh" +PyMODINIT_FUNC PyInit_trackerrk4(void) { + return inittrackerrk4(); +} \ No newline at end of file diff --git a/src/core/utils_init.cc b/src/core/utils_init.cc new file mode 100644 index 00000000..5f8cd02f --- /dev/null +++ b/src/core/utils_init.cc @@ -0,0 +1,4 @@ +#include "wrap_utils.hh" +PyMODINIT_FUNC PyInit_orbit_utils(void) { + return wrap_orbit_utils::initutils(); +} \ No newline at end of file diff --git a/src/meson.build b/src/meson.build new file mode 100644 index 00000000..0cc4195e --- /dev/null +++ b/src/meson.build @@ -0,0 +1,410 @@ + +#project('orbit', ['cpp'], version: '0.0.1') + + +# Add Python installation details +python = import('python').find_installation(pure: false) + +py3 = python.dependency() + +# Add C++ compiler details +cpp = meson.get_compiler('cpp') + +base = meson.current_source_dir() + '/core' + + + +inc = [ +'/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/Headers', +'/opt/homebrew/include' +] +link_a = ['-L/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib', + '-L/opt/homebrew/lib', + '-lpython3.9', '-lfftw3' +] + + +sources = files([ + 'linac/wrap_linacmodule.cc', + 'linac/tracking/linac_tracking.cc', + 'linac/tracking/wrap_linac_tracking.cc', + 'linac/rfgap/wrap_BaseRfGap.cc', + 'linac/rfgap/BaseRfGap_slow.cc', + 'linac/rfgap/wrap_RfGapTTF_slow.cc', + 'linac/rfgap/wrap_RfGapThreePointTTF.cc', + 'linac/rfgap/BaseRfGap.cc', + 'linac/rfgap/RfGapThreePointTTF.cc', + 'linac/rfgap/MatrixRfGap.cc', + 'linac/rfgap/wrap_BaseRfGap_slow.cc', + 'linac/rfgap/wrap_RfGapThreePointTTF_slow.cc', + 'linac/rfgap/wrap_SuperFishFieldSource.cc', + 'linac/rfgap/RfGapTTF.cc', + 'linac/rfgap/SuperFishFieldSource.cc', + 'linac/rfgap/RfGapTTF_slow.cc', + 'linac/rfgap/RfGapThreePointTTF_slow.cc', + 'linac/rfgap/wrap_RfGapTTF.cc', + 'linac/rfgap/wrap_MatrixRfGap.cc', + 'orbit/OrbitConst.cc', + 'orbit/wrap_bunch.cc', + 'orbit/wrap_syncpart.cc', + 'orbit/Bunch.cc', + 'orbit/SyncPart.cc', + 'orbit/BunchDiagnostics/wrap_bunch_tune_analysis.cc', + 'orbit/BunchDiagnostics/wrap_bunch_twiss_analysis.cc', + 'orbit/BunchDiagnostics/BunchTwissAnalysis.cc', + 'orbit/BunchDiagnostics/BunchTuneAnalysis.cc', + 'orbit/FieldTracker/wrap_fieldtracker.cc', + 'orbit/FieldTracker/FieldTracker.cc', + 'orbit/MaterialInteractions/wrap_foil.cc', + 'orbit/MaterialInteractions/Foil.cc', + 'orbit/MaterialInteractions/Collimator.cc', + 'orbit/MaterialInteractions/numrecipes.cc', + 'orbit/MaterialInteractions/cross_sections.cc', + 'orbit/MaterialInteractions/wrap_collimator.cc', + 'orbit/MaterialInteractions/MaterialInteractions.cc', + 'orbit/RFCavities/Dual_Harmonic_Cav.cc', + 'orbit/RFCavities/Frequency_Cav.cc', + 'orbit/RFCavities/Barrier_Cav.cc', + 'orbit/RFCavities/wrap_Harmonic_Cav.cc', + 'orbit/RFCavities/Harmonic_Cav.cc', + 'orbit/RFCavities/wrap_Dual_Harmonic_Cav.cc', + 'orbit/RFCavities/wrap_Barrier_Cav.cc', + 'orbit/RFCavities/wrap_Frequency_Cav.cc', + 'orbit/RFCavities/wrap_rfcavities.cc', + 'orbit/Impedances/wrap_TImpedance.cc', + 'orbit/Impedances/TImpedance.cc', + 'orbit/Impedances/wrap_impedances.cc', + 'orbit/Impedances/LImpedance.cc', + 'orbit/Impedances/wrap_LImpedance.cc', + 'orbit/SynchPartRedefinition/SynchPartRedefinitionZdE.cc', + 'orbit/SynchPartRedefinition/wrap_synch_part_redefinition_z_de.cc', + 'orbit/Errors/errorbase.cc', + 'orbit/Errors/wrap_errorbase.cc', + 'orbit/ParticlesAttributes/ParticleInitialCoordinates.cc', + 'orbit/ParticlesAttributes/ParticleIdNumber.cc', + 'orbit/ParticlesAttributes/ParticleMacroSize.cc', + 'orbit/ParticlesAttributes/ParticleAttributesFactory.cc', + 'orbit/ParticlesAttributes/WaveFunctionAmplitudes.cc', + 'orbit/ParticlesAttributes/pq_coordinates.cc', + 'orbit/ParticlesAttributes/Evolution.cc', + 'orbit/ParticlesAttributes/ParticleAttributes.cc', + 'orbit/ParticlesAttributes/TurnNumberAttributes.cc', + 'orbit/ParticlesAttributes/LostParticleAttributes.cc', + 'orbit/ParticlesAttributes/ParticlePhaseAttributes.cc', + 'orbit/ParticlesAttributes/part_time.cc', + 'orbit/ParticlesAttributes/AtomPopulations.cc', + 'orbit/Apertures/CircleApertureShape.cc', + 'orbit/Apertures/PhaseAperture.cc', + 'orbit/Apertures/Aperture.cc', + 'orbit/Apertures/wrap_aperture.cc', + 'orbit/Apertures/wrap_CompositeApertureShape.cc', + 'orbit/Apertures/RectangularApertureShape.cc', + 'orbit/Apertures/PyBaseApertureShape.cc', + 'orbit/Apertures/ConvexApertureShape.cc', + 'orbit/Apertures/wrap_ConvexApertureShape.cc', + 'orbit/Apertures/wrap_PyBaseApertureShape.cc', + 'orbit/Apertures/EnergyAperture.cc', + 'orbit/Apertures/BaseAperture.cc', + 'orbit/Apertures/EllipseApertureShape.cc', + 'orbit/Apertures/wrap_BaseAperture.cc', + 'orbit/Apertures/wrap_PrimitiveApertureShape.cc', + 'orbit/Apertures/CompositeApertureShape.cc', + 'orbit/Apertures/wrap_EnergyAperture.cc', + 'orbit/Apertures/wrap_TAperture.cc', + 'orbit/Apertures/wrap_PhaseAperture.cc', + 'orbit/Apertures/BaseApertureShape.cc', + 'trackerrk4/wrap_runge_kutta_tracker.cc', + 'trackerrk4/wrap_py_external_effects.cc', + 'trackerrk4/ExternalEffects.cc', + 'trackerrk4/ExtEffectsContainer.cc', + 'trackerrk4/wrap_trackerrk4.cc', + 'trackerrk4/PyExternalEffects.cc', + 'trackerrk4/RungeKuttaTracker.cc', + 'trackerrk4/wrap_ext_effects_container.cc', + 'libmain/libmain.cc', + 'mpi/wrap_orbit_mpi.cc', + 'mpi/wrap_mpi_comm.cc', + 'mpi/orbit_mpi.cc', + 'mpi/wrap_mpi_datatype.cc', + 'mpi/wrap_mpi_request.cc', + 'mpi/wrap_mpi_op.cc', + 'mpi/wrap_mpi_status.cc', + 'mpi/wrap_mpi_group.cc', + 'spacecharge/PoissonSolverFFT3D.cc', + 'spacecharge/SpaceChargeCalcUnifEllipse.cc', + 'spacecharge/ForceSolver2D.cc', + 'spacecharge/PoissonSolverFFT2D.cc', + 'spacecharge/wrap_poissonsolverfft2d.cc', + 'spacecharge/wrap_poissonsolverfft3d.cc', + 'spacecharge/PoissonSolver2D.cc', + 'spacecharge/SpaceChargeForceCalc2p5D.cc', + 'spacecharge/PoissonSolver3D.cc', + 'spacecharge/SpaceChargeCalc3D.cc', + 'spacecharge/wrap_boundary2d.cc', + 'spacecharge/wrap_forcesolverfft2d.cc', + 'spacecharge/ForceSolverFFT2D.cc', + 'spacecharge/SpaceChargeCalcSliceBySlice2D.cc', + 'spacecharge/Grid3D.cc', + 'spacecharge/wrap_spacecharge.cc', + 'spacecharge/wrap_spacechargecalc2p5d_rb.cc', + 'spacecharge/Grid2D.cc', + 'spacecharge/SpaceChargeCalc2p5Drb.cc', + 'spacecharge/Grid1D.cc', + 'spacecharge/LSpaceChargeCalc.cc', + 'spacecharge/wrap_grid1D.cc', + 'spacecharge/wrap_uniform_ellipsoid_field_calculator.cc', + 'spacecharge/ShapedBoundary2D.cc', + 'spacecharge/wrap_grid3D.cc', + 'spacecharge/BaseBoundary2D.cc', + 'spacecharge/wrap_grid2D.cc', + 'spacecharge/wrap_spacechargecalc_uniform_ellipse.cc', + 'spacecharge/wrap_spacechargecalc3d.cc', + 'spacecharge/UniformEllipsoidFieldCalculator.cc', + 'spacecharge/wrap_spacechargeforcecalc2p5d.cc', + 'spacecharge/SpaceChargeCalc2p5D.cc', + 'spacecharge/wrap_spacechargecalc_slicebyslice_2D.cc', + 'spacecharge/wrap_spacechargecalc2p5d.cc', + 'spacecharge/wrap_lspacechargecalc.cc', + 'utils/wrap_function.cc', + 'utils/FieldSourceContainer.cc', + 'utils/AttributesBucket.cc', + 'utils/bessel.cc', + 'utils/PyBaseFieldSource.cc', + 'utils/wrap_field_source_container.cc', + 'utils/OU_SplineCH.cc', + 'utils/CppPyWrapper.cc', + 'utils/wrap_random.cc', + 'utils/wrap_utils.cc', + 'utils/StringUtils.cc', + 'utils/wrap_py_base_field_source.cc', + 'utils/wrap_splinech.cc', + 'utils/Random.cc', + 'utils/wrap_numrecipes.cc', + 'utils/BaseFieldSource.cc', + 'utils/OU_Function.cc', + 'utils/MathPolynomial.cc', + 'utils/BufferStore.cc', + 'utils/statistics/wrap_statmoments2d.cc', + 'utils/statistics/StatMoments2D.cc', + 'utils/field_sources/wrap_loop_field_source.cc', + 'utils/field_sources/LoopFieldSource.cc', + 'utils/field_sources/QuadFieldSource.cc', + 'utils/field_sources/ShiftedFieldSource.cc', + 'utils/field_sources/wrap_dipole_field_source.cc', + 'utils/field_sources/wrap_quad_field_source.cc', + 'utils/field_sources/wrap_magnetic_field_source_grid3d.cc', + 'utils/field_sources/DipoleFieldSource.cc', + 'utils/field_sources/wrap_field_sources_module.cc', + 'utils/field_sources/MagnetFieldSourceGrid3D.cc', + 'utils/integration/gauss_legendre_points.cc', + 'utils/integration/wrap_gauss_legendre_integrator.cc', + 'utils/integration/GaussLegendreIntegrator.cc', + 'utils/bunch/ParticlesWithIdFunctions.cc', + 'utils/bunch/wrap_bunch_extrema_calculator.cc', + 'utils/bunch/TwissFilteringFunctions.cc', + 'utils/bunch/InitialCoordsAttrFunctions.cc', + 'utils/bunch/BunchExtremaCalculator.cc', + 'utils/bunch/wrap_bunch_utils_functions.cc', + 'utils/harmonic_analysis/HarmonicData.cc', + 'utils/harmonic_analysis/wrap_harmonic_data.cc', + 'utils/polynomial/wrap_polynomial.cc', + 'utils/polynomial/OU_Polynomial.cc', + 'utils/matrix/wrap_matrix.cc', + 'utils/matrix/PhaseVector.cc', + 'utils/matrix/MatrixOperations.cc', + 'utils/matrix/wrap_phase_vector.cc', + 'utils/matrix/Matrix.cc', + 'teapot/wrap_teapotbase.cc', + 'teapot/wrap_matrix_generator.cc', + 'teapot/teapotbase.cc', + 'teapot/MatrixGenerator.cc' +]) +headers = include_directories([ + 'main', + 'orbit/SynchPartRedefinition', + 'trackerrk4', + 'utils/ellipticalint', + 'teapot', + 'mpi', + 'orbit/ParticlesAttributes', + 'orbit/Errors', + 'orbit/FieldTracker', + 'utils/statistics', + 'utils', + 'linac/tracking', + 'spacecharge', + 'orbit/MaterialInteractions', + 'utils/field_sources', + 'utils/bunch', + 'orbit/Impedances', + 'utils/harmonic_analysis', + 'linac', + 'utils/polynomial', + 'linac/rfgap', + 'orbit/RFCavities', + 'utils/matrix', + 'orbit/BunchDiagnostics', + 'orbit', + 'utils/integration', + 'libmain', + 'orbit/Apertures' + +]) + +inc += headers + +core_lib = library('core', + sources: sources, + include_directories: inc, + cpp_args: ['-fPIC', '-std=c++11'], + link_args: link_a, + install: true, + +) + +core_dep = declare_dependency(link_with : core_lib) + + + + +python.extension_module('orbit_mpi', + sources: [base + '/mpi_init.cc'], + include_directories: inc, + cpp_args: ['-fPIC', '-std=c++11'], + dependencies: [core_dep], + install: true, + subdir: 'orbit/core', +) + + +python.extension_module('bunch', + sources: [base + '/bunch_init.cc'], + include_directories: inc, + cpp_args: ['-fPIC', '-std=c++11'], + dependencies: [core_dep], + install: true, + subdir: 'orbit/core', +) + +python.extension_module('spacecharge', + sources: [base + '/spacecharge_init.cc'], + include_directories: inc, + cpp_args: ['-fPIC', '-std=c++11'], + dependencies: [core_dep], + install: true, + subdir: 'orbit/core', +) + +python.extension_module('trackerrk4', + sources: [base + '/trackerrk4_init.cc'], + include_directories: inc, + cpp_args: ['-fPIC', '-std=c++11'], + dependencies: [core_dep], + install: true, + subdir: 'orbit/core', +) + +python.extension_module('teapot_base', + sources: [base + '/teapot_base_init.cc'], + include_directories: inc, + cpp_args: ['-fPIC', '-std=c++11'], + dependencies: [core_dep], + install: true, + subdir: 'orbit/core', +) + +python.extension_module('linac', + sources: [base + '/linac_init.cc'], + include_directories: inc, + cpp_args: ['-fPIC', '-std=c++11'], + dependencies: [core_dep], + install: true, + subdir: 'orbit/core', +) + +python.extension_module('orbit_utils', + sources: [base + '/utils_init.cc'], + include_directories: inc, + cpp_args: ['-fPIC', '-std=c++11'], + dependencies: [core_dep], + install: true, + subdir: 'orbit/core', +) + +python.extension_module('aperture', + sources: [base + '/aperture_init.cc'], + include_directories: inc, + cpp_args: ['-fPIC', '-std=c++11'], + dependencies: [core_dep], + install: true, + subdir: 'orbit/core', +) + +python.extension_module('foil', + sources: [base + '/foil_init.cc'], + include_directories: inc, + cpp_args: ['-fPIC', '-std=c++11'], + dependencies: [core_dep], + install: true, + subdir: 'orbit/core', +) + +python.extension_module('field_sources', + sources: [base + '/field_sources_init.cc'], + include_directories: inc, + cpp_args: ['-fPIC', '-std=c++11'], + dependencies: [core_dep], + install: true, + subdir: 'orbit/core', +) + +python.extension_module('rfcavities', + sources: [base + '/rfcavities_init.cc'], + include_directories: inc, + cpp_args: ['-fPIC', '-std=c++11'], + dependencies: [core_dep], + install: true, + subdir: 'orbit/core', +) + +python.extension_module('impedances', + sources: [base + '/impedances_init.cc'], + include_directories: inc, + cpp_args: ['-fPIC', '-std=c++11'], + dependencies: [core_dep], + install: true, + subdir: 'orbit/core', +) + +python.extension_module('fieldtracker', + sources: [base + '/fieldtracker_init.cc'], + include_directories: inc, + cpp_args: ['-fPIC', '-std=c++11'], + dependencies: [core_dep], + install: true, + subdir: 'orbit/core', +) + +python.extension_module('collimator', + sources: [base + '/collimator_init.cc'], + include_directories: inc, + cpp_args: ['-fPIC', '-std=c++11'], + dependencies: [core_dep], + install: true, + subdir: 'orbit/core', +) + +python.extension_module('error_base', + sources: [base + '/error_base_init.cc'], + include_directories: inc, + cpp_args: ['-fPIC', '-std=c++11'], + dependencies: [core_dep], + install: true, + subdir: 'orbit/core', +) + + + + + + diff --git a/src/orbit/wrap_bunch.cc b/src/orbit/wrap_bunch.cc index 2995fc3f..b91add4e 100644 --- a/src/orbit/wrap_bunch.cc +++ b/src/orbit/wrap_bunch.cc @@ -46,7 +46,7 @@ namespace wrap_orbit_bunch{ // Template: PyObject* PyObject_CallMethod( PyObject *o, char *method, char *format, ...) //see Python/C API documentation //It will create a SyncParticle object and set the reference to it from pyBunch - PyObject* mod = PyImport_ImportModule("_bunch"); + PyObject* mod = PyImport_ImportModule("orbit.core.bunch"); PyObject* pySyncPart = PyObject_CallMethod(mod,const_cast("SyncParticle"),const_cast("O"),self); //the references should be decreased because they were created as "new reference" @@ -1335,7 +1335,9 @@ extern "C" { } PyObject* getBunchType(const char* name){ - PyObject* mod = PyImport_ImportModule("_bunch"); + printf("Imorting bunch"); + PyObject* mod = PyImport_ImportModule("orbit.core.bunch"); + printf("Imported bunch"); PyObject* pyType = PyObject_GetAttrString(mod,name); Py_DECREF(mod); Py_DECREF(pyType); From c59a56422e333e042ccf27a476622c3e904d2608 Mon Sep 17 00:00:00 2001 From: "Zhukov, Alexander P" Date: Sun, 31 Mar 2024 15:03:02 -0400 Subject: [PATCH 03/12] Removed debug printouts --- src/orbit/wrap_bunch.cc | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/orbit/wrap_bunch.cc b/src/orbit/wrap_bunch.cc index b91add4e..0d87767d 100644 --- a/src/orbit/wrap_bunch.cc +++ b/src/orbit/wrap_bunch.cc @@ -1335,9 +1335,7 @@ extern "C" { } PyObject* getBunchType(const char* name){ - printf("Imorting bunch"); PyObject* mod = PyImport_ImportModule("orbit.core.bunch"); - printf("Imported bunch"); PyObject* pyType = PyObject_GetAttrString(mod,name); Py_DECREF(mod); Py_DECREF(pyType); From e01ed5820583b97c2d6b06a14bc9e2417c5a1d8f Mon Sep 17 00:00:00 2001 From: "Zhukov, Alexander P" Date: Sun, 31 Mar 2024 15:49:41 -0400 Subject: [PATCH 04/12] Minor refactoring and README --- README.md | 110 +++--------------- .../{test_imports.py => imports_test.py} | 0 meson.build | 10 ++ requirements.txt | 4 + src/meson.build | 11 -- 5 files changed, 33 insertions(+), 102 deletions(-) rename examples/meson/{test_imports.py => imports_test.py} (100%) create mode 100644 requirements.txt diff --git a/README.md b/README.md index 98b4da2d..11e7ab40 100644 --- a/README.md +++ b/README.md @@ -1,118 +1,46 @@ -# PyOrbit3 package installation +# PyOrbit3 package installation with meson -## 0. Required software - -One needs compilers and python development packages, depending on Linux flavor the package can be called **python-dev** or **python-devel**. - -This guide was tested on following configurations - -| CPU | Architecture | OS | Python | Compiler | -|---------------|--------------|--------------|---------|--------------| -| Intel i7-7700 | x86_64 | RHEL 8.7 | 3.9.13 | gcc-8.5 | -| | x86_64 | Arch | 3.10.10 | gcc-12.2.1 | -| Apple M2 | arm64 | macOS 13.3.1 | 3.9.6 | clang-14.0.3 | - - -## 1. Installation from source - -First step is to clone the source code: - -```bash -git clone https://github.com/PyORBIT-Collaboration/PyORBIT3.git -``` +This is experimental setup that is work in progress. There segfaulting issues with RF nodes. -Make sure you have a C++ compiler. +## 0. Required software -On Debian based distributions: -``` -sudo apt-get update -sudo apt-get install build-essential -``` +One needs compilers and python. -On RedHat based distributions -``` -sudo yum update -sudo yum group install "Development Tools" -``` - -You will also need to install the relevant packages in order to use PyOrbit. You can either do this through conda, or by installing the packages with your preferred package manager. -### Conda Setup (Recommended): +## 1. Preparing environment -First of all make sure you have conda installed. Then run the following: +First step is to clone the source code from meson branch: ```bash -cd pyorbit3 -conda env create -n pyorbit --file environment.yml -conda activate pyorbit -``` - -### Manual Setup: - -Make sure that you have the correct python version installed. We require python=3.10. Further the following packages are required, use your preferred packet manager to install them: - -- FFTW -- Matplotlib -- Numpy & Scipy -- Mpich - -On Debian based distributions: -``` -sudo apt-get install python-dev libmpich-dev mpich zlib1g-dev libfftw3-dev +git clone -b meson https://github.com/azukov/PyORBIT3.git ``` -On RedHat based distributions -``` -sudo yum install python-devel mpich mpich-devel zlib-devel fftw-devel -``` +Initialize new virtual environment and install packages -Then install the Python dependencies using PIP: ``` -pip install numpy scipy matplotlib +python -m venv .mes +source .mes/bin/activate +pip install -U pip +pip install -r requirements ``` - -For both of these methods these are the minimum requirements you need to run the examples. Additional packages will be required if you would like to modify and deploy to GitHub. These packages are pre-commit, flake8 and pytest to name a few. +Edit meson.build and set correct paths/flags for python/fftw3 headers and libraries ## 2. Build After you have installed everything, the next step is to build. In order to build the project, navigate to the root pyorbit directory and run the following: ```bash -python setup.py clean -pip install . + pip install --no-build-isolation --editable . ``` You need only build the project after a change is made to the core c++ or python classes. -## 3. Run SNS linac example - -Navigate to your examples directory: - -```bash -cd examples/SNS_Linac/pyorbit3_linac_model/ -python pyorbit3_sns_linac_mebt_hebt2.py -``` +## 3. Run excamples -Additionally if you would like to run the example on multiple MPI nodes you can use the following: +Navigate to your examples/meson directory: ```bash -mpirun -n 4 python pyorbit3_sns_linac_mebt_hebt2.py +cd examples/meson +python imports_test.py +python uspas_test.py ``` - -In the above line you can change the number 4 for however many MPI nodes you would like to test it on. - -# Structure -**./src** - source code for the core ORBIT C++ classes, including - wrappers, etc. - -**./py** - python modules and wrapper classes for the core ORBIT - classes. - -**./ext** - source code for external modules. Compilations of this - code should be placed into **./lib**. - -**./lib** - .so shared libraries to be used under pyORBIT interpreter. - -**./examples** - pyORBIT3 examples. - -**./tests** - pytests written for the CI Pipeline. diff --git a/examples/meson/test_imports.py b/examples/meson/imports_test.py similarity index 100% rename from examples/meson/test_imports.py rename to examples/meson/imports_test.py diff --git a/meson.build b/meson.build index 141151a6..c4dfeb03 100644 --- a/meson.build +++ b/meson.build @@ -1,3 +1,13 @@ project('orbit', ['cpp'], version: '0.0.1') +inc = [ +'/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/Headers', +'/opt/homebrew/include' +] + +link_a = ['-L/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib', + '-L/opt/homebrew/lib', + '-lpython3.9', '-lfftw3' +] + subdir('src') subdir('py/orbit') \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 00000000..8bdf4b8f --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +ninja +meson-python +numpy +matplotlib \ No newline at end of file diff --git a/src/meson.build b/src/meson.build index 0cc4195e..874b1093 100644 --- a/src/meson.build +++ b/src/meson.build @@ -13,17 +13,6 @@ cpp = meson.get_compiler('cpp') base = meson.current_source_dir() + '/core' - -inc = [ -'/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/Headers', -'/opt/homebrew/include' -] -link_a = ['-L/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib', - '-L/opt/homebrew/lib', - '-lpython3.9', '-lfftw3' -] - - sources = files([ 'linac/wrap_linacmodule.cc', 'linac/tracking/linac_tracking.cc', From d5d24c21019cd01d63345776df6673b6045c50e6 Mon Sep 17 00:00:00 2001 From: "Zhukov, Alexander P" Date: Sun, 31 Mar 2024 15:52:36 -0400 Subject: [PATCH 05/12] Typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 11e7ab40..2ecc5c7e 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ After you have installed everything, the next step is to build. In order to buil You need only build the project after a change is made to the core c++ or python classes. -## 3. Run excamples +## 3. Run examples Navigate to your examples/meson directory: From 4f1fa01d36d2db29136acda9ec694f9760b3cc8c Mon Sep 17 00:00:00 2001 From: "Zhukov, Alexander P" Date: Sun, 31 Mar 2024 18:58:40 -0400 Subject: [PATCH 06/12] Fixed module references. --- README.md | 45 +++++++++++++++---- src/linac/wrap_linacmodule.cc | 2 +- src/mpi/wrap_mpi_comm.cc | 2 +- src/orbit/Errors/wrap_errorbase.cc | 2 +- src/orbit/Impedances/wrap_impedances.cc | 2 +- src/orbit/RFCavities/wrap_rfcavities.cc | 2 +- src/spacecharge/wrap_spacecharge.cc | 2 +- src/spacecharge/wrap_spacechargecalc2p5d.cc | 6 +-- .../wrap_spacechargecalc2p5d_rb.cc | 8 ++-- src/spacecharge/wrap_spacechargecalc3d.cc | 4 +- .../wrap_spacechargecalc_slicebyslice_2D.cc | 4 +- .../wrap_spacechargecalc_uniform_ellipse.cc | 2 +- .../wrap_spacechargeforcecalc2p5d.cc | 8 ++-- src/teapot/wrap_teapotbase.cc | 2 +- src/trackerrk4/wrap_trackerrk4.cc | 2 +- src/utils/matrix/wrap_matrix.cc | 14 +++--- src/utils/matrix/wrap_phase_vector.cc | 12 ++--- src/utils/wrap_utils.cc | 2 +- 18 files changed, 75 insertions(+), 46 deletions(-) diff --git a/README.md b/README.md index 2ecc5c7e..656c566c 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,34 @@ -# PyOrbit3 package installation with meson +# PyOrbit3 with meson + +This uses meson-python to build orbit package. + +There is no **setup.py** file, instead we have **meson.build**. +**pyproject.toml** is changed to use meson. + +This is experimental setup that is work in progress. +The pure python part is built with hierarchical **meson.build** files in **py/**. +The C++ setup is combined in one file **src/meson.build**. + +### Main modifications in C++ code +1. **src/libmain/** is not used, still there for reference but will be gone soon. +2. **src/core/** contains one C++ file per module inside _orbit.core_ +3. The files **wrap_XXXX.cc** were modified to correctly reference modules +```cpp +// line +PyObject* mod = PyImport_ImportModule("_bunch"); +// replaced with +PyObject* mod = PyImport_ImportModule("orbit.core.bunch"); +``` + -This is experimental setup that is work in progress. There segfaulting issues with RF nodes. + +# Setup ## 0. Required software -One needs compilers and python. +One needs compilers, python and libfftw (and potentially mpi). +See [PyORBIT3](https://github.com/PyORBIT-Collaboration/PyORBIT3) for external +requirements. ## 1. Preparing environment @@ -23,24 +47,29 @@ source .mes/bin/activate pip install -U pip pip install -r requirements ``` -Edit meson.build and set correct paths/flags for python/fftw3 headers and libraries +Edit **meson.build** and set correct paths/flags for python/fftw3 headers and libraries ## 2. Build -After you have installed everything, the next step is to build. In order to build the project, navigate to the root pyorbit directory and run the following: - +To install orbit package in development mode run following: ```bash pip install --no-build-isolation --editable . ``` +No rebuild is necessary, just edit **py/** or **src/** and meson will rebuild as needed when import happens. -You need only build the project after a change is made to the core c++ or python classes. ## 3. Run examples -Navigate to your examples/meson directory: +Special examples used for meson testing ```bash cd examples/meson python imports_test.py python uspas_test.py ``` + +SNS linac example +```bash +cd examples/SNS_Linac/pyorbit3_linac_model/ +python pyorbit3_sns_linac_mebt_hebt2.py +``` diff --git a/src/linac/wrap_linacmodule.cc b/src/linac/wrap_linacmodule.cc index fd42a1e2..42a6d89a 100644 --- a/src/linac/wrap_linacmodule.cc +++ b/src/linac/wrap_linacmodule.cc @@ -45,7 +45,7 @@ extern "C" { } PyObject* getLinacType(char* name){ - PyObject* mod = PyImport_ImportModule("_linac"); + PyObject* mod = PyImport_ImportModule("orbit.core.linac"); PyObject* pyType = PyObject_GetAttrString(mod,name); Py_DECREF(mod); Py_DECREF(pyType); diff --git a/src/mpi/wrap_mpi_comm.cc b/src/mpi/wrap_mpi_comm.cc index 6d6f27a0..d16cd810 100644 --- a/src/mpi/wrap_mpi_comm.cc +++ b/src/mpi/wrap_mpi_comm.cc @@ -170,7 +170,7 @@ extern "C" { } PyObject* getMPI_CommType(const char* name){ - PyObject* mod = PyImport_ImportModule("_orbit_mpi"); + PyObject* mod = PyImport_ImportModule("orbit.core.orbit_mpi"); PyObject* mpi_comm_mod = PyObject_GetAttrString(mod,"mpi_comm"); PyObject* pyType = PyObject_GetAttrString(mpi_comm_mod,name); Py_DECREF(mpi_comm_mod); diff --git a/src/orbit/Errors/wrap_errorbase.cc b/src/orbit/Errors/wrap_errorbase.cc index 1fafff27..82494511 100644 --- a/src/orbit/Errors/wrap_errorbase.cc +++ b/src/orbit/Errors/wrap_errorbase.cc @@ -389,7 +389,7 @@ extern "C" PyObject* getBaseERRORType(char* name) { - PyObject* mod = PyImport_ImportModule("_error_base"); + PyObject* mod = PyImport_ImportModule("orbit.core.error_base"); PyObject* pyType = PyObject_GetAttrString(mod, name); Py_DECREF(mod); Py_DECREF(pyType); diff --git a/src/orbit/Impedances/wrap_impedances.cc b/src/orbit/Impedances/wrap_impedances.cc index a8bab3b3..16293211 100644 --- a/src/orbit/Impedances/wrap_impedances.cc +++ b/src/orbit/Impedances/wrap_impedances.cc @@ -32,7 +32,7 @@ PyMODINIT_FUNC initimpedances() PyObject* getImpedanceType(char* name) { - PyObject* mod = PyImport_ImportModule("_impedances"); + PyObject* mod = PyImport_ImportModule("orbit.core.impedances"); PyObject* pyType = PyObject_GetAttrString(mod, name); Py_DECREF(mod); Py_DECREF(pyType); diff --git a/src/orbit/RFCavities/wrap_rfcavities.cc b/src/orbit/RFCavities/wrap_rfcavities.cc index e02b9632..4034c5dd 100644 --- a/src/orbit/RFCavities/wrap_rfcavities.cc +++ b/src/orbit/RFCavities/wrap_rfcavities.cc @@ -37,7 +37,7 @@ PyMODINIT_FUNC initrfcavities() PyObject* getRFCavityType(char* name) { - PyObject* mod = PyImport_ImportModule("_rfcavities"); + PyObject* mod = PyImport_ImportModule("orbit.core.rfcavities"); PyObject* pyType = PyObject_GetAttrString(mod, name); Py_DECREF(mod); Py_DECREF(pyType); diff --git a/src/spacecharge/wrap_spacecharge.cc b/src/spacecharge/wrap_spacecharge.cc index 4e4d35f2..ab8d9ed5 100644 --- a/src/spacecharge/wrap_spacecharge.cc +++ b/src/spacecharge/wrap_spacecharge.cc @@ -53,7 +53,7 @@ extern "C" { } PyObject* getSpaceChargeType(const char* name){ - PyObject* mod = PyImport_ImportModule("_spacecharge"); + PyObject* mod = PyImport_ImportModule("orbit.core.spacecharge"); PyObject* pyType = PyObject_GetAttrString(mod,name); Py_DECREF(mod); Py_DECREF(pyType); diff --git a/src/spacecharge/wrap_spacechargecalc2p5d.cc b/src/spacecharge/wrap_spacechargecalc2p5d.cc index a8d635c2..2ba12f3c 100644 --- a/src/spacecharge/wrap_spacechargecalc2p5d.cc +++ b/src/spacecharge/wrap_spacechargecalc2p5d.cc @@ -61,7 +61,7 @@ extern "C" { return cpp_grid2d->getPyWrapper(); } //It will create a pyGrid2D object - PyObject* mod = PyImport_ImportModule("_spacecharge"); + PyObject* mod = PyImport_ImportModule("orbit.core.spacecharge"); PyObject* pyGrid2D = PyObject_CallMethod(mod,const_cast("Grid2D"),const_cast("ii"),cpp_grid2d->getSizeX(),cpp_grid2d->getSizeY()); //delete the c++ reference to the internal Grid2D inside pyGrid2D and assign the new one delete ((Grid2D*)((pyORBIT_Object*) pyGrid2D)->cpp_obj); @@ -82,7 +82,7 @@ extern "C" { return cpp_grid2d->getPyWrapper(); } //It will create a pyGrid2D object - PyObject* mod = PyImport_ImportModule("_spacecharge"); + PyObject* mod = PyImport_ImportModule("orbit.core.spacecharge"); PyObject* pyGrid2D = PyObject_CallMethod(mod,const_cast("Grid2D"),const_cast("ii"),cpp_grid2d->getSizeX(),cpp_grid2d->getSizeY()); //delete the c++ reference to the internal Grid2D inside pyGrid2D and assign the new one delete ((Grid2D*)((pyORBIT_Object*) pyGrid2D)->cpp_obj); @@ -103,7 +103,7 @@ extern "C" { return cpp_grid1d->getPyWrapper(); } //It will create a pyGrid2D object - PyObject* mod = PyImport_ImportModule("_spacecharge"); + PyObject* mod = PyImport_ImportModule("orbit.core.spacecharge"); PyObject* pyGrid1D = PyObject_CallMethod(mod,const_cast("Grid1D"),const_cast("i"),cpp_grid1d->getSizeZ()); //delete the c++ reference to the internal Grid1D inside pyGrid1D and assign the new one delete ((Grid1D*)((pyORBIT_Object*) pyGrid1D)->cpp_obj); diff --git a/src/spacecharge/wrap_spacechargecalc2p5d_rb.cc b/src/spacecharge/wrap_spacechargecalc2p5d_rb.cc index d50cf58f..31bdbae8 100644 --- a/src/spacecharge/wrap_spacechargecalc2p5d_rb.cc +++ b/src/spacecharge/wrap_spacechargecalc2p5d_rb.cc @@ -60,7 +60,7 @@ extern "C" { return cpp_grid2d->getPyWrapper(); } //It will create a pyGrid2D object - PyObject* mod = PyImport_ImportModule("_spacecharge"); + PyObject* mod = PyImport_ImportModule("orbit.core.spacecharge"); PyObject* pyGrid2D = PyObject_CallMethod(mod,const_cast("Grid2D"),const_cast("ii"),cpp_grid2d->getSizeX(),cpp_grid2d->getSizeY()); //delete the c++ reference to the internal Grid2D inside pyGrid2D and assign the new one delete ((Grid2D*)((pyORBIT_Object*) pyGrid2D)->cpp_obj); @@ -81,7 +81,7 @@ extern "C" { return cpp_grid2d->getPyWrapper(); } //It will create a pyGrid2D object - PyObject* mod = PyImport_ImportModule("_spacecharge"); + PyObject* mod = PyImport_ImportModule("orbit.core.spacecharge"); PyObject* pyGrid2D = PyObject_CallMethod(mod,const_cast("Grid2D"),const_cast("ii"),cpp_grid2d->getSizeX(),cpp_grid2d->getSizeY()); //delete the c++ reference to the internal Grid2D inside pyGrid2D and assign the new one delete ((Grid2D*)((pyORBIT_Object*) pyGrid2D)->cpp_obj); @@ -102,7 +102,7 @@ extern "C" { return cpp_grid1d->getPyWrapper(); } //It will create a pyGrid2D object - PyObject* mod = PyImport_ImportModule("_spacecharge"); + PyObject* mod = PyImport_ImportModule("orbit.core.spacecharge"); PyObject* pyGrid1D = PyObject_CallMethod(mod,const_cast("Grid1D"),const_cast("i"),cpp_grid1d->getSizeZ()); //delete the c++ reference to the internal Grid1D inside pyGrid1D and assign the new one delete ((Grid1D*)((pyORBIT_Object*) pyGrid1D)->cpp_obj); @@ -123,7 +123,7 @@ extern "C" { return cpp_grid1d->getPyWrapper(); } //It will create a pyGrid2D object - PyObject* mod = PyImport_ImportModule("_spacecharge"); + PyObject* mod = PyImport_ImportModule("orbit.core.spacecharge"); PyObject* pyGrid1D = PyObject_CallMethod(mod,const_cast("Grid1D"),const_cast("i"),cpp_grid1d->getSizeZ()); //delete the c++ reference to the internal Grid1D inside pyGrid1D and assign the new one delete ((Grid1D*)((pyORBIT_Object*) pyGrid1D)->cpp_obj); diff --git a/src/spacecharge/wrap_spacechargecalc3d.cc b/src/spacecharge/wrap_spacechargecalc3d.cc index 7d06b873..18bae349 100644 --- a/src/spacecharge/wrap_spacechargecalc3d.cc +++ b/src/spacecharge/wrap_spacechargecalc3d.cc @@ -55,7 +55,7 @@ extern "C" { return cpp_grid3d->getPyWrapper(); } //It will create a pyGrid3D object - PyObject* mod = PyImport_ImportModule("_spacecharge"); + PyObject* mod = PyImport_ImportModule("orbit.core.spacecharge"); PyObject* pyGrid3D = PyObject_CallMethod(mod,const_cast("Grid3D"),const_cast("iii"),cpp_grid3d->getSizeX(),cpp_grid3d->getSizeY(),cpp_grid3d->getSizeZ()); //delete the c++ reference to the internal Grid3D inside pyGrid3D and assign the new one delete ((Grid3D*)((pyORBIT_Object*) pyGrid3D)->cpp_obj); @@ -76,7 +76,7 @@ extern "C" { return cpp_grid3d->getPyWrapper(); } //It will create a pyGrid3D object - PyObject* mod = PyImport_ImportModule("_spacecharge"); + PyObject* mod = PyImport_ImportModule("orbit.core.spacecharge"); PyObject* pyGrid3D = PyObject_CallMethod(mod,const_cast("Grid3D"),const_cast("iii"),cpp_grid3d->getSizeX(),cpp_grid3d->getSizeY(),cpp_grid3d->getSizeZ()); //delete the c++ reference to the internal Grid3D inside pyGrid3D and assign the new one delete ((Grid3D*)((pyORBIT_Object*) pyGrid3D)->cpp_obj); diff --git a/src/spacecharge/wrap_spacechargecalc_slicebyslice_2D.cc b/src/spacecharge/wrap_spacechargecalc_slicebyslice_2D.cc index 7c1c4fb3..5e75809c 100755 --- a/src/spacecharge/wrap_spacechargecalc_slicebyslice_2D.cc +++ b/src/spacecharge/wrap_spacechargecalc_slicebyslice_2D.cc @@ -61,7 +61,7 @@ extern "C" { return cpp_grid3d->getPyWrapper(); } //It will create a pyGrid3D object - PyObject* mod = PyImport_ImportModule("_spacecharge"); + PyObject* mod = PyImport_ImportModule("orbit.core.spacecharge"); PyObject* pyGrid3D = PyObject_CallMethod(mod,const_cast("Grid3D"),const_cast("iii"),cpp_grid3d->getSizeX(),cpp_grid3d->getSizeY(),cpp_grid3d->getSizeZ()); //delete the c++ reference to the internal Grid3D inside pyGrid3D and assign the new one delete ((Grid3D*)((pyORBIT_Object*) pyGrid3D)->cpp_obj); @@ -82,7 +82,7 @@ extern "C" { return cpp_grid3d->getPyWrapper(); } //It will create a pyGrid3D object - PyObject* mod = PyImport_ImportModule("_spacecharge"); + PyObject* mod = PyImport_ImportModule("orbit.core.spacecharge"); PyObject* pyGrid3D = PyObject_CallMethod(mod,const_cast("Grid3D"),const_cast("iii"),cpp_grid3d->getSizeX(),cpp_grid3d->getSizeY(),cpp_grid3d->getSizeZ()); //delete the c++ reference to the internal Grid3D inside pyGrid3D and assign the new one delete ((Grid3D*)((pyORBIT_Object*) pyGrid3D)->cpp_obj); diff --git a/src/spacecharge/wrap_spacechargecalc_uniform_ellipse.cc b/src/spacecharge/wrap_spacechargecalc_uniform_ellipse.cc index 8b0f9389..657c610f 100644 --- a/src/spacecharge/wrap_spacechargecalc_uniform_ellipse.cc +++ b/src/spacecharge/wrap_spacechargecalc_uniform_ellipse.cc @@ -80,7 +80,7 @@ extern "C" { return cpp_ellipseFieldCalc->getPyWrapper(); } //It will create a pyUniformEllipsoidFieldCalculator object - PyObject* mod = PyImport_ImportModule("_spacecharge"); + PyObject* mod = PyImport_ImportModule("orbit.core.spacecharge"); PyObject* pyUniformEllipsoidFieldCalculator = PyObject_CallMethod(mod,const_cast("UniformEllipsoidFieldCalculator"),const_cast("")); //delete the c++ reference to the internal UniformEllipsoidFieldCalculator inside pyUniformEllipsoidFieldCalculator and assign the new one delete ((UniformEllipsoidFieldCalculator*)((pyORBIT_Object*) pyUniformEllipsoidFieldCalculator)->cpp_obj); diff --git a/src/spacecharge/wrap_spacechargeforcecalc2p5d.cc b/src/spacecharge/wrap_spacechargeforcecalc2p5d.cc index 660ba1b2..65e98689 100644 --- a/src/spacecharge/wrap_spacechargeforcecalc2p5d.cc +++ b/src/spacecharge/wrap_spacechargeforcecalc2p5d.cc @@ -57,7 +57,7 @@ extern "C" { return cpp_grid2d->getPyWrapper(); } //It will create a pyGrid2D object - PyObject* mod = PyImport_ImportModule("spacecharge"); + PyObject* mod = PyImport_ImportModule("orbit.core.spacecharge"); PyObject* pyGrid2D = PyObject_CallMethod(mod,const_cast("Grid2D"),const_cast("ii"),cpp_grid2d->getSizeX(),cpp_grid2d->getSizeY()); //delete the c++ reference to the internal Grid2D inside pyGrid2D and assign the new one delete ((Grid2D*)((pyORBIT_Object*) pyGrid2D)->cpp_obj); @@ -78,7 +78,7 @@ extern "C" { return cpp_grid2d->getPyWrapper(); } //It will create a pyGrid2D object - PyObject* mod = PyImport_ImportModule("spacecharge"); + PyObject* mod = PyImport_ImportModule("orbit.core.spacecharge"); PyObject* pyGrid2D = PyObject_CallMethod(mod,const_cast("Grid2D"),const_cast("ii"),cpp_grid2d->getSizeX(),cpp_grid2d->getSizeY()); //delete the c++ reference to the internal Grid2D inside pyGrid2D and assign the new one delete ((Grid2D*)((pyORBIT_Object*) pyGrid2D)->cpp_obj); @@ -100,7 +100,7 @@ extern "C" { return cpp_grid2d->getPyWrapper(); } //It will create a pyGrid2D object - PyObject* mod = PyImport_ImportModule("spacecharge"); + PyObject* mod = PyImport_ImportModule("orbit.core.spacecharge"); PyObject* pyGrid2D = PyObject_CallMethod(mod,const_cast("Grid2D"),const_cast("ii"),cpp_grid2d->getSizeX(),cpp_grid2d->getSizeY()); //delete the c++ reference to the internal Grid2D inside pyGrid2D and assign the new one delete ((Grid2D*)((pyORBIT_Object*) pyGrid2D)->cpp_obj); @@ -122,7 +122,7 @@ extern "C" { return cpp_grid1d->getPyWrapper(); } //It will create a pyGrid2D object - PyObject* mod = PyImport_ImportModule("spacecharge"); + PyObject* mod = PyImport_ImportModule("orbit.core.spacecharge"); PyObject* pyGrid1D = PyObject_CallMethod(mod,const_cast("Grid1D"),const_cast("i"),cpp_grid1d->getSizeZ()); //delete the c++ reference to the internal Grid1D inside pyGrid1D and assign the new one delete ((Grid1D*)((pyORBIT_Object*) pyGrid1D)->cpp_obj); diff --git a/src/teapot/wrap_teapotbase.cc b/src/teapot/wrap_teapotbase.cc index 127b5b5c..60dd64e5 100644 --- a/src/teapot/wrap_teapotbase.cc +++ b/src/teapot/wrap_teapotbase.cc @@ -533,7 +533,7 @@ extern "C" PyObject* getBaseTEAPOTType(char* name) { - PyObject* mod = PyImport_ImportModule("_teapot_base"); + PyObject* mod = PyImport_ImportModule("orbit.core.teapot_base"); PyObject* pyType = PyObject_GetAttrString(mod, name); Py_DECREF(mod); Py_DECREF(pyType); diff --git a/src/trackerrk4/wrap_trackerrk4.cc b/src/trackerrk4/wrap_trackerrk4.cc index 8b2d8e8c..5d23b55c 100644 --- a/src/trackerrk4/wrap_trackerrk4.cc +++ b/src/trackerrk4/wrap_trackerrk4.cc @@ -30,7 +30,7 @@ extern "C" { return module; } PyObject* getTrackerRK4Type(const char* name){ - PyObject* mod = PyImport_ImportModule("_trackerrk4"); + PyObject* mod = PyImport_ImportModule("orbit.core.trackerrk4"); PyObject* pyType = PyObject_GetAttrString(mod,name); Py_DECREF(mod); Py_DECREF(pyType); diff --git a/src/utils/matrix/wrap_matrix.cc b/src/utils/matrix/wrap_matrix.cc index aa5b9b93..eb329230 100644 --- a/src/utils/matrix/wrap_matrix.cc +++ b/src/utils/matrix/wrap_matrix.cc @@ -118,7 +118,7 @@ extern "C" { Matrix* cpp_Matrix = (Matrix*) pyMatrix->cpp_obj; int n = cpp_Matrix->rows(); int m = cpp_Matrix->columns(); - PyObject* mod = PyImport_ImportModule("_orbit_utils"); + PyObject* mod = PyImport_ImportModule("orbit.core.orbit_utils"); PyObject* pyMatr = PyObject_CallMethod(mod,const_cast("Matrix"),const_cast("ii"),n,m); pyORBIT_Object* pyMatrix_child = (pyORBIT_Object*) pyMatr; Matrix* cpp_Matrix_child = (Matrix*) pyMatrix_child->cpp_obj; @@ -165,7 +165,7 @@ extern "C" { // invert() - returns the inverted matrix, or None static PyObject* Matrix_invert(PyObject *self, PyObject *args){ - PyObject* mod = PyImport_ImportModule("_orbit_utils"); + PyObject* mod = PyImport_ImportModule("orbit.core.orbit_utils"); PyObject* pyMtrx = PyObject_CallMethod(mod,const_cast("Matrix"),const_cast("O"),self); Matrix* cpp_mtrx = (Matrix*) ((pyORBIT_Object*) pyMtrx)->cpp_obj; Py_DECREF(mod); @@ -189,7 +189,7 @@ extern "C" { if(!PyArg_ParseTuple(args,"d:add",&val)){ error("PyMatrix - add(number) - input parameter is needed."); } - PyObject* mod = PyImport_ImportModule("_orbit_utils"); + PyObject* mod = PyImport_ImportModule("orbit.core.orbit_utils"); PyObject* pyMtrx = PyObject_CallMethod(mod,const_cast("Matrix"),const_cast("O"),self); Matrix* cpp_mtrx = (Matrix*) ((pyORBIT_Object*) pyMtrx)->cpp_obj; cpp_mtrx->add(val); @@ -198,7 +198,7 @@ extern "C" { } PyObject* pyORBIT_Matrix_Type = getOrbitUtilsType("Matrix"); if(PyObject_IsInstance(pyIn,pyORBIT_Matrix_Type)){ - PyObject* mod = PyImport_ImportModule("_orbit_utils"); + PyObject* mod = PyImport_ImportModule("orbit.core.orbit_utils"); PyObject* pyMtrx = PyObject_CallMethod(mod,const_cast("Matrix"),const_cast("O"),self); Matrix* cpp_mtrx = (Matrix*) ((pyORBIT_Object*) pyMtrx)->cpp_obj; Py_DECREF(mod); @@ -223,7 +223,7 @@ extern "C" { if(!PyArg_ParseTuple(args,"d:mult",&val)){ error("PyMatrix - mult(number) - input parameter is needed."); } - PyObject* mod = PyImport_ImportModule("_orbit_utils"); + PyObject* mod = PyImport_ImportModule("orbit.core.orbit_utils"); PyObject* pyMtrx = PyObject_CallMethod(mod,const_cast("Matrix"),const_cast("O"),self); Matrix* cpp_mtrx = (Matrix*) ((pyORBIT_Object*) pyMtrx)->cpp_obj; cpp_mtrx->mult(val); @@ -232,7 +232,7 @@ extern "C" { } PyObject* pyORBIT_Matrix_Type = getOrbitUtilsType("Matrix"); if(PyObject_IsInstance(pyIn,pyORBIT_Matrix_Type)){ - PyObject* mod = PyImport_ImportModule("_orbit_utils"); + PyObject* mod = PyImport_ImportModule("orbit.core.orbit_utils"); PyObject* pyMtrx = PyObject_CallMethod(mod,const_cast("Matrix"),const_cast("O"),self); Matrix* cpp_mtrx = (Matrix*) ((pyORBIT_Object*) pyMtrx)->cpp_obj; Py_DECREF(mod); @@ -245,7 +245,7 @@ extern "C" { if(cpp_Matrix->columns() != cpp_PhaseVector->size()){ error("PyMatrix - mult(vector) - unequal sizes of columns and vectors."); } - PyObject* mod = PyImport_ImportModule("_orbit_utils"); + PyObject* mod = PyImport_ImportModule("orbit.core.orbit_utils"); PyObject* pyVctr = PyObject_CallMethod(mod,const_cast("PhaseVector"),const_cast("i"),cpp_Matrix->rows()); MatrixOperations::mult(cpp_Matrix,cpp_PhaseVector,(PhaseVector*) ((pyORBIT_Object*)pyVctr)->cpp_obj); Py_DECREF(mod); diff --git a/src/utils/matrix/wrap_phase_vector.cc b/src/utils/matrix/wrap_phase_vector.cc index 89ff4d0d..bff60f33 100644 --- a/src/utils/matrix/wrap_phase_vector.cc +++ b/src/utils/matrix/wrap_phase_vector.cc @@ -114,7 +114,7 @@ extern "C" { pyORBIT_Object* pyPhaseVector = (pyORBIT_Object*) self; PhaseVector* cpp_PhaseVector = (PhaseVector*) pyPhaseVector->cpp_obj; int n = cpp_PhaseVector->size(); - PyObject* mod = PyImport_ImportModule("_orbit_utils"); + PyObject* mod = PyImport_ImportModule("orbit.core.orbit_utils"); PyObject* pyVctr = PyObject_CallMethod(mod,const_cast("PhaseVector"),const_cast("i"),n); pyORBIT_Object* pyPhaseVector_child = (pyORBIT_Object*) pyVctr; PhaseVector* cpp_PhaseVector_child = (PhaseVector*) pyPhaseVector_child->cpp_obj; @@ -165,7 +165,7 @@ extern "C" { if(!PyArg_ParseTuple(args,"d:add",&val)){ error("Py PhaseVector- add(number) - input parameter is needed."); } - PyObject* mod = PyImport_ImportModule("_orbit_utils"); + PyObject* mod = PyImport_ImportModule("orbit.core.orbit_utils"); PyObject* pyVctr = PyObject_CallMethod(mod,const_cast("PhaseVector"),const_cast("O"),self); PhaseVector* cpp_vctr = (PhaseVector*) ((pyORBIT_Object*) pyVctr)->cpp_obj; cpp_vctr->add(val); @@ -178,7 +178,7 @@ extern "C" { if(cpp_PhaseVector->size() != cpp_PhaseVector_In->size()){ error("PyPhaseVector - add(vector) - unequal sizes of the vectors."); } - PyObject* mod = PyImport_ImportModule("_orbit_utils"); + PyObject* mod = PyImport_ImportModule("orbit.core.orbit_utils"); PyObject* pyVctr = PyObject_CallMethod(mod,const_cast("PhaseVector"),const_cast("O"),self); PhaseVector* cpp_vctr = (PhaseVector*) ((pyORBIT_Object*) pyVctr)->cpp_obj; cpp_vctr->add(cpp_PhaseVector_In); @@ -203,7 +203,7 @@ extern "C" { if(!PyArg_ParseTuple(args,"d:mult",&val)){ error("Py PhaseVector- mult(number) - input parameter is needed."); } - PyObject* mod = PyImport_ImportModule("_orbit_utils"); + PyObject* mod = PyImport_ImportModule("orbit.core.orbit_utils"); PyObject* pyVctr = PyObject_CallMethod(mod,const_cast("PhaseVector"),const_cast("O"),self); PhaseVector* cpp_vctr = (PhaseVector*) ((pyORBIT_Object*) pyVctr)->cpp_obj; cpp_vctr->mult(val); @@ -224,7 +224,7 @@ extern "C" { if(cpp_PhaseVector->size() != cpp_Matrix->rows()){ error("PyPhaseVector - mult(matrix) - unequal sizes of vectors and rows."); } - PyObject* mod = PyImport_ImportModule("_orbit_utils"); + PyObject* mod = PyImport_ImportModule("orbit.core.orbit_utils"); PyObject* pyVctr = PyObject_CallMethod(mod,const_cast("PhaseVector"),const_cast("i"),cpp_Matrix->columns()); MatrixOperations::mult(cpp_PhaseVector,cpp_Matrix,(PhaseVector*) ((pyORBIT_Object*)pyVctr)->cpp_obj); Py_DECREF(mod); @@ -249,7 +249,7 @@ extern "C" { if(cpp_PhaseVector->size() != cpp_PhaseVector_In->size() || cpp_PhaseVector_In->size() != 3){ error("PyPhaseVector - vct_mult(vector) - vector sizes should be 3."); } - PyObject* mod = PyImport_ImportModule("_orbit_utils"); + PyObject* mod = PyImport_ImportModule("orbit.core.orbit_utils"); PyObject* pyVctr = PyObject_CallMethod(mod,const_cast("PhaseVector"),const_cast("i"),3); double* v1 = cpp_PhaseVector->getArray(); double* v2 = cpp_PhaseVector_In->getArray(); diff --git a/src/utils/wrap_utils.cc b/src/utils/wrap_utils.cc index 3c443dcd..820976a1 100644 --- a/src/utils/wrap_utils.cc +++ b/src/utils/wrap_utils.cc @@ -59,7 +59,7 @@ extern "C" { } PyObject* getOrbitUtilsType(const char* name){ - PyObject* mod = PyImport_ImportModule(const_cast("_orbit_utils")); + PyObject* mod = PyImport_ImportModule(const_cast("orbit.core.orbit_utils")); PyObject* pyType = PyObject_GetAttrString(mod,name); Py_DECREF(mod); Py_DECREF(pyType); From fd7abcbe45aa296aef3a177141d59ec101777f70 Mon Sep 17 00:00:00 2001 From: Yngve Levinsen Date: Fri, 5 Apr 2024 08:41:23 +0200 Subject: [PATCH 07/12] meson fix for linux --- meson.build | 11 +---------- src/meson.build | 14 ++++++++------ 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/meson.build b/meson.build index c4dfeb03..eeeb68bf 100644 --- a/meson.build +++ b/meson.build @@ -1,13 +1,4 @@ project('orbit', ['cpp'], version: '0.0.1') -inc = [ -'/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/Headers', -'/opt/homebrew/include' -] - -link_a = ['-L/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib', - '-L/opt/homebrew/lib', - '-lpython3.9', '-lfftw3' -] subdir('src') -subdir('py/orbit') \ No newline at end of file +subdir('py/orbit') diff --git a/src/meson.build b/src/meson.build index 874b1093..341b389c 100644 --- a/src/meson.build +++ b/src/meson.build @@ -3,15 +3,16 @@ # Add Python installation details -python = import('python').find_installation(pure: false) - -py3 = python.dependency() +python = import('python').find_installation('python3', pure: false) # Add C++ compiler details cpp = meson.get_compiler('cpp') base = meson.current_source_dir() + '/core' +dependencies = [] + +dependencies += dependency('fftw3', version: '>= 3.0.0', required: true) sources = files([ 'linac/wrap_linacmodule.cc', @@ -208,7 +209,8 @@ sources = files([ 'teapot/teapotbase.cc', 'teapot/MatrixGenerator.cc' ]) -headers = include_directories([ +inc = include_directories([ + python.get_variable('INCLUDEPY', ''), 'main', 'orbit/SynchPartRedefinition', 'trackerrk4', @@ -240,13 +242,13 @@ headers = include_directories([ ]) -inc += headers core_lib = library('core', sources: sources, include_directories: inc, cpp_args: ['-fPIC', '-std=c++11'], - link_args: link_a, + override_options: ['b_lundef=false'], + dependencies: dependencies, install: true, ) From 62861faec949a539dc01651c132089a9ebeed427 Mon Sep 17 00:00:00 2001 From: austin-hoover Date: Tue, 30 Apr 2024 16:14:19 -0400 Subject: [PATCH 08/12] Fix integer division error in impedance node --- py/orbit/impedances/ImpedanceNode.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/py/orbit/impedances/ImpedanceNode.py b/py/orbit/impedances/ImpedanceNode.py index 6ed246c6..7777c683 100644 --- a/py/orbit/impedances/ImpedanceNode.py +++ b/py/orbit/impedances/ImpedanceNode.py @@ -218,7 +218,7 @@ def assignLatFuncs(self, qX, alphaX, betaX, qY, alphaY, betaY): self.timpedance.assignLatFuncs(qX, alphaX, betaX, qY, alphaY, betaY) def assignImpedance(self, XorY, py_cmplx_arrp, py_cmplx_arrm): - size = self.nBins / 2 + size = self.nBins // 2 if len(py_cmplx_arrp) < size: start = len(py_cmplx_arrp) for n in range(start, size): @@ -229,7 +229,7 @@ def assignImpedance(self, XorY, py_cmplx_arrp, py_cmplx_arrm): py_cmplx_arrm.append(py_cmplx_arrm[start - 1]) Zp = [] Zm = [] - for n in range(self.nBins / 2): + for n in range(size): Zp.append(py_cmplx_arrp[n]) Zm.append(py_cmplx_arrm[n]) self.timpedance.assignImpedance(XorY, Zp, Zm) From 1573e5682a0ecfd1822039d2d56c542d6620a5e8 Mon Sep 17 00:00:00 2001 From: Shishlo Date: Wed, 22 May 2024 13:38:16 -0400 Subject: [PATCH 09/12] The static method adaptorForString(txt) was added to XmlDataAdaptor class. It creates data adaptor tree from a plain text representation of XML file. --- py/orbit/utils/xml/XmlDataAdaptor.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/py/orbit/utils/xml/XmlDataAdaptor.py b/py/orbit/utils/xml/XmlDataAdaptor.py index 9e53c9eb..30930348 100644 --- a/py/orbit/utils/xml/XmlDataAdaptor.py +++ b/py/orbit/utils/xml/XmlDataAdaptor.py @@ -230,6 +230,14 @@ def adaptorForFile(file_name): xml_root_adaptor = XmlDataAdaptor(root.tag) XmlDataAdaptor._makeDataAdaptor(xml_root_adaptor, root) return xml_root_adaptor + + @staticmethod + def adaptorForString(txt): + """returns the new data adaptor created from the input text""" + root = ET.fromstring(txt) + xml_root_adaptor = XmlDataAdaptor(root.tag) + XmlDataAdaptor._makeDataAdaptor(xml_root_adaptor, root) + return xml_root_adaptor @staticmethod def _makeDataAdaptor(data_adaptor, dom_node): From 23ab29185ce6685d50fabc8a17cf740814a32852 Mon Sep 17 00:00:00 2001 From: "Zhukov, Alexander P" Date: Wed, 22 May 2024 16:33:27 -0400 Subject: [PATCH 10/12] Meson build and GitHub actions Updated README for meson build system. Introduced actions to test installation on different platforms. No MPI builds only. --- .github/workflows/compilation.yml | 120 ++++++++++++++++++++++++++++ .github/workflows/conda-build.sh | 5 ++ .github/workflows/conda-tests.sh | 4 + .github/workflows/conda-versions.sh | 7 ++ .github/workflows/pip-build.sh | 6 ++ .github/workflows/pip-tests.sh | 3 + .github/workflows/pip-versions.sh | 5 ++ MesonBuild.md | 75 +++++++++++++++++ README.md | 111 ++++++++++++++----------- environment.yml | 5 +- meson.build | 2 +- pyproject.toml | 7 +- requirements.txt | 4 +- 13 files changed, 300 insertions(+), 54 deletions(-) create mode 100644 .github/workflows/compilation.yml create mode 100755 .github/workflows/conda-build.sh create mode 100755 .github/workflows/conda-tests.sh create mode 100755 .github/workflows/conda-versions.sh create mode 100755 .github/workflows/pip-build.sh create mode 100755 .github/workflows/pip-tests.sh create mode 100755 .github/workflows/pip-versions.sh create mode 100644 MesonBuild.md diff --git a/.github/workflows/compilation.yml b/.github/workflows/compilation.yml new file mode 100644 index 00000000..a60ceb9b --- /dev/null +++ b/.github/workflows/compilation.yml @@ -0,0 +1,120 @@ +name: build-pyorbit + +on: + push: + tags: + - '*' + branches: + - '*' + +jobs: + + + apple-silicon: + runs-on: macos-14 + steps: + - name: Install packages + run: | + brew reinstall pkg-config fftw + + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Build + run: | + .github/workflows/pip-build.sh + + - name: Test + run: | + .github/workflows/pip-tests.sh + + - name: Print Versions + run: | + .github/workflows/pip-versions.sh + + + centos-stream: + runs-on: ubuntu-latest + container: + image: quay.io/centos/centos:stream9 + steps: + - name: Install packages + run: | + dnf group install -y "Development Tools" + dnf install -y python3-devel fftw3-devel + + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Build + run: | + .github/workflows/pip-build.sh + + - name: Test + run: | + .github/workflows/pip-tests.sh + + - name: Print Versions + run: | + .github/workflows/pip-versions.sh + + + + ubuntu: + runs-on: ubuntu-latest + container: + image: ubuntu:latest + steps: + - name: Install packages + run: | + apt-get update -y + apt-get install -y build-essential python3 libfftw3-dev python3-venv libpython3-dev pkg-config git + + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Build + run: | + .github/workflows/pip-build.sh + + - name: Test + run: | + .github/workflows/pip-tests.sh + + - name: Print Versions + run: | + .github/workflows/pip-versions.sh + + + conda: + runs-on: ubuntu-latest + container: + image: ubuntu:latest + steps: + - name: Install Conda + run: | + apt update -y + apt install -y curl gpg git build-essential + curl https://repo.anaconda.com/pkgs/misc/gpgkeys/anaconda.asc | gpg --dearmor > conda.gpg + install -o root -g root -m 644 conda.gpg /usr/share/keyrings/conda-archive-keyring.gpg + echo "deb [arch=amd64 signed-by=/usr/share/keyrings/conda-archive-keyring.gpg] https://repo.anaconda.com/pkgs/misc/debrepo/conda stable main" > /etc/apt/sources.list.d/conda.list + apt update -y + apt install -y conda + + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Build + run: | + .github/workflows/conda-build.sh + + - name: Test + run: | + .github/workflows/conda-tests.sh + + - name: Print Versions + run: | + .github/workflows/conda-versions.sh diff --git a/.github/workflows/conda-build.sh b/.github/workflows/conda-build.sh new file mode 100755 index 00000000..a0d0da77 --- /dev/null +++ b/.github/workflows/conda-build.sh @@ -0,0 +1,5 @@ +. /opt/conda/etc/profile.d/conda.sh +conda env create -n po3 --file environment.yml +conda activate po3 +pip install -U meson-python setuptools setuptools-scm +pip install --no-build-isolation --editable . \ No newline at end of file diff --git a/.github/workflows/conda-tests.sh b/.github/workflows/conda-tests.sh new file mode 100755 index 00000000..721a486e --- /dev/null +++ b/.github/workflows/conda-tests.sh @@ -0,0 +1,4 @@ +. /opt/conda/etc/profile.d/conda.sh +conda activate po3 +cd examples/SNS_Linac/pyorbit3_linac_model/ +python pyorbit3_sns_sts_linac_mebt_hebt2.py \ No newline at end of file diff --git a/.github/workflows/conda-versions.sh b/.github/workflows/conda-versions.sh new file mode 100755 index 00000000..703173a4 --- /dev/null +++ b/.github/workflows/conda-versions.sh @@ -0,0 +1,7 @@ +. /opt/conda/etc/profile.d/conda.sh +conda activate po3 +python -V +conda -V +pip -V +gcc -v +python -m setuptools_scm \ No newline at end of file diff --git a/.github/workflows/pip-build.sh b/.github/workflows/pip-build.sh new file mode 100755 index 00000000..2ca2c9e1 --- /dev/null +++ b/.github/workflows/pip-build.sh @@ -0,0 +1,6 @@ +python3 -m venv .po3 +. .po3/bin/activate +pip install -U pip +pip install -r requirements.txt +pip install -U setuptools +pip install --no-build-isolation --editable . \ No newline at end of file diff --git a/.github/workflows/pip-tests.sh b/.github/workflows/pip-tests.sh new file mode 100755 index 00000000..80d30df4 --- /dev/null +++ b/.github/workflows/pip-tests.sh @@ -0,0 +1,3 @@ +. .po3/bin/activate +cd examples/SNS_Linac/pyorbit3_linac_model/ +python pyorbit3_sns_sts_linac_mebt_hebt2.py \ No newline at end of file diff --git a/.github/workflows/pip-versions.sh b/.github/workflows/pip-versions.sh new file mode 100755 index 00000000..a7738d1a --- /dev/null +++ b/.github/workflows/pip-versions.sh @@ -0,0 +1,5 @@ +. .po3/bin/activate +python -V +pip -V +gcc -v +python -m setuptools_scm \ No newline at end of file diff --git a/MesonBuild.md b/MesonBuild.md new file mode 100644 index 00000000..656c566c --- /dev/null +++ b/MesonBuild.md @@ -0,0 +1,75 @@ +# PyOrbit3 with meson + +This uses meson-python to build orbit package. + +There is no **setup.py** file, instead we have **meson.build**. +**pyproject.toml** is changed to use meson. + +This is experimental setup that is work in progress. +The pure python part is built with hierarchical **meson.build** files in **py/**. +The C++ setup is combined in one file **src/meson.build**. + +### Main modifications in C++ code +1. **src/libmain/** is not used, still there for reference but will be gone soon. +2. **src/core/** contains one C++ file per module inside _orbit.core_ +3. The files **wrap_XXXX.cc** were modified to correctly reference modules +```cpp +// line +PyObject* mod = PyImport_ImportModule("_bunch"); +// replaced with +PyObject* mod = PyImport_ImportModule("orbit.core.bunch"); +``` + + + +# Setup + +## 0. Required software + +One needs compilers, python and libfftw (and potentially mpi). +See [PyORBIT3](https://github.com/PyORBIT-Collaboration/PyORBIT3) for external +requirements. + + +## 1. Preparing environment + +First step is to clone the source code from meson branch: + +```bash +git clone -b meson https://github.com/azukov/PyORBIT3.git +``` + +Initialize new virtual environment and install packages + +``` +python -m venv .mes +source .mes/bin/activate +pip install -U pip +pip install -r requirements +``` +Edit **meson.build** and set correct paths/flags for python/fftw3 headers and libraries + +## 2. Build + +To install orbit package in development mode run following: +```bash + pip install --no-build-isolation --editable . +``` +No rebuild is necessary, just edit **py/** or **src/** and meson will rebuild as needed when import happens. + + +## 3. Run examples + +Special examples used for meson testing + +```bash +cd examples/meson +python imports_test.py +python uspas_test.py +``` + +SNS linac example +```bash +cd examples/SNS_Linac/pyorbit3_linac_model/ +python pyorbit3_sns_linac_mebt_hebt2.py +``` diff --git a/README.md b/README.md index 656c566c..0957a6fd 100644 --- a/README.md +++ b/README.md @@ -1,75 +1,92 @@ -# PyOrbit3 with meson - -This uses meson-python to build orbit package. - -There is no **setup.py** file, instead we have **meson.build**. -**pyproject.toml** is changed to use meson. - -This is experimental setup that is work in progress. -The pure python part is built with hierarchical **meson.build** files in **py/**. -The C++ setup is combined in one file **src/meson.build**. - -### Main modifications in C++ code -1. **src/libmain/** is not used, still there for reference but will be gone soon. -2. **src/core/** contains one C++ file per module inside _orbit.core_ -3. The files **wrap_XXXX.cc** were modified to correctly reference modules -```cpp -// line -PyObject* mod = PyImport_ImportModule("_bunch"); -// replaced with -PyObject* mod = PyImport_ImportModule("orbit.core.bunch"); -``` +# PyOrbit3 package installation +## 1. Introduction +This guide provides isntructions how to install PyORBIT code.
+This guide doesn't cover MPI enabled installation.
+The following configurations are included in CI testing, versions will change as the runner images progress. +| HW | Architecture | OS | Python | Compiler | Package | +|---------------|--------------|---------------|---------|--------------|--------------| +| PC | x86_64 | CentOS latest | 3.9.18 | gcc-11.4.1 | pip-24.0 | +| PC | x86_64 | Ubuntu latest | 3.12.3 | gcc-13.2.0 | pip-24.0 | +| Apple Silicon | arm64 | macOS 14 | 3.12.3 | clang-15.0.0 | pip-24.0 | +| PC | x86_64 | Ubuntu latest | 3.10.14 | gcc-13.2.0 | conda-24.5.0 | -# Setup -## 0. Required software -One needs compilers, python and libfftw (and potentially mpi). -See [PyORBIT3](https://github.com/PyORBIT-Collaboration/PyORBIT3) for external -requirements. +## 2. Installation from source +First step is to clone the source code: -## 1. Preparing environment +```bash +git clone https://github.com/PyORBIT-Collaboration/PyORBIT3.git +``` -First step is to clone the source code from meson branch: +### Pip Setup -```bash -git clone -b meson https://github.com/azukov/PyORBIT3.git +On Ubuntu distributions: +``` +sudo apt-get update +sudo apt-get install -y build-essential python3 libfftw3-dev python3-venv libpython3-dev pkg-config git +``` + +On CentOS distributions: +``` +dnf group install -y "Development Tools" +dnf install -y python3-devel fftw3-devel +``` + +Make sure that you have the correct python version installed. We require python>3.9.
+Create virtual environment. +``` +python3 -m venv .po3 +. .po3/bin/activate +pip install -U pip +pip install -r requirements.txt +pip install -U setuptools ``` -Initialize new virtual environment and install packages +### Conda Setup +First of all make sure you have conda installed and development packages.
+Development packages for Ubuntu: ``` -python -m venv .mes -source .mes/bin/activate -pip install -U pip -pip install -r requirements +apt update -y +apt install -y curl gpg git build-essential ``` -Edit **meson.build** and set correct paths/flags for python/fftw3 headers and libraries -## 2. Build +Then run the following: -To install orbit package in development mode run following: ```bash - pip install --no-build-isolation --editable . +cd pyorbit3 +conda env create -n po3 --file environment.yml +conda activate po3 +pip install -U meson-python setuptools setuptools-scm ``` -No rebuild is necessary, just edit **py/** or **src/** and meson will rebuild as needed when import happens. -## 3. Run examples +## 3. Build -Special examples used for meson testing +If you plan to modify PyORBIT's code, install it in editable mode. +You will NOT need to rebuild after modifications to the code. [Meson](MesonBuild.md) will rebuild as necessary on import. +``` +pip install --no-build-isolation --editable . +``` -```bash -cd examples/meson -python imports_test.py -python uspas_test.py +Alternatively if you don't plan to modify PyORBIT's code ``` +pip install . +``` + + +## 4. Run full SNS linac example + +Navigate to your **examples** directory and launch tracking of SNS linac. -SNS linac example ```bash cd examples/SNS_Linac/pyorbit3_linac_model/ python pyorbit3_sns_linac_mebt_hebt2.py ``` + + + diff --git a/environment.yml b/environment.yml index 3d08bfb6..556ecff3 100644 --- a/environment.yml +++ b/environment.yml @@ -7,5 +7,6 @@ dependencies: - numpy - scipy - matplotlib - - mpich - - mpi + - meson + - pkg-config + - ninja diff --git a/meson.build b/meson.build index eeeb68bf..b2bb9c79 100644 --- a/meson.build +++ b/meson.build @@ -1,4 +1,4 @@ -project('orbit', ['cpp'], version: '0.0.1') +project('PyORBIT', ['cpp'], version: run_command('python', '-m', 'setuptools_scm').stdout().strip()) subdir('src') subdir('py/orbit') diff --git a/pyproject.toml b/pyproject.toml index a11221b5..e3fbca76 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,8 +3,8 @@ build-backend = 'mesonpy' requires = ['meson-python'] [project] -name = 'orbit' -version = '0.0.1' +name = 'PyORBIT' +dynamic = ["version"] description = 'Use meson-python to build c++ anf python modules.' requires-python = '>=3.9' authors = [ @@ -12,3 +12,6 @@ authors = [ ] +[tool.setuptools_scm] + + diff --git a/requirements.txt b/requirements.txt index 8bdf4b8f..d4a7c8fd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ ninja meson-python -numpy -matplotlib \ No newline at end of file +setuptools +setuptools-scm \ No newline at end of file From a680a82cce5a9519a702b7061da526227f52325e Mon Sep 17 00:00:00 2001 From: "Zhukov, Alexander P" Date: Thu, 23 May 2024 13:47:53 -0400 Subject: [PATCH 11/12] Fixed build requirements for isolated builds. Typo in README. --- README.md | 2 +- pyproject.toml | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0957a6fd..b0b4e005 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # PyOrbit3 package installation ## 1. Introduction -This guide provides isntructions how to install PyORBIT code.
+This guide provides instructions how to install PyORBIT code.
This guide doesn't cover MPI enabled installation.
The following configurations are included in CI testing, versions will change as the runner images progress. diff --git a/pyproject.toml b/pyproject.toml index e3fbca76..a65921e6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,12 +1,16 @@ [build-system] build-backend = 'mesonpy' -requires = ['meson-python'] +requires = ['meson-python', "setuptools>=45", "wheel", "setuptools_scm"] [project] name = 'PyORBIT' dynamic = ["version"] description = 'Use meson-python to build c++ anf python modules.' requires-python = '>=3.9' +#dependencies = [ +#'setuptools', +#'setuptools-scm' +#] authors = [ {name = 'Alexander Zhukov', email = 'zhukovap@ornl.gov'}, ] From d9b947bb2b5695188fb7384b2b103b1df6d63201 Mon Sep 17 00:00:00 2001 From: "Zhukov, Alexander P" Date: Tue, 28 May 2024 11:31:45 -0400 Subject: [PATCH 12/12] Added instructions for MacOS. --- README.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b0b4e005..ff221326 100644 --- a/README.md +++ b/README.md @@ -24,18 +24,24 @@ git clone https://github.com/PyORBIT-Collaboration/PyORBIT3.git ### Pip Setup -On Ubuntu distributions: +#### Ubuntu based distributions: ``` sudo apt-get update sudo apt-get install -y build-essential python3 libfftw3-dev python3-venv libpython3-dev pkg-config git ``` -On CentOS distributions: +#### Redhat based distributions: ``` dnf group install -y "Development Tools" dnf install -y python3-devel fftw3-devel ``` +#### MacOS +Install Homebrew, make sure that homebrew programs are in the **$PATH** (optional step in Homebrew installation) +```bash +brew install pkg-config fftw +``` + Make sure that you have the correct python version installed. We require python>3.9.
Create virtual environment. ```