Esempio n. 1
0
def pysp_instance_creation_callback(scenario_name, node_names, cb_data):

    #print("Building instance for scenario =", scenario_name)
    scennum = sputils.extract_num(scenario_name)

    uc_model_params = pdp.get_uc_model()

    # Now using cb_data
    ##path = os.environ[UC_NUMSCENS_ENV_VAR] + "scenarios_r1"
    path = cb_data["path"]

    scenario_data = DataPortal(model=uc_model_params)
    scenario_data.load(filename=path + os.sep + "RootNode.dat")
    scenario_data.load(filename=path + os.sep + "Node" + str(scennum) + ".dat")

    scenario_params = uc_model_params.create_instance(scenario_data,
                                                      report_timing=False,
                                                      name=scenario_name)

    scenario_md = md.ModelData(
        pdp.create_model_data_dict_params(scenario_params, keep_names=True))

    ## TODO: use the "power_balance_constraints" for now. In the future, networks should be
    ##       handled with a custom callback -- also consider other base models
    scenario_instance = uc.create_tight_unit_commitment_model(
        scenario_md, network_constraints='power_balance_constraints')

    # hold over string attribute from Egret,
    # causes warning wth LShaped/Benders
    del scenario_instance.objective

    return scenario_instance
Esempio n. 2
0
def pysp_instance_creation_callback(scenario_name,
                                    path=None,
                                    scenario_count=None):
    """
    Notes:
    - The uc_cylinders.py code has a `scenario_count` kwarg that gets passed to
      the spokes, but it seems to be unused here...
    """
    #print("Building instance for scenario =", scenario_name)
    scennum = sputils.extract_num(scenario_name)

    uc_model_params = pdp.get_uc_model()

    scenario_data = DataPortal(model=uc_model_params)
    scenario_data.load(filename=path + os.sep + "RootNode.dat")
    scenario_data.load(filename=path + os.sep + "Node" + str(scennum) + ".dat")

    scenario_params = uc_model_params.create_instance(scenario_data,
                                                      report_timing=False,
                                                      name=scenario_name)

    scenario_md = md.ModelData(
        pdp.create_model_data_dict_params(scenario_params, keep_names=True))

    ## TODO: use the "power_balance_constraints" for now. In the future, networks should be
    ##       handled with a custom callback -- also consider other base models
    scenario_instance = uc.create_tight_unit_commitment_model(
        scenario_md, network_constraints='power_balance_constraints')

    # hold over string attribute from Egret,
    # causes warning wth LShaped/Benders
    del scenario_instance.objective

    return scenario_instance
Esempio n. 3
0
 def __init__(self, options: Options):
     self._uc_model_template = get_uc_model()
     self._instance_directory_name = os.path.join(
         os.path.expanduser(options.data_path), "pyspdir_twostage")
     self._actuals_by_date = {}
     self._forecasts_by_date = {}
     self._first_day = options.start_date
     self._final_day = self._first_day + timedelta(days=options.num_days -
                                                   1)
 def initialize(self, options: Options) -> None:
     ''' Do one-time initial setup
     '''
     self._uc_model_template = get_uc_model()
     self._instance_directory_name = os.path.join(os.path.expanduser(options.data_directory), 
                                                  "pyspdir_twostage")
     self._actuals_by_date = {}
     self._forecasts_by_date = {}
     self._first_day = dateutil.parser.parse(options.start_date).date()
     self._final_day = self._first_day + timedelta(days=options.num_days-1)
Esempio n. 5
0
def check_scen_template_for_sources(template_file, source_names):
    """
    This function will check the template file has all of the source names
    set in the 'NondispatchableGeneratorsAtBus' variable. Specifically, we must
    have that each source name appears in at least one bus.

    This should have a line of the following sort in the scenario template file

    set NondispatchableGeneratorsAtBus[Bus1] := Wind;

    If any source is not found, then this will raise an error.

    Args:
        template_file (str): The path to the scenario skeleton file
        model_file (str): The path to the Reference Model used for pyomo. This
            must have a model attribute
        source_names (list[str]): A list of the source names to be checked
    """
    try:
        model = pdp.get_uc_model()
        instance = model.create_instance(template_file)
    except Exception as e:
        s = ""
        s += "Error reading scenario data into Egret"
        s += "Check file {}".format(template_file)
        s += "Error reported: {}".format(','.join(map(str, e.args)))
        raise RuntimeError(s)

    for source in source_names:
        # If the source is in at least one bus, we are good
        for bus, sources in instance.NondispatchableGeneratorsAtBus.items():
            if source in sources:
                break
        else:
            # If we get through all the buses and do not find the source.
            raise RuntimeError(
                "Source {} not found in template file {}".format(
                    source, template_file))
Esempio n. 6
0
from prescient.util import DEFAULT_MAX_LABEL_LENGTH
from prescient.util.math_utils import round_small_values
from prescient.simulator.data_manager import RucMarket
from ..modeling_engine import ForecastErrorMethod
from ..forecast_helper import get_forecastables
from . import reporting

from typing import TYPE_CHECKING
if TYPE_CHECKING:
    from prescient.data.data_provider import DataProvider
    from prescient.data.simulation_state import SimulationState
    from typing import Optional
    from egret.data.model_data import ModelData as EgretModel

uc_abstract_data_model = get_uc_model()

########################################################################################
# a utility to find the "nearest" - quantified via Euclidean distance - scenario among #
# a candidate set relative to the input scenario, up through and including the         #
# specified simulation hour.                                                           #
########################################################################################

def call_solver(solver,instance,options,solver_options,relaxed=False, set_instance=True):
    tee = options.output_solver_logs
    if not tee:
        egret_logger.setLevel(logging.WARNING)
    symbolic_solver_labels = options.symbolic_solver_labels
    mipgap = options.ruc_mipgap

    solver_options_dict = dict()