Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/ppopt/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import logging
import os

os.environ["OMP_NUM_THREADS"] = "1" # export OMP_NUM_THREADS=1
os.environ["OPENBLAS_NUM_THREADS"] = "1" # export OPENBLAS_NUM_THREADS=1
os.environ["MKL_NUM_THREADS"] = "1" # export MKL_NUM_THREADS=1
os.environ["VECLIB_MAXIMUM_THREADS"] = "1" # export VECLIB_MAXIMUM_THREADS=1
os.environ["NUMEXPR_NUM_THREADS"] = "1" # export NUMEXPR_NUM_THREADS=1

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)

sh = logging.StreamHandler()
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
sh.setFormatter(formatter)
sh.setLevel(logging.INFO)
logger.addHandler(sh)
5 changes: 4 additions & 1 deletion src/ppopt/mp_solvers/mpqp_geometric.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import logging

from ..mpqp_program import MPQP_Program
from ..solution import Solution
from ..utils.general_utils import make_column
from ..utils.mpqp_utils import gen_cr_from_active_set
from .solver_utils import fathem_facet, get_facet_centers

logger = logging.getLogger(__name__)


def solve(program: MPQP_Program, active_set=None) -> Solution:
"""
Expand All @@ -18,7 +21,7 @@ def solve(program: MPQP_Program, active_set=None) -> Solution:
"""
if active_set is None:
active_set = program.gen_optimal_active_set()
print(f'Using a found active set {active_set}')
logger.info(f'Using a found active set {active_set}')

initial_region = gen_cr_from_active_set(program, active_set, check_full_dim=False)

Expand Down
7 changes: 5 additions & 2 deletions src/ppopt/mp_solvers/mpqp_graph.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
from typing import List, Optional
import logging

from ..mpqp_program import MPQP_Program
from ..solution import Solution
from ..utils.constraint_utilities import is_full_rank
from ..utils.mpqp_utils import gen_cr_from_active_set
from .solver_utils import CombinationTester, generate_extra, generate_reduce

logger = logging.getLogger(__name__)


def graph_initialization(program, initial_active_sets):
"""
Expand All @@ -28,9 +31,9 @@ def graph_initialization(program, initial_active_sets):
to_attempt = [tuple(a_set) for a_set in initial_active_sets]

if len(to_attempt) != 0:
print(f'First region {to_attempt[0]}')
logger.info(f'First region {to_attempt[0]}')
else:
print('Failed to find an initial region!')
logger.warning('Failed to find an initial region!')

return attempted, solution, murder_list, to_attempt

Expand Down
13 changes: 8 additions & 5 deletions src/ppopt/mp_solvers/mpqp_parallel_combinatorial_exp.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import time
from random import shuffle
from typing import List, Tuple
Expand All @@ -13,6 +14,8 @@
from ..utils.mpqp_utils import gen_cr_from_active_set
from .solver_utils import generate_children_sets

logger = logging.getLogger(__name__)


def full_process(program: MPQP_Program, active_set: List[int]) -> Tuple[List[List[int]], List[CriticalRegion]]:
"""
Expand Down Expand Up @@ -78,7 +81,7 @@ def solve(program: MPQP_Program, num_cores=-1) -> Solution:
if num_cores == -1:
num_cores = num_cpu_cores()

print(f'Spawned threads across {num_cores}')
logger.debug(f'Spawned threads across {num_cores}')

pool = Pool(num_cores)

Expand All @@ -100,8 +103,8 @@ def solve(program: MPQP_Program, num_cores=-1) -> Solution:
to_check.append(program.equality_indices)

for i in range(max_depth):
print(f'Time at depth test {i + 1}, {time.time() - start}')
print(f'Number of active sets to be considered is {len(to_check)}')
logger.debug(f'Time at depth test {i + 1}, {time.time() - start}')
logger.debug(f'Number of active sets to be considered is {len(to_check)}')

depth_time = time.time()

Expand All @@ -113,7 +116,7 @@ def solve(program: MPQP_Program, num_cores=-1) -> Solution:

outputs = pool.map(f, to_check)

print(f'Time to run all tasks in parallel {time.time() - depth_time}')
logger.debug(f'Time to run all tasks in parallel {time.time() - depth_time}')
depth_time = time.time()

for output in outputs:
Expand All @@ -123,7 +126,7 @@ def solve(program: MPQP_Program, num_cores=-1) -> Solution:
for region in output[1]:
solution.add_region(region)

print(f'Time to process all depth outputs {time.time() - depth_time}')
logger.debug(f'Time to process all depth outputs {time.time() - depth_time}')

to_check = future_list

Expand Down
11 changes: 6 additions & 5 deletions src/ppopt/mp_solvers/mpqp_parallel_geometric.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

import logging
import numpy

# noinspection PyProtectedMember
Expand All @@ -10,6 +10,7 @@
from ..utils.mpqp_utils import gen_cr_from_active_set
from .solver_utils import fathem_facet, get_facet_centers

logger = logging.getLogger(__name__)

