Example #1
0
def get_systematic_errors(model_twiss, num_simulations, num_processes, output_dir, errors_path, accelerator, energy, tunex, tuney):
    print "Started systematic error script, using " + str(num_processes) + " processes for " + str(num_simulations) + " simulations"
    model_dir_path = os.path.dirname(model_twiss)
    run_data_path = os.path.join(output_dir, "RUN_DATA")
    if accelerator.upper().startswith("LHCB"):
        if errors_path is None:
            beam = accelerator.upper().replace("LHC", "").replace("RUNII", "").replace("_2016", "")
            errors_path = os.path.join(CURRENT_PATH, "..", "..", "MODEL", "LHC" + beam, "dipole_b2_errors")
    elif accelerator.upper() in ["ALBA", "ESRF"]:
        if not errors_path is None:
            print >> sys.stdout, str(accelerator) + " doesn't need error tables, ignoring input"
    else:
        print >> sys.stderr, "No error table templates available for", accelerator, "specify an error tables path (--error-tables option)"
        sys.exit(-1)
    iotools.create_dirs(run_data_path)

    pool = multiprocessing.Pool(processes=num_processes)

    print "Running simulations..."
    start_time = time.time()
    times = _run_parallel_simulations(run_data_path, model_dir_path, num_simulations, errors_path, accelerator, energy, tunex, tuney, pool)
    _show_time_statistics(times)
    end_time = time.time()
    print "Done (" + str(end_time - start_time) + " seconds)\n"

    print "Calculating systematic error bars..."
    start_time = time.time()
    _parallel_get_systematic_errors_binary_file(model_twiss, run_data_path, output_dir, pool, num_simulations, num_processes)
    end_time = time.time()
    print "Done (" + str(end_time - start_time) + " seconds)\n"

    print "Cleaning output directory..."
    _create_summary(model_twiss, num_simulations, num_processes, output_dir, errors_path, accelerator, energy, tunex, tuney)
    iotools.delete_item(run_data_path)
    print "All done."
Example #2
0
    def _run_Segment_by_Segment_Match(self, output_path):
        print "Running Segment by Segment Match..."
        beam1path = ""
        beam2path = ""
        if "beam1" in output_path:
            beam1path = output_path
            beam2path = beam1path.replace("beam1", "beam2")
        if "beam2" in output_path:
            beam2path = output_path
            beam1path = beam2path.replace("beam2", "beam1")
        if os.path.isdir(os.path.join(beam1path, "sbs")) and os.path.isdir(
                os.path.join(beam2path, "sbs")):
            temp_dir = beam1path.replace("beam1", "match")
            iotools.create_dirs(temp_dir)
            self._sbs_match_output_paths.append(temp_dir)
            for ip in IP_SEGMENTS_TO_RUN:
                print "For IP" + str(ip) + "..."
                call_command = sys.executable + " " + os.path.abspath(self._path_to_sbs_match) + \
                " --ip " + str(ip) + \
                " --beam1 " + beam1path + \
                " --beam2 " + beam2path + \
                " --temp " + temp_dir
                self._run_outer_process(call_command,
                                        "Segment by Segment Match")
                iotools.copy_item(
                    os.path.join(temp_dir, "match", "changeparameters.madx"),
                    os.path.join(temp_dir,
                                 "changeparametersIP" + str(ip) + ".madx"))
                iotools.delete_item(os.path.join(temp_dir, "match"))

        else:
            print "No data for both beams yet."
Example #3
0
def run_drive(sdds_file_path, start_turn, end_turn, tune_x, tune_y,
              nat_tune_x=None, nat_tune_y=None, clean_up=False,
              stdout=None, stderr=None):
    output_path = os.path.abspath(os.path.dirname(sdds_file_path))
    driving_terms_path = _generate_driving_terms(sdds_file_path, output_path, start_turn, end_turn)
    drive_inp_path = _generate_drive_inp(output_path, tune_x, tune_y, nat_tune_x, nat_tune_y)
    _run_drive_exe(output_path, stdout, stderr)
    if clean_up:
        iotools.delete_item(driving_terms_path)
        iotools.delete_item(drive_inp_path)
