示例#1
0
    def get_presolved_bounds(self) -> Union[Tuple[List[float]], None]:
        if not self.run_successful:
            raise Exception(
                "Papilo run failed, cannot retriece solved bounds!")
        out = OutputGrabber()

        with out:
            reader: FileReaderInterface = get_reader(self.output_file)
        return reader.get_var_bounds()
示例#2
0
def propagation_measure_run(input_file: str):
    print("\n========== Starting measure executions for the ", input_file,
          " file. ==========\n")
    out = OutputGrabber(sys.stderr)

    # with out:
    reader: FileReaderInterface = get_reader(input_file)

    n_cons = reader.get_n_cons()
    n_vars = reader.get_n_vars()
    nnz = reader.get_nnz()
    lbs, ubs = reader.get_var_bounds()
    lhss, rhss = reader.get_lrhss()
    coeffs, row_ptrs, col_indices = reader.get_cons_matrix()
    vartypes = reader.get_SCIP_vartypes()

    lbs = list(filter(lambda x: x < -1e20, lbs))
    ubs = list(filter(lambda x: x > 1e20, ubs))
    print("num inf: ", len(lbs) + len(ubs))
    exit(1)
    # print sparsity and input data size
    print("num vars: ", n_vars)
    print("num cons: ", n_cons)
    print("nnz     : ", nnz)

    lbs_seq = lbs_gpuatomic = lbs
    ubs_seq = ubs_gpuatomic = ubs

    (seq_new_lbs, seq_new_ubs) = propagateSequentialWithMeasure(
        n_vars, n_cons, nnz, col_indices, row_ptrs, coeffs, lhss, rhss,
        lbs_seq, ubs_seq, vartypes)

    (gpuatomic_new_lbs, gpuatomic_new_ubs) = propagateGPUAtomicWithMeasure(
        n_vars, n_cons, nnz, col_indices, row_ptrs, coeffs, lhss, rhss,
        lbs_gpuatomic, ubs_gpuatomic, vartypes)

    seq_new_lbs = normalize_infs(seq_new_lbs)
    seq_new_ubs = normalize_infs(seq_new_ubs)
    gpuatomic_new_lbs = normalize_infs(gpuatomic_new_lbs)
    gpuatomic_new_ubs = normalize_infs(gpuatomic_new_ubs)

    equal_seq_gpu_atomic = arrays_equal(seq_new_lbs,
                                        gpuatomic_new_lbs) and arrays_equal(
                                            seq_new_ubs, gpuatomic_new_ubs)
    print("cpu_seq to gpu_atomic results match: ", equal_seq_gpu_atomic)

    print(out.capturedtext)
    print("========== End measure executions for the ", input_file,
          " file. ==========\n")
示例#3
0
def propagation_measure_run(input_file: str):
    out = OutputGrabber()

    with out:
        reader: FileReaderInterface = get_reader(input_file)

        n_cons = reader.get_n_cons()
        n_vars = reader.get_n_vars()
        nnz = reader.get_nnz()
        lbs, ubs = reader.get_var_bounds()
        lhss, rhss = reader.get_lrhss()
        coeffs, row_ptrs, col_indices = reader.get_cons_matrix()
        vartypes = reader.get_SCIP_vartypes()

        # print sparsity and input data size
        print("num vars: ", n_vars)
        print("num cons: ", n_cons)
        print("nnz     : ", nnz)

        lbs_seq = lbs_gpuatomic = lbs
        ubs_seq = ubs_gpuatomic = ubs

        (seq_new_lbs, seq_new_ubs) = propagateSequentialWithMeasure(
            n_vars, n_cons, nnz, col_indices, row_ptrs, coeffs, lhss, rhss,
            lbs_seq, ubs_seq, vartypes)

        (gpuatomic_new_lbs, gpuatomic_new_ubs) = propagateGPUAtomicWithMeasure(
            n_vars, n_cons, nnz, col_indices, row_ptrs, coeffs, lhss, rhss,
            lbs_gpuatomic, ubs_gpuatomic, vartypes)

        seq_new_lbs = normalize_infs(seq_new_lbs)
        seq_new_ubs = normalize_infs(seq_new_ubs)
        gpuatomic_new_lbs = normalize_infs(gpuatomic_new_lbs)
        gpuatomic_new_ubs = normalize_infs(gpuatomic_new_ubs)

        equal_seq_gpu_atomic = arrays_equal(
            seq_new_lbs, gpuatomic_new_lbs) and arrays_equal(
                seq_new_ubs, gpuatomic_new_ubs)
        print("cpu_seq to gpu_atomic results match: ", equal_seq_gpu_atomic)

    print(out.capturedtext)

    plot_progress_save_pdf(out.capturedtext)
