Skip to content

Commit

Permalink
Cleaned Up Use of MGA configs. Temporarily disabled Excel construction
Browse files Browse the repository at this point in the history
Excel construction via pyam is causing errors.  Temp disabled.  Also temp disabled logging test involving pyam
  • Loading branch information
jeff-ws committed May 27, 2024
1 parent 4d92b59 commit d28fda6
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 850 deletions.
7 changes: 4 additions & 3 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dependencies:
# Requirements for core model functionality
- python=3.12
- pyomo=6.7
- pyomo.extras
# - pyomo.extras
- xlwt
- ipython
- matplotlib
Expand All @@ -22,7 +22,7 @@ dependencies:
- salib
- pydoe
- pyutilib
- glpk
# - glpk
- python-graphviz
- ipykernel
- jupyter
Expand All @@ -33,12 +33,13 @@ dependencies:
- plotly
- pyam
# cbc solver below cannot be installed via Conda on Windows
- coincbc
# - coincbc
- pytest
- deprecated
- openpyxl
- networkx
- gravis
- gurobi

# Below required to update documentation
- sphinx
Expand Down
3 changes: 2 additions & 1 deletion environment_minimal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ dependencies:
- pyam
# cbc solver below cannot be installed via Conda on Windows
# - coincbc
# - pytest
- pytest
- deprecated
- openpyxl
- networkx
- gravis
- gurobi

# Below required to update documentation
# - sphinx
Expand Down
11 changes: 8 additions & 3 deletions temoa/extensions/modeling_to_generate_alternatives/hull.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,14 @@ def __init__(self, points: np.ndarray, **kwargs):
"""
# the number of columns in the first volley of points sets the dimensions of the hull
self.dim = points.shape[1]
if self.dim > points.shape[0]:
logger.error('Hull dimension less than points')
raise ValueError('Hull dimension less than points')
if self.dim + 1 > points.shape[0]:
logger.error(
'Insufficient points to make hull. Should have at least hull dimensionality + 1.'
)
raise ValueError(
'Insufficient points to make hull. Should have at least hull dimensionality + 1.'
f' Received {points.shape[0]} points'
)
logger.info(
'Initializing Hull with points: %d and dimensions: %d', points.shape[0], points.shape[1]
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
import queue
import sqlite3
import time
import tomllib
from datetime import datetime
from logging import getLogger
from multiprocessing import Queue
from pathlib import Path
from queue import Empty

import pyomo.environ as pyo
import toml
from pyomo.contrib.solver.results import Results
from pyomo.dataportal import DataPortal
from pyomo.opt import check_optimal_termination
Expand Down Expand Up @@ -86,14 +86,15 @@ def __init__(self, config: TemoaConfig):

# read in the options
try:
with open(path_to_options_file, 'r') as f:
all_options = toml.load(f)
with open(path_to_options_file, 'rb') as f:
all_options = tomllib.load(f)
s_options = all_options.get(self.config.solver_name, {})
logger.info('Using solver options: %s', s_options)

except FileNotFoundError:
logger.warning('Unable to find solver options toml file. Using default options.')
s_options = {}
all_options = {}

# get handle on solver instance
self.opt = pyo.SolverFactory(self.config.solver_name)
Expand All @@ -115,7 +116,8 @@ def __init__(self, config: TemoaConfig):
except ValueError:
logger.warning('No/bad MGA Weighting specified. Using default: Hull Expansion')
self.mga_weighting = MgaWeighting.HULL_EXPANSION

self.num_workers = all_options.get('num_workers', 1)
logger.info('MGA workers are set to %s', self.num_workers)
self.iteration_limit = config.mga_inputs.get('iteration_limit', 20)
logger.info('Set MGA iteration limit to: %d', self.iteration_limit)
self.time_limit_hrs = config.mga_inputs.get('time_limit_hrs', 12)
Expand Down Expand Up @@ -208,7 +210,7 @@ def start(self):
'solver_name': self.config.solver_name,
'solver_options': self.worker_solver_options,
}
num_workers = 6
num_workers = self.num_workers
# construct path for the solver logs
s_path = Path(get_OUTPUT_PATH(), 'solver_logs')
if not s_path.exists():
Expand Down Expand Up @@ -249,8 +251,8 @@ def start(self):
self.process_solve_results(next_result)
logger.info('Solve count: %d', self.solve_count)
self.solve_count += 1
if self.verbose:
print(f'Solve count: {self.solve_count}')
if self.verbose or not self.config.silent:
print(f'MGA Solve count: {self.solve_count}')
if self.solve_count >= self.iteration_limit:
logger.info('Starting shutdown process based on MGA iteration limit')
self.internal_stop = True
Expand Down Expand Up @@ -292,8 +294,8 @@ def start(self):
self.process_solve_results(next_result)
logger.info('Solve count: %d', self.solve_count)
self.solve_count += 1
if self.verbose:
print(f'Solve count: {self.solve_count}')
if self.verbose or not self.config.silent:
print(f'MGA Solve count: {self.solve_count}')
while True:
try:
record = log_queue.get_nowait()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,11 @@ def _generate_basis_coefficients(category_mapping: dict, technology_size: dict)
return q

def tracker(self):
"""A little function to track the size of the hull, after it is built initially"""
if len(self.hull_points) > 10:
"""
A little function to track the size of the hull, after it is built initially
Note: This hull is a "throw away" and only used for volume calc, but it is pretty quick
"""
if self.hull is not None:
hull = Hull(self.hull_points)
volume = hull.volume
logger.info(f'Tracking hull at {volume}')
Expand Down
87 changes: 0 additions & 87 deletions temoa/extensions/modeling_to_generate_alternatives/temoa_mga.py

This file was deleted.

Loading

0 comments on commit d28fda6

Please sign in to comment.