Example #4
0
 def tearDown(self):
     if self._successful_test:
         to_check_dirs = iotools.get_all_dir_names_in_dir(self.path_to_check)
         for to_check_dir in to_check_dirs:
             directory_to_check = os.path.join(self.path_to_check, to_check_dir)
             input_arguments = " clean --temp=" + directory_to_check
             call_command = os.path.abspath(self.path_to_modified_sbs_match) + " " + input_arguments
             call_command = sys.executable + " " + call_command
             process = subprocess.Popen(call_command, shell=True)
             process.communicate()
             iotools.delete_item(directory_to_check)
         iotools.delete_item(os.path.join(self.path_to_check, "test_log.log"))
     else:
         print "Test wasn't successful, will not delete output"
Example #5
0
 def tearDown(self):
     try:
         os.unlink("ats")
         os.unlink("db")
         os.unlink("db5")
         os.unlink("ds")
     except:
         pass
     for output_path in self._output_paths:
         iotools.delete_item(output_path)
         pass
     for output_path in self._sbs_match_output_paths:
         iotools.delete_item(output_path)
         pass
Example #6
0
 def tearDown(self):
     try:
         os.unlink("ats")
         os.unlink("db")
         os.unlink("db5")
         os.unlink("ds")
     except:
         pass
     for output_path in self._output_paths:
         iotools.delete_item(output_path)
         pass
     for output_path in self._sbs_match_output_paths:
         iotools.delete_item(output_path)
         pass
Example #7
0
 def tearDown(self):
     if self._successful_test:
         to_check_dirs = iotools.get_all_dir_names_in_dir(
             self.path_to_check)
         for to_check_dir in to_check_dirs:
             directory_to_check = os.path.join(self.path_to_check,
                                               to_check_dir)
             input_arguments = " clean --temp=" + directory_to_check
             call_command = os.path.abspath(
                 self.path_to_modified_sbs_match) + " " + input_arguments
             call_command = sys.executable + " " + call_command
             process = subprocess.Popen(call_command, shell=True)
             process.communicate()
             iotools.delete_item(directory_to_check)
         iotools.delete_item(
             os.path.join(self.path_to_check, "test_log.log"))
     else:
         print "Test wasn't successful, will not delete output"
Example #8
0
def run_drive(sdds_file_path,
              start_turn,
              end_turn,
              tune_x,
              tune_y,
              nat_tune_x=None,
              nat_tune_y=None,
              clean_up=False,
              stdout=None,
              stderr=None,
              tune_window=0.01):
    output_path = os.path.abspath(os.path.dirname(sdds_file_path))
    driving_terms_path = _generate_driving_terms(sdds_file_path, output_path,
                                                 start_turn, end_turn)
    drive_inp_path = _generate_drive_inp(output_path, tune_x, tune_y,
                                         nat_tune_x, nat_tune_y, tune_window)
    _run_drive_exe(output_path, stdout, stderr)
    if clean_up:
        iotools.delete_item(driving_terms_path)
        iotools.delete_item(drive_inp_path)
Example #9
0
    def _run_Segment_by_Segment_Match(self, output_path):
        print "Running Segment by Segment Match..."
        beam1path = ""
        beam2path = ""
        if "beam1" in output_path:
            beam1path = output_path
            beam2path = beam1path.replace("beam1", "beam2")
        if "beam2" in output_path:
            beam2path = output_path
            beam1path = beam2path.replace("beam2", "beam1")
        if os.path.isdir(os.path.join(beam1path, "sbs")) and os.path.isdir(os.path.join(beam2path, "sbs")):
            temp_dir = beam1path.replace("beam1", "match")
            iotools.create_dirs(temp_dir)
            self._sbs_match_output_paths.append(temp_dir)
            for ip in IP_SEGMENTS_TO_RUN:
                print "For IP" + str(ip) + "..."
                call_command = (
                    sys.executable
                    + " "
                    + os.path.abspath(self._path_to_sbs_match)
                    + " --ip "
                    + str(ip)
                    + " --beam1 "
                    + beam1path
                    + " --beam2 "
                    + beam2path
                    + " --temp "
                    + temp_dir
                )
                self._run_outer_process(call_command, "Segment by Segment Match")
                iotools.copy_item(
                    os.path.join(temp_dir, "match", "changeparameters.madx"),
                    os.path.join(temp_dir, "changeparametersIP" + str(ip) + ".madx"),
                )
                iotools.delete_item(os.path.join(temp_dir, "match"))

        else:
            print "No data for both beams yet."
def _clean_up_files(ouput_dir):
    print('Cleaning up...')
    iotools.delete_item(ouput_dir)