def full_process(center: numpy.ndarray, norm: numpy.ndarray, radius: float, program: MPQP_Program, current_active_set,
indexed_region_as):
Expand Down Expand Up @@ -47,18 +48,18 @@ def solve(program: MPQP_Program, active_set=None, num_cores=-1) -> Solution:
"""
if active_set is None:
active_set = program.gen_optimal_active_set()
print(f'Using a found active set {active_set}')
logger.info(f'Using a found active set {active_set}')

initial_region = gen_cr_from_active_set(program, active_set, check_full_dim=False)

if initial_region is None:
print('Could not find a valid initial region')
logger.warning('Could not find a valid initial region')
return Solution(program, [])

if num_cores == -1:
num_cores = num_cpu_cores()

print(f'Spawned threads across {num_cores}')
logger.debug(f'Spawned threads across {num_cores}')

pool = Pool(num_cores)

Expand All @@ -74,7 +75,7 @@ def solve(program: MPQP_Program, active_set=None, num_cores=-1) -> Solution:

while len(work_items) > 0:

print(f' Number of Facets to look at this time {len(work_items)}')
logger.debug(f' Number of Facets to look at this time {len(work_items)}')
f = lambda x: full_process(x[0], x[1], x[2], program, x[3], indexed_region_as)

outputs = pool.map(f, work_items)
Expand Down
11 changes: 7 additions & 4 deletions src/ppopt/mp_solvers/mpqp_parallel_geometric_exp.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import List, Optional
import logging

import numpy

Expand All @@ -11,6 +12,8 @@
from ..utils.mpqp_utils import gen_cr_from_active_set
from .solver_utils import get_facet_centers

logger = logging.getLogger(__name__)


def fathem_facet_exp(center: numpy.ndarray, normal: numpy.ndarray, radius: float, program, current_active_set: list) -> \
Optional[List[int]]:
Expand Down Expand Up @@ -102,12 +105,12 @@ def solve(program: MPQP_Program, initial_active_sets: Optional[List[List[int]]]
if initial_active_sets[-1] is None:
raise ValueError('No Active Sets Found')

print(f'Using a found active set {initial_active_sets[-1]}')
logger.info(f'Using a found active set {initial_active_sets[-1]}')

if num_cores == -1:
num_cores = num_cpu_cores()

print(f'Spawned threads across {num_cores}')
logger.debug(f'Spawned threads across {num_cores}')

pool = Pool(num_cores)

Expand All @@ -131,7 +134,7 @@ def solve(program: MPQP_Program, initial_active_sets: Optional[List[List[int]]]

while len(work_items) > 0:

print(f' Number of Facets to look at this time {len(work_items)}')
logger.debug(f' Number of Facets to look at this time {len(work_items)}')
f = lambda x: fathem_facet_exp(x[0], x[1], x[2], program, x[3])

found_active_sets = pool.map(f, work_items)
Expand All @@ -150,7 +153,7 @@ def solve(program: MPQP_Program, initial_active_sets: Optional[List[List[int]]]
work_items = []
# process the outputs
filtered_outputs = [output for output in outputs if output is not None]
print(f' Number of Regions adding in this pass {len(filtered_outputs)}!')
logger.debug(f' Number of Regions adding in this pass {len(filtered_outputs)}!')

for output in filtered_outputs:

Expand Down
13 changes: 8 additions & 5 deletions src/ppopt/mp_solvers/mpqp_parrallel_combinatorial.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import time
from random import shuffle
from typing import List, Optional, Set, Tuple
import logging

# noinspection PyProtectedMember
from pathos.multiprocessing import ProcessingPool as Pool
Expand All @@ -13,6 +14,8 @@
from ..utils.mpqp_utils import gen_cr_from_active_set
from .solver_utils import CombinationTester, generate_children_sets

logger = logging.getLogger(__name__)


def full_process(program: MPQP_Program, active_set: List[int], murder_list, gen_children) -> Tuple[Optional[CriticalRegion], Set[Tuple[int,...]], List[List[int]]]:
"""
Expand Down Expand Up @@ -82,7 +85,7 @@ def solve(program: MPQP_Program, num_cores=-1) -> Solution:
if num_cores == -1:
num_cores = num_cpu_cores()

print(f'Spawned threads across {num_cores}')
logger.debug(f'Spawned threads across {num_cores}')

pool = Pool(num_cores)

Expand All @@ -100,8 +103,8 @@ def solve(program: MPQP_Program, num_cores=-1) -> Solution:
to_check.extend(root_node)

for i in range(max_depth):
print(f'Time at depth test {i + 1}, {time.time() - start}')
print(f'Number of active sets to be considered is {len(to_check)}')
logger.debug(f'Time at depth test {i + 1}, {time.time() - start}')
logger.debug(f'Number of active sets to be considered is {len(to_check)}')

depth_time = time.time()

Expand All @@ -115,7 +118,7 @@ def solve(program: MPQP_Program, num_cores=-1) -> Solution:

outputs = pool.map(f, to_check)

print(f'Time to run all tasks in parallel {time.time() - depth_time}')
logger.debug(f'Time to run all tasks in parallel {time.time() - depth_time}')
depth_time = time.time()

