### Install GridPath from Source Source: https://gridpath.readthedocs.io/en/latest/_sources/installation.rst.txt Install GridPath from its source code. Navigate to the extracted source directory and run the installation command. This is typically for developers. ```bash pip install . ``` -------------------------------- ### Generate Total Installed Capacity Plot Source: https://gridpath.readthedocs.io/en/latest/_sources/visualization.rst.txt Example command to generate a plot showing total installed capacity across modeling periods for a specific scenario and load zone. Ensure a functioning database is available. ```bash gridpath_viz_capacity_total_plot --scenario test --load_zone CAISO --show ``` -------------------------------- ### Install GridPath from PyPI Source: https://gridpath.readthedocs.io/en/latest/_sources/installation.rst.txt Install the latest stable version of GridPath directly from the Python Package Index (PyPI). Ensure your virtual environment is activated first. ```bash pip install GridPath ``` -------------------------------- ### Install All Developer Extras for GridPath Source: https://gridpath.readthedocs.io/en/latest/_sources/installation.rst.txt Install all additional packages required for development, such as documentation building or code formatting. This command installs GridPath in editable mode with all extras. ```bash pip install -e .[all] ``` -------------------------------- ### Get GridPath Command Help Source: https://gridpath.readthedocs.io/en/latest/_sources/usage.rst.txt View usage and optional arguments for GridPath commands, such as specifying a solver. This is useful for understanding all available options. ```bash gridpath_run_e2e --help ``` -------------------------------- ### Setup Logging for Optimization Run Source: https://gridpath.readthedocs.io/en/latest/_modules/gridpath/run_scenario.html Sets up logging for an optimization run if requested. This involves creating a log directory and redirecting standard output and error to a logger object. ```python # If directed to do so, log optimization run (only if actually solving) if parsed_arguments.log: logs_directory = create_logs_directory_if_not_exists( scenario_directory, weather_iteration_directory, hydro_iteration_directory, availability_iteration_directory, subproblem_directory, stage_directory, ) # Save sys.stdout, so we can return to it later stdout_original = sys.stdout stderr_original = sys.stderr # The print statement will call the write() method of any object # you assign to sys.stdout (in this case the Logging object). The # write method of Logging writes both to sys.stdout and a log file # (see auxiliary/auxiliary.py) logger = Logging( logs_dir=logs_directory, start_time=datetime.datetime.now(), e2e=False, process_id=None, ) sys.stdout = logger sys.stderr = logger ``` -------------------------------- ### Install Specific GridPath Version from PyPI Source: https://gridpath.readthedocs.io/en/latest/_sources/installation.rst.txt Install a specific version of GridPath from PyPI, for example, version 0.16.0. Note that versions prior to 0.16.0 are not available on PyPI. ```bash pip install GridPath==0.16.0 ``` -------------------------------- ### Generate Total Installed Capacity Plot Source: https://gridpath.readthedocs.io/en/latest/visualization.html Use this command-line script to generate a plot showing the total installed capacity across modeling periods for a specific scenario. Ensure you have a functioning GridPath database. ```bash gridpath_viz_capacity_total_plot --scenario test --load_zone CAISO --show ``` -------------------------------- ### Get Project Energy Target Zones from Database Source: https://gridpath.readthedocs.io/en/latest/_modules/gridpath/project/operations/energy_target_contributions.html Retrieves projects and their associated energy target zones from the database. Filters projects based on portfolio inclusion and energy target zone availability. ```python def get_inputs_from_database( scenario_id, subscenarios, weather_iteration, hydro_iteration, availability_iteration, subproblem, stage, conn, ): """ :param subscenarios: SubScenarios object with all subscenario info :param subproblem: :param stage: :param conn: database connection :return: """ c = conn.cursor() # Get the energy-target zones for project in our portfolio and with zones in our # Energy target zone project_zones = c.execute( """SELECT project, energy_target_zone FROM -- Get projects from portfolio only (SELECT project FROM inputs_project_portfolios WHERE project_portfolio_scenario_id = {} ) as prj_tbl LEFT OUTER JOIN -- Get energy_target zones for those projects (SELECT project, energy_target_zone FROM inputs_project_energy_target_zones WHERE project_energy_target_zone_scenario_id = {} ) as prj_energy_target_zone_tbl USING (project) -- Filter out projects whose RPS zone is not one included in our -- energy_target_zone_scenario_id WHERE energy_target_zone in ( SELECT energy_target_zone FROM inputs_geography_energy_target_zones WHERE energy_target_zone_scenario_id = {} ); """.format( subscenarios.PROJECT_PORTFOLIO_SCENARIO_ID, subscenarios.PROJECT_ENERGY_TARGET_ZONE_SCENARIO_ID, subscenarios.ENERGY_TARGET_ZONE_SCENARIO_ID, ) ) return project_zones ``` -------------------------------- ### Import and Initialize Capacity Modules Source: https://gridpath.readthedocs.io/en/latest/_modules/gridpath/project/capacity/capacity.html This code snippet imports necessary capacity type modules and adds any components specific to those modules to the model. It's used during the dynamic input phase of model setup. ```python required_capacity_modules = get_required_subtype_modules( scenario_directory=scenario_directory, weather_iteration=weather_iteration, hydro_iteration=hydro_iteration, availability_iteration=availability_iteration, subproblem=subproblem, stage=stage, which_type="capacity_type", ) # Import needed capacity type modules imported_capacity_modules = load_project_capacity_type_modules( required_capacity_modules ) # Add any components specific to the capacity type modules for op_m in required_capacity_modules: imp_op_m = imported_capacity_modules[op_m] if hasattr(imp_op_m, "add_model_components"): imp_op_m.add_model_components( m, d, scenario_directory, weather_iteration, hydro_iteration, availability_iteration, subproblem, stage, ) ``` -------------------------------- ### Parallel Scenario Processing Pool Setup Source: https://gridpath.readthedocs.io/en/latest/_modules/gridpath/run_scenario.html This code iterates through scenario directory structures to build a pool of tasks for parallel processing. It filters for incomplete stages if the '--incomplete_only' flag is set. The pool is configured to use 'spawn' for compatibility on Linux. ```python pool_data = [] for weather_iteration_str in scenario_directory_structure.keys(): for hydro_iteration_str in scenario_directory_structure[ weather_iteration_str ].keys(): for availability_iteration_str in scenario_directory_structure[ weather_iteration_str ][hydro_iteration_str]: # We may have passed "empty_string" to avoid actual empty # strings as dictionary keys; convert to actual empty # strings here to pass to the directory creation methods weather_iteration_str = ensure_empty_string( weather_iteration_str ) hydro_iteration_str = ensure_empty_string(hydro_iteration_str) availability_iteration_str = ensure_empty_string( availability_iteration_str ) for subproblem_str in scenario_directory_structure[ weather_iteration_str ][hydro_iteration_str][availability_iteration_str].keys(): stage_directories = scenario_directory_structure[ weather_iteration_str ][hydro_iteration_str][availability_iteration_str][ subproblem_str ] # If --incomplete_only flag is set, filter out complete subproblems if parsed_arguments.incomplete_only: # Filter stage directories to only include incomplete stages incomplete_stage_directories = [ stage_dir for stage_dir in stage_directories if not is_subproblem_stage_complete( scenario_directory, weather_iteration_str, hydro_iteration_str, availability_iteration_str, subproblem_str, stage_dir, ) ] # Only add to pool if there are incomplete stages if incomplete_stage_directories: pool_data.append( [ scenario_directory, weather_iteration_str, hydro_iteration_str, availability_iteration_str, subproblem_str, incomplete_stage_directories, scenario_structure.STAGE_FLAG, parsed_arguments, objective_values, ] ) else: # Add all stages if not filtering pool_data.append( [ scenario_directory, weather_iteration_str, hydro_iteration_str, availability_iteration_str, subproblem_str, stage_directories, scenario_structure.STAGE_FLAG, parsed_arguments, objective_values, ] ) pool_data = tuple(pool_data) # Adjust pool size based on actual number of tasks # (may be less than total subproblems if using --incomplete_only) n_tasks = len(pool_data) if n_tasks == 0: if not parsed_arguments.quiet: print("All subproblems already complete. Nothing to solve.") return objective_values # Don't create more processes than tasks if n_parallel_subproblems > n_tasks: n_parallel_subproblems = n_tasks # Pool must use spawn to work properly on Linux pool = get_context("spawn").Pool(n_parallel_subproblems) ``` -------------------------------- ### Activate Python Virtual Environment on Windows (cmd.exe) Source: https://gridpath.readthedocs.io/en/latest/_sources/installation.rst.txt Activate the created Python virtual environment on Windows using the cmd.exe command prompt. This must be done before installing GridPath. ```bash C:\> PATH\TO\PYTHON\ENV\Scripts\activate.bat ``` -------------------------------- ### Get Performance Standard Project Zones from Database Source: https://gridpath.readthedocs.io/en/latest/_modules/gridpath/project/operations/performance_standard.html Retrieves project and their associated performance standard zones from the database. It joins project portfolios with performance standard zone assignments and filters based on geography. ```python def get_inputs_from_database( scenario_id, subscenarios, weather_iteration, hydro_iteration, availability_iteration, subproblem, stage, conn, ): """ :param subscenarios: SubScenarios object with all subscenario info :param subproblem: :param stage: :param conn: database connection :return: """ c = conn.cursor() project_zones = c.execute( """SELECT project, performance_standard_zone FROM -- Get projects from portfolio only (SELECT project FROM inputs_project_portfolios WHERE project_portfolio_scenario_id = {} ) as prj_tbl LEFT OUTER JOIN -- Get performance standard zones for those projects (SELECT project, performance_standard_zone FROM inputs_project_performance_standard_zones WHERE project_performance_standard_zone_scenario_id = {} ) as prj_ps_zone_tbl USING (project) -- Filter out projects whose performance standard zone is not one included in -- our performance_standard_zone_scenario_id WHERE performance_standard_zone in ( SELECT performance_standard_zone FROM inputs_geography_performance_standard_zones WHERE performance_standard_zone_scenario_id = {} ); """.format( subscenarios.PROJECT_PORTFOLIO_SCENARIO_ID, subscenarios.PROJECT_PERFORMANCE_STANDARD_ZONE_SCENARIO_ID, subscenarios.PERFORMANCE_STANDARD_ZONE_SCENARIO_ID, ) ) return project_zones ``` -------------------------------- ### Display Help for GridPath Load Scenarios Source: https://gridpath.readthedocs.io/en/latest/database.html Run this command to view all available arguments and usage instructions for the `gridpath_load_scenarios` command. ```bash >>> gridpath_load_scenarios --help ``` -------------------------------- ### Run GridPath End-to-End Source: https://gridpath.readthedocs.io/en/latest/_sources/usage.rst.txt Use this command to run a GridPath scenario from start to finish, including getting inputs, solving, importing results, and processing them. Ensure your GridPath Python environment is enabled. ```bash gridpath_run_e2e --database /PATH/TO/DATABASE --scenario SCENARIO_NAME --scenario_location /PATH/TO/SCENARIO ``` -------------------------------- ### Create Raw Data Database Source: https://gridpath.readthedocs.io/en/latest/_sources/data_toolkit.rst.txt Use this command to initialize the raw data database. Specify the database path, schema file, and optionally omit data loading. ```bash gridpath_run_data_toolkit --single_step create_database --database PATH/TO/RAW/DB --db_schema ./raw_data_db_schema.sql --omit_data ``` -------------------------------- ### Add Project Aggregate Startup Costs Source: https://gridpath.readthedocs.io/en/latest/_modules/gridpath/objective/project/aggregate_operational_costs.html Adds Pyomo components to aggregate startup costs for all projects across all operational timepoints. This calculation includes the hours in each timepoint, the timepoint weight, the number of years represented by the period, and the discount factor for that period. ```python def total_startup_cost_rule(mod): """ Sum startup costs for the objective function term. :param mod: :return: """ return sum( mod.Startup_Cost[g, tmp] * mod.hrs_in_tmp[tmp] * mod.tmp_weight[tmp] * mod.number_years_represented[mod.period[tmp]] * mod.discount_factor[mod.period[tmp]] for (g, tmp) in mod.STARTUP_COST_PRJ_OPR_TMPS ) m.Total_Startup_Cost = Expression(rule=total_startup_cost_rule) ``` -------------------------------- ### Display GridPath Command Help Source: https://gridpath.readthedocs.io/en/latest/usage.html Access the help menu for `gridpath_run_e2e` to see usage details and optional arguments, such as specifying a solver. ```bash gridpath_run_e2e --help ``` -------------------------------- ### Define Period Start Year Parameter Source: https://gridpath.readthedocs.io/en/latest/_modules/gridpath/temporal/investment/periods.html Defines the starting year for each period. This parameter is required and must be a non-negative real number. ```python m.period_start_year = Param(m.PERIODS, within=NonNegativeReals) ``` -------------------------------- ### Run GridPath Scenario with Pre-written Inputs Source: https://gridpath.readthedocs.io/en/latest/usage.html Use this command if you are not using the database and have already written input .tab files for your scenario. Specify the scenario name and its location. ```bash gridpath_run --scenario SCENARIO_NAME --scenario_location /PATH/TO/SCENARIO ``` -------------------------------- ### Get Project Reserve Derates from Database Source: https://gridpath.readthedocs.io/en/latest/_modules/gridpath/project/operations/reserves/reserve_provision.html Fetches project-specific derating factors for reserves from the database. It selects projects from the portfolio and joins with their operational characteristics to get the reserve derate. ```sql SELECT project, {}_derate FROM -- Get projects from portfolio only (SELECT project FROM inputs_project_portfolios WHERE project_portfolio_scenario_id = {} ) as prj_tbl LEFT OUTER JOIN -- Get derates for those projects (SELECT project, {}_derate FROM inputs_project_operational_chars WHERE project_operational_chars_scenario_id = {} ) as prj_derate_tbl USING (project); ``` -------------------------------- ### Set Up Gridpath Modules Source: https://gridpath.readthedocs.io/en/latest/_modules/gridpath/run_scenario.html Determines and loads the necessary Gridpath modules and populates dynamic components for a scenario run. This function prepares the environment for scenario execution. ```python # Determine and load modules modules_to_use = determine_modules( scenario_directory=scenario_directory, multi_stage=multi_stage ) loaded_modules = load_modules(modules_to_use) # Determine the dynamic components based on the needed modules and input # data # populate_dynamic_inputs(dynamic_components, loaded_modules, # scenario_directory, subproblem, stage) return modules_to_use, loaded_modules ``` -------------------------------- ### Create Problem Instance and Save Files Source: https://gridpath.readthedocs.io/en/latest/_modules/gridpath/run_scenario.html Creates a problem instance and saves it along with dynamic components and symbol map to pickle files. This is used when not loading a pre-existing solution. ```python else: dynamic_components, instance = create_problem( scenario_directory=scenario_directory, weather_iteration=weather_iteration_directory, hydro_iteration=hydro_iteration_directory, availability_iteration=availability_iteration_directory, subproblem=subproblem_directory, stage=stage_directory, multi_stage=multi_stage, parsed_arguments=parsed_arguments, ) if parsed_arguments.create_lp_problem_file_only: prob_sol_files_directory = os.path.join( scenario_directory, subproblem_directory, stage_directory, "prob_sol_files", ) if not os.path.exists(prob_sol_files_directory): os.makedirs(prob_sol_files_directory) with open( os.path.join(prob_sol_files_directory, "instance.pickle"), "wb" ) as f_out: dill.dump(instance, f_out) with open( os.path.join(prob_sol_files_directory, "dynamic_components.pickle"), "wb", ) as f_out: dill.dump(dynamic_components, f_out) smap_id = write_problem_file( instance=instance, prob_sol_files_directory=prob_sol_files_directory ) symbol_map = instance.solutions.symbol_map[smap_id] symbol_cuid_pairs = tuple( (symbol, ComponentUID(var_weakref, cuid_buffer={})) for symbol, var_weakref in symbol_map.bySymbol.items() ) with open( os.path.join(prob_sol_files_directory, "symbol_map.pickle"), "wb" ) as f_out: dill.dump(symbol_cuid_pairs, f_out) ``` -------------------------------- ### Get Operational Periods for a Project Source: https://gridpath.readthedocs.io/en/latest/_modules/gridpath/project/capacity/capacity.html Filters and returns a sorted list of operational periods for a specific project from a given list of project-period tuples. ```python def operational_periods_by_project(prj, project_operational_periods): "" " "" " return sorted( list( set( period for (project, period) in project_operational_periods if project == prj ) ) ) ``` -------------------------------- ### Display Help for gridpath_load_csvs Source: https://gridpath.readthedocs.io/en/latest/database.html Run this command to see usage information for the `gridpath_load_csvs` tool. ```bash >>> gridpath_load_csvs --help ``` -------------------------------- ### Generate Dispatch Plot Arguments Source: https://gridpath.readthedocs.io/en/latest/_sources/visualization.rst.txt This snippet displays the argument parser setup for the dispatch_plot script. It defines the command-line arguments the script can process. ```python from viz.dispatch_plot import create_parser parser = create_parser() ``` -------------------------------- ### Run Data Toolkit for Temporal Scenarios Source: https://gridpath.readthedocs.io/en/latest/data_toolkit.html Execute the `create_temporal_scenarios` step using the GridPath data toolkit. Specify the path to your settings CSV file. ```bash gridpath_run_data_toolkit --single_step create_temporal_scenarios --settings_csv PATH/TO/SETTINGS/CSV ``` -------------------------------- ### Get Cross-Feature Modules Source: https://gridpath.readthedocs.io/en/latest/architecture.html Returns a dictionary mapping tuples of features to lists of modules. Modules in these lists are included only if all features in the corresponding tuple are selected. ```python cross_feature_modules_list() ``` -------------------------------- ### Get All GridPath Modules Source: https://gridpath.readthedocs.io/en/latest/architecture.html Retrieves a list of all GridPath modules in the order they are loaded when all optional features are selected. This provides a comprehensive view of available modules. ```python all_modules_list() ``` -------------------------------- ### Load Scenario Data and Create Problem Instance Source: https://gridpath.readthedocs.io/en/latest/_modules/gridpath/run_scenario.html Loads scenario data and creates an optimization problem instance. This is a foundational step before solving the optimization problem. ```python # Load the scenario data if not parsed_arguments.quiet: print("Loading data...") scenario_data = load_scenario_data( model, dynamic_components, loaded_modules, scenario_directory, weather_iteration, hydro_iteration, availability_iteration, subproblem, stage, ) if not parsed_arguments.quiet: print("Creating problem instance...") instance = create_problem_instance(model, scenario_data) # Fix variables if modules request so instance = fix_variables( instance, dynamic_components, scenario_directory, weather_iteration, hydro_iteration, availability_iteration, subproblem, stage, loaded_modules, ) return dynamic_components, instance ``` -------------------------------- ### Generate Energy Target Plot Arguments Source: https://gridpath.readthedocs.io/en/latest/_sources/visualization.rst.txt This snippet displays the argument parser setup for the energy_target_plot script. It defines the command-line arguments the script can process. ```python from viz.energy_target_plot import create_parser parser = create_parser() ``` -------------------------------- ### Generate Total Capacity Plot Arguments Source: https://gridpath.readthedocs.io/en/latest/_sources/visualization.rst.txt This snippet displays the argument parser setup for the capacity_total_plot script. It defines the command-line arguments the script can process. ```python from viz.capacity_total_plot import create_parser parser = create_parser() ``` -------------------------------- ### Run Data Toolkit for Availability Iterations Source: https://gridpath.readthedocs.io/en/latest/data_toolkit.html This command initiates the creation of availability iteration input CSVs using the data toolkit. Ensure you provide the correct path to your settings CSV file. ```bash gridpath_run_data_toolkit --single_step create_availability_iteration_input_csvs --settings_csv PATH/TO/SETTINGS/CSV ``` -------------------------------- ### Define Number of Years Represented in a Period Source: https://gridpath.readthedocs.io/en/latest/_modules/gridpath/temporal/investment/periods.html Calculates the number of years each period represents based on its start and end years. This parameter is essential for time-dependent calculations. ```python m.number_years_represented = Param( m.PERIODS, within=NonNegativeReals, initialize=lambda mod, p: mod.period_end_year[p] - mod.period_start_year[p], ) ``` -------------------------------- ### Load Scenarios with Database and CSV Path Source: https://gridpath.readthedocs.io/en/latest/database.html Use this command to load scenarios from a CSV file. Specify the database path and the directory containing the scenario CSV. ```bash >>> gridpath_load_scenarios --database PATH/DO/DB --csv_path PATH/TO/SCENARIO/CSV ``` -------------------------------- ### Get Temporal Horizons from Database Source: https://gridpath.readthedocs.io/en/latest/_modules/gridpath/temporal/operations/horizons.html Retrieves temporal horizon and horizon timepoint data from the database for a given scenario and stage. It filters out built-in horizon types. ```python builtin_hrz_types_list = ", ".join(f"'{h}'" for h in BUILTIN_HORIZON_TYPES) c1 = conn.cursor() horizons = c1.execute(f"""SELECT horizon, balancing_type_horizon, boundary FROM inputs_temporal_horizons WHERE temporal_scenario_id = {subscenarios.TEMPORAL_SCENARIO_ID} AND (balancing_type_horizon, horizon) in ( SELECT DISTINCT balancing_type_horizon, horizon FROM inputs_temporal_horizon_timepoints WHERE temporal_scenario_id = {subscenarios.TEMPORAL_SCENARIO_ID} AND subproblem_id = {subproblem} AND stage_id = {stage} ) -- Don't get the built-ins AND balancing_type_horizon NOT IN ({builtin_hrz_types_list}) ORDER BY balancing_type_horizon, horizon;""") c2 = conn.cursor() horizon_timepoints = c2.execute( f"""SELECT horizon, balancing_type_horizon, timepoint FROM inputs_temporal_horizon_timepoints WHERE temporal_scenario_id = {subscenarios.TEMPORAL_SCENARIO_ID} AND subproblem_id = {subproblem} AND stage_id = {stage} -- Don't get the built-ins AND balancing_type_horizon NOT IN ({builtin_hrz_types_list}) ORDER BY balancing_type_horizon, timepoint;""" ) return horizons, horizon_timepoints ``` -------------------------------- ### Create GridPath Database Source: https://gridpath.readthedocs.io/en/latest/database.html Use this command to create an empty GridPath database. Specify the database path using the --database flag. ```bash >>> gridpath_create_database --database PATH/DO/DB ``` -------------------------------- ### Get Valid Period Months by Timepoint Source: https://gridpath.readthedocs.io/en/latest/_modules/gridpath/temporal/operations/horizons.html Calculates and returns a list of unique (period, month) tuples for all timepoints in the model. This is used to initialize the VALID_PERIOD_MONTHS set. ```python def get_valid_period_months_by_tmp(mod): prd_months = list(set([(mod.period[tmp], mod.month[tmp]) for tmp in mod.TMPS])) return prd_months ``` -------------------------------- ### Generate Hydro Curtailment Heatmap Plot Arguments Source: https://gridpath.readthedocs.io/en/latest/_sources/visualization.rst.txt This snippet displays the argument parser setup for the curtailment_hydro_heatmap_plot script. It defines the command-line arguments the script can process. ```python from viz.curtailment_hydro_heatmap_plot import create_parser parser = create_parser() ``` -------------------------------- ### Run Data Toolkit for Monte Carlo Weather Draws Source: https://gridpath.readthedocs.io/en/latest/data_toolkit.html Execute the `create_monte_carlo_weather_draws` step using the GridPath data toolkit. Ensure your settings CSV is correctly configured. ```bash gridpath_run_data_toolkit --single_step create_monte_carlo_weather_draws --settings_csv PATH/TO/SETTINGS/CSV ``` -------------------------------- ### Run Input Validation Suite Source: https://gridpath.readthedocs.io/en/latest/_sources/database.rst.txt Execute the input validation suite from the command line. Replace SCENARIO_NAME with the target scenario and PATH/TO/DATABASE with the actual database path. ```bash validate_inputs.py --scenario SCENARIO_NAME --database PATH/TO/DATABASE ``` -------------------------------- ### Generate Total Scenario Comparison Plot Arguments Source: https://gridpath.readthedocs.io/en/latest/_sources/visualization.rst.txt This snippet displays the argument parser setup for the capacity_total_scenario_comparison_plot script. It defines the command-line arguments the script can process. ```python from viz.capacity_total_scenario_comparison_plot import create_parser parser = create_parser() ``` -------------------------------- ### Calculate Startup Fuel Burn Rule Source: https://gridpath.readthedocs.io/en/latest/_modules/gridpath/project/operations/fuel_burn.html Calculates the startup fuel burn for projects, retrieving the appropriate expression based on the project's operational type. ```python def startup_fuel_burn_rule(mod, prj, tmp): """ Startup fuel burn is defined for some operational types while they are zero for others. Get the appropriate expression for each generator based on its operational type. """ op_type = mod.operational_type[prj] if hasattr(imported_operational_modules[op_type], "startup_fuel_burn_rule"): return imported_operational_modules[op_type].startup_fuel_burn_rule( mod, prj, tmp ) else: return op_type_init.startup_fuel_burn_rule(mod, prj, tmp) m.Startup_Fuel_Burn_MMBtu = Expression( m.STARTUP_FUEL_PRJ_OPR_TMPS, rule=startup_fuel_burn_rule ) ``` -------------------------------- ### Save Objective Function Value Source: https://gridpath.readthedocs.io/en/latest/_modules/gridpath/run_scenario.html Saves the calculated objective function value (e.g., NPV) to a file. It includes logic to round the value for test examples. ```python objective_function_value = instance.NPV() # Round objective function value of test examples if os.path.dirname(scenario_directory)[-8:] == "examples": objective_function_value = round(objective_function_value, 2) with open( os.path.join( scenario_directory, weather_iteration, hydro_iteration, availability_iteration, subproblem, stage, "results", "objective_function_value.txt", ), "w", newline="", ) as objective_file: objective_file.write(str(objective_function_value)) ``` -------------------------------- ### Activate Python Virtual Environment on Linux/MacOS Source: https://gridpath.readthedocs.io/en/latest/_sources/installation.rst.txt Activate the created Python virtual environment on Linux-based systems or MacOS using the source command. This is required before installing GridPath. ```bash source PATH/TO/PYTHON/ENV/bin/activate ``` -------------------------------- ### Initialize Carbon Cap Constraint Components Source: https://gridpath.readthedocs.io/en/latest/_modules/gridpath/auxiliary/dynamic_components.html Initializes lists for carbon cap constraint components, distinguishing between emission components and credit components. Modules are expected to add their relevant component names. ```python # Carbon cap constraint # Modules will add component names to these lists setattr(self, carbon_cap_balance_emission_components, list()) setattr(self, carbon_cap_balance_credit_components, list()) ``` -------------------------------- ### Startup Cost Rule Definition Source: https://gridpath.readthedocs.io/en/latest/_modules/gridpath/project/operations/costs.html Defines the startup cost for a project based on its operational type, handling both simple and start-time specific rules. It dynamically imports rules from operational modules. ```python if prj in mod.STARTUP_COST_SIMPLE_PRJS: if hasattr( imported_operational_modules[op_type], "startup_cost_simple_rule" ): startup_cost_simple = imported_operational_modules[ op_type ].startup_cost_simple_rule(mod, prj, tmp) else: startup_cost_simple = op_type_init.startup_cost_simple_rule( mod, prj, tmp ) else: startup_cost_simple = 0 if prj in mod.STARTUP_BY_ST_PRJS: if hasattr( imported_operational_modules[op_type], "startup_cost_by_st_rule" ): startup_cost_by_st = imported_operational_modules[ op_type ].startup_cost_by_st_rule(mod, prj, tmp) else: startup_cost_by_st = op_type_init.startup_cost_by_st_rule(mod, prj, tmp) else: startup_cost_by_st = 0 return startup_cost_simple + startup_cost_by_st m.Startup_Cost = Expression(m.STARTUP_COST_PRJ_OPR_TMPS, rule=startup_cost_rule) ``` -------------------------------- ### Define First Horizon Timepoint Parameter Source: https://gridpath.readthedocs.io/en/latest/_modules/gridpath/temporal/operations/horizons.html Defines the `first_hrz_tmp` parameter, mapping each balancing type-horizon pair to its first timepoint. This is useful for identifying the start of a horizon period. ```python m.first_hrz_tmp = Param( m.BLN_TYPE_HRZS, within=PositiveIntegers, initialize=first_hrz_tmp_init, ) ``` -------------------------------- ### Get Optional Modules by Feature Source: https://gridpath.readthedocs.io/en/latest/architecture.html Returns a dictionary where keys are optional feature names and values are lists of modules included in each feature. Each module belongs to only one feature. ```python optional_modules_list() ``` -------------------------------- ### Initialize Carbon Credits Tracking Components Source: https://gridpath.readthedocs.io/en/latest/_modules/gridpath/auxiliary/dynamic_components.html Initializes lists for carbon credits tracking, categorizing components into generation and purchase. Modules will add their relevant component names to these lists. ```python # Carbon credits tracking # Modules will add component names to these lists setattr(self, carbon_credits_balance_generation_components, list()) setattr(self, carbon_credits_balance_purchase_components, list()) ``` -------------------------------- ### Minimum Fraction of Fuel Blend Startup Constraint Source: https://gridpath.readthedocs.io/en/latest/_modules/gridpath/project/operations/fuel_burn.html Enforces a minimum proportion for each fuel in the blend for project startup fuel burn in each timepoint. ```python def min_fraction_of_fuel_blend_startup_rule(mod, prj, f, tmp): """ In each timepoint, enforce a minimum on the proportion in the blend of each fuel. """ return ( mod.Project_Startup_Fuel_Burn_by_Fuel[prj, f, tmp] >= mod.min_fraction_in_fuel_blend[prj, f] * mod.Startup_Fuel_Burn_MMBtu[prj, tmp] ) m.Min_Fuel_Fraction_of_Blend_Startup_Constraint = Constraint( m.STARTUP_FUEL_PRJS_FUEL_OPR_TMPS, rule=min_fraction_of_fuel_blend_startup_rule ) ``` -------------------------------- ### Define Timepoints in GridPath Source: https://gridpath.readthedocs.io/en/latest/_sources/functionality.rst.txt This module handles the definition and management of timepoints within the GridPath temporal setup. It is a fundamental component for structuring the model's time-based operations. ```python import gridpath.temporal.operations.timepoints ``` -------------------------------- ### Run Input Validation Suite Source: https://gridpath.readthedocs.io/en/latest/database.html Execute the GridPath input validation suite from the command line. Specify the scenario name and the path to the database. ```bash validate_inputs.py --scenario SCENARIO_NAME --database PATH/TO/DATABASE ```