Skip to content

Commit

Permalink
Remove "Reporting Variables" from solution.
Browse files Browse the repository at this point in the history
Fixes #13.  Sort of.

I suppose I could still incorporate this script automatically into a
post-process section, but for now, it's required to manually execute it.
For example:

    $ ./temoa.py  utopia.dat  |  ./temoa.py  --calculate_report_variables -
       # or
    $ ./temoa.py  utopia.dat > utopia.sol
    $ ./temoa.py --calculate_report_variables utopia.sol > utopia_extended.sol

So, still not ideal, and as #13 states, could lead to a mismatch, but
better than nothing as larger problems will not run much faster in the
Pyomo stage.  "Don't let 'perfect' be the enemy of 'good'."

The astute observer will note that some previously implemented pieces
are no longer implemented, like InvestmentByTech.  That's pending as
round two of this needs to pull in certain details from parameters.
  • Loading branch information
Kevin Hunter committed Dec 4, 2013
1 parent 9d00fbc commit 4386a03
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 107 deletions.
31 changes: 26 additions & 5 deletions temoa_model/temoa_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1398,7 +1398,7 @@ def bibliographicalInformation ( ):


def parse_args ( ):
import argparse, platform
import argparse, platform, sys

from coopr.opt import SolverFactory as SF
from pyutilib.component.core import PluginGlobals
Expand Down Expand Up @@ -1440,9 +1440,10 @@ def parse_args ( ):
parser = argparse.ArgumentParser()
parser.prog = path.basename( argv[0].strip('/') )

graphviz = parser.add_argument_group('Graphviz Options')
solver = parser.add_argument_group('Solver Options')
stochastic = parser.add_argument_group('Stochastic Options')
graphviz = parser.add_argument_group('Graphviz Options')
solver = parser.add_argument_group('Solver Options')
stochastic = parser.add_argument_group('Stochastic Options')
postprocess = parser.add_argument_group('Postprocessing Options')

parser.add_argument('dot_dat',
type=str,
Expand Down Expand Up @@ -1542,13 +1543,25 @@ def parse_args ( ):
'ignoring the uncertainty of a stochastic tree. Specify the path '
'to the stochastic scenario directory. (i.e., where to find '
'ScenarioStructure.dat)',
action='store',
metavar='STOCHASTIC_DIRECTORY',
dest='eciu',
default=None)


help_calc_report = ('Use the supplied data to calculate so-called '
'"reporting" variables generally useful to energy modelers. Note that '
'this option expects pre-calculated data. Generally, use this in a '
'pipeline like: "{0} [...] | {0} --calculate_report_variables -" or "'
'{0} --calculate_report_variables ./path/to/data".').format( sys.argv[0] )
postprocess.add_argument('--calculate_report_variables',
help=help_calc_report,
type=argparse.FileType('rb'),
default=None
)

options = parser.parse_args()

# First, the options that exit or do not perform any "real" computation
if options.version:
version()
# this function exits
Expand All @@ -1557,6 +1570,14 @@ def parse_args ( ):
bibliographicalInformation()
# this function exits.

if options.calculate_report_variables:
# options.calculate_report_variables is an open file by argparse
from temoa_calculate import calculate_reporting_variables
data = calculate_reporting_variables( options.calculate_report_variables )
sys.stdout.write( data )
sys.stdout.flush()
raise SystemExit

# It would be nice if this implemented with add_mutually_exclusive_group
# but I /also/ want them in separate groups for display. Bummer.
if not (options.dot_dat or options.eciu):
Expand Down
2 changes: 0 additions & 2 deletions temoa_model/temoa_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,6 @@ def temoa_create_model ( name='TEMOA Entire Energy System Economic Optimization
domain=NonNegativeReals
)

AddReportingVariables( M )