示例#4
0
def prop_compare_seq_gpu(lp_file_path: str,
                         datatype: _SimpleCData = c_double,
                         seed: int = 0,
                         synctype: int = 0) -> None:
    reader: FileReaderInterface = get_reader(lp_file_path)

    n_cons = reader.get_n_cons()
    n_vars = reader.get_n_vars()
    nnz = reader.get_nnz()
    lbs, ubs = reader.get_var_bounds()
    lhss, rhss = reader.get_lrhss()
    coeffs, row_ptrs, col_indices = reader.get_cons_matrix()
    vartypes = reader.get_SCIP_vartypes()

    #num_seeds = 5
    # for seed in range(num_seeds):
    #    print("\nRunning seed ", seed)
    if seed != 0:
        coeffs, col_indices, row_ptrs, lbs, ubs, lhss, rhss, vartypes = permute_mip(
            n_cons, n_vars, coeffs, col_indices, row_ptrs, lbs, ubs, lhss,
            rhss, vartypes, seed)

    exec_run(n_vars, n_cons, nnz, coeffs, col_indices, row_ptrs, lbs, ubs,
             lhss, rhss, vartypes, synctype)
示例#5
0
def papilo_comparison_run(lp_file_path: str,
                          papilo_path: str,
                          datatype: _SimpleCData = c_double) -> None:
    reader: FileReaderInterface = get_reader(lp_file_path)

    n_cons = reader.get_n_cons()
    n_vars = reader.get_n_vars()
    nnz = reader.get_nnz()
    lbs, ubs = reader.get_var_bounds()
    lhss, rhss = reader.get_lrhss()
    coeffs, row_ptrs, col_indices = reader.get_cons_matrix()
    vartypes = reader.get_SCIP_vartypes()

    # print sparsity and input data size
    print("num vars: ", n_vars)
    print("num cons: ", n_cons)
    print("nnz     : ", nnz)

    lbs_dis = lbs_seq = lbs_gpuatomic = lbs_gpu = lbs_omp = lbs
    ubs_dis = ubs_seq = ubs_gpuatomic = ubs_gpu = ubs_omp = ubs

    with OutputGrabber():
        (tmp_lbs, tmp_ubs) = propagateSequential(n_vars,
                                                 n_cons,
                                                 nnz,
                                                 col_indices,
                                                 row_ptrs,
                                                 coeffs,
                                                 lhss,
                                                 rhss,
                                                 lbs_dis,
                                                 ubs_dis,
                                                 vartypes,
                                                 datatype=datatype)
        tmp_lbs = normalize_infs(tmp_lbs)
        tmp_ubs = normalize_infs(tmp_ubs)

# (omp_new_lbs, omp_new_ubs) = propagateFullOMP(n_vars, n_cons, nnz, col_indices, row_ptrs, coeffs, lhss, rhss, lbs_omp, ubs_omp, vartypes, datatype=c_double)

    (seq_new_lbs, seq_new_ubs,
     stdout) = propagateSequentialWithPapiloPostsolve(reader,
                                                      n_vars,
                                                      n_cons,
                                                      nnz,
                                                      col_indices,
                                                      row_ptrs,
                                                      coeffs,
                                                      lhss,
                                                      rhss,
                                                      lbs_seq,
                                                      ubs_seq,
                                                      vartypes,
                                                      papilo_path,
                                                      datatype=c_double)

    print("papilo execution start...")
    papilo = PapiloInterface(lp_file_path, papilo_path)
    papilo_output = papilo.run_papilo(use_rationals=False)
    lbs_papilo, ubs_papilo = papilo.get_presolved_bounds()

    print("papilo propagation done. Num rounds: ", papilo.get_num_rounds())
    print("papilo execution time : ", papilo.get_exec_time(), " seconds")

    #print("papilo outputL \n", papilo_output)

    # omp_new_lbs = normalize_infs(omp_new_lbs)
    # omp_new_ubs = normalize_infs(omp_new_ubs)
    seq_new_lbs = normalize_infs(seq_new_lbs)
    seq_new_ubs = normalize_infs(seq_new_ubs)
    lbs_papilo = normalize_infs(lbs_papilo)
    ubs_papilo = normalize_infs(ubs_papilo)

    #  equal_seq_omp = arrays_equal(tmp_lbs, omp_new_lbs) and arrays_equal(tmp_ubs, omp_new_ubs)
    equal_seq_papilo = arrays_equal(seq_new_lbs, lbs_papilo) and arrays_equal(
        seq_new_ubs, ubs_papilo)

    #  print("cpu_seq to cpu_omp results match: ", equal_seq_omp)
    print("cpu_seq to pailo results match: ", equal_seq_papilo)
    print("all results match: ", equal_seq_papilo)
