From 22f7cb34ee327a284d4ddb530f1d601670203aca Mon Sep 17 00:00:00 2001 From: Joey Zhu Date: Mon, 3 Oct 2022 13:07:44 -0700 Subject: [PATCH 01/12] test --- cmake/dependencies/ABLASTR.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/cmake/dependencies/ABLASTR.cmake b/cmake/dependencies/ABLASTR.cmake index aeb0abd44..2e1dbe0b2 100644 --- a/cmake/dependencies/ABLASTR.cmake +++ b/cmake/dependencies/ABLASTR.cmake @@ -29,6 +29,7 @@ macro(find_ablastr) # transitive control for openPMD/FFT/PICSAR superbuild # TODO (future) + # TODO: delete this # ABLASTR superbuild if(ImpactX_ablastr_internal OR ImpactX_ablastr_src) set(CMAKE_POLICY_DEFAULT_CMP0077 NEW) From d7e9ee76733b0df00e0a0c1846e73d437b1c614a Mon Sep 17 00:00:00 2001 From: Joey Zhu Date: Tue, 4 Oct 2022 11:29:45 -0700 Subject: [PATCH 02/12] sync with mainline --- cmake/dependencies/ABLASTR.cmake | 1 - 1 file changed, 1 deletion(-) diff --git a/cmake/dependencies/ABLASTR.cmake b/cmake/dependencies/ABLASTR.cmake index 2e1dbe0b2..aeb0abd44 100644 --- a/cmake/dependencies/ABLASTR.cmake +++ b/cmake/dependencies/ABLASTR.cmake @@ -29,7 +29,6 @@ macro(find_ablastr) # transitive control for openPMD/FFT/PICSAR superbuild # TODO (future) - # TODO: delete this # ABLASTR superbuild if(ImpactX_ablastr_internal OR ImpactX_ablastr_src) set(CMAKE_POLICY_DEFAULT_CMP0077 NEW) From 0ecbc309261a3509083d37efe626aaae56b2e4cc Mon Sep 17 00:00:00 2001 From: Joey Zhu Date: Tue, 4 Oct 2022 13:46:57 -0700 Subject: [PATCH 03/12] Implement infrastructure for main files: - mad_var - mad_cmd - mad_elem - mad_macro --- src/madx/README.md | 15 ++++++ src/madx/mad_cmd.py | 107 ++++++++++++++++++++++++++++++++++++++++++ src/madx/mad_elem.py | 90 +++++++++++++++++++++++++++++++++++ src/madx/mad_macro.py | 45 ++++++++++++++++++ src/madx/mad_var.py | 83 ++++++++++++++++++++++++++++++++ 5 files changed, 340 insertions(+) create mode 100644 src/madx/README.md create mode 100644 src/madx/mad_cmd.py create mode 100644 src/madx/mad_elem.py create mode 100644 src/madx/mad_macro.py create mode 100644 src/madx/mad_var.py diff --git a/src/madx/README.md b/src/madx/README.md new file mode 100644 index 000000000..440425f36 --- /dev/null +++ b/src/madx/README.md @@ -0,0 +1,15 @@ +# MadX Python Interpreter (10/4/22) + +Author: Joey Zhu (https://github.com/np-eazy) + +This Python interpreter was written as a subset of MadX's C interpreter's full functionalities to suit the needs of ImpactX. +Implementation contains a lot of boilerplate, but this is to maintain a reliable, verbatim approach for transcribing a large +volume of code. + +### Supported objects +- Variables +- Elements +- Macros (Lines) + +### Removed Functionalities +- Fortran90 interface \ No newline at end of file diff --git a/src/madx/mad_cmd.py b/src/madx/mad_cmd.py new file mode 100644 index 000000000..b4b70475d --- /dev/null +++ b/src/madx/mad_cmd.py @@ -0,0 +1,107 @@ +class Command: + def __init__(self, name, module, group, stamp, link_type, mad8_type, beam_def, par_names, par): + self.name = name + self.module = module + self.group = group + self.stamp = stamp + self.link_type = link_type + self.mad8_type = mad8_type + self.beam_def = beam_def + self.par_names = par_names + self.par = par + + +class CommandList: + def __init__(self, name, max_length): + self.name = name + self.lst = [] + self.names = [] + self.max_length = max_length + + def add_var(self, var): + # TODO: add separately for names + self.lst += [var] + + +class CommandListList: + def __init__(self, max_length): + self.lst = [] + self.names = [] + self.max_length = max_length + + def add_var(self, var): + # TODO: add separately for names + self.lst += [var] + + +# TODO: Implement functions as needed +# Interface +def new_command(name, nl_length, pl_length, module, group, link, mad_8): + return None + +def delete_command(command): + return None + +def clone_command(command): + return None + +def clone_command_flat(command): + return None + +def find_command(name, command_list): + return None + + +# List Commands +def new_command_list(name, max_length): + return CommandList(name, max_length) + +def delete_command_list(command_list): + return None + +def find_command_list(name, command_list_list): + return None + +def grow_command_list(command_list): + return None + +def add_to_command_list(label, command, command_list, flag): + return None + +def new_command_list_list(max_length): + return CommandListList(max_length) + +def add_to_command_list_list(label, command_list, command_list_list): + return None + + +# Command Methods +def exec_command(): + return None + +def decode_command(): + return None + +def dump_command(command): # For Debugging + return None + +def print_command(command): + return None + +def store_command_def(): # Processes command definition + return None + +def make_line(statement): + return None + +def get_stmt(file, supp_flag): + return None + +def get_defined_commands(): + return None + +def remove_from_command_list(label, command_list): + return None + +def exec_add_expression(in_cmd): + return None diff --git a/src/madx/mad_elem.py b/src/madx/mad_elem.py new file mode 100644 index 000000000..08b3b1148 --- /dev/null +++ b/src/madx/mad_elem.py @@ -0,0 +1,90 @@ +class Element: + def __init__(self, name, def_type, bv, length, defi, parent, stamp, base_type, aperture, multipole): + self.name = name + self.def_type = def_type + self.bv = bv + self.length = length + self.defi = defi + self.parent = parent + self.stamp = stamp + self.base_type = base_type + self.aperture = aperture + self.multipole = multipole + +class ElementList: + def __init__(self, max_length): + self.lst = [] + self.max_length = max_length + + def add_var(self, var): + self.lst += [var] + + +def make_element(name, parent, command, flag): + return None + +def clone_element(element): + return None + +def delete_element(element): + return None + +def update_element(element, update_command): + return None + +def update_element_children(element, update_command): + return None + + +def dump_element(element): + return None + +def export_el_def(element, string, noexpr): + return None + +def export_el_def_8(element, string, noexpr): + return None + + +def new_el_list(max_length): + return ElementList(max_length) + +def delete_el_list(el_list): + return None + +def find_element(name, el_list): + return None + +def write_elems(el_list, command_list, file, noexpr): + return None + +def write_elems_8(el_list, command_list, file): + return None + + +def new_elem_node(element, occ_cnt): + return None + +def make_elem_node(element, occ_cnt): + return None + +def compound(e_name, occ_cnt): + return None + + +def enter_element(in_cmd): + return None + +def element_name(name, l): + return None + +def element_value(node, params): + return None + +def element_vector(element, params, vector): + return None + + + + + diff --git a/src/madx/mad_macro.py b/src/madx/mad_macro.py new file mode 100644 index 000000000..81b1961fb --- /dev/null +++ b/src/madx/mad_macro.py @@ -0,0 +1,45 @@ +class Macro: + def __init__(self, name, n_formal, dead, formal, tokens, body, stamp, original): + self.name = name + self.n_formal = n_formal + self.dead = dead + self.formal = formal + self.tokens = tokens + self.body = body + self.stamp = stamp + self.original = original + + +class MacroList: + def __init__(self, max_length): + self.lst = [] + self.max_length = max_length + + def add_var(self, var): + self.lst += [var] + + + +def make_macro(statemenet): + return None + +def new_macro(n_formal, length, p_length): + return None + +def new_macro_list(max_length): + return MacroList(max_length) + +def add_to_macro_list(macro, macro_list): + return None + +def disable_line(name, macro_list): + return None + +def replace_lines(macro, replace, reps): + return None + +def save_macros2file(): + return None + +def exec_macro(in_cmd, pos): + return None \ No newline at end of file diff --git a/src/madx/mad_var.py b/src/madx/mad_var.py new file mode 100644 index 000000000..46e9cdc02 --- /dev/null +++ b/src/madx/mad_var.py @@ -0,0 +1,83 @@ +class Constant: + def __init__(self, name, expr, value, stamp): + self.name = name + self.expr = expr + self.value = value + self.stamp = stamp + + +class Variable: + def __init__(self, name, val, val_type, type, expression, string): + self.name = name + self.val = val + self.val_type = val_type + self.type = type + self.expression = expression + self.string = string + + +class VariableList: + def __init__(self, max_length): + self.lst = [] + self.max_length = max_length + + def add_var(self, var): + self.lst += [var] + + +# TODO: Implement as needed +def enter_variable(in_cmd): + return None + +def new_variable(name, val, val_type, typ, expression, string): + return Variable(name, val, val_type, typ, expression, string) + +def variable_value(var): + return None + + +def new_var_list(max_length): + return VariableList(max_length) + +def clone_var_list(var_list): + return None + +def delete_var_list(var_list): + return None + +def add_to_var_list(var, var_list, flag): + # TODO: Re-implement placeholder function var flag + var_list.add_var(var) + +def find_variable(name, var_list): + return None + + +def make_string_variable(string): + return None + +def write_vars(var_list, command_list, file, noexpr): + return None + +def write_vars_8(var_list, command_list, file): + return None + +def set_variable(name, value): + return None + +def set_stringvar(name, string): + return None + +def get_variable(name): + return None + +def get_varstring(name): + return None + +def get_defined_constants(): + return None + + + + + From caec449cf0a1c644a273ec0c8f386c99a628a108 Mon Sep 17 00:00:00 2001 From: Joey Zhu Date: Tue, 4 Oct 2022 14:12:25 -0700 Subject: [PATCH 04/12] Implement core/global interpreter infrastructure: - mad_main - mad_gvar - mad_core: mad_init_c --- src/madx/mad_core.py | 208 +++++++++++++++++++++++++++++++++++++++++++ src/madx/mad_gvar.py | 14 +++ src/madx/mad_main.py | 19 ++++ 3 files changed, 241 insertions(+) create mode 100644 src/madx/mad_core.py create mode 100644 src/madx/mad_gvar.py create mode 100644 src/madx/mad_main.py diff --git a/src/madx/mad_core.py b/src/madx/mad_core.py new file mode 100644 index 000000000..54ad259d2 --- /dev/null +++ b/src/madx/mad_core.py @@ -0,0 +1,208 @@ +# include +# include "madx.h" + +from mad_var import * +from mad_elem import * +from mad_macro import * +from mad_cmd import * + + +def mad_init_c(gvar): + # TODO: Implement subset of mad_init_c + # allocate variable ptr + ione = 1 + + # make stdout unbuffered for proper I/O synchronization with fortran + # setvbuf(stdout, 0, _IONBF, 0); + # + # init55(123456789); /* random generator */ + # if (watch_flag == 1) debug_file = fopen("madx.debug", "w"); + # else if (watch_flag == 2) debug_file = stdout; + # if (stamp_flag == 1) stamp_file = fopen("madx.stamp", "w"); + # else if (stamp_flag == 2) stamp_file = stdout; + + # in = new_in_buff_list(100); /* list of input buffers, dynamic */ + + # // quick and dirty fix to accept jobs from filename + # in->input_files[0] = mad_argc > 1 ? fopen(mad_argv[1], "r") : stdin; + # if (!in->input_files[0]) { + # mad_error("invalid input filename ", " %s", mad_argv[1]); + # in->input_files[0] = stdin; + # } + # interactive = intrac(); + # prt_file = stdout; + # pro = new_in_buff_list(100); /* list of process buffers, dynamic */ + # pro->buffers[0] = new_in_buffer(IN_BUFF_SIZE); + # pro->curr = 1; + # c_dum = new_char_array(AUX_LG); + # c_join = new_char_array(AUX_LG); + # work = new_char_array(AUX_LG); + # l_wrk = new_char_array(AUX_LG); + + # Physical Constants: + # deco_init(); + # get_defined_constants(); + # get_defined_commands(command_def); + # get_defined_commands(element_def); + # get_sxf_names(); + # + # pi = get_variable("pi"); + # twopi = two * pi; + # degrad = 180 / pi; + # raddeg = pi / 180; + # e = get_variable("e"); + # clight = get_variable("clight"); + # hbar = get_variable("hbar"); + + # Global Variable Initialization: + # aux_buff = new_char_array(AUX_LG); /* dynamic temporary buffer */ + gvar.variable_list = new_var_list(2000) # dynamic list of variables + gvar.beam_list = new_command_list("beam_list", 10) # dynamic beam list + gvar.table_deselect = new_command_list_list(10) # dynamic + gvar.table_select = new_command_list_list(10) # dynamic + gvar.defined_commands = new_command_list("defined_commands", 100) # dynamic + gvar.stored_commands = new_command_list("stored_commands", 500) # dynamic + gvar.line_list = new_macro_list(100) # dynamic + gvar.macro_list = new_macro_list(100) # dynamic + gvar.base_type_list = new_el_list(60) # dynamic + gvar.element_list = new_el_list(20000) # dynamic + # buffered_cmds = new_in_cmd_list(10000); /* dynamic */ + # sequences = new_sequence_list(20); /* dynamic */ + # match_sequs = new_sequence_list(2); + # selected_ranges = new_node_list(10000); /* dynamic */ + gvar.selected_elements = new_el_list(10000) # dynamic + # tmp_p_array = new_char_p_array(1000); /* dynamic */ + # tmp_l_array = new_char_p_array(1000); /* dynamic */ + # sxf_list = new_name_list("sxf_list", 50); /* dynamic */ + # all_table_lists = new_table_list_list(10); /* dynamic */ + + # # Initialize needed work for commands + var = new_variable("twiss_tol", 1.e-6, 1, 1, None, None) + add_to_var_list(var, gvar.variable_list, 1) + # title = permbuff("no-title"); + # set_defaults("option"); + # if (interactive) { int false = 0; set_option("echo", &false); } + # set_defaults("beam"); + # add_to_command_list("default_beam", current_beam, beam_list, 0); + # set_defaults("set"); + # set_defaults("setplot"); + # set_defaults("threader"); + # table_register = new_table_list(10); /* dynamic */ + # beta0_list = new_command_list("beta0_list", 10); /* dynamic */ + # savebeta_list = new_command_list("savebeta_list", 10); /* dynamic */ + # seqedit_select = /* dynamic - for "select seqedit" commands */ + # new_command_list("seqedit_select", 10); + # error_select = /* dynamic - for "select error" commands */ + # new_command_list("error-select", 10); + # save_select = /* dynamic - for "select save" commands */ + # new_command_list("save_select", 10); + # slice_select = /* dynamic - for "select makethin" commands */ + # new_command_list("slice_select", 10); + # sector_select = /* dynamic - for "select sectormap" commands */ + # new_command_list("sector_select", 10); + # interp_select = /* dynamic - for "select sectormap" commands */ + # new_command_list("interp_select", 10); + # s_range = new_int_array(10); /* dynamic */ + # e_range = new_int_array(10); /* dynamic */ + # sd_range = new_int_array(10); /* dynamic */ + # ed_range = new_int_array(10); /* dynamic */ + # zero_double(orbit0, 6); + # zero_double(disp0, 6); + # zero_double(guess_orbit,6); + # zero_double(oneturnmat, 36); + # set_option("twiss_print", &ione); + return None + + +def madx_start(gvar): + # TODO: Implement normal madx_start + + mad_init_c(gvar) + + time = None + # /* setbuf(stdout,(char *)0); */ /* no buffering - for debugging */ + # time(&start_time); /* initialize timing */ + # tm = localtime(&start_time); /* split system time */ + # last_time = start_time; + + # // compute padding of OSTYPE + # const char *pad[] = { "", " ", " ", " " }; + # const int pad_sz = sizeof pad/sizeof *pad; + # int pad_idx = strlen("Windows")-strlen(version_ostype); + # if (pad_idx >= pad_sz) pad_idx = pad_sz-1; + + # printf("\n ++++++++++++++++++++++++++++++++++++++++++++\n"); + # printf(" + MAD-X %s (%s bit, %s) %s +\n", version_name, version_arch, version_ostype, pad[pad_idx]); + # printf(" + Support: mad@cern.ch, http://cern.ch/mad +\n"); + # printf(" + Release date: %s +\n", version_date); + # printf(" + Execution date: %04d.%02d.%02d %02d:%02d:%02d +\n", + # tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday, + # tm->tm_hour, tm->tm_min, tm->tm_sec); + # printf(" ++++++++++++++++++++++++++++++++++++++++++++\n"); + # if (interactive) putchar('\n'); + return None + + +def madx_input(top): + # TODO: Implement normal madx_input + # TODO: Implement dynamic metadata lists + # { + # fputs("This is where STDOUT is", stdout); + # if (interactive && in->curr == 0) fputs("X:> ", stdout); + # if (return_flag || get_stmt(in->input_files[in->curr], 0) == 0) + # { + # if (in->input_files[in->curr] != stdin) { + # fclose(in->input_files[in->curr]); + # in->input_files[in->curr] = 0; + # } + # if (in->curr == 0) + # return; + # else + # in->curr -= 1; + # return_flag = 0; + # if (in->curr == top) return; + # } + # else + # { + # stolower_nq(in->buffers[in->curr]->c_a->c); + # pro_input(in->buffers[in->curr]->c_a->c); + # if (stop_flag) return; + # } + # } + return None + + +def madx_finish(): + # TODO: Implement normal madx_finish + # TODO: Implement MadX-ImpactX Interface by dumping lists + # int warn_numb, warn_numbf, nwarnings; + # + # /* should work with Lahey on windows 24.03.2004 */ + # + # match2_delete_expressions(); + # match2_delete_arrays(); + # + # if (final_message == 0) + # { + # final_message = 1; + # if (plots_made) + # { + # gxterm_(); + # } + # mad_err_getwarn(&warn_numb, &warn_numbf); + # nwarnings = warn_numb + warn_numbf; + # printf("\n Number of warnings: %d\n",nwarnings); + # if (nwarnings > 0) + # { + # printf("%d in C and %d in Fortran\n",warn_numb,warn_numbf); + # } + # if (get_option("trace")) time_stamp("end"); + # + # // printf("poly-mul= %llu\n", poly_mul_count); + # + # printf("\n" + # " ++++++++++++++++++++++++++++++++++++++++++++\n"); + # printf(" + MAD-X finished normally +\n"); + # printf(" ++++++++++++++++++++++++++++++++++++++++++++\n"); + # } + return None diff --git a/src/madx/mad_gvar.py b/src/madx/mad_gvar.py new file mode 100644 index 000000000..39ba96a46 --- /dev/null +++ b/src/madx/mad_gvar.py @@ -0,0 +1,14 @@ +class GlobalVariable: + def __init__(self): + self.variable_list = None + self.beam_list = None + self.table_deselect = None + self.table_select = None + self.defined_commands = None + self.stored_commands = None + self.line_list = None + self.macro_list = None + self.base_type_list = None + self.element_list = None + self.selected_elements = None + diff --git a/src/madx/mad_main.py b/src/madx/mad_main.py new file mode 100644 index 000000000..e8cc11d85 --- /dev/null +++ b/src/madx/mad_main.py @@ -0,0 +1,19 @@ +from mad_core import * +import mad_gvar + + +def mad_init(): + madx_start(gvar) + +# TODO: Redefine function to take in gvar and filepath argument instead of int +def mad_run(gvar, file=0): + madx_input(file) + +def mad_finish(gvar): + madx_finish() + + +gvar = mad_gvar.GlobalVariable() +mad_init() +mad_run() +mad_finish() \ No newline at end of file From 107a68a15fb549088f4671b73dd833ead849b63a Mon Sep 17 00:00:00 2001 From: Joey Zhu Date: Tue, 4 Oct 2022 15:16:27 -0700 Subject: [PATCH 05/12] Reorganize files into directories, implement core/global interpreter infrastructure: - mad_core: madx_input --- src/madx/README.md | 5 +- src/madx/mad_core.py | 59 +++++++++++---------- src/madx/mad_main.py | 18 ++++--- src/madx/{ => objects}/mad_cmd.py | 0 src/madx/{ => objects}/mad_elem.py | 0 src/madx/{ => objects}/mad_gvar.py | 3 ++ src/madx/{ => objects}/mad_macro.py | 0 src/madx/{ => objects}/mad_var.py | 0 src/madx/utils/mad_str.py | 80 +++++++++++++++++++++++++++++ 9 files changed, 125 insertions(+), 40 deletions(-) rename src/madx/{ => objects}/mad_cmd.py (100%) rename src/madx/{ => objects}/mad_elem.py (100%) rename src/madx/{ => objects}/mad_gvar.py (86%) rename src/madx/{ => objects}/mad_macro.py (100%) rename src/madx/{ => objects}/mad_var.py (100%) create mode 100644 src/madx/utils/mad_str.py diff --git a/src/madx/README.md b/src/madx/README.md index 440425f36..37b6c3a81 100644 --- a/src/madx/README.md +++ b/src/madx/README.md @@ -11,5 +11,6 @@ volume of code. - Elements - Macros (Lines) -### Removed Functionalities -- Fortran90 interface \ No newline at end of file +### Removed/Changed Functionalities +- stdin stdout char buffers are replaced with Python file read +- Removed Fortran90 interface \ No newline at end of file diff --git a/src/madx/mad_core.py b/src/madx/mad_core.py index 54ad259d2..3eb9b082d 100644 --- a/src/madx/mad_core.py +++ b/src/madx/mad_core.py @@ -1,10 +1,12 @@ # include # include "madx.h" -from mad_var import * -from mad_elem import * -from mad_macro import * -from mad_cmd import * +from src.madx.objects.mad_var import * +from src.madx.objects.mad_elem import * +from src.madx.objects.mad_macro import * +from src.madx.objects.mad_cmd import * + +from src.madx.utils.mad_str import * def mad_init_c(gvar): @@ -143,36 +145,33 @@ def madx_start(gvar): return None -def madx_input(top): - # TODO: Implement normal madx_input +def madx_input(filename, gvar): # TODO: Implement dynamic metadata lists - # { - # fputs("This is where STDOUT is", stdout); - # if (interactive && in->curr == 0) fputs("X:> ", stdout); - # if (return_flag || get_stmt(in->input_files[in->curr], 0) == 0) - # { - # if (in->input_files[in->curr] != stdin) { - # fclose(in->input_files[in->curr]); - # in->input_files[in->curr] = 0; - # } - # if (in->curr == 0) - # return; - # else - # in->curr -= 1; - # return_flag = 0; - # if (in->curr == top) return; - # } - # else - # { - # stolower_nq(in->buffers[in->curr]->c_a->c); - # pro_input(in->buffers[in->curr]->c_a->c); - # if (stop_flag) return; - # } - # } + + # The original MadX file uses charbuffers, but in the Python version we want to keep + # implementation simple with filenames and char lists, and whatever equivalent looping + # logic. We assume that given ImpactX's use case, there is only one case for the input: + # That is, anything and everything is in file_content, so we don't have to do any buffer logic. + file_content = [] + with open(filename, 'r') as f: + file_content += [f.read()] + i = 0 + in_stop = False + while not in_stop: + stolower_nq(file_content, i) + + # TODO: Figure out exactly where pro_input is defined. This is the entry point into the interpreter logic + # pro_input(file_content, i) + if gvar.stop_flag: + return + + in_stop = i < len(file_content) + i += 1 # whenever a buffer char is popped for interpreter + return None -def madx_finish(): +def madx_finish(gvar): # TODO: Implement normal madx_finish # TODO: Implement MadX-ImpactX Interface by dumping lists # int warn_numb, warn_numbf, nwarnings; diff --git a/src/madx/mad_main.py b/src/madx/mad_main.py index e8cc11d85..7a15e9d21 100644 --- a/src/madx/mad_main.py +++ b/src/madx/mad_main.py @@ -1,19 +1,21 @@ from mad_core import * -import mad_gvar +from src.madx.objects import mad_gvar -def mad_init(): +def mad_init(gvar): madx_start(gvar) + # TODO: Redefine function to take in gvar and filepath argument instead of int def mad_run(gvar, file=0): - madx_input(file) + madx_input(file, gvar) + def mad_finish(gvar): - madx_finish() + madx_finish(gvar) -gvar = mad_gvar.GlobalVariable() -mad_init() -mad_run() -mad_finish() \ No newline at end of file +global_variable = mad_gvar.GlobalVariable() +mad_init(global_variable) +mad_run(global_variable) +mad_finish(global_variable) diff --git a/src/madx/mad_cmd.py b/src/madx/objects/mad_cmd.py similarity index 100% rename from src/madx/mad_cmd.py rename to src/madx/objects/mad_cmd.py diff --git a/src/madx/mad_elem.py b/src/madx/objects/mad_elem.py similarity index 100% rename from src/madx/mad_elem.py rename to src/madx/objects/mad_elem.py diff --git a/src/madx/mad_gvar.py b/src/madx/objects/mad_gvar.py similarity index 86% rename from src/madx/mad_gvar.py rename to src/madx/objects/mad_gvar.py index 39ba96a46..b15c9e9e4 100644 --- a/src/madx/mad_gvar.py +++ b/src/madx/objects/mad_gvar.py @@ -12,3 +12,6 @@ def __init__(self): self.element_list = None self.selected_elements = None + self.return_flag = False + self.stop_flag = False + diff --git a/src/madx/mad_macro.py b/src/madx/objects/mad_macro.py similarity index 100% rename from src/madx/mad_macro.py rename to src/madx/objects/mad_macro.py diff --git a/src/madx/mad_var.py b/src/madx/objects/mad_var.py similarity index 100% rename from src/madx/mad_var.py rename to src/madx/objects/mad_var.py diff --git a/src/madx/utils/mad_str.py b/src/madx/utils/mad_str.py new file mode 100644 index 000000000..a2ef05206 --- /dev/null +++ b/src/madx/utils/mad_str.py @@ -0,0 +1,80 @@ +def myatof(input): + return None + +def mycpy(sout, sin): + return None + +def mystrchr(input, c): + return None + +def mystrcpy(target, source): + return None + +def mystrstr(string, s): + return None + +def myrepl(char_in, char_out, string_in, string_out): + return None + +def mysplit(buf, list): + return None + + + +def conv_char(string, tint): + return None + +def stolower_nq(string, i): + return string + +def strip(name): + return None + +def supp_lt(inbuf, flag): + return 0 + +def supp_mul_char(c, string): + return None + +# Suppress trailing blanks in string +def supp_tb(string): + return None + +# Return whether String defaults to 0 +def zero_string(string): + return False + +# Copy string to allocated buffer, strdump +def tmpbuff(string): + return string + +def buffer(string): + return tmpbuff(string) + +def permbuff(string): + return buffer(string) + +def join(it_list, n): + return "" + +def join_b(it_list, n): + return "" + +def next_non_blank(string): + return '' + +def next_non_blank_pos(string): + return 0 + +def noquote(string): + return string + +def quote_level(string, send): + return 0 + +def square_to_colon(string): + return 0 + +def slash_to_bkslash(string): + return string + From 582258d408bd0528470a20137c794183c16de701 Mon Sep 17 00:00:00 2001 From: Joey Zhu Date: Tue, 4 Oct 2022 15:23:25 -0700 Subject: [PATCH 06/12] Finish organizing mad_core infrastructure --- src/madx/mad_core.py | 71 ++++++++++---------------------------------- 1 file changed, 15 insertions(+), 56 deletions(-) diff --git a/src/madx/mad_core.py b/src/madx/mad_core.py index 3eb9b082d..2360b3f32 100644 --- a/src/madx/mad_core.py +++ b/src/madx/mad_core.py @@ -117,36 +117,13 @@ def mad_init_c(gvar): def madx_start(gvar): - # TODO: Implement normal madx_start mad_init_c(gvar) - time = None - # /* setbuf(stdout,(char *)0); */ /* no buffering - for debugging */ - # time(&start_time); /* initialize timing */ - # tm = localtime(&start_time); /* split system time */ - # last_time = start_time; - - # // compute padding of OSTYPE - # const char *pad[] = { "", " ", " ", " " }; - # const int pad_sz = sizeof pad/sizeof *pad; - # int pad_idx = strlen("Windows")-strlen(version_ostype); - # if (pad_idx >= pad_sz) pad_idx = pad_sz-1; - - # printf("\n ++++++++++++++++++++++++++++++++++++++++++++\n"); - # printf(" + MAD-X %s (%s bit, %s) %s +\n", version_name, version_arch, version_ostype, pad[pad_idx]); - # printf(" + Support: mad@cern.ch, http://cern.ch/mad +\n"); - # printf(" + Release date: %s +\n", version_date); - # printf(" + Execution date: %04d.%02d.%02d %02d:%02d:%02d +\n", - # tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday, - # tm->tm_hour, tm->tm_min, tm->tm_sec); - # printf(" ++++++++++++++++++++++++++++++++++++++++++++\n"); - # if (interactive) putchar('\n'); return None def madx_input(filename, gvar): - # TODO: Implement dynamic metadata lists # The original MadX file uses charbuffers, but in the Python version we want to keep # implementation simple with filenames and char lists, and whatever equivalent looping @@ -158,9 +135,11 @@ def madx_input(filename, gvar): i = 0 in_stop = False while not in_stop: + # TODO: Implement dynamic metadata lists + # We don't need line numbers per se, just the order of buffer consumption is enough for metadata. stolower_nq(file_content, i) - # TODO: Figure out exactly where pro_input is defined. This is the entry point into the interpreter logic + # TODO: Figure out exactly where pro_input is defined. This is the entry point into the interpreter logic but isn't clearly defined in the source code. # pro_input(file_content, i) if gvar.stop_flag: return @@ -172,36 +151,16 @@ def madx_input(filename, gvar): def madx_finish(gvar): - # TODO: Implement normal madx_finish - # TODO: Implement MadX-ImpactX Interface by dumping lists - # int warn_numb, warn_numbf, nwarnings; - # - # /* should work with Lahey on windows 24.03.2004 */ - # - # match2_delete_expressions(); - # match2_delete_arrays(); - # - # if (final_message == 0) - # { - # final_message = 1; - # if (plots_made) - # { - # gxterm_(); - # } - # mad_err_getwarn(&warn_numb, &warn_numbf); - # nwarnings = warn_numb + warn_numbf; - # printf("\n Number of warnings: %d\n",nwarnings); - # if (nwarnings > 0) - # { - # printf("%d in C and %d in Fortran\n",warn_numb,warn_numbf); - # } - # if (get_option("trace")) time_stamp("end"); - # - # // printf("poly-mul= %llu\n", poly_mul_count); - # - # printf("\n" - # " ++++++++++++++++++++++++++++++++++++++++++++\n"); - # printf(" + MAD-X finished normally +\n"); - # printf(" ++++++++++++++++++++++++++++++++++++++++++++\n"); - # } + for variable in gvar.variable_list: + # TODO: Convert variable into ImpactX known type and add to other lists + variable = variable + + for element in gvar.el_list: + # TODO: Convert element into ImpactX known type and add to other lists + element = element + + for line in gvar.line_list: + # TODO: Convert line into ImpactX known type and add to other lists + line = line + return None From ecc22c7cc51f4a82561aed1ce612d1e6d67497fd Mon Sep 17 00:00:00 2001 From: Joey Zhu Date: Tue, 4 Oct 2022 15:28:05 -0700 Subject: [PATCH 07/12] Finish organizing mad_core infrastructure, re-organized TODOs --- src/madx/README.md | 5 ++++- src/madx/mad_core.py | 1 - src/madx/mad_main.py | 1 - src/madx/objects/mad_cmd.py | 4 +--- src/madx/objects/mad_elem.py | 1 + src/madx/objects/mad_gvar.py | 1 + src/madx/objects/mad_macro.py | 1 + src/madx/objects/mad_var.py | 3 +-- src/madx/utils/mad_str.py | 1 + 9 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/madx/README.md b/src/madx/README.md index 37b6c3a81..4d3e5ef12 100644 --- a/src/madx/README.md +++ b/src/madx/README.md @@ -13,4 +13,7 @@ volume of code. ### Removed/Changed Functionalities - stdin stdout char buffers are replaced with Python file read -- Removed Fortran90 interface \ No newline at end of file +- Removed Fortran90 interface + +### Other dev notes +- Execution begins at mad_main.py \ No newline at end of file diff --git a/src/madx/mad_core.py b/src/madx/mad_core.py index 2360b3f32..8c534bdd9 100644 --- a/src/madx/mad_core.py +++ b/src/madx/mad_core.py @@ -10,7 +10,6 @@ def mad_init_c(gvar): - # TODO: Implement subset of mad_init_c # allocate variable ptr ione = 1 diff --git a/src/madx/mad_main.py b/src/madx/mad_main.py index 7a15e9d21..5dfc50bc3 100644 --- a/src/madx/mad_main.py +++ b/src/madx/mad_main.py @@ -6,7 +6,6 @@ def mad_init(gvar): madx_start(gvar) -# TODO: Redefine function to take in gvar and filepath argument instead of int def mad_run(gvar, file=0): madx_input(file, gvar) diff --git a/src/madx/objects/mad_cmd.py b/src/madx/objects/mad_cmd.py index b4b70475d..7824c1e97 100644 --- a/src/madx/objects/mad_cmd.py +++ b/src/madx/objects/mad_cmd.py @@ -1,3 +1,4 @@ +# TODO: Implement on-demand class Command: def __init__(self, name, module, group, stamp, link_type, mad8_type, beam_def, par_names, par): self.name = name @@ -19,7 +20,6 @@ def __init__(self, name, max_length): self.max_length = max_length def add_var(self, var): - # TODO: add separately for names self.lst += [var] @@ -30,11 +30,9 @@ def __init__(self, max_length): self.max_length = max_length def add_var(self, var): - # TODO: add separately for names self.lst += [var] -# TODO: Implement functions as needed # Interface def new_command(name, nl_length, pl_length, module, group, link, mad_8): return None diff --git a/src/madx/objects/mad_elem.py b/src/madx/objects/mad_elem.py index 08b3b1148..c38c73bbb 100644 --- a/src/madx/objects/mad_elem.py +++ b/src/madx/objects/mad_elem.py @@ -1,3 +1,4 @@ +# TODO: Implement on-demand class Element: def __init__(self, name, def_type, bv, length, defi, parent, stamp, base_type, aperture, multipole): self.name = name diff --git a/src/madx/objects/mad_gvar.py b/src/madx/objects/mad_gvar.py index b15c9e9e4..99abd5e25 100644 --- a/src/madx/objects/mad_gvar.py +++ b/src/madx/objects/mad_gvar.py @@ -1,3 +1,4 @@ +# TODO: Implement on-demand class GlobalVariable: def __init__(self): self.variable_list = None diff --git a/src/madx/objects/mad_macro.py b/src/madx/objects/mad_macro.py index 81b1961fb..bfc1206a4 100644 --- a/src/madx/objects/mad_macro.py +++ b/src/madx/objects/mad_macro.py @@ -1,3 +1,4 @@ +# TODO: Implement on-demand class Macro: def __init__(self, name, n_formal, dead, formal, tokens, body, stamp, original): self.name = name diff --git a/src/madx/objects/mad_var.py b/src/madx/objects/mad_var.py index 46e9cdc02..ec35af110 100644 --- a/src/madx/objects/mad_var.py +++ b/src/madx/objects/mad_var.py @@ -1,3 +1,4 @@ +# TODO: Implement on-demand class Constant: def __init__(self, name, expr, value, stamp): self.name = name @@ -25,7 +26,6 @@ def add_var(self, var): self.lst += [var] -# TODO: Implement as needed def enter_variable(in_cmd): return None @@ -46,7 +46,6 @@ def delete_var_list(var_list): return None def add_to_var_list(var, var_list, flag): - # TODO: Re-implement placeholder function var flag var_list.add_var(var) def find_variable(name, var_list): diff --git a/src/madx/utils/mad_str.py b/src/madx/utils/mad_str.py index a2ef05206..89aae979e 100644 --- a/src/madx/utils/mad_str.py +++ b/src/madx/utils/mad_str.py @@ -25,6 +25,7 @@ def conv_char(string, tint): return None def stolower_nq(string, i): + # TODO: Implement this and other string processing algorithms as needed return string def strip(name): From db52b8ea2abd3672849215cc56bb71cdb7d11231 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 4 Oct 2022 22:28:21 +0000 Subject: [PATCH 08/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/madx/README.md | 2 +- src/madx/mad_core.py | 9 ++++----- src/madx/mad_main.py | 1 + src/madx/objects/mad_cmd.py | 27 ++++++++++++++++++++++++--- src/madx/objects/mad_elem.py | 35 +++++++++++++++++++++++++++++------ src/madx/objects/mad_gvar.py | 1 - src/madx/objects/mad_macro.py | 10 ++++++++-- src/madx/objects/mad_var.py | 18 +++++++++++++----- src/madx/utils/mad_str.py | 27 ++++++++++++++++++++++++--- 9 files changed, 104 insertions(+), 26 deletions(-) diff --git a/src/madx/README.md b/src/madx/README.md index 4d3e5ef12..f2d3716e3 100644 --- a/src/madx/README.md +++ b/src/madx/README.md @@ -16,4 +16,4 @@ volume of code. - Removed Fortran90 interface ### Other dev notes -- Execution begins at mad_main.py \ No newline at end of file +- Execution begins at mad_main.py diff --git a/src/madx/mad_core.py b/src/madx/mad_core.py index 8c534bdd9..22cdd1b3a 100644 --- a/src/madx/mad_core.py +++ b/src/madx/mad_core.py @@ -1,11 +1,10 @@ # include # include "madx.h" -from src.madx.objects.mad_var import * +from src.madx.objects.mad_cmd import * from src.madx.objects.mad_elem import * from src.madx.objects.mad_macro import * -from src.madx.objects.mad_cmd import * - +from src.madx.objects.mad_var import * from src.madx.utils.mad_str import * @@ -78,7 +77,7 @@ def mad_init_c(gvar): # all_table_lists = new_table_list_list(10); /* dynamic */ # # Initialize needed work for commands - var = new_variable("twiss_tol", 1.e-6, 1, 1, None, None) + var = new_variable("twiss_tol", 1.0e-6, 1, 1, None, None) add_to_var_list(var, gvar.variable_list, 1) # title = permbuff("no-title"); # set_defaults("option"); @@ -129,7 +128,7 @@ def madx_input(filename, gvar): # logic. We assume that given ImpactX's use case, there is only one case for the input: # That is, anything and everything is in file_content, so we don't have to do any buffer logic. file_content = [] - with open(filename, 'r') as f: + with open(filename, "r") as f: file_content += [f.read()] i = 0 in_stop = False diff --git a/src/madx/mad_main.py b/src/madx/mad_main.py index 5dfc50bc3..a8450c46b 100644 --- a/src/madx/mad_main.py +++ b/src/madx/mad_main.py @@ -1,4 +1,5 @@ from mad_core import * + from src.madx.objects import mad_gvar diff --git a/src/madx/objects/mad_cmd.py b/src/madx/objects/mad_cmd.py index 7824c1e97..98ef9a3df 100644 --- a/src/madx/objects/mad_cmd.py +++ b/src/madx/objects/mad_cmd.py @@ -1,6 +1,8 @@ # TODO: Implement on-demand class Command: - def __init__(self, name, module, group, stamp, link_type, mad8_type, beam_def, par_names, par): + def __init__( + self, name, module, group, stamp, link_type, mad8_type, beam_def, par_names, par + ): self.name = name self.module = module self.group = group @@ -37,15 +39,19 @@ def add_var(self, var): def new_command(name, nl_length, pl_length, module, group, link, mad_8): return None + def delete_command(command): return None + def clone_command(command): return None + def clone_command_flat(command): return None + def find_command(name, command_list): return None @@ -54,21 +60,27 @@ def find_command(name, command_list): def new_command_list(name, max_length): return CommandList(name, max_length) + def delete_command_list(command_list): return None + def find_command_list(name, command_list_list): return None + def grow_command_list(command_list): return None + def add_to_command_list(label, command, command_list, flag): return None + def new_command_list_list(max_length): return CommandListList(max_length) + def add_to_command_list_list(label, command_list, command_list_list): return None @@ -77,29 +89,38 @@ def add_to_command_list_list(label, command_list, command_list_list): def exec_command(): return None + def decode_command(): return None -def dump_command(command): # For Debugging + +def dump_command(command): # For Debugging return None + def print_command(command): return None -def store_command_def(): # Processes command definition + +def store_command_def(): # Processes command definition return None + def make_line(statement): return None + def get_stmt(file, supp_flag): return None + def get_defined_commands(): return None + def remove_from_command_list(label, command_list): return None + def exec_add_expression(in_cmd): return None diff --git a/src/madx/objects/mad_elem.py b/src/madx/objects/mad_elem.py index c38c73bbb..178158621 100644 --- a/src/madx/objects/mad_elem.py +++ b/src/madx/objects/mad_elem.py @@ -1,6 +1,18 @@ # TODO: Implement on-demand class Element: - def __init__(self, name, def_type, bv, length, defi, parent, stamp, base_type, aperture, multipole): + def __init__( + self, + name, + def_type, + bv, + length, + defi, + parent, + stamp, + base_type, + aperture, + multipole, + ): self.name = name self.def_type = def_type self.bv = bv @@ -12,6 +24,7 @@ def __init__(self, name, def_type, bv, length, defi, parent, stamp, base_type, a self.aperture = aperture self.multipole = multipole + class ElementList: def __init__(self, max_length): self.lst = [] @@ -24,15 +37,19 @@ def add_var(self, var): def make_element(name, parent, command, flag): return None + def clone_element(element): return None + def delete_element(element): return None + def update_element(element, update_command): return None + def update_element_children(element, update_command): return None @@ -40,9 +57,11 @@ def update_element_children(element, update_command): def dump_element(element): return None + def export_el_def(element, string, noexpr): return None + def export_el_def_8(element, string, noexpr): return None @@ -50,15 +69,19 @@ def export_el_def_8(element, string, noexpr): def new_el_list(max_length): return ElementList(max_length) + def delete_el_list(el_list): return None + def find_element(name, el_list): return None + def write_elems(el_list, command_list, file, noexpr): return None + def write_elems_8(el_list, command_list, file): return None @@ -66,9 +89,11 @@ def write_elems_8(el_list, command_list, file): def new_elem_node(element, occ_cnt): return None + def make_elem_node(element, occ_cnt): return None + def compound(e_name, occ_cnt): return None @@ -76,16 +101,14 @@ def compound(e_name, occ_cnt): def enter_element(in_cmd): return None + def element_name(name, l): return None + def element_value(node, params): return None + def element_vector(element, params, vector): return None - - - - - diff --git a/src/madx/objects/mad_gvar.py b/src/madx/objects/mad_gvar.py index 99abd5e25..2c59fc473 100644 --- a/src/madx/objects/mad_gvar.py +++ b/src/madx/objects/mad_gvar.py @@ -15,4 +15,3 @@ def __init__(self): self.return_flag = False self.stop_flag = False - diff --git a/src/madx/objects/mad_macro.py b/src/madx/objects/mad_macro.py index bfc1206a4..3e317cb6d 100644 --- a/src/madx/objects/mad_macro.py +++ b/src/madx/objects/mad_macro.py @@ -20,27 +20,33 @@ def add_var(self, var): self.lst += [var] - def make_macro(statemenet): return None + def new_macro(n_formal, length, p_length): return None + def new_macro_list(max_length): return MacroList(max_length) + def add_to_macro_list(macro, macro_list): return None + def disable_line(name, macro_list): return None + def replace_lines(macro, replace, reps): return None + def save_macros2file(): return None + def exec_macro(in_cmd, pos): - return None \ No newline at end of file + return None diff --git a/src/madx/objects/mad_var.py b/src/madx/objects/mad_var.py index ec35af110..17cedc518 100644 --- a/src/madx/objects/mad_var.py +++ b/src/madx/objects/mad_var.py @@ -29,9 +29,11 @@ def add_var(self, var): def enter_variable(in_cmd): return None + def new_variable(name, val, val_type, typ, expression, string): return Variable(name, val, val_type, typ, expression, string) + def variable_value(var): return None @@ -39,15 +41,19 @@ def variable_value(var): def new_var_list(max_length): return VariableList(max_length) + def clone_var_list(var_list): return None + def delete_var_list(var_list): return None + def add_to_var_list(var, var_list, flag): var_list.add_var(var) + def find_variable(name, var_list): return None @@ -55,28 +61,30 @@ def find_variable(name, var_list): def make_string_variable(string): return None + def write_vars(var_list, command_list, file, noexpr): return None + def write_vars_8(var_list, command_list, file): return None + def set_variable(name, value): return None + def set_stringvar(name, string): return None + def get_variable(name): return None + def get_varstring(name): return None + def get_defined_constants(): return None - - - - - diff --git a/src/madx/utils/mad_str.py b/src/madx/utils/mad_str.py index 89aae979e..d46caedfa 100644 --- a/src/madx/utils/mad_str.py +++ b/src/madx/utils/mad_str.py @@ -1,81 +1,102 @@ def myatof(input): return None + def mycpy(sout, sin): return None + def mystrchr(input, c): return None + def mystrcpy(target, source): return None + def mystrstr(string, s): return None + def myrepl(char_in, char_out, string_in, string_out): return None + def mysplit(buf, list): return None - def conv_char(string, tint): return None + def stolower_nq(string, i): # TODO: Implement this and other string processing algorithms as needed return string + def strip(name): return None + def supp_lt(inbuf, flag): return 0 + def supp_mul_char(c, string): return None + # Suppress trailing blanks in string def supp_tb(string): return None + # Return whether String defaults to 0 def zero_string(string): return False + # Copy string to allocated buffer, strdump def tmpbuff(string): return string + def buffer(string): return tmpbuff(string) + def permbuff(string): return buffer(string) + def join(it_list, n): return "" + def join_b(it_list, n): return "" + def next_non_blank(string): - return '' + return "" + def next_non_blank_pos(string): return 0 + def noquote(string): return string + def quote_level(string, send): return 0 + def square_to_colon(string): return 0 + def slash_to_bkslash(string): return string - From e199d3bc938697e6ab06763f217278d442f005f4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 4 Oct 2022 22:28:21 +0000 Subject: [PATCH 09/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/madx/README.md | 2 +- src/madx/mad_core.py | 9 ++++----- src/madx/mad_main.py | 1 + src/madx/objects/mad_cmd.py | 27 ++++++++++++++++++++++++--- src/madx/objects/mad_elem.py | 35 +++++++++++++++++++++++++++++------ src/madx/objects/mad_gvar.py | 1 - src/madx/objects/mad_macro.py | 10 ++++++++-- src/madx/objects/mad_var.py | 18 +++++++++++++----- src/madx/utils/mad_str.py | 29 ++++++++++++++++++++++++++--- 9 files changed, 106 insertions(+), 26 deletions(-) diff --git a/src/madx/README.md b/src/madx/README.md index 4d3e5ef12..f2d3716e3 100644 --- a/src/madx/README.md +++ b/src/madx/README.md @@ -16,4 +16,4 @@ volume of code. - Removed Fortran90 interface ### Other dev notes -- Execution begins at mad_main.py \ No newline at end of file +- Execution begins at mad_main.py diff --git a/src/madx/mad_core.py b/src/madx/mad_core.py index 8c534bdd9..22cdd1b3a 100644 --- a/src/madx/mad_core.py +++ b/src/madx/mad_core.py @@ -1,11 +1,10 @@ # include # include "madx.h" -from src.madx.objects.mad_var import * +from src.madx.objects.mad_cmd import * from src.madx.objects.mad_elem import * from src.madx.objects.mad_macro import * -from src.madx.objects.mad_cmd import * - +from src.madx.objects.mad_var import * from src.madx.utils.mad_str import * @@ -78,7 +77,7 @@ def mad_init_c(gvar): # all_table_lists = new_table_list_list(10); /* dynamic */ # # Initialize needed work for commands - var = new_variable("twiss_tol", 1.e-6, 1, 1, None, None) + var = new_variable("twiss_tol", 1.0e-6, 1, 1, None, None) add_to_var_list(var, gvar.variable_list, 1) # title = permbuff("no-title"); # set_defaults("option"); @@ -129,7 +128,7 @@ def madx_input(filename, gvar): # logic. We assume that given ImpactX's use case, there is only one case for the input: # That is, anything and everything is in file_content, so we don't have to do any buffer logic. file_content = [] - with open(filename, 'r') as f: + with open(filename, "r") as f: file_content += [f.read()] i = 0 in_stop = False diff --git a/src/madx/mad_main.py b/src/madx/mad_main.py index 5dfc50bc3..a8450c46b 100644 --- a/src/madx/mad_main.py +++ b/src/madx/mad_main.py @@ -1,4 +1,5 @@ from mad_core import * + from src.madx.objects import mad_gvar diff --git a/src/madx/objects/mad_cmd.py b/src/madx/objects/mad_cmd.py index 7824c1e97..98ef9a3df 100644 --- a/src/madx/objects/mad_cmd.py +++ b/src/madx/objects/mad_cmd.py @@ -1,6 +1,8 @@ # TODO: Implement on-demand class Command: - def __init__(self, name, module, group, stamp, link_type, mad8_type, beam_def, par_names, par): + def __init__( + self, name, module, group, stamp, link_type, mad8_type, beam_def, par_names, par + ): self.name = name self.module = module self.group = group @@ -37,15 +39,19 @@ def add_var(self, var): def new_command(name, nl_length, pl_length, module, group, link, mad_8): return None + def delete_command(command): return None + def clone_command(command): return None + def clone_command_flat(command): return None + def find_command(name, command_list): return None @@ -54,21 +60,27 @@ def find_command(name, command_list): def new_command_list(name, max_length): return CommandList(name, max_length) + def delete_command_list(command_list): return None + def find_command_list(name, command_list_list): return None + def grow_command_list(command_list): return None + def add_to_command_list(label, command, command_list, flag): return None + def new_command_list_list(max_length): return CommandListList(max_length) + def add_to_command_list_list(label, command_list, command_list_list): return None @@ -77,29 +89,38 @@ def add_to_command_list_list(label, command_list, command_list_list): def exec_command(): return None + def decode_command(): return None -def dump_command(command): # For Debugging + +def dump_command(command): # For Debugging return None + def print_command(command): return None -def store_command_def(): # Processes command definition + +def store_command_def(): # Processes command definition return None + def make_line(statement): return None + def get_stmt(file, supp_flag): return None + def get_defined_commands(): return None + def remove_from_command_list(label, command_list): return None + def exec_add_expression(in_cmd): return None diff --git a/src/madx/objects/mad_elem.py b/src/madx/objects/mad_elem.py index c38c73bbb..178158621 100644 --- a/src/madx/objects/mad_elem.py +++ b/src/madx/objects/mad_elem.py @@ -1,6 +1,18 @@ # TODO: Implement on-demand class Element: - def __init__(self, name, def_type, bv, length, defi, parent, stamp, base_type, aperture, multipole): + def __init__( + self, + name, + def_type, + bv, + length, + defi, + parent, + stamp, + base_type, + aperture, + multipole, + ): self.name = name self.def_type = def_type self.bv = bv @@ -12,6 +24,7 @@ def __init__(self, name, def_type, bv, length, defi, parent, stamp, base_type, a self.aperture = aperture self.multipole = multipole + class ElementList: def __init__(self, max_length): self.lst = [] @@ -24,15 +37,19 @@ def add_var(self, var): def make_element(name, parent, command, flag): return None + def clone_element(element): return None + def delete_element(element): return None + def update_element(element, update_command): return None + def update_element_children(element, update_command): return None @@ -40,9 +57,11 @@ def update_element_children(element, update_command): def dump_element(element): return None + def export_el_def(element, string, noexpr): return None + def export_el_def_8(element, string, noexpr): return None @@ -50,15 +69,19 @@ def export_el_def_8(element, string, noexpr): def new_el_list(max_length): return ElementList(max_length) + def delete_el_list(el_list): return None + def find_element(name, el_list): return None + def write_elems(el_list, command_list, file, noexpr): return None + def write_elems_8(el_list, command_list, file): return None @@ -66,9 +89,11 @@ def write_elems_8(el_list, command_list, file): def new_elem_node(element, occ_cnt): return None + def make_elem_node(element, occ_cnt): return None + def compound(e_name, occ_cnt): return None @@ -76,16 +101,14 @@ def compound(e_name, occ_cnt): def enter_element(in_cmd): return None + def element_name(name, l): return None + def element_value(node, params): return None + def element_vector(element, params, vector): return None - - - - - diff --git a/src/madx/objects/mad_gvar.py b/src/madx/objects/mad_gvar.py index 99abd5e25..2c59fc473 100644 --- a/src/madx/objects/mad_gvar.py +++ b/src/madx/objects/mad_gvar.py @@ -15,4 +15,3 @@ def __init__(self): self.return_flag = False self.stop_flag = False - diff --git a/src/madx/objects/mad_macro.py b/src/madx/objects/mad_macro.py index bfc1206a4..3e317cb6d 100644 --- a/src/madx/objects/mad_macro.py +++ b/src/madx/objects/mad_macro.py @@ -20,27 +20,33 @@ def add_var(self, var): self.lst += [var] - def make_macro(statemenet): return None + def new_macro(n_formal, length, p_length): return None + def new_macro_list(max_length): return MacroList(max_length) + def add_to_macro_list(macro, macro_list): return None + def disable_line(name, macro_list): return None + def replace_lines(macro, replace, reps): return None + def save_macros2file(): return None + def exec_macro(in_cmd, pos): - return None \ No newline at end of file + return None diff --git a/src/madx/objects/mad_var.py b/src/madx/objects/mad_var.py index ec35af110..17cedc518 100644 --- a/src/madx/objects/mad_var.py +++ b/src/madx/objects/mad_var.py @@ -29,9 +29,11 @@ def add_var(self, var): def enter_variable(in_cmd): return None + def new_variable(name, val, val_type, typ, expression, string): return Variable(name, val, val_type, typ, expression, string) + def variable_value(var): return None @@ -39,15 +41,19 @@ def variable_value(var): def new_var_list(max_length): return VariableList(max_length) + def clone_var_list(var_list): return None + def delete_var_list(var_list): return None + def add_to_var_list(var, var_list, flag): var_list.add_var(var) + def find_variable(name, var_list): return None @@ -55,28 +61,30 @@ def find_variable(name, var_list): def make_string_variable(string): return None + def write_vars(var_list, command_list, file, noexpr): return None + def write_vars_8(var_list, command_list, file): return None + def set_variable(name, value): return None + def set_stringvar(name, string): return None + def get_variable(name): return None + def get_varstring(name): return None + def get_defined_constants(): return None - - - - - diff --git a/src/madx/utils/mad_str.py b/src/madx/utils/mad_str.py index 89aae979e..aaab68ec3 100644 --- a/src/madx/utils/mad_str.py +++ b/src/madx/utils/mad_str.py @@ -1,81 +1,104 @@ def myatof(input): return None + def mycpy(sout, sin): return None + def mystrchr(input, c): return None + def mystrcpy(target, source): return None + def mystrstr(string, s): return None + def myrepl(char_in, char_out, string_in, string_out): return None + def mysplit(buf, list): return None - def conv_char(string, tint): return None + def stolower_nq(string, i): # TODO: Implement this and other string processing algorithms as needed return string + def strip(name): return None + def supp_lt(inbuf, flag): return 0 + def supp_mul_char(c, string): return None + # Suppress trailing blanks in string def supp_tb(string): return None + # Return whether String defaults to 0 def zero_string(string): return False + # Copy string to allocated buffer, strdump def tmpbuff(string): return string + def buffer(string): return tmpbuff(string) + def permbuff(string): return buffer(string) +def is_token(pb, string, string_length): + return False + def join(it_list, n): return "" + def join_b(it_list, n): return "" + def next_non_blank(string): - return '' + return "" + def next_non_blank_pos(string): return 0 + def noquote(string): return string + def quote_level(string, send): return 0 + def square_to_colon(string): return 0 + def slash_to_bkslash(string): return string - From bcf62f46f1b30f56fea165831a0cf8ca73ed394a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 4 Oct 2022 22:35:00 +0000 Subject: [PATCH 10/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/madx/utils/mad_str.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/madx/utils/mad_str.py b/src/madx/utils/mad_str.py index 38ea804da..0770cc605 100644 --- a/src/madx/utils/mad_str.py +++ b/src/madx/utils/mad_str.py @@ -69,6 +69,7 @@ def buffer(string): def permbuff(string): return buffer(string) + def is_token(pb, string, string_length): return False From 80fdde0745cfb7fc751abea37fdaa139672b423b Mon Sep 17 00:00:00 2001 From: Joey Zhu Date: Tue, 4 Oct 2022 15:43:27 -0700 Subject: [PATCH 11/12] add mad_eval file --- src/madx/interpreter/mad_eval.py | 4 ++++ src/madx/mad_core.py | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 src/madx/interpreter/mad_eval.py diff --git a/src/madx/interpreter/mad_eval.py b/src/madx/interpreter/mad_eval.py new file mode 100644 index 000000000..6acbaac05 --- /dev/null +++ b/src/madx/interpreter/mad_eval.py @@ -0,0 +1,4 @@ +def pro_input(file_content, i): + # TODO: This is where the parsing logic starts!!! + return None + diff --git a/src/madx/mad_core.py b/src/madx/mad_core.py index 22cdd1b3a..0cf0f8943 100644 --- a/src/madx/mad_core.py +++ b/src/madx/mad_core.py @@ -6,6 +6,7 @@ from src.madx.objects.mad_macro import * from src.madx.objects.mad_var import * from src.madx.utils.mad_str import * +from src.madx.interpreter.mad_eval import * def mad_init_c(gvar): @@ -137,8 +138,9 @@ def madx_input(filename, gvar): # We don't need line numbers per se, just the order of buffer consumption is enough for metadata. stolower_nq(file_content, i) - # TODO: Figure out exactly where pro_input is defined. This is the entry point into the interpreter logic but isn't clearly defined in the source code. - # pro_input(file_content, i) + # TODO: Figure out exactly where pro_input is defined. This is the entry point into the interpreter logic but + # isn't clearly defined in the source code. + pro_input(file_content, i) if gvar.stop_flag: return From 6671ac6db7aa78ff1f50df85c13f7e09c79dc5da Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 4 Oct 2022 22:43:56 +0000 Subject: [PATCH 12/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/madx/interpreter/mad_eval.py | 1 - src/madx/mad_core.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/madx/interpreter/mad_eval.py b/src/madx/interpreter/mad_eval.py index 6acbaac05..ffaa0e290 100644 --- a/src/madx/interpreter/mad_eval.py +++ b/src/madx/interpreter/mad_eval.py @@ -1,4 +1,3 @@ def pro_input(file_content, i): # TODO: This is where the parsing logic starts!!! return None - diff --git a/src/madx/mad_core.py b/src/madx/mad_core.py index 0cf0f8943..fc4bd8156 100644 --- a/src/madx/mad_core.py +++ b/src/madx/mad_core.py @@ -1,12 +1,12 @@ # include # include "madx.h" +from src.madx.interpreter.mad_eval import * from src.madx.objects.mad_cmd import * from src.madx.objects.mad_elem import * from src.madx.objects.mad_macro import * from src.madx.objects.mad_var import * from src.madx.utils.mad_str import * -from src.madx.interpreter.mad_eval import * def mad_init_c(gvar):