if i + 1 == max_depth:
Expand All @@ -130,7 +133,7 @@ def solve(program: MPQP_Program, num_cores=-1) -> Solution:
if output[0] is not None:
solution.add_region(output[0])

print(f'Time to process all depth outputs {time.time() - depth_time}')
logger.debug(f'Time to process all depth outputs {time.time() - depth_time}')

to_check = future_list

Expand Down
4 changes: 3 additions & 1 deletion src/ppopt/mp_solvers/mpqp_parrallel_graph.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import List, Optional, Set, Tuple
import logging

# noinspection PyProtectedMember
from pathos.multiprocessing import ProcessingPool as Pool
Expand All @@ -14,6 +15,7 @@
manufacture_lambda,
)

logger = logging.getLogger(__name__)

def full_process(program, candidate, murder_list):
"""
Expand Down Expand Up @@ -99,7 +101,7 @@ def f(x):
tiered_to_attempt[cursor] = []
cursor += 1

print(f'Processing {len(to_attempt)} in this parallel swap')
logger.debug(f'Processing {len(to_attempt)} in this parallel swap')
outputs = pool.map(f, to_attempt)

for candidate in to_attempt:
Expand Down
4 changes: 3 additions & 1 deletion src/ppopt/mp_solvers/solve_mpmiqp.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from enum import Enum
import logging

from ..mpmilp_program import MPMILP_Program
from ..solution import Solution
Expand All @@ -9,6 +10,7 @@

from ..utils.region_overlap_utils import reduce_overlapping_critical_regions_1d

logger = logging.getLogger(__name__)

class mpmiqp_algorithm(Enum):
"""
Expand Down Expand Up @@ -36,7 +38,7 @@ def solve_mpmiqp(problem: MPMILP_Program, mpmiqp_algo: mpmiqp_algorithm = mpmiqp
reduce_overlap=True) -> Solution:
# the case of a continuous problem just solve it and return
if len(problem.binary_indices) == 0:
print("The problem does not have any binary variables, solving as a continuous problem instead.")
logger.warning("The problem does not have any binary variables, solving as a continuous problem instead.")
# noinspection PyTypeChecker
return solve_mpqp(problem, cont_algo)

Expand Down
5 changes: 4 additions & 1 deletion src/ppopt/mplp_program.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import List, Optional, Tuple

import logging
import numpy
import warnings

Expand All @@ -24,6 +25,8 @@

# noinspection GrazieInspection

logger = logging.getLogger(__name__)

class MPLP_Program:
r"""
The standard class for multiparametric linear programming
Expand Down Expand Up @@ -101,7 +104,7 @@ def __init__(self, A, b, c, H, A_t, b_t, F, c_c=None, c_t=None, Q_t=None, equali

# print warnings if there are any
for warning in problem_warning:
warnings.warn(warning, UserWarning)
logger.warning(warning)

# calls constraint processing to remove redundant constraints
if post_process:
Expand Down
5 changes: 4 additions & 1 deletion src/ppopt/mpmilp_program.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import List, Optional
import logging

import numpy

Expand All @@ -8,6 +9,8 @@
from .utils.constraint_utilities import detect_implicit_equalities
from .utils.general_utils import ppopt_block

logger = logging.getLogger(__name__)


class MPMILP_Program(MPLP_Program):
# noinspection SpellCheckingInspection
Expand Down Expand Up @@ -64,7 +67,7 @@ def __init__(self, A: numpy.ndarray, b: numpy.ndarray, c: numpy.ndarray, H: nump
self.cont_indices = [i for i in range(self.num_x()) if i not in self.binary_indices]

if len(self.cont_indices) == 0:
print("Pure Integer case is not considered here only the Mixed case!!!")
logger.warning("Pure Integer case is not considered here only the Mixed case!!!")

if post_process:
self.post_process()
Expand Down
6 changes: 4 additions & 2 deletions src/ppopt/plot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import time
import logging
from math import atan2
from typing import List, Optional

Expand All @@ -12,6 +13,7 @@
from .solver import Solver
from .utils.general_utils import make_column

logger = logging.getLogger(__name__)

def vertex_enumeration_2d(A: numpy.ndarray, b: numpy.ndarray, solver: Solver) -> List[numpy.ndarray]:
"""
Expand Down Expand Up @@ -120,7 +122,7 @@ def parametric_plot(solution: Solution, save_path: Optional[str] = None, show=Tr

# check if the solution is actually 2 dimensional
if solution.theta_dim() != 2:
print(f"Solution is not 2D, the dimensionality of the solution is {solution.theta_dim()}")
logger.error(f"Solution is not 2D, the dimensionality of the solution is {solution.theta_dim()}")
return

vertex_list = gen_vertices(solution)
Expand Down Expand Up @@ -164,7 +166,7 @@ def parametric_plot_1D(solution: Solution, save_path: Optional[str] = None, show

# check if the solution is actually 1 dimensional
if solution.theta_dim() != 1:
print(f"Solution is not 1D, the dimensionality of the solution is {solution.theta_dim()}")
logger.error(f"Solution is not 1D, the dimensionality of the solution is {solution.theta_dim()}")
return

if plot_subset is None:
Expand Down