示例#6
0
def prop_compare_seq_gpu(lp_file_path: str,
                         datatype: _SimpleCData = c_double) -> None:
    reader: FileReaderInterface = get_reader(lp_file_path)

    n_cons = reader.get_n_cons()
    n_vars = reader.get_n_vars()
    nnz = reader.get_nnz()
    lbs, ubs = reader.get_var_bounds()
    lhss, rhss = reader.get_lrhss()
    coeffs, row_ptrs, col_indices = reader.get_cons_matrix()
    vartypes = reader.get_SCIP_vartypes()

    # print sparsity and input data size
    print("num vars: ", n_vars)
    print("num cons: ", n_cons)
    print("nnz     : ", nnz)

    lbs_dis = lbs_seq = lbs_gpuatomic = lbs_gpu = lbs_omp = lbs
    ubs_dis = ubs_seq = ubs_gpuatomic = ubs_gpu = ubs_omp = ubs

    (seq_new_lbs, seq_new_ubs) = propagateSequential(n_vars,
                                                     n_cons,
                                                     nnz,
                                                     col_indices,
                                                     row_ptrs,
                                                     coeffs,
                                                     lhss,
                                                     rhss,
                                                     lbs_seq,
                                                     ubs_seq,
                                                     vartypes,
                                                     datatype=c_double)

    (omp_new_lbs, omp_new_ubs) = propagateFullOMP(n_vars,
                                                  n_cons,
                                                  nnz,
                                                  col_indices,
                                                  row_ptrs,
                                                  coeffs,
                                                  lhss,
                                                  rhss,
                                                  lbs_omp,
                                                  ubs_omp,
                                                  vartypes,
                                                  datatype=c_double)

    # (gpu_new_lbs, gpu_new_ubs) = propagateGPUReduction(n_vars, n_cons, nnz, col_indices, row_ptrs, coeffs, lhss, rhss, lbs_gpu, ubs_gpu, vartypes, datatype=datatype)

    # (dis_new_lbs, dis_new_ubs) = propagateSequentialDisjoint( n_vars, n_cons, nnz, col_indices, row_ptrs, coeffs, lhss, rhss, lbs_dis, ubs_dis, vartypes)
    #  idx = 1

    (gpuatomic_new_lbs,
     gpuatomic_new_ubs) = propagateGPUAtomic(n_vars,
                                             n_cons,
                                             nnz,
                                             col_indices,
                                             row_ptrs,
                                             coeffs,
                                             lhss,
                                             rhss,
                                             lbs_gpuatomic,
                                             ubs_gpuatomic,
                                             vartypes,
                                             fullAsync=False,
                                             datatype=datatype)

    seq_new_lbs = normalize_infs(seq_new_lbs)
    seq_new_ubs = normalize_infs(seq_new_ubs)
    # gpu_new_lbs = normalize_infs(gpu_new_lbs)
    # gpu_new_ubs = normalize_infs(gpu_new_ubs)
    omp_new_lbs = normalize_infs(omp_new_lbs)
    omp_new_ubs = normalize_infs(omp_new_ubs)
    gpuatomic_new_lbs = normalize_infs(gpuatomic_new_lbs)
    gpuatomic_new_ubs = normalize_infs(gpuatomic_new_ubs)
    # # dis_new_lbs = normalize_infs(dis_new_lbs)
    # # dis_new_ubs = normalize_infs(dis_new_ubs)
    #

    equal_seq_omp = arrays_equal(seq_new_lbs, omp_new_lbs) and arrays_equal(
        seq_new_ubs, omp_new_ubs)
    equal_seq_gpu_atomic = arrays_equal(seq_new_lbs,
                                        gpuatomic_new_lbs) and arrays_equal(
                                            seq_new_ubs, gpuatomic_new_ubs)
    # equal_seq_gpu_full = arrays_equal(seq_new_lbs, gpu_new_lbs) and arrays_equal(seq_new_ubs, gpu_new_ubs)
    # # equal_seq_dis = arrays_equal(seq_new_lbs, dis_new_lbs) and arrays_equal(seq_new_ubs, dis_new_ubs)
    print("\ncpu_seq to cpu_omp results match: ", equal_seq_omp)
    # print("cpu_seq to gpu_reduction results match: ", equal_seq_gpu_full)
    print("cpu_seq to gpu_atomic results match: ", equal_seq_gpu_atomic)
    # # print("cpu_seq to cpu_seq_dis results match: ", equal_seq_dis)
    print("all results match: ", equal_seq_gpu_atomic and equal_seq_omp)