Skip to content

Commit 9acf26e

Browse files
committed
Move patching to patch file
1 parent 76ae227 commit 9acf26e

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

switch_model/solve.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
)
2323
from switch_model.upgrade import do_inputs_need_upgrade, upgrade_inputs
2424
from switch_model.tools.graph.cli_graph import main as graph_main
25-
from switch_model.utilities.load_data import patch_to_allow_loading
2625
from switch_model.utilities.patches import patch_pyomo
2726
from switch_model.utilities.results_info import save_info, add_info, ResultsInfoSection
2827

@@ -91,9 +90,6 @@ def debug(type, value, tb):
9190
# Patch pyomo if needed, to allow reconstruction of expressions.
9291
# This must be done before the model is constructed.
9392
patch_pyomo()
94-
# This allows us to use input_file= when defining a Set or Param
95-
patch_to_allow_loading(Set)
96-
patch_to_allow_loading(Param)
9793

9894
# Define the model
9995
model = create_model(modules, args=args)

switch_model/utilities/patches.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
import pyomo.version
66
from pyomo.core.base.misc import _robust_sort_keyfcn
77

8+
from switch_model.utilities.load_data import patch_to_allow_loading
9+
from pyomo.environ import Set, Param
10+
811

912
def fixed_robust_sort_keyfcn(self, val, use_key=True):
1013
"""Generate a tuple ( str(type_name), val ) for sorting the value.
@@ -55,6 +58,10 @@ def patch_pyomo():
5558
from pyomo.core.base.misc import _robust_sort_keyfcn
5659
setattr(_robust_sort_keyfcn, "__call__", fixed_robust_sort_keyfcn)
5760

61+
# Patch Set and Param to allow specifying input file location (via input_file="...")
62+
patch_to_allow_loading(Set)
63+
patch_to_allow_loading(Param)
64+
5865
def replace_method(class_ref, method_name, new_source_code):
5966
"""
6067
Replace specified class method with a compiled version of new_source_code.

0 commit comments

Comments
 (0)