M.BaseloadDiurnalConstraint_psdtv = Set(
dimen=5, rule=BaseloadDiurnalConstraintIndices )
M.CommodityBalanceConstraint_psdc = Set(
Expand Down
100 changes: 0 additions & 100 deletions temoa_model/temoa_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -1218,103 +1218,3 @@ def EnergyConsumptionByPeriodTechAndVintage_Constraint ( M, p, t, v ):
# End *_rule definitions
##############################################################################

##############################################################################
# Miscellaneous related functions

def AddReportingVariables ( M ):
# Additional and derived variables, mainly for reporting purposes. As
# these are basically used to export information for modeler consumption,
# these could be taken out of here and put in a post-processing step. This
# is in fact what we'll likely want to do as we grow because Coopr remains
# fairly inefficient, and each Variable represents a fair chunk of memory,
# among other resources. Luckily, all told, these are cheap, compared
# to the computational cost of the other constraints.
M.ActivityByPeriodTechAndOutputVarIndices = Set(
dimen=3, rule=ActivityByPeriodTechAndOutputVariableIndices )
M.ActivityByPeriodTechVintageAndOutputVarIndices = Set(
dimen=4, rule=ActivityByPeriodTechVintageAndOutputVariableIndices )

M.ActivityByTechAndOutputVarIndices = Set(
dimen=2, rule=ActivityByTechAndOutputVariableIndices )
M.ActivityByInputAndTechVarIndices = Set(
dimen=2, rule=ActivityByInputAndTechVariableIndices )

M.ActivityByPeriodInputAndTechVarIndices = Set(
dimen=3, rule=ActivityByPeriodInputAndTechVariableIndices )
M.ActivityByPeriodInputTechAndVintageVarIndices = Set(
dimen=4, rule=ActivityByPeriodInputTechAndVintageVariableIndices )

M.EmissionActivityByTechVarIndices = Set(
dimen=2, rule=EmissionActivityByTechVariableIndices )
M.EmissionActivityByPeriodAndTechVarIndices = Set(
dimen=3, rule=EmissionActivityByPeriodAndTechVariableIndices )
M.EmissionActivityByTechAndVintageVarIndices = Set(
dimen=3, rule=EmissionActivityByTechAndVintageVariableIndices )

M.EnergyConsumptionByTechAndOutputVarIndices = Set(
dimen=2, rule=EnergyConsumptionByTechAndOutputVariableIndices )
M.EnergyConsumptionByPeriodAndTechVarIndices = Set(
dimen=2, rule=EnergyConsumptionByPeriodAndTechVariableIndices )
M.EnergyConsumptionByPeriodInputAndTechVarIndices = Set(
dimen=3, rule=EnergyConsumptionByPeriodInputAndTechVariableIndices )
M.EnergyConsumptionByPeriodTechAndOutputVarIndices = Set(
dimen=3, rule=EnergyConsumptionByPeriodTechAndOutputVariableIndices )
M.EnergyConsumptionByPeriodTechAndVintageVarIndices = Set(
dimen=3, rule=EnergyConsumptionByPeriodTechAndVintageVariableIndices )

M.V_ActivityByPeriodAndTech = Var( M.time_optimize, M.tech_all, domain=NonNegativeReals )
M.V_ActivityByPeriodTechAndOutput = Var( M.ActivityByPeriodTechAndOutputVarIndices, domain=NonNegativeReals )
M.V_ActivityByPeriodTechVintageAndOutput = Var( M.ActivityByPeriodTechVintageAndOutputVarIndices, domain=NonNegativeReals )

M.V_ActivityByTechAndOutput = Var( M.ActivityByTechAndOutputVarIndices, domain=NonNegativeReals )
M.V_ActivityByInputAndTech = Var( M.ActivityByInputAndTechVarIndices, domain=NonNegativeReals )

M.V_ActivityByPeriodInputAndTech = Var( M.ActivityByPeriodInputAndTechVarIndices, domain=NonNegativeReals )
M.V_ActivityByPeriodInputTechAndVintage = Var( M.ActivityByPeriodInputTechAndVintageVarIndices, domain=NonNegativeReals )

M.V_InvestmentByTech = Var( M.tech_all, domain=NonNegativeReals )
M.V_InvestmentByTechAndVintage = Var( M.tech_all, M.vintage_optimize, domain=NonNegativeReals )

M.V_EmissionActivityTotal = Var( M.commodity_emissions, domain=Reals )
M.V_EmissionActivityByPeriod = Var( M.commodity_emissions, M.time_optimize, domain=Reals )
M.V_EmissionActivityByTech = Var( M.EmissionActivityByTechVarIndices, domain=Reals )
M.V_EmissionActivityByPeriodAndTech = Var( M.EmissionActivityByPeriodAndTechVarIndices, domain=Reals )
M.V_EmissionActivityByTechAndVintage = Var( M.EmissionActivityByTechAndVintageVarIndices, domain=Reals )

M.V_EnergyConsumptionByTech = Var( M.tech_all, domain=NonNegativeReals )
M.V_EnergyConsumptionByTechAndOutput = Var( M.EnergyConsumptionByTechAndOutputVarIndices, domain=NonNegativeReals )
M.V_EnergyConsumptionByPeriodAndTech = Var( M.EnergyConsumptionByPeriodAndTechVarIndices, domain=NonNegativeReals )
M.V_EnergyConsumptionByPeriodInputAndTech = Var( M.EnergyConsumptionByPeriodInputAndTechVarIndices, domain=NonNegativeReals )
M.V_EnergyConsumptionByPeriodTechAndOutput = Var( M.EnergyConsumptionByPeriodTechAndOutputVarIndices, domain=NonNegativeReals )
M.V_EnergyConsumptionByPeriodTechAndVintage = Var( M.EnergyConsumptionByPeriodTechAndVintageVarIndices, domain=NonNegativeReals )

# The requisite constraints to set the derived variables above.

M.ActivityByPeriodTechConstraint = Constraint( M.time_optimize, M.tech_all, rule=ActivityByPeriodTech_Constraint )
M.ActivityByPeriodTechAndOutputConstraint = Constraint( M.ActivityByPeriodTechAndOutputVarIndices, rule=ActivityByPeriodTechAndOutput_Constraint )
M.ActivityByPeriodTechVintageAndOutputConstraint = Constraint( M.ActivityByPeriodTechVintageAndOutputVarIndices, rule=ActivityByPeriodTechVintageAndOutput_Constraint )

M.ActivityByTechAndOutputConstraint = Constraint( M.ActivityByTechAndOutputVarIndices, rule=ActivityByTechAndOutput_Constraint )
M.ActivityByInputAndTechConstraint = Constraint( M.ActivityByInputAndTechVarIndices, rule=ActivityByInputAndTech_Constraint )

M.ActivityByPeriodInputAndTechConstraint = Constraint( M.ActivityByPeriodInputAndTechVarIndices, rule=ActivityByPeriodInputAndTech_Constraint )
M.ActivityByPeriodInputTechAndVintageConstraint = Constraint( M.ActivityByPeriodInputTechAndVintageVarIndices, rule=ActivityByPeriodInputTechAndVintage_Constraint )

M.InvestmentByTechConstraint = Constraint( M.tech_all, rule=InvestmentByTech_Constraint )
M.InvestmentByTechAndVintageConstraint = Constraint( M.tech_all, M.vintage_optimize, rule=InvestmentByTechAndVintage_Constraint )

M.EmissionActivityTotalConstraint = Constraint( M.commodity_emissions, rule=EmissionActivityTotal_Constraint )
M.EmissionActivityByPeriodConstraint = Constraint( M.commodity_emissions, M.time_optimize, rule=EmissionActivityByPeriod_Constraint )
M.EmissionActivityByTechConstraint = Constraint( M.EmissionActivityByTechVarIndices, rule=EmissionActivityByTech_Constraint )
M.EmissionActivityByPeriodAndTechConstraint = Constraint( M.EmissionActivityByPeriodAndTechVarIndices, rule=EmissionActivityByPeriodAndTech_Constraint )
M.EmissionActivityByTechAndVintageConstraint = Constraint( M.EmissionActivityByTechAndVintageVarIndices, rule=EmissionActivityByTechAndVintage_Constraint )

M.EnergyConsumptionByTechConstraint = Constraint( M.tech_all, rule=EnergyConsumptionByTech_Constraint )
M.EnergyConsumptionByTechAndOutputConstraint = Constraint( M.EnergyConsumptionByTechAndOutputVarIndices, rule=EnergyConsumptionByTechAndOutput_Constraint )
M.EnergyConsumptionByPeriodAndTechConstraint = Constraint( M.EnergyConsumptionByPeriodAndTechVarIndices, rule=EnergyConsumptionByPeriodAndTech_Constraint )
M.EnergyConsumptionByPeriodInputAndTechConstraint = Constraint( M.EnergyConsumptionByPeriodInputAndTechVarIndices, rule=EnergyConsumptionByPeriodInputAndTech_Constraint )
M.EnergyConsumptionByPeriodTechAndOutputConstraint = Constraint( M.EnergyConsumptionByPeriodTechAndOutputVarIndices, rule=EnergyConsumptionByPeriodTechAndOutput_Constraint )
M.EnergyConsumptionByPeriodTechAndVintageConstraint = Constraint( M.EnergyConsumptionByPeriodTechAndVintageVarIndices, rule=EnergyConsumptionByPeriodTechAndVintage_Constraint )

# End miscellaneous related functions
##############################################################################

0 comments on commit 4386a03

Please sign